blob: f8afa6783fb85122fd10a1055de1da0a2f7cf317 [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 */ + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500144 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
145 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500146 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#define decode_setclientid_maxsz \
148 (op_decode_hdr_maxsz + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500149 2 /* clientid */ + \
150 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
151 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
152 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#define encode_setclientid_confirm_maxsz \
154 (op_encode_hdr_maxsz + \
155 3 + (NFS4_VERIFIER_SIZE >> 2))
156#define decode_setclientid_confirm_maxsz \
157 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400158#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
159#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400160#define encode_share_access_maxsz \
161 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500162#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400163#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
164#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
165#define encode_open_maxsz (op_encode_hdr_maxsz + \
166 2 + encode_share_access_maxsz + 2 + \
167 open_owner_id_maxsz + \
168 encode_opentype_maxsz + \
169 encode_claim_null_maxsz)
170#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400171#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400172 decode_ace_maxsz)
173#define decode_change_info_maxsz (5)
174#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400175 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400176 decode_change_info_maxsz + 1 + \
177 nfs4_fattr_bitmap_maxsz + \
178 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400179#define encode_open_confirm_maxsz \
180 (op_encode_hdr_maxsz + \
181 encode_stateid_maxsz + 1)
182#define decode_open_confirm_maxsz \
183 (op_decode_hdr_maxsz + \
184 decode_stateid_maxsz)
185#define encode_open_downgrade_maxsz \
186 (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 1 + \
188 encode_share_access_maxsz)
189#define decode_open_downgrade_maxsz \
190 (op_decode_hdr_maxsz + \
191 decode_stateid_maxsz)
192#define encode_close_maxsz (op_encode_hdr_maxsz + \
193 1 + encode_stateid_maxsz)
194#define decode_close_maxsz (op_decode_hdr_maxsz + \
195 decode_stateid_maxsz)
196#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
197 encode_stateid_maxsz + \
198 encode_attrs_maxsz)
199#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
200 nfs4_fattr_bitmap_maxsz)
201#define encode_read_maxsz (op_encode_hdr_maxsz + \
202 encode_stateid_maxsz + 3)
203#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
204#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400205 2 + encode_verifier_maxsz + 5 + \
206 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400207#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Chuck Levera7697f62014-03-12 12:51:17 -0400208 decode_verifier_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400209#define encode_readlink_maxsz (op_encode_hdr_maxsz)
210#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
211#define encode_write_maxsz (op_encode_hdr_maxsz + \
212 encode_stateid_maxsz + 4)
213#define decode_write_maxsz (op_decode_hdr_maxsz + \
214 2 + decode_verifier_maxsz)
215#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
216#define decode_commit_maxsz (op_decode_hdr_maxsz + \
217 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218#define encode_remove_maxsz (op_encode_hdr_maxsz + \
219 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400220#define decode_remove_maxsz (op_decode_hdr_maxsz + \
221 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222#define encode_rename_maxsz (op_encode_hdr_maxsz + \
223 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400224#define decode_rename_maxsz (op_decode_hdr_maxsz + \
225 decode_change_info_maxsz + \
226 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227#define encode_link_maxsz (op_encode_hdr_maxsz + \
228 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400229#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400230#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400231#define encode_lock_maxsz (op_encode_hdr_maxsz + \
232 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400233 1 + encode_stateid_maxsz + 1 + \
234 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400235#define decode_lock_denied_maxsz \
236 (8 + decode_lockowner_maxsz)
237#define decode_lock_maxsz (op_decode_hdr_maxsz + \
238 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400239#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
240 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400241#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
242 decode_lock_denied_maxsz)
243#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
244 encode_stateid_maxsz + \
245 4)
246#define decode_locku_maxsz (op_decode_hdr_maxsz + \
247 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400248#define encode_release_lockowner_maxsz \
249 (op_encode_hdr_maxsz + \
250 encode_lockowner_maxsz)
251#define decode_release_lockowner_maxsz \
252 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400253#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
254#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
256 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400257 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000258 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
260#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400261 1 + 2 + nfs4_name_maxsz + \
262 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400263#define decode_create_maxsz (op_decode_hdr_maxsz + \
264 decode_change_info_maxsz + \
265 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400266#define encode_statfs_maxsz (encode_getattr_maxsz)
267#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
269#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400270#define encode_getacl_maxsz (encode_getattr_maxsz)
271#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
272 nfs4_fattr_bitmap_maxsz + 1)
273#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
274 encode_stateid_maxsz + 3)
275#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400276#define encode_fs_locations_maxsz \
277 (encode_getattr_maxsz)
278#define decode_fs_locations_maxsz \
279 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000280#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400281#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 -0400282
283#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400284#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500285#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
286 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400287
Benny Halevy99fe60d2009-04-01 09:22:29 -0400288#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
289 encode_verifier_maxsz + \
290 1 /* co_ownerid.len */ + \
291 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
292 1 /* flags */ + \
293 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400294 /* max is SP4_MACH_CRED (for now) */ + \
295 1 + NFS4_OP_MAP_NUM_WORDS + \
296 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500297 1 /* implementation id array of size 1 */ + \
298 1 /* nii_domain */ + \
299 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
300 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500301 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500302 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400303#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
304 2 /* eir_clientid */ + \
305 1 /* eir_sequenceid */ + \
306 1 /* eir_flags */ + \
307 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400308 /* max is SP4_MACH_CRED (for now) */ + \
309 1 + NFS4_OP_MAP_NUM_WORDS + \
310 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400311 2 /* eir_server_owner.so_minor_id */ + \
312 /* eir_server_owner.so_major_id<> */ \
313 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
314 /* eir_server_scope<> */ \
315 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
316 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500317 1 /* nii_domain */ + \
318 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
319 1 /* nii_name */ + \
320 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
321 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400322#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
323#define decode_channel_attrs_maxsz (6 + \
324 1 /* ca_rdma_ird.len */ + \
325 1 /* ca_rdma_ird */)
326#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
327 2 /* csa_clientid */ + \
328 1 /* csa_sequence */ + \
329 1 /* csa_flags */ + \
330 encode_channel_attrs_maxsz + \
331 encode_channel_attrs_maxsz + \
332 1 /* csa_cb_program */ + \
333 1 /* csa_sec_parms.len (1) */ + \
334 1 /* cb_secflavor (AUTH_SYS) */ + \
335 1 /* stamp */ + \
336 1 /* machinename.len */ + \
337 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
338 1 /* uid */ + \
339 1 /* gid */ + \
340 1 /* gids.len (0) */)
341#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
342 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
343 1 /* csr_sequence */ + \
344 1 /* csr_flags */ + \
345 decode_channel_attrs_maxsz + \
346 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400347#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
348 /* bctsa_sessid */ \
349 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
350 1 /* bctsa_dir */ + \
351 1 /* bctsa_use_conn_in_rdma_mode */)
352#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
353 /* bctsr_sessid */ \
354 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
355 1 /* bctsr_dir */ + \
356 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400357#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
358#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400359#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
360#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400361#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
362 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
363#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
364 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500365#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
366#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700367#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
368 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
369 1 /* layout type */ + \
370 1 /* maxcount */ + \
371 1 /* bitmap size */ + \
372 1 /* notification bitmap length */ + \
373 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400374#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
375 1 /* layout type */ + \
376 1 /* opaque devaddr4 length */ + \
377 /* devaddr4 payload is read into page */ \
378 1 /* notification bitmap length */ + \
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700379 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400380#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
381 encode_stateid_maxsz)
382#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
383 decode_stateid_maxsz + \
384 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000385#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
386 2 /* offset */ + \
387 2 /* length */ + \
388 1 /* reclaim */ + \
389 encode_stateid_maxsz + \
390 1 /* new offset (true) */ + \
391 2 /* last byte written */ + \
392 1 /* nt_timechanged (false) */ + \
393 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500394 1 /* layoutupdate4 opaqueue len */)
395 /* the actual content of layoutupdate4 should
396 be allocated by drivers and spliced in
397 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000398#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300399#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
400 encode_stateid_maxsz + \
401 1 /* FIXME: opaque lrf_body always empty at the moment */)
402#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
403 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400404#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
405#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400406#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
407 XDR_QUADLEN(NFS4_STATEID_SIZE))
408#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400409#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
410 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400411#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400412#else /* CONFIG_NFS_V4_1 */
413#define encode_sequence_maxsz 0
414#define decode_sequence_maxsz 0
415#endif /* CONFIG_NFS_V4_1 */
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
418#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
419#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400420 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400422 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400424 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400426 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400428 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400430 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400434 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400436 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400438 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400440 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400442 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400444 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400446 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400447 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400449 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400451 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400452 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400454 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400456 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400460 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400462 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400463 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400464 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400465 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400466 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400467 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400470 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400471 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400472 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400473 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400474 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400475#define NFS4_enc_open_confirm_sz \
476 (compound_encode_hdr_maxsz + \
477 encode_putfh_maxsz + \
478 encode_open_confirm_maxsz)
479#define NFS4_dec_open_confirm_sz \
480 (compound_decode_hdr_maxsz + \
481 decode_putfh_maxsz + \
482 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400484 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400486 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400487 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400488 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400490 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400492 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400493 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400494 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#define NFS4_enc_open_downgrade_sz \
496 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400497 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400498 encode_putfh_maxsz + \
499 encode_open_downgrade_maxsz + \
500 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501#define NFS4_dec_open_downgrade_sz \
502 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400503 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400504 decode_putfh_maxsz + \
505 decode_open_downgrade_maxsz + \
506 decode_getattr_maxsz)
507#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400508 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400509 encode_putfh_maxsz + \
510 encode_close_maxsz + \
511 encode_getattr_maxsz)
512#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400513 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400514 decode_putfh_maxsz + \
515 decode_close_maxsz + \
516 decode_getattr_maxsz)
517#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400518 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400519 encode_putfh_maxsz + \
520 encode_setattr_maxsz + \
521 encode_getattr_maxsz)
522#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400523 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400524 decode_putfh_maxsz + \
525 decode_setattr_maxsz + \
526 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400528 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 encode_putfh_maxsz + \
530 encode_fsinfo_maxsz)
531#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400532 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 decode_putfh_maxsz + \
534 decode_fsinfo_maxsz)
535#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
536 encode_renew_maxsz)
537#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
538 decode_renew_maxsz)
539#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
540 encode_setclientid_maxsz)
541#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
542 decode_setclientid_maxsz)
543#define NFS4_enc_setclientid_confirm_sz \
544 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400545 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546#define NFS4_dec_setclientid_confirm_sz \
547 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400548 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400550 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400552 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400554 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400556 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400558 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400560 encode_lockt_maxsz)
561#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400563 decode_putfh_maxsz + \
564 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400568 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400572 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400573#define NFS4_enc_release_lockowner_sz \
574 (compound_encode_hdr_maxsz + \
575 encode_lockowner_maxsz)
576#define NFS4_dec_release_lockowner_sz \
577 (compound_decode_hdr_maxsz + \
578 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400582 encode_access_maxsz + \
583 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400585 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400587 decode_access_maxsz + \
588 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400592 encode_getattr_maxsz + \
593 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400595 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400597 decode_getattr_maxsz + \
598 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400600 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 encode_putfh_maxsz + \
602 encode_lookup_maxsz + \
603 encode_getattr_maxsz + \
604 encode_getfh_maxsz)
605#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400608 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 decode_getattr_maxsz + \
610 decode_getfh_maxsz)
611#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400612 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 encode_putrootfh_maxsz + \
614 encode_getattr_maxsz + \
615 encode_getfh_maxsz)
616#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400617 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 decode_putrootfh_maxsz + \
619 decode_getattr_maxsz + \
620 decode_getfh_maxsz)
621#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400624 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400626 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400628 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400630 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 encode_putfh_maxsz + \
632 encode_savefh_maxsz + \
633 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400634 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400636 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 decode_putfh_maxsz + \
638 decode_savefh_maxsz + \
639 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400640 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 encode_putfh_maxsz + \
644 encode_savefh_maxsz + \
645 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400646 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400647 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400648 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 decode_putfh_maxsz + \
652 decode_savefh_maxsz + \
653 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400654 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400655 decode_restorefh_maxsz + \
656 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400658 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 encode_putfh_maxsz + \
660 encode_symlink_maxsz + \
661 encode_getattr_maxsz + \
662 encode_getfh_maxsz)
663#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400664 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 decode_putfh_maxsz + \
666 decode_symlink_maxsz + \
667 decode_getattr_maxsz + \
668 decode_getfh_maxsz)
669#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400670 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 encode_putfh_maxsz + \
672 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400673 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400674 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 decode_putfh_maxsz + \
678 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400679 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400680 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400682 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 encode_putfh_maxsz + \
684 encode_getattr_maxsz)
685#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400686 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 decode_putfh_maxsz + \
688 decode_getattr_maxsz)
689#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400690 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400692 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400694 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400696 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400698 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800699 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 encode_getattr_maxsz)
701#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400702 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800703 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 decode_getattr_maxsz)
705#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400706 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100708 encode_delegreturn_maxsz + \
709 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400711 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100712 decode_delegreturn_maxsz + \
713 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000714#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400715 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000716 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400717 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000718#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400719 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000720 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400721 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000722#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400723 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000724 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400725 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000726#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400727 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000728 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400729 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400730#define NFS4_enc_fs_locations_sz \
731 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400732 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400733 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400734 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400735 encode_fs_locations_maxsz + \
736 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400737#define NFS4_dec_fs_locations_sz \
738 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400739 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400740 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400741 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400742 decode_fs_locations_maxsz + \
743 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000744#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
745 encode_sequence_maxsz + \
746 encode_putfh_maxsz + \
747 encode_secinfo_maxsz)
748#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
749 decode_sequence_maxsz + \
750 decode_putfh_maxsz + \
751 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400752#define NFS4_enc_fsid_present_sz \
753 (compound_encode_hdr_maxsz + \
754 encode_sequence_maxsz + \
755 encode_putfh_maxsz + \
756 encode_getfh_maxsz + \
757 encode_renew_maxsz)
758#define NFS4_dec_fsid_present_sz \
759 (compound_decode_hdr_maxsz + \
760 decode_sequence_maxsz + \
761 decode_putfh_maxsz + \
762 decode_getfh_maxsz + \
763 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400764#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400765#define NFS4_enc_bind_conn_to_session_sz \
766 (compound_encode_hdr_maxsz + \
767 encode_bind_conn_to_session_maxsz)
768#define NFS4_dec_bind_conn_to_session_sz \
769 (compound_decode_hdr_maxsz + \
770 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400771#define NFS4_enc_exchange_id_sz \
772 (compound_encode_hdr_maxsz + \
773 encode_exchange_id_maxsz)
774#define NFS4_dec_exchange_id_sz \
775 (compound_decode_hdr_maxsz + \
776 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400777#define NFS4_enc_create_session_sz \
778 (compound_encode_hdr_maxsz + \
779 encode_create_session_maxsz)
780#define NFS4_dec_create_session_sz \
781 (compound_decode_hdr_maxsz + \
782 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400783#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
784 encode_destroy_session_maxsz)
785#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
786 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400787#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
788 encode_destroy_clientid_maxsz)
789#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
790 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400791#define NFS4_enc_sequence_sz \
792 (compound_decode_hdr_maxsz + \
793 encode_sequence_maxsz)
794#define NFS4_dec_sequence_sz \
795 (compound_decode_hdr_maxsz + \
796 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400797#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
798 encode_sequence_maxsz + \
799 encode_putrootfh_maxsz + \
800 encode_fsinfo_maxsz)
801#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
802 decode_sequence_maxsz + \
803 decode_putrootfh_maxsz + \
804 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500805#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
806 encode_sequence_maxsz + \
807 encode_reclaim_complete_maxsz)
808#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
809 decode_sequence_maxsz + \
810 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400811#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
812 encode_sequence_maxsz +\
813 encode_getdeviceinfo_maxsz)
814#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
815 decode_sequence_maxsz + \
816 decode_getdeviceinfo_maxsz)
817#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
818 encode_sequence_maxsz + \
819 encode_putfh_maxsz + \
820 encode_layoutget_maxsz)
821#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
822 decode_sequence_maxsz + \
823 decode_putfh_maxsz + \
824 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000825#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
826 encode_sequence_maxsz +\
827 encode_putfh_maxsz + \
828 encode_layoutcommit_maxsz + \
829 encode_getattr_maxsz)
830#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
831 decode_sequence_maxsz + \
832 decode_putfh_maxsz + \
833 decode_layoutcommit_maxsz + \
834 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300835#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
836 encode_sequence_maxsz + \
837 encode_putfh_maxsz + \
838 encode_layoutreturn_maxsz)
839#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
840 decode_sequence_maxsz + \
841 decode_putfh_maxsz + \
842 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400843#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
844 encode_sequence_maxsz + \
845 encode_putrootfh_maxsz +\
846 encode_secinfo_no_name_maxsz)
847#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
848 decode_sequence_maxsz + \
849 decode_putrootfh_maxsz + \
850 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400851#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
852 encode_sequence_maxsz + \
853 encode_test_stateid_maxsz)
854#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
855 decode_sequence_maxsz + \
856 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400857#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
858 encode_sequence_maxsz + \
859 encode_free_stateid_maxsz)
860#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
861 decode_sequence_maxsz + \
862 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500863
864const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
865 compound_encode_hdr_maxsz +
866 encode_sequence_maxsz +
867 encode_putfh_maxsz +
868 encode_getattr_maxsz) *
869 XDR_UNIT);
870
871const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
872 compound_decode_hdr_maxsz +
873 decode_sequence_maxsz +
874 decode_putfh_maxsz) *
875 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400876
877const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
878 compound_decode_hdr_maxsz +
879 decode_sequence_maxsz) *
880 XDR_UNIT);
881EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400882#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
Trond Myklebustbca79472009-03-11 14:10:26 -0400884static const umode_t nfs_type2fmt[] = {
885 [NF4BAD] = 0,
886 [NF4REG] = S_IFREG,
887 [NF4DIR] = S_IFDIR,
888 [NF4BLK] = S_IFBLK,
889 [NF4CHR] = S_IFCHR,
890 [NF4LNK] = S_IFLNK,
891 [NF4SOCK] = S_IFSOCK,
892 [NF4FIFO] = S_IFIFO,
893 [NF4ATTRDIR] = 0,
894 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895};
896
897struct compound_hdr {
898 int32_t status;
899 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500900 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 uint32_t taglen;
902 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400903 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400904 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905};
906
Benny Halevy13c65ce2009-08-14 17:19:25 +0300907static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
908{
909 __be32 *p = xdr_reserve_space(xdr, nbytes);
910 BUG_ON(!p);
911 return p;
912}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Trond Myklebustcb17e552012-03-04 18:13:56 -0500914static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
915{
916 __be32 *p;
917
918 p = xdr_reserve_space(xdr, len);
919 xdr_encode_opaque_fixed(p, buf, len);
920}
921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
923{
Al Viro8687b632006-10-19 23:28:48 -0700924 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500926 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 xdr_encode_opaque(p, str, len);
928}
929
Trond Myklebust4ade9822012-03-04 18:13:57 -0500930static void encode_uint32(struct xdr_stream *xdr, u32 n)
931{
932 __be32 *p;
933
934 p = reserve_space(xdr, 4);
935 *p = cpu_to_be32(n);
936}
937
Trond Myklebustff2eb682012-03-05 11:40:12 -0500938static void encode_uint64(struct xdr_stream *xdr, u64 n)
939{
940 __be32 *p;
941
942 p = reserve_space(xdr, 8);
943 xdr_encode_hyper(p, n);
944}
945
Trond Myklebust4ade9822012-03-04 18:13:57 -0500946static void encode_nfs4_seqid(struct xdr_stream *xdr,
947 const struct nfs_seqid *seqid)
948{
949 encode_uint32(xdr, seqid->sequence->counter);
950}
951
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400952static void encode_compound_hdr(struct xdr_stream *xdr,
953 struct rpc_rqst *req,
954 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955{
Al Viro8687b632006-10-19 23:28:48 -0700956 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400957 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400958
959 /* initialize running count of expected bytes in reply.
960 * NOTE: the replied tag SHOULD be the same is the one sent,
961 * but this is not required as a MUST for the server to do so. */
962 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
Trond Myklebust7fc38842012-10-15 11:51:21 -0400964 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500965 encode_string(xdr, hdr->taglen, hdr->tag);
966 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300967 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500968 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300969 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500970}
971
Trond Myklebustab19b482012-03-04 18:13:57 -0500972static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
973 uint32_t replen,
974 struct compound_hdr *hdr)
975{
976 encode_uint32(xdr, op);
977 hdr->nops++;
978 hdr->replen += replen;
979}
980
Andy Adamsond0179312008-12-23 16:06:17 -0500981static void encode_nops(struct compound_hdr *hdr)
982{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400983 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500984 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985}
986
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500987static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
988{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500989 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500990}
991
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
993{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500994 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995}
996
David Quigleyaa9c2662013-05-22 12:50:44 -0400997static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
998 const struct nfs4_label *label,
999 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000{
1001 char owner_name[IDMAP_NAMESZ];
1002 char owner_group[IDMAP_NAMESZ];
1003 int owner_namelen = 0;
1004 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001005 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001006 unsigned i;
1007 uint32_t len = 0;
1008 uint32_t bmval_len;
1009 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
1011 /*
1012 * We reserve enough space to write the entire attribute buffer at once.
1013 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001014 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1015 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001016 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001018 if (iap->ia_valid & ATTR_SIZE) {
1019 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001021 }
1022 if (iap->ia_valid & ATTR_MODE) {
1023 bmval[1] |= FATTR4_WORD1_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 len += 4;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001025 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001027 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001029 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001030 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 /* XXX */
1032 strcpy(owner_name, "nobody");
1033 owner_namelen = sizeof("nobody") - 1;
1034 /* goto out; */
1035 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001036 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1038 }
1039 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001040 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001042 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001043 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 strcpy(owner_group, "nobody");
1045 owner_grouplen = sizeof("nobody") - 1;
1046 /* goto out; */
1047 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001048 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1050 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001052 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1053 len += 16;
1054 } else if (iap->ia_valid & ATTR_ATIME) {
1055 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1056 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 }
1058 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001059 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1060 len += 16;
1061 } else if (iap->ia_valid & ATTR_MTIME) {
1062 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1063 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001065 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001066 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1067 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1068 }
1069
1070 if (bmval[2] != 0)
1071 bmval_len = 3;
1072 else if (bmval[1] != 0)
1073 bmval_len = 2;
1074 else
1075 bmval_len = 1;
1076
1077 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1078
1079 *p++ = cpu_to_be32(bmval_len);
1080 for (i = 0; i < bmval_len; i++)
1081 *p++ = cpu_to_be32(bmval[i]);
1082 *p++ = cpu_to_be32(len);
1083
1084 if (bmval[0] & FATTR4_WORD0_SIZE)
1085 p = xdr_encode_hyper(p, iap->ia_size);
1086 if (bmval[1] & FATTR4_WORD1_MODE)
1087 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1088 if (bmval[1] & FATTR4_WORD1_OWNER)
1089 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1090 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1091 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1092 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1093 if (iap->ia_valid & ATTR_ATIME_SET) {
1094 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1095 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1096 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1097 } else
1098 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1099 }
1100 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1101 if (iap->ia_valid & ATTR_MTIME_SET) {
1102 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1103 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1104 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1105 } else
1106 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1107 }
1108 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001109 *p++ = cpu_to_be32(label->lfs);
1110 *p++ = cpu_to_be32(label->pi);
1111 *p++ = cpu_to_be32(label->len);
1112 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1113 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001114
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001118static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001120 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1121 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122}
1123
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001124static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125{
Trond Myklebustab19b482012-03-04 18:13:57 -05001126 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001127 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001128 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129}
1130
Fred Isaman0b7c0152012-04-20 14:47:39 -04001131static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132{
Al Viro8687b632006-10-19 23:28:48 -07001133 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001134
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001135 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1136 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001137 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001138 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001141static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Al Viro8687b632006-10-19 23:28:48 -07001143 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001144
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001145 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1146 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
1148 switch (create->ftype) {
1149 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001150 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001151 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001152 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 break;
1154
1155 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001156 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001157 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001158 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 break;
1160
1161 default:
1162 break;
1163 }
1164
Benny Halevy811652b2009-08-14 17:19:34 +03001165 encode_string(xdr, create->name->len, create->name->name);
David Quigleyaa9c2662013-05-22 12:50:44 -04001166 encode_attrs(xdr, create->attrs, create->label, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167}
1168
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001169static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170{
Andy Adamson05d564f2008-12-23 16:06:15 -05001171 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001173 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1174 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001175 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001176 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177}
1178
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001179static 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 -07001180{
Andy Adamson05d564f2008-12-23 16:06:15 -05001181 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001183 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1184 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001185 *p++ = cpu_to_be32(2);
1186 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001187 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188}
1189
Fred Isamandae100c2011-07-30 20:52:37 -04001190static void
1191encode_getattr_three(struct xdr_stream *xdr,
1192 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1193 struct compound_hdr *hdr)
1194{
1195 __be32 *p;
1196
Trond Myklebustab19b482012-03-04 18:13:57 -05001197 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001198 if (bm2) {
1199 p = reserve_space(xdr, 16);
1200 *p++ = cpu_to_be32(3);
1201 *p++ = cpu_to_be32(bm0);
1202 *p++ = cpu_to_be32(bm1);
1203 *p = cpu_to_be32(bm2);
1204 } else if (bm1) {
1205 p = reserve_space(xdr, 12);
1206 *p++ = cpu_to_be32(2);
1207 *p++ = cpu_to_be32(bm0);
1208 *p = cpu_to_be32(bm1);
1209 } else {
1210 p = reserve_space(xdr, 8);
1211 *p++ = cpu_to_be32(1);
1212 *p = cpu_to_be32(bm0);
1213 }
Fred Isamandae100c2011-07-30 20:52:37 -04001214}
1215
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001216static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217{
David Quigleya09df2c2013-05-22 12:50:41 -04001218 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1219 bitmask[1] & nfs4_fattr_bitmap[1],
1220 bitmask[2] & nfs4_fattr_bitmap[2],
1221 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222}
1223
Andy Adamson88034c32012-05-23 05:02:34 -04001224static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001225 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001226 struct compound_hdr *hdr)
1227{
1228 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001229 bitmask[0] & open_bitmap[0],
1230 bitmask[1] & open_bitmap[1],
1231 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001232 hdr);
1233}
1234
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001235static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236{
Fred Isamandae100c2011-07-30 20:52:37 -04001237 encode_getattr_three(xdr,
1238 bitmask[0] & nfs4_fsinfo_bitmap[0],
1239 bitmask[1] & nfs4_fsinfo_bitmap[1],
1240 bitmask[2] & nfs4_fsinfo_bitmap[2],
1241 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242}
1243
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001244static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001245{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001246 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1247 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001248}
1249
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001250static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251{
Trond Myklebustab19b482012-03-04 18:13:57 -05001252 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253}
1254
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001255static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256{
Trond Myklebustab19b482012-03-04 18:13:57 -05001257 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001258 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259}
1260
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001261static inline int nfs4_lock_type(struct file_lock *fl, int block)
1262{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001263 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001264 return block ? NFS4_READW_LT : NFS4_READ_LT;
1265 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1266}
1267
1268static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1269{
1270 if (fl->fl_end == OFFSET_MAX)
1271 return ~(uint64_t)0;
1272 return fl->fl_end - fl->fl_start + 1;
1273}
1274
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001275static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1276{
1277 __be32 *p;
1278
Trond Myklebustd035c362010-12-21 10:45:27 -05001279 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001280 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001281 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001282 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001283 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001284 xdr_encode_hyper(p, lowner->id);
1285}
1286
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287/*
1288 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1289 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1290 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001291static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
Al Viro8687b632006-10-19 23:28:48 -07001293 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001295 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1296 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001297 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1298 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001299 p = xdr_encode_hyper(p, args->fl->fl_start);
1300 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001301 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001302 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001303 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001304 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001305 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001306 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 }
1308 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001309 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001310 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312}
1313
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001314static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315{
Al Viro8687b632006-10-19 23:28:48 -07001316 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001318 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1319 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001320 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001321 p = xdr_encode_hyper(p, args->fl->fl_start);
1322 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001323 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324}
1325
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001326static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327{
Al Viro8687b632006-10-19 23:28:48 -07001328 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001330 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1331 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001332 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001333 encode_nfs4_stateid(xdr, args->stateid);
1334 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001335 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001336 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337}
1338
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001339static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1340{
Trond Myklebustab19b482012-03-04 18:13:57 -05001341 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001342 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001343}
1344
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001345static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346{
Trond Myklebustab19b482012-03-04 18:13:57 -05001347 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001348 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349}
1350
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001351static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352{
Al Viro8687b632006-10-19 23:28:48 -07001353 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Benny Halevy13c65ce2009-08-14 17:19:25 +03001355 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001356 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001357 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001358 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001359 break;
1360 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001361 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001362 break;
1363 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001364 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001365 break;
1366 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001367 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 }
Benny Halevy34558512009-08-14 17:19:30 +03001369 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370}
1371
1372static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1373{
Al Viro8687b632006-10-19 23:28:48 -07001374 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 /*
1376 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1377 * owner 4 = 32
1378 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001379 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001380 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001381 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001382 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001383 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001384 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001385 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001386 *p++ = cpu_to_be32(arg->id.uniquifier);
1387 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388}
1389
1390static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1391{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001392 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001393 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Benny Halevy13c65ce2009-08-14 17:19:25 +03001395 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001396 switch(arg->createmode) {
1397 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001398 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001399 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Andy Adamson05d564f2008-12-23 16:06:15 -05001400 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001401 case NFS4_CREATE_GUARDED:
1402 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001403 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001404 break;
1405 case NFS4_CREATE_EXCLUSIVE:
1406 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1407 encode_nfs4_verifier(xdr, &arg->u.verifier);
1408 break;
1409 case NFS4_CREATE_EXCLUSIVE4_1:
1410 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1411 encode_nfs4_verifier(xdr, &arg->u.verifier);
1412 dummy.ia_valid = 0;
David Quigleyaa9c2662013-05-22 12:50:44 -04001413 encode_attrs(xdr, &dummy, arg->label, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 }
1415}
1416
1417static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1418{
Al Viro8687b632006-10-19 23:28:48 -07001419 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Benny Halevy13c65ce2009-08-14 17:19:25 +03001421 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001423 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001424 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001425 break;
1426 default:
Benny Halevy34558512009-08-14 17:19:30 +03001427 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001428 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 }
1430}
1431
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001432static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433{
Al Viro8687b632006-10-19 23:28:48 -07001434 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Benny Halevy13c65ce2009-08-14 17:19:25 +03001436 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001438 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001439 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001440 break;
1441 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001442 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001443 break;
1444 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001445 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001446 break;
1447 default:
1448 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 }
1450}
1451
1452static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1453{
Al Viro8687b632006-10-19 23:28:48 -07001454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Benny Halevy13c65ce2009-08-14 17:19:25 +03001456 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001457 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 encode_string(xdr, name->len, name->name);
1459}
1460
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001461static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462{
Al Viro8687b632006-10-19 23:28:48 -07001463 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Benny Halevy13c65ce2009-08-14 17:19:25 +03001465 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001466 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 encode_delegation_type(xdr, type);
1468}
1469
1470static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1471{
Al Viro8687b632006-10-19 23:28:48 -07001472 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001474 p = reserve_space(xdr, 4);
1475 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1476 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 encode_string(xdr, name->len, name->name);
1478}
1479
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001480static inline void encode_claim_fh(struct xdr_stream *xdr)
1481{
1482 __be32 *p;
1483
1484 p = reserve_space(xdr, 4);
1485 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1486}
1487
1488static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1489{
1490 __be32 *p;
1491
1492 p = reserve_space(xdr, 4);
1493 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1494 encode_nfs4_stateid(xdr, stateid);
1495}
1496
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001497static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498{
Trond Myklebustab19b482012-03-04 18:13:57 -05001499 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 encode_openhdr(xdr, arg);
1501 encode_opentype(xdr, arg);
1502 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001503 case NFS4_OPEN_CLAIM_NULL:
1504 encode_claim_null(xdr, arg->name);
1505 break;
1506 case NFS4_OPEN_CLAIM_PREVIOUS:
1507 encode_claim_previous(xdr, arg->u.delegation_type);
1508 break;
1509 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1510 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1511 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001512 case NFS4_OPEN_CLAIM_FH:
1513 encode_claim_fh(xdr);
1514 break;
1515 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1516 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1517 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001518 default:
1519 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521}
1522
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001523static 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 -07001524{
Trond Myklebustab19b482012-03-04 18:13:57 -05001525 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001526 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001527 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528}
1529
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001530static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531{
Trond Myklebustab19b482012-03-04 18:13:57 -05001532 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001533 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001534 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001535 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536}
1537
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001538static void
Andy Adamsond0179312008-12-23 16:06:17 -05001539encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540{
Trond Myklebustab19b482012-03-04 18:13:57 -05001541 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001542 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543}
1544
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001545static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546{
Trond Myklebustab19b482012-03-04 18:13:57 -05001547 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548}
1549
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001550static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1551 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552{
Al Viro8687b632006-10-19 23:28:48 -07001553 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Trond Myklebustab19b482012-03-04 18:13:57 -05001555 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001556 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
Benny Halevy13c65ce2009-08-14 17:19:25 +03001558 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001559 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001560 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561}
1562
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001563static 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 -07001564{
David Quigleyaa9c2662013-05-22 12:50:44 -04001565 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001566 FATTR4_WORD0_RDATTR_ERROR,
1567 FATTR4_WORD1_MOUNTED_ON_FILEID,
1568 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001569 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001570 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001571 uint32_t attrlen = 0;
1572 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001574 if (readdir->plus) {
1575 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001576 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001577 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1578 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1579 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1580 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001581 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001582 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001583 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001584 /* Use mounted_on_fileid only if the server supports it */
1585 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1586 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001587 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1588 attrs[i] &= readdir->bitmask[i];
1589 if (attrs[i] != 0)
1590 attrlen = i+1;
1591 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001592
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001593 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001594 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001595 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001596 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001597 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001598 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001599 *p++ = cpu_to_be32(attrlen);
1600 for (i = 0; i < attrlen; i++)
1601 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001602 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001603
1604 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001605 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001606 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001607 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001608 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001609 attrs[1] & readdir->bitmask[1],
1610 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611}
1612
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001613static 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 -07001614{
Trond Myklebustab19b482012-03-04 18:13:57 -05001615 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616}
1617
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001618static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619{
Trond Myklebustab19b482012-03-04 18:13:57 -05001620 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001621 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622}
1623
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001624static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625{
Trond Myklebustab19b482012-03-04 18:13:57 -05001626 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001627 encode_string(xdr, oldname->len, oldname->name);
1628 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629}
1630
Chuck Leverbb4dae52012-03-01 17:01:48 -05001631static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1632 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001634 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001635 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636}
1637
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001638static void
Andy Adamsond0179312008-12-23 16:06:17 -05001639encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001640{
Trond Myklebustab19b482012-03-04 18:13:57 -05001641 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001642}
1643
Chuck Lever9f06c712010-12-14 14:59:18 +00001644static void
Andy Adamsond0179312008-12-23 16:06:17 -05001645encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001646{
Al Viro8687b632006-10-19 23:28:48 -07001647 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001648
Trond Myklebustab19b482012-03-04 18:13:57 -05001649 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001650 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001651 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001652 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001653 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001654 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001655 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001656 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001657}
1658
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001659static void
Andy Adamsond0179312008-12-23 16:06:17 -05001660encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
Trond Myklebustab19b482012-03-04 18:13:57 -05001662 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663}
1664
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001665static 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 -07001666{
Trond Myklebustab19b482012-03-04 18:13:57 -05001667 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001668 encode_nfs4_stateid(xdr, &arg->stateid);
David Quigleyaa9c2662013-05-22 12:50:44 -04001669 encode_attrs(xdr, arg->iap, arg->label, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670}
1671
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001672static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673{
Al Viro8687b632006-10-19 23:28:48 -07001674 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
Trond Myklebust70019512012-03-04 20:49:32 -05001676 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001677 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
1679 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001680 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001681 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1683 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001684 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001685 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686}
1687
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001688static 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 -07001689{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001690 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1691 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001692 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001693 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694}
1695
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001696static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1697 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698{
Al Viro8687b632006-10-19 23:28:48 -07001699 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
Trond Myklebustab19b482012-03-04 18:13:57 -05001701 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001702 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
Benny Halevy13c65ce2009-08-14 17:19:25 +03001704 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001705 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001706 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001707 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
1709 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710}
1711
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001712static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713{
Trond Myklebustab19b482012-03-04 18:13:57 -05001714 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001715 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001717
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001718static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1719{
Trond Myklebustab19b482012-03-04 18:13:57 -05001720 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001721 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001722}
1723
Benny Halevy99fe60d2009-04-01 09:22:29 -04001724#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001725/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001726static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1727 struct nfs4_session *session,
1728 struct compound_hdr *hdr)
1729{
1730 __be32 *p;
1731
1732 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1733 decode_bind_conn_to_session_maxsz, hdr);
1734 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1735 p = xdr_reserve_space(xdr, 8);
1736 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1737 *p = 0; /* use_conn_in_rdma_mode = False */
1738}
1739
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001740static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1741{
1742 unsigned int i;
1743 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1744 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1745 encode_uint32(xdr, op_map->u.words[i]);
1746}
1747
Benny Halevy99fe60d2009-04-01 09:22:29 -04001748static void encode_exchange_id(struct xdr_stream *xdr,
1749 struct nfs41_exchange_id_args *args,
1750 struct compound_hdr *hdr)
1751{
1752 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001753 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001754 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001755
Trond Myklebust70019512012-03-04 20:49:32 -05001756 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001757 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001758
1759 encode_string(xdr, args->id_len, args->id);
1760
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001761 encode_uint32(xdr, args->flags);
1762 encode_uint32(xdr, args->state_protect.how);
1763
1764 switch (args->state_protect.how) {
1765 case SP4_NONE:
1766 break;
1767 case SP4_MACH_CRED:
1768 encode_op_map(xdr, &args->state_protect.enforce);
1769 encode_op_map(xdr, &args->state_protect.allow);
1770 break;
1771 default:
1772 WARN_ON_ONCE(1);
1773 break;
1774 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001775
1776 if (send_implementation_id &&
1777 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1778 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001779 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001780 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1781 utsname()->sysname, utsname()->release,
1782 utsname()->version, utsname()->machine);
1783
1784 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001785 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001786
1787 encode_string(xdr,
1788 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1789 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1790 encode_string(xdr, len, impl_name);
1791 /* just send zeros for nii_date - the date is in nii_name */
1792 p = reserve_space(xdr, 12);
1793 p = xdr_encode_hyper(p, 0);
1794 *p = cpu_to_be32(0);
1795 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001796 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001797}
Andy Adamsonfc931582009-04-01 09:22:31 -04001798
1799static void encode_create_session(struct xdr_stream *xdr,
1800 struct nfs41_create_session_args *args,
1801 struct compound_hdr *hdr)
1802{
1803 __be32 *p;
1804 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1805 uint32_t len;
1806 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001807 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001808 u32 max_resp_sz_cached;
1809
1810 /*
1811 * Assumes OPEN is the biggest non-idempotent compound.
1812 * 2 is the verifier.
1813 */
1814 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1815 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001816
Andy Adamsonfc931582009-04-01 09:22:31 -04001817 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1818 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001819
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001820 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1821 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001822 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001823 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1824 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001825
Andy Adamsonfc931582009-04-01 09:22:31 -04001826 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001827 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001828 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1829 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001830 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001831 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1832 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1833 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001834
1835 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001836 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001837 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1838 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1839 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1840 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1841 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1842 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001843
Benny Halevye75bc1c2009-08-14 17:18:54 +03001844 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001845 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001846 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001847
1848 /* authsys_parms rfc1831 */
Trond Myklebust17f26b12013-08-21 15:48:42 -04001849 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001850 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001851 *p++ = cpu_to_be32(0); /* UID */
1852 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001853 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001854}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001855
1856static void encode_destroy_session(struct xdr_stream *xdr,
1857 struct nfs4_session *session,
1858 struct compound_hdr *hdr)
1859{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001860 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1861 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001862}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001863
Trond Myklebust66245532012-05-25 17:18:09 -04001864static void encode_destroy_clientid(struct xdr_stream *xdr,
1865 uint64_t clientid,
1866 struct compound_hdr *hdr)
1867{
1868 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1869 encode_uint64(xdr, clientid);
1870}
1871
Ricardo Labiaga180197532009-12-05 16:08:40 -05001872static void encode_reclaim_complete(struct xdr_stream *xdr,
1873 struct nfs41_reclaim_complete_args *args,
1874 struct compound_hdr *hdr)
1875{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001876 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1877 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001878}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001879#endif /* CONFIG_NFS_V4_1 */
1880
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001881static void encode_sequence(struct xdr_stream *xdr,
1882 const struct nfs4_sequence_args *args,
1883 struct compound_hdr *hdr)
1884{
1885#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001886 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001887 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001888 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001889 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001890
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001891 tp = slot->table;
1892 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001893 if (!session)
1894 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001895
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001896 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001897
1898 /*
1899 * Sessionid + seqid + slotid + max slotid + cache_this
1900 */
1901 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1902 "max_slotid=%d cache_this=%d\n",
1903 __func__,
1904 ((u32 *)session->sess_id.data)[0],
1905 ((u32 *)session->sess_id.data)[1],
1906 ((u32 *)session->sess_id.data)[2],
1907 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001908 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001909 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001910 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001911 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001912 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001913 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001914 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001915 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001916#endif /* CONFIG_NFS_V4_1 */
1917}
1918
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001919#ifdef CONFIG_NFS_V4_1
1920static void
1921encode_getdeviceinfo(struct xdr_stream *xdr,
1922 const struct nfs4_getdeviceinfo_args *args,
1923 struct compound_hdr *hdr)
1924{
1925 __be32 *p;
1926
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001927 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001928 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001929 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1930 NFS4_DEVICEID4_SIZE);
1931 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001932 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001933
1934 p = reserve_space(xdr, 4 + 4);
1935 *p++ = cpu_to_be32(1); /* bitmap length */
1936 *p++ = cpu_to_be32(NOTIFY_DEVICEID4_CHANGE | NOTIFY_DEVICEID4_DELETE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001937}
1938
1939static void
1940encode_layoutget(struct xdr_stream *xdr,
1941 const struct nfs4_layoutget_args *args,
1942 struct compound_hdr *hdr)
1943{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001944 __be32 *p;
1945
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001946 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1947 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001948 *p++ = cpu_to_be32(0); /* Signal layout available */
1949 *p++ = cpu_to_be32(args->type);
1950 *p++ = cpu_to_be32(args->range.iomode);
1951 p = xdr_encode_hyper(p, args->range.offset);
1952 p = xdr_encode_hyper(p, args->range.length);
1953 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001954 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001955 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001956
1957 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1958 __func__,
1959 args->type,
1960 args->range.iomode,
1961 (unsigned long)args->range.offset,
1962 (unsigned long)args->range.length,
1963 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001964}
Andy Adamson863a3c62011-03-23 13:27:54 +00001965
1966static int
1967encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001968 struct inode *inode,
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001969 struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001970 struct compound_hdr *hdr)
1971{
1972 __be32 *p;
1973
1974 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1975 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1976
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001977 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1978 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001979 /* Only whole file layouts */
1980 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001981 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001982 *p = cpu_to_be32(0); /* reclaim */
1983 encode_nfs4_stateid(xdr, &args->stateid);
1984 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001985 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1986 p = xdr_encode_hyper(p, args->lastbytewritten);
1987 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1988 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001989
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001990 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
Benny Halevyac7db722011-05-22 19:53:48 +03001991 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1992 NFS_I(inode)->layout, xdr, args);
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001993 } else {
1994 encode_uint32(xdr, args->layoutupdate_len);
1995 if (args->layoutupdate_pages) {
1996 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
1997 args->layoutupdate_len);
1998 }
1999 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002000
Andy Adamson863a3c62011-03-23 13:27:54 +00002001 return 0;
2002}
Benny Halevycbe82602011-05-22 19:52:37 +03002003
2004static void
2005encode_layoutreturn(struct xdr_stream *xdr,
2006 const struct nfs4_layoutreturn_args *args,
2007 struct compound_hdr *hdr)
2008{
2009 __be32 *p;
2010
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002011 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2012 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002013 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2014 *p++ = cpu_to_be32(args->layout_type);
2015 *p++ = cpu_to_be32(IOMODE_ANY);
2016 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002017 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002018 p = xdr_encode_hyper(p, 0);
2019 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2020 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002021 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002022 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002023 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2024 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2025 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002026 } else
2027 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002028}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002029
2030static int
2031encode_secinfo_no_name(struct xdr_stream *xdr,
2032 const struct nfs41_secinfo_no_name_args *args,
2033 struct compound_hdr *hdr)
2034{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002035 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2036 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002037 return 0;
2038}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002039
2040static void encode_test_stateid(struct xdr_stream *xdr,
2041 struct nfs41_test_stateid_args *args,
2042 struct compound_hdr *hdr)
2043{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002044 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2045 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002046 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002047}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002048
2049static void encode_free_stateid(struct xdr_stream *xdr,
2050 struct nfs41_free_stateid_args *args,
2051 struct compound_hdr *hdr)
2052{
Trond Myklebustab19b482012-03-04 18:13:57 -05002053 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002054 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002055}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002056#endif /* CONFIG_NFS_V4_1 */
2057
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058/*
2059 * END OF "GENERIC" ENCODE ROUTINES.
2060 */
2061
Benny Halevy66cc0422009-04-01 09:22:10 -04002062static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2063{
2064#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002065 struct nfs4_session *session = args->sa_slot->table->session;
2066 if (session)
2067 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002068#endif /* CONFIG_NFS_V4_1 */
2069 return 0;
2070}
2071
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072/*
2073 * Encode an ACCESS request
2074 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002075static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2076 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002079 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Chuck Lever9f06c712010-12-14 14:59:18 +00002082 encode_compound_hdr(xdr, req, &hdr);
2083 encode_sequence(xdr, &args->seq_args, &hdr);
2084 encode_putfh(xdr, args->fh, &hdr);
2085 encode_access(xdr, args->access, &hdr);
2086 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002087 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088}
2089
2090/*
2091 * Encode LOOKUP request
2092 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002093static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2094 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002097 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
Chuck Lever9f06c712010-12-14 14:59:18 +00002100 encode_compound_hdr(xdr, req, &hdr);
2101 encode_sequence(xdr, &args->seq_args, &hdr);
2102 encode_putfh(xdr, args->dir_fh, &hdr);
2103 encode_lookup(xdr, args->name, &hdr);
2104 encode_getfh(xdr, &hdr);
2105 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002106 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107}
2108
2109/*
2110 * Encode LOOKUP_ROOT request
2111 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002112static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2113 struct xdr_stream *xdr,
2114 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002117 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119
Chuck Lever9f06c712010-12-14 14:59:18 +00002120 encode_compound_hdr(xdr, req, &hdr);
2121 encode_sequence(xdr, &args->seq_args, &hdr);
2122 encode_putrootfh(xdr, &hdr);
2123 encode_getfh(xdr, &hdr);
2124 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002125 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126}
2127
2128/*
2129 * Encode REMOVE request
2130 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002131static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2132 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002135 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
Chuck Lever9f06c712010-12-14 14:59:18 +00002138 encode_compound_hdr(xdr, req, &hdr);
2139 encode_sequence(xdr, &args->seq_args, &hdr);
2140 encode_putfh(xdr, args->fh, &hdr);
2141 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002142 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143}
2144
2145/*
2146 * Encode RENAME request
2147 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002148static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2149 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002152 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154
Chuck Lever9f06c712010-12-14 14:59:18 +00002155 encode_compound_hdr(xdr, req, &hdr);
2156 encode_sequence(xdr, &args->seq_args, &hdr);
2157 encode_putfh(xdr, args->old_dir, &hdr);
2158 encode_savefh(xdr, &hdr);
2159 encode_putfh(xdr, args->new_dir, &hdr);
2160 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002161 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162}
2163
2164/*
2165 * Encode LINK request
2166 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002167static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2168 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002171 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173
Chuck Lever9f06c712010-12-14 14:59:18 +00002174 encode_compound_hdr(xdr, req, &hdr);
2175 encode_sequence(xdr, &args->seq_args, &hdr);
2176 encode_putfh(xdr, args->fh, &hdr);
2177 encode_savefh(xdr, &hdr);
2178 encode_putfh(xdr, args->dir_fh, &hdr);
2179 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002180 encode_restorefh(xdr, &hdr);
2181 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002182 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183}
2184
2185/*
2186 * Encode CREATE request
2187 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002188static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2189 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002192 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
Chuck Lever9f06c712010-12-14 14:59:18 +00002195 encode_compound_hdr(xdr, req, &hdr);
2196 encode_sequence(xdr, &args->seq_args, &hdr);
2197 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002198 encode_create(xdr, args, &hdr);
2199 encode_getfh(xdr, &hdr);
2200 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002201 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202}
2203
2204/*
2205 * Encode SYMLINK request
2206 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002207static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2208 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209{
Chuck Lever9f06c712010-12-14 14:59:18 +00002210 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211}
2212
2213/*
2214 * Encode GETATTR request
2215 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002216static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2217 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002220 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222
Chuck Lever9f06c712010-12-14 14:59:18 +00002223 encode_compound_hdr(xdr, req, &hdr);
2224 encode_sequence(xdr, &args->seq_args, &hdr);
2225 encode_putfh(xdr, args->fh, &hdr);
2226 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002227 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228}
2229
2230/*
2231 * Encode a CLOSE request
2232 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002233static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2234 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235{
Andy Adamson05d564f2008-12-23 16:06:15 -05002236 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002237 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002238 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239
Chuck Lever9f06c712010-12-14 14:59:18 +00002240 encode_compound_hdr(xdr, req, &hdr);
2241 encode_sequence(xdr, &args->seq_args, &hdr);
2242 encode_putfh(xdr, args->fh, &hdr);
2243 encode_close(xdr, args, &hdr);
2244 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002245 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246}
2247
2248/*
2249 * Encode an OPEN request
2250 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002251static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2252 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002255 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257
Chuck Lever9f06c712010-12-14 14:59:18 +00002258 encode_compound_hdr(xdr, req, &hdr);
2259 encode_sequence(xdr, &args->seq_args, &hdr);
2260 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002261 encode_open(xdr, args, &hdr);
2262 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002263 if (args->access)
2264 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002265 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002266 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267}
2268
2269/*
2270 * Encode an OPEN_CONFIRM request
2271 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002272static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2273 struct xdr_stream *xdr,
2274 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002277 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279
Chuck Lever9f06c712010-12-14 14:59:18 +00002280 encode_compound_hdr(xdr, req, &hdr);
2281 encode_putfh(xdr, args->fh, &hdr);
2282 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002283 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284}
2285
2286/*
2287 * Encode an OPEN request with no attributes.
2288 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002289static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2290 struct xdr_stream *xdr,
2291 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002294 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296
Chuck Lever9f06c712010-12-14 14:59:18 +00002297 encode_compound_hdr(xdr, req, &hdr);
2298 encode_sequence(xdr, &args->seq_args, &hdr);
2299 encode_putfh(xdr, args->fh, &hdr);
2300 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002301 if (args->access)
2302 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002303 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002304 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305}
2306
2307/*
2308 * Encode an OPEN_DOWNGRADE request
2309 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002310static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2311 struct xdr_stream *xdr,
2312 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002315 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
Chuck Lever9f06c712010-12-14 14:59:18 +00002318 encode_compound_hdr(xdr, req, &hdr);
2319 encode_sequence(xdr, &args->seq_args, &hdr);
2320 encode_putfh(xdr, args->fh, &hdr);
2321 encode_open_downgrade(xdr, args, &hdr);
2322 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002323 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324}
2325
2326/*
2327 * Encode a LOCK request
2328 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002329static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2330 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002333 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
Chuck Lever9f06c712010-12-14 14:59:18 +00002336 encode_compound_hdr(xdr, req, &hdr);
2337 encode_sequence(xdr, &args->seq_args, &hdr);
2338 encode_putfh(xdr, args->fh, &hdr);
2339 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002340 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341}
2342
2343/*
2344 * Encode a LOCKT request
2345 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002346static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2347 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002350 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352
Chuck Lever9f06c712010-12-14 14:59:18 +00002353 encode_compound_hdr(xdr, req, &hdr);
2354 encode_sequence(xdr, &args->seq_args, &hdr);
2355 encode_putfh(xdr, args->fh, &hdr);
2356 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002357 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358}
2359
2360/*
2361 * Encode a LOCKU request
2362 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002363static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2364 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002367 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369
Chuck Lever9f06c712010-12-14 14:59:18 +00002370 encode_compound_hdr(xdr, req, &hdr);
2371 encode_sequence(xdr, &args->seq_args, &hdr);
2372 encode_putfh(xdr, args->fh, &hdr);
2373 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002374 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375}
2376
Chuck Lever9f06c712010-12-14 14:59:18 +00002377static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2378 struct xdr_stream *xdr,
2379 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002380{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002381 struct compound_hdr hdr = {
2382 .minorversion = 0,
2383 };
2384
Chuck Lever9f06c712010-12-14 14:59:18 +00002385 encode_compound_hdr(xdr, req, &hdr);
2386 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002387 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002388}
2389
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390/*
2391 * Encode a READLINK request
2392 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002393static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2394 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002397 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399
Chuck Lever9f06c712010-12-14 14:59:18 +00002400 encode_compound_hdr(xdr, req, &hdr);
2401 encode_sequence(xdr, &args->seq_args, &hdr);
2402 encode_putfh(xdr, args->fh, &hdr);
2403 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002404
Benny Halevy28f56692009-04-01 09:22:09 -04002405 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002406 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002407 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408}
2409
2410/*
2411 * Encode a READDIR request
2412 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002413static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2414 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002417 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
Chuck Lever9f06c712010-12-14 14:59:18 +00002420 encode_compound_hdr(xdr, req, &hdr);
2421 encode_sequence(xdr, &args->seq_args, &hdr);
2422 encode_putfh(xdr, args->fh, &hdr);
2423 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002424
Benny Halevy28f56692009-04-01 09:22:09 -04002425 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002426 args->pgbase, args->count);
2427 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002428 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002429 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002430 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431}
2432
2433/*
2434 * Encode a READ request
2435 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002436static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002437 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002440 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442
Chuck Lever9f06c712010-12-14 14:59:18 +00002443 encode_compound_hdr(xdr, req, &hdr);
2444 encode_sequence(xdr, &args->seq_args, &hdr);
2445 encode_putfh(xdr, args->fh, &hdr);
2446 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447
Benny Halevy28f56692009-04-01 09:22:09 -04002448 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002450 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002451 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452}
2453
2454/*
2455 * Encode an SETATTR request
2456 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002457static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2458 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459{
Andy Adamson05d564f2008-12-23 16:06:15 -05002460 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002461 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002462 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463
Chuck Lever9f06c712010-12-14 14:59:18 +00002464 encode_compound_hdr(xdr, req, &hdr);
2465 encode_sequence(xdr, &args->seq_args, &hdr);
2466 encode_putfh(xdr, args->fh, &hdr);
2467 encode_setattr(xdr, args, args->server, &hdr);
2468 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002469 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470}
2471
2472/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002473 * Encode a GETACL request
2474 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002475static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2476 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002477{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002478 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002479 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002480 };
Benny Halevy28f56692009-04-01 09:22:09 -04002481 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002482
Chuck Lever9f06c712010-12-14 14:59:18 +00002483 encode_compound_hdr(xdr, req, &hdr);
2484 encode_sequence(xdr, &args->seq_args, &hdr);
2485 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002486 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002487 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002488
Benny Halevy28f56692009-04-01 09:22:09 -04002489 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002490 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002491
Andy Adamsond0179312008-12-23 16:06:17 -05002492 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002493}
2494
2495/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 * Encode a WRITE request
2497 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002498static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002499 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002502 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504
Chuck Lever9f06c712010-12-14 14:59:18 +00002505 encode_compound_hdr(xdr, req, &hdr);
2506 encode_sequence(xdr, &args->seq_args, &hdr);
2507 encode_putfh(xdr, args->fh, &hdr);
2508 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002509 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002510 if (args->bitmask)
2511 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002512 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513}
2514
2515/*
2516 * a COMMIT request
2517 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002518static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002519 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002522 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524
Chuck Lever9f06c712010-12-14 14:59:18 +00002525 encode_compound_hdr(xdr, req, &hdr);
2526 encode_sequence(xdr, &args->seq_args, &hdr);
2527 encode_putfh(xdr, args->fh, &hdr);
2528 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002529 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530}
2531
2532/*
2533 * FSINFO request
2534 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002535static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2536 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002539 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541
Chuck Lever9f06c712010-12-14 14:59:18 +00002542 encode_compound_hdr(xdr, req, &hdr);
2543 encode_sequence(xdr, &args->seq_args, &hdr);
2544 encode_putfh(xdr, args->fh, &hdr);
2545 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002546 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547}
2548
2549/*
2550 * a PATHCONF request
2551 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002552static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2553 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002556 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558
Chuck Lever9f06c712010-12-14 14:59:18 +00002559 encode_compound_hdr(xdr, req, &hdr);
2560 encode_sequence(xdr, &args->seq_args, &hdr);
2561 encode_putfh(xdr, args->fh, &hdr);
2562 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002563 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002564 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565}
2566
2567/*
2568 * a STATFS request
2569 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002570static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2571 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002574 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576
Chuck Lever9f06c712010-12-14 14:59:18 +00002577 encode_compound_hdr(xdr, req, &hdr);
2578 encode_sequence(xdr, &args->seq_args, &hdr);
2579 encode_putfh(xdr, args->fh, &hdr);
2580 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002581 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002582 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583}
2584
2585/*
2586 * GETATTR_BITMAP request
2587 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002588static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2589 struct xdr_stream *xdr,
2590 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002593 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
Chuck Lever9f06c712010-12-14 14:59:18 +00002596 encode_compound_hdr(xdr, req, &hdr);
2597 encode_sequence(xdr, &args->seq_args, &hdr);
2598 encode_putfh(xdr, args->fhandle, &hdr);
2599 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002600 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002601 FATTR4_WORD0_LINK_SUPPORT|
2602 FATTR4_WORD0_SYMLINK_SUPPORT|
2603 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002604 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605}
2606
2607/*
2608 * a RENEW request
2609 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002610static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2611 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002614 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 };
2616
Chuck Lever9f06c712010-12-14 14:59:18 +00002617 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002618 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002619 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620}
2621
2622/*
2623 * a SETCLIENTID request
2624 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002625static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2626 struct xdr_stream *xdr,
2627 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002630 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 };
2632
Chuck Lever9f06c712010-12-14 14:59:18 +00002633 encode_compound_hdr(xdr, req, &hdr);
2634 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002635 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636}
2637
2638/*
2639 * a SETCLIENTID_CONFIRM request
2640 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002641static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2642 struct xdr_stream *xdr,
2643 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002646 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648
Chuck Lever9f06c712010-12-14 14:59:18 +00002649 encode_compound_hdr(xdr, req, &hdr);
2650 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002651 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652}
2653
2654/*
2655 * DELEGRETURN request
2656 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002657static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2658 struct xdr_stream *xdr,
2659 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002662 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
Chuck Lever9f06c712010-12-14 14:59:18 +00002665 encode_compound_hdr(xdr, req, &hdr);
2666 encode_sequence(xdr, &args->seq_args, &hdr);
2667 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002668 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002669 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002670 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671}
2672
2673/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002674 * Encode FS_LOCATIONS request
2675 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002676static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2677 struct xdr_stream *xdr,
2678 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002679{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002680 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002681 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002682 };
Benny Halevy28f56692009-04-01 09:22:09 -04002683 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002684
Chuck Lever9f06c712010-12-14 14:59:18 +00002685 encode_compound_hdr(xdr, req, &hdr);
2686 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002687 if (args->migration) {
2688 encode_putfh(xdr, args->fh, &hdr);
2689 replen = hdr.replen;
2690 encode_fs_locations(xdr, args->bitmask, &hdr);
2691 if (args->renew)
2692 encode_renew(xdr, args->clientid, &hdr);
2693 } else {
2694 encode_putfh(xdr, args->dir_fh, &hdr);
2695 encode_lookup(xdr, args->name, &hdr);
2696 replen = hdr.replen;
2697 encode_fs_locations(xdr, args->bitmask, &hdr);
2698 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002699
Chuck Leverb03d7352013-10-17 14:12:50 -04002700 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002701 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002702 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002703 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002704}
2705
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002706/*
2707 * Encode SECINFO request
2708 */
2709static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2710 struct xdr_stream *xdr,
2711 struct nfs4_secinfo_arg *args)
2712{
2713 struct compound_hdr hdr = {
2714 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2715 };
2716
2717 encode_compound_hdr(xdr, req, &hdr);
2718 encode_sequence(xdr, &args->seq_args, &hdr);
2719 encode_putfh(xdr, args->dir_fh, &hdr);
2720 encode_secinfo(xdr, args->name, &hdr);
2721 encode_nops(&hdr);
2722}
2723
Chuck Lever44c99932013-10-17 14:13:30 -04002724/*
2725 * Encode FSID_PRESENT request
2726 */
2727static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2728 struct xdr_stream *xdr,
2729 struct nfs4_fsid_present_arg *args)
2730{
2731 struct compound_hdr hdr = {
2732 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2733 };
2734
2735 encode_compound_hdr(xdr, req, &hdr);
2736 encode_sequence(xdr, &args->seq_args, &hdr);
2737 encode_putfh(xdr, args->fh, &hdr);
2738 encode_getfh(xdr, &hdr);
2739 if (args->renew)
2740 encode_renew(xdr, args->clientid, &hdr);
2741 encode_nops(&hdr);
2742}
2743
Benny Halevy99fe60d2009-04-01 09:22:29 -04002744#if defined(CONFIG_NFS_V4_1)
2745/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002746 * BIND_CONN_TO_SESSION request
2747 */
2748static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2749 struct xdr_stream *xdr,
2750 struct nfs_client *clp)
2751{
2752 struct compound_hdr hdr = {
2753 .minorversion = clp->cl_mvops->minor_version,
2754 };
2755
2756 encode_compound_hdr(xdr, req, &hdr);
2757 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2758 encode_nops(&hdr);
2759}
2760
2761/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002762 * EXCHANGE_ID request
2763 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002764static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2765 struct xdr_stream *xdr,
2766 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002767{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002768 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002769 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002770 };
2771
Chuck Lever9f06c712010-12-14 14:59:18 +00002772 encode_compound_hdr(xdr, req, &hdr);
2773 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002774 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002775}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002776
2777/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002778 * a CREATE_SESSION request
2779 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002780static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2781 struct xdr_stream *xdr,
2782 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002783{
Andy Adamsonfc931582009-04-01 09:22:31 -04002784 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002785 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002786 };
2787
Chuck Lever9f06c712010-12-14 14:59:18 +00002788 encode_compound_hdr(xdr, req, &hdr);
2789 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002790 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002791}
2792
2793/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002794 * a DESTROY_SESSION request
2795 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002796static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2797 struct xdr_stream *xdr,
2798 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002799{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002800 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002801 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002802 };
2803
Chuck Lever9f06c712010-12-14 14:59:18 +00002804 encode_compound_hdr(xdr, req, &hdr);
2805 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002806 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002807}
2808
2809/*
Trond Myklebust66245532012-05-25 17:18:09 -04002810 * a DESTROY_CLIENTID request
2811 */
2812static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2813 struct xdr_stream *xdr,
2814 struct nfs_client *clp)
2815{
2816 struct compound_hdr hdr = {
2817 .minorversion = clp->cl_mvops->minor_version,
2818 };
2819
2820 encode_compound_hdr(xdr, req, &hdr);
2821 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2822 encode_nops(&hdr);
2823}
2824
2825/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002826 * a SEQUENCE request
2827 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002828static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2829 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002830{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002831 struct compound_hdr hdr = {
2832 .minorversion = nfs4_xdr_minorversion(args),
2833 };
2834
Chuck Lever9f06c712010-12-14 14:59:18 +00002835 encode_compound_hdr(xdr, req, &hdr);
2836 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002837 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002838}
2839
2840/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002841 * a GET_LEASE_TIME request
2842 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002843static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2844 struct xdr_stream *xdr,
2845 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002846{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002847 struct compound_hdr hdr = {
2848 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2849 };
Fred Isamandae100c2011-07-30 20:52:37 -04002850 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002851
Chuck Lever9f06c712010-12-14 14:59:18 +00002852 encode_compound_hdr(xdr, req, &hdr);
2853 encode_sequence(xdr, &args->la_seq_args, &hdr);
2854 encode_putrootfh(xdr, &hdr);
2855 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002856 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002857}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002858
2859/*
2860 * a RECLAIM_COMPLETE request
2861 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002862static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2863 struct xdr_stream *xdr,
2864 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002865{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002866 struct compound_hdr hdr = {
2867 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2868 };
2869
Chuck Lever9f06c712010-12-14 14:59:18 +00002870 encode_compound_hdr(xdr, req, &hdr);
2871 encode_sequence(xdr, &args->seq_args, &hdr);
2872 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002873 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002874}
2875
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002876/*
2877 * Encode GETDEVICEINFO request
2878 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002879static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2880 struct xdr_stream *xdr,
2881 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002882{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002883 struct compound_hdr hdr = {
2884 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2885 };
2886
Chuck Lever9f06c712010-12-14 14:59:18 +00002887 encode_compound_hdr(xdr, req, &hdr);
2888 encode_sequence(xdr, &args->seq_args, &hdr);
2889 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002890
2891 /* set up reply kvec. Subtract notification bitmap max size (2)
2892 * so that notification bitmap is put in xdr_buf tail */
2893 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2894 args->pdev->pages, args->pdev->pgbase,
2895 args->pdev->pglen);
2896
2897 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002898}
2899
2900/*
2901 * Encode LAYOUTGET request
2902 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002903static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2904 struct xdr_stream *xdr,
2905 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002906{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002907 struct compound_hdr hdr = {
2908 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2909 };
2910
Chuck Lever9f06c712010-12-14 14:59:18 +00002911 encode_compound_hdr(xdr, req, &hdr);
2912 encode_sequence(xdr, &args->seq_args, &hdr);
2913 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2914 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002915
2916 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2917 args->layout.pages, 0, args->layout.pglen);
2918
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002919 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002920}
Andy Adamson863a3c62011-03-23 13:27:54 +00002921
2922/*
2923 * Encode LAYOUTCOMMIT request
2924 */
Benny Halevycbe82602011-05-22 19:52:37 +03002925static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2926 struct xdr_stream *xdr,
2927 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002928{
Benny Halevyac7db722011-05-22 19:53:48 +03002929 struct nfs4_layoutcommit_data *data =
2930 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002931 struct compound_hdr hdr = {
2932 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2933 };
2934
2935 encode_compound_hdr(xdr, req, &hdr);
2936 encode_sequence(xdr, &args->seq_args, &hdr);
2937 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002938 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002939 encode_getfattr(xdr, args->bitmask, &hdr);
2940 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002941}
2942
2943/*
2944 * Encode LAYOUTRETURN request
2945 */
2946static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2947 struct xdr_stream *xdr,
2948 struct nfs4_layoutreturn_args *args)
2949{
2950 struct compound_hdr hdr = {
2951 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2952 };
2953
2954 encode_compound_hdr(xdr, req, &hdr);
2955 encode_sequence(xdr, &args->seq_args, &hdr);
2956 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2957 encode_layoutreturn(xdr, args, &hdr);
2958 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002959}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002960
2961/*
2962 * Encode SECINFO_NO_NAME request
2963 */
2964static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2965 struct xdr_stream *xdr,
2966 struct nfs41_secinfo_no_name_args *args)
2967{
2968 struct compound_hdr hdr = {
2969 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2970 };
2971
2972 encode_compound_hdr(xdr, req, &hdr);
2973 encode_sequence(xdr, &args->seq_args, &hdr);
2974 encode_putrootfh(xdr, &hdr);
2975 encode_secinfo_no_name(xdr, args, &hdr);
2976 encode_nops(&hdr);
2977 return 0;
2978}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002979
2980/*
2981 * Encode TEST_STATEID request
2982 */
2983static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2984 struct xdr_stream *xdr,
2985 struct nfs41_test_stateid_args *args)
2986{
2987 struct compound_hdr hdr = {
2988 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2989 };
2990
2991 encode_compound_hdr(xdr, req, &hdr);
2992 encode_sequence(xdr, &args->seq_args, &hdr);
2993 encode_test_stateid(xdr, args, &hdr);
2994 encode_nops(&hdr);
2995}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002996
2997/*
2998 * Encode FREE_STATEID request
2999 */
3000static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3001 struct xdr_stream *xdr,
3002 struct nfs41_free_stateid_args *args)
3003{
3004 struct compound_hdr hdr = {
3005 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3006 };
3007
3008 encode_compound_hdr(xdr, req, &hdr);
3009 encode_sequence(xdr, &args->seq_args, &hdr);
3010 encode_free_stateid(xdr, args, &hdr);
3011 encode_nops(&hdr);
3012}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003013#endif /* CONFIG_NFS_V4_1 */
3014
Benny Halevy686841b2009-08-14 17:19:48 +03003015static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3016{
3017 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3018 "Remaining buffer length is %tu words.\n",
3019 func, xdr->end - xdr->p);
3020}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021
Trond Myklebust683b57b2006-06-09 09:34:22 -04003022static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023{
Al Viro8687b632006-10-19 23:28:48 -07003024 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025
Benny Halevyc0eae662009-08-14 17:20:14 +03003026 p = xdr_inline_decode(xdr, 4);
3027 if (unlikely(!p))
3028 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003029 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003030 p = xdr_inline_decode(xdr, *len);
3031 if (unlikely(!p))
3032 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 *string = (char *)p;
3034 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003035out_overflow:
3036 print_overflow_msg(__func__, xdr);
3037 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038}
3039
3040static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3041{
Al Viro8687b632006-10-19 23:28:48 -07003042 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043
Benny Halevyc0eae662009-08-14 17:20:14 +03003044 p = xdr_inline_decode(xdr, 8);
3045 if (unlikely(!p))
3046 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003047 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003048 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003049
Benny Halevyc0eae662009-08-14 17:20:14 +03003050 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3051 if (unlikely(!p))
3052 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 hdr->tag = (char *)p;
3054 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003055 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003056 if (unlikely(hdr->nops < 1))
3057 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003059out_overflow:
3060 print_overflow_msg(__func__, xdr);
3061 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062}
3063
Trond Myklebustc7848f62013-12-04 17:39:23 -05003064static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3065 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066{
Al Viro8687b632006-10-19 23:28:48 -07003067 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 uint32_t opnum;
3069 int32_t nfserr;
3070
Benny Halevyc0eae662009-08-14 17:20:14 +03003071 p = xdr_inline_decode(xdr, 8);
3072 if (unlikely(!p))
3073 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003074 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003075 if (unlikely(opnum != expected))
3076 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003077 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003078 if (nfserr == NFS_OK)
3079 *nfs_retval = 0;
3080 else
3081 *nfs_retval = nfs4_stat_to_errno(nfserr);
3082 return true;
3083out_bad_operation:
3084 dprintk("nfs: Server returned operation"
3085 " %d but we issued a request for %d\n",
3086 opnum, expected);
3087 *nfs_retval = -EREMOTEIO;
3088 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003089out_overflow:
3090 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003091 *nfs_retval = -EIO;
3092 return false;
3093}
3094
3095static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3096{
3097 int retval;
3098
3099 __decode_op_hdr(xdr, expected, &retval);
3100 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101}
3102
3103/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003104static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105{
Al Viro8687b632006-10-19 23:28:48 -07003106 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003107 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 char *str;
3109
Benny Halevyc0eae662009-08-14 17:20:14 +03003110 p = xdr_inline_decode(xdr, 12);
3111 if (likely(p))
3112 return decode_opaque_inline(xdr, &strlen, &str);
3113 print_overflow_msg(__func__, xdr);
3114 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115}
3116
3117static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3118{
Al Viro8687b632006-10-19 23:28:48 -07003119 uint32_t bmlen;
3120 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121
Benny Halevyc0eae662009-08-14 17:20:14 +03003122 p = xdr_inline_decode(xdr, 4);
3123 if (unlikely(!p))
3124 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003125 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126
Fred Isamandae100c2011-07-30 20:52:37 -04003127 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003128 p = xdr_inline_decode(xdr, (bmlen << 2));
3129 if (unlikely(!p))
3130 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003132 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003133 if (bmlen > 1) {
3134 bitmap[1] = be32_to_cpup(p++);
3135 if (bmlen > 2)
3136 bitmap[2] = be32_to_cpup(p);
3137 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 }
3139 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003140out_overflow:
3141 print_overflow_msg(__func__, xdr);
3142 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143}
3144
Trond Myklebust256e48b2012-06-21 11:18:13 -04003145static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146{
Al Viro8687b632006-10-19 23:28:48 -07003147 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
Benny Halevyc0eae662009-08-14 17:20:14 +03003149 p = xdr_inline_decode(xdr, 4);
3150 if (unlikely(!p))
3151 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003152 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003153 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003155out_overflow:
3156 print_overflow_msg(__func__, xdr);
3157 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158}
3159
3160static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3161{
3162 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003163 int ret;
3164 ret = decode_attr_bitmap(xdr, bitmask);
3165 if (unlikely(ret < 0))
3166 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3168 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003169 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3170 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3171 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 return 0;
3173}
3174
3175static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3176{
Al Viro8687b632006-10-19 23:28:48 -07003177 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003178 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179
3180 *type = 0;
3181 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3182 return -EIO;
3183 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003184 p = xdr_inline_decode(xdr, 4);
3185 if (unlikely(!p))
3186 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003187 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003189 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 return -EIO;
3191 }
3192 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003193 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003195 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003196 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003197out_overflow:
3198 print_overflow_msg(__func__, xdr);
3199 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200}
3201
Chuck Lever264e6352012-03-01 17:02:05 -05003202static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3203 uint32_t *bitmap, uint32_t *type)
3204{
3205 __be32 *p;
3206
3207 *type = 0;
3208 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3209 return -EIO;
3210 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3211 p = xdr_inline_decode(xdr, 4);
3212 if (unlikely(!p))
3213 goto out_overflow;
3214 *type = be32_to_cpup(p);
3215 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3216 }
3217 dprintk("%s: expire type=0x%x\n", __func__, *type);
3218 return 0;
3219out_overflow:
3220 print_overflow_msg(__func__, xdr);
3221 return -EIO;
3222}
3223
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3225{
Al Viro8687b632006-10-19 23:28:48 -07003226 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003227 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228
3229 *change = 0;
3230 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3231 return -EIO;
3232 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003233 p = xdr_inline_decode(xdr, 8);
3234 if (unlikely(!p))
3235 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003236 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003238 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003240 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003242 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003243out_overflow:
3244 print_overflow_msg(__func__, xdr);
3245 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246}
3247
3248static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3249{
Al Viro8687b632006-10-19 23:28:48 -07003250 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003251 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252
3253 *size = 0;
3254 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3255 return -EIO;
3256 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003257 p = xdr_inline_decode(xdr, 8);
3258 if (unlikely(!p))
3259 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003260 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003262 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003264 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003265 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003266out_overflow:
3267 print_overflow_msg(__func__, xdr);
3268 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269}
3270
3271static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3272{
Al Viro8687b632006-10-19 23:28:48 -07003273 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274
3275 *res = 0;
3276 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3277 return -EIO;
3278 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003279 p = xdr_inline_decode(xdr, 4);
3280 if (unlikely(!p))
3281 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003282 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3284 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003285 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003287out_overflow:
3288 print_overflow_msg(__func__, xdr);
3289 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290}
3291
3292static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3293{
Al Viro8687b632006-10-19 23:28:48 -07003294 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295
3296 *res = 0;
3297 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3298 return -EIO;
3299 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003300 p = xdr_inline_decode(xdr, 4);
3301 if (unlikely(!p))
3302 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003303 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3305 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003306 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003308out_overflow:
3309 print_overflow_msg(__func__, xdr);
3310 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311}
3312
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003313static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314{
Al Viro8687b632006-10-19 23:28:48 -07003315 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003316 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317
3318 fsid->major = 0;
3319 fsid->minor = 0;
3320 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3321 return -EIO;
3322 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003323 p = xdr_inline_decode(xdr, 16);
3324 if (unlikely(!p))
3325 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003326 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003327 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003329 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003331 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 (unsigned long long)fsid->major,
3333 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003334 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003335out_overflow:
3336 print_overflow_msg(__func__, xdr);
3337 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338}
3339
3340static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3341{
Al Viro8687b632006-10-19 23:28:48 -07003342 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343
3344 *res = 60;
3345 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3346 return -EIO;
3347 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003348 p = xdr_inline_decode(xdr, 4);
3349 if (unlikely(!p))
3350 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003351 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3353 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003354 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003356out_overflow:
3357 print_overflow_msg(__func__, xdr);
3358 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359}
3360
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003361static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003362{
3363 __be32 *p;
3364
3365 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3366 return -EIO;
3367 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3368 p = xdr_inline_decode(xdr, 4);
3369 if (unlikely(!p))
3370 goto out_overflow;
3371 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003372 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003373 }
3374 return 0;
3375out_overflow:
3376 print_overflow_msg(__func__, xdr);
3377 return -EIO;
3378}
3379
3380static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3381{
3382 __be32 *p;
3383 int len;
3384
Trond Myklebust7ad07352010-10-23 15:34:20 -04003385 if (fh != NULL)
3386 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003387
3388 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3389 return -EIO;
3390 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3391 p = xdr_inline_decode(xdr, 4);
3392 if (unlikely(!p))
3393 goto out_overflow;
3394 len = be32_to_cpup(p);
3395 if (len > NFS4_FHSIZE)
3396 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003397 p = xdr_inline_decode(xdr, len);
3398 if (unlikely(!p))
3399 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003400 if (fh != NULL) {
3401 memcpy(fh->data, p, len);
3402 fh->size = len;
3403 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003404 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3405 }
3406 return 0;
3407out_overflow:
3408 print_overflow_msg(__func__, xdr);
3409 return -EIO;
3410}
3411
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3413{
Al Viro8687b632006-10-19 23:28:48 -07003414 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003416 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3418 return -EIO;
3419 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003420 p = xdr_inline_decode(xdr, 4);
3421 if (unlikely(!p))
3422 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003423 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3425 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003426 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003428out_overflow:
3429 print_overflow_msg(__func__, xdr);
3430 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431}
3432
3433static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3434{
Al Viro8687b632006-10-19 23:28:48 -07003435 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003436 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437
3438 *fileid = 0;
3439 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3440 return -EIO;
3441 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003442 p = xdr_inline_decode(xdr, 8);
3443 if (unlikely(!p))
3444 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003445 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003447 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003449 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003450 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003451out_overflow:
3452 print_overflow_msg(__func__, xdr);
3453 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454}
3455
Manoj Naik99baf622006-06-09 09:34:24 -04003456static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3457{
Al Viro8687b632006-10-19 23:28:48 -07003458 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003459 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003460
3461 *fileid = 0;
3462 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3463 return -EIO;
3464 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003465 p = xdr_inline_decode(xdr, 8);
3466 if (unlikely(!p))
3467 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003468 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003469 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003470 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003471 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003472 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003473 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003474out_overflow:
3475 print_overflow_msg(__func__, xdr);
3476 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003477}
3478
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3480{
Al Viro8687b632006-10-19 23:28:48 -07003481 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 int status = 0;
3483
3484 *res = 0;
3485 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3486 return -EIO;
3487 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003488 p = xdr_inline_decode(xdr, 8);
3489 if (unlikely(!p))
3490 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003491 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3493 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003494 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003496out_overflow:
3497 print_overflow_msg(__func__, xdr);
3498 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499}
3500
3501static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3502{
Al Viro8687b632006-10-19 23:28:48 -07003503 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 int status = 0;
3505
3506 *res = 0;
3507 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3508 return -EIO;
3509 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003510 p = xdr_inline_decode(xdr, 8);
3511 if (unlikely(!p))
3512 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003513 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3515 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003516 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003518out_overflow:
3519 print_overflow_msg(__func__, xdr);
3520 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521}
3522
3523static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3524{
Al Viro8687b632006-10-19 23:28:48 -07003525 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 int status = 0;
3527
3528 *res = 0;
3529 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3530 return -EIO;
3531 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003532 p = xdr_inline_decode(xdr, 8);
3533 if (unlikely(!p))
3534 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003535 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3537 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003538 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003540out_overflow:
3541 print_overflow_msg(__func__, xdr);
3542 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543}
3544
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003545static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3546{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003547 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003548 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003549 int status = 0;
3550
Benny Halevyc0eae662009-08-14 17:20:14 +03003551 p = xdr_inline_decode(xdr, 4);
3552 if (unlikely(!p))
3553 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003554 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003555 if (n == 0)
3556 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003557 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003558 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3559 dprintk("cannot parse %d components in path\n", n);
3560 goto out_eio;
3561 }
3562 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003563 struct nfs4_string *component = &path->components[path->ncomponents];
3564 status = decode_opaque_inline(xdr, &component->len, &component->data);
3565 if (unlikely(status != 0))
3566 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003567 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003568 pr_cont("%s%.*s ",
3569 (path->ncomponents != n ? "/ " : ""),
3570 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003571 }
3572out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003573 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003574root_path:
3575/* a root pathname is sent as a zero component4 */
3576 path->ncomponents = 1;
3577 path->components[0].len=0;
3578 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003579 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003580 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003581out_eio:
3582 dprintk(" status %d", status);
3583 status = -EIO;
3584 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003585out_overflow:
3586 print_overflow_msg(__func__, xdr);
3587 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003588}
3589
3590static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003591{
3592 int n;
Al Viro8687b632006-10-19 23:28:48 -07003593 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003594 int status = -EIO;
3595
3596 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3597 goto out;
3598 status = 0;
3599 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3600 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003601 status = -EIO;
3602 /* Ignore borken servers that return unrequested attrs */
3603 if (unlikely(res == NULL))
3604 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003605 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003606 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003607 if (unlikely(status != 0))
3608 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003609 p = xdr_inline_decode(xdr, 4);
3610 if (unlikely(!p))
3611 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003612 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003613 if (n <= 0)
3614 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003615 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003616 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003617 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003618
Trond Myklebust809b4262013-03-27 11:54:45 -04003619 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3620 break;
3621 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003622 p = xdr_inline_decode(xdr, 4);
3623 if (unlikely(!p))
3624 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003625 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003626
Chuck Lever02a29762012-03-01 17:00:31 -05003627 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003628 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3629 struct nfs4_string *server;
3630
3631 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003632 unsigned int i;
3633 dprintk("%s: using first %u of %u servers "
3634 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003635 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003636 NFS4_FS_LOCATION_MAXSERVERS,
3637 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003638 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003639 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003640 char *data;
3641 status = decode_opaque_inline(xdr, &len, &data);
3642 if (unlikely(status != 0))
3643 goto out_eio;
3644 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003645 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003646 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003647 server = &loc->servers[loc->nservers];
3648 status = decode_opaque_inline(xdr, &server->len, &server->data);
3649 if (unlikely(status != 0))
3650 goto out_eio;
3651 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003652 }
3653 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003654 if (unlikely(status != 0))
3655 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003656 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003657 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003658 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003659out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003660 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003661 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003662out_overflow:
3663 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003664out_eio:
3665 status = -EIO;
3666 goto out;
3667}
3668
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3670{
Al Viro8687b632006-10-19 23:28:48 -07003671 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 int status = 0;
3673
3674 *res = 0;
3675 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3676 return -EIO;
3677 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003678 p = xdr_inline_decode(xdr, 8);
3679 if (unlikely(!p))
3680 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003681 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3683 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003684 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003686out_overflow:
3687 print_overflow_msg(__func__, xdr);
3688 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689}
3690
3691static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3692{
Al Viro8687b632006-10-19 23:28:48 -07003693 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694 int status = 0;
3695
3696 *maxlink = 1;
3697 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3698 return -EIO;
3699 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003700 p = xdr_inline_decode(xdr, 4);
3701 if (unlikely(!p))
3702 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003703 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3705 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003706 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003708out_overflow:
3709 print_overflow_msg(__func__, xdr);
3710 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711}
3712
3713static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3714{
Al Viro8687b632006-10-19 23:28:48 -07003715 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 int status = 0;
3717
3718 *maxname = 1024;
3719 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3720 return -EIO;
3721 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003722 p = xdr_inline_decode(xdr, 4);
3723 if (unlikely(!p))
3724 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003725 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3727 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003728 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003730out_overflow:
3731 print_overflow_msg(__func__, xdr);
3732 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733}
3734
3735static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3736{
Al Viro8687b632006-10-19 23:28:48 -07003737 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 int status = 0;
3739
3740 *res = 1024;
3741 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3742 return -EIO;
3743 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3744 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003745 p = xdr_inline_decode(xdr, 8);
3746 if (unlikely(!p))
3747 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003748 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 if (maxread > 0x7FFFFFFF)
3750 maxread = 0x7FFFFFFF;
3751 *res = (uint32_t)maxread;
3752 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3753 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003754 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003756out_overflow:
3757 print_overflow_msg(__func__, xdr);
3758 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759}
3760
3761static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3762{
Al Viro8687b632006-10-19 23:28:48 -07003763 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764 int status = 0;
3765
3766 *res = 1024;
3767 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3768 return -EIO;
3769 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3770 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003771 p = xdr_inline_decode(xdr, 8);
3772 if (unlikely(!p))
3773 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003774 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 if (maxwrite > 0x7FFFFFFF)
3776 maxwrite = 0x7FFFFFFF;
3777 *res = (uint32_t)maxwrite;
3778 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3779 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003780 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003782out_overflow:
3783 print_overflow_msg(__func__, xdr);
3784 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785}
3786
Trond Myklebustbca79472009-03-11 14:10:26 -04003787static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788{
Trond Myklebustbca79472009-03-11 14:10:26 -04003789 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003790 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003791 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792
3793 *mode = 0;
3794 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3795 return -EIO;
3796 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003797 p = xdr_inline_decode(xdr, 4);
3798 if (unlikely(!p))
3799 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003800 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003801 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003803 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003805 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003806 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003807out_overflow:
3808 print_overflow_msg(__func__, xdr);
3809 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810}
3811
3812static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3813{
Al Viro8687b632006-10-19 23:28:48 -07003814 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003815 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816
3817 *nlink = 1;
3818 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3819 return -EIO;
3820 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003821 p = xdr_inline_decode(xdr, 4);
3822 if (unlikely(!p))
3823 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003824 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003826 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003828 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003829 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003830out_overflow:
3831 print_overflow_msg(__func__, xdr);
3832 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833}
3834
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003835static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003836 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003837 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838{
Al Viro8687b632006-10-19 23:28:48 -07003839 uint32_t len;
3840 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003841 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842
Eric W. Biedermane5782072013-02-01 14:22:02 -08003843 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3845 return -EIO;
3846 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003847 p = xdr_inline_decode(xdr, 4);
3848 if (unlikely(!p))
3849 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003850 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003851 p = xdr_inline_decode(xdr, len);
3852 if (unlikely(!p))
3853 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003854 if (owner_name != NULL) {
3855 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3856 if (owner_name->data != NULL) {
3857 owner_name->len = len;
3858 ret = NFS_ATTR_FATTR_OWNER_NAME;
3859 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003860 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003861 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003862 ret = NFS_ATTR_FATTR_OWNER;
3863 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003865 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003867 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003868 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3870 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003871 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003872 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003873out_overflow:
3874 print_overflow_msg(__func__, xdr);
3875 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876}
3877
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003878static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003879 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003880 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881{
Al Viro8687b632006-10-19 23:28:48 -07003882 uint32_t len;
3883 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003884 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885
Eric W. Biedermane5782072013-02-01 14:22:02 -08003886 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3888 return -EIO;
3889 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003890 p = xdr_inline_decode(xdr, 4);
3891 if (unlikely(!p))
3892 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003893 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003894 p = xdr_inline_decode(xdr, len);
3895 if (unlikely(!p))
3896 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003897 if (group_name != NULL) {
3898 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3899 if (group_name->data != NULL) {
3900 group_name->len = len;
3901 ret = NFS_ATTR_FATTR_GROUP_NAME;
3902 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003903 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003904 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003905 ret = NFS_ATTR_FATTR_GROUP;
3906 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003908 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003910 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003911 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3913 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003914 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003915 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003916out_overflow:
3917 print_overflow_msg(__func__, xdr);
3918 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919}
3920
3921static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3922{
Al Viro8687b632006-10-19 23:28:48 -07003923 uint32_t major = 0, minor = 0;
3924 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003925 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926
3927 *rdev = MKDEV(0,0);
3928 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3929 return -EIO;
3930 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3931 dev_t tmp;
3932
Benny Halevyc0eae662009-08-14 17:20:14 +03003933 p = xdr_inline_decode(xdr, 8);
3934 if (unlikely(!p))
3935 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003936 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003937 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 tmp = MKDEV(major, minor);
3939 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3940 *rdev = tmp;
3941 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003942 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003944 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003945 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003946out_overflow:
3947 print_overflow_msg(__func__, xdr);
3948 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949}
3950
3951static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3952{
Al Viro8687b632006-10-19 23:28:48 -07003953 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 int status = 0;
3955
3956 *res = 0;
3957 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3958 return -EIO;
3959 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003960 p = xdr_inline_decode(xdr, 8);
3961 if (unlikely(!p))
3962 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003963 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3965 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003966 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003968out_overflow:
3969 print_overflow_msg(__func__, xdr);
3970 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971}
3972
3973static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3974{
Al Viro8687b632006-10-19 23:28:48 -07003975 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 int status = 0;
3977
3978 *res = 0;
3979 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3980 return -EIO;
3981 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003982 p = xdr_inline_decode(xdr, 8);
3983 if (unlikely(!p))
3984 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003985 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3987 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003988 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003990out_overflow:
3991 print_overflow_msg(__func__, xdr);
3992 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993}
3994
3995static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3996{
Al Viro8687b632006-10-19 23:28:48 -07003997 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 int status = 0;
3999
4000 *res = 0;
4001 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4002 return -EIO;
4003 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004004 p = xdr_inline_decode(xdr, 8);
4005 if (unlikely(!p))
4006 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004007 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4009 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004010 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004012out_overflow:
4013 print_overflow_msg(__func__, xdr);
4014 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015}
4016
4017static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4018{
Al Viro8687b632006-10-19 23:28:48 -07004019 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004020 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021
4022 *used = 0;
4023 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4024 return -EIO;
4025 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004026 p = xdr_inline_decode(xdr, 8);
4027 if (unlikely(!p))
4028 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004029 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004031 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004033 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004035 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004036out_overflow:
4037 print_overflow_msg(__func__, xdr);
4038 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039}
4040
4041static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4042{
Al Viro8687b632006-10-19 23:28:48 -07004043 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044 uint64_t sec;
4045 uint32_t nsec;
4046
Benny Halevyc0eae662009-08-14 17:20:14 +03004047 p = xdr_inline_decode(xdr, 12);
4048 if (unlikely(!p))
4049 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004050 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004051 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 time->tv_sec = (time_t)sec;
4053 time->tv_nsec = (long)nsec;
4054 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004055out_overflow:
4056 print_overflow_msg(__func__, xdr);
4057 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058}
4059
4060static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4061{
4062 int status = 0;
4063
4064 time->tv_sec = 0;
4065 time->tv_nsec = 0;
4066 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4067 return -EIO;
4068 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4069 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004070 if (status == 0)
4071 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4073 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004074 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 return status;
4076}
4077
4078static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4079{
4080 int status = 0;
4081
4082 time->tv_sec = 0;
4083 time->tv_nsec = 0;
4084 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4085 return -EIO;
4086 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4087 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004088 if (status == 0)
4089 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4091 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004092 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093 return status;
4094}
4095
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004096static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4097 struct timespec *time)
4098{
4099 int status = 0;
4100
4101 time->tv_sec = 0;
4102 time->tv_nsec = 0;
4103 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4104 return -EIO;
4105 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4106 status = decode_attr_time(xdr, time);
4107 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4108 }
4109 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4110 (long)time->tv_nsec);
4111 return status;
4112}
4113
David Quigleyaa9c2662013-05-22 12:50:44 -04004114static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4115 struct nfs4_label *label)
4116{
4117 uint32_t pi = 0;
4118 uint32_t lfs = 0;
4119 __u32 len;
4120 __be32 *p;
4121 int status = 0;
4122
4123 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4124 return -EIO;
4125 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4126 p = xdr_inline_decode(xdr, 4);
4127 if (unlikely(!p))
4128 goto out_overflow;
4129 lfs = be32_to_cpup(p++);
4130 p = xdr_inline_decode(xdr, 4);
4131 if (unlikely(!p))
4132 goto out_overflow;
4133 pi = be32_to_cpup(p++);
4134 p = xdr_inline_decode(xdr, 4);
4135 if (unlikely(!p))
4136 goto out_overflow;
4137 len = be32_to_cpup(p++);
4138 p = xdr_inline_decode(xdr, len);
4139 if (unlikely(!p))
4140 goto out_overflow;
4141 if (len < NFS4_MAXLABELLEN) {
4142 if (label) {
4143 memcpy(label->label, p, len);
4144 label->len = len;
4145 label->pi = pi;
4146 label->lfs = lfs;
4147 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4148 }
4149 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4150 } else
4151 printk(KERN_WARNING "%s: label too long (%u)!\n",
4152 __func__, len);
4153 }
4154 if (label && label->label)
4155 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4156 (char *)label->label, label->len, label->pi, label->lfs);
4157 return status;
4158
4159out_overflow:
4160 print_overflow_msg(__func__, xdr);
4161 return -EIO;
4162}
4163
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4165{
4166 int status = 0;
4167
4168 time->tv_sec = 0;
4169 time->tv_nsec = 0;
4170 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4171 return -EIO;
4172 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4173 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004174 if (status == 0)
4175 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4177 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004178 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179 return status;
4180}
4181
Trond Myklebust256e48b2012-06-21 11:18:13 -04004182static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183{
4184 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004185 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186
4187 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004188 dprintk("%s: server returned incorrect attribute length: "
4189 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004190 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191 attrwords << 2,
4192 (attrwords < nwords) ? '<' : '>',
4193 nwords << 2);
4194 return -EIO;
4195 }
4196 return 0;
4197}
4198
4199static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4200{
Al Viro8687b632006-10-19 23:28:48 -07004201 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202
Benny Halevyc0eae662009-08-14 17:20:14 +03004203 p = xdr_inline_decode(xdr, 20);
4204 if (unlikely(!p))
4205 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004206 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004207 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004208 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004210out_overflow:
4211 print_overflow_msg(__func__, xdr);
4212 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213}
4214
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004215static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216{
Al Viro8687b632006-10-19 23:28:48 -07004217 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218 uint32_t supp, acc;
4219 int status;
4220
4221 status = decode_op_hdr(xdr, OP_ACCESS);
4222 if (status)
4223 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004224 p = xdr_inline_decode(xdr, 8);
4225 if (unlikely(!p))
4226 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004227 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004228 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004229 *supported = supp;
4230 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004232out_overflow:
4233 print_overflow_msg(__func__, xdr);
4234 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235}
4236
Benny Halevy07d30432009-08-14 17:19:52 +03004237static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238{
Al Viro8687b632006-10-19 23:28:48 -07004239 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004240
4241 p = xdr_inline_decode(xdr, len);
4242 if (likely(p)) {
4243 memcpy(buf, p, len);
4244 return 0;
4245 }
4246 print_overflow_msg(__func__, xdr);
4247 return -EIO;
4248}
4249
4250static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4251{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004252 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253}
4254
4255static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4256{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 int status;
4258
4259 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004260 if (status != -EIO)
4261 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004262 if (!status)
4263 status = decode_stateid(xdr, &res->stateid);
4264 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265}
4266
Benny Halevydb942bb2009-08-14 17:19:56 +03004267static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4268{
Chuck Levercd937102012-03-02 17:14:31 -05004269 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270}
4271
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004272static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4273{
4274 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4275}
4276
Fred Isaman0b7c0152012-04-20 14:47:39 -04004277static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279 int status;
4280
4281 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004282 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004283 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004284 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285}
4286
4287static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4288{
Al Viro8687b632006-10-19 23:28:48 -07004289 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004290 uint32_t bmlen;
4291 int status;
4292
4293 status = decode_op_hdr(xdr, OP_CREATE);
4294 if (status)
4295 return status;
4296 if ((status = decode_change_info(xdr, cinfo)))
4297 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004298 p = xdr_inline_decode(xdr, 4);
4299 if (unlikely(!p))
4300 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004301 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004302 p = xdr_inline_decode(xdr, bmlen << 2);
4303 if (likely(p))
4304 return 0;
4305out_overflow:
4306 print_overflow_msg(__func__, xdr);
4307 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308}
4309
4310static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4311{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004312 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004313 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314 int status;
4315
4316 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4317 goto xdr_error;
4318 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4319 goto xdr_error;
4320 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4321 goto xdr_error;
4322 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4323 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004324 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4325 &res->fh_expire_type)) != 0)
4326 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4328 goto xdr_error;
4329 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4330 goto xdr_error;
4331 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4332 goto xdr_error;
4333 status = verify_attr_len(xdr, savep, attrlen);
4334xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004335 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 return status;
4337}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004338
Linus Torvalds1da177e2005-04-16 15:20:36 -07004339static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4340{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004341 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004342 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004344
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4346 goto xdr_error;
4347 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4348 goto xdr_error;
4349 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4350 goto xdr_error;
4351
4352 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4353 goto xdr_error;
4354 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4355 goto xdr_error;
4356 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4357 goto xdr_error;
4358 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4359 goto xdr_error;
4360 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4361 goto xdr_error;
4362 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4363 goto xdr_error;
4364
4365 status = verify_attr_len(xdr, savep, attrlen);
4366xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004367 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368 return status;
4369}
4370
4371static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4372{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004373 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004374 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004375 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004376
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4378 goto xdr_error;
4379 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4380 goto xdr_error;
4381 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4382 goto xdr_error;
4383
4384 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4385 goto xdr_error;
4386 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4387 goto xdr_error;
4388
4389 status = verify_attr_len(xdr, savep, attrlen);
4390xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004391 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392 return status;
4393}
4394
Andy Adamson88034c32012-05-23 05:02:34 -04004395static int decode_threshold_hint(struct xdr_stream *xdr,
4396 uint32_t *bitmap,
4397 uint64_t *res,
4398 uint32_t hint_bit)
4399{
4400 __be32 *p;
4401
4402 *res = 0;
4403 if (likely(bitmap[0] & hint_bit)) {
4404 p = xdr_inline_decode(xdr, 8);
4405 if (unlikely(!p))
4406 goto out_overflow;
4407 xdr_decode_hyper(p, res);
4408 }
4409 return 0;
4410out_overflow:
4411 print_overflow_msg(__func__, xdr);
4412 return -EIO;
4413}
4414
4415static int decode_first_threshold_item4(struct xdr_stream *xdr,
4416 struct nfs4_threshold *res)
4417{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004418 __be32 *p;
4419 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004420 uint32_t bitmap[3] = {0,}, attrlen;
4421 int status;
4422
4423 /* layout type */
4424 p = xdr_inline_decode(xdr, 4);
4425 if (unlikely(!p)) {
4426 print_overflow_msg(__func__, xdr);
4427 return -EIO;
4428 }
4429 res->l_type = be32_to_cpup(p);
4430
4431 /* thi_hintset bitmap */
4432 status = decode_attr_bitmap(xdr, bitmap);
4433 if (status < 0)
4434 goto xdr_error;
4435
4436 /* thi_hintlist length */
4437 status = decode_attr_length(xdr, &attrlen, &savep);
4438 if (status < 0)
4439 goto xdr_error;
4440 /* thi_hintlist */
4441 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4442 if (status < 0)
4443 goto xdr_error;
4444 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4445 if (status < 0)
4446 goto xdr_error;
4447 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4448 THRESHOLD_RD_IO);
4449 if (status < 0)
4450 goto xdr_error;
4451 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4452 THRESHOLD_WR_IO);
4453 if (status < 0)
4454 goto xdr_error;
4455
4456 status = verify_attr_len(xdr, savep, attrlen);
4457 res->bm = bitmap[0];
4458
4459 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4460 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4461 res->wr_io_sz);
4462xdr_error:
4463 dprintk("%s ret=%d!\n", __func__, status);
4464 return status;
4465}
4466
4467/*
4468 * Thresholds on pNFS direct I/O vrs MDS I/O
4469 */
4470static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4471 uint32_t *bitmap,
4472 struct nfs4_threshold *res)
4473{
4474 __be32 *p;
4475 int status = 0;
4476 uint32_t num;
4477
4478 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4479 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004480 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004481 /* Did the server return an unrequested attribute? */
4482 if (unlikely(res == NULL))
4483 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004484 p = xdr_inline_decode(xdr, 4);
4485 if (unlikely(!p))
4486 goto out_overflow;
4487 num = be32_to_cpup(p);
4488 if (num == 0)
4489 return 0;
4490 if (num > 1)
4491 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4492 "drivers per filesystem not supported\n",
4493 __func__);
4494
4495 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004496 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004497 }
4498 return status;
4499out_overflow:
4500 print_overflow_msg(__func__, xdr);
4501 return -EIO;
4502}
4503
Bryan Schumakerae42c702010-10-21 16:33:17 -04004504static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4505 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004506 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004507 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508{
Trond Myklebustbca79472009-03-11 14:10:26 -04004509 int status;
4510 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004511 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004512 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004514 status = decode_attr_type(xdr, bitmap, &type);
4515 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004517 fattr->mode = 0;
4518 if (status != 0) {
4519 fattr->mode |= nfs_type2fmt[type];
4520 fattr->valid |= status;
4521 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004522
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004523 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4524 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004526 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004527
4528 status = decode_attr_size(xdr, bitmap, &fattr->size);
4529 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004531 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004532
4533 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4534 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004535 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004536 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004537
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004538 err = 0;
4539 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004540 if (status < 0)
4541 goto xdr_error;
4542
4543 status = decode_attr_filehandle(xdr, bitmap, fh);
4544 if (status < 0)
4545 goto xdr_error;
4546
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004547 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4548 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004550 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004551
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004552 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004553 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004554 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004555 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004556
4557 status = decode_attr_mode(xdr, bitmap, &fmode);
4558 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004559 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004560 if (status != 0) {
4561 fattr->mode |= fmode;
4562 fattr->valid |= status;
4563 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004564
4565 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4566 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004567 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004568 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004569
Trond Myklebust6926afd2012-01-07 13:22:46 -05004570 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004571 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004573 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004574
Trond Myklebust6926afd2012-01-07 13:22:46 -05004575 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004576 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004578 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004579
4580 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4581 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004583 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004584
4585 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4586 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004588 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004589
4590 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4591 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004593 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004594
4595 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4596 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004597 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004598 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004599
4600 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4601 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004602 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004603 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004604
Trond Myklebust28331a42011-04-27 13:47:52 -04004605 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004606 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004607 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004608 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004609
Andy Adamson88034c32012-05-23 05:02:34 -04004610 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4611 if (status < 0)
4612 goto xdr_error;
4613
David Quigleyaa9c2662013-05-22 12:50:44 -04004614 if (label) {
4615 status = decode_attr_security_label(xdr, bitmap, label);
4616 if (status < 0)
4617 goto xdr_error;
4618 fattr->valid |= status;
4619 }
4620
Bryan Schumakerae42c702010-10-21 16:33:17 -04004621xdr_error:
4622 dprintk("%s: xdr returned %d\n", __func__, -status);
4623 return status;
4624}
4625
4626static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004627 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004628 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004629{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004630 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004631 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004632 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004633 int status;
4634
4635 status = decode_op_hdr(xdr, OP_GETATTR);
4636 if (status < 0)
4637 goto xdr_error;
4638
4639 status = decode_attr_bitmap(xdr, bitmap);
4640 if (status < 0)
4641 goto xdr_error;
4642
4643 status = decode_attr_length(xdr, &attrlen, &savep);
4644 if (status < 0)
4645 goto xdr_error;
4646
David Quigleyaa9c2662013-05-22 12:50:44 -04004647 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4648 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004649 if (status < 0)
4650 goto xdr_error;
4651
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004652 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004653xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004654 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655 return status;
4656}
4657
David Quigleyaa9c2662013-05-22 12:50:44 -04004658static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4659 struct nfs4_label *label, const struct nfs_server *server)
4660{
4661 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4662}
4663
Bryan Schumakerae42c702010-10-21 16:33:17 -04004664static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004665 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004666{
David Quigleyaa9c2662013-05-22 12:50:44 -04004667 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004668}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669
Andy Adamson504913f2010-10-20 00:17:57 -04004670/*
4671 * Decode potentially multiple layout types. Currently we only support
4672 * one layout driver per file system.
4673 */
4674static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4675 uint32_t *layouttype)
4676{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004677 __be32 *p;
Andy Adamson504913f2010-10-20 00:17:57 -04004678 int num;
4679
4680 p = xdr_inline_decode(xdr, 4);
4681 if (unlikely(!p))
4682 goto out_overflow;
4683 num = be32_to_cpup(p);
4684
4685 /* pNFS is not supported by the underlying file system */
4686 if (num == 0) {
4687 *layouttype = 0;
4688 return 0;
4689 }
4690 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004691 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4692 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004693
4694 /* Decode and set first layout type, move xdr->p past unused types */
4695 p = xdr_inline_decode(xdr, num * 4);
4696 if (unlikely(!p))
4697 goto out_overflow;
4698 *layouttype = be32_to_cpup(p);
4699 return 0;
4700out_overflow:
4701 print_overflow_msg(__func__, xdr);
4702 return -EIO;
4703}
4704
4705/*
4706 * The type of file system exported.
4707 * Note we must ensure that layouttype is set in any non-error case.
4708 */
4709static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4710 uint32_t *layouttype)
4711{
4712 int status = 0;
4713
4714 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4715 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4716 return -EIO;
4717 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4718 status = decode_first_pnfs_layout_type(xdr, layouttype);
4719 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4720 } else
4721 *layouttype = 0;
4722 return status;
4723}
4724
Fred Isamandae100c2011-07-30 20:52:37 -04004725/*
4726 * The prefered block size for layout directed io
4727 */
4728static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4729 uint32_t *res)
4730{
4731 __be32 *p;
4732
4733 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4734 *res = 0;
4735 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4736 p = xdr_inline_decode(xdr, 4);
4737 if (unlikely(!p)) {
4738 print_overflow_msg(__func__, xdr);
4739 return -EIO;
4740 }
4741 *res = be32_to_cpup(p);
4742 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4743 }
4744 return 0;
4745}
4746
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4748{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004749 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004750 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751 int status;
4752
4753 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4754 goto xdr_error;
4755 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4756 goto xdr_error;
4757 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4758 goto xdr_error;
4759
4760 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4761
4762 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4763 goto xdr_error;
4764 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4765 goto xdr_error;
4766 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4767 goto xdr_error;
4768 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4769 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4770 goto xdr_error;
4771 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004772 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4773 if (status != 0)
4774 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004775 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4776 if (status != 0)
4777 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004778 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4779 if (status)
4780 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004781
4782 status = verify_attr_len(xdr, savep, attrlen);
4783xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004784 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785 return status;
4786}
4787
4788static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4789{
Al Viro8687b632006-10-19 23:28:48 -07004790 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004791 uint32_t len;
4792 int status;
4793
Trond Myklebust99367812007-07-17 21:52:41 -04004794 /* Zero handle first to allow comparisons */
4795 memset(fh, 0, sizeof(*fh));
4796
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 status = decode_op_hdr(xdr, OP_GETFH);
4798 if (status)
4799 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800
Benny Halevyc0eae662009-08-14 17:20:14 +03004801 p = xdr_inline_decode(xdr, 4);
4802 if (unlikely(!p))
4803 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004804 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004805 if (len > NFS4_FHSIZE)
4806 return -EIO;
4807 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004808 p = xdr_inline_decode(xdr, len);
4809 if (unlikely(!p))
4810 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004811 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004813out_overflow:
4814 print_overflow_msg(__func__, xdr);
4815 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816}
4817
4818static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4819{
4820 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004821
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822 status = decode_op_hdr(xdr, OP_LINK);
4823 if (status)
4824 return status;
4825 return decode_change_info(xdr, cinfo);
4826}
4827
4828/*
4829 * We create the owner, so we know a proper owner.id length is 4.
4830 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004831static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004833 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004834 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004835 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004837 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004838 if (unlikely(!p))
4839 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004840 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004841 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004842 type = be32_to_cpup(p++); /* 4 byte read */
4843 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004844 fl->fl_start = (loff_t)offset;
4845 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4846 if (length == ~(uint64_t)0)
4847 fl->fl_end = OFFSET_MAX;
4848 fl->fl_type = F_WRLCK;
4849 if (type & 1)
4850 fl->fl_type = F_RDLCK;
4851 fl->fl_pid = 0;
4852 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004853 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4854 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4855 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004856 if (likely(p))
4857 return -NFS4ERR_DENIED;
4858out_overflow:
4859 print_overflow_msg(__func__, xdr);
4860 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861}
4862
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004863static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865 int status;
4866
4867 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004868 if (status == -EIO)
4869 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004871 status = decode_stateid(xdr, &res->stateid);
4872 if (unlikely(status))
4873 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004875 status = decode_lock_denied(xdr, NULL);
4876 if (res->open_seqid != NULL)
4877 nfs_increment_open_seqid(status, res->open_seqid);
4878 nfs_increment_lock_seqid(status, res->lock_seqid);
4879out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880 return status;
4881}
4882
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004883static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004884{
4885 int status;
4886 status = decode_op_hdr(xdr, OP_LOCKT);
4887 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004888 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889 return status;
4890}
4891
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004892static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004894 int status;
4895
4896 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004897 if (status != -EIO)
4898 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004899 if (status == 0)
4900 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901 return status;
4902}
4903
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004904static int decode_release_lockowner(struct xdr_stream *xdr)
4905{
4906 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4907}
4908
Linus Torvalds1da177e2005-04-16 15:20:36 -07004909static int decode_lookup(struct xdr_stream *xdr)
4910{
4911 return decode_op_hdr(xdr, OP_LOOKUP);
4912}
4913
4914/* This is too sick! */
4915static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4916{
Andy Adamson05d564f2008-12-23 16:06:15 -05004917 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918 uint32_t limit_type, nblocks, blocksize;
4919
Benny Halevyc0eae662009-08-14 17:20:14 +03004920 p = xdr_inline_decode(xdr, 12);
4921 if (unlikely(!p))
4922 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004923 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004924 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004925 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004926 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004927 break;
4928 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004929 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004930 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004931 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004932 }
4933 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004934out_overflow:
4935 print_overflow_msg(__func__, xdr);
4936 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004937}
4938
4939static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4940{
Andy Adamson05d564f2008-12-23 16:06:15 -05004941 __be32 *p;
4942 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004943 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944
Benny Halevyc0eae662009-08-14 17:20:14 +03004945 p = xdr_inline_decode(xdr, 4);
4946 if (unlikely(!p))
4947 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004948 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004949 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4950 res->delegation_type = 0;
4951 return 0;
4952 }
Benny Halevy07d30432009-08-14 17:19:52 +03004953 status = decode_stateid(xdr, &res->delegation);
4954 if (unlikely(status))
4955 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004956 p = xdr_inline_decode(xdr, 4);
4957 if (unlikely(!p))
4958 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004959 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004960
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004962 case NFS4_OPEN_DELEGATE_READ:
4963 res->delegation_type = FMODE_READ;
4964 break;
4965 case NFS4_OPEN_DELEGATE_WRITE:
4966 res->delegation_type = FMODE_WRITE|FMODE_READ;
4967 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004968 return -EIO;
4969 }
David Howells7539bba2006-08-22 20:06:09 -04004970 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004971out_overflow:
4972 print_overflow_msg(__func__, xdr);
4973 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974}
4975
4976static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4977{
Andy Adamson05d564f2008-12-23 16:06:15 -05004978 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004979 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004980 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004981
Trond Myklebustc7848f62013-12-04 17:39:23 -05004982 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
4983 return status;
4984 nfs_increment_open_seqid(status, res->seqid);
4985 if (status)
4986 return status;
4987 status = decode_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004988 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004989 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990
Andy Adamson05d564f2008-12-23 16:06:15 -05004991 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992
Benny Halevyc0eae662009-08-14 17:20:14 +03004993 p = xdr_inline_decode(xdr, 8);
4994 if (unlikely(!p))
4995 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004996 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004997 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004998 if (bmlen > 10)
4999 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005000
Benny Halevyc0eae662009-08-14 17:20:14 +03005001 p = xdr_inline_decode(xdr, bmlen << 2);
5002 if (unlikely(!p))
5003 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005004 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5005 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005006 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005007 for (; i < NFS4_BITMAP_SIZE; i++)
5008 res->attrset[i] = 0;
5009
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010 return decode_delegation(xdr, res);
5011xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005012 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005014out_overflow:
5015 print_overflow_msg(__func__, xdr);
5016 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005017}
5018
5019static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5020{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005021 int status;
5022
Andy Adamson05d564f2008-12-23 16:06:15 -05005023 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005024 if (status != -EIO)
5025 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005026 if (!status)
5027 status = decode_stateid(xdr, &res->stateid);
5028 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029}
5030
5031static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5032{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005033 int status;
5034
5035 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005036 if (status != -EIO)
5037 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005038 if (!status)
5039 status = decode_stateid(xdr, &res->stateid);
5040 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041}
5042
5043static int decode_putfh(struct xdr_stream *xdr)
5044{
5045 return decode_op_hdr(xdr, OP_PUTFH);
5046}
5047
5048static int decode_putrootfh(struct xdr_stream *xdr)
5049{
5050 return decode_op_hdr(xdr, OP_PUTROOTFH);
5051}
5052
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005053static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5054 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005055{
Al Viro8687b632006-10-19 23:28:48 -07005056 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005057 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058 int status;
5059
5060 status = decode_op_hdr(xdr, OP_READ);
5061 if (status)
5062 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005063 p = xdr_inline_decode(xdr, 8);
5064 if (unlikely(!p))
5065 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005066 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005067 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005068 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005070 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071 "count %u > recvd %u\n", count, recvd);
5072 count = recvd;
5073 eof = 0;
5074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005075 res->eof = eof;
5076 res->count = count;
5077 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005078out_overflow:
5079 print_overflow_msg(__func__, xdr);
5080 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081}
5082
5083static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5084{
Chuck Leverbcecff72007-10-26 13:32:03 -04005085 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005086 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087
5088 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005089 if (!status)
5090 status = decode_verifier(xdr, readdir->verifier.data);
5091 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005092 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005093 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005094 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005095 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005096 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005097}
5098
5099static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5100{
5101 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005102 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005103 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104 int status;
5105
5106 status = decode_op_hdr(xdr, OP_READLINK);
5107 if (status)
5108 return status;
5109
5110 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005111 p = xdr_inline_decode(xdr, 4);
5112 if (unlikely(!p))
5113 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005114 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005116 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117 return -ENAMETOOLONG;
5118 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005119 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005121 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005122 "count %u > recvd %u\n", len, recvd);
5123 return -EIO;
5124 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005125 /*
5126 * The XDR encode routine has set things up so that
5127 * the link text will be copied directly into the
5128 * buffer. We just have to do overflow-checking,
5129 * and and null-terminate the text (the VFS expects
5130 * null-termination).
5131 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005132 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005134out_overflow:
5135 print_overflow_msg(__func__, xdr);
5136 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005137}
5138
5139static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5140{
5141 int status;
5142
5143 status = decode_op_hdr(xdr, OP_REMOVE);
5144 if (status)
5145 goto out;
5146 status = decode_change_info(xdr, cinfo);
5147out:
5148 return status;
5149}
5150
5151static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5152 struct nfs4_change_info *new_cinfo)
5153{
5154 int status;
5155
5156 status = decode_op_hdr(xdr, OP_RENAME);
5157 if (status)
5158 goto out;
5159 if ((status = decode_change_info(xdr, old_cinfo)))
5160 goto out;
5161 status = decode_change_info(xdr, new_cinfo);
5162out:
5163 return status;
5164}
5165
5166static int decode_renew(struct xdr_stream *xdr)
5167{
5168 return decode_op_hdr(xdr, OP_RENEW);
5169}
5170
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005171static int
5172decode_restorefh(struct xdr_stream *xdr)
5173{
5174 return decode_op_hdr(xdr, OP_RESTOREFH);
5175}
5176
J. Bruce Fields029d1052005-06-22 17:16:22 +00005177static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005178 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005179{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005180 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005181 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005182 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005183 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005184 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005185
Andy Adamsonbf118a32011-12-07 11:55:27 -05005186 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005187 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5188 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005189
Trond Myklebust519d3952012-08-14 17:30:10 -04005190 xdr_enter_page(xdr, xdr->buf->page_len);
5191
Trond Myklebustcff298c2012-08-14 17:14:17 -04005192 /* Calculate the offset of the page data */
5193 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005194
J. Bruce Fields029d1052005-06-22 17:16:22 +00005195 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5196 goto out;
5197 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5198 goto out;
5199
5200 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5201 return -EIO;
5202 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005203
Andy Adamsonbf118a32011-12-07 11:55:27 -05005204 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5205 * are stored with the acl data to handle the problem of
5206 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005207 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005208 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005209
5210 /* Check for receive buffer overflow */
5211 if (res->acl_len > (xdr->nwords << 2) ||
5212 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5213 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005214 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005215 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005216 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005217 } else
5218 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005219
5220out:
5221 return status;
5222}
5223
Linus Torvalds1da177e2005-04-16 15:20:36 -07005224static int
5225decode_savefh(struct xdr_stream *xdr)
5226{
5227 return decode_op_hdr(xdr, OP_SAVEFH);
5228}
5229
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005230static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005231{
Al Viro8687b632006-10-19 23:28:48 -07005232 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005233 uint32_t bmlen;
5234 int status;
5235
Linus Torvalds1da177e2005-04-16 15:20:36 -07005236 status = decode_op_hdr(xdr, OP_SETATTR);
5237 if (status)
5238 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005239 p = xdr_inline_decode(xdr, 4);
5240 if (unlikely(!p))
5241 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005242 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005243 p = xdr_inline_decode(xdr, bmlen << 2);
5244 if (likely(p))
5245 return 0;
5246out_overflow:
5247 print_overflow_msg(__func__, xdr);
5248 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249}
5250
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005251static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252{
Al Viro8687b632006-10-19 23:28:48 -07005253 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254 uint32_t opnum;
5255 int32_t nfserr;
5256
Benny Halevyc0eae662009-08-14 17:20:14 +03005257 p = xdr_inline_decode(xdr, 8);
5258 if (unlikely(!p))
5259 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005260 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005261 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005262 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005263 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005264 return -EIO;
5265 }
Benny Halevycccddf42009-08-14 17:20:19 +03005266 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005267 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005268 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5269 if (unlikely(!p))
5270 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005271 p = xdr_decode_hyper(p, &res->clientid);
5272 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005273 } else if (nfserr == NFSERR_CLID_INUSE) {
5274 uint32_t len;
5275
5276 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005277 p = xdr_inline_decode(xdr, 4);
5278 if (unlikely(!p))
5279 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005280 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005281 p = xdr_inline_decode(xdr, len);
5282 if (unlikely(!p))
5283 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005284
5285 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005286 p = xdr_inline_decode(xdr, 4);
5287 if (unlikely(!p))
5288 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005289 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005290 p = xdr_inline_decode(xdr, len);
5291 if (unlikely(!p))
5292 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005293 return -NFSERR_CLID_INUSE;
5294 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005295 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296
5297 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005298out_overflow:
5299 print_overflow_msg(__func__, xdr);
5300 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005301}
5302
5303static int decode_setclientid_confirm(struct xdr_stream *xdr)
5304{
5305 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5306}
5307
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005308static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005309{
Al Viro8687b632006-10-19 23:28:48 -07005310 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005311 int status;
5312
5313 status = decode_op_hdr(xdr, OP_WRITE);
5314 if (status)
5315 return status;
5316
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005317 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005318 if (unlikely(!p))
5319 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005320 res->count = be32_to_cpup(p++);
5321 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005322 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005323out_overflow:
5324 print_overflow_msg(__func__, xdr);
5325 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005326}
5327
5328static int decode_delegreturn(struct xdr_stream *xdr)
5329{
5330 return decode_op_hdr(xdr, OP_DELEGRETURN);
5331}
5332
Chuck Leverfb15b262013-03-16 15:54:34 -04005333static int decode_secinfo_gss(struct xdr_stream *xdr,
5334 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005335{
Chuck Leverfb15b262013-03-16 15:54:34 -04005336 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005337 __be32 *p;
5338
5339 p = xdr_inline_decode(xdr, 4);
5340 if (unlikely(!p))
5341 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005342 oid_len = be32_to_cpup(p);
5343 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005344 goto out_err;
5345
Chuck Leverfb15b262013-03-16 15:54:34 -04005346 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005347 if (unlikely(!p))
5348 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005349 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5350 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005351
5352 p = xdr_inline_decode(xdr, 8);
5353 if (unlikely(!p))
5354 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005355 flavor->flavor_info.qop = be32_to_cpup(p++);
5356 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005357
5358 return 0;
5359
5360out_overflow:
5361 print_overflow_msg(__func__, xdr);
5362 return -EIO;
5363out_err:
5364 return -EINVAL;
5365}
5366
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005367static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005368{
Chuck Leverfb15b262013-03-16 15:54:34 -04005369 struct nfs4_secinfo4 *sec_flavor;
5370 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005371 int status;
5372 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005373
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005374 p = xdr_inline_decode(xdr, 4);
5375 if (unlikely(!p))
5376 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005377
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005378 res->flavors->num_flavors = 0;
5379 num_flavors = be32_to_cpup(p);
5380
5381 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005382 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005383 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005384 break;
5385
5386 p = xdr_inline_decode(xdr, 4);
5387 if (unlikely(!p))
5388 goto out_overflow;
5389 sec_flavor->flavor = be32_to_cpup(p);
5390
5391 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005392 status = decode_secinfo_gss(xdr, sec_flavor);
5393 if (status)
5394 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005395 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005396 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005397 }
5398
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005399 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005400out:
5401 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005402out_overflow:
5403 print_overflow_msg(__func__, xdr);
5404 return -EIO;
5405}
5406
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005407static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5408{
5409 int status = decode_op_hdr(xdr, OP_SECINFO);
5410 if (status)
5411 return status;
5412 return decode_secinfo_common(xdr, res);
5413}
5414
Benny Halevy99fe60d2009-04-01 09:22:29 -04005415#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005416static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5417{
5418 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5419 if (status)
5420 return status;
5421 return decode_secinfo_common(xdr, res);
5422}
5423
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005424static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5425{
5426 __be32 *p;
5427 uint32_t bitmap_words;
5428 unsigned int i;
5429
5430 p = xdr_inline_decode(xdr, 4);
5431 bitmap_words = be32_to_cpup(p++);
5432 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5433 return -EIO;
5434 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5435 for (i = 0; i < bitmap_words; i++)
5436 op_map->u.words[i] = be32_to_cpup(p++);
5437
5438 return 0;
5439}
5440
Benny Halevy99fe60d2009-04-01 09:22:29 -04005441static int decode_exchange_id(struct xdr_stream *xdr,
5442 struct nfs41_exchange_id_res *res)
5443{
5444 __be32 *p;
5445 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005446 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005447 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005448 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005449
5450 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5451 if (status)
5452 return status;
5453
Benny Halevyc0eae662009-08-14 17:20:14 +03005454 p = xdr_inline_decode(xdr, 8);
5455 if (unlikely(!p))
5456 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005457 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005458 p = xdr_inline_decode(xdr, 12);
5459 if (unlikely(!p))
5460 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005461 res->seqid = be32_to_cpup(p++);
5462 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005463
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005464 res->state_protect.how = be32_to_cpup(p);
5465 switch (res->state_protect.how) {
5466 case SP4_NONE:
5467 break;
5468 case SP4_MACH_CRED:
5469 status = decode_op_map(xdr, &res->state_protect.enforce);
5470 if (status)
5471 return status;
5472 status = decode_op_map(xdr, &res->state_protect.allow);
5473 if (status)
5474 return status;
5475 break;
5476 default:
5477 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005478 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005479 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005480
Chuck Leveracdeb692012-05-21 22:46:16 -04005481 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005482 p = xdr_inline_decode(xdr, 8);
5483 if (unlikely(!p))
5484 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005485 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005486
Chuck Leveracdeb692012-05-21 22:46:16 -04005487 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005488 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5489 if (unlikely(status))
5490 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005491 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5492 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005493 memcpy(res->server_owner->major_id, dummy_str, dummy);
5494 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005495
Chuck Leveracdeb692012-05-21 22:46:16 -04005496 /* server_scope4 */
5497 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5498 if (unlikely(status))
5499 return status;
5500 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5501 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005502 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5503 res->server_scope->server_scope_sz = dummy;
5504
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005505 /* Implementation Id */
5506 p = xdr_inline_decode(xdr, 4);
5507 if (unlikely(!p))
5508 goto out_overflow;
5509 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005510
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005511 if (impl_id_count) {
5512 /* nii_domain */
5513 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5514 if (unlikely(status))
5515 return status;
5516 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5517 return -EIO;
5518 memcpy(res->impl_id->domain, dummy_str, dummy);
5519
5520 /* nii_name */
5521 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5522 if (unlikely(status))
5523 return status;
5524 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5525 return -EIO;
5526 memcpy(res->impl_id->name, dummy_str, dummy);
5527
5528 /* nii_date */
5529 p = xdr_inline_decode(xdr, 12);
5530 if (unlikely(!p))
5531 goto out_overflow;
5532 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5533 res->impl_id->date.nseconds = be32_to_cpup(p);
5534
5535 /* if there's more than one entry, ignore the rest */
5536 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005537 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005538out_overflow:
5539 print_overflow_msg(__func__, xdr);
5540 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005541}
Andy Adamsonfc931582009-04-01 09:22:31 -04005542
5543static int decode_chan_attrs(struct xdr_stream *xdr,
5544 struct nfs4_channel_attrs *attrs)
5545{
5546 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005547 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005548
Benny Halevyc0eae662009-08-14 17:20:14 +03005549 p = xdr_inline_decode(xdr, 28);
5550 if (unlikely(!p))
5551 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005552 val = be32_to_cpup(p++); /* headerpadsz */
5553 if (val)
5554 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005555 attrs->max_rqst_sz = be32_to_cpup(p++);
5556 attrs->max_resp_sz = be32_to_cpup(p++);
5557 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5558 attrs->max_ops = be32_to_cpup(p++);
5559 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005560 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005561 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005562 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5563 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005564 return -EINVAL;
5565 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005566 if (nr_attrs == 1) {
5567 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5568 if (unlikely(!p))
5569 goto out_overflow;
5570 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005571 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005572out_overflow:
5573 print_overflow_msg(__func__, xdr);
5574 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005575}
5576
Benny Halevye78291e2009-08-14 17:20:00 +03005577static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5578{
5579 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005580}
5581
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005582static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5583 struct nfs41_bind_conn_to_session_res *res)
5584{
5585 __be32 *p;
5586 int status;
5587
5588 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5589 if (!status)
5590 status = decode_sessionid(xdr, &res->session->sess_id);
5591 if (unlikely(status))
5592 return status;
5593
5594 /* dir flags, rdma mode bool */
5595 p = xdr_inline_decode(xdr, 8);
5596 if (unlikely(!p))
5597 goto out_overflow;
5598
5599 res->dir = be32_to_cpup(p++);
5600 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5601 return -EIO;
5602 if (be32_to_cpup(p) == 0)
5603 res->use_conn_in_rdma_mode = false;
5604 else
5605 res->use_conn_in_rdma_mode = true;
5606
5607 return 0;
5608out_overflow:
5609 print_overflow_msg(__func__, xdr);
5610 return -EIO;
5611}
5612
Andy Adamsonfc931582009-04-01 09:22:31 -04005613static int decode_create_session(struct xdr_stream *xdr,
5614 struct nfs41_create_session_res *res)
5615{
5616 __be32 *p;
5617 int status;
5618 struct nfs_client *clp = res->client;
5619 struct nfs4_session *session = clp->cl_session;
5620
5621 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005622 if (!status)
5623 status = decode_sessionid(xdr, &session->sess_id);
5624 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005625 return status;
5626
Andy Adamsonfc931582009-04-01 09:22:31 -04005627 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005628 p = xdr_inline_decode(xdr, 8);
5629 if (unlikely(!p))
5630 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005631 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005632 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005633
5634 /* Channel attributes */
5635 status = decode_chan_attrs(xdr, &session->fc_attrs);
5636 if (!status)
5637 status = decode_chan_attrs(xdr, &session->bc_attrs);
5638 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005639out_overflow:
5640 print_overflow_msg(__func__, xdr);
5641 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005642}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005643
5644static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5645{
5646 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5647}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005648
Trond Myklebust66245532012-05-25 17:18:09 -04005649static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5650{
5651 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5652}
5653
Ricardo Labiaga180197532009-12-05 16:08:40 -05005654static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5655{
5656 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5657}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005658#endif /* CONFIG_NFS_V4_1 */
5659
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005660static int decode_sequence(struct xdr_stream *xdr,
5661 struct nfs4_sequence_res *res,
5662 struct rpc_rqst *rqstp)
5663{
5664#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005665 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005666 struct nfs4_sessionid id;
5667 u32 dummy;
5668 int status;
5669 __be32 *p;
5670
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005671 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005672 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005673 if (!res->sr_slot->table->session)
5674 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005675
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005676 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005677 if (!status)
5678 status = decode_sessionid(xdr, &id);
5679 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005680 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005681
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005682 /*
5683 * If the server returns different values for sessionID, slotID or
5684 * sequence number, the server is looney tunes.
5685 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005686 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005687 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005688
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005689 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005690 NFS4_MAX_SESSIONID_LEN)) {
5691 dprintk("%s Invalid session id\n", __func__);
5692 goto out_err;
5693 }
Benny Halevye78291e2009-08-14 17:20:00 +03005694
Benny Halevyc0eae662009-08-14 17:20:14 +03005695 p = xdr_inline_decode(xdr, 20);
5696 if (unlikely(!p))
5697 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005698
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005699 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005700 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005701 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005702 dprintk("%s Invalid sequence number\n", __func__);
5703 goto out_err;
5704 }
5705 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005706 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005707 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005708 dprintk("%s Invalid slot id\n", __func__);
5709 goto out_err;
5710 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005711 /* highest slot id */
5712 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005713 /* target highest slot id */
5714 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005715 /* result flags */
5716 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005717 status = 0;
5718out_err:
5719 res->sr_status = status;
5720 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005721out_overflow:
5722 print_overflow_msg(__func__, xdr);
5723 status = -EIO;
5724 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005725#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005726 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005727#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005728}
5729
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005730#if defined(CONFIG_NFS_V4_1)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005731static int decode_getdeviceinfo(struct xdr_stream *xdr,
5732 struct pnfs_device *pdev)
5733{
5734 __be32 *p;
5735 uint32_t len, type;
5736 int status;
5737
5738 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5739 if (status) {
5740 if (status == -ETOOSMALL) {
5741 p = xdr_inline_decode(xdr, 4);
5742 if (unlikely(!p))
5743 goto out_overflow;
5744 pdev->mincount = be32_to_cpup(p);
5745 dprintk("%s: Min count too small. mincnt = %u\n",
5746 __func__, pdev->mincount);
5747 }
5748 return status;
5749 }
5750
5751 p = xdr_inline_decode(xdr, 8);
5752 if (unlikely(!p))
5753 goto out_overflow;
5754 type = be32_to_cpup(p++);
5755 if (type != pdev->layout_type) {
5756 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5757 __func__, pdev->layout_type, type);
5758 return -EINVAL;
5759 }
5760 /*
5761 * Get the length of the opaque device_addr4. xdr_read_pages places
5762 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5763 * and places the remaining xdr data in xdr_buf->tail
5764 */
5765 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005766 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5767 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005768
5769 /* Parse notification bitmap, verifying that it is zero. */
5770 p = xdr_inline_decode(xdr, 4);
5771 if (unlikely(!p))
5772 goto out_overflow;
5773 len = be32_to_cpup(p);
5774 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005775 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005776
5777 p = xdr_inline_decode(xdr, 4 * len);
5778 if (unlikely(!p))
5779 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005780
5781 if (be32_to_cpup(p++) &
5782 ~(NOTIFY_DEVICEID4_CHANGE | NOTIFY_DEVICEID4_DELETE)) {
5783 dprintk("%s: unsupported notification\n",
5784 __func__);
5785 }
5786
5787 for (i = 1; i < len; i++) {
5788 if (be32_to_cpup(p++)) {
5789 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005790 __func__);
5791 return -EIO;
5792 }
5793 }
5794 }
5795 return 0;
5796out_overflow:
5797 print_overflow_msg(__func__, xdr);
5798 return -EIO;
5799}
5800
5801static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5802 struct nfs4_layoutget_res *res)
5803{
5804 __be32 *p;
5805 int status;
5806 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005807 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005808
5809 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5810 if (status)
5811 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005812 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005813 if (unlikely(!p))
5814 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005815 res->return_on_close = be32_to_cpup(p);
5816 decode_stateid(xdr, &res->stateid);
5817 p = xdr_inline_decode(xdr, 4);
5818 if (unlikely(!p))
5819 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005820 layout_count = be32_to_cpup(p);
5821 if (!layout_count) {
5822 dprintk("%s: server responded with empty layout array\n",
5823 __func__);
5824 return -EINVAL;
5825 }
5826
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005827 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005828 if (unlikely(!p))
5829 goto out_overflow;
5830 p = xdr_decode_hyper(p, &res->range.offset);
5831 p = xdr_decode_hyper(p, &res->range.length);
5832 res->range.iomode = be32_to_cpup(p++);
5833 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005834 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005835
5836 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5837 __func__,
5838 (unsigned long)res->range.offset,
5839 (unsigned long)res->range.length,
5840 res->range.iomode,
5841 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005842 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005843
Trond Myklebust64bd5772012-06-20 22:35:05 -04005844 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005845 if (res->layoutp->len > recvd) {
5846 dprintk("NFS: server cheating in layoutget reply: "
5847 "layout len %u > recvd %u\n",
5848 res->layoutp->len, recvd);
5849 return -EINVAL;
5850 }
5851
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005852 if (layout_count > 1) {
5853 /* We only handle a length one array at the moment. Any
5854 * further entries are just ignored. Note that this means
5855 * the client may see a response that is less than the
5856 * minimum it requested.
5857 */
5858 dprintk("%s: server responded with %d layouts, dropping tail\n",
5859 __func__, layout_count);
5860 }
5861
5862 return 0;
5863out_overflow:
5864 print_overflow_msg(__func__, xdr);
5865 return -EIO;
5866}
Andy Adamson863a3c62011-03-23 13:27:54 +00005867
Benny Halevycbe82602011-05-22 19:52:37 +03005868static int decode_layoutreturn(struct xdr_stream *xdr,
5869 struct nfs4_layoutreturn_res *res)
5870{
5871 __be32 *p;
5872 int status;
5873
5874 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5875 if (status)
5876 return status;
5877 p = xdr_inline_decode(xdr, 4);
5878 if (unlikely(!p))
5879 goto out_overflow;
5880 res->lrs_present = be32_to_cpup(p);
5881 if (res->lrs_present)
5882 status = decode_stateid(xdr, &res->stateid);
5883 return status;
5884out_overflow:
5885 print_overflow_msg(__func__, xdr);
5886 return -EIO;
5887}
5888
Andy Adamson863a3c62011-03-23 13:27:54 +00005889static int decode_layoutcommit(struct xdr_stream *xdr,
5890 struct rpc_rqst *req,
5891 struct nfs4_layoutcommit_res *res)
5892{
5893 __be32 *p;
5894 __u32 sizechanged;
5895 int status;
5896
5897 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005898 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005899 if (status)
5900 return status;
5901
5902 p = xdr_inline_decode(xdr, 4);
5903 if (unlikely(!p))
5904 goto out_overflow;
5905 sizechanged = be32_to_cpup(p);
5906
5907 if (sizechanged) {
5908 /* throw away new size */
5909 p = xdr_inline_decode(xdr, 8);
5910 if (unlikely(!p))
5911 goto out_overflow;
5912 }
5913 return 0;
5914out_overflow:
5915 print_overflow_msg(__func__, xdr);
5916 return -EIO;
5917}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005918
5919static int decode_test_stateid(struct xdr_stream *xdr,
5920 struct nfs41_test_stateid_res *res)
5921{
5922 __be32 *p;
5923 int status;
5924 int num_res;
5925
5926 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5927 if (status)
5928 return status;
5929
5930 p = xdr_inline_decode(xdr, 4);
5931 if (unlikely(!p))
5932 goto out_overflow;
5933 num_res = be32_to_cpup(p++);
5934 if (num_res != 1)
5935 goto out;
5936
5937 p = xdr_inline_decode(xdr, 4);
5938 if (unlikely(!p))
5939 goto out_overflow;
5940 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005941
5942 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005943out_overflow:
5944 print_overflow_msg(__func__, xdr);
5945out:
5946 return -EIO;
5947}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005948
5949static int decode_free_stateid(struct xdr_stream *xdr,
5950 struct nfs41_free_stateid_res *res)
5951{
Andy Adamson9f79fb42013-09-10 12:56:29 -04005952 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005953 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005954}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005955#endif /* CONFIG_NFS_V4_1 */
5956
Linus Torvalds1da177e2005-04-16 15:20:36 -07005957/*
Benny Halevy49c25592008-12-23 16:06:16 -05005958 * END OF "GENERIC" DECODE ROUTINES.
5959 */
5960
5961/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005962 * Decode OPEN_DOWNGRADE response
5963 */
Chuck Leverbf269552010-12-14 14:59:29 +00005964static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5965 struct xdr_stream *xdr,
5966 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005967{
Andy Adamson05d564f2008-12-23 16:06:15 -05005968 struct compound_hdr hdr;
5969 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970
Chuck Leverbf269552010-12-14 14:59:29 +00005971 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005972 if (status)
5973 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005974 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005975 if (status)
5976 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005977 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005978 if (status)
5979 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005980 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005981 if (status != 0)
5982 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005983 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005985 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005986}
5987
5988/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005989 * Decode ACCESS response
5990 */
Chuck Leverbf269552010-12-14 14:59:29 +00005991static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5992 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005993{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005994 struct compound_hdr hdr;
5995 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005996
Chuck Leverbf269552010-12-14 14:59:29 +00005997 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005998 if (status)
5999 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006000 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006001 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006002 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006003 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006004 if (status != 0)
6005 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006006 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006007 if (status != 0)
6008 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006009 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010out:
6011 return status;
6012}
6013
6014/*
6015 * Decode LOOKUP response
6016 */
Chuck Leverbf269552010-12-14 14:59:29 +00006017static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6018 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006019{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006020 struct compound_hdr hdr;
6021 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006022
Chuck Leverbf269552010-12-14 14:59:29 +00006023 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006024 if (status)
6025 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006026 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006027 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006028 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006029 status = decode_putfh(xdr);
6030 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006031 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006032 status = decode_lookup(xdr);
6033 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006034 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006035 status = decode_getfh(xdr, res->fh);
6036 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006037 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006038 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006039out:
6040 return status;
6041}
6042
6043/*
6044 * Decode LOOKUP_ROOT response
6045 */
Chuck Leverbf269552010-12-14 14:59:29 +00006046static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6047 struct xdr_stream *xdr,
6048 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006049{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006050 struct compound_hdr hdr;
6051 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006052
Chuck Leverbf269552010-12-14 14:59:29 +00006053 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006054 if (status)
6055 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006056 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006057 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006058 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006059 status = decode_putrootfh(xdr);
6060 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006062 status = decode_getfh(xdr, res->fh);
6063 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006064 status = decode_getfattr_label(xdr, res->fattr,
6065 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006066out:
6067 return status;
6068}
6069
6070/*
6071 * Decode REMOVE response
6072 */
Chuck Leverbf269552010-12-14 14:59:29 +00006073static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6074 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006075{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006076 struct compound_hdr hdr;
6077 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006078
Chuck Leverbf269552010-12-14 14:59:29 +00006079 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006080 if (status)
6081 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006082 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006083 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006084 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006085 status = decode_putfh(xdr);
6086 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006087 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006088 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089out:
6090 return status;
6091}
6092
6093/*
6094 * Decode RENAME response
6095 */
Chuck Leverbf269552010-12-14 14:59:29 +00006096static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6097 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006099 struct compound_hdr hdr;
6100 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006101
Chuck Leverbf269552010-12-14 14:59:29 +00006102 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006103 if (status)
6104 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006105 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006106 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006107 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006108 status = decode_putfh(xdr);
6109 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006110 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006111 status = decode_savefh(xdr);
6112 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006114 status = decode_putfh(xdr);
6115 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006116 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006117 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118out:
6119 return status;
6120}
6121
6122/*
6123 * Decode LINK response
6124 */
Chuck Leverbf269552010-12-14 14:59:29 +00006125static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6126 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006127{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006128 struct compound_hdr hdr;
6129 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006130
Chuck Leverbf269552010-12-14 14:59:29 +00006131 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006132 if (status)
6133 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006134 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006135 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006136 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006137 status = decode_putfh(xdr);
6138 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006139 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006140 status = decode_savefh(xdr);
6141 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006142 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006143 status = decode_putfh(xdr);
6144 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006145 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006146 status = decode_link(xdr, &res->cinfo);
6147 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006148 goto out;
6149 /*
6150 * Note order: OP_LINK leaves the directory as the current
6151 * filehandle.
6152 */
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_restorefh(xdr);
6154 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006155 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006156 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006157out:
6158 return status;
6159}
6160
6161/*
6162 * Decode CREATE response
6163 */
Chuck Leverbf269552010-12-14 14:59:29 +00006164static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6165 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006166{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006167 struct compound_hdr hdr;
6168 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006169
Chuck Leverbf269552010-12-14 14:59:29 +00006170 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006171 if (status)
6172 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006173 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006174 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006175 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006176 status = decode_putfh(xdr);
6177 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006178 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006179 status = decode_create(xdr, &res->dir_cinfo);
6180 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006182 status = decode_getfh(xdr, res->fh);
6183 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006184 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006185 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006186out:
6187 return status;
6188}
6189
6190/*
6191 * Decode SYMLINK response
6192 */
Chuck Leverbf269552010-12-14 14:59:29 +00006193static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6194 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195{
Chuck Leverbf269552010-12-14 14:59:29 +00006196 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197}
6198
6199/*
6200 * Decode GETATTR response
6201 */
Chuck Leverbf269552010-12-14 14:59:29 +00006202static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6203 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006204{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205 struct compound_hdr hdr;
6206 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006207
Chuck Leverbf269552010-12-14 14:59:29 +00006208 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209 if (status)
6210 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006211 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006212 if (status)
6213 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006214 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006215 if (status)
6216 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006217 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218out:
6219 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006220}
6221
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006222/*
6223 * Encode an SETACL request
6224 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006225static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6226 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006227{
Andy Adamson05d564f2008-12-23 16:06:15 -05006228 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006229 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006230 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006231
Chuck Lever9f06c712010-12-14 14:59:18 +00006232 encode_compound_hdr(xdr, req, &hdr);
6233 encode_sequence(xdr, &args->seq_args, &hdr);
6234 encode_putfh(xdr, args->fh, &hdr);
6235 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006236 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006237}
Andy Adamson05d564f2008-12-23 16:06:15 -05006238
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006239/*
6240 * Decode SETACL response
6241 */
6242static int
Chuck Leverbf269552010-12-14 14:59:29 +00006243nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006244 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006245{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006246 struct compound_hdr hdr;
6247 int status;
6248
Chuck Leverbf269552010-12-14 14:59:29 +00006249 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006250 if (status)
6251 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006252 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006253 if (status)
6254 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006256 if (status)
6257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006258 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006259out:
6260 return status;
6261}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262
6263/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006264 * Decode GETACL response
6265 */
6266static int
Chuck Leverbf269552010-12-14 14:59:29 +00006267nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006268 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006269{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006270 struct compound_hdr hdr;
6271 int status;
6272
Trond Myklebust331818f2012-02-03 18:30:53 -05006273 if (res->acl_scratch != NULL) {
6274 void *p = page_address(res->acl_scratch);
6275 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6276 }
Chuck Leverbf269552010-12-14 14:59:29 +00006277 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006278 if (status)
6279 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006280 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006281 if (status)
6282 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006283 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006284 if (status)
6285 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006286 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006287
6288out:
6289 return status;
6290}
6291
6292/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006293 * Decode CLOSE response
6294 */
Chuck Leverbf269552010-12-14 14:59:29 +00006295static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6296 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006297{
Andy Adamson05d564f2008-12-23 16:06:15 -05006298 struct compound_hdr hdr;
6299 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006300
Chuck Leverbf269552010-12-14 14:59:29 +00006301 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006302 if (status)
6303 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006304 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006305 if (status)
6306 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006307 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006308 if (status)
6309 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006311 if (status != 0)
6312 goto out;
6313 /*
6314 * Note: Server may do delete on close for this file
6315 * in which case the getattr call will fail with
6316 * an ESTALE error. Shouldn't be a problem,
6317 * though, since fattr->valid will remain unset.
6318 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006319 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006320out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006321 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006322}
6323
6324/*
6325 * Decode OPEN response
6326 */
Chuck Leverbf269552010-12-14 14:59:29 +00006327static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6328 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006329{
Andy Adamson05d564f2008-12-23 16:06:15 -05006330 struct compound_hdr hdr;
6331 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332
Chuck Leverbf269552010-12-14 14:59:29 +00006333 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006334 if (status)
6335 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006336 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006337 if (status)
6338 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006339 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006340 if (status)
6341 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006342 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006343 if (status)
6344 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006345 status = decode_getfh(xdr, &res->fh);
6346 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006347 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006348 if (res->access_request)
6349 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006350 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006352 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353}
6354
6355/*
6356 * Decode OPEN_CONFIRM response
6357 */
Chuck Leverbf269552010-12-14 14:59:29 +00006358static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6359 struct xdr_stream *xdr,
6360 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006361{
Andy Adamson05d564f2008-12-23 16:06:15 -05006362 struct compound_hdr hdr;
6363 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364
Chuck Leverbf269552010-12-14 14:59:29 +00006365 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006366 if (status)
6367 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006368 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006369 if (status)
6370 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006371 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006373 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006374}
6375
6376/*
6377 * Decode OPEN response
6378 */
Chuck Leverbf269552010-12-14 14:59:29 +00006379static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6380 struct xdr_stream *xdr,
6381 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006382{
Andy Adamson05d564f2008-12-23 16:06:15 -05006383 struct compound_hdr hdr;
6384 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006385
Chuck Leverbf269552010-12-14 14:59:29 +00006386 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006387 if (status)
6388 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006389 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006390 if (status)
6391 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006392 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006393 if (status)
6394 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006395 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006396 if (status)
6397 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006398 if (res->access_request)
6399 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006400 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006401out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006402 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006403}
6404
6405/*
6406 * Decode SETATTR response
6407 */
Chuck Leverbf269552010-12-14 14:59:29 +00006408static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6409 struct xdr_stream *xdr,
6410 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411{
Andy Adamson05d564f2008-12-23 16:06:15 -05006412 struct compound_hdr hdr;
6413 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006414
Chuck Leverbf269552010-12-14 14:59:29 +00006415 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006416 if (status)
6417 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006418 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006419 if (status)
6420 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006421 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006422 if (status)
6423 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006424 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006425 if (status)
6426 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006427 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006428out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006429 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006430}
6431
6432/*
6433 * Decode LOCK response
6434 */
Chuck Leverbf269552010-12-14 14:59:29 +00006435static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6436 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006438 struct compound_hdr hdr;
6439 int status;
6440
Chuck Leverbf269552010-12-14 14:59:29 +00006441 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006442 if (status)
6443 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006444 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006445 if (status)
6446 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006447 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448 if (status)
6449 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006450 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006451out:
6452 return status;
6453}
6454
6455/*
6456 * Decode LOCKT response
6457 */
Chuck Leverbf269552010-12-14 14:59:29 +00006458static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6459 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461 struct compound_hdr hdr;
6462 int status;
6463
Chuck Leverbf269552010-12-14 14:59:29 +00006464 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465 if (status)
6466 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006467 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006468 if (status)
6469 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006470 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471 if (status)
6472 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006473 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006474out:
6475 return status;
6476}
6477
6478/*
6479 * Decode LOCKU response
6480 */
Chuck Leverbf269552010-12-14 14:59:29 +00006481static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6482 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006483{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484 struct compound_hdr hdr;
6485 int status;
6486
Chuck Leverbf269552010-12-14 14:59:29 +00006487 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006488 if (status)
6489 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006490 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006491 if (status)
6492 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006493 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006494 if (status)
6495 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006496 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497out:
6498 return status;
6499}
6500
Chuck Leverbf269552010-12-14 14:59:29 +00006501static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6502 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006503{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006504 struct compound_hdr hdr;
6505 int status;
6506
Chuck Leverbf269552010-12-14 14:59:29 +00006507 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006508 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006509 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006510 return status;
6511}
6512
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513/*
6514 * Decode READLINK response
6515 */
Chuck Leverbf269552010-12-14 14:59:29 +00006516static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6517 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006518 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006519{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520 struct compound_hdr hdr;
6521 int status;
6522
Chuck Leverbf269552010-12-14 14:59:29 +00006523 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524 if (status)
6525 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006527 if (status)
6528 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006529 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530 if (status)
6531 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006532 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006533out:
6534 return status;
6535}
6536
6537/*
6538 * Decode READDIR response
6539 */
Chuck Leverbf269552010-12-14 14:59:29 +00006540static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6541 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006542{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543 struct compound_hdr hdr;
6544 int status;
6545
Chuck Leverbf269552010-12-14 14:59:29 +00006546 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547 if (status)
6548 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006549 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006550 if (status)
6551 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006552 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006553 if (status)
6554 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006555 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556out:
6557 return status;
6558}
6559
6560/*
6561 * Decode Read response
6562 */
Chuck Leverbf269552010-12-14 14:59:29 +00006563static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006564 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006565{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006566 struct compound_hdr hdr;
6567 int status;
6568
Chuck Leverbf269552010-12-14 14:59:29 +00006569 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006570 if (status)
6571 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006572 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006573 if (status)
6574 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006575 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006576 if (status)
6577 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006578 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006579 if (!status)
6580 status = res->count;
6581out:
6582 return status;
6583}
6584
6585/*
6586 * Decode WRITE response
6587 */
Chuck Leverbf269552010-12-14 14:59:29 +00006588static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006589 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006590{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006591 struct compound_hdr hdr;
6592 int status;
6593
Chuck Leverbf269552010-12-14 14:59:29 +00006594 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595 if (status)
6596 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006597 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006598 if (status)
6599 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006600 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006601 if (status)
6602 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006603 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006604 if (status)
6605 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006606 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006607 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006608 if (!status)
6609 status = res->count;
6610out:
6611 return status;
6612}
6613
6614/*
6615 * Decode COMMIT response
6616 */
Chuck Leverbf269552010-12-14 14:59:29 +00006617static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006618 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006619{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006620 struct compound_hdr hdr;
6621 int status;
6622
Chuck Leverbf269552010-12-14 14:59:29 +00006623 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006624 if (status)
6625 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006626 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006627 if (status)
6628 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006629 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006630 if (status)
6631 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006632 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633out:
6634 return status;
6635}
6636
6637/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006638 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006639 */
Chuck Leverbf269552010-12-14 14:59:29 +00006640static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006641 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006642{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643 struct compound_hdr hdr;
6644 int status;
6645
Chuck Leverbf269552010-12-14 14:59:29 +00006646 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006648 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006649 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006650 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006651 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006652 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653 return status;
6654}
6655
6656/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006657 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006658 */
Chuck Leverbf269552010-12-14 14:59:29 +00006659static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006660 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006661{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006662 struct compound_hdr hdr;
6663 int status;
6664
Chuck Leverbf269552010-12-14 14:59:29 +00006665 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006668 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006669 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006670 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006671 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672 return status;
6673}
6674
6675/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006676 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006677 */
Chuck Leverbf269552010-12-14 14:59:29 +00006678static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006679 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006680{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006681 struct compound_hdr hdr;
6682 int status;
6683
Chuck Leverbf269552010-12-14 14:59:29 +00006684 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006685 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006686 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006687 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006688 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006689 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006690 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006691 return status;
6692}
6693
6694/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006695 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006696 */
Chuck Leverbf269552010-12-14 14:59:29 +00006697static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6698 struct xdr_stream *xdr,
6699 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006700{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006701 struct compound_hdr hdr;
6702 int status;
6703
Chuck Leverbf269552010-12-14 14:59:29 +00006704 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006705 if (status)
6706 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006707 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006708 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006709 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006710 status = decode_putfh(xdr);
6711 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006713 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006714out:
6715 return status;
6716}
6717
6718/*
6719 * Decode RENEW response
6720 */
Chuck Leverbf269552010-12-14 14:59:29 +00006721static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6722 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006723{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006724 struct compound_hdr hdr;
6725 int status;
6726
Chuck Leverbf269552010-12-14 14:59:29 +00006727 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006728 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006729 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006730 return status;
6731}
6732
6733/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006734 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006735 */
Chuck Leverbf269552010-12-14 14:59:29 +00006736static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6737 struct xdr_stream *xdr,
6738 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006739{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006740 struct compound_hdr hdr;
6741 int status;
6742
Chuck Leverbf269552010-12-14 14:59:29 +00006743 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006744 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006745 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006746 return status;
6747}
6748
6749/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006750 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006751 */
Chuck Leverbf269552010-12-14 14:59:29 +00006752static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006753 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006754{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006755 struct compound_hdr hdr;
6756 int status;
6757
Chuck Leverbf269552010-12-14 14:59:29 +00006758 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006759 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006760 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006761 return status;
6762}
6763
6764/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006765 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766 */
Chuck Leverbf269552010-12-14 14:59:29 +00006767static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6768 struct xdr_stream *xdr,
6769 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006770{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006771 struct compound_hdr hdr;
6772 int status;
6773
Chuck Leverbf269552010-12-14 14:59:29 +00006774 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006775 if (status)
6776 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006777 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006778 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006779 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006780 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006781 if (status != 0)
6782 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006783 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006784 if (status != 0)
6785 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006786 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006787out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006788 return status;
6789}
6790
Trond Myklebust683b57b2006-06-09 09:34:22 -04006791/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006792 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006793 */
Chuck Leverbf269552010-12-14 14:59:29 +00006794static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6795 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006796 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006797{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006798 struct compound_hdr hdr;
6799 int status;
6800
Chuck Leverbf269552010-12-14 14:59:29 +00006801 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006802 if (status)
6803 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006804 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006805 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006806 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006807 status = decode_putfh(xdr);
6808 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006809 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006810 if (res->migration) {
6811 xdr_enter_page(xdr, PAGE_SIZE);
6812 status = decode_getfattr_generic(xdr,
6813 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006814 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006815 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006816 if (status)
6817 goto out;
6818 if (res->renew)
6819 status = decode_renew(xdr);
6820 } else {
6821 status = decode_lookup(xdr);
6822 if (status)
6823 goto out;
6824 xdr_enter_page(xdr, PAGE_SIZE);
6825 status = decode_getfattr_generic(xdr,
6826 &res->fs_locations->fattr,
6827 NULL, res->fs_locations,
6828 NULL, res->fs_locations->server);
6829 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006830out:
6831 return status;
6832}
6833
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006834/*
6835 * Decode SECINFO response
6836 */
6837static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6838 struct xdr_stream *xdr,
6839 struct nfs4_secinfo_res *res)
6840{
6841 struct compound_hdr hdr;
6842 int status;
6843
6844 status = decode_compound_hdr(xdr, &hdr);
6845 if (status)
6846 goto out;
6847 status = decode_sequence(xdr, &res->seq_res, rqstp);
6848 if (status)
6849 goto out;
6850 status = decode_putfh(xdr);
6851 if (status)
6852 goto out;
6853 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006854out:
6855 return status;
6856}
6857
Chuck Lever44c99932013-10-17 14:13:30 -04006858/*
6859 * Decode FSID_PRESENT response
6860 */
6861static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6862 struct xdr_stream *xdr,
6863 struct nfs4_fsid_present_res *res)
6864{
6865 struct compound_hdr hdr;
6866 int status;
6867
6868 status = decode_compound_hdr(xdr, &hdr);
6869 if (status)
6870 goto out;
6871 status = decode_sequence(xdr, &res->seq_res, rqstp);
6872 if (status)
6873 goto out;
6874 status = decode_putfh(xdr);
6875 if (status)
6876 goto out;
6877 status = decode_getfh(xdr, res->fh);
6878 if (status)
6879 goto out;
6880 if (res->renew)
6881 status = decode_renew(xdr);
6882out:
6883 return status;
6884}
6885
Benny Halevy99fe60d2009-04-01 09:22:29 -04006886#if defined(CONFIG_NFS_V4_1)
6887/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006888 * Decode BIND_CONN_TO_SESSION response
6889 */
6890static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6891 struct xdr_stream *xdr,
6892 void *res)
6893{
6894 struct compound_hdr hdr;
6895 int status;
6896
6897 status = decode_compound_hdr(xdr, &hdr);
6898 if (!status)
6899 status = decode_bind_conn_to_session(xdr, res);
6900 return status;
6901}
6902
6903/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006904 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006905 */
Chuck Leverbf269552010-12-14 14:59:29 +00006906static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6907 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006908 void *res)
6909{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006910 struct compound_hdr hdr;
6911 int status;
6912
Chuck Leverbf269552010-12-14 14:59:29 +00006913 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006914 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006915 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006916 return status;
6917}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006918
6919/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006920 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006921 */
Chuck Leverbf269552010-12-14 14:59:29 +00006922static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6923 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006924 struct nfs41_create_session_res *res)
6925{
Andy Adamsonfc931582009-04-01 09:22:31 -04006926 struct compound_hdr hdr;
6927 int status;
6928
Chuck Leverbf269552010-12-14 14:59:29 +00006929 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006930 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006931 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006932 return status;
6933}
6934
6935/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006936 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006937 */
Chuck Leverbf269552010-12-14 14:59:29 +00006938static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6939 struct xdr_stream *xdr,
6940 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006941{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006942 struct compound_hdr hdr;
6943 int status;
6944
Chuck Leverbf269552010-12-14 14:59:29 +00006945 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006946 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006947 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006948 return status;
6949}
6950
6951/*
Trond Myklebust66245532012-05-25 17:18:09 -04006952 * Decode DESTROY_CLIENTID response
6953 */
6954static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6955 struct xdr_stream *xdr,
6956 void *res)
6957{
6958 struct compound_hdr hdr;
6959 int status;
6960
6961 status = decode_compound_hdr(xdr, &hdr);
6962 if (!status)
6963 status = decode_destroy_clientid(xdr, res);
6964 return status;
6965}
6966
6967/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006968 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006969 */
Chuck Leverbf269552010-12-14 14:59:29 +00006970static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6971 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006972 struct nfs4_sequence_res *res)
6973{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006974 struct compound_hdr hdr;
6975 int status;
6976
Chuck Leverbf269552010-12-14 14:59:29 +00006977 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006978 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006979 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006980 return status;
6981}
6982
6983/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006984 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006985 */
Chuck Leverbf269552010-12-14 14:59:29 +00006986static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6987 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006988 struct nfs4_get_lease_time_res *res)
6989{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006990 struct compound_hdr hdr;
6991 int status;
6992
Chuck Leverbf269552010-12-14 14:59:29 +00006993 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006994 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006995 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006996 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006997 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006998 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006999 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007000 return status;
7001}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007002
7003/*
7004 * Decode RECLAIM_COMPLETE response
7005 */
Chuck Leverbf269552010-12-14 14:59:29 +00007006static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7007 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007008 struct nfs41_reclaim_complete_res *res)
7009{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007010 struct compound_hdr hdr;
7011 int status;
7012
Chuck Leverbf269552010-12-14 14:59:29 +00007013 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007014 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007015 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007016 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307017 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007018 return status;
7019}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007020
7021/*
7022 * Decode GETDEVINFO response
7023 */
Chuck Leverbf269552010-12-14 14:59:29 +00007024static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7025 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007026 struct nfs4_getdeviceinfo_res *res)
7027{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007028 struct compound_hdr hdr;
7029 int status;
7030
Chuck Leverbf269552010-12-14 14:59:29 +00007031 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007032 if (status != 0)
7033 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007034 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007035 if (status != 0)
7036 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007037 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007038out:
7039 return status;
7040}
7041
7042/*
7043 * Decode LAYOUTGET response
7044 */
Chuck Leverbf269552010-12-14 14:59:29 +00007045static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7046 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007047 struct nfs4_layoutget_res *res)
7048{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007049 struct compound_hdr hdr;
7050 int status;
7051
Chuck Leverbf269552010-12-14 14:59:29 +00007052 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007053 if (status)
7054 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007055 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007056 if (status)
7057 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007058 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007059 if (status)
7060 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007061 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007062out:
7063 return status;
7064}
Andy Adamson863a3c62011-03-23 13:27:54 +00007065
7066/*
Benny Halevycbe82602011-05-22 19:52:37 +03007067 * Decode LAYOUTRETURN response
7068 */
7069static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7070 struct xdr_stream *xdr,
7071 struct nfs4_layoutreturn_res *res)
7072{
7073 struct compound_hdr hdr;
7074 int status;
7075
7076 status = decode_compound_hdr(xdr, &hdr);
7077 if (status)
7078 goto out;
7079 status = decode_sequence(xdr, &res->seq_res, rqstp);
7080 if (status)
7081 goto out;
7082 status = decode_putfh(xdr);
7083 if (status)
7084 goto out;
7085 status = decode_layoutreturn(xdr, res);
7086out:
7087 return status;
7088}
7089
7090/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007091 * Decode LAYOUTCOMMIT response
7092 */
7093static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7094 struct xdr_stream *xdr,
7095 struct nfs4_layoutcommit_res *res)
7096{
7097 struct compound_hdr hdr;
7098 int status;
7099
7100 status = decode_compound_hdr(xdr, &hdr);
7101 if (status)
7102 goto out;
7103 status = decode_sequence(xdr, &res->seq_res, rqstp);
7104 if (status)
7105 goto out;
7106 status = decode_putfh(xdr);
7107 if (status)
7108 goto out;
7109 status = decode_layoutcommit(xdr, rqstp, res);
7110 if (status)
7111 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007112 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007113out:
7114 return status;
7115}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007116
7117/*
7118 * Decode SECINFO_NO_NAME response
7119 */
7120static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7121 struct xdr_stream *xdr,
7122 struct nfs4_secinfo_res *res)
7123{
7124 struct compound_hdr hdr;
7125 int status;
7126
7127 status = decode_compound_hdr(xdr, &hdr);
7128 if (status)
7129 goto out;
7130 status = decode_sequence(xdr, &res->seq_res, rqstp);
7131 if (status)
7132 goto out;
7133 status = decode_putrootfh(xdr);
7134 if (status)
7135 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007136 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007137out:
7138 return status;
7139}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007140
7141/*
7142 * Decode TEST_STATEID response
7143 */
7144static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7145 struct xdr_stream *xdr,
7146 struct nfs41_test_stateid_res *res)
7147{
7148 struct compound_hdr hdr;
7149 int status;
7150
7151 status = decode_compound_hdr(xdr, &hdr);
7152 if (status)
7153 goto out;
7154 status = decode_sequence(xdr, &res->seq_res, rqstp);
7155 if (status)
7156 goto out;
7157 status = decode_test_stateid(xdr, res);
7158out:
7159 return status;
7160}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007161
7162/*
7163 * Decode FREE_STATEID response
7164 */
7165static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7166 struct xdr_stream *xdr,
7167 struct nfs41_free_stateid_res *res)
7168{
7169 struct compound_hdr hdr;
7170 int status;
7171
7172 status = decode_compound_hdr(xdr, &hdr);
7173 if (status)
7174 goto out;
7175 status = decode_sequence(xdr, &res->seq_res, rqstp);
7176 if (status)
7177 goto out;
7178 status = decode_free_stateid(xdr, res);
7179out:
7180 return status;
7181}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007182#endif /* CONFIG_NFS_V4_1 */
7183
Chuck Lever573c4e12010-12-14 14:58:11 +00007184/**
7185 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7186 * the local page cache.
7187 * @xdr: XDR stream where entry resides
7188 * @entry: buffer to fill in with entry data
7189 * @plus: boolean indicating whether this should be a readdirplus entry
7190 *
7191 * Returns zero if successful, otherwise a negative errno value is
7192 * returned.
7193 *
7194 * This function is not invoked during READDIR reply decoding, but
7195 * rather whenever an application invokes the getdents(2) system call
7196 * on a directory already in our cache.
7197 */
7198int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7199 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007200{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007201 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007202 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007203 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007204 __be32 *p = xdr_inline_decode(xdr, 4);
7205 if (unlikely(!p))
7206 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007207 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007208 p = xdr_inline_decode(xdr, 4);
7209 if (unlikely(!p))
7210 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007211 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007212 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007213 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007214 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007215 }
7216
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007217 p = xdr_inline_decode(xdr, 12);
7218 if (unlikely(!p))
7219 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007220 entry->prev_cookie = entry->cookie;
7221 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007222 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007223
Trond Myklebust9af8c222010-10-24 11:52:55 -04007224 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007225 if (unlikely(!p))
7226 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007227 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007228
7229 /*
7230 * In case the server doesn't return an inode number,
7231 * we fake one here. (We don't use inode number 0,
7232 * since glibc seems to choke on it...)
7233 */
7234 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007235 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007236
Trond Myklebust9af8c222010-10-24 11:52:55 -04007237 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007238 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007239
Trond Myklebust256e48b2012-06-21 11:18:13 -04007240 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007241 goto out_overflow;
7242
Chuck Lever573c4e12010-12-14 14:58:11 +00007243 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007244 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007245 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007246 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7247 entry->ino = entry->fattr->mounted_on_fileid;
7248 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007249 entry->ino = entry->fattr->fileid;
7250
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007251 entry->d_type = DT_UNKNOWN;
7252 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7253 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7254
Chuck Lever573c4e12010-12-14 14:58:11 +00007255 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007256
7257out_overflow:
7258 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007259 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007260}
7261
7262/*
7263 * We need to translate between nfs status return values and
7264 * the local errno values which may not be the same.
7265 */
7266static struct {
7267 int stat;
7268 int errno;
7269} nfs_errtbl[] = {
7270 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007271 { NFS4ERR_PERM, -EPERM },
7272 { NFS4ERR_NOENT, -ENOENT },
7273 { NFS4ERR_IO, -errno_NFSERR_IO},
7274 { NFS4ERR_NXIO, -ENXIO },
7275 { NFS4ERR_ACCESS, -EACCES },
7276 { NFS4ERR_EXIST, -EEXIST },
7277 { NFS4ERR_XDEV, -EXDEV },
7278 { NFS4ERR_NOTDIR, -ENOTDIR },
7279 { NFS4ERR_ISDIR, -EISDIR },
7280 { NFS4ERR_INVAL, -EINVAL },
7281 { NFS4ERR_FBIG, -EFBIG },
7282 { NFS4ERR_NOSPC, -ENOSPC },
7283 { NFS4ERR_ROFS, -EROFS },
7284 { NFS4ERR_MLINK, -EMLINK },
7285 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7286 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7287 { NFS4ERR_DQUOT, -EDQUOT },
7288 { NFS4ERR_STALE, -ESTALE },
7289 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007290 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7291 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7292 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007293 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007294 { NFS4ERR_BADTYPE, -EBADTYPE },
7295 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007296 { NFS4ERR_SYMLINK, -ELOOP },
7297 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7298 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007299 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007300};
7301
7302/*
7303 * Convert an NFS error code to a local one.
7304 * This one is used jointly by NFSv2 and NFSv3.
7305 */
7306static int
David Howells0a8ea432006-08-22 20:06:08 -04007307nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007308{
7309 int i;
7310 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7311 if (nfs_errtbl[i].stat == stat)
7312 return nfs_errtbl[i].errno;
7313 }
7314 if (stat <= 10000 || stat > 10100) {
7315 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007316 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007317 }
7318 /* If we cannot translate the error, the recovery routines should
7319 * handle it.
7320 * Note: remaining NFSv4 error codes have values > 10000, so should
7321 * not conflict with native Linux error codes.
7322 */
Benny Halevy856dff32008-03-31 17:39:06 +03007323 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007324}
7325
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007326#ifdef CONFIG_NFS_V4_2
7327#include "nfs42xdr.c"
7328#endif /* CONFIG_NFS_V4_2 */
7329
Linus Torvalds1da177e2005-04-16 15:20:36 -07007330#define PROC(proc, argtype, restype) \
7331[NFSPROC4_CLNT_##proc] = { \
7332 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007333 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007334 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007335 .p_arglen = NFS4_##argtype##_sz, \
7336 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007337 .p_statidx = NFSPROC4_CLNT_##proc, \
7338 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007339}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007340
7341struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007342 PROC(READ, enc_read, dec_read),
7343 PROC(WRITE, enc_write, dec_write),
7344 PROC(COMMIT, enc_commit, dec_commit),
7345 PROC(OPEN, enc_open, dec_open),
7346 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7347 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7348 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7349 PROC(CLOSE, enc_close, dec_close),
7350 PROC(SETATTR, enc_setattr, dec_setattr),
7351 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7352 PROC(RENEW, enc_renew, dec_renew),
7353 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7354 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7355 PROC(LOCK, enc_lock, dec_lock),
7356 PROC(LOCKT, enc_lockt, dec_lockt),
7357 PROC(LOCKU, enc_locku, dec_locku),
7358 PROC(ACCESS, enc_access, dec_access),
7359 PROC(GETATTR, enc_getattr, dec_getattr),
7360 PROC(LOOKUP, enc_lookup, dec_lookup),
7361 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7362 PROC(REMOVE, enc_remove, dec_remove),
7363 PROC(RENAME, enc_rename, dec_rename),
7364 PROC(LINK, enc_link, dec_link),
7365 PROC(SYMLINK, enc_symlink, dec_symlink),
7366 PROC(CREATE, enc_create, dec_create),
7367 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7368 PROC(STATFS, enc_statfs, dec_statfs),
7369 PROC(READLINK, enc_readlink, dec_readlink),
7370 PROC(READDIR, enc_readdir, dec_readdir),
7371 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7372 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7373 PROC(GETACL, enc_getacl, dec_getacl),
7374 PROC(SETACL, enc_setacl, dec_setacl),
7375 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7376 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007377 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007378 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007379#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007380 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7381 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7382 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7383 PROC(SEQUENCE, enc_sequence, dec_sequence),
7384 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7385 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7386 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7387 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007388 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007389 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007390 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007391 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007392 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007393 PROC(BIND_CONN_TO_SESSION,
7394 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007395 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007396#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007397#ifdef CONFIG_NFS_V4_2
7398 PROC(SEEK, enc_seek, dec_seek),
7399#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007400};
7401
Trond Myklebusta613fa12012-01-20 13:53:56 -05007402const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007403 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007404 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007405 .procs = nfs4_procedures
7406};
7407
7408/*
7409 * Local variables:
7410 * c-basic-offset: 8
7411 * End:
7412 */