blob: f58e8a9793971d73637c66ddcdf1e58197506a36 [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>
Chuck Leverf0920752012-05-21 22:45:41 -040055
Trond Myklebust4ce79712005-06-22 17:16:21 +000056#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050057#include "internal.h"
Anna Schumaker40c64c22015-04-15 13:00:05 -040058#include "nfs4idmap.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{
Trond Myklebusta6796412015-01-23 19:04:44 -0500949 if (seqid != NULL)
950 encode_uint32(xdr, seqid->sequence->counter);
951 else
952 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500953}
954
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400955static void encode_compound_hdr(struct xdr_stream *xdr,
956 struct rpc_rqst *req,
957 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958{
Al Viro8687b632006-10-19 23:28:48 -0700959 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400960 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400961
962 /* initialize running count of expected bytes in reply.
963 * NOTE: the replied tag SHOULD be the same is the one sent,
964 * but this is not required as a MUST for the server to do so. */
965 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Trond Myklebust7fc38842012-10-15 11:51:21 -0400967 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500968 encode_string(xdr, hdr->taglen, hdr->tag);
969 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300970 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500971 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300972 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500973}
974
Trond Myklebustab19b482012-03-04 18:13:57 -0500975static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
976 uint32_t replen,
977 struct compound_hdr *hdr)
978{
979 encode_uint32(xdr, op);
980 hdr->nops++;
981 hdr->replen += replen;
982}
983
Andy Adamsond0179312008-12-23 16:06:17 -0500984static void encode_nops(struct compound_hdr *hdr)
985{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400986 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500987 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988}
989
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500990static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
991{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500992 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500993}
994
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
996{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500997 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998}
999
David Quigleyaa9c2662013-05-22 12:50:44 -04001000static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1001 const struct nfs4_label *label,
1002 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003{
1004 char owner_name[IDMAP_NAMESZ];
1005 char owner_group[IDMAP_NAMESZ];
1006 int owner_namelen = 0;
1007 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001008 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001009 unsigned i;
1010 uint32_t len = 0;
1011 uint32_t bmval_len;
1012 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
1014 /*
1015 * We reserve enough space to write the entire attribute buffer at once.
1016 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001017 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1018 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001019 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001021 if (iap->ia_valid & ATTR_SIZE) {
1022 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001024 }
1025 if (iap->ia_valid & ATTR_MODE) {
1026 bmval[1] |= FATTR4_WORD1_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 len += 4;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001028 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001030 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001032 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001033 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 /* XXX */
1035 strcpy(owner_name, "nobody");
1036 owner_namelen = sizeof("nobody") - 1;
1037 /* goto out; */
1038 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001039 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1041 }
1042 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001043 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001045 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001046 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 strcpy(owner_group, "nobody");
1048 owner_grouplen = sizeof("nobody") - 1;
1049 /* goto out; */
1050 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001051 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1053 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001055 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1056 len += 16;
1057 } else if (iap->ia_valid & ATTR_ATIME) {
1058 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1059 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 }
1061 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001062 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1063 len += 16;
1064 } else if (iap->ia_valid & ATTR_MTIME) {
1065 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1066 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001068 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001069 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1070 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1071 }
1072
1073 if (bmval[2] != 0)
1074 bmval_len = 3;
1075 else if (bmval[1] != 0)
1076 bmval_len = 2;
1077 else
1078 bmval_len = 1;
1079
1080 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1081
1082 *p++ = cpu_to_be32(bmval_len);
1083 for (i = 0; i < bmval_len; i++)
1084 *p++ = cpu_to_be32(bmval[i]);
1085 *p++ = cpu_to_be32(len);
1086
1087 if (bmval[0] & FATTR4_WORD0_SIZE)
1088 p = xdr_encode_hyper(p, iap->ia_size);
1089 if (bmval[1] & FATTR4_WORD1_MODE)
1090 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1091 if (bmval[1] & FATTR4_WORD1_OWNER)
1092 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1093 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1094 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1095 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1096 if (iap->ia_valid & ATTR_ATIME_SET) {
1097 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1098 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1099 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1100 } else
1101 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1102 }
1103 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1104 if (iap->ia_valid & ATTR_MTIME_SET) {
1105 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1106 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1107 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1108 } else
1109 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1110 }
1111 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001112 *p++ = cpu_to_be32(label->lfs);
1113 *p++ = cpu_to_be32(label->pi);
1114 *p++ = cpu_to_be32(label->len);
1115 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1116 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001117
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119}
1120
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001121static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001123 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1124 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125}
1126
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001127static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128{
Trond Myklebustab19b482012-03-04 18:13:57 -05001129 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001130 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001131 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132}
1133
Fred Isaman0b7c0152012-04-20 14:47:39 -04001134static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135{
Al Viro8687b632006-10-19 23:28:48 -07001136 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001137
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001138 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1139 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001140 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001141 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
1143
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001144static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
Al Viro8687b632006-10-19 23:28:48 -07001146 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001147
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001148 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1149 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
1151 switch (create->ftype) {
1152 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001153 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001154 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001155 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 break;
1157
1158 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001159 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001160 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001161 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 break;
1163
1164 default:
1165 break;
1166 }
1167
Benny Halevy811652b2009-08-14 17:19:34 +03001168 encode_string(xdr, create->name->len, create->name->name);
David Quigleyaa9c2662013-05-22 12:50:44 -04001169 encode_attrs(xdr, create->attrs, create->label, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170}
1171
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001172static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173{
Andy Adamson05d564f2008-12-23 16:06:15 -05001174 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001176 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1177 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001178 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001179 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180}
1181
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001182static 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 -07001183{
Andy Adamson05d564f2008-12-23 16:06:15 -05001184 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001186 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1187 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001188 *p++ = cpu_to_be32(2);
1189 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001190 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191}
1192
Fred Isamandae100c2011-07-30 20:52:37 -04001193static void
1194encode_getattr_three(struct xdr_stream *xdr,
1195 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1196 struct compound_hdr *hdr)
1197{
1198 __be32 *p;
1199
Trond Myklebustab19b482012-03-04 18:13:57 -05001200 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001201 if (bm2) {
1202 p = reserve_space(xdr, 16);
1203 *p++ = cpu_to_be32(3);
1204 *p++ = cpu_to_be32(bm0);
1205 *p++ = cpu_to_be32(bm1);
1206 *p = cpu_to_be32(bm2);
1207 } else if (bm1) {
1208 p = reserve_space(xdr, 12);
1209 *p++ = cpu_to_be32(2);
1210 *p++ = cpu_to_be32(bm0);
1211 *p = cpu_to_be32(bm1);
1212 } else {
1213 p = reserve_space(xdr, 8);
1214 *p++ = cpu_to_be32(1);
1215 *p = cpu_to_be32(bm0);
1216 }
Fred Isamandae100c2011-07-30 20:52:37 -04001217}
1218
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001219static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220{
David Quigleya09df2c2013-05-22 12:50:41 -04001221 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1222 bitmask[1] & nfs4_fattr_bitmap[1],
1223 bitmask[2] & nfs4_fattr_bitmap[2],
1224 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225}
1226
Andy Adamson88034c32012-05-23 05:02:34 -04001227static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001228 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001229 struct compound_hdr *hdr)
1230{
1231 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001232 bitmask[0] & open_bitmap[0],
1233 bitmask[1] & open_bitmap[1],
1234 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001235 hdr);
1236}
1237
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001238static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239{
Fred Isamandae100c2011-07-30 20:52:37 -04001240 encode_getattr_three(xdr,
1241 bitmask[0] & nfs4_fsinfo_bitmap[0],
1242 bitmask[1] & nfs4_fsinfo_bitmap[1],
1243 bitmask[2] & nfs4_fsinfo_bitmap[2],
1244 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245}
1246
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001247static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001248{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001249 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1250 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001251}
1252
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001253static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254{
Trond Myklebustab19b482012-03-04 18:13:57 -05001255 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256}
1257
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001258static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259{
Trond Myklebustab19b482012-03-04 18:13:57 -05001260 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001261 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262}
1263
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001264static inline int nfs4_lock_type(struct file_lock *fl, int block)
1265{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001266 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001267 return block ? NFS4_READW_LT : NFS4_READ_LT;
1268 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1269}
1270
1271static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1272{
1273 if (fl->fl_end == OFFSET_MAX)
1274 return ~(uint64_t)0;
1275 return fl->fl_end - fl->fl_start + 1;
1276}
1277
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001278static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1279{
1280 __be32 *p;
1281
Trond Myklebustd035c362010-12-21 10:45:27 -05001282 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001283 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001284 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001285 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001286 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001287 xdr_encode_hyper(p, lowner->id);
1288}
1289
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290/*
1291 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1292 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1293 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001294static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295{
Al Viro8687b632006-10-19 23:28:48 -07001296 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001298 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1299 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001300 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1301 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001302 p = xdr_encode_hyper(p, args->fl->fl_start);
1303 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001304 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001305 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001306 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001307 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001308 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001309 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 }
1311 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001312 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001313 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315}
1316
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001317static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318{
Al Viro8687b632006-10-19 23:28:48 -07001319 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001321 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1322 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001323 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001324 p = xdr_encode_hyper(p, args->fl->fl_start);
1325 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001326 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327}
1328
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001329static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330{
Al Viro8687b632006-10-19 23:28:48 -07001331 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001333 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1334 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001335 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001336 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001337 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001338 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001339 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340}
1341
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001342static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1343{
Trond Myklebustab19b482012-03-04 18:13:57 -05001344 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001345 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001346}
1347
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001348static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349{
Trond Myklebustab19b482012-03-04 18:13:57 -05001350 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001351 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352}
1353
Trond Myklebust6ae37332015-01-30 14:21:14 -05001354static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355{
Al Viro8687b632006-10-19 23:28:48 -07001356 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Benny Halevy13c65ce2009-08-14 17:19:25 +03001358 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001359 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001360 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361}
1362
1363static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1364{
Al Viro8687b632006-10-19 23:28:48 -07001365 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 /*
1367 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1368 * owner 4 = 32
1369 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001370 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001371 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001372 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001373 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001374 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001375 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001376 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001377 *p++ = cpu_to_be32(arg->id.uniquifier);
1378 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379}
1380
1381static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1382{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001383 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001384 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
Benny Halevy13c65ce2009-08-14 17:19:25 +03001386 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001387 switch(arg->createmode) {
1388 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001389 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001390 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Andy Adamson05d564f2008-12-23 16:06:15 -05001391 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001392 case NFS4_CREATE_GUARDED:
1393 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001394 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001395 break;
1396 case NFS4_CREATE_EXCLUSIVE:
1397 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1398 encode_nfs4_verifier(xdr, &arg->u.verifier);
1399 break;
1400 case NFS4_CREATE_EXCLUSIVE4_1:
1401 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1402 encode_nfs4_verifier(xdr, &arg->u.verifier);
1403 dummy.ia_valid = 0;
David Quigleyaa9c2662013-05-22 12:50:44 -04001404 encode_attrs(xdr, &dummy, arg->label, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 }
1406}
1407
1408static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1409{
Al Viro8687b632006-10-19 23:28:48 -07001410 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
Benny Halevy13c65ce2009-08-14 17:19:25 +03001412 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001414 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001415 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001416 break;
1417 default:
Benny Halevy34558512009-08-14 17:19:30 +03001418 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001419 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 }
1421}
1422
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001423static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424{
Al Viro8687b632006-10-19 23:28:48 -07001425 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
Benny Halevy13c65ce2009-08-14 17:19:25 +03001427 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001429 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001430 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001431 break;
1432 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001433 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001434 break;
1435 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001436 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001437 break;
1438 default:
1439 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 }
1441}
1442
1443static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1444{
Al Viro8687b632006-10-19 23:28:48 -07001445 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Benny Halevy13c65ce2009-08-14 17:19:25 +03001447 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001448 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 encode_string(xdr, name->len, name->name);
1450}
1451
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001452static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453{
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_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 encode_delegation_type(xdr, type);
1459}
1460
1461static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1462{
Al Viro8687b632006-10-19 23:28:48 -07001463 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001465 p = reserve_space(xdr, 4);
1466 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1467 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 encode_string(xdr, name->len, name->name);
1469}
1470
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001471static inline void encode_claim_fh(struct xdr_stream *xdr)
1472{
1473 __be32 *p;
1474
1475 p = reserve_space(xdr, 4);
1476 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1477}
1478
1479static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1480{
1481 __be32 *p;
1482
1483 p = reserve_space(xdr, 4);
1484 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1485 encode_nfs4_stateid(xdr, stateid);
1486}
1487
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001488static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489{
Trond Myklebustab19b482012-03-04 18:13:57 -05001490 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 encode_openhdr(xdr, arg);
1492 encode_opentype(xdr, arg);
1493 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001494 case NFS4_OPEN_CLAIM_NULL:
1495 encode_claim_null(xdr, arg->name);
1496 break;
1497 case NFS4_OPEN_CLAIM_PREVIOUS:
1498 encode_claim_previous(xdr, arg->u.delegation_type);
1499 break;
1500 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1501 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1502 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001503 case NFS4_OPEN_CLAIM_FH:
1504 encode_claim_fh(xdr);
1505 break;
1506 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1507 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1508 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001509 default:
1510 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512}
1513
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001514static 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 -07001515{
Trond Myklebustab19b482012-03-04 18:13:57 -05001516 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001517 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001518 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519}
1520
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001521static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522{
Trond Myklebustab19b482012-03-04 18:13:57 -05001523 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001524 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001525 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001526 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527}
1528
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001529static void
Andy Adamsond0179312008-12-23 16:06:17 -05001530encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, 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_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001533 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534}
1535
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001536static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537{
Trond Myklebustab19b482012-03-04 18:13:57 -05001538 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539}
1540
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001541static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1542 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543{
Al Viro8687b632006-10-19 23:28:48 -07001544 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
Trond Myklebustab19b482012-03-04 18:13:57 -05001546 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001547 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
Benny Halevy13c65ce2009-08-14 17:19:25 +03001549 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001550 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001551 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552}
1553
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001554static 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 -07001555{
David Quigleyaa9c2662013-05-22 12:50:44 -04001556 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001557 FATTR4_WORD0_RDATTR_ERROR,
1558 FATTR4_WORD1_MOUNTED_ON_FILEID,
1559 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001560 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001561 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001562 uint32_t attrlen = 0;
1563 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001565 if (readdir->plus) {
1566 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001567 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001568 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1569 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1570 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1571 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001572 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001573 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001574 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001575 /* Use mounted_on_fileid only if the server supports it */
1576 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1577 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001578 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1579 attrs[i] &= readdir->bitmask[i];
1580 if (attrs[i] != 0)
1581 attrlen = i+1;
1582 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001583
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001584 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001585 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001586 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001587 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001588 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001589 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001590 *p++ = cpu_to_be32(attrlen);
1591 for (i = 0; i < attrlen; i++)
1592 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001593 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001594
1595 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001596 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001597 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001598 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001599 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001600 attrs[1] & readdir->bitmask[1],
1601 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602}
1603
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001604static 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 -07001605{
Trond Myklebustab19b482012-03-04 18:13:57 -05001606 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607}
1608
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001609static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610{
Trond Myklebustab19b482012-03-04 18:13:57 -05001611 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001612 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613}
1614
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001615static 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 -07001616{
Trond Myklebustab19b482012-03-04 18:13:57 -05001617 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001618 encode_string(xdr, oldname->len, oldname->name);
1619 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620}
1621
Chuck Leverbb4dae52012-03-01 17:01:48 -05001622static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1623 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001625 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001626 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627}
1628
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001629static void
Andy Adamsond0179312008-12-23 16:06:17 -05001630encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001631{
Trond Myklebustab19b482012-03-04 18:13:57 -05001632 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001633}
1634
Chuck Lever9f06c712010-12-14 14:59:18 +00001635static void
Andy Adamsond0179312008-12-23 16:06:17 -05001636encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001637{
Al Viro8687b632006-10-19 23:28:48 -07001638 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001639
Trond Myklebustab19b482012-03-04 18:13:57 -05001640 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001641 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001642 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001643 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001644 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001645 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001646 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001647 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001648}
1649
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001650static void
Andy Adamsond0179312008-12-23 16:06:17 -05001651encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652{
Trond Myklebustab19b482012-03-04 18:13:57 -05001653 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654}
1655
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001656static 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 -07001657{
Trond Myklebustab19b482012-03-04 18:13:57 -05001658 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001659 encode_nfs4_stateid(xdr, &arg->stateid);
David Quigleyaa9c2662013-05-22 12:50:44 -04001660 encode_attrs(xdr, arg->iap, arg->label, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661}
1662
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001663static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664{
Al Viro8687b632006-10-19 23:28:48 -07001665 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
Trond Myklebust70019512012-03-04 20:49:32 -05001667 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001668 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
Jeff Layton3a6bb732015-06-09 19:43:57 -04001670 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1671 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001672 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001673 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1675 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001676 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001677 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678}
1679
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001680static 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 -07001681{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001682 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1683 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001684 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001685 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686}
1687
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001688static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1689 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690{
Al Viro8687b632006-10-19 23:28:48 -07001691 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
Trond Myklebustab19b482012-03-04 18:13:57 -05001693 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001694 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
Benny Halevy13c65ce2009-08-14 17:19:25 +03001696 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001697 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001698 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001699 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
1701 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702}
1703
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001704static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705{
Trond Myklebustab19b482012-03-04 18:13:57 -05001706 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001707 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001709
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001710static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1711{
Trond Myklebustab19b482012-03-04 18:13:57 -05001712 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001713 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001714}
1715
Benny Halevy99fe60d2009-04-01 09:22:29 -04001716#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001717/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001718static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08001719 struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001720 struct compound_hdr *hdr)
1721{
1722 __be32 *p;
1723
1724 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1725 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001726 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001727 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001728 *p++ = cpu_to_be32(args->dir);
1729 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001730}
1731
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001732static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1733{
1734 unsigned int i;
1735 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1736 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1737 encode_uint32(xdr, op_map->u.words[i]);
1738}
1739
Benny Halevy99fe60d2009-04-01 09:22:29 -04001740static void encode_exchange_id(struct xdr_stream *xdr,
1741 struct nfs41_exchange_id_args *args,
1742 struct compound_hdr *hdr)
1743{
1744 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001745 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001746 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001747
Trond Myklebust70019512012-03-04 20:49:32 -05001748 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001749 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001750
Jeff Layton3a6bb732015-06-09 19:43:57 -04001751 encode_string(xdr, strlen(args->client->cl_owner_id),
1752 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001753
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001754 encode_uint32(xdr, args->flags);
1755 encode_uint32(xdr, args->state_protect.how);
1756
1757 switch (args->state_protect.how) {
1758 case SP4_NONE:
1759 break;
1760 case SP4_MACH_CRED:
1761 encode_op_map(xdr, &args->state_protect.enforce);
1762 encode_op_map(xdr, &args->state_protect.allow);
1763 break;
1764 default:
1765 WARN_ON_ONCE(1);
1766 break;
1767 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001768
1769 if (send_implementation_id &&
1770 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1771 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001772 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001773 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1774 utsname()->sysname, utsname()->release,
1775 utsname()->version, utsname()->machine);
1776
1777 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001778 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001779
1780 encode_string(xdr,
1781 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1782 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1783 encode_string(xdr, len, impl_name);
1784 /* just send zeros for nii_date - the date is in nii_name */
1785 p = reserve_space(xdr, 12);
1786 p = xdr_encode_hyper(p, 0);
1787 *p = cpu_to_be32(0);
1788 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001789 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001790}
Andy Adamsonfc931582009-04-01 09:22:31 -04001791
1792static void encode_create_session(struct xdr_stream *xdr,
1793 struct nfs41_create_session_args *args,
1794 struct compound_hdr *hdr)
1795{
1796 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001797 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001798 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001799 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001800 u32 max_resp_sz_cached;
1801
1802 /*
1803 * Assumes OPEN is the biggest non-idempotent compound.
1804 * 2 is the verifier.
1805 */
1806 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1807 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001808
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001809 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001810 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001811 p = xdr_encode_hyper(p, args->clientid);
1812 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001813 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001814
Andy Adamsonfc931582009-04-01 09:22:31 -04001815 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001816 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001817 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1818 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001819 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001820 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1821 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1822 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001823
1824 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001825 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001826 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1827 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1828 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1829 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1830 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1831 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001832
Benny Halevye75bc1c2009-08-14 17:18:54 +03001833 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001834 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001835 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001836
1837 /* authsys_parms rfc1831 */
Trond Myklebust17f26b12013-08-21 15:48:42 -04001838 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001839 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001840 *p++ = cpu_to_be32(0); /* UID */
1841 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001842 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001843}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001844
1845static void encode_destroy_session(struct xdr_stream *xdr,
1846 struct nfs4_session *session,
1847 struct compound_hdr *hdr)
1848{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001849 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1850 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001851}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001852
Trond Myklebust66245532012-05-25 17:18:09 -04001853static void encode_destroy_clientid(struct xdr_stream *xdr,
1854 uint64_t clientid,
1855 struct compound_hdr *hdr)
1856{
1857 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1858 encode_uint64(xdr, clientid);
1859}
1860
Ricardo Labiaga180197532009-12-05 16:08:40 -05001861static void encode_reclaim_complete(struct xdr_stream *xdr,
1862 struct nfs41_reclaim_complete_args *args,
1863 struct compound_hdr *hdr)
1864{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001865 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1866 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001867}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001868#endif /* CONFIG_NFS_V4_1 */
1869
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001870static void encode_sequence(struct xdr_stream *xdr,
1871 const struct nfs4_sequence_args *args,
1872 struct compound_hdr *hdr)
1873{
1874#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001875 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001876 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001877 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001878 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001879
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001880 tp = slot->table;
1881 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001882 if (!session)
1883 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001884
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001885 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001886
1887 /*
1888 * Sessionid + seqid + slotid + max slotid + cache_this
1889 */
1890 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1891 "max_slotid=%d cache_this=%d\n",
1892 __func__,
1893 ((u32 *)session->sess_id.data)[0],
1894 ((u32 *)session->sess_id.data)[1],
1895 ((u32 *)session->sess_id.data)[2],
1896 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001897 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001898 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001899 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001900 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001901 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001902 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001903 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001904 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001905#endif /* CONFIG_NFS_V4_1 */
1906}
1907
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001908#ifdef CONFIG_NFS_V4_1
1909static void
1910encode_getdeviceinfo(struct xdr_stream *xdr,
1911 const struct nfs4_getdeviceinfo_args *args,
1912 struct compound_hdr *hdr)
1913{
1914 __be32 *p;
1915
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001916 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001917 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001918 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1919 NFS4_DEVICEID4_SIZE);
1920 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001921 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001922
1923 p = reserve_space(xdr, 4 + 4);
1924 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001925 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001926}
1927
1928static void
1929encode_layoutget(struct xdr_stream *xdr,
1930 const struct nfs4_layoutget_args *args,
1931 struct compound_hdr *hdr)
1932{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001933 __be32 *p;
1934
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001935 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1936 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001937 *p++ = cpu_to_be32(0); /* Signal layout available */
1938 *p++ = cpu_to_be32(args->type);
1939 *p++ = cpu_to_be32(args->range.iomode);
1940 p = xdr_encode_hyper(p, args->range.offset);
1941 p = xdr_encode_hyper(p, args->range.length);
1942 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001943 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001944 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001945
1946 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1947 __func__,
1948 args->type,
1949 args->range.iomode,
1950 (unsigned long)args->range.offset,
1951 (unsigned long)args->range.length,
1952 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001953}
Andy Adamson863a3c62011-03-23 13:27:54 +00001954
1955static int
1956encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001957 struct inode *inode,
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001958 struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001959 struct compound_hdr *hdr)
1960{
1961 __be32 *p;
1962
1963 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1964 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1965
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001966 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1967 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001968 /* Only whole file layouts */
1969 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001970 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001971 *p = cpu_to_be32(0); /* reclaim */
1972 encode_nfs4_stateid(xdr, &args->stateid);
1973 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001974 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1975 p = xdr_encode_hyper(p, args->lastbytewritten);
1976 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1977 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001978
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001979 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
Benny Halevyac7db722011-05-22 19:53:48 +03001980 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1981 NFS_I(inode)->layout, xdr, args);
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001982 } else {
1983 encode_uint32(xdr, args->layoutupdate_len);
1984 if (args->layoutupdate_pages) {
1985 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
1986 args->layoutupdate_len);
1987 }
1988 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001989
Andy Adamson863a3c62011-03-23 13:27:54 +00001990 return 0;
1991}
Benny Halevycbe82602011-05-22 19:52:37 +03001992
1993static void
1994encode_layoutreturn(struct xdr_stream *xdr,
1995 const struct nfs4_layoutreturn_args *args,
1996 struct compound_hdr *hdr)
1997{
1998 __be32 *p;
1999
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002000 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2001 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002002 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2003 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002004 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002005 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002006 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002007 p = xdr_encode_hyper(p, args->range.offset);
2008 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002009 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002010 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002011 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002012 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2013 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2014 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002015 } else
2016 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002017}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002018
2019static int
2020encode_secinfo_no_name(struct xdr_stream *xdr,
2021 const struct nfs41_secinfo_no_name_args *args,
2022 struct compound_hdr *hdr)
2023{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002024 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2025 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002026 return 0;
2027}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002028
2029static void encode_test_stateid(struct xdr_stream *xdr,
2030 struct nfs41_test_stateid_args *args,
2031 struct compound_hdr *hdr)
2032{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002033 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2034 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002035 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002036}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002037
2038static void encode_free_stateid(struct xdr_stream *xdr,
2039 struct nfs41_free_stateid_args *args,
2040 struct compound_hdr *hdr)
2041{
Trond Myklebustab19b482012-03-04 18:13:57 -05002042 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002043 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002044}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002045#endif /* CONFIG_NFS_V4_1 */
2046
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047/*
2048 * END OF "GENERIC" ENCODE ROUTINES.
2049 */
2050
Benny Halevy66cc0422009-04-01 09:22:10 -04002051static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2052{
2053#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002054 struct nfs4_session *session = args->sa_slot->table->session;
2055 if (session)
2056 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002057#endif /* CONFIG_NFS_V4_1 */
2058 return 0;
2059}
2060
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061/*
2062 * Encode an ACCESS request
2063 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002064static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2065 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002068 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070
Chuck Lever9f06c712010-12-14 14:59:18 +00002071 encode_compound_hdr(xdr, req, &hdr);
2072 encode_sequence(xdr, &args->seq_args, &hdr);
2073 encode_putfh(xdr, args->fh, &hdr);
2074 encode_access(xdr, args->access, &hdr);
2075 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002076 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077}
2078
2079/*
2080 * Encode LOOKUP request
2081 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002082static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2083 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002086 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088
Chuck Lever9f06c712010-12-14 14:59:18 +00002089 encode_compound_hdr(xdr, req, &hdr);
2090 encode_sequence(xdr, &args->seq_args, &hdr);
2091 encode_putfh(xdr, args->dir_fh, &hdr);
2092 encode_lookup(xdr, args->name, &hdr);
2093 encode_getfh(xdr, &hdr);
2094 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002095 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096}
2097
2098/*
2099 * Encode LOOKUP_ROOT request
2100 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002101static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2102 struct xdr_stream *xdr,
2103 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002106 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
Chuck Lever9f06c712010-12-14 14:59:18 +00002109 encode_compound_hdr(xdr, req, &hdr);
2110 encode_sequence(xdr, &args->seq_args, &hdr);
2111 encode_putrootfh(xdr, &hdr);
2112 encode_getfh(xdr, &hdr);
2113 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002114 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115}
2116
2117/*
2118 * Encode REMOVE request
2119 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002120static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2121 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002124 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
Chuck Lever9f06c712010-12-14 14:59:18 +00002127 encode_compound_hdr(xdr, req, &hdr);
2128 encode_sequence(xdr, &args->seq_args, &hdr);
2129 encode_putfh(xdr, args->fh, &hdr);
2130 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002131 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132}
2133
2134/*
2135 * Encode RENAME request
2136 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002137static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2138 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002141 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
Chuck Lever9f06c712010-12-14 14:59:18 +00002144 encode_compound_hdr(xdr, req, &hdr);
2145 encode_sequence(xdr, &args->seq_args, &hdr);
2146 encode_putfh(xdr, args->old_dir, &hdr);
2147 encode_savefh(xdr, &hdr);
2148 encode_putfh(xdr, args->new_dir, &hdr);
2149 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002150 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151}
2152
2153/*
2154 * Encode LINK request
2155 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002156static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2157 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002160 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
Chuck Lever9f06c712010-12-14 14:59:18 +00002163 encode_compound_hdr(xdr, req, &hdr);
2164 encode_sequence(xdr, &args->seq_args, &hdr);
2165 encode_putfh(xdr, args->fh, &hdr);
2166 encode_savefh(xdr, &hdr);
2167 encode_putfh(xdr, args->dir_fh, &hdr);
2168 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002169 encode_restorefh(xdr, &hdr);
2170 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002171 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172}
2173
2174/*
2175 * Encode CREATE request
2176 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002177static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2178 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002181 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183
Chuck Lever9f06c712010-12-14 14:59:18 +00002184 encode_compound_hdr(xdr, req, &hdr);
2185 encode_sequence(xdr, &args->seq_args, &hdr);
2186 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002187 encode_create(xdr, args, &hdr);
2188 encode_getfh(xdr, &hdr);
2189 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002190 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191}
2192
2193/*
2194 * Encode SYMLINK request
2195 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002196static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2197 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198{
Chuck Lever9f06c712010-12-14 14:59:18 +00002199 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200}
2201
2202/*
2203 * Encode GETATTR request
2204 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002205static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2206 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002209 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
Chuck Lever9f06c712010-12-14 14:59:18 +00002212 encode_compound_hdr(xdr, req, &hdr);
2213 encode_sequence(xdr, &args->seq_args, &hdr);
2214 encode_putfh(xdr, args->fh, &hdr);
2215 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002216 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217}
2218
2219/*
2220 * Encode a CLOSE request
2221 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002222static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2223 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224{
Andy Adamson05d564f2008-12-23 16:06:15 -05002225 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002226 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002227 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228
Chuck Lever9f06c712010-12-14 14:59:18 +00002229 encode_compound_hdr(xdr, req, &hdr);
2230 encode_sequence(xdr, &args->seq_args, &hdr);
2231 encode_putfh(xdr, args->fh, &hdr);
2232 encode_close(xdr, args, &hdr);
2233 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002234 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235}
2236
2237/*
2238 * Encode an OPEN request
2239 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002240static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2241 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002244 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246
Chuck Lever9f06c712010-12-14 14:59:18 +00002247 encode_compound_hdr(xdr, req, &hdr);
2248 encode_sequence(xdr, &args->seq_args, &hdr);
2249 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002250 encode_open(xdr, args, &hdr);
2251 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002252 if (args->access)
2253 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002254 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002255 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256}
2257
2258/*
2259 * Encode an OPEN_CONFIRM request
2260 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002261static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2262 struct xdr_stream *xdr,
2263 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002266 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
Chuck Lever9f06c712010-12-14 14:59:18 +00002269 encode_compound_hdr(xdr, req, &hdr);
2270 encode_putfh(xdr, args->fh, &hdr);
2271 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002272 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273}
2274
2275/*
2276 * Encode an OPEN request with no attributes.
2277 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002278static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2279 struct xdr_stream *xdr,
2280 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002283 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
Chuck Lever9f06c712010-12-14 14:59:18 +00002286 encode_compound_hdr(xdr, req, &hdr);
2287 encode_sequence(xdr, &args->seq_args, &hdr);
2288 encode_putfh(xdr, args->fh, &hdr);
2289 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002290 if (args->access)
2291 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002292 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002293 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294}
2295
2296/*
2297 * Encode an OPEN_DOWNGRADE request
2298 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002299static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2300 struct xdr_stream *xdr,
2301 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002304 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306
Chuck Lever9f06c712010-12-14 14:59:18 +00002307 encode_compound_hdr(xdr, req, &hdr);
2308 encode_sequence(xdr, &args->seq_args, &hdr);
2309 encode_putfh(xdr, args->fh, &hdr);
2310 encode_open_downgrade(xdr, args, &hdr);
2311 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002312 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313}
2314
2315/*
2316 * Encode a LOCK request
2317 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002318static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2319 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002322 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Chuck Lever9f06c712010-12-14 14:59:18 +00002325 encode_compound_hdr(xdr, req, &hdr);
2326 encode_sequence(xdr, &args->seq_args, &hdr);
2327 encode_putfh(xdr, args->fh, &hdr);
2328 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002329 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330}
2331
2332/*
2333 * Encode a LOCKT request
2334 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002335static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2336 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002339 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Chuck Lever9f06c712010-12-14 14:59:18 +00002342 encode_compound_hdr(xdr, req, &hdr);
2343 encode_sequence(xdr, &args->seq_args, &hdr);
2344 encode_putfh(xdr, args->fh, &hdr);
2345 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002346 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347}
2348
2349/*
2350 * Encode a LOCKU request
2351 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002352static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2353 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002356 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358
Chuck Lever9f06c712010-12-14 14:59:18 +00002359 encode_compound_hdr(xdr, req, &hdr);
2360 encode_sequence(xdr, &args->seq_args, &hdr);
2361 encode_putfh(xdr, args->fh, &hdr);
2362 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002363 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364}
2365
Chuck Lever9f06c712010-12-14 14:59:18 +00002366static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2367 struct xdr_stream *xdr,
2368 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002369{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002370 struct compound_hdr hdr = {
2371 .minorversion = 0,
2372 };
2373
Chuck Lever9f06c712010-12-14 14:59:18 +00002374 encode_compound_hdr(xdr, req, &hdr);
2375 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002376 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002377}
2378
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379/*
2380 * Encode a READLINK request
2381 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002382static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2383 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002386 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388
Chuck Lever9f06c712010-12-14 14:59:18 +00002389 encode_compound_hdr(xdr, req, &hdr);
2390 encode_sequence(xdr, &args->seq_args, &hdr);
2391 encode_putfh(xdr, args->fh, &hdr);
2392 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002393
Benny Halevy28f56692009-04-01 09:22:09 -04002394 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002395 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002396 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397}
2398
2399/*
2400 * Encode a READDIR request
2401 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002402static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2403 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002406 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408
Chuck Lever9f06c712010-12-14 14:59:18 +00002409 encode_compound_hdr(xdr, req, &hdr);
2410 encode_sequence(xdr, &args->seq_args, &hdr);
2411 encode_putfh(xdr, args->fh, &hdr);
2412 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002413
Benny Halevy28f56692009-04-01 09:22:09 -04002414 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002415 args->pgbase, args->count);
2416 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002417 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002418 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002419 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420}
2421
2422/*
2423 * Encode a READ request
2424 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002425static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002426 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002429 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431
Chuck Lever9f06c712010-12-14 14:59:18 +00002432 encode_compound_hdr(xdr, req, &hdr);
2433 encode_sequence(xdr, &args->seq_args, &hdr);
2434 encode_putfh(xdr, args->fh, &hdr);
2435 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436
Benny Halevy28f56692009-04-01 09:22:09 -04002437 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002439 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002440 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441}
2442
2443/*
2444 * Encode an SETATTR request
2445 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002446static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2447 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448{
Andy Adamson05d564f2008-12-23 16:06:15 -05002449 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002450 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002451 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452
Chuck Lever9f06c712010-12-14 14:59:18 +00002453 encode_compound_hdr(xdr, req, &hdr);
2454 encode_sequence(xdr, &args->seq_args, &hdr);
2455 encode_putfh(xdr, args->fh, &hdr);
2456 encode_setattr(xdr, args, args->server, &hdr);
2457 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002458 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459}
2460
2461/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002462 * Encode a GETACL request
2463 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002464static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2465 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002466{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002467 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002468 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002469 };
Benny Halevy28f56692009-04-01 09:22:09 -04002470 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002471
Chuck Lever9f06c712010-12-14 14:59:18 +00002472 encode_compound_hdr(xdr, req, &hdr);
2473 encode_sequence(xdr, &args->seq_args, &hdr);
2474 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002475 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002476 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002477
Benny Halevy28f56692009-04-01 09:22:09 -04002478 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002479 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002480
Andy Adamsond0179312008-12-23 16:06:17 -05002481 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002482}
2483
2484/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 * Encode a WRITE request
2486 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002487static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002488 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002491 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493
Chuck Lever9f06c712010-12-14 14:59:18 +00002494 encode_compound_hdr(xdr, req, &hdr);
2495 encode_sequence(xdr, &args->seq_args, &hdr);
2496 encode_putfh(xdr, args->fh, &hdr);
2497 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002498 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002499 if (args->bitmask)
2500 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002501 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502}
2503
2504/*
2505 * a COMMIT request
2506 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002507static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002508 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002511 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513
Chuck Lever9f06c712010-12-14 14:59:18 +00002514 encode_compound_hdr(xdr, req, &hdr);
2515 encode_sequence(xdr, &args->seq_args, &hdr);
2516 encode_putfh(xdr, args->fh, &hdr);
2517 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002518 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519}
2520
2521/*
2522 * FSINFO request
2523 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002524static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2525 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002528 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530
Chuck Lever9f06c712010-12-14 14:59:18 +00002531 encode_compound_hdr(xdr, req, &hdr);
2532 encode_sequence(xdr, &args->seq_args, &hdr);
2533 encode_putfh(xdr, args->fh, &hdr);
2534 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002535 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536}
2537
2538/*
2539 * a PATHCONF request
2540 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002541static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2542 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002545 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547
Chuck Lever9f06c712010-12-14 14:59:18 +00002548 encode_compound_hdr(xdr, req, &hdr);
2549 encode_sequence(xdr, &args->seq_args, &hdr);
2550 encode_putfh(xdr, args->fh, &hdr);
2551 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002552 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002553 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554}
2555
2556/*
2557 * a STATFS request
2558 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002559static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2560 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002563 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565
Chuck Lever9f06c712010-12-14 14:59:18 +00002566 encode_compound_hdr(xdr, req, &hdr);
2567 encode_sequence(xdr, &args->seq_args, &hdr);
2568 encode_putfh(xdr, args->fh, &hdr);
2569 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002570 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002571 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572}
2573
2574/*
2575 * GETATTR_BITMAP request
2576 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002577static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2578 struct xdr_stream *xdr,
2579 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002582 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584
Chuck Lever9f06c712010-12-14 14:59:18 +00002585 encode_compound_hdr(xdr, req, &hdr);
2586 encode_sequence(xdr, &args->seq_args, &hdr);
2587 encode_putfh(xdr, args->fhandle, &hdr);
2588 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002589 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002590 FATTR4_WORD0_LINK_SUPPORT|
2591 FATTR4_WORD0_SYMLINK_SUPPORT|
2592 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002593 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594}
2595
2596/*
2597 * a RENEW request
2598 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002599static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2600 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002603 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 };
2605
Chuck Lever9f06c712010-12-14 14:59:18 +00002606 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002607 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002608 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609}
2610
2611/*
2612 * a SETCLIENTID request
2613 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002614static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2615 struct xdr_stream *xdr,
2616 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002619 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 };
2621
Chuck Lever9f06c712010-12-14 14:59:18 +00002622 encode_compound_hdr(xdr, req, &hdr);
2623 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002624 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625}
2626
2627/*
2628 * a SETCLIENTID_CONFIRM request
2629 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002630static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2631 struct xdr_stream *xdr,
2632 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002635 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637
Chuck Lever9f06c712010-12-14 14:59:18 +00002638 encode_compound_hdr(xdr, req, &hdr);
2639 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002640 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641}
2642
2643/*
2644 * DELEGRETURN request
2645 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002646static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2647 struct xdr_stream *xdr,
2648 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002651 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653
Chuck Lever9f06c712010-12-14 14:59:18 +00002654 encode_compound_hdr(xdr, req, &hdr);
2655 encode_sequence(xdr, &args->seq_args, &hdr);
2656 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002657 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002658 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002659 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660}
2661
2662/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002663 * Encode FS_LOCATIONS request
2664 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002665static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2666 struct xdr_stream *xdr,
2667 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002668{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002669 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002670 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002671 };
Benny Halevy28f56692009-04-01 09:22:09 -04002672 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002673
Chuck Lever9f06c712010-12-14 14:59:18 +00002674 encode_compound_hdr(xdr, req, &hdr);
2675 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002676 if (args->migration) {
2677 encode_putfh(xdr, args->fh, &hdr);
2678 replen = hdr.replen;
2679 encode_fs_locations(xdr, args->bitmask, &hdr);
2680 if (args->renew)
2681 encode_renew(xdr, args->clientid, &hdr);
2682 } else {
2683 encode_putfh(xdr, args->dir_fh, &hdr);
2684 encode_lookup(xdr, args->name, &hdr);
2685 replen = hdr.replen;
2686 encode_fs_locations(xdr, args->bitmask, &hdr);
2687 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002688
Chuck Leverb03d7352013-10-17 14:12:50 -04002689 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002690 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002691 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002692 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002693}
2694
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002695/*
2696 * Encode SECINFO request
2697 */
2698static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2699 struct xdr_stream *xdr,
2700 struct nfs4_secinfo_arg *args)
2701{
2702 struct compound_hdr hdr = {
2703 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2704 };
2705
2706 encode_compound_hdr(xdr, req, &hdr);
2707 encode_sequence(xdr, &args->seq_args, &hdr);
2708 encode_putfh(xdr, args->dir_fh, &hdr);
2709 encode_secinfo(xdr, args->name, &hdr);
2710 encode_nops(&hdr);
2711}
2712
Chuck Lever44c99932013-10-17 14:13:30 -04002713/*
2714 * Encode FSID_PRESENT request
2715 */
2716static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2717 struct xdr_stream *xdr,
2718 struct nfs4_fsid_present_arg *args)
2719{
2720 struct compound_hdr hdr = {
2721 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2722 };
2723
2724 encode_compound_hdr(xdr, req, &hdr);
2725 encode_sequence(xdr, &args->seq_args, &hdr);
2726 encode_putfh(xdr, args->fh, &hdr);
2727 encode_getfh(xdr, &hdr);
2728 if (args->renew)
2729 encode_renew(xdr, args->clientid, &hdr);
2730 encode_nops(&hdr);
2731}
2732
Benny Halevy99fe60d2009-04-01 09:22:29 -04002733#if defined(CONFIG_NFS_V4_1)
2734/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002735 * BIND_CONN_TO_SESSION request
2736 */
2737static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2738 struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08002739 struct nfs41_bind_conn_to_session_args *args)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002740{
2741 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002742 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002743 };
2744
2745 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002746 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002747 encode_nops(&hdr);
2748}
2749
2750/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002751 * EXCHANGE_ID request
2752 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002753static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2754 struct xdr_stream *xdr,
2755 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002756{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002757 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002758 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002759 };
2760
Chuck Lever9f06c712010-12-14 14:59:18 +00002761 encode_compound_hdr(xdr, req, &hdr);
2762 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002763 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002764}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002765
2766/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002767 * a CREATE_SESSION request
2768 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002769static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2770 struct xdr_stream *xdr,
2771 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002772{
Andy Adamsonfc931582009-04-01 09:22:31 -04002773 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002774 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002775 };
2776
Chuck Lever9f06c712010-12-14 14:59:18 +00002777 encode_compound_hdr(xdr, req, &hdr);
2778 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002779 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002780}
2781
2782/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002783 * a DESTROY_SESSION request
2784 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002785static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2786 struct xdr_stream *xdr,
2787 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002788{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002789 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002790 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002791 };
2792
Chuck Lever9f06c712010-12-14 14:59:18 +00002793 encode_compound_hdr(xdr, req, &hdr);
2794 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002795 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002796}
2797
2798/*
Trond Myklebust66245532012-05-25 17:18:09 -04002799 * a DESTROY_CLIENTID request
2800 */
2801static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2802 struct xdr_stream *xdr,
2803 struct nfs_client *clp)
2804{
2805 struct compound_hdr hdr = {
2806 .minorversion = clp->cl_mvops->minor_version,
2807 };
2808
2809 encode_compound_hdr(xdr, req, &hdr);
2810 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2811 encode_nops(&hdr);
2812}
2813
2814/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002815 * a SEQUENCE request
2816 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002817static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2818 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002819{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002820 struct compound_hdr hdr = {
2821 .minorversion = nfs4_xdr_minorversion(args),
2822 };
2823
Chuck Lever9f06c712010-12-14 14:59:18 +00002824 encode_compound_hdr(xdr, req, &hdr);
2825 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002826 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002827}
2828
2829/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002830 * a GET_LEASE_TIME request
2831 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002832static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2833 struct xdr_stream *xdr,
2834 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002835{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002836 struct compound_hdr hdr = {
2837 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2838 };
Fred Isamandae100c2011-07-30 20:52:37 -04002839 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002840
Chuck Lever9f06c712010-12-14 14:59:18 +00002841 encode_compound_hdr(xdr, req, &hdr);
2842 encode_sequence(xdr, &args->la_seq_args, &hdr);
2843 encode_putrootfh(xdr, &hdr);
2844 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002845 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002846}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002847
2848/*
2849 * a RECLAIM_COMPLETE request
2850 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002851static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2852 struct xdr_stream *xdr,
2853 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002854{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002855 struct compound_hdr hdr = {
2856 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2857 };
2858
Chuck Lever9f06c712010-12-14 14:59:18 +00002859 encode_compound_hdr(xdr, req, &hdr);
2860 encode_sequence(xdr, &args->seq_args, &hdr);
2861 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002862 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002863}
2864
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002865/*
2866 * Encode GETDEVICEINFO request
2867 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002868static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2869 struct xdr_stream *xdr,
2870 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002871{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002872 struct compound_hdr hdr = {
2873 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2874 };
2875
Chuck Lever9f06c712010-12-14 14:59:18 +00002876 encode_compound_hdr(xdr, req, &hdr);
2877 encode_sequence(xdr, &args->seq_args, &hdr);
2878 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002879
2880 /* set up reply kvec. Subtract notification bitmap max size (2)
2881 * so that notification bitmap is put in xdr_buf tail */
2882 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2883 args->pdev->pages, args->pdev->pgbase,
2884 args->pdev->pglen);
2885
2886 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002887}
2888
2889/*
2890 * Encode LAYOUTGET request
2891 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002892static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2893 struct xdr_stream *xdr,
2894 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002895{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002896 struct compound_hdr hdr = {
2897 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2898 };
2899
Chuck Lever9f06c712010-12-14 14:59:18 +00002900 encode_compound_hdr(xdr, req, &hdr);
2901 encode_sequence(xdr, &args->seq_args, &hdr);
2902 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2903 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002904
2905 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2906 args->layout.pages, 0, args->layout.pglen);
2907
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002908 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002909}
Andy Adamson863a3c62011-03-23 13:27:54 +00002910
2911/*
2912 * Encode LAYOUTCOMMIT request
2913 */
Benny Halevycbe82602011-05-22 19:52:37 +03002914static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2915 struct xdr_stream *xdr,
2916 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002917{
Benny Halevyac7db722011-05-22 19:53:48 +03002918 struct nfs4_layoutcommit_data *data =
2919 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002920 struct compound_hdr hdr = {
2921 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2922 };
2923
2924 encode_compound_hdr(xdr, req, &hdr);
2925 encode_sequence(xdr, &args->seq_args, &hdr);
2926 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002927 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002928 encode_getfattr(xdr, args->bitmask, &hdr);
2929 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002930}
2931
2932/*
2933 * Encode LAYOUTRETURN request
2934 */
2935static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2936 struct xdr_stream *xdr,
2937 struct nfs4_layoutreturn_args *args)
2938{
2939 struct compound_hdr hdr = {
2940 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2941 };
2942
2943 encode_compound_hdr(xdr, req, &hdr);
2944 encode_sequence(xdr, &args->seq_args, &hdr);
2945 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2946 encode_layoutreturn(xdr, args, &hdr);
2947 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002948}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002949
2950/*
2951 * Encode SECINFO_NO_NAME request
2952 */
2953static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2954 struct xdr_stream *xdr,
2955 struct nfs41_secinfo_no_name_args *args)
2956{
2957 struct compound_hdr hdr = {
2958 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2959 };
2960
2961 encode_compound_hdr(xdr, req, &hdr);
2962 encode_sequence(xdr, &args->seq_args, &hdr);
2963 encode_putrootfh(xdr, &hdr);
2964 encode_secinfo_no_name(xdr, args, &hdr);
2965 encode_nops(&hdr);
2966 return 0;
2967}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002968
2969/*
2970 * Encode TEST_STATEID request
2971 */
2972static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2973 struct xdr_stream *xdr,
2974 struct nfs41_test_stateid_args *args)
2975{
2976 struct compound_hdr hdr = {
2977 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2978 };
2979
2980 encode_compound_hdr(xdr, req, &hdr);
2981 encode_sequence(xdr, &args->seq_args, &hdr);
2982 encode_test_stateid(xdr, args, &hdr);
2983 encode_nops(&hdr);
2984}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002985
2986/*
2987 * Encode FREE_STATEID request
2988 */
2989static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2990 struct xdr_stream *xdr,
2991 struct nfs41_free_stateid_args *args)
2992{
2993 struct compound_hdr hdr = {
2994 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2995 };
2996
2997 encode_compound_hdr(xdr, req, &hdr);
2998 encode_sequence(xdr, &args->seq_args, &hdr);
2999 encode_free_stateid(xdr, args, &hdr);
3000 encode_nops(&hdr);
3001}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003002#endif /* CONFIG_NFS_V4_1 */
3003
Benny Halevy686841b2009-08-14 17:19:48 +03003004static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3005{
3006 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3007 "Remaining buffer length is %tu words.\n",
3008 func, xdr->end - xdr->p);
3009}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010
Trond Myklebust683b57b2006-06-09 09:34:22 -04003011static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012{
Al Viro8687b632006-10-19 23:28:48 -07003013 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014
Benny Halevyc0eae662009-08-14 17:20:14 +03003015 p = xdr_inline_decode(xdr, 4);
3016 if (unlikely(!p))
3017 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003018 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003019 p = xdr_inline_decode(xdr, *len);
3020 if (unlikely(!p))
3021 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 *string = (char *)p;
3023 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003024out_overflow:
3025 print_overflow_msg(__func__, xdr);
3026 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027}
3028
3029static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3030{
Al Viro8687b632006-10-19 23:28:48 -07003031 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032
Benny Halevyc0eae662009-08-14 17:20:14 +03003033 p = xdr_inline_decode(xdr, 8);
3034 if (unlikely(!p))
3035 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003036 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003037 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003038
Benny Halevyc0eae662009-08-14 17:20:14 +03003039 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3040 if (unlikely(!p))
3041 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 hdr->tag = (char *)p;
3043 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003044 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003045 if (unlikely(hdr->nops < 1))
3046 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003048out_overflow:
3049 print_overflow_msg(__func__, xdr);
3050 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051}
3052
Trond Myklebustc7848f62013-12-04 17:39:23 -05003053static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3054 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055{
Al Viro8687b632006-10-19 23:28:48 -07003056 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 uint32_t opnum;
3058 int32_t nfserr;
3059
Benny Halevyc0eae662009-08-14 17:20:14 +03003060 p = xdr_inline_decode(xdr, 8);
3061 if (unlikely(!p))
3062 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003063 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003064 if (unlikely(opnum != expected))
3065 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003066 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003067 if (nfserr == NFS_OK)
3068 *nfs_retval = 0;
3069 else
3070 *nfs_retval = nfs4_stat_to_errno(nfserr);
3071 return true;
3072out_bad_operation:
3073 dprintk("nfs: Server returned operation"
3074 " %d but we issued a request for %d\n",
3075 opnum, expected);
3076 *nfs_retval = -EREMOTEIO;
3077 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003078out_overflow:
3079 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003080 *nfs_retval = -EIO;
3081 return false;
3082}
3083
3084static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3085{
3086 int retval;
3087
3088 __decode_op_hdr(xdr, expected, &retval);
3089 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090}
3091
3092/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003093static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094{
Al Viro8687b632006-10-19 23:28:48 -07003095 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003096 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 char *str;
3098
Benny Halevyc0eae662009-08-14 17:20:14 +03003099 p = xdr_inline_decode(xdr, 12);
3100 if (likely(p))
3101 return decode_opaque_inline(xdr, &strlen, &str);
3102 print_overflow_msg(__func__, xdr);
3103 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104}
3105
3106static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3107{
Al Viro8687b632006-10-19 23:28:48 -07003108 uint32_t bmlen;
3109 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110
Benny Halevyc0eae662009-08-14 17:20:14 +03003111 p = xdr_inline_decode(xdr, 4);
3112 if (unlikely(!p))
3113 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003114 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115
Fred Isamandae100c2011-07-30 20:52:37 -04003116 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003117 p = xdr_inline_decode(xdr, (bmlen << 2));
3118 if (unlikely(!p))
3119 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003121 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003122 if (bmlen > 1) {
3123 bitmap[1] = be32_to_cpup(p++);
3124 if (bmlen > 2)
3125 bitmap[2] = be32_to_cpup(p);
3126 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 }
3128 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003129out_overflow:
3130 print_overflow_msg(__func__, xdr);
3131 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132}
3133
Trond Myklebust256e48b2012-06-21 11:18:13 -04003134static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135{
Al Viro8687b632006-10-19 23:28:48 -07003136 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137
Benny Halevyc0eae662009-08-14 17:20:14 +03003138 p = xdr_inline_decode(xdr, 4);
3139 if (unlikely(!p))
3140 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003141 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003142 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003144out_overflow:
3145 print_overflow_msg(__func__, xdr);
3146 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147}
3148
3149static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3150{
3151 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003152 int ret;
3153 ret = decode_attr_bitmap(xdr, bitmask);
3154 if (unlikely(ret < 0))
3155 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3157 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003158 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3159 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3160 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 return 0;
3162}
3163
3164static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3165{
Al Viro8687b632006-10-19 23:28:48 -07003166 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003167 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168
3169 *type = 0;
3170 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3171 return -EIO;
3172 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003173 p = xdr_inline_decode(xdr, 4);
3174 if (unlikely(!p))
3175 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003176 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003178 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 return -EIO;
3180 }
3181 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003182 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003184 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003185 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003186out_overflow:
3187 print_overflow_msg(__func__, xdr);
3188 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189}
3190
Chuck Lever264e6352012-03-01 17:02:05 -05003191static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3192 uint32_t *bitmap, uint32_t *type)
3193{
3194 __be32 *p;
3195
3196 *type = 0;
3197 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3198 return -EIO;
3199 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3200 p = xdr_inline_decode(xdr, 4);
3201 if (unlikely(!p))
3202 goto out_overflow;
3203 *type = be32_to_cpup(p);
3204 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3205 }
3206 dprintk("%s: expire type=0x%x\n", __func__, *type);
3207 return 0;
3208out_overflow:
3209 print_overflow_msg(__func__, xdr);
3210 return -EIO;
3211}
3212
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3214{
Al Viro8687b632006-10-19 23:28:48 -07003215 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003216 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217
3218 *change = 0;
3219 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3220 return -EIO;
3221 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003222 p = xdr_inline_decode(xdr, 8);
3223 if (unlikely(!p))
3224 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003225 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003227 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003229 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003231 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003232out_overflow:
3233 print_overflow_msg(__func__, xdr);
3234 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235}
3236
3237static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3238{
Al Viro8687b632006-10-19 23:28:48 -07003239 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003240 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241
3242 *size = 0;
3243 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3244 return -EIO;
3245 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003246 p = xdr_inline_decode(xdr, 8);
3247 if (unlikely(!p))
3248 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003249 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003251 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003253 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003254 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003255out_overflow:
3256 print_overflow_msg(__func__, xdr);
3257 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258}
3259
3260static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3261{
Al Viro8687b632006-10-19 23:28:48 -07003262 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263
3264 *res = 0;
3265 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3266 return -EIO;
3267 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003268 p = xdr_inline_decode(xdr, 4);
3269 if (unlikely(!p))
3270 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003271 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3273 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003274 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003276out_overflow:
3277 print_overflow_msg(__func__, xdr);
3278 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279}
3280
3281static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3282{
Al Viro8687b632006-10-19 23:28:48 -07003283 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284
3285 *res = 0;
3286 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3287 return -EIO;
3288 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003289 p = xdr_inline_decode(xdr, 4);
3290 if (unlikely(!p))
3291 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003292 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3294 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003295 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003297out_overflow:
3298 print_overflow_msg(__func__, xdr);
3299 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300}
3301
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003302static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303{
Al Viro8687b632006-10-19 23:28:48 -07003304 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003305 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306
3307 fsid->major = 0;
3308 fsid->minor = 0;
3309 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3310 return -EIO;
3311 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003312 p = xdr_inline_decode(xdr, 16);
3313 if (unlikely(!p))
3314 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003315 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003316 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003318 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003320 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 (unsigned long long)fsid->major,
3322 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003323 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003324out_overflow:
3325 print_overflow_msg(__func__, xdr);
3326 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327}
3328
3329static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3330{
Al Viro8687b632006-10-19 23:28:48 -07003331 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332
3333 *res = 60;
3334 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3335 return -EIO;
3336 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003337 p = xdr_inline_decode(xdr, 4);
3338 if (unlikely(!p))
3339 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003340 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3342 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003343 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003345out_overflow:
3346 print_overflow_msg(__func__, xdr);
3347 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348}
3349
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003350static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003351{
3352 __be32 *p;
3353
3354 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3355 return -EIO;
3356 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3357 p = xdr_inline_decode(xdr, 4);
3358 if (unlikely(!p))
3359 goto out_overflow;
3360 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003361 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003362 }
3363 return 0;
3364out_overflow:
3365 print_overflow_msg(__func__, xdr);
3366 return -EIO;
3367}
3368
3369static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3370{
3371 __be32 *p;
3372 int len;
3373
Trond Myklebust7ad07352010-10-23 15:34:20 -04003374 if (fh != NULL)
3375 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003376
3377 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3378 return -EIO;
3379 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3380 p = xdr_inline_decode(xdr, 4);
3381 if (unlikely(!p))
3382 goto out_overflow;
3383 len = be32_to_cpup(p);
3384 if (len > NFS4_FHSIZE)
3385 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003386 p = xdr_inline_decode(xdr, len);
3387 if (unlikely(!p))
3388 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003389 if (fh != NULL) {
3390 memcpy(fh->data, p, len);
3391 fh->size = len;
3392 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003393 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3394 }
3395 return 0;
3396out_overflow:
3397 print_overflow_msg(__func__, xdr);
3398 return -EIO;
3399}
3400
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3402{
Al Viro8687b632006-10-19 23:28:48 -07003403 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003405 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3407 return -EIO;
3408 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003409 p = xdr_inline_decode(xdr, 4);
3410 if (unlikely(!p))
3411 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003412 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3414 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003415 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003417out_overflow:
3418 print_overflow_msg(__func__, xdr);
3419 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420}
3421
3422static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3423{
Al Viro8687b632006-10-19 23:28:48 -07003424 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003425 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426
3427 *fileid = 0;
3428 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3429 return -EIO;
3430 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003431 p = xdr_inline_decode(xdr, 8);
3432 if (unlikely(!p))
3433 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003434 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003436 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003438 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003439 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003440out_overflow:
3441 print_overflow_msg(__func__, xdr);
3442 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443}
3444
Manoj Naik99baf622006-06-09 09:34:24 -04003445static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3446{
Al Viro8687b632006-10-19 23:28:48 -07003447 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003448 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003449
3450 *fileid = 0;
3451 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3452 return -EIO;
3453 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003454 p = xdr_inline_decode(xdr, 8);
3455 if (unlikely(!p))
3456 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003457 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003458 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003459 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003460 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003461 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003462 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003463out_overflow:
3464 print_overflow_msg(__func__, xdr);
3465 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003466}
3467
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3469{
Al Viro8687b632006-10-19 23:28:48 -07003470 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471 int status = 0;
3472
3473 *res = 0;
3474 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3475 return -EIO;
3476 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003477 p = xdr_inline_decode(xdr, 8);
3478 if (unlikely(!p))
3479 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003480 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3482 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003483 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003485out_overflow:
3486 print_overflow_msg(__func__, xdr);
3487 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488}
3489
3490static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3491{
Al Viro8687b632006-10-19 23:28:48 -07003492 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493 int status = 0;
3494
3495 *res = 0;
3496 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3497 return -EIO;
3498 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003499 p = xdr_inline_decode(xdr, 8);
3500 if (unlikely(!p))
3501 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003502 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3504 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003505 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003507out_overflow:
3508 print_overflow_msg(__func__, xdr);
3509 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510}
3511
3512static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3513{
Al Viro8687b632006-10-19 23:28:48 -07003514 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515 int status = 0;
3516
3517 *res = 0;
3518 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3519 return -EIO;
3520 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003521 p = xdr_inline_decode(xdr, 8);
3522 if (unlikely(!p))
3523 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003524 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3526 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003527 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003529out_overflow:
3530 print_overflow_msg(__func__, xdr);
3531 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532}
3533
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003534static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3535{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003536 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003537 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003538 int status = 0;
3539
Benny Halevyc0eae662009-08-14 17:20:14 +03003540 p = xdr_inline_decode(xdr, 4);
3541 if (unlikely(!p))
3542 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003543 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003544 if (n == 0)
3545 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003546 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003547 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3548 dprintk("cannot parse %d components in path\n", n);
3549 goto out_eio;
3550 }
3551 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003552 struct nfs4_string *component = &path->components[path->ncomponents];
3553 status = decode_opaque_inline(xdr, &component->len, &component->data);
3554 if (unlikely(status != 0))
3555 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003556 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003557 pr_cont("%s%.*s ",
3558 (path->ncomponents != n ? "/ " : ""),
3559 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003560 }
3561out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003562 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003563root_path:
3564/* a root pathname is sent as a zero component4 */
3565 path->ncomponents = 1;
3566 path->components[0].len=0;
3567 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003568 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003569 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003570out_eio:
3571 dprintk(" status %d", status);
3572 status = -EIO;
3573 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003574out_overflow:
3575 print_overflow_msg(__func__, xdr);
3576 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003577}
3578
3579static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003580{
3581 int n;
Al Viro8687b632006-10-19 23:28:48 -07003582 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003583 int status = -EIO;
3584
3585 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3586 goto out;
3587 status = 0;
3588 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3589 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003590 status = -EIO;
3591 /* Ignore borken servers that return unrequested attrs */
3592 if (unlikely(res == NULL))
3593 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003594 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003595 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003596 if (unlikely(status != 0))
3597 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003598 p = xdr_inline_decode(xdr, 4);
3599 if (unlikely(!p))
3600 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003601 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003602 if (n <= 0)
3603 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003604 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003605 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003606 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003607
Trond Myklebust809b4262013-03-27 11:54:45 -04003608 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3609 break;
3610 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003611 p = xdr_inline_decode(xdr, 4);
3612 if (unlikely(!p))
3613 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003614 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003615
Chuck Lever02a29762012-03-01 17:00:31 -05003616 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003617 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3618 struct nfs4_string *server;
3619
3620 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003621 unsigned int i;
3622 dprintk("%s: using first %u of %u servers "
3623 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003624 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003625 NFS4_FS_LOCATION_MAXSERVERS,
3626 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003627 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003628 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003629 char *data;
3630 status = decode_opaque_inline(xdr, &len, &data);
3631 if (unlikely(status != 0))
3632 goto out_eio;
3633 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003634 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003635 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003636 server = &loc->servers[loc->nservers];
3637 status = decode_opaque_inline(xdr, &server->len, &server->data);
3638 if (unlikely(status != 0))
3639 goto out_eio;
3640 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003641 }
3642 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003643 if (unlikely(status != 0))
3644 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003645 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003646 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003647 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003648out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003649 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003650 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003651out_overflow:
3652 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003653out_eio:
3654 status = -EIO;
3655 goto out;
3656}
3657
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3659{
Al Viro8687b632006-10-19 23:28:48 -07003660 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661 int status = 0;
3662
3663 *res = 0;
3664 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3665 return -EIO;
3666 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003667 p = xdr_inline_decode(xdr, 8);
3668 if (unlikely(!p))
3669 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003670 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3672 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003673 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003675out_overflow:
3676 print_overflow_msg(__func__, xdr);
3677 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678}
3679
3680static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3681{
Al Viro8687b632006-10-19 23:28:48 -07003682 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 int status = 0;
3684
3685 *maxlink = 1;
3686 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3687 return -EIO;
3688 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003689 p = xdr_inline_decode(xdr, 4);
3690 if (unlikely(!p))
3691 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003692 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3694 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003695 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003697out_overflow:
3698 print_overflow_msg(__func__, xdr);
3699 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700}
3701
3702static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3703{
Al Viro8687b632006-10-19 23:28:48 -07003704 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 int status = 0;
3706
3707 *maxname = 1024;
3708 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3709 return -EIO;
3710 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003711 p = xdr_inline_decode(xdr, 4);
3712 if (unlikely(!p))
3713 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003714 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3716 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003717 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003719out_overflow:
3720 print_overflow_msg(__func__, xdr);
3721 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722}
3723
3724static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3725{
Al Viro8687b632006-10-19 23:28:48 -07003726 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727 int status = 0;
3728
3729 *res = 1024;
3730 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3731 return -EIO;
3732 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3733 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003734 p = xdr_inline_decode(xdr, 8);
3735 if (unlikely(!p))
3736 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003737 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 if (maxread > 0x7FFFFFFF)
3739 maxread = 0x7FFFFFFF;
3740 *res = (uint32_t)maxread;
3741 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3742 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003743 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003745out_overflow:
3746 print_overflow_msg(__func__, xdr);
3747 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748}
3749
3750static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3751{
Al Viro8687b632006-10-19 23:28:48 -07003752 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 int status = 0;
3754
3755 *res = 1024;
3756 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3757 return -EIO;
3758 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3759 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003760 p = xdr_inline_decode(xdr, 8);
3761 if (unlikely(!p))
3762 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003763 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764 if (maxwrite > 0x7FFFFFFF)
3765 maxwrite = 0x7FFFFFFF;
3766 *res = (uint32_t)maxwrite;
3767 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3768 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003769 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003771out_overflow:
3772 print_overflow_msg(__func__, xdr);
3773 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774}
3775
Trond Myklebustbca79472009-03-11 14:10:26 -04003776static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777{
Trond Myklebustbca79472009-03-11 14:10:26 -04003778 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003779 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003780 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781
3782 *mode = 0;
3783 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3784 return -EIO;
3785 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003786 p = xdr_inline_decode(xdr, 4);
3787 if (unlikely(!p))
3788 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003789 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003790 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003792 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003794 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003795 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003796out_overflow:
3797 print_overflow_msg(__func__, xdr);
3798 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799}
3800
3801static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3802{
Al Viro8687b632006-10-19 23:28:48 -07003803 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003804 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805
3806 *nlink = 1;
3807 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3808 return -EIO;
3809 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003810 p = xdr_inline_decode(xdr, 4);
3811 if (unlikely(!p))
3812 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003813 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003815 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003817 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003818 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003819out_overflow:
3820 print_overflow_msg(__func__, xdr);
3821 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822}
3823
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003824static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003825 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003826 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827{
Al Viro8687b632006-10-19 23:28:48 -07003828 uint32_t len;
3829 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003830 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831
Eric W. Biedermane5782072013-02-01 14:22:02 -08003832 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3834 return -EIO;
3835 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003836 p = xdr_inline_decode(xdr, 4);
3837 if (unlikely(!p))
3838 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003839 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003840 p = xdr_inline_decode(xdr, len);
3841 if (unlikely(!p))
3842 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003843 if (owner_name != NULL) {
3844 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3845 if (owner_name->data != NULL) {
3846 owner_name->len = len;
3847 ret = NFS_ATTR_FATTR_OWNER_NAME;
3848 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003849 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003850 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003851 ret = NFS_ATTR_FATTR_OWNER;
3852 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003854 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003856 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003857 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3859 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003860 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003861 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003862out_overflow:
3863 print_overflow_msg(__func__, xdr);
3864 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865}
3866
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003867static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003868 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003869 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870{
Al Viro8687b632006-10-19 23:28:48 -07003871 uint32_t len;
3872 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003873 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874
Eric W. Biedermane5782072013-02-01 14:22:02 -08003875 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3877 return -EIO;
3878 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003879 p = xdr_inline_decode(xdr, 4);
3880 if (unlikely(!p))
3881 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003882 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003883 p = xdr_inline_decode(xdr, len);
3884 if (unlikely(!p))
3885 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003886 if (group_name != NULL) {
3887 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3888 if (group_name->data != NULL) {
3889 group_name->len = len;
3890 ret = NFS_ATTR_FATTR_GROUP_NAME;
3891 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003892 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003893 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003894 ret = NFS_ATTR_FATTR_GROUP;
3895 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003897 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003899 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003900 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3902 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003903 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003904 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003905out_overflow:
3906 print_overflow_msg(__func__, xdr);
3907 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908}
3909
3910static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3911{
Al Viro8687b632006-10-19 23:28:48 -07003912 uint32_t major = 0, minor = 0;
3913 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003914 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915
3916 *rdev = MKDEV(0,0);
3917 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3918 return -EIO;
3919 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3920 dev_t tmp;
3921
Benny Halevyc0eae662009-08-14 17:20:14 +03003922 p = xdr_inline_decode(xdr, 8);
3923 if (unlikely(!p))
3924 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003925 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003926 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927 tmp = MKDEV(major, minor);
3928 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3929 *rdev = tmp;
3930 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003931 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003933 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003934 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003935out_overflow:
3936 print_overflow_msg(__func__, xdr);
3937 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938}
3939
3940static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3941{
Al Viro8687b632006-10-19 23:28:48 -07003942 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 int status = 0;
3944
3945 *res = 0;
3946 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3947 return -EIO;
3948 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003949 p = xdr_inline_decode(xdr, 8);
3950 if (unlikely(!p))
3951 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003952 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3954 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003955 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003957out_overflow:
3958 print_overflow_msg(__func__, xdr);
3959 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960}
3961
3962static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3963{
Al Viro8687b632006-10-19 23:28:48 -07003964 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 int status = 0;
3966
3967 *res = 0;
3968 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3969 return -EIO;
3970 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003971 p = xdr_inline_decode(xdr, 8);
3972 if (unlikely(!p))
3973 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003974 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3976 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003977 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003979out_overflow:
3980 print_overflow_msg(__func__, xdr);
3981 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982}
3983
3984static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3985{
Al Viro8687b632006-10-19 23:28:48 -07003986 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 int status = 0;
3988
3989 *res = 0;
3990 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3991 return -EIO;
3992 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003993 p = xdr_inline_decode(xdr, 8);
3994 if (unlikely(!p))
3995 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003996 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3998 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003999 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004001out_overflow:
4002 print_overflow_msg(__func__, xdr);
4003 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004}
4005
4006static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4007{
Al Viro8687b632006-10-19 23:28:48 -07004008 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004009 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010
4011 *used = 0;
4012 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4013 return -EIO;
4014 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004015 p = xdr_inline_decode(xdr, 8);
4016 if (unlikely(!p))
4017 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004018 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004020 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004022 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004023 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004024 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004025out_overflow:
4026 print_overflow_msg(__func__, xdr);
4027 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028}
4029
4030static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4031{
Al Viro8687b632006-10-19 23:28:48 -07004032 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 uint64_t sec;
4034 uint32_t nsec;
4035
Benny Halevyc0eae662009-08-14 17:20:14 +03004036 p = xdr_inline_decode(xdr, 12);
4037 if (unlikely(!p))
4038 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004039 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004040 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041 time->tv_sec = (time_t)sec;
4042 time->tv_nsec = (long)nsec;
4043 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004044out_overflow:
4045 print_overflow_msg(__func__, xdr);
4046 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047}
4048
4049static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4050{
4051 int status = 0;
4052
4053 time->tv_sec = 0;
4054 time->tv_nsec = 0;
4055 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4056 return -EIO;
4057 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4058 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004059 if (status == 0)
4060 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4062 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004063 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 return status;
4065}
4066
4067static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4068{
4069 int status = 0;
4070
4071 time->tv_sec = 0;
4072 time->tv_nsec = 0;
4073 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4074 return -EIO;
4075 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4076 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004077 if (status == 0)
4078 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4080 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004081 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 return status;
4083}
4084
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004085static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4086 struct timespec *time)
4087{
4088 int status = 0;
4089
4090 time->tv_sec = 0;
4091 time->tv_nsec = 0;
4092 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4093 return -EIO;
4094 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4095 status = decode_attr_time(xdr, time);
4096 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4097 }
4098 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4099 (long)time->tv_nsec);
4100 return status;
4101}
4102
David Quigleyaa9c2662013-05-22 12:50:44 -04004103static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4104 struct nfs4_label *label)
4105{
4106 uint32_t pi = 0;
4107 uint32_t lfs = 0;
4108 __u32 len;
4109 __be32 *p;
4110 int status = 0;
4111
4112 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4113 return -EIO;
4114 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4115 p = xdr_inline_decode(xdr, 4);
4116 if (unlikely(!p))
4117 goto out_overflow;
4118 lfs = be32_to_cpup(p++);
4119 p = xdr_inline_decode(xdr, 4);
4120 if (unlikely(!p))
4121 goto out_overflow;
4122 pi = be32_to_cpup(p++);
4123 p = xdr_inline_decode(xdr, 4);
4124 if (unlikely(!p))
4125 goto out_overflow;
4126 len = be32_to_cpup(p++);
4127 p = xdr_inline_decode(xdr, len);
4128 if (unlikely(!p))
4129 goto out_overflow;
4130 if (len < NFS4_MAXLABELLEN) {
4131 if (label) {
4132 memcpy(label->label, p, len);
4133 label->len = len;
4134 label->pi = pi;
4135 label->lfs = lfs;
4136 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4137 }
4138 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4139 } else
4140 printk(KERN_WARNING "%s: label too long (%u)!\n",
4141 __func__, len);
4142 }
4143 if (label && label->label)
4144 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4145 (char *)label->label, label->len, label->pi, label->lfs);
4146 return status;
4147
4148out_overflow:
4149 print_overflow_msg(__func__, xdr);
4150 return -EIO;
4151}
4152
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4154{
4155 int status = 0;
4156
4157 time->tv_sec = 0;
4158 time->tv_nsec = 0;
4159 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4160 return -EIO;
4161 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4162 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004163 if (status == 0)
4164 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004165 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4166 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004167 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168 return status;
4169}
4170
Trond Myklebust256e48b2012-06-21 11:18:13 -04004171static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172{
4173 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004174 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175
4176 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004177 dprintk("%s: server returned incorrect attribute length: "
4178 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004179 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180 attrwords << 2,
4181 (attrwords < nwords) ? '<' : '>',
4182 nwords << 2);
4183 return -EIO;
4184 }
4185 return 0;
4186}
4187
4188static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4189{
Al Viro8687b632006-10-19 23:28:48 -07004190 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191
Benny Halevyc0eae662009-08-14 17:20:14 +03004192 p = xdr_inline_decode(xdr, 20);
4193 if (unlikely(!p))
4194 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004195 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004196 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004197 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004199out_overflow:
4200 print_overflow_msg(__func__, xdr);
4201 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202}
4203
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004204static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205{
Al Viro8687b632006-10-19 23:28:48 -07004206 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 uint32_t supp, acc;
4208 int status;
4209
4210 status = decode_op_hdr(xdr, OP_ACCESS);
4211 if (status)
4212 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004213 p = xdr_inline_decode(xdr, 8);
4214 if (unlikely(!p))
4215 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004216 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004217 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004218 *supported = supp;
4219 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004221out_overflow:
4222 print_overflow_msg(__func__, xdr);
4223 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224}
4225
Benny Halevy07d30432009-08-14 17:19:52 +03004226static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227{
Al Viro8687b632006-10-19 23:28:48 -07004228 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004229
4230 p = xdr_inline_decode(xdr, len);
4231 if (likely(p)) {
4232 memcpy(buf, p, len);
4233 return 0;
4234 }
4235 print_overflow_msg(__func__, xdr);
4236 return -EIO;
4237}
4238
4239static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4240{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004241 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004242}
4243
4244static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4245{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246 int status;
4247
4248 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004249 if (status != -EIO)
4250 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004251 if (!status)
4252 status = decode_stateid(xdr, &res->stateid);
4253 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254}
4255
Benny Halevydb942bb2009-08-14 17:19:56 +03004256static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4257{
Chuck Levercd937102012-03-02 17:14:31 -05004258 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004259}
4260
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004261static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4262{
4263 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4264}
4265
Fred Isaman0b7c0152012-04-20 14:47:39 -04004266static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268 int status;
4269
4270 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004271 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004272 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004273 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274}
4275
4276static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4277{
Al Viro8687b632006-10-19 23:28:48 -07004278 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279 uint32_t bmlen;
4280 int status;
4281
4282 status = decode_op_hdr(xdr, OP_CREATE);
4283 if (status)
4284 return status;
4285 if ((status = decode_change_info(xdr, cinfo)))
4286 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004287 p = xdr_inline_decode(xdr, 4);
4288 if (unlikely(!p))
4289 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004290 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004291 p = xdr_inline_decode(xdr, bmlen << 2);
4292 if (likely(p))
4293 return 0;
4294out_overflow:
4295 print_overflow_msg(__func__, xdr);
4296 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297}
4298
4299static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4300{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004301 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004302 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303 int status;
4304
4305 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4306 goto xdr_error;
4307 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4308 goto xdr_error;
4309 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4310 goto xdr_error;
4311 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4312 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004313 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4314 &res->fh_expire_type)) != 0)
4315 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4317 goto xdr_error;
4318 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4319 goto xdr_error;
4320 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4321 goto xdr_error;
4322 status = verify_attr_len(xdr, savep, attrlen);
4323xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004324 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325 return status;
4326}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004327
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4329{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004330 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004331 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004333
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4335 goto xdr_error;
4336 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4337 goto xdr_error;
4338 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4339 goto xdr_error;
4340
4341 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4342 goto xdr_error;
4343 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4344 goto xdr_error;
4345 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4346 goto xdr_error;
4347 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4348 goto xdr_error;
4349 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4350 goto xdr_error;
4351 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4352 goto xdr_error;
4353
4354 status = verify_attr_len(xdr, savep, attrlen);
4355xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004356 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 return status;
4358}
4359
4360static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4361{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004362 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004363 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004364 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004365
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4367 goto xdr_error;
4368 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4369 goto xdr_error;
4370 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4371 goto xdr_error;
4372
4373 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4374 goto xdr_error;
4375 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4376 goto xdr_error;
4377
4378 status = verify_attr_len(xdr, savep, attrlen);
4379xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004380 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004381 return status;
4382}
4383
Andy Adamson88034c32012-05-23 05:02:34 -04004384static int decode_threshold_hint(struct xdr_stream *xdr,
4385 uint32_t *bitmap,
4386 uint64_t *res,
4387 uint32_t hint_bit)
4388{
4389 __be32 *p;
4390
4391 *res = 0;
4392 if (likely(bitmap[0] & hint_bit)) {
4393 p = xdr_inline_decode(xdr, 8);
4394 if (unlikely(!p))
4395 goto out_overflow;
4396 xdr_decode_hyper(p, res);
4397 }
4398 return 0;
4399out_overflow:
4400 print_overflow_msg(__func__, xdr);
4401 return -EIO;
4402}
4403
4404static int decode_first_threshold_item4(struct xdr_stream *xdr,
4405 struct nfs4_threshold *res)
4406{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004407 __be32 *p;
4408 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004409 uint32_t bitmap[3] = {0,}, attrlen;
4410 int status;
4411
4412 /* layout type */
4413 p = xdr_inline_decode(xdr, 4);
4414 if (unlikely(!p)) {
4415 print_overflow_msg(__func__, xdr);
4416 return -EIO;
4417 }
4418 res->l_type = be32_to_cpup(p);
4419
4420 /* thi_hintset bitmap */
4421 status = decode_attr_bitmap(xdr, bitmap);
4422 if (status < 0)
4423 goto xdr_error;
4424
4425 /* thi_hintlist length */
4426 status = decode_attr_length(xdr, &attrlen, &savep);
4427 if (status < 0)
4428 goto xdr_error;
4429 /* thi_hintlist */
4430 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4431 if (status < 0)
4432 goto xdr_error;
4433 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4434 if (status < 0)
4435 goto xdr_error;
4436 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4437 THRESHOLD_RD_IO);
4438 if (status < 0)
4439 goto xdr_error;
4440 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4441 THRESHOLD_WR_IO);
4442 if (status < 0)
4443 goto xdr_error;
4444
4445 status = verify_attr_len(xdr, savep, attrlen);
4446 res->bm = bitmap[0];
4447
4448 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4449 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4450 res->wr_io_sz);
4451xdr_error:
4452 dprintk("%s ret=%d!\n", __func__, status);
4453 return status;
4454}
4455
4456/*
4457 * Thresholds on pNFS direct I/O vrs MDS I/O
4458 */
4459static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4460 uint32_t *bitmap,
4461 struct nfs4_threshold *res)
4462{
4463 __be32 *p;
4464 int status = 0;
4465 uint32_t num;
4466
4467 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4468 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004469 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004470 /* Did the server return an unrequested attribute? */
4471 if (unlikely(res == NULL))
4472 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004473 p = xdr_inline_decode(xdr, 4);
4474 if (unlikely(!p))
4475 goto out_overflow;
4476 num = be32_to_cpup(p);
4477 if (num == 0)
4478 return 0;
4479 if (num > 1)
4480 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4481 "drivers per filesystem not supported\n",
4482 __func__);
4483
4484 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004485 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004486 }
4487 return status;
4488out_overflow:
4489 print_overflow_msg(__func__, xdr);
4490 return -EIO;
4491}
4492
Bryan Schumakerae42c702010-10-21 16:33:17 -04004493static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4494 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004495 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004496 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497{
Trond Myklebustbca79472009-03-11 14:10:26 -04004498 int status;
4499 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004500 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004501 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004503 status = decode_attr_type(xdr, bitmap, &type);
4504 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004505 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004506 fattr->mode = 0;
4507 if (status != 0) {
4508 fattr->mode |= nfs_type2fmt[type];
4509 fattr->valid |= status;
4510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004512 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4513 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004514 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004515 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004516
4517 status = decode_attr_size(xdr, bitmap, &fattr->size);
4518 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004520 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004521
4522 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4523 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004524 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004525 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004526
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004527 err = 0;
4528 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004529 if (status < 0)
4530 goto xdr_error;
4531
4532 status = decode_attr_filehandle(xdr, bitmap, fh);
4533 if (status < 0)
4534 goto xdr_error;
4535
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004536 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4537 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004539 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004540
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004541 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004542 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004543 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004544 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004545
4546 status = decode_attr_mode(xdr, bitmap, &fmode);
4547 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004549 if (status != 0) {
4550 fattr->mode |= fmode;
4551 fattr->valid |= status;
4552 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004553
4554 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4555 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004556 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004557 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004558
Trond Myklebust6926afd2012-01-07 13:22:46 -05004559 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004560 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004562 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004563
Trond Myklebust6926afd2012-01-07 13:22:46 -05004564 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004565 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004567 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004568
4569 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4570 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004571 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004572 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004573
4574 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4575 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004577 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004578
4579 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4580 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004582 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004583
4584 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4585 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004587 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004588
4589 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4590 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004592 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004593
Trond Myklebust28331a42011-04-27 13:47:52 -04004594 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004595 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004596 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004597 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004598
Andy Adamson88034c32012-05-23 05:02:34 -04004599 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4600 if (status < 0)
4601 goto xdr_error;
4602
David Quigleyaa9c2662013-05-22 12:50:44 -04004603 if (label) {
4604 status = decode_attr_security_label(xdr, bitmap, label);
4605 if (status < 0)
4606 goto xdr_error;
4607 fattr->valid |= status;
4608 }
4609
Bryan Schumakerae42c702010-10-21 16:33:17 -04004610xdr_error:
4611 dprintk("%s: xdr returned %d\n", __func__, -status);
4612 return status;
4613}
4614
4615static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004616 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004617 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004618{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004619 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004620 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004621 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004622 int status;
4623
4624 status = decode_op_hdr(xdr, OP_GETATTR);
4625 if (status < 0)
4626 goto xdr_error;
4627
4628 status = decode_attr_bitmap(xdr, bitmap);
4629 if (status < 0)
4630 goto xdr_error;
4631
4632 status = decode_attr_length(xdr, &attrlen, &savep);
4633 if (status < 0)
4634 goto xdr_error;
4635
David Quigleyaa9c2662013-05-22 12:50:44 -04004636 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4637 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004638 if (status < 0)
4639 goto xdr_error;
4640
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004641 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004643 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644 return status;
4645}
4646
David Quigleyaa9c2662013-05-22 12:50:44 -04004647static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4648 struct nfs4_label *label, const struct nfs_server *server)
4649{
4650 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4651}
4652
Bryan Schumakerae42c702010-10-21 16:33:17 -04004653static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004654 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004655{
David Quigleyaa9c2662013-05-22 12:50:44 -04004656 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004657}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658
Andy Adamson504913f2010-10-20 00:17:57 -04004659/*
4660 * Decode potentially multiple layout types. Currently we only support
4661 * one layout driver per file system.
4662 */
4663static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4664 uint32_t *layouttype)
4665{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004666 __be32 *p;
Andy Adamson504913f2010-10-20 00:17:57 -04004667 int num;
4668
4669 p = xdr_inline_decode(xdr, 4);
4670 if (unlikely(!p))
4671 goto out_overflow;
4672 num = be32_to_cpup(p);
4673
4674 /* pNFS is not supported by the underlying file system */
4675 if (num == 0) {
4676 *layouttype = 0;
4677 return 0;
4678 }
4679 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004680 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4681 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004682
4683 /* Decode and set first layout type, move xdr->p past unused types */
4684 p = xdr_inline_decode(xdr, num * 4);
4685 if (unlikely(!p))
4686 goto out_overflow;
4687 *layouttype = be32_to_cpup(p);
4688 return 0;
4689out_overflow:
4690 print_overflow_msg(__func__, xdr);
4691 return -EIO;
4692}
4693
4694/*
4695 * The type of file system exported.
4696 * Note we must ensure that layouttype is set in any non-error case.
4697 */
4698static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4699 uint32_t *layouttype)
4700{
4701 int status = 0;
4702
4703 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4704 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4705 return -EIO;
4706 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4707 status = decode_first_pnfs_layout_type(xdr, layouttype);
4708 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4709 } else
4710 *layouttype = 0;
4711 return status;
4712}
4713
Fred Isamandae100c2011-07-30 20:52:37 -04004714/*
4715 * The prefered block size for layout directed io
4716 */
4717static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4718 uint32_t *res)
4719{
4720 __be32 *p;
4721
4722 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4723 *res = 0;
4724 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4725 p = xdr_inline_decode(xdr, 4);
4726 if (unlikely(!p)) {
4727 print_overflow_msg(__func__, xdr);
4728 return -EIO;
4729 }
4730 *res = be32_to_cpup(p);
4731 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4732 }
4733 return 0;
4734}
4735
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4737{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004738 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004739 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740 int status;
4741
4742 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4743 goto xdr_error;
4744 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4745 goto xdr_error;
4746 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4747 goto xdr_error;
4748
4749 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4750
4751 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4752 goto xdr_error;
4753 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4754 goto xdr_error;
4755 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4756 goto xdr_error;
4757 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4758 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4759 goto xdr_error;
4760 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004761 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4762 if (status != 0)
4763 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004764 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4765 if (status != 0)
4766 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004767 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4768 if (status)
4769 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770
4771 status = verify_attr_len(xdr, savep, attrlen);
4772xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004773 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 return status;
4775}
4776
4777static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4778{
Al Viro8687b632006-10-19 23:28:48 -07004779 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780 uint32_t len;
4781 int status;
4782
Trond Myklebust99367812007-07-17 21:52:41 -04004783 /* Zero handle first to allow comparisons */
4784 memset(fh, 0, sizeof(*fh));
4785
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 status = decode_op_hdr(xdr, OP_GETFH);
4787 if (status)
4788 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789
Benny Halevyc0eae662009-08-14 17:20:14 +03004790 p = xdr_inline_decode(xdr, 4);
4791 if (unlikely(!p))
4792 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004793 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794 if (len > NFS4_FHSIZE)
4795 return -EIO;
4796 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004797 p = xdr_inline_decode(xdr, len);
4798 if (unlikely(!p))
4799 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004800 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004802out_overflow:
4803 print_overflow_msg(__func__, xdr);
4804 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004805}
4806
4807static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4808{
4809 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004810
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811 status = decode_op_hdr(xdr, OP_LINK);
4812 if (status)
4813 return status;
4814 return decode_change_info(xdr, cinfo);
4815}
4816
4817/*
4818 * We create the owner, so we know a proper owner.id length is 4.
4819 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004820static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004822 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004823 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004824 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004826 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004827 if (unlikely(!p))
4828 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004829 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004830 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004831 type = be32_to_cpup(p++); /* 4 byte read */
4832 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004833 fl->fl_start = (loff_t)offset;
4834 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4835 if (length == ~(uint64_t)0)
4836 fl->fl_end = OFFSET_MAX;
4837 fl->fl_type = F_WRLCK;
4838 if (type & 1)
4839 fl->fl_type = F_RDLCK;
4840 fl->fl_pid = 0;
4841 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004842 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4843 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4844 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004845 if (likely(p))
4846 return -NFS4ERR_DENIED;
4847out_overflow:
4848 print_overflow_msg(__func__, xdr);
4849 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850}
4851
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004852static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854 int status;
4855
4856 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004857 if (status == -EIO)
4858 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004859 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004860 status = decode_stateid(xdr, &res->stateid);
4861 if (unlikely(status))
4862 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004864 status = decode_lock_denied(xdr, NULL);
4865 if (res->open_seqid != NULL)
4866 nfs_increment_open_seqid(status, res->open_seqid);
4867 nfs_increment_lock_seqid(status, res->lock_seqid);
4868out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004869 return status;
4870}
4871
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004872static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873{
4874 int status;
4875 status = decode_op_hdr(xdr, OP_LOCKT);
4876 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004877 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 return status;
4879}
4880
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004881static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883 int status;
4884
4885 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004886 if (status != -EIO)
4887 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004888 if (status == 0)
4889 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 return status;
4891}
4892
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004893static int decode_release_lockowner(struct xdr_stream *xdr)
4894{
4895 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4896}
4897
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898static int decode_lookup(struct xdr_stream *xdr)
4899{
4900 return decode_op_hdr(xdr, OP_LOOKUP);
4901}
4902
4903/* This is too sick! */
4904static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4905{
Andy Adamson05d564f2008-12-23 16:06:15 -05004906 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004907 uint32_t limit_type, nblocks, blocksize;
4908
Benny Halevyc0eae662009-08-14 17:20:14 +03004909 p = xdr_inline_decode(xdr, 12);
4910 if (unlikely(!p))
4911 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004912 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004914 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004915 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004916 break;
4917 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004918 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004919 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004920 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921 }
4922 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004923out_overflow:
4924 print_overflow_msg(__func__, xdr);
4925 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926}
4927
Trond Myklebust6ae37332015-01-30 14:21:14 -05004928static int decode_rw_delegation(struct xdr_stream *xdr,
4929 uint32_t delegation_type,
4930 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004931{
Andy Adamson05d564f2008-12-23 16:06:15 -05004932 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004933 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004934
Benny Halevy07d30432009-08-14 17:19:52 +03004935 status = decode_stateid(xdr, &res->delegation);
4936 if (unlikely(status))
4937 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004938 p = xdr_inline_decode(xdr, 4);
4939 if (unlikely(!p))
4940 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004941 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004942
Linus Torvalds1da177e2005-04-16 15:20:36 -07004943 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004944 case NFS4_OPEN_DELEGATE_READ:
4945 res->delegation_type = FMODE_READ;
4946 break;
4947 case NFS4_OPEN_DELEGATE_WRITE:
4948 res->delegation_type = FMODE_WRITE|FMODE_READ;
4949 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004950 return -EIO;
4951 }
David Howells7539bba2006-08-22 20:06:09 -04004952 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004953out_overflow:
4954 print_overflow_msg(__func__, xdr);
4955 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004956}
4957
Trond Myklebust6ae37332015-01-30 14:21:14 -05004958static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4959{
4960 __be32 *p;
4961 uint32_t why_no_delegation;
4962
4963 p = xdr_inline_decode(xdr, 4);
4964 if (unlikely(!p))
4965 goto out_overflow;
4966 why_no_delegation = be32_to_cpup(p);
4967 switch (why_no_delegation) {
4968 case WND4_CONTENTION:
4969 case WND4_RESOURCE:
4970 xdr_inline_decode(xdr, 4);
4971 /* Ignore for now */
4972 }
4973 return 0;
4974out_overflow:
4975 print_overflow_msg(__func__, xdr);
4976 return -EIO;
4977}
4978
4979static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4980{
4981 __be32 *p;
4982 uint32_t delegation_type;
4983
4984 p = xdr_inline_decode(xdr, 4);
4985 if (unlikely(!p))
4986 goto out_overflow;
4987 delegation_type = be32_to_cpup(p);
4988 res->delegation_type = 0;
4989 switch (delegation_type) {
4990 case NFS4_OPEN_DELEGATE_NONE:
4991 return 0;
4992 case NFS4_OPEN_DELEGATE_READ:
4993 case NFS4_OPEN_DELEGATE_WRITE:
4994 return decode_rw_delegation(xdr, delegation_type, res);
4995 case NFS4_OPEN_DELEGATE_NONE_EXT:
4996 return decode_no_delegation(xdr, res);
4997 }
4998 return -EIO;
4999out_overflow:
5000 print_overflow_msg(__func__, xdr);
5001 return -EIO;
5002}
5003
Linus Torvalds1da177e2005-04-16 15:20:36 -07005004static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5005{
Andy Adamson05d564f2008-12-23 16:06:15 -05005006 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005007 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005008 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009
Trond Myklebustc7848f62013-12-04 17:39:23 -05005010 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5011 return status;
5012 nfs_increment_open_seqid(status, res->seqid);
5013 if (status)
5014 return status;
5015 status = decode_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005016 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005017 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018
Andy Adamson05d564f2008-12-23 16:06:15 -05005019 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005020
Benny Halevyc0eae662009-08-14 17:20:14 +03005021 p = xdr_inline_decode(xdr, 8);
5022 if (unlikely(!p))
5023 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005024 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005025 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005026 if (bmlen > 10)
5027 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028
Benny Halevyc0eae662009-08-14 17:20:14 +03005029 p = xdr_inline_decode(xdr, bmlen << 2);
5030 if (unlikely(!p))
5031 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005032 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5033 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005034 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005035 for (; i < NFS4_BITMAP_SIZE; i++)
5036 res->attrset[i] = 0;
5037
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038 return decode_delegation(xdr, res);
5039xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005040 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005042out_overflow:
5043 print_overflow_msg(__func__, xdr);
5044 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045}
5046
5047static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5048{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049 int status;
5050
Andy Adamson05d564f2008-12-23 16:06:15 -05005051 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005052 if (status != -EIO)
5053 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005054 if (!status)
5055 status = decode_stateid(xdr, &res->stateid);
5056 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057}
5058
5059static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5060{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061 int status;
5062
5063 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005064 if (status != -EIO)
5065 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005066 if (!status)
5067 status = decode_stateid(xdr, &res->stateid);
5068 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069}
5070
5071static int decode_putfh(struct xdr_stream *xdr)
5072{
5073 return decode_op_hdr(xdr, OP_PUTFH);
5074}
5075
5076static int decode_putrootfh(struct xdr_stream *xdr)
5077{
5078 return decode_op_hdr(xdr, OP_PUTROOTFH);
5079}
5080
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005081static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5082 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083{
Al Viro8687b632006-10-19 23:28:48 -07005084 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005085 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086 int status;
5087
5088 status = decode_op_hdr(xdr, OP_READ);
5089 if (status)
5090 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005091 p = xdr_inline_decode(xdr, 8);
5092 if (unlikely(!p))
5093 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005094 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005095 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005096 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005097 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005098 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005099 "count %u > recvd %u\n", count, recvd);
5100 count = recvd;
5101 eof = 0;
5102 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103 res->eof = eof;
5104 res->count = count;
5105 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005106out_overflow:
5107 print_overflow_msg(__func__, xdr);
5108 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109}
5110
5111static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5112{
Chuck Leverbcecff72007-10-26 13:32:03 -04005113 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005114 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115
5116 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005117 if (!status)
5118 status = decode_verifier(xdr, readdir->verifier.data);
5119 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005121 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005122 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005123 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005124 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005125}
5126
5127static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5128{
5129 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005130 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005131 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132 int status;
5133
5134 status = decode_op_hdr(xdr, OP_READLINK);
5135 if (status)
5136 return status;
5137
5138 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005139 p = xdr_inline_decode(xdr, 4);
5140 if (unlikely(!p))
5141 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005142 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005144 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005145 return -ENAMETOOLONG;
5146 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005147 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005148 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005149 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005150 "count %u > recvd %u\n", len, recvd);
5151 return -EIO;
5152 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153 /*
5154 * The XDR encode routine has set things up so that
5155 * the link text will be copied directly into the
5156 * buffer. We just have to do overflow-checking,
5157 * and and null-terminate the text (the VFS expects
5158 * null-termination).
5159 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005160 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005161 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005162out_overflow:
5163 print_overflow_msg(__func__, xdr);
5164 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005165}
5166
5167static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5168{
5169 int status;
5170
5171 status = decode_op_hdr(xdr, OP_REMOVE);
5172 if (status)
5173 goto out;
5174 status = decode_change_info(xdr, cinfo);
5175out:
5176 return status;
5177}
5178
5179static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5180 struct nfs4_change_info *new_cinfo)
5181{
5182 int status;
5183
5184 status = decode_op_hdr(xdr, OP_RENAME);
5185 if (status)
5186 goto out;
5187 if ((status = decode_change_info(xdr, old_cinfo)))
5188 goto out;
5189 status = decode_change_info(xdr, new_cinfo);
5190out:
5191 return status;
5192}
5193
5194static int decode_renew(struct xdr_stream *xdr)
5195{
5196 return decode_op_hdr(xdr, OP_RENEW);
5197}
5198
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005199static int
5200decode_restorefh(struct xdr_stream *xdr)
5201{
5202 return decode_op_hdr(xdr, OP_RESTOREFH);
5203}
5204
J. Bruce Fields029d1052005-06-22 17:16:22 +00005205static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005206 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005207{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005208 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005209 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005210 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005211 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005212 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005213
Andy Adamsonbf118a32011-12-07 11:55:27 -05005214 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005215 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5216 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005217
Trond Myklebust519d3952012-08-14 17:30:10 -04005218 xdr_enter_page(xdr, xdr->buf->page_len);
5219
Trond Myklebustcff298c2012-08-14 17:14:17 -04005220 /* Calculate the offset of the page data */
5221 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005222
J. Bruce Fields029d1052005-06-22 17:16:22 +00005223 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5224 goto out;
5225 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5226 goto out;
5227
5228 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5229 return -EIO;
5230 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005231
Andy Adamsonbf118a32011-12-07 11:55:27 -05005232 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5233 * are stored with the acl data to handle the problem of
5234 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005235 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005236 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005237
5238 /* Check for receive buffer overflow */
5239 if (res->acl_len > (xdr->nwords << 2) ||
5240 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5241 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005242 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005243 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005244 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005245 } else
5246 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005247
5248out:
5249 return status;
5250}
5251
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252static int
5253decode_savefh(struct xdr_stream *xdr)
5254{
5255 return decode_op_hdr(xdr, OP_SAVEFH);
5256}
5257
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005258static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005259{
Al Viro8687b632006-10-19 23:28:48 -07005260 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005261 uint32_t bmlen;
5262 int status;
5263
Linus Torvalds1da177e2005-04-16 15:20:36 -07005264 status = decode_op_hdr(xdr, OP_SETATTR);
5265 if (status)
5266 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005267 p = xdr_inline_decode(xdr, 4);
5268 if (unlikely(!p))
5269 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005270 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005271 p = xdr_inline_decode(xdr, bmlen << 2);
5272 if (likely(p))
5273 return 0;
5274out_overflow:
5275 print_overflow_msg(__func__, xdr);
5276 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277}
5278
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005279static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005280{
Al Viro8687b632006-10-19 23:28:48 -07005281 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282 uint32_t opnum;
5283 int32_t nfserr;
5284
Benny Halevyc0eae662009-08-14 17:20:14 +03005285 p = xdr_inline_decode(xdr, 8);
5286 if (unlikely(!p))
5287 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005288 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005289 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005290 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005291 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005292 return -EIO;
5293 }
Benny Halevycccddf42009-08-14 17:20:19 +03005294 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005295 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005296 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5297 if (unlikely(!p))
5298 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005299 p = xdr_decode_hyper(p, &res->clientid);
5300 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005301 } else if (nfserr == NFSERR_CLID_INUSE) {
5302 uint32_t len;
5303
5304 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005305 p = xdr_inline_decode(xdr, 4);
5306 if (unlikely(!p))
5307 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005308 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005309 p = xdr_inline_decode(xdr, len);
5310 if (unlikely(!p))
5311 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005312
5313 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005314 p = xdr_inline_decode(xdr, 4);
5315 if (unlikely(!p))
5316 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005317 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005318 p = xdr_inline_decode(xdr, len);
5319 if (unlikely(!p))
5320 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005321 return -NFSERR_CLID_INUSE;
5322 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005323 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005324
5325 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005326out_overflow:
5327 print_overflow_msg(__func__, xdr);
5328 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005329}
5330
5331static int decode_setclientid_confirm(struct xdr_stream *xdr)
5332{
5333 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5334}
5335
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005336static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005337{
Al Viro8687b632006-10-19 23:28:48 -07005338 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005339 int status;
5340
5341 status = decode_op_hdr(xdr, OP_WRITE);
5342 if (status)
5343 return status;
5344
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005345 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005346 if (unlikely(!p))
5347 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005348 res->count = be32_to_cpup(p++);
5349 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005350 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005351out_overflow:
5352 print_overflow_msg(__func__, xdr);
5353 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005354}
5355
5356static int decode_delegreturn(struct xdr_stream *xdr)
5357{
5358 return decode_op_hdr(xdr, OP_DELEGRETURN);
5359}
5360
Chuck Leverfb15b262013-03-16 15:54:34 -04005361static int decode_secinfo_gss(struct xdr_stream *xdr,
5362 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005363{
Chuck Leverfb15b262013-03-16 15:54:34 -04005364 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005365 __be32 *p;
5366
5367 p = xdr_inline_decode(xdr, 4);
5368 if (unlikely(!p))
5369 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005370 oid_len = be32_to_cpup(p);
5371 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005372 goto out_err;
5373
Chuck Leverfb15b262013-03-16 15:54:34 -04005374 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005375 if (unlikely(!p))
5376 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005377 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5378 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005379
5380 p = xdr_inline_decode(xdr, 8);
5381 if (unlikely(!p))
5382 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005383 flavor->flavor_info.qop = be32_to_cpup(p++);
5384 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005385
5386 return 0;
5387
5388out_overflow:
5389 print_overflow_msg(__func__, xdr);
5390 return -EIO;
5391out_err:
5392 return -EINVAL;
5393}
5394
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005395static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005396{
Chuck Leverfb15b262013-03-16 15:54:34 -04005397 struct nfs4_secinfo4 *sec_flavor;
5398 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005399 int status;
5400 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005401
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005402 p = xdr_inline_decode(xdr, 4);
5403 if (unlikely(!p))
5404 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005405
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005406 res->flavors->num_flavors = 0;
5407 num_flavors = be32_to_cpup(p);
5408
5409 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005410 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005411 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005412 break;
5413
5414 p = xdr_inline_decode(xdr, 4);
5415 if (unlikely(!p))
5416 goto out_overflow;
5417 sec_flavor->flavor = be32_to_cpup(p);
5418
5419 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005420 status = decode_secinfo_gss(xdr, sec_flavor);
5421 if (status)
5422 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005423 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005424 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005425 }
5426
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005427 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005428out:
5429 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005430out_overflow:
5431 print_overflow_msg(__func__, xdr);
5432 return -EIO;
5433}
5434
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005435static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5436{
5437 int status = decode_op_hdr(xdr, OP_SECINFO);
5438 if (status)
5439 return status;
5440 return decode_secinfo_common(xdr, res);
5441}
5442
Benny Halevy99fe60d2009-04-01 09:22:29 -04005443#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005444static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5445{
5446 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5447 if (status)
5448 return status;
5449 return decode_secinfo_common(xdr, res);
5450}
5451
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005452static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5453{
5454 __be32 *p;
5455 uint32_t bitmap_words;
5456 unsigned int i;
5457
5458 p = xdr_inline_decode(xdr, 4);
5459 bitmap_words = be32_to_cpup(p++);
5460 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5461 return -EIO;
5462 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5463 for (i = 0; i < bitmap_words; i++)
5464 op_map->u.words[i] = be32_to_cpup(p++);
5465
5466 return 0;
5467}
5468
Benny Halevy99fe60d2009-04-01 09:22:29 -04005469static int decode_exchange_id(struct xdr_stream *xdr,
5470 struct nfs41_exchange_id_res *res)
5471{
5472 __be32 *p;
5473 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005474 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005475 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005476 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005477
5478 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5479 if (status)
5480 return status;
5481
Benny Halevyc0eae662009-08-14 17:20:14 +03005482 p = xdr_inline_decode(xdr, 8);
5483 if (unlikely(!p))
5484 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005485 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005486 p = xdr_inline_decode(xdr, 12);
5487 if (unlikely(!p))
5488 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005489 res->seqid = be32_to_cpup(p++);
5490 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005491
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005492 res->state_protect.how = be32_to_cpup(p);
5493 switch (res->state_protect.how) {
5494 case SP4_NONE:
5495 break;
5496 case SP4_MACH_CRED:
5497 status = decode_op_map(xdr, &res->state_protect.enforce);
5498 if (status)
5499 return status;
5500 status = decode_op_map(xdr, &res->state_protect.allow);
5501 if (status)
5502 return status;
5503 break;
5504 default:
5505 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005506 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005507 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005508
Chuck Leveracdeb692012-05-21 22:46:16 -04005509 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005510 p = xdr_inline_decode(xdr, 8);
5511 if (unlikely(!p))
5512 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005513 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005514
Chuck Leveracdeb692012-05-21 22:46:16 -04005515 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005516 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5517 if (unlikely(status))
5518 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005519 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5520 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005521 memcpy(res->server_owner->major_id, dummy_str, dummy);
5522 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005523
Chuck Leveracdeb692012-05-21 22:46:16 -04005524 /* server_scope4 */
5525 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5526 if (unlikely(status))
5527 return status;
5528 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5529 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005530 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5531 res->server_scope->server_scope_sz = dummy;
5532
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005533 /* Implementation Id */
5534 p = xdr_inline_decode(xdr, 4);
5535 if (unlikely(!p))
5536 goto out_overflow;
5537 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005538
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005539 if (impl_id_count) {
5540 /* nii_domain */
5541 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5542 if (unlikely(status))
5543 return status;
5544 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5545 return -EIO;
5546 memcpy(res->impl_id->domain, dummy_str, dummy);
5547
5548 /* nii_name */
5549 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5550 if (unlikely(status))
5551 return status;
5552 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5553 return -EIO;
5554 memcpy(res->impl_id->name, dummy_str, dummy);
5555
5556 /* nii_date */
5557 p = xdr_inline_decode(xdr, 12);
5558 if (unlikely(!p))
5559 goto out_overflow;
5560 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5561 res->impl_id->date.nseconds = be32_to_cpup(p);
5562
5563 /* if there's more than one entry, ignore the rest */
5564 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005565 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005566out_overflow:
5567 print_overflow_msg(__func__, xdr);
5568 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005569}
Andy Adamsonfc931582009-04-01 09:22:31 -04005570
5571static int decode_chan_attrs(struct xdr_stream *xdr,
5572 struct nfs4_channel_attrs *attrs)
5573{
5574 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005575 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005576
Benny Halevyc0eae662009-08-14 17:20:14 +03005577 p = xdr_inline_decode(xdr, 28);
5578 if (unlikely(!p))
5579 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005580 val = be32_to_cpup(p++); /* headerpadsz */
5581 if (val)
5582 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005583 attrs->max_rqst_sz = be32_to_cpup(p++);
5584 attrs->max_resp_sz = be32_to_cpup(p++);
5585 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5586 attrs->max_ops = be32_to_cpup(p++);
5587 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005588 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005589 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005590 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5591 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005592 return -EINVAL;
5593 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005594 if (nr_attrs == 1) {
5595 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5596 if (unlikely(!p))
5597 goto out_overflow;
5598 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005599 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005600out_overflow:
5601 print_overflow_msg(__func__, xdr);
5602 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005603}
5604
Benny Halevye78291e2009-08-14 17:20:00 +03005605static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5606{
5607 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005608}
5609
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005610static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5611 struct nfs41_bind_conn_to_session_res *res)
5612{
5613 __be32 *p;
5614 int status;
5615
5616 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5617 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005618 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005619 if (unlikely(status))
5620 return status;
5621
5622 /* dir flags, rdma mode bool */
5623 p = xdr_inline_decode(xdr, 8);
5624 if (unlikely(!p))
5625 goto out_overflow;
5626
5627 res->dir = be32_to_cpup(p++);
5628 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5629 return -EIO;
5630 if (be32_to_cpup(p) == 0)
5631 res->use_conn_in_rdma_mode = false;
5632 else
5633 res->use_conn_in_rdma_mode = true;
5634
5635 return 0;
5636out_overflow:
5637 print_overflow_msg(__func__, xdr);
5638 return -EIO;
5639}
5640
Andy Adamsonfc931582009-04-01 09:22:31 -04005641static int decode_create_session(struct xdr_stream *xdr,
5642 struct nfs41_create_session_res *res)
5643{
5644 __be32 *p;
5645 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005646
5647 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005648 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005649 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005650 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005651 return status;
5652
Andy Adamsonfc931582009-04-01 09:22:31 -04005653 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005654 p = xdr_inline_decode(xdr, 8);
5655 if (unlikely(!p))
5656 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005657 res->seqid = be32_to_cpup(p++);
5658 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005659
5660 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005661 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005662 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005663 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005664 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005665out_overflow:
5666 print_overflow_msg(__func__, xdr);
5667 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005668}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005669
5670static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5671{
5672 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5673}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005674
Trond Myklebust66245532012-05-25 17:18:09 -04005675static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5676{
5677 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5678}
5679
Ricardo Labiaga180197532009-12-05 16:08:40 -05005680static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5681{
5682 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5683}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005684#endif /* CONFIG_NFS_V4_1 */
5685
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005686static int decode_sequence(struct xdr_stream *xdr,
5687 struct nfs4_sequence_res *res,
5688 struct rpc_rqst *rqstp)
5689{
5690#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005691 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005692 struct nfs4_sessionid id;
5693 u32 dummy;
5694 int status;
5695 __be32 *p;
5696
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005697 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005698 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005699 if (!res->sr_slot->table->session)
5700 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005701
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005702 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005703 if (!status)
5704 status = decode_sessionid(xdr, &id);
5705 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005706 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005707
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005708 /*
5709 * If the server returns different values for sessionID, slotID or
5710 * sequence number, the server is looney tunes.
5711 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005712 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005713 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005714
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005715 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005716 NFS4_MAX_SESSIONID_LEN)) {
5717 dprintk("%s Invalid session id\n", __func__);
5718 goto out_err;
5719 }
Benny Halevye78291e2009-08-14 17:20:00 +03005720
Benny Halevyc0eae662009-08-14 17:20:14 +03005721 p = xdr_inline_decode(xdr, 20);
5722 if (unlikely(!p))
5723 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005724
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005725 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005726 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005727 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005728 dprintk("%s Invalid sequence number\n", __func__);
5729 goto out_err;
5730 }
5731 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005732 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005733 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005734 dprintk("%s Invalid slot id\n", __func__);
5735 goto out_err;
5736 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005737 /* highest slot id */
5738 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005739 /* target highest slot id */
5740 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005741 /* result flags */
5742 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005743 status = 0;
5744out_err:
5745 res->sr_status = status;
5746 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005747out_overflow:
5748 print_overflow_msg(__func__, xdr);
5749 status = -EIO;
5750 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005751#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005752 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005753#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005754}
5755
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005756#if defined(CONFIG_NFS_V4_1)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005757static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005758 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005759{
Trond Myklebust4e590802015-03-09 14:01:25 -04005760 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005761 __be32 *p;
5762 uint32_t len, type;
5763 int status;
5764
5765 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5766 if (status) {
5767 if (status == -ETOOSMALL) {
5768 p = xdr_inline_decode(xdr, 4);
5769 if (unlikely(!p))
5770 goto out_overflow;
5771 pdev->mincount = be32_to_cpup(p);
5772 dprintk("%s: Min count too small. mincnt = %u\n",
5773 __func__, pdev->mincount);
5774 }
5775 return status;
5776 }
5777
5778 p = xdr_inline_decode(xdr, 8);
5779 if (unlikely(!p))
5780 goto out_overflow;
5781 type = be32_to_cpup(p++);
5782 if (type != pdev->layout_type) {
5783 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5784 __func__, pdev->layout_type, type);
5785 return -EINVAL;
5786 }
5787 /*
5788 * Get the length of the opaque device_addr4. xdr_read_pages places
5789 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5790 * and places the remaining xdr data in xdr_buf->tail
5791 */
5792 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005793 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5794 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005795
5796 /* Parse notification bitmap, verifying that it is zero. */
5797 p = xdr_inline_decode(xdr, 4);
5798 if (unlikely(!p))
5799 goto out_overflow;
5800 len = be32_to_cpup(p);
5801 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005802 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005803
5804 p = xdr_inline_decode(xdr, 4 * len);
5805 if (unlikely(!p))
5806 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005807
Trond Myklebust4e590802015-03-09 14:01:25 -04005808 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005809 for (i = 1; i < len; i++) {
5810 if (be32_to_cpup(p++)) {
5811 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005812 __func__);
5813 return -EIO;
5814 }
5815 }
5816 }
5817 return 0;
5818out_overflow:
5819 print_overflow_msg(__func__, xdr);
5820 return -EIO;
5821}
5822
5823static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5824 struct nfs4_layoutget_res *res)
5825{
5826 __be32 *p;
5827 int status;
5828 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005829 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005830
5831 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5832 if (status)
5833 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005834 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005835 if (unlikely(!p))
5836 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005837 res->return_on_close = be32_to_cpup(p);
5838 decode_stateid(xdr, &res->stateid);
5839 p = xdr_inline_decode(xdr, 4);
5840 if (unlikely(!p))
5841 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005842 layout_count = be32_to_cpup(p);
5843 if (!layout_count) {
5844 dprintk("%s: server responded with empty layout array\n",
5845 __func__);
5846 return -EINVAL;
5847 }
5848
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005849 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005850 if (unlikely(!p))
5851 goto out_overflow;
5852 p = xdr_decode_hyper(p, &res->range.offset);
5853 p = xdr_decode_hyper(p, &res->range.length);
5854 res->range.iomode = be32_to_cpup(p++);
5855 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005856 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005857
5858 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5859 __func__,
5860 (unsigned long)res->range.offset,
5861 (unsigned long)res->range.length,
5862 res->range.iomode,
5863 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005864 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005865
Trond Myklebust64bd5772012-06-20 22:35:05 -04005866 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005867 if (res->layoutp->len > recvd) {
5868 dprintk("NFS: server cheating in layoutget reply: "
5869 "layout len %u > recvd %u\n",
5870 res->layoutp->len, recvd);
5871 return -EINVAL;
5872 }
5873
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005874 if (layout_count > 1) {
5875 /* We only handle a length one array at the moment. Any
5876 * further entries are just ignored. Note that this means
5877 * the client may see a response that is less than the
5878 * minimum it requested.
5879 */
5880 dprintk("%s: server responded with %d layouts, dropping tail\n",
5881 __func__, layout_count);
5882 }
5883
5884 return 0;
5885out_overflow:
5886 print_overflow_msg(__func__, xdr);
5887 return -EIO;
5888}
Andy Adamson863a3c62011-03-23 13:27:54 +00005889
Benny Halevycbe82602011-05-22 19:52:37 +03005890static int decode_layoutreturn(struct xdr_stream *xdr,
5891 struct nfs4_layoutreturn_res *res)
5892{
5893 __be32 *p;
5894 int status;
5895
5896 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5897 if (status)
5898 return status;
5899 p = xdr_inline_decode(xdr, 4);
5900 if (unlikely(!p))
5901 goto out_overflow;
5902 res->lrs_present = be32_to_cpup(p);
5903 if (res->lrs_present)
5904 status = decode_stateid(xdr, &res->stateid);
5905 return status;
5906out_overflow:
5907 print_overflow_msg(__func__, xdr);
5908 return -EIO;
5909}
5910
Andy Adamson863a3c62011-03-23 13:27:54 +00005911static int decode_layoutcommit(struct xdr_stream *xdr,
5912 struct rpc_rqst *req,
5913 struct nfs4_layoutcommit_res *res)
5914{
5915 __be32 *p;
5916 __u32 sizechanged;
5917 int status;
5918
5919 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005920 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005921 if (status)
5922 return status;
5923
5924 p = xdr_inline_decode(xdr, 4);
5925 if (unlikely(!p))
5926 goto out_overflow;
5927 sizechanged = be32_to_cpup(p);
5928
5929 if (sizechanged) {
5930 /* throw away new size */
5931 p = xdr_inline_decode(xdr, 8);
5932 if (unlikely(!p))
5933 goto out_overflow;
5934 }
5935 return 0;
5936out_overflow:
5937 print_overflow_msg(__func__, xdr);
5938 return -EIO;
5939}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005940
5941static int decode_test_stateid(struct xdr_stream *xdr,
5942 struct nfs41_test_stateid_res *res)
5943{
5944 __be32 *p;
5945 int status;
5946 int num_res;
5947
5948 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5949 if (status)
5950 return status;
5951
5952 p = xdr_inline_decode(xdr, 4);
5953 if (unlikely(!p))
5954 goto out_overflow;
5955 num_res = be32_to_cpup(p++);
5956 if (num_res != 1)
5957 goto out;
5958
5959 p = xdr_inline_decode(xdr, 4);
5960 if (unlikely(!p))
5961 goto out_overflow;
5962 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005963
5964 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005965out_overflow:
5966 print_overflow_msg(__func__, xdr);
5967out:
5968 return -EIO;
5969}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005970
5971static int decode_free_stateid(struct xdr_stream *xdr,
5972 struct nfs41_free_stateid_res *res)
5973{
Andy Adamson9f79fb42013-09-10 12:56:29 -04005974 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005975 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005976}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005977#endif /* CONFIG_NFS_V4_1 */
5978
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979/*
Benny Halevy49c25592008-12-23 16:06:16 -05005980 * END OF "GENERIC" DECODE ROUTINES.
5981 */
5982
5983/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984 * Decode OPEN_DOWNGRADE response
5985 */
Chuck Leverbf269552010-12-14 14:59:29 +00005986static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5987 struct xdr_stream *xdr,
5988 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005989{
Andy Adamson05d564f2008-12-23 16:06:15 -05005990 struct compound_hdr hdr;
5991 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005992
Chuck Leverbf269552010-12-14 14:59:29 +00005993 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005994 if (status)
5995 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005996 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005997 if (status)
5998 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005999 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006000 if (status)
6001 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006002 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006003 if (status != 0)
6004 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006005 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006006out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006007 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008}
6009
6010/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006011 * Decode ACCESS response
6012 */
Chuck Leverbf269552010-12-14 14:59:29 +00006013static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6014 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006015{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006016 struct compound_hdr hdr;
6017 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006018
Chuck Leverbf269552010-12-14 14:59:29 +00006019 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006020 if (status)
6021 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006022 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006023 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006025 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006026 if (status != 0)
6027 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006028 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006029 if (status != 0)
6030 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006031 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006032out:
6033 return status;
6034}
6035
6036/*
6037 * Decode LOOKUP response
6038 */
Chuck Leverbf269552010-12-14 14:59:29 +00006039static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6040 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006041{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006042 struct compound_hdr hdr;
6043 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006044
Chuck Leverbf269552010-12-14 14:59:29 +00006045 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006046 if (status)
6047 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006048 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006049 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006050 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006051 status = decode_putfh(xdr);
6052 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006053 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006054 status = decode_lookup(xdr);
6055 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006057 status = decode_getfh(xdr, res->fh);
6058 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006059 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006060 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061out:
6062 return status;
6063}
6064
6065/*
6066 * Decode LOOKUP_ROOT response
6067 */
Chuck Leverbf269552010-12-14 14:59:29 +00006068static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6069 struct xdr_stream *xdr,
6070 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006071{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006072 struct compound_hdr hdr;
6073 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006074
Chuck Leverbf269552010-12-14 14:59:29 +00006075 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006076 if (status)
6077 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006078 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006079 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006080 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006081 status = decode_putrootfh(xdr);
6082 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006084 status = decode_getfh(xdr, res->fh);
6085 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006086 status = decode_getfattr_label(xdr, res->fattr,
6087 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006088out:
6089 return status;
6090}
6091
6092/*
6093 * Decode REMOVE response
6094 */
Chuck Leverbf269552010-12-14 14:59:29 +00006095static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6096 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098 struct compound_hdr hdr;
6099 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006100
Chuck Leverbf269552010-12-14 14:59:29 +00006101 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006102 if (status)
6103 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006104 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006105 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006107 status = decode_putfh(xdr);
6108 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006109 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006110 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006111out:
6112 return status;
6113}
6114
6115/*
6116 * Decode RENAME response
6117 */
Chuck Leverbf269552010-12-14 14:59:29 +00006118static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6119 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006120{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006121 struct compound_hdr hdr;
6122 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006123
Chuck Leverbf269552010-12-14 14:59:29 +00006124 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006125 if (status)
6126 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006127 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006128 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006129 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006130 status = decode_putfh(xdr);
6131 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006132 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006133 status = decode_savefh(xdr);
6134 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006135 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_putfh(xdr);
6137 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006139 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006140out:
6141 return status;
6142}
6143
6144/*
6145 * Decode LINK response
6146 */
Chuck Leverbf269552010-12-14 14:59:29 +00006147static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6148 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006149{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006150 struct compound_hdr hdr;
6151 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006152
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006154 if (status)
6155 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006157 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006158 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_putfh(xdr);
6160 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006161 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006162 status = decode_savefh(xdr);
6163 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006165 status = decode_putfh(xdr);
6166 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006167 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006168 status = decode_link(xdr, &res->cinfo);
6169 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006170 goto out;
6171 /*
6172 * Note order: OP_LINK leaves the directory as the current
6173 * filehandle.
6174 */
Chuck Leverbf269552010-12-14 14:59:29 +00006175 status = decode_restorefh(xdr);
6176 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006177 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006178 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006179out:
6180 return status;
6181}
6182
6183/*
6184 * Decode CREATE response
6185 */
Chuck Leverbf269552010-12-14 14:59:29 +00006186static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6187 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189 struct compound_hdr hdr;
6190 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006191
Chuck Leverbf269552010-12-14 14:59:29 +00006192 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006193 if (status)
6194 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006195 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006196 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006198 status = decode_putfh(xdr);
6199 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_create(xdr, &res->dir_cinfo);
6202 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006204 status = decode_getfh(xdr, res->fh);
6205 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006207 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208out:
6209 return status;
6210}
6211
6212/*
6213 * Decode SYMLINK response
6214 */
Chuck Leverbf269552010-12-14 14:59:29 +00006215static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6216 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006217{
Chuck Leverbf269552010-12-14 14:59:29 +00006218 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219}
6220
6221/*
6222 * Decode GETATTR response
6223 */
Chuck Leverbf269552010-12-14 14:59:29 +00006224static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6225 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227 struct compound_hdr hdr;
6228 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006229
Chuck Leverbf269552010-12-14 14:59:29 +00006230 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006231 if (status)
6232 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006233 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006234 if (status)
6235 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006236 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237 if (status)
6238 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006239 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006240out:
6241 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242}
6243
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006244/*
6245 * Encode an SETACL request
6246 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006247static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6248 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006249{
Andy Adamson05d564f2008-12-23 16:06:15 -05006250 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006251 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006252 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006253
Chuck Lever9f06c712010-12-14 14:59:18 +00006254 encode_compound_hdr(xdr, req, &hdr);
6255 encode_sequence(xdr, &args->seq_args, &hdr);
6256 encode_putfh(xdr, args->fh, &hdr);
6257 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006258 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006259}
Andy Adamson05d564f2008-12-23 16:06:15 -05006260
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006261/*
6262 * Decode SETACL response
6263 */
6264static int
Chuck Leverbf269552010-12-14 14:59:29 +00006265nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006266 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006267{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006268 struct compound_hdr hdr;
6269 int status;
6270
Chuck Leverbf269552010-12-14 14:59:29 +00006271 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006272 if (status)
6273 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006274 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006275 if (status)
6276 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006277 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006278 if (status)
6279 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006280 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006281out:
6282 return status;
6283}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006284
6285/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006286 * Decode GETACL response
6287 */
6288static int
Chuck Leverbf269552010-12-14 14:59:29 +00006289nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006290 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006291{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006292 struct compound_hdr hdr;
6293 int status;
6294
Trond Myklebust331818f2012-02-03 18:30:53 -05006295 if (res->acl_scratch != NULL) {
6296 void *p = page_address(res->acl_scratch);
6297 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6298 }
Chuck Leverbf269552010-12-14 14:59:29 +00006299 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006300 if (status)
6301 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006302 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006303 if (status)
6304 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006305 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006306 if (status)
6307 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006308 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006309
6310out:
6311 return status;
6312}
6313
6314/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006315 * Decode CLOSE response
6316 */
Chuck Leverbf269552010-12-14 14:59:29 +00006317static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6318 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006319{
Andy Adamson05d564f2008-12-23 16:06:15 -05006320 struct compound_hdr hdr;
6321 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006322
Chuck Leverbf269552010-12-14 14:59:29 +00006323 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006324 if (status)
6325 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006326 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006327 if (status)
6328 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006329 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006330 if (status)
6331 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006332 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006333 if (status != 0)
6334 goto out;
6335 /*
6336 * Note: Server may do delete on close for this file
6337 * in which case the getattr call will fail with
6338 * an ESTALE error. Shouldn't be a problem,
6339 * though, since fattr->valid will remain unset.
6340 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006341 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006342out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006343 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006344}
6345
6346/*
6347 * Decode OPEN response
6348 */
Chuck Leverbf269552010-12-14 14:59:29 +00006349static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6350 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351{
Andy Adamson05d564f2008-12-23 16:06:15 -05006352 struct compound_hdr hdr;
6353 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354
Chuck Leverbf269552010-12-14 14:59:29 +00006355 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006356 if (status)
6357 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006358 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006359 if (status)
6360 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006361 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006362 if (status)
6363 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006365 if (status)
6366 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006367 status = decode_getfh(xdr, &res->fh);
6368 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006369 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006370 if (res->access_request)
6371 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006372 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006373out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006374 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006375}
6376
6377/*
6378 * Decode OPEN_CONFIRM response
6379 */
Chuck Leverbf269552010-12-14 14:59:29 +00006380static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6381 struct xdr_stream *xdr,
6382 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006383{
Andy Adamson05d564f2008-12-23 16:06:15 -05006384 struct compound_hdr hdr;
6385 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006386
Chuck Leverbf269552010-12-14 14:59:29 +00006387 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006388 if (status)
6389 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006390 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006391 if (status)
6392 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006393 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006394out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006395 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396}
6397
6398/*
6399 * Decode OPEN response
6400 */
Chuck Leverbf269552010-12-14 14:59:29 +00006401static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6402 struct xdr_stream *xdr,
6403 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006404{
Andy Adamson05d564f2008-12-23 16:06:15 -05006405 struct compound_hdr hdr;
6406 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407
Chuck Leverbf269552010-12-14 14:59:29 +00006408 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006409 if (status)
6410 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006411 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006412 if (status)
6413 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006414 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006415 if (status)
6416 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006417 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006418 if (status)
6419 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006420 if (res->access_request)
6421 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006422 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006423out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006424 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006425}
6426
6427/*
6428 * Decode SETATTR response
6429 */
Chuck Leverbf269552010-12-14 14:59:29 +00006430static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6431 struct xdr_stream *xdr,
6432 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006433{
Andy Adamson05d564f2008-12-23 16:06:15 -05006434 struct compound_hdr hdr;
6435 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006436
Chuck Leverbf269552010-12-14 14:59:29 +00006437 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006438 if (status)
6439 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006440 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006441 if (status)
6442 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006443 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006444 if (status)
6445 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006446 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006447 if (status)
6448 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006449 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006451 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006452}
6453
6454/*
6455 * Decode LOCK response
6456 */
Chuck Leverbf269552010-12-14 14:59:29 +00006457static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6458 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006459{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460 struct compound_hdr hdr;
6461 int status;
6462
Chuck Leverbf269552010-12-14 14:59:29 +00006463 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464 if (status)
6465 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006466 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006467 if (status)
6468 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006469 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006470 if (status)
6471 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006472 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006473out:
6474 return status;
6475}
6476
6477/*
6478 * Decode LOCKT response
6479 */
Chuck Leverbf269552010-12-14 14:59:29 +00006480static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6481 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006483 struct compound_hdr hdr;
6484 int status;
6485
Chuck Leverbf269552010-12-14 14:59:29 +00006486 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006487 if (status)
6488 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006489 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006490 if (status)
6491 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006492 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006493 if (status)
6494 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006495 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006496out:
6497 return status;
6498}
6499
6500/*
6501 * Decode LOCKU response
6502 */
Chuck Leverbf269552010-12-14 14:59:29 +00006503static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6504 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006505{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006506 struct compound_hdr hdr;
6507 int status;
6508
Chuck Leverbf269552010-12-14 14:59:29 +00006509 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006510 if (status)
6511 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006512 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006513 if (status)
6514 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006515 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516 if (status)
6517 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006518 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006519out:
6520 return status;
6521}
6522
Chuck Leverbf269552010-12-14 14:59:29 +00006523static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6524 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006525{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006526 struct compound_hdr hdr;
6527 int status;
6528
Chuck Leverbf269552010-12-14 14:59:29 +00006529 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006530 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006531 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006532 return status;
6533}
6534
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535/*
6536 * Decode READLINK response
6537 */
Chuck Leverbf269552010-12-14 14:59:29 +00006538static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6539 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006540 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006542 struct compound_hdr hdr;
6543 int status;
6544
Chuck Leverbf269552010-12-14 14:59:29 +00006545 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006546 if (status)
6547 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006548 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006549 if (status)
6550 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006552 if (status)
6553 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006554 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006555out:
6556 return status;
6557}
6558
6559/*
6560 * Decode READDIR response
6561 */
Chuck Leverbf269552010-12-14 14:59:29 +00006562static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6563 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006564{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006565 struct compound_hdr hdr;
6566 int status;
6567
Chuck Leverbf269552010-12-14 14:59:29 +00006568 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006569 if (status)
6570 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006571 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006572 if (status)
6573 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006574 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006575 if (status)
6576 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006577 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006578out:
6579 return status;
6580}
6581
6582/*
6583 * Decode Read response
6584 */
Chuck Leverbf269552010-12-14 14:59:29 +00006585static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006586 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006587{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006588 struct compound_hdr hdr;
6589 int status;
6590
Chuck Leverbf269552010-12-14 14:59:29 +00006591 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006592 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593 if (status)
6594 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006595 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006596 if (status)
6597 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006598 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006599 if (status)
6600 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006601 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006602 if (!status)
6603 status = res->count;
6604out:
6605 return status;
6606}
6607
6608/*
6609 * Decode WRITE response
6610 */
Chuck Leverbf269552010-12-14 14:59:29 +00006611static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006612 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006614 struct compound_hdr hdr;
6615 int status;
6616
Chuck Leverbf269552010-12-14 14:59:29 +00006617 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006618 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006619 if (status)
6620 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006621 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006622 if (status)
6623 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006624 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006625 if (status)
6626 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006627 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006628 if (status)
6629 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006630 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006631 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006632 if (!status)
6633 status = res->count;
6634out:
6635 return status;
6636}
6637
6638/*
6639 * Decode COMMIT response
6640 */
Chuck Leverbf269552010-12-14 14:59:29 +00006641static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006642 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644 struct compound_hdr hdr;
6645 int status;
6646
Chuck Leverbf269552010-12-14 14:59:29 +00006647 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006648 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649 if (status)
6650 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006651 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006652 if (status)
6653 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006654 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006655 if (status)
6656 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006657 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006658out:
6659 return status;
6660}
6661
6662/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006663 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006664 */
Chuck Leverbf269552010-12-14 14:59:29 +00006665static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006666 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006667{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006668 struct compound_hdr hdr;
6669 int status;
6670
Chuck Leverbf269552010-12-14 14:59:29 +00006671 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006673 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006674 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006675 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006676 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006677 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006678 return status;
6679}
6680
6681/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006682 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006683 */
Chuck Leverbf269552010-12-14 14:59:29 +00006684static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006685 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006686{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006687 struct compound_hdr hdr;
6688 int status;
6689
Chuck Leverbf269552010-12-14 14:59:29 +00006690 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006691 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006692 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006693 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006694 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006695 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006696 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006697 return status;
6698}
6699
6700/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006701 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006702 */
Chuck Leverbf269552010-12-14 14:59:29 +00006703static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006704 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006705{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006706 struct compound_hdr hdr;
6707 int status;
6708
Chuck Leverbf269552010-12-14 14:59:29 +00006709 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006710 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006711 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006712 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006713 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006714 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006715 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006716 return status;
6717}
6718
6719/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006720 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006721 */
Chuck Leverbf269552010-12-14 14:59:29 +00006722static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6723 struct xdr_stream *xdr,
6724 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006725{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006726 struct compound_hdr hdr;
6727 int status;
6728
Chuck Leverbf269552010-12-14 14:59:29 +00006729 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006730 if (status)
6731 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006732 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006733 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006734 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006735 status = decode_putfh(xdr);
6736 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006737 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006738 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006739out:
6740 return status;
6741}
6742
6743/*
6744 * Decode RENEW response
6745 */
Chuck Leverbf269552010-12-14 14:59:29 +00006746static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6747 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006748{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749 struct compound_hdr hdr;
6750 int status;
6751
Chuck Leverbf269552010-12-14 14:59:29 +00006752 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006753 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006754 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006755 return status;
6756}
6757
6758/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006759 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006760 */
Chuck Leverbf269552010-12-14 14:59:29 +00006761static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6762 struct xdr_stream *xdr,
6763 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006764{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006765 struct compound_hdr hdr;
6766 int status;
6767
Chuck Leverbf269552010-12-14 14:59:29 +00006768 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006769 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006770 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006771 return status;
6772}
6773
6774/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006775 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006776 */
Chuck Leverbf269552010-12-14 14:59:29 +00006777static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006778 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006779{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006780 struct compound_hdr hdr;
6781 int status;
6782
Chuck Leverbf269552010-12-14 14:59:29 +00006783 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006784 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006785 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006786 return status;
6787}
6788
6789/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006790 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006791 */
Chuck Leverbf269552010-12-14 14:59:29 +00006792static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6793 struct xdr_stream *xdr,
6794 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006795{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006796 struct compound_hdr hdr;
6797 int status;
6798
Chuck Leverbf269552010-12-14 14:59:29 +00006799 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006800 if (status)
6801 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006802 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006803 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006804 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006805 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006806 if (status != 0)
6807 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006808 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006809 if (status != 0)
6810 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006811 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006812out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006813 return status;
6814}
6815
Trond Myklebust683b57b2006-06-09 09:34:22 -04006816/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006817 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006818 */
Chuck Leverbf269552010-12-14 14:59:29 +00006819static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6820 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006821 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006822{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006823 struct compound_hdr hdr;
6824 int status;
6825
Chuck Leverbf269552010-12-14 14:59:29 +00006826 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006827 if (status)
6828 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006829 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006830 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006831 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006832 status = decode_putfh(xdr);
6833 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006834 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006835 if (res->migration) {
6836 xdr_enter_page(xdr, PAGE_SIZE);
6837 status = decode_getfattr_generic(xdr,
6838 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006839 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006840 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006841 if (status)
6842 goto out;
6843 if (res->renew)
6844 status = decode_renew(xdr);
6845 } else {
6846 status = decode_lookup(xdr);
6847 if (status)
6848 goto out;
6849 xdr_enter_page(xdr, PAGE_SIZE);
6850 status = decode_getfattr_generic(xdr,
6851 &res->fs_locations->fattr,
6852 NULL, res->fs_locations,
6853 NULL, res->fs_locations->server);
6854 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006855out:
6856 return status;
6857}
6858
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006859/*
6860 * Decode SECINFO response
6861 */
6862static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6863 struct xdr_stream *xdr,
6864 struct nfs4_secinfo_res *res)
6865{
6866 struct compound_hdr hdr;
6867 int status;
6868
6869 status = decode_compound_hdr(xdr, &hdr);
6870 if (status)
6871 goto out;
6872 status = decode_sequence(xdr, &res->seq_res, rqstp);
6873 if (status)
6874 goto out;
6875 status = decode_putfh(xdr);
6876 if (status)
6877 goto out;
6878 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006879out:
6880 return status;
6881}
6882
Chuck Lever44c99932013-10-17 14:13:30 -04006883/*
6884 * Decode FSID_PRESENT response
6885 */
6886static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6887 struct xdr_stream *xdr,
6888 struct nfs4_fsid_present_res *res)
6889{
6890 struct compound_hdr hdr;
6891 int status;
6892
6893 status = decode_compound_hdr(xdr, &hdr);
6894 if (status)
6895 goto out;
6896 status = decode_sequence(xdr, &res->seq_res, rqstp);
6897 if (status)
6898 goto out;
6899 status = decode_putfh(xdr);
6900 if (status)
6901 goto out;
6902 status = decode_getfh(xdr, res->fh);
6903 if (status)
6904 goto out;
6905 if (res->renew)
6906 status = decode_renew(xdr);
6907out:
6908 return status;
6909}
6910
Benny Halevy99fe60d2009-04-01 09:22:29 -04006911#if defined(CONFIG_NFS_V4_1)
6912/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006913 * Decode BIND_CONN_TO_SESSION response
6914 */
6915static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6916 struct xdr_stream *xdr,
6917 void *res)
6918{
6919 struct compound_hdr hdr;
6920 int status;
6921
6922 status = decode_compound_hdr(xdr, &hdr);
6923 if (!status)
6924 status = decode_bind_conn_to_session(xdr, res);
6925 return status;
6926}
6927
6928/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006929 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006930 */
Chuck Leverbf269552010-12-14 14:59:29 +00006931static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6932 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006933 void *res)
6934{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006935 struct compound_hdr hdr;
6936 int status;
6937
Chuck Leverbf269552010-12-14 14:59:29 +00006938 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006939 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006940 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006941 return status;
6942}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006943
6944/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006945 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006946 */
Chuck Leverbf269552010-12-14 14:59:29 +00006947static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6948 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006949 struct nfs41_create_session_res *res)
6950{
Andy Adamsonfc931582009-04-01 09:22:31 -04006951 struct compound_hdr hdr;
6952 int status;
6953
Chuck Leverbf269552010-12-14 14:59:29 +00006954 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006955 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006956 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006957 return status;
6958}
6959
6960/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006961 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006962 */
Chuck Leverbf269552010-12-14 14:59:29 +00006963static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6964 struct xdr_stream *xdr,
6965 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006966{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006967 struct compound_hdr hdr;
6968 int status;
6969
Chuck Leverbf269552010-12-14 14:59:29 +00006970 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006971 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006972 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006973 return status;
6974}
6975
6976/*
Trond Myklebust66245532012-05-25 17:18:09 -04006977 * Decode DESTROY_CLIENTID response
6978 */
6979static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6980 struct xdr_stream *xdr,
6981 void *res)
6982{
6983 struct compound_hdr hdr;
6984 int status;
6985
6986 status = decode_compound_hdr(xdr, &hdr);
6987 if (!status)
6988 status = decode_destroy_clientid(xdr, res);
6989 return status;
6990}
6991
6992/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006993 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006994 */
Chuck Leverbf269552010-12-14 14:59:29 +00006995static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6996 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006997 struct nfs4_sequence_res *res)
6998{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006999 struct compound_hdr hdr;
7000 int status;
7001
Chuck Leverbf269552010-12-14 14:59:29 +00007002 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007003 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007004 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007005 return status;
7006}
7007
7008/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007009 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007010 */
Chuck Leverbf269552010-12-14 14:59:29 +00007011static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7012 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04007013 struct nfs4_get_lease_time_res *res)
7014{
Andy Adamson2050f0c2009-04-01 09:22:30 -04007015 struct compound_hdr hdr;
7016 int status;
7017
Chuck Leverbf269552010-12-14 14:59:29 +00007018 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007019 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007020 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007021 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007022 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007023 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007024 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007025 return status;
7026}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007027
7028/*
7029 * Decode RECLAIM_COMPLETE response
7030 */
Chuck Leverbf269552010-12-14 14:59:29 +00007031static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7032 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007033 struct nfs41_reclaim_complete_res *res)
7034{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007035 struct compound_hdr hdr;
7036 int status;
7037
Chuck Leverbf269552010-12-14 14:59:29 +00007038 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007039 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007040 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007041 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307042 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007043 return status;
7044}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007045
7046/*
7047 * Decode GETDEVINFO response
7048 */
Chuck Leverbf269552010-12-14 14:59:29 +00007049static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7050 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007051 struct nfs4_getdeviceinfo_res *res)
7052{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007053 struct compound_hdr hdr;
7054 int status;
7055
Chuck Leverbf269552010-12-14 14:59:29 +00007056 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007057 if (status != 0)
7058 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007059 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007060 if (status != 0)
7061 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007062 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007063out:
7064 return status;
7065}
7066
7067/*
7068 * Decode LAYOUTGET response
7069 */
Chuck Leverbf269552010-12-14 14:59:29 +00007070static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7071 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007072 struct nfs4_layoutget_res *res)
7073{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007074 struct compound_hdr hdr;
7075 int status;
7076
Chuck Leverbf269552010-12-14 14:59:29 +00007077 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007078 if (status)
7079 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007080 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007081 if (status)
7082 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007083 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007084 if (status)
7085 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007086 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007087out:
7088 return status;
7089}
Andy Adamson863a3c62011-03-23 13:27:54 +00007090
7091/*
Benny Halevycbe82602011-05-22 19:52:37 +03007092 * Decode LAYOUTRETURN response
7093 */
7094static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7095 struct xdr_stream *xdr,
7096 struct nfs4_layoutreturn_res *res)
7097{
7098 struct compound_hdr hdr;
7099 int status;
7100
7101 status = decode_compound_hdr(xdr, &hdr);
7102 if (status)
7103 goto out;
7104 status = decode_sequence(xdr, &res->seq_res, rqstp);
7105 if (status)
7106 goto out;
7107 status = decode_putfh(xdr);
7108 if (status)
7109 goto out;
7110 status = decode_layoutreturn(xdr, res);
7111out:
7112 return status;
7113}
7114
7115/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007116 * Decode LAYOUTCOMMIT response
7117 */
7118static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7119 struct xdr_stream *xdr,
7120 struct nfs4_layoutcommit_res *res)
7121{
7122 struct compound_hdr hdr;
7123 int status;
7124
7125 status = decode_compound_hdr(xdr, &hdr);
7126 if (status)
7127 goto out;
7128 status = decode_sequence(xdr, &res->seq_res, rqstp);
7129 if (status)
7130 goto out;
7131 status = decode_putfh(xdr);
7132 if (status)
7133 goto out;
7134 status = decode_layoutcommit(xdr, rqstp, res);
7135 if (status)
7136 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007137 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007138out:
7139 return status;
7140}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007141
7142/*
7143 * Decode SECINFO_NO_NAME response
7144 */
7145static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7146 struct xdr_stream *xdr,
7147 struct nfs4_secinfo_res *res)
7148{
7149 struct compound_hdr hdr;
7150 int status;
7151
7152 status = decode_compound_hdr(xdr, &hdr);
7153 if (status)
7154 goto out;
7155 status = decode_sequence(xdr, &res->seq_res, rqstp);
7156 if (status)
7157 goto out;
7158 status = decode_putrootfh(xdr);
7159 if (status)
7160 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007161 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007162out:
7163 return status;
7164}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007165
7166/*
7167 * Decode TEST_STATEID response
7168 */
7169static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7170 struct xdr_stream *xdr,
7171 struct nfs41_test_stateid_res *res)
7172{
7173 struct compound_hdr hdr;
7174 int status;
7175
7176 status = decode_compound_hdr(xdr, &hdr);
7177 if (status)
7178 goto out;
7179 status = decode_sequence(xdr, &res->seq_res, rqstp);
7180 if (status)
7181 goto out;
7182 status = decode_test_stateid(xdr, res);
7183out:
7184 return status;
7185}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007186
7187/*
7188 * Decode FREE_STATEID response
7189 */
7190static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7191 struct xdr_stream *xdr,
7192 struct nfs41_free_stateid_res *res)
7193{
7194 struct compound_hdr hdr;
7195 int status;
7196
7197 status = decode_compound_hdr(xdr, &hdr);
7198 if (status)
7199 goto out;
7200 status = decode_sequence(xdr, &res->seq_res, rqstp);
7201 if (status)
7202 goto out;
7203 status = decode_free_stateid(xdr, res);
7204out:
7205 return status;
7206}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007207#endif /* CONFIG_NFS_V4_1 */
7208
Chuck Lever573c4e12010-12-14 14:58:11 +00007209/**
7210 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7211 * the local page cache.
7212 * @xdr: XDR stream where entry resides
7213 * @entry: buffer to fill in with entry data
7214 * @plus: boolean indicating whether this should be a readdirplus entry
7215 *
7216 * Returns zero if successful, otherwise a negative errno value is
7217 * returned.
7218 *
7219 * This function is not invoked during READDIR reply decoding, but
7220 * rather whenever an application invokes the getdents(2) system call
7221 * on a directory already in our cache.
7222 */
7223int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7224 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007225{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007226 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007227 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007228 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007229 __be32 *p = xdr_inline_decode(xdr, 4);
7230 if (unlikely(!p))
7231 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007232 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007233 p = xdr_inline_decode(xdr, 4);
7234 if (unlikely(!p))
7235 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007236 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007237 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007238 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007239 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007240 }
7241
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007242 p = xdr_inline_decode(xdr, 12);
7243 if (unlikely(!p))
7244 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007245 entry->prev_cookie = entry->cookie;
7246 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007247 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007248
Trond Myklebust9af8c222010-10-24 11:52:55 -04007249 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007250 if (unlikely(!p))
7251 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007252 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007253
7254 /*
7255 * In case the server doesn't return an inode number,
7256 * we fake one here. (We don't use inode number 0,
7257 * since glibc seems to choke on it...)
7258 */
7259 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007260 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007261
Trond Myklebust9af8c222010-10-24 11:52:55 -04007262 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007263 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007264
Trond Myklebust256e48b2012-06-21 11:18:13 -04007265 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007266 goto out_overflow;
7267
Chuck Lever573c4e12010-12-14 14:58:11 +00007268 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007269 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007270 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007271 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7272 entry->ino = entry->fattr->mounted_on_fileid;
7273 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007274 entry->ino = entry->fattr->fileid;
7275
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007276 entry->d_type = DT_UNKNOWN;
7277 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7278 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7279
Chuck Lever573c4e12010-12-14 14:58:11 +00007280 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007281
7282out_overflow:
7283 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007284 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007285}
7286
7287/*
7288 * We need to translate between nfs status return values and
7289 * the local errno values which may not be the same.
7290 */
7291static struct {
7292 int stat;
7293 int errno;
7294} nfs_errtbl[] = {
7295 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007296 { NFS4ERR_PERM, -EPERM },
7297 { NFS4ERR_NOENT, -ENOENT },
7298 { NFS4ERR_IO, -errno_NFSERR_IO},
7299 { NFS4ERR_NXIO, -ENXIO },
7300 { NFS4ERR_ACCESS, -EACCES },
7301 { NFS4ERR_EXIST, -EEXIST },
7302 { NFS4ERR_XDEV, -EXDEV },
7303 { NFS4ERR_NOTDIR, -ENOTDIR },
7304 { NFS4ERR_ISDIR, -EISDIR },
7305 { NFS4ERR_INVAL, -EINVAL },
7306 { NFS4ERR_FBIG, -EFBIG },
7307 { NFS4ERR_NOSPC, -ENOSPC },
7308 { NFS4ERR_ROFS, -EROFS },
7309 { NFS4ERR_MLINK, -EMLINK },
7310 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7311 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7312 { NFS4ERR_DQUOT, -EDQUOT },
7313 { NFS4ERR_STALE, -ESTALE },
7314 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007315 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7316 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7317 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007318 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007319 { NFS4ERR_BADTYPE, -EBADTYPE },
7320 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007321 { NFS4ERR_SYMLINK, -ELOOP },
7322 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7323 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007324 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007325};
7326
7327/*
7328 * Convert an NFS error code to a local one.
7329 * This one is used jointly by NFSv2 and NFSv3.
7330 */
7331static int
David Howells0a8ea432006-08-22 20:06:08 -04007332nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007333{
7334 int i;
7335 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7336 if (nfs_errtbl[i].stat == stat)
7337 return nfs_errtbl[i].errno;
7338 }
7339 if (stat <= 10000 || stat > 10100) {
7340 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007341 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007342 }
7343 /* If we cannot translate the error, the recovery routines should
7344 * handle it.
7345 * Note: remaining NFSv4 error codes have values > 10000, so should
7346 * not conflict with native Linux error codes.
7347 */
Benny Halevy856dff32008-03-31 17:39:06 +03007348 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007349}
7350
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007351#ifdef CONFIG_NFS_V4_2
7352#include "nfs42xdr.c"
7353#endif /* CONFIG_NFS_V4_2 */
7354
Linus Torvalds1da177e2005-04-16 15:20:36 -07007355#define PROC(proc, argtype, restype) \
7356[NFSPROC4_CLNT_##proc] = { \
7357 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007358 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007359 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007360 .p_arglen = NFS4_##argtype##_sz, \
7361 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007362 .p_statidx = NFSPROC4_CLNT_##proc, \
7363 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007364}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007365
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007366#define STUB(proc) \
7367[NFSPROC4_CLNT_##proc] = { \
7368 .p_name = #proc, \
7369}
7370
Linus Torvalds1da177e2005-04-16 15:20:36 -07007371struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007372 PROC(READ, enc_read, dec_read),
7373 PROC(WRITE, enc_write, dec_write),
7374 PROC(COMMIT, enc_commit, dec_commit),
7375 PROC(OPEN, enc_open, dec_open),
7376 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7377 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7378 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7379 PROC(CLOSE, enc_close, dec_close),
7380 PROC(SETATTR, enc_setattr, dec_setattr),
7381 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7382 PROC(RENEW, enc_renew, dec_renew),
7383 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7384 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7385 PROC(LOCK, enc_lock, dec_lock),
7386 PROC(LOCKT, enc_lockt, dec_lockt),
7387 PROC(LOCKU, enc_locku, dec_locku),
7388 PROC(ACCESS, enc_access, dec_access),
7389 PROC(GETATTR, enc_getattr, dec_getattr),
7390 PROC(LOOKUP, enc_lookup, dec_lookup),
7391 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7392 PROC(REMOVE, enc_remove, dec_remove),
7393 PROC(RENAME, enc_rename, dec_rename),
7394 PROC(LINK, enc_link, dec_link),
7395 PROC(SYMLINK, enc_symlink, dec_symlink),
7396 PROC(CREATE, enc_create, dec_create),
7397 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7398 PROC(STATFS, enc_statfs, dec_statfs),
7399 PROC(READLINK, enc_readlink, dec_readlink),
7400 PROC(READDIR, enc_readdir, dec_readdir),
7401 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7402 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7403 PROC(GETACL, enc_getacl, dec_getacl),
7404 PROC(SETACL, enc_setacl, dec_setacl),
7405 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7406 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007407 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007408 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007409#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007410 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7411 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7412 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7413 PROC(SEQUENCE, enc_sequence, dec_sequence),
7414 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7415 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7416 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7417 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007418 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007419 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007420 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007421 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007422 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007423 STUB(GETDEVICELIST),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007424 PROC(BIND_CONN_TO_SESSION,
7425 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007426 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007427#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007428#ifdef CONFIG_NFS_V4_2
7429 PROC(SEEK, enc_seek, dec_seek),
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007430 PROC(ALLOCATE, enc_allocate, dec_allocate),
Anna Schumaker624bd5b2014-11-25 13:18:16 -05007431 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007432#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007433};
7434
Trond Myklebusta613fa12012-01-20 13:53:56 -05007435const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007436 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007437 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007438 .procs = nfs4_procedures
7439};
7440
7441/*
7442 * Local variables:
7443 * c-basic-offset: 8
7444 * End:
7445 */