blob: e3018e7a316c822157b4810c2ea5cb34b6ccc6a3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
55#include <linux/nfs_idmap.h>
Chuck Leverf0920752012-05-21 22:45:41 -040056
Trond Myklebust4ce79712005-06-22 17:16:21 +000057#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050058#include "internal.h"
Trond Myklebust76e697b2012-11-26 14:20:49 -050059#include "nfs4session.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040060#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040061#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63#define NFSDBG_FACILITY NFSDBG_XDR
64
65/* Mapping from NFS error code to "errno" error code. */
66#define errno_NFSERR_IO EIO
67
David Howells0a8ea432006-08-22 20:06:08 -040068static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
71#ifdef DEBUG
72#define NFS4_MAXTAGLEN 20
73#else
74#define NFS4_MAXTAGLEN 0
75#endif
76
Andy Adamson6c0195a2008-12-23 16:06:15 -050077/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040078 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040080#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050081#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040082#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85#define op_encode_hdr_maxsz (1)
86#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040087#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
90#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
92 (NFS4_FHSIZE >> 2))
93#define decode_putfh_maxsz (op_decode_hdr_maxsz)
94#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
95#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
96#define encode_getfh_maxsz (op_encode_hdr_maxsz)
97#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
98 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040099#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +0000100#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
102#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400103#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
104#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
David Quigleyaa9c2662013-05-22 12:50:44 -0400105#ifdef CONFIG_NFS_V4_SECURITY_LABEL
106/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
107#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
David Quigleyaa9c2662013-05-22 12:50:44 -0400108#else
109#define nfs4_label_maxsz 0
David Quigleyaa9c2662013-05-22 12:50:44 -0400110#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400111/* We support only one layout type per file system */
112#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000113/* This is based on getfattr, which uses the most attributes: */
114#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400115 3 + 3 + 3 + nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400116 nfs4_group_maxsz + nfs4_label_maxsz + \
117 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000118#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
119 nfs4_fattr_value_maxsz)
120#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400121#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
122 1 + 2 + 1 + \
123 nfs4_owner_maxsz + \
124 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400125 nfs4_label_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400126 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define encode_savefh_maxsz (op_encode_hdr_maxsz)
128#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400129#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
130#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200131#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400132/* The 5 accounts for the PNFS attributes, and assumes that at most three
133 * layout types will be returned.
134 */
135#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
136 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
138#define decode_renew_maxsz (op_decode_hdr_maxsz)
139#define encode_setclientid_maxsz \
140 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500141 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
142 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
143 1 /* sc_prog */ + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500144 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
145 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500146 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#define decode_setclientid_maxsz \
148 (op_decode_hdr_maxsz + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500149 2 /* clientid */ + \
150 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
151 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
152 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#define encode_setclientid_confirm_maxsz \
154 (op_encode_hdr_maxsz + \
155 3 + (NFS4_VERIFIER_SIZE >> 2))
156#define decode_setclientid_confirm_maxsz \
157 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400158#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
159#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400160#define encode_share_access_maxsz \
161 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500162#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400163#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
164#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
165#define encode_open_maxsz (op_encode_hdr_maxsz + \
166 2 + encode_share_access_maxsz + 2 + \
167 open_owner_id_maxsz + \
168 encode_opentype_maxsz + \
169 encode_claim_null_maxsz)
170#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400171#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400172 decode_ace_maxsz)
173#define decode_change_info_maxsz (5)
174#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400175 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400176 decode_change_info_maxsz + 1 + \
177 nfs4_fattr_bitmap_maxsz + \
178 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400179#define encode_open_confirm_maxsz \
180 (op_encode_hdr_maxsz + \
181 encode_stateid_maxsz + 1)
182#define decode_open_confirm_maxsz \
183 (op_decode_hdr_maxsz + \
184 decode_stateid_maxsz)
185#define encode_open_downgrade_maxsz \
186 (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 1 + \
188 encode_share_access_maxsz)
189#define decode_open_downgrade_maxsz \
190 (op_decode_hdr_maxsz + \
191 decode_stateid_maxsz)
192#define encode_close_maxsz (op_encode_hdr_maxsz + \
193 1 + encode_stateid_maxsz)
194#define decode_close_maxsz (op_decode_hdr_maxsz + \
195 decode_stateid_maxsz)
196#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
197 encode_stateid_maxsz + \
198 encode_attrs_maxsz)
199#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
200 nfs4_fattr_bitmap_maxsz)
201#define encode_read_maxsz (op_encode_hdr_maxsz + \
202 encode_stateid_maxsz + 3)
203#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
204#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400205 2 + encode_verifier_maxsz + 5 + \
206 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400207#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Chuck Levera7697f62014-03-12 12:51:17 -0400208 decode_verifier_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400209#define encode_readlink_maxsz (op_encode_hdr_maxsz)
210#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
211#define encode_write_maxsz (op_encode_hdr_maxsz + \
212 encode_stateid_maxsz + 4)
213#define decode_write_maxsz (op_decode_hdr_maxsz + \
214 2 + decode_verifier_maxsz)
215#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
216#define decode_commit_maxsz (op_decode_hdr_maxsz + \
217 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218#define encode_remove_maxsz (op_encode_hdr_maxsz + \
219 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400220#define decode_remove_maxsz (op_decode_hdr_maxsz + \
221 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222#define encode_rename_maxsz (op_encode_hdr_maxsz + \
223 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400224#define decode_rename_maxsz (op_decode_hdr_maxsz + \
225 decode_change_info_maxsz + \
226 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227#define encode_link_maxsz (op_encode_hdr_maxsz + \
228 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400229#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400230#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400231#define encode_lock_maxsz (op_encode_hdr_maxsz + \
232 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400233 1 + encode_stateid_maxsz + 1 + \
234 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400235#define decode_lock_denied_maxsz \
236 (8 + decode_lockowner_maxsz)
237#define decode_lock_maxsz (op_decode_hdr_maxsz + \
238 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400239#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
240 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400241#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
242 decode_lock_denied_maxsz)
243#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
244 encode_stateid_maxsz + \
245 4)
246#define decode_locku_maxsz (op_decode_hdr_maxsz + \
247 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400248#define encode_release_lockowner_maxsz \
249 (op_encode_hdr_maxsz + \
250 encode_lockowner_maxsz)
251#define decode_release_lockowner_maxsz \
252 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400253#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
254#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
256 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400257 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000258 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
260#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400261 1 + 2 + nfs4_name_maxsz + \
262 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400263#define decode_create_maxsz (op_decode_hdr_maxsz + \
264 decode_change_info_maxsz + \
265 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400266#define encode_statfs_maxsz (encode_getattr_maxsz)
267#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
269#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400270#define encode_getacl_maxsz (encode_getattr_maxsz)
271#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
272 nfs4_fattr_bitmap_maxsz + 1)
273#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
274 encode_stateid_maxsz + 3)
275#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400276#define encode_fs_locations_maxsz \
277 (encode_getattr_maxsz)
278#define decode_fs_locations_maxsz \
279 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000280#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400281#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400282
283#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400284#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500285#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
286 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400287
Benny Halevy99fe60d2009-04-01 09:22:29 -0400288#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
289 encode_verifier_maxsz + \
290 1 /* co_ownerid.len */ + \
291 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
292 1 /* flags */ + \
293 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400294 /* max is SP4_MACH_CRED (for now) */ + \
295 1 + NFS4_OP_MAP_NUM_WORDS + \
296 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500297 1 /* implementation id array of size 1 */ + \
298 1 /* nii_domain */ + \
299 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
300 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500301 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500302 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400303#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
304 2 /* eir_clientid */ + \
305 1 /* eir_sequenceid */ + \
306 1 /* eir_flags */ + \
307 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400308 /* max is SP4_MACH_CRED (for now) */ + \
309 1 + NFS4_OP_MAP_NUM_WORDS + \
310 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400311 2 /* eir_server_owner.so_minor_id */ + \
312 /* eir_server_owner.so_major_id<> */ \
313 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
314 /* eir_server_scope<> */ \
315 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
316 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500317 1 /* nii_domain */ + \
318 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
319 1 /* nii_name */ + \
320 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
321 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400322#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
323#define decode_channel_attrs_maxsz (6 + \
324 1 /* ca_rdma_ird.len */ + \
325 1 /* ca_rdma_ird */)
326#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
327 2 /* csa_clientid */ + \
328 1 /* csa_sequence */ + \
329 1 /* csa_flags */ + \
330 encode_channel_attrs_maxsz + \
331 encode_channel_attrs_maxsz + \
332 1 /* csa_cb_program */ + \
333 1 /* csa_sec_parms.len (1) */ + \
334 1 /* cb_secflavor (AUTH_SYS) */ + \
335 1 /* stamp */ + \
336 1 /* machinename.len */ + \
337 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
338 1 /* uid */ + \
339 1 /* gid */ + \
340 1 /* gids.len (0) */)
341#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
342 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
343 1 /* csr_sequence */ + \
344 1 /* csr_flags */ + \
345 decode_channel_attrs_maxsz + \
346 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400347#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
348 /* bctsa_sessid */ \
349 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
350 1 /* bctsa_dir */ + \
351 1 /* bctsa_use_conn_in_rdma_mode */)
352#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
353 /* bctsr_sessid */ \
354 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
355 1 /* bctsr_dir */ + \
356 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400357#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
358#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400359#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
360#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400361#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
362 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
363#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
364 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500365#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
366#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700367#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
368 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
369 1 /* layout type */ + \
370 1 /* maxcount */ + \
371 1 /* bitmap size */ + \
372 1 /* notification bitmap length */ + \
373 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400374#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
375 1 /* layout type */ + \
376 1 /* opaque devaddr4 length */ + \
377 /* devaddr4 payload is read into page */ \
378 1 /* notification bitmap length */ + \
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700379 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400380#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
381 encode_stateid_maxsz)
382#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
383 decode_stateid_maxsz + \
384 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000385#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
386 2 /* offset */ + \
387 2 /* length */ + \
388 1 /* reclaim */ + \
389 encode_stateid_maxsz + \
390 1 /* new offset (true) */ + \
391 2 /* last byte written */ + \
392 1 /* nt_timechanged (false) */ + \
393 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500394 1 /* layoutupdate4 opaqueue len */)
395 /* the actual content of layoutupdate4 should
396 be allocated by drivers and spliced in
397 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000398#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300399#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
400 encode_stateid_maxsz + \
401 1 /* FIXME: opaque lrf_body always empty at the moment */)
402#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
403 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400404#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
405#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400406#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
407 XDR_QUADLEN(NFS4_STATEID_SIZE))
408#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400409#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
410 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400411#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400412#else /* CONFIG_NFS_V4_1 */
413#define encode_sequence_maxsz 0
414#define decode_sequence_maxsz 0
415#endif /* CONFIG_NFS_V4_1 */
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
418#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
419#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400420 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400422 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400424 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400426 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400428 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400430 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400434 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400436 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400438 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400440 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400442 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400444 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400446 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400447 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400449 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400451 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400452 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400454 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400456 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400460 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400462 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400463 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400464 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400465 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400466 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400467 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400470 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400471 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400472 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400473 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400474 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400475#define NFS4_enc_open_confirm_sz \
476 (compound_encode_hdr_maxsz + \
477 encode_putfh_maxsz + \
478 encode_open_confirm_maxsz)
479#define NFS4_dec_open_confirm_sz \
480 (compound_decode_hdr_maxsz + \
481 decode_putfh_maxsz + \
482 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400484 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400486 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400487 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400488 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400490 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400492 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400493 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400494 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#define NFS4_enc_open_downgrade_sz \
496 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400497 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400498 encode_putfh_maxsz + \
499 encode_open_downgrade_maxsz + \
500 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501#define NFS4_dec_open_downgrade_sz \
502 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400503 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400504 decode_putfh_maxsz + \
505 decode_open_downgrade_maxsz + \
506 decode_getattr_maxsz)
507#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400508 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400509 encode_putfh_maxsz + \
510 encode_close_maxsz + \
511 encode_getattr_maxsz)
512#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400513 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400514 decode_putfh_maxsz + \
515 decode_close_maxsz + \
516 decode_getattr_maxsz)
517#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400518 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400519 encode_putfh_maxsz + \
520 encode_setattr_maxsz + \
521 encode_getattr_maxsz)
522#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400523 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400524 decode_putfh_maxsz + \
525 decode_setattr_maxsz + \
526 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400528 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 encode_putfh_maxsz + \
530 encode_fsinfo_maxsz)
531#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400532 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 decode_putfh_maxsz + \
534 decode_fsinfo_maxsz)
535#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
536 encode_renew_maxsz)
537#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
538 decode_renew_maxsz)
539#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
540 encode_setclientid_maxsz)
541#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
542 decode_setclientid_maxsz)
543#define NFS4_enc_setclientid_confirm_sz \
544 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400545 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546#define NFS4_dec_setclientid_confirm_sz \
547 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400548 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400550 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400552 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400554 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400556 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400558 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400560 encode_lockt_maxsz)
561#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400563 decode_putfh_maxsz + \
564 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400568 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400572 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400573#define NFS4_enc_release_lockowner_sz \
574 (compound_encode_hdr_maxsz + \
575 encode_lockowner_maxsz)
576#define NFS4_dec_release_lockowner_sz \
577 (compound_decode_hdr_maxsz + \
578 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400582 encode_access_maxsz + \
583 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400585 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400587 decode_access_maxsz + \
588 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400592 encode_getattr_maxsz + \
593 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400595 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400597 decode_getattr_maxsz + \
598 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400600 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 encode_putfh_maxsz + \
602 encode_lookup_maxsz + \
603 encode_getattr_maxsz + \
604 encode_getfh_maxsz)
605#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400608 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 decode_getattr_maxsz + \
610 decode_getfh_maxsz)
611#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400612 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 encode_putrootfh_maxsz + \
614 encode_getattr_maxsz + \
615 encode_getfh_maxsz)
616#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400617 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 decode_putrootfh_maxsz + \
619 decode_getattr_maxsz + \
620 decode_getfh_maxsz)
621#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400624 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400626 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400628 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400630 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 encode_putfh_maxsz + \
632 encode_savefh_maxsz + \
633 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400634 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400636 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 decode_putfh_maxsz + \
638 decode_savefh_maxsz + \
639 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400640 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 encode_putfh_maxsz + \
644 encode_savefh_maxsz + \
645 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400646 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400647 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400648 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 decode_putfh_maxsz + \
652 decode_savefh_maxsz + \
653 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400654 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400655 decode_restorefh_maxsz + \
656 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400658 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 encode_putfh_maxsz + \
660 encode_symlink_maxsz + \
661 encode_getattr_maxsz + \
662 encode_getfh_maxsz)
663#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400664 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 decode_putfh_maxsz + \
666 decode_symlink_maxsz + \
667 decode_getattr_maxsz + \
668 decode_getfh_maxsz)
669#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400670 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 encode_putfh_maxsz + \
672 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400673 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400674 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 decode_putfh_maxsz + \
678 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400679 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400680 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400682 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 encode_putfh_maxsz + \
684 encode_getattr_maxsz)
685#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400686 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 decode_putfh_maxsz + \
688 decode_getattr_maxsz)
689#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400690 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400692 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400694 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400696 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400698 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800699 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 encode_getattr_maxsz)
701#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400702 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800703 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 decode_getattr_maxsz)
705#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400706 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100708 encode_delegreturn_maxsz + \
709 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400711 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100712 decode_delegreturn_maxsz + \
713 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000714#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400715 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000716 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400717 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000718#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400719 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000720 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400721 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000722#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400723 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000724 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400725 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000726#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400727 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000728 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400729 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400730#define NFS4_enc_fs_locations_sz \
731 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400732 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400733 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400734 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400735 encode_fs_locations_maxsz + \
736 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400737#define NFS4_dec_fs_locations_sz \
738 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400739 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400740 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400741 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400742 decode_fs_locations_maxsz + \
743 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000744#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
745 encode_sequence_maxsz + \
746 encode_putfh_maxsz + \
747 encode_secinfo_maxsz)
748#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
749 decode_sequence_maxsz + \
750 decode_putfh_maxsz + \
751 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400752#define NFS4_enc_fsid_present_sz \
753 (compound_encode_hdr_maxsz + \
754 encode_sequence_maxsz + \
755 encode_putfh_maxsz + \
756 encode_getfh_maxsz + \
757 encode_renew_maxsz)
758#define NFS4_dec_fsid_present_sz \
759 (compound_decode_hdr_maxsz + \
760 decode_sequence_maxsz + \
761 decode_putfh_maxsz + \
762 decode_getfh_maxsz + \
763 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400764#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400765#define NFS4_enc_bind_conn_to_session_sz \
766 (compound_encode_hdr_maxsz + \
767 encode_bind_conn_to_session_maxsz)
768#define NFS4_dec_bind_conn_to_session_sz \
769 (compound_decode_hdr_maxsz + \
770 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400771#define NFS4_enc_exchange_id_sz \
772 (compound_encode_hdr_maxsz + \
773 encode_exchange_id_maxsz)
774#define NFS4_dec_exchange_id_sz \
775 (compound_decode_hdr_maxsz + \
776 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400777#define NFS4_enc_create_session_sz \
778 (compound_encode_hdr_maxsz + \
779 encode_create_session_maxsz)
780#define NFS4_dec_create_session_sz \
781 (compound_decode_hdr_maxsz + \
782 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400783#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
784 encode_destroy_session_maxsz)
785#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
786 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400787#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
788 encode_destroy_clientid_maxsz)
789#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
790 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400791#define NFS4_enc_sequence_sz \
792 (compound_decode_hdr_maxsz + \
793 encode_sequence_maxsz)
794#define NFS4_dec_sequence_sz \
795 (compound_decode_hdr_maxsz + \
796 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400797#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
798 encode_sequence_maxsz + \
799 encode_putrootfh_maxsz + \
800 encode_fsinfo_maxsz)
801#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
802 decode_sequence_maxsz + \
803 decode_putrootfh_maxsz + \
804 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500805#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
806 encode_sequence_maxsz + \
807 encode_reclaim_complete_maxsz)
808#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
809 decode_sequence_maxsz + \
810 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400811#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
812 encode_sequence_maxsz +\
813 encode_getdeviceinfo_maxsz)
814#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
815 decode_sequence_maxsz + \
816 decode_getdeviceinfo_maxsz)
817#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
818 encode_sequence_maxsz + \
819 encode_putfh_maxsz + \
820 encode_layoutget_maxsz)
821#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
822 decode_sequence_maxsz + \
823 decode_putfh_maxsz + \
824 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000825#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
826 encode_sequence_maxsz +\
827 encode_putfh_maxsz + \
828 encode_layoutcommit_maxsz + \
829 encode_getattr_maxsz)
830#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
831 decode_sequence_maxsz + \
832 decode_putfh_maxsz + \
833 decode_layoutcommit_maxsz + \
834 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300835#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
836 encode_sequence_maxsz + \
837 encode_putfh_maxsz + \
838 encode_layoutreturn_maxsz)
839#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
840 decode_sequence_maxsz + \
841 decode_putfh_maxsz + \
842 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400843#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
844 encode_sequence_maxsz + \
845 encode_putrootfh_maxsz +\
846 encode_secinfo_no_name_maxsz)
847#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
848 decode_sequence_maxsz + \
849 decode_putrootfh_maxsz + \
850 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400851#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
852 encode_sequence_maxsz + \
853 encode_test_stateid_maxsz)
854#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
855 decode_sequence_maxsz + \
856 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400857#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
858 encode_sequence_maxsz + \
859 encode_free_stateid_maxsz)
860#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
861 decode_sequence_maxsz + \
862 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500863
864const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
865 compound_encode_hdr_maxsz +
866 encode_sequence_maxsz +
867 encode_putfh_maxsz +
868 encode_getattr_maxsz) *
869 XDR_UNIT);
870
871const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
872 compound_decode_hdr_maxsz +
873 decode_sequence_maxsz +
874 decode_putfh_maxsz) *
875 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400876
877const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
878 compound_decode_hdr_maxsz +
879 decode_sequence_maxsz) *
880 XDR_UNIT);
881EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400882#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
Trond Myklebustbca79472009-03-11 14:10:26 -0400884static const umode_t nfs_type2fmt[] = {
885 [NF4BAD] = 0,
886 [NF4REG] = S_IFREG,
887 [NF4DIR] = S_IFDIR,
888 [NF4BLK] = S_IFBLK,
889 [NF4CHR] = S_IFCHR,
890 [NF4LNK] = S_IFLNK,
891 [NF4SOCK] = S_IFSOCK,
892 [NF4FIFO] = S_IFIFO,
893 [NF4ATTRDIR] = 0,
894 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895};
896
897struct compound_hdr {
898 int32_t status;
899 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500900 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 uint32_t taglen;
902 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400903 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400904 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905};
906
Benny Halevy13c65ce2009-08-14 17:19:25 +0300907static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
908{
909 __be32 *p = xdr_reserve_space(xdr, nbytes);
910 BUG_ON(!p);
911 return p;
912}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Trond Myklebustcb17e552012-03-04 18:13:56 -0500914static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
915{
916 __be32 *p;
917
918 p = xdr_reserve_space(xdr, len);
919 xdr_encode_opaque_fixed(p, buf, len);
920}
921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
923{
Al Viro8687b632006-10-19 23:28:48 -0700924 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500926 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 xdr_encode_opaque(p, str, len);
928}
929
Trond Myklebust4ade9822012-03-04 18:13:57 -0500930static void encode_uint32(struct xdr_stream *xdr, u32 n)
931{
932 __be32 *p;
933
934 p = reserve_space(xdr, 4);
935 *p = cpu_to_be32(n);
936}
937
Trond Myklebustff2eb682012-03-05 11:40:12 -0500938static void encode_uint64(struct xdr_stream *xdr, u64 n)
939{
940 __be32 *p;
941
942 p = reserve_space(xdr, 8);
943 xdr_encode_hyper(p, n);
944}
945
Trond Myklebust4ade9822012-03-04 18:13:57 -0500946static void encode_nfs4_seqid(struct xdr_stream *xdr,
947 const struct nfs_seqid *seqid)
948{
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 Myklebustdc0b0272008-12-23 15:21:56 -05001354static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
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 Myklebustdc0b0272008-12-23 15:21:56 -05001359 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001360 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001361 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001362 break;
1363 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001364 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001365 break;
1366 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001367 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001368 break;
1369 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001370 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 }
Benny Halevy34558512009-08-14 17:19:30 +03001372 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373}
1374
1375static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1376{
Al Viro8687b632006-10-19 23:28:48 -07001377 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 /*
1379 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1380 * owner 4 = 32
1381 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001382 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001383 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001384 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001385 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001386 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001387 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001388 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001389 *p++ = cpu_to_be32(arg->id.uniquifier);
1390 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391}
1392
1393static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1394{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001395 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001396 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
Benny Halevy13c65ce2009-08-14 17:19:25 +03001398 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001399 switch(arg->createmode) {
1400 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001401 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001402 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Andy Adamson05d564f2008-12-23 16:06:15 -05001403 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001404 case NFS4_CREATE_GUARDED:
1405 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001406 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001407 break;
1408 case NFS4_CREATE_EXCLUSIVE:
1409 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1410 encode_nfs4_verifier(xdr, &arg->u.verifier);
1411 break;
1412 case NFS4_CREATE_EXCLUSIVE4_1:
1413 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1414 encode_nfs4_verifier(xdr, &arg->u.verifier);
1415 dummy.ia_valid = 0;
David Quigleyaa9c2662013-05-22 12:50:44 -04001416 encode_attrs(xdr, &dummy, arg->label, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 }
1418}
1419
1420static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1421{
Al Viro8687b632006-10-19 23:28:48 -07001422 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
Benny Halevy13c65ce2009-08-14 17:19:25 +03001424 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001426 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001427 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001428 break;
1429 default:
Benny Halevy34558512009-08-14 17:19:30 +03001430 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001431 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 }
1433}
1434
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001435static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436{
Al Viro8687b632006-10-19 23:28:48 -07001437 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
Benny Halevy13c65ce2009-08-14 17:19:25 +03001439 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001441 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001442 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001443 break;
1444 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001445 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001446 break;
1447 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001448 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001449 break;
1450 default:
1451 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 }
1453}
1454
1455static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1456{
Al Viro8687b632006-10-19 23:28:48 -07001457 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Benny Halevy13c65ce2009-08-14 17:19:25 +03001459 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001460 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 encode_string(xdr, name->len, name->name);
1462}
1463
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001464static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465{
Al Viro8687b632006-10-19 23:28:48 -07001466 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Benny Halevy13c65ce2009-08-14 17:19:25 +03001468 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001469 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 encode_delegation_type(xdr, type);
1471}
1472
1473static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1474{
Al Viro8687b632006-10-19 23:28:48 -07001475 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001477 p = reserve_space(xdr, 4);
1478 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1479 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 encode_string(xdr, name->len, name->name);
1481}
1482
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001483static inline void encode_claim_fh(struct xdr_stream *xdr)
1484{
1485 __be32 *p;
1486
1487 p = reserve_space(xdr, 4);
1488 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1489}
1490
1491static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1492{
1493 __be32 *p;
1494
1495 p = reserve_space(xdr, 4);
1496 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1497 encode_nfs4_stateid(xdr, stateid);
1498}
1499
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001500static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501{
Trond Myklebustab19b482012-03-04 18:13:57 -05001502 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 encode_openhdr(xdr, arg);
1504 encode_opentype(xdr, arg);
1505 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001506 case NFS4_OPEN_CLAIM_NULL:
1507 encode_claim_null(xdr, arg->name);
1508 break;
1509 case NFS4_OPEN_CLAIM_PREVIOUS:
1510 encode_claim_previous(xdr, arg->u.delegation_type);
1511 break;
1512 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1513 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1514 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001515 case NFS4_OPEN_CLAIM_FH:
1516 encode_claim_fh(xdr);
1517 break;
1518 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1519 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1520 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001521 default:
1522 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524}
1525
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001526static 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 -07001527{
Trond Myklebustab19b482012-03-04 18:13:57 -05001528 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001529 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001530 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531}
1532
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001533static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534{
Trond Myklebustab19b482012-03-04 18:13:57 -05001535 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001536 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001537 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001538 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539}
1540
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001541static void
Andy Adamsond0179312008-12-23 16:06:17 -05001542encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543{
Trond Myklebustab19b482012-03-04 18:13:57 -05001544 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001545 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546}
1547
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001548static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549{
Trond Myklebustab19b482012-03-04 18:13:57 -05001550 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551}
1552
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001553static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1554 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555{
Al Viro8687b632006-10-19 23:28:48 -07001556 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
Trond Myklebustab19b482012-03-04 18:13:57 -05001558 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001559 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
Benny Halevy13c65ce2009-08-14 17:19:25 +03001561 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001562 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001563 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564}
1565
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001566static 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 -07001567{
David Quigleyaa9c2662013-05-22 12:50:44 -04001568 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001569 FATTR4_WORD0_RDATTR_ERROR,
1570 FATTR4_WORD1_MOUNTED_ON_FILEID,
1571 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001572 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001573 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001574 uint32_t attrlen = 0;
1575 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001577 if (readdir->plus) {
1578 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001579 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001580 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1581 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1582 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1583 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001584 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001585 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001586 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001587 /* Use mounted_on_fileid only if the server supports it */
1588 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1589 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001590 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1591 attrs[i] &= readdir->bitmask[i];
1592 if (attrs[i] != 0)
1593 attrlen = i+1;
1594 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001595
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001596 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001597 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001598 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001599 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001600 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001601 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001602 *p++ = cpu_to_be32(attrlen);
1603 for (i = 0; i < attrlen; i++)
1604 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001605 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001606
1607 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001608 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001609 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001610 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001611 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001612 attrs[1] & readdir->bitmask[1],
1613 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614}
1615
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001616static 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 -07001617{
Trond Myklebustab19b482012-03-04 18:13:57 -05001618 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619}
1620
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001621static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622{
Trond Myklebustab19b482012-03-04 18:13:57 -05001623 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001624 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625}
1626
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001627static 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 -07001628{
Trond Myklebustab19b482012-03-04 18:13:57 -05001629 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001630 encode_string(xdr, oldname->len, oldname->name);
1631 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632}
1633
Chuck Leverbb4dae52012-03-01 17:01:48 -05001634static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1635 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001637 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001638 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639}
1640
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001641static void
Andy Adamsond0179312008-12-23 16:06:17 -05001642encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001643{
Trond Myklebustab19b482012-03-04 18:13:57 -05001644 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001645}
1646
Chuck Lever9f06c712010-12-14 14:59:18 +00001647static void
Andy Adamsond0179312008-12-23 16:06:17 -05001648encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001649{
Al Viro8687b632006-10-19 23:28:48 -07001650 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001651
Trond Myklebustab19b482012-03-04 18:13:57 -05001652 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001653 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001654 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001655 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001656 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001657 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001658 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001659 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001660}
1661
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001662static void
Andy Adamsond0179312008-12-23 16:06:17 -05001663encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664{
Trond Myklebustab19b482012-03-04 18:13:57 -05001665 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666}
1667
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001668static 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 -07001669{
Trond Myklebustab19b482012-03-04 18:13:57 -05001670 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001671 encode_nfs4_stateid(xdr, &arg->stateid);
David Quigleyaa9c2662013-05-22 12:50:44 -04001672 encode_attrs(xdr, arg->iap, arg->label, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673}
1674
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001675static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676{
Al Viro8687b632006-10-19 23:28:48 -07001677 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
Trond Myklebust70019512012-03-04 20:49:32 -05001679 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001680 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
1682 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001683 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001684 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1686 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001687 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001688 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689}
1690
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001691static 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 -07001692{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001693 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1694 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001695 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001696 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697}
1698
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001699static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1700 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701{
Al Viro8687b632006-10-19 23:28:48 -07001702 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
Trond Myklebustab19b482012-03-04 18:13:57 -05001704 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001705 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Benny Halevy13c65ce2009-08-14 17:19:25 +03001707 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001708 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001709 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001710 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
1712 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713}
1714
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001715static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716{
Trond Myklebustab19b482012-03-04 18:13:57 -05001717 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001718 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001720
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001721static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1722{
Trond Myklebustab19b482012-03-04 18:13:57 -05001723 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001724 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001725}
1726
Benny Halevy99fe60d2009-04-01 09:22:29 -04001727#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001728/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001729static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1730 struct nfs4_session *session,
1731 struct compound_hdr *hdr)
1732{
1733 __be32 *p;
1734
1735 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1736 decode_bind_conn_to_session_maxsz, hdr);
1737 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1738 p = xdr_reserve_space(xdr, 8);
1739 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1740 *p = 0; /* use_conn_in_rdma_mode = False */
1741}
1742
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001743static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1744{
1745 unsigned int i;
1746 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1747 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1748 encode_uint32(xdr, op_map->u.words[i]);
1749}
1750
Benny Halevy99fe60d2009-04-01 09:22:29 -04001751static void encode_exchange_id(struct xdr_stream *xdr,
1752 struct nfs41_exchange_id_args *args,
1753 struct compound_hdr *hdr)
1754{
1755 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001756 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001757 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001758
Trond Myklebust70019512012-03-04 20:49:32 -05001759 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001760 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001761
1762 encode_string(xdr, args->id_len, args->id);
1763
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001764 encode_uint32(xdr, args->flags);
1765 encode_uint32(xdr, args->state_protect.how);
1766
1767 switch (args->state_protect.how) {
1768 case SP4_NONE:
1769 break;
1770 case SP4_MACH_CRED:
1771 encode_op_map(xdr, &args->state_protect.enforce);
1772 encode_op_map(xdr, &args->state_protect.allow);
1773 break;
1774 default:
1775 WARN_ON_ONCE(1);
1776 break;
1777 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001778
1779 if (send_implementation_id &&
1780 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1781 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001782 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001783 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1784 utsname()->sysname, utsname()->release,
1785 utsname()->version, utsname()->machine);
1786
1787 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001788 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001789
1790 encode_string(xdr,
1791 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1792 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1793 encode_string(xdr, len, impl_name);
1794 /* just send zeros for nii_date - the date is in nii_name */
1795 p = reserve_space(xdr, 12);
1796 p = xdr_encode_hyper(p, 0);
1797 *p = cpu_to_be32(0);
1798 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001799 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001800}
Andy Adamsonfc931582009-04-01 09:22:31 -04001801
1802static void encode_create_session(struct xdr_stream *xdr,
1803 struct nfs41_create_session_args *args,
1804 struct compound_hdr *hdr)
1805{
1806 __be32 *p;
1807 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1808 uint32_t len;
1809 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001810 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001811 u32 max_resp_sz_cached;
1812
1813 /*
1814 * Assumes OPEN is the biggest non-idempotent compound.
1815 * 2 is the verifier.
1816 */
1817 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1818 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001819
Andy Adamsonfc931582009-04-01 09:22:31 -04001820 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1821 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001822
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001823 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1824 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001825 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001826 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1827 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001828
Andy Adamsonfc931582009-04-01 09:22:31 -04001829 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001830 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001831 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1832 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001833 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001834 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1835 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1836 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001837
1838 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001839 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001840 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1841 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1842 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1843 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1844 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1845 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001846
Benny Halevye75bc1c2009-08-14 17:18:54 +03001847 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001848 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001849 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001850
1851 /* authsys_parms rfc1831 */
Trond Myklebust17f26b12013-08-21 15:48:42 -04001852 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001853 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001854 *p++ = cpu_to_be32(0); /* UID */
1855 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001856 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001857}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001858
1859static void encode_destroy_session(struct xdr_stream *xdr,
1860 struct nfs4_session *session,
1861 struct compound_hdr *hdr)
1862{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001863 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1864 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001865}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001866
Trond Myklebust66245532012-05-25 17:18:09 -04001867static void encode_destroy_clientid(struct xdr_stream *xdr,
1868 uint64_t clientid,
1869 struct compound_hdr *hdr)
1870{
1871 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1872 encode_uint64(xdr, clientid);
1873}
1874
Ricardo Labiaga180197532009-12-05 16:08:40 -05001875static void encode_reclaim_complete(struct xdr_stream *xdr,
1876 struct nfs41_reclaim_complete_args *args,
1877 struct compound_hdr *hdr)
1878{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001879 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1880 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001881}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001882#endif /* CONFIG_NFS_V4_1 */
1883
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001884static void encode_sequence(struct xdr_stream *xdr,
1885 const struct nfs4_sequence_args *args,
1886 struct compound_hdr *hdr)
1887{
1888#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001889 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001890 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001891 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001892 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001893
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001894 tp = slot->table;
1895 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001896 if (!session)
1897 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001898
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001899 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001900
1901 /*
1902 * Sessionid + seqid + slotid + max slotid + cache_this
1903 */
1904 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1905 "max_slotid=%d cache_this=%d\n",
1906 __func__,
1907 ((u32 *)session->sess_id.data)[0],
1908 ((u32 *)session->sess_id.data)[1],
1909 ((u32 *)session->sess_id.data)[2],
1910 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001911 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001912 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001913 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001914 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001915 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001916 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001917 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001918 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001919#endif /* CONFIG_NFS_V4_1 */
1920}
1921
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001922#ifdef CONFIG_NFS_V4_1
1923static void
1924encode_getdeviceinfo(struct xdr_stream *xdr,
1925 const struct nfs4_getdeviceinfo_args *args,
1926 struct compound_hdr *hdr)
1927{
1928 __be32 *p;
1929
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001930 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001931 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001932 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1933 NFS4_DEVICEID4_SIZE);
1934 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001935 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001936
1937 p = reserve_space(xdr, 4 + 4);
1938 *p++ = cpu_to_be32(1); /* bitmap length */
1939 *p++ = cpu_to_be32(NOTIFY_DEVICEID4_CHANGE | NOTIFY_DEVICEID4_DELETE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001940}
1941
1942static void
1943encode_layoutget(struct xdr_stream *xdr,
1944 const struct nfs4_layoutget_args *args,
1945 struct compound_hdr *hdr)
1946{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001947 __be32 *p;
1948
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001949 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1950 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001951 *p++ = cpu_to_be32(0); /* Signal layout available */
1952 *p++ = cpu_to_be32(args->type);
1953 *p++ = cpu_to_be32(args->range.iomode);
1954 p = xdr_encode_hyper(p, args->range.offset);
1955 p = xdr_encode_hyper(p, args->range.length);
1956 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001957 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001958 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001959
1960 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1961 __func__,
1962 args->type,
1963 args->range.iomode,
1964 (unsigned long)args->range.offset,
1965 (unsigned long)args->range.length,
1966 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001967}
Andy Adamson863a3c62011-03-23 13:27:54 +00001968
1969static int
1970encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001971 struct inode *inode,
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001972 struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001973 struct compound_hdr *hdr)
1974{
1975 __be32 *p;
1976
1977 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1978 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1979
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001980 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1981 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001982 /* Only whole file layouts */
1983 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001984 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001985 *p = cpu_to_be32(0); /* reclaim */
1986 encode_nfs4_stateid(xdr, &args->stateid);
1987 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001988 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1989 p = xdr_encode_hyper(p, args->lastbytewritten);
1990 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1991 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001992
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001993 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
Benny Halevyac7db722011-05-22 19:53:48 +03001994 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1995 NFS_I(inode)->layout, xdr, args);
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001996 } else {
1997 encode_uint32(xdr, args->layoutupdate_len);
1998 if (args->layoutupdate_pages) {
1999 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2000 args->layoutupdate_len);
2001 }
2002 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002003
Andy Adamson863a3c62011-03-23 13:27:54 +00002004 return 0;
2005}
Benny Halevycbe82602011-05-22 19:52:37 +03002006
2007static void
2008encode_layoutreturn(struct xdr_stream *xdr,
2009 const struct nfs4_layoutreturn_args *args,
2010 struct compound_hdr *hdr)
2011{
2012 __be32 *p;
2013
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002014 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2015 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002016 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2017 *p++ = cpu_to_be32(args->layout_type);
2018 *p++ = cpu_to_be32(IOMODE_ANY);
2019 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002020 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002021 p = xdr_encode_hyper(p, 0);
2022 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2023 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002024 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002025 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002026 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2027 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2028 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002029 } else
2030 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002031}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002032
2033static int
2034encode_secinfo_no_name(struct xdr_stream *xdr,
2035 const struct nfs41_secinfo_no_name_args *args,
2036 struct compound_hdr *hdr)
2037{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002038 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2039 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002040 return 0;
2041}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002042
2043static void encode_test_stateid(struct xdr_stream *xdr,
2044 struct nfs41_test_stateid_args *args,
2045 struct compound_hdr *hdr)
2046{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002047 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2048 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002049 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002050}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002051
2052static void encode_free_stateid(struct xdr_stream *xdr,
2053 struct nfs41_free_stateid_args *args,
2054 struct compound_hdr *hdr)
2055{
Trond Myklebustab19b482012-03-04 18:13:57 -05002056 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002057 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002058}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002059#endif /* CONFIG_NFS_V4_1 */
2060
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061/*
2062 * END OF "GENERIC" ENCODE ROUTINES.
2063 */
2064
Benny Halevy66cc0422009-04-01 09:22:10 -04002065static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2066{
2067#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002068 struct nfs4_session *session = args->sa_slot->table->session;
2069 if (session)
2070 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002071#endif /* CONFIG_NFS_V4_1 */
2072 return 0;
2073}
2074
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075/*
2076 * Encode an ACCESS request
2077 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002078static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2079 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002082 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
Chuck Lever9f06c712010-12-14 14:59:18 +00002085 encode_compound_hdr(xdr, req, &hdr);
2086 encode_sequence(xdr, &args->seq_args, &hdr);
2087 encode_putfh(xdr, args->fh, &hdr);
2088 encode_access(xdr, args->access, &hdr);
2089 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002090 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091}
2092
2093/*
2094 * Encode LOOKUP request
2095 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002096static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2097 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002100 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
Chuck Lever9f06c712010-12-14 14:59:18 +00002103 encode_compound_hdr(xdr, req, &hdr);
2104 encode_sequence(xdr, &args->seq_args, &hdr);
2105 encode_putfh(xdr, args->dir_fh, &hdr);
2106 encode_lookup(xdr, args->name, &hdr);
2107 encode_getfh(xdr, &hdr);
2108 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002109 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110}
2111
2112/*
2113 * Encode LOOKUP_ROOT request
2114 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002115static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2116 struct xdr_stream *xdr,
2117 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002120 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122
Chuck Lever9f06c712010-12-14 14:59:18 +00002123 encode_compound_hdr(xdr, req, &hdr);
2124 encode_sequence(xdr, &args->seq_args, &hdr);
2125 encode_putrootfh(xdr, &hdr);
2126 encode_getfh(xdr, &hdr);
2127 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002128 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129}
2130
2131/*
2132 * Encode REMOVE request
2133 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002134static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2135 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002138 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
Chuck Lever9f06c712010-12-14 14:59:18 +00002141 encode_compound_hdr(xdr, req, &hdr);
2142 encode_sequence(xdr, &args->seq_args, &hdr);
2143 encode_putfh(xdr, args->fh, &hdr);
2144 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002145 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146}
2147
2148/*
2149 * Encode RENAME request
2150 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002151static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2152 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002155 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
Chuck Lever9f06c712010-12-14 14:59:18 +00002158 encode_compound_hdr(xdr, req, &hdr);
2159 encode_sequence(xdr, &args->seq_args, &hdr);
2160 encode_putfh(xdr, args->old_dir, &hdr);
2161 encode_savefh(xdr, &hdr);
2162 encode_putfh(xdr, args->new_dir, &hdr);
2163 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002164 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165}
2166
2167/*
2168 * Encode LINK request
2169 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002170static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2171 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002174 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
Chuck Lever9f06c712010-12-14 14:59:18 +00002177 encode_compound_hdr(xdr, req, &hdr);
2178 encode_sequence(xdr, &args->seq_args, &hdr);
2179 encode_putfh(xdr, args->fh, &hdr);
2180 encode_savefh(xdr, &hdr);
2181 encode_putfh(xdr, args->dir_fh, &hdr);
2182 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002183 encode_restorefh(xdr, &hdr);
2184 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002185 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186}
2187
2188/*
2189 * Encode CREATE request
2190 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002191static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2192 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002195 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
Chuck Lever9f06c712010-12-14 14:59:18 +00002198 encode_compound_hdr(xdr, req, &hdr);
2199 encode_sequence(xdr, &args->seq_args, &hdr);
2200 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002201 encode_create(xdr, args, &hdr);
2202 encode_getfh(xdr, &hdr);
2203 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002204 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205}
2206
2207/*
2208 * Encode SYMLINK request
2209 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002210static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2211 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212{
Chuck Lever9f06c712010-12-14 14:59:18 +00002213 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214}
2215
2216/*
2217 * Encode GETATTR request
2218 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002219static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2220 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002223 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225
Chuck Lever9f06c712010-12-14 14:59:18 +00002226 encode_compound_hdr(xdr, req, &hdr);
2227 encode_sequence(xdr, &args->seq_args, &hdr);
2228 encode_putfh(xdr, args->fh, &hdr);
2229 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002230 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231}
2232
2233/*
2234 * Encode a CLOSE request
2235 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002236static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2237 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238{
Andy Adamson05d564f2008-12-23 16:06:15 -05002239 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002240 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002241 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
Chuck Lever9f06c712010-12-14 14:59:18 +00002243 encode_compound_hdr(xdr, req, &hdr);
2244 encode_sequence(xdr, &args->seq_args, &hdr);
2245 encode_putfh(xdr, args->fh, &hdr);
2246 encode_close(xdr, args, &hdr);
2247 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002248 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249}
2250
2251/*
2252 * Encode an OPEN request
2253 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002254static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2255 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002258 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260
Chuck Lever9f06c712010-12-14 14:59:18 +00002261 encode_compound_hdr(xdr, req, &hdr);
2262 encode_sequence(xdr, &args->seq_args, &hdr);
2263 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002264 encode_open(xdr, args, &hdr);
2265 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002266 if (args->access)
2267 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002268 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002269 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270}
2271
2272/*
2273 * Encode an OPEN_CONFIRM request
2274 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002275static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2276 struct xdr_stream *xdr,
2277 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002280 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282
Chuck Lever9f06c712010-12-14 14:59:18 +00002283 encode_compound_hdr(xdr, req, &hdr);
2284 encode_putfh(xdr, args->fh, &hdr);
2285 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002286 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287}
2288
2289/*
2290 * Encode an OPEN request with no attributes.
2291 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002292static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2293 struct xdr_stream *xdr,
2294 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002297 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299
Chuck Lever9f06c712010-12-14 14:59:18 +00002300 encode_compound_hdr(xdr, req, &hdr);
2301 encode_sequence(xdr, &args->seq_args, &hdr);
2302 encode_putfh(xdr, args->fh, &hdr);
2303 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002304 if (args->access)
2305 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002306 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002307 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308}
2309
2310/*
2311 * Encode an OPEN_DOWNGRADE request
2312 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002313static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2314 struct xdr_stream *xdr,
2315 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002318 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
Chuck Lever9f06c712010-12-14 14:59:18 +00002321 encode_compound_hdr(xdr, req, &hdr);
2322 encode_sequence(xdr, &args->seq_args, &hdr);
2323 encode_putfh(xdr, args->fh, &hdr);
2324 encode_open_downgrade(xdr, args, &hdr);
2325 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002326 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327}
2328
2329/*
2330 * Encode a LOCK request
2331 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002332static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2333 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002336 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
Chuck Lever9f06c712010-12-14 14:59:18 +00002339 encode_compound_hdr(xdr, req, &hdr);
2340 encode_sequence(xdr, &args->seq_args, &hdr);
2341 encode_putfh(xdr, args->fh, &hdr);
2342 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002343 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344}
2345
2346/*
2347 * Encode a LOCKT request
2348 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002349static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2350 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002353 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
Chuck Lever9f06c712010-12-14 14:59:18 +00002356 encode_compound_hdr(xdr, req, &hdr);
2357 encode_sequence(xdr, &args->seq_args, &hdr);
2358 encode_putfh(xdr, args->fh, &hdr);
2359 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002360 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361}
2362
2363/*
2364 * Encode a LOCKU request
2365 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002366static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2367 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002370 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372
Chuck Lever9f06c712010-12-14 14:59:18 +00002373 encode_compound_hdr(xdr, req, &hdr);
2374 encode_sequence(xdr, &args->seq_args, &hdr);
2375 encode_putfh(xdr, args->fh, &hdr);
2376 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002377 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378}
2379
Chuck Lever9f06c712010-12-14 14:59:18 +00002380static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2381 struct xdr_stream *xdr,
2382 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002383{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002384 struct compound_hdr hdr = {
2385 .minorversion = 0,
2386 };
2387
Chuck Lever9f06c712010-12-14 14:59:18 +00002388 encode_compound_hdr(xdr, req, &hdr);
2389 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002390 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002391}
2392
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393/*
2394 * Encode a READLINK request
2395 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002396static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2397 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002400 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
Chuck Lever9f06c712010-12-14 14:59:18 +00002403 encode_compound_hdr(xdr, req, &hdr);
2404 encode_sequence(xdr, &args->seq_args, &hdr);
2405 encode_putfh(xdr, args->fh, &hdr);
2406 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002407
Benny Halevy28f56692009-04-01 09:22:09 -04002408 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002409 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002410 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411}
2412
2413/*
2414 * Encode a READDIR request
2415 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002416static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2417 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002420 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422
Chuck Lever9f06c712010-12-14 14:59:18 +00002423 encode_compound_hdr(xdr, req, &hdr);
2424 encode_sequence(xdr, &args->seq_args, &hdr);
2425 encode_putfh(xdr, args->fh, &hdr);
2426 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002427
Benny Halevy28f56692009-04-01 09:22:09 -04002428 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002429 args->pgbase, args->count);
2430 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002431 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002432 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002433 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434}
2435
2436/*
2437 * Encode a READ request
2438 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002439static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002440 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002443 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
Chuck Lever9f06c712010-12-14 14:59:18 +00002446 encode_compound_hdr(xdr, req, &hdr);
2447 encode_sequence(xdr, &args->seq_args, &hdr);
2448 encode_putfh(xdr, args->fh, &hdr);
2449 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
Benny Halevy28f56692009-04-01 09:22:09 -04002451 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002453 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002454 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455}
2456
2457/*
2458 * Encode an SETATTR request
2459 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002460static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2461 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462{
Andy Adamson05d564f2008-12-23 16:06:15 -05002463 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002464 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002465 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466
Chuck Lever9f06c712010-12-14 14:59:18 +00002467 encode_compound_hdr(xdr, req, &hdr);
2468 encode_sequence(xdr, &args->seq_args, &hdr);
2469 encode_putfh(xdr, args->fh, &hdr);
2470 encode_setattr(xdr, args, args->server, &hdr);
2471 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002472 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473}
2474
2475/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002476 * Encode a GETACL request
2477 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002478static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2479 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002480{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002481 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002482 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002483 };
Benny Halevy28f56692009-04-01 09:22:09 -04002484 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002485
Chuck Lever9f06c712010-12-14 14:59:18 +00002486 encode_compound_hdr(xdr, req, &hdr);
2487 encode_sequence(xdr, &args->seq_args, &hdr);
2488 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002489 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002490 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002491
Benny Halevy28f56692009-04-01 09:22:09 -04002492 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002493 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002494
Andy Adamsond0179312008-12-23 16:06:17 -05002495 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002496}
2497
2498/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 * Encode a WRITE request
2500 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002501static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002502 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002505 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507
Chuck Lever9f06c712010-12-14 14:59:18 +00002508 encode_compound_hdr(xdr, req, &hdr);
2509 encode_sequence(xdr, &args->seq_args, &hdr);
2510 encode_putfh(xdr, args->fh, &hdr);
2511 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002512 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002513 if (args->bitmask)
2514 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002515 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516}
2517
2518/*
2519 * a COMMIT request
2520 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002521static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002522 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002525 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527
Chuck Lever9f06c712010-12-14 14:59:18 +00002528 encode_compound_hdr(xdr, req, &hdr);
2529 encode_sequence(xdr, &args->seq_args, &hdr);
2530 encode_putfh(xdr, args->fh, &hdr);
2531 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002532 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533}
2534
2535/*
2536 * FSINFO request
2537 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002538static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2539 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002542 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544
Chuck Lever9f06c712010-12-14 14:59:18 +00002545 encode_compound_hdr(xdr, req, &hdr);
2546 encode_sequence(xdr, &args->seq_args, &hdr);
2547 encode_putfh(xdr, args->fh, &hdr);
2548 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002549 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550}
2551
2552/*
2553 * a PATHCONF request
2554 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002555static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2556 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002559 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561
Chuck Lever9f06c712010-12-14 14:59:18 +00002562 encode_compound_hdr(xdr, req, &hdr);
2563 encode_sequence(xdr, &args->seq_args, &hdr);
2564 encode_putfh(xdr, args->fh, &hdr);
2565 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002566 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002567 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568}
2569
2570/*
2571 * a STATFS request
2572 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002573static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2574 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002577 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579
Chuck Lever9f06c712010-12-14 14:59:18 +00002580 encode_compound_hdr(xdr, req, &hdr);
2581 encode_sequence(xdr, &args->seq_args, &hdr);
2582 encode_putfh(xdr, args->fh, &hdr);
2583 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002584 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002585 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586}
2587
2588/*
2589 * GETATTR_BITMAP request
2590 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002591static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2592 struct xdr_stream *xdr,
2593 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002596 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598
Chuck Lever9f06c712010-12-14 14:59:18 +00002599 encode_compound_hdr(xdr, req, &hdr);
2600 encode_sequence(xdr, &args->seq_args, &hdr);
2601 encode_putfh(xdr, args->fhandle, &hdr);
2602 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002603 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002604 FATTR4_WORD0_LINK_SUPPORT|
2605 FATTR4_WORD0_SYMLINK_SUPPORT|
2606 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002607 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608}
2609
2610/*
2611 * a RENEW request
2612 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002613static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2614 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002617 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 };
2619
Chuck Lever9f06c712010-12-14 14:59:18 +00002620 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002621 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002622 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623}
2624
2625/*
2626 * a SETCLIENTID request
2627 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002628static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2629 struct xdr_stream *xdr,
2630 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002633 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 };
2635
Chuck Lever9f06c712010-12-14 14:59:18 +00002636 encode_compound_hdr(xdr, req, &hdr);
2637 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002638 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639}
2640
2641/*
2642 * a SETCLIENTID_CONFIRM request
2643 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002644static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2645 struct xdr_stream *xdr,
2646 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002649 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
Chuck Lever9f06c712010-12-14 14:59:18 +00002652 encode_compound_hdr(xdr, req, &hdr);
2653 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002654 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655}
2656
2657/*
2658 * DELEGRETURN request
2659 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002660static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2661 struct xdr_stream *xdr,
2662 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002665 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667
Chuck Lever9f06c712010-12-14 14:59:18 +00002668 encode_compound_hdr(xdr, req, &hdr);
2669 encode_sequence(xdr, &args->seq_args, &hdr);
2670 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002671 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002672 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002673 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674}
2675
2676/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002677 * Encode FS_LOCATIONS request
2678 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002679static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2680 struct xdr_stream *xdr,
2681 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002682{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002683 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002684 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002685 };
Benny Halevy28f56692009-04-01 09:22:09 -04002686 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002687
Chuck Lever9f06c712010-12-14 14:59:18 +00002688 encode_compound_hdr(xdr, req, &hdr);
2689 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002690 if (args->migration) {
2691 encode_putfh(xdr, args->fh, &hdr);
2692 replen = hdr.replen;
2693 encode_fs_locations(xdr, args->bitmask, &hdr);
2694 if (args->renew)
2695 encode_renew(xdr, args->clientid, &hdr);
2696 } else {
2697 encode_putfh(xdr, args->dir_fh, &hdr);
2698 encode_lookup(xdr, args->name, &hdr);
2699 replen = hdr.replen;
2700 encode_fs_locations(xdr, args->bitmask, &hdr);
2701 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002702
Chuck Leverb03d7352013-10-17 14:12:50 -04002703 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002704 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002705 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002706 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002707}
2708
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002709/*
2710 * Encode SECINFO request
2711 */
2712static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2713 struct xdr_stream *xdr,
2714 struct nfs4_secinfo_arg *args)
2715{
2716 struct compound_hdr hdr = {
2717 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2718 };
2719
2720 encode_compound_hdr(xdr, req, &hdr);
2721 encode_sequence(xdr, &args->seq_args, &hdr);
2722 encode_putfh(xdr, args->dir_fh, &hdr);
2723 encode_secinfo(xdr, args->name, &hdr);
2724 encode_nops(&hdr);
2725}
2726
Chuck Lever44c99932013-10-17 14:13:30 -04002727/*
2728 * Encode FSID_PRESENT request
2729 */
2730static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2731 struct xdr_stream *xdr,
2732 struct nfs4_fsid_present_arg *args)
2733{
2734 struct compound_hdr hdr = {
2735 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2736 };
2737
2738 encode_compound_hdr(xdr, req, &hdr);
2739 encode_sequence(xdr, &args->seq_args, &hdr);
2740 encode_putfh(xdr, args->fh, &hdr);
2741 encode_getfh(xdr, &hdr);
2742 if (args->renew)
2743 encode_renew(xdr, args->clientid, &hdr);
2744 encode_nops(&hdr);
2745}
2746
Benny Halevy99fe60d2009-04-01 09:22:29 -04002747#if defined(CONFIG_NFS_V4_1)
2748/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002749 * BIND_CONN_TO_SESSION request
2750 */
2751static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2752 struct xdr_stream *xdr,
2753 struct nfs_client *clp)
2754{
2755 struct compound_hdr hdr = {
2756 .minorversion = clp->cl_mvops->minor_version,
2757 };
2758
2759 encode_compound_hdr(xdr, req, &hdr);
2760 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2761 encode_nops(&hdr);
2762}
2763
2764/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002765 * EXCHANGE_ID request
2766 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002767static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2768 struct xdr_stream *xdr,
2769 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002770{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002771 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002772 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002773 };
2774
Chuck Lever9f06c712010-12-14 14:59:18 +00002775 encode_compound_hdr(xdr, req, &hdr);
2776 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002777 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002778}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002779
2780/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002781 * a CREATE_SESSION request
2782 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002783static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2784 struct xdr_stream *xdr,
2785 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002786{
Andy Adamsonfc931582009-04-01 09:22:31 -04002787 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002788 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002789 };
2790
Chuck Lever9f06c712010-12-14 14:59:18 +00002791 encode_compound_hdr(xdr, req, &hdr);
2792 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002793 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002794}
2795
2796/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002797 * a DESTROY_SESSION request
2798 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002799static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2800 struct xdr_stream *xdr,
2801 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002802{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002803 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002804 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002805 };
2806
Chuck Lever9f06c712010-12-14 14:59:18 +00002807 encode_compound_hdr(xdr, req, &hdr);
2808 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002809 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002810}
2811
2812/*
Trond Myklebust66245532012-05-25 17:18:09 -04002813 * a DESTROY_CLIENTID request
2814 */
2815static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2816 struct xdr_stream *xdr,
2817 struct nfs_client *clp)
2818{
2819 struct compound_hdr hdr = {
2820 .minorversion = clp->cl_mvops->minor_version,
2821 };
2822
2823 encode_compound_hdr(xdr, req, &hdr);
2824 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2825 encode_nops(&hdr);
2826}
2827
2828/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002829 * a SEQUENCE request
2830 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002831static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2832 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002833{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002834 struct compound_hdr hdr = {
2835 .minorversion = nfs4_xdr_minorversion(args),
2836 };
2837
Chuck Lever9f06c712010-12-14 14:59:18 +00002838 encode_compound_hdr(xdr, req, &hdr);
2839 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002840 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002841}
2842
2843/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002844 * a GET_LEASE_TIME request
2845 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002846static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2847 struct xdr_stream *xdr,
2848 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002849{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002850 struct compound_hdr hdr = {
2851 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2852 };
Fred Isamandae100c2011-07-30 20:52:37 -04002853 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002854
Chuck Lever9f06c712010-12-14 14:59:18 +00002855 encode_compound_hdr(xdr, req, &hdr);
2856 encode_sequence(xdr, &args->la_seq_args, &hdr);
2857 encode_putrootfh(xdr, &hdr);
2858 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002859 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002860}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002861
2862/*
2863 * a RECLAIM_COMPLETE request
2864 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002865static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2866 struct xdr_stream *xdr,
2867 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002868{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002869 struct compound_hdr hdr = {
2870 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2871 };
2872
Chuck Lever9f06c712010-12-14 14:59:18 +00002873 encode_compound_hdr(xdr, req, &hdr);
2874 encode_sequence(xdr, &args->seq_args, &hdr);
2875 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002876 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002877}
2878
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002879/*
2880 * Encode GETDEVICEINFO request
2881 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002882static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2883 struct xdr_stream *xdr,
2884 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002885{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002886 struct compound_hdr hdr = {
2887 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2888 };
2889
Chuck Lever9f06c712010-12-14 14:59:18 +00002890 encode_compound_hdr(xdr, req, &hdr);
2891 encode_sequence(xdr, &args->seq_args, &hdr);
2892 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002893
2894 /* set up reply kvec. Subtract notification bitmap max size (2)
2895 * so that notification bitmap is put in xdr_buf tail */
2896 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2897 args->pdev->pages, args->pdev->pgbase,
2898 args->pdev->pglen);
2899
2900 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002901}
2902
2903/*
2904 * Encode LAYOUTGET request
2905 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002906static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2907 struct xdr_stream *xdr,
2908 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002909{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002910 struct compound_hdr hdr = {
2911 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2912 };
2913
Chuck Lever9f06c712010-12-14 14:59:18 +00002914 encode_compound_hdr(xdr, req, &hdr);
2915 encode_sequence(xdr, &args->seq_args, &hdr);
2916 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2917 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002918
2919 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2920 args->layout.pages, 0, args->layout.pglen);
2921
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002922 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002923}
Andy Adamson863a3c62011-03-23 13:27:54 +00002924
2925/*
2926 * Encode LAYOUTCOMMIT request
2927 */
Benny Halevycbe82602011-05-22 19:52:37 +03002928static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2929 struct xdr_stream *xdr,
2930 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002931{
Benny Halevyac7db722011-05-22 19:53:48 +03002932 struct nfs4_layoutcommit_data *data =
2933 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002934 struct compound_hdr hdr = {
2935 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2936 };
2937
2938 encode_compound_hdr(xdr, req, &hdr);
2939 encode_sequence(xdr, &args->seq_args, &hdr);
2940 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002941 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002942 encode_getfattr(xdr, args->bitmask, &hdr);
2943 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002944}
2945
2946/*
2947 * Encode LAYOUTRETURN request
2948 */
2949static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2950 struct xdr_stream *xdr,
2951 struct nfs4_layoutreturn_args *args)
2952{
2953 struct compound_hdr hdr = {
2954 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2955 };
2956
2957 encode_compound_hdr(xdr, req, &hdr);
2958 encode_sequence(xdr, &args->seq_args, &hdr);
2959 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2960 encode_layoutreturn(xdr, args, &hdr);
2961 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002962}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002963
2964/*
2965 * Encode SECINFO_NO_NAME request
2966 */
2967static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2968 struct xdr_stream *xdr,
2969 struct nfs41_secinfo_no_name_args *args)
2970{
2971 struct compound_hdr hdr = {
2972 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2973 };
2974
2975 encode_compound_hdr(xdr, req, &hdr);
2976 encode_sequence(xdr, &args->seq_args, &hdr);
2977 encode_putrootfh(xdr, &hdr);
2978 encode_secinfo_no_name(xdr, args, &hdr);
2979 encode_nops(&hdr);
2980 return 0;
2981}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002982
2983/*
2984 * Encode TEST_STATEID request
2985 */
2986static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2987 struct xdr_stream *xdr,
2988 struct nfs41_test_stateid_args *args)
2989{
2990 struct compound_hdr hdr = {
2991 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2992 };
2993
2994 encode_compound_hdr(xdr, req, &hdr);
2995 encode_sequence(xdr, &args->seq_args, &hdr);
2996 encode_test_stateid(xdr, args, &hdr);
2997 encode_nops(&hdr);
2998}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002999
3000/*
3001 * Encode FREE_STATEID request
3002 */
3003static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3004 struct xdr_stream *xdr,
3005 struct nfs41_free_stateid_args *args)
3006{
3007 struct compound_hdr hdr = {
3008 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3009 };
3010
3011 encode_compound_hdr(xdr, req, &hdr);
3012 encode_sequence(xdr, &args->seq_args, &hdr);
3013 encode_free_stateid(xdr, args, &hdr);
3014 encode_nops(&hdr);
3015}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003016#endif /* CONFIG_NFS_V4_1 */
3017
Benny Halevy686841b2009-08-14 17:19:48 +03003018static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3019{
3020 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3021 "Remaining buffer length is %tu words.\n",
3022 func, xdr->end - xdr->p);
3023}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024
Trond Myklebust683b57b2006-06-09 09:34:22 -04003025static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026{
Al Viro8687b632006-10-19 23:28:48 -07003027 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028
Benny Halevyc0eae662009-08-14 17:20:14 +03003029 p = xdr_inline_decode(xdr, 4);
3030 if (unlikely(!p))
3031 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003032 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003033 p = xdr_inline_decode(xdr, *len);
3034 if (unlikely(!p))
3035 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 *string = (char *)p;
3037 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003038out_overflow:
3039 print_overflow_msg(__func__, xdr);
3040 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041}
3042
3043static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3044{
Al Viro8687b632006-10-19 23:28:48 -07003045 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046
Benny Halevyc0eae662009-08-14 17:20:14 +03003047 p = xdr_inline_decode(xdr, 8);
3048 if (unlikely(!p))
3049 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003050 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003051 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003052
Benny Halevyc0eae662009-08-14 17:20:14 +03003053 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3054 if (unlikely(!p))
3055 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 hdr->tag = (char *)p;
3057 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003058 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003059 if (unlikely(hdr->nops < 1))
3060 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003062out_overflow:
3063 print_overflow_msg(__func__, xdr);
3064 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065}
3066
Trond Myklebustc7848f62013-12-04 17:39:23 -05003067static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3068 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069{
Al Viro8687b632006-10-19 23:28:48 -07003070 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 uint32_t opnum;
3072 int32_t nfserr;
3073
Benny Halevyc0eae662009-08-14 17:20:14 +03003074 p = xdr_inline_decode(xdr, 8);
3075 if (unlikely(!p))
3076 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003077 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003078 if (unlikely(opnum != expected))
3079 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003080 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003081 if (nfserr == NFS_OK)
3082 *nfs_retval = 0;
3083 else
3084 *nfs_retval = nfs4_stat_to_errno(nfserr);
3085 return true;
3086out_bad_operation:
3087 dprintk("nfs: Server returned operation"
3088 " %d but we issued a request for %d\n",
3089 opnum, expected);
3090 *nfs_retval = -EREMOTEIO;
3091 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003092out_overflow:
3093 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003094 *nfs_retval = -EIO;
3095 return false;
3096}
3097
3098static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3099{
3100 int retval;
3101
3102 __decode_op_hdr(xdr, expected, &retval);
3103 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104}
3105
3106/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003107static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108{
Al Viro8687b632006-10-19 23:28:48 -07003109 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003110 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 char *str;
3112
Benny Halevyc0eae662009-08-14 17:20:14 +03003113 p = xdr_inline_decode(xdr, 12);
3114 if (likely(p))
3115 return decode_opaque_inline(xdr, &strlen, &str);
3116 print_overflow_msg(__func__, xdr);
3117 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118}
3119
3120static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3121{
Al Viro8687b632006-10-19 23:28:48 -07003122 uint32_t bmlen;
3123 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124
Benny Halevyc0eae662009-08-14 17:20:14 +03003125 p = xdr_inline_decode(xdr, 4);
3126 if (unlikely(!p))
3127 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003128 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129
Fred Isamandae100c2011-07-30 20:52:37 -04003130 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003131 p = xdr_inline_decode(xdr, (bmlen << 2));
3132 if (unlikely(!p))
3133 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003135 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003136 if (bmlen > 1) {
3137 bitmap[1] = be32_to_cpup(p++);
3138 if (bmlen > 2)
3139 bitmap[2] = be32_to_cpup(p);
3140 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 }
3142 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003143out_overflow:
3144 print_overflow_msg(__func__, xdr);
3145 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146}
3147
Trond Myklebust256e48b2012-06-21 11:18:13 -04003148static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149{
Al Viro8687b632006-10-19 23:28:48 -07003150 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151
Benny Halevyc0eae662009-08-14 17:20:14 +03003152 p = xdr_inline_decode(xdr, 4);
3153 if (unlikely(!p))
3154 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003155 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003156 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003158out_overflow:
3159 print_overflow_msg(__func__, xdr);
3160 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161}
3162
3163static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3164{
3165 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003166 int ret;
3167 ret = decode_attr_bitmap(xdr, bitmask);
3168 if (unlikely(ret < 0))
3169 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3171 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003172 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3173 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3174 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 return 0;
3176}
3177
3178static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3179{
Al Viro8687b632006-10-19 23:28:48 -07003180 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003181 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182
3183 *type = 0;
3184 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3185 return -EIO;
3186 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003187 p = xdr_inline_decode(xdr, 4);
3188 if (unlikely(!p))
3189 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003190 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003192 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 return -EIO;
3194 }
3195 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003196 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003198 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003199 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003200out_overflow:
3201 print_overflow_msg(__func__, xdr);
3202 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203}
3204
Chuck Lever264e6352012-03-01 17:02:05 -05003205static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3206 uint32_t *bitmap, uint32_t *type)
3207{
3208 __be32 *p;
3209
3210 *type = 0;
3211 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3212 return -EIO;
3213 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3214 p = xdr_inline_decode(xdr, 4);
3215 if (unlikely(!p))
3216 goto out_overflow;
3217 *type = be32_to_cpup(p);
3218 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3219 }
3220 dprintk("%s: expire type=0x%x\n", __func__, *type);
3221 return 0;
3222out_overflow:
3223 print_overflow_msg(__func__, xdr);
3224 return -EIO;
3225}
3226
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3228{
Al Viro8687b632006-10-19 23:28:48 -07003229 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003230 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231
3232 *change = 0;
3233 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3234 return -EIO;
3235 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003236 p = xdr_inline_decode(xdr, 8);
3237 if (unlikely(!p))
3238 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003239 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003241 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003243 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003245 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003246out_overflow:
3247 print_overflow_msg(__func__, xdr);
3248 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249}
3250
3251static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3252{
Al Viro8687b632006-10-19 23:28:48 -07003253 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003254 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255
3256 *size = 0;
3257 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3258 return -EIO;
3259 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003260 p = xdr_inline_decode(xdr, 8);
3261 if (unlikely(!p))
3262 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003263 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003265 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003267 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003268 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003269out_overflow:
3270 print_overflow_msg(__func__, xdr);
3271 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272}
3273
3274static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3275{
Al Viro8687b632006-10-19 23:28:48 -07003276 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277
3278 *res = 0;
3279 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3280 return -EIO;
3281 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003282 p = xdr_inline_decode(xdr, 4);
3283 if (unlikely(!p))
3284 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003285 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3287 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003288 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003290out_overflow:
3291 print_overflow_msg(__func__, xdr);
3292 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293}
3294
3295static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3296{
Al Viro8687b632006-10-19 23:28:48 -07003297 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298
3299 *res = 0;
3300 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3301 return -EIO;
3302 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003303 p = xdr_inline_decode(xdr, 4);
3304 if (unlikely(!p))
3305 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003306 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3308 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003309 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003311out_overflow:
3312 print_overflow_msg(__func__, xdr);
3313 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314}
3315
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003316static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317{
Al Viro8687b632006-10-19 23:28:48 -07003318 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003319 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320
3321 fsid->major = 0;
3322 fsid->minor = 0;
3323 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3324 return -EIO;
3325 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003326 p = xdr_inline_decode(xdr, 16);
3327 if (unlikely(!p))
3328 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003329 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003330 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003332 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003334 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 (unsigned long long)fsid->major,
3336 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003337 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003338out_overflow:
3339 print_overflow_msg(__func__, xdr);
3340 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341}
3342
3343static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3344{
Al Viro8687b632006-10-19 23:28:48 -07003345 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346
3347 *res = 60;
3348 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3349 return -EIO;
3350 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003351 p = xdr_inline_decode(xdr, 4);
3352 if (unlikely(!p))
3353 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003354 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3356 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003357 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003359out_overflow:
3360 print_overflow_msg(__func__, xdr);
3361 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362}
3363
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003364static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003365{
3366 __be32 *p;
3367
3368 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3369 return -EIO;
3370 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3371 p = xdr_inline_decode(xdr, 4);
3372 if (unlikely(!p))
3373 goto out_overflow;
3374 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003375 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003376 }
3377 return 0;
3378out_overflow:
3379 print_overflow_msg(__func__, xdr);
3380 return -EIO;
3381}
3382
3383static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3384{
3385 __be32 *p;
3386 int len;
3387
Trond Myklebust7ad07352010-10-23 15:34:20 -04003388 if (fh != NULL)
3389 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003390
3391 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3392 return -EIO;
3393 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3394 p = xdr_inline_decode(xdr, 4);
3395 if (unlikely(!p))
3396 goto out_overflow;
3397 len = be32_to_cpup(p);
3398 if (len > NFS4_FHSIZE)
3399 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003400 p = xdr_inline_decode(xdr, len);
3401 if (unlikely(!p))
3402 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003403 if (fh != NULL) {
3404 memcpy(fh->data, p, len);
3405 fh->size = len;
3406 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003407 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3408 }
3409 return 0;
3410out_overflow:
3411 print_overflow_msg(__func__, xdr);
3412 return -EIO;
3413}
3414
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3416{
Al Viro8687b632006-10-19 23:28:48 -07003417 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003419 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3421 return -EIO;
3422 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003423 p = xdr_inline_decode(xdr, 4);
3424 if (unlikely(!p))
3425 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003426 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3428 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003429 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003431out_overflow:
3432 print_overflow_msg(__func__, xdr);
3433 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434}
3435
3436static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3437{
Al Viro8687b632006-10-19 23:28:48 -07003438 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003439 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440
3441 *fileid = 0;
3442 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3443 return -EIO;
3444 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003445 p = xdr_inline_decode(xdr, 8);
3446 if (unlikely(!p))
3447 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003448 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003450 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003452 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003453 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003454out_overflow:
3455 print_overflow_msg(__func__, xdr);
3456 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457}
3458
Manoj Naik99baf622006-06-09 09:34:24 -04003459static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3460{
Al Viro8687b632006-10-19 23:28:48 -07003461 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003462 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003463
3464 *fileid = 0;
3465 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3466 return -EIO;
3467 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003468 p = xdr_inline_decode(xdr, 8);
3469 if (unlikely(!p))
3470 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003471 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003472 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003473 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003474 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003475 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003476 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003477out_overflow:
3478 print_overflow_msg(__func__, xdr);
3479 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003480}
3481
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3483{
Al Viro8687b632006-10-19 23:28:48 -07003484 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 int status = 0;
3486
3487 *res = 0;
3488 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3489 return -EIO;
3490 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003491 p = xdr_inline_decode(xdr, 8);
3492 if (unlikely(!p))
3493 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003494 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3496 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003497 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003499out_overflow:
3500 print_overflow_msg(__func__, xdr);
3501 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502}
3503
3504static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3505{
Al Viro8687b632006-10-19 23:28:48 -07003506 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 int status = 0;
3508
3509 *res = 0;
3510 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3511 return -EIO;
3512 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003513 p = xdr_inline_decode(xdr, 8);
3514 if (unlikely(!p))
3515 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003516 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3518 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003519 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003521out_overflow:
3522 print_overflow_msg(__func__, xdr);
3523 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524}
3525
3526static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3527{
Al Viro8687b632006-10-19 23:28:48 -07003528 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 int status = 0;
3530
3531 *res = 0;
3532 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3533 return -EIO;
3534 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003535 p = xdr_inline_decode(xdr, 8);
3536 if (unlikely(!p))
3537 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003538 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3540 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003541 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003543out_overflow:
3544 print_overflow_msg(__func__, xdr);
3545 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546}
3547
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003548static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3549{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003550 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003551 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003552 int status = 0;
3553
Benny Halevyc0eae662009-08-14 17:20:14 +03003554 p = xdr_inline_decode(xdr, 4);
3555 if (unlikely(!p))
3556 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003557 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003558 if (n == 0)
3559 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003560 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003561 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3562 dprintk("cannot parse %d components in path\n", n);
3563 goto out_eio;
3564 }
3565 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003566 struct nfs4_string *component = &path->components[path->ncomponents];
3567 status = decode_opaque_inline(xdr, &component->len, &component->data);
3568 if (unlikely(status != 0))
3569 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003570 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003571 pr_cont("%s%.*s ",
3572 (path->ncomponents != n ? "/ " : ""),
3573 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003574 }
3575out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003576 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003577root_path:
3578/* a root pathname is sent as a zero component4 */
3579 path->ncomponents = 1;
3580 path->components[0].len=0;
3581 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003582 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003583 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003584out_eio:
3585 dprintk(" status %d", status);
3586 status = -EIO;
3587 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003588out_overflow:
3589 print_overflow_msg(__func__, xdr);
3590 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003591}
3592
3593static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003594{
3595 int n;
Al Viro8687b632006-10-19 23:28:48 -07003596 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003597 int status = -EIO;
3598
3599 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3600 goto out;
3601 status = 0;
3602 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3603 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003604 status = -EIO;
3605 /* Ignore borken servers that return unrequested attrs */
3606 if (unlikely(res == NULL))
3607 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003608 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003609 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003610 if (unlikely(status != 0))
3611 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003612 p = xdr_inline_decode(xdr, 4);
3613 if (unlikely(!p))
3614 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003615 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003616 if (n <= 0)
3617 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003618 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003619 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003620 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003621
Trond Myklebust809b4262013-03-27 11:54:45 -04003622 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3623 break;
3624 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003625 p = xdr_inline_decode(xdr, 4);
3626 if (unlikely(!p))
3627 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003628 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003629
Chuck Lever02a29762012-03-01 17:00:31 -05003630 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003631 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3632 struct nfs4_string *server;
3633
3634 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003635 unsigned int i;
3636 dprintk("%s: using first %u of %u servers "
3637 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003638 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003639 NFS4_FS_LOCATION_MAXSERVERS,
3640 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003641 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003642 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003643 char *data;
3644 status = decode_opaque_inline(xdr, &len, &data);
3645 if (unlikely(status != 0))
3646 goto out_eio;
3647 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003648 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003649 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003650 server = &loc->servers[loc->nservers];
3651 status = decode_opaque_inline(xdr, &server->len, &server->data);
3652 if (unlikely(status != 0))
3653 goto out_eio;
3654 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003655 }
3656 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003657 if (unlikely(status != 0))
3658 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003659 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003660 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003661 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003662out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003663 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003664 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003665out_overflow:
3666 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003667out_eio:
3668 status = -EIO;
3669 goto out;
3670}
3671
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3673{
Al Viro8687b632006-10-19 23:28:48 -07003674 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 int status = 0;
3676
3677 *res = 0;
3678 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3679 return -EIO;
3680 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003681 p = xdr_inline_decode(xdr, 8);
3682 if (unlikely(!p))
3683 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003684 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3686 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003687 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003689out_overflow:
3690 print_overflow_msg(__func__, xdr);
3691 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692}
3693
3694static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3695{
Al Viro8687b632006-10-19 23:28:48 -07003696 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 int status = 0;
3698
3699 *maxlink = 1;
3700 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3701 return -EIO;
3702 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003703 p = xdr_inline_decode(xdr, 4);
3704 if (unlikely(!p))
3705 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003706 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3708 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003709 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003711out_overflow:
3712 print_overflow_msg(__func__, xdr);
3713 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714}
3715
3716static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3717{
Al Viro8687b632006-10-19 23:28:48 -07003718 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 int status = 0;
3720
3721 *maxname = 1024;
3722 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3723 return -EIO;
3724 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003725 p = xdr_inline_decode(xdr, 4);
3726 if (unlikely(!p))
3727 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003728 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3730 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003731 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003733out_overflow:
3734 print_overflow_msg(__func__, xdr);
3735 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736}
3737
3738static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3739{
Al Viro8687b632006-10-19 23:28:48 -07003740 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741 int status = 0;
3742
3743 *res = 1024;
3744 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3745 return -EIO;
3746 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3747 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003748 p = xdr_inline_decode(xdr, 8);
3749 if (unlikely(!p))
3750 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003751 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 if (maxread > 0x7FFFFFFF)
3753 maxread = 0x7FFFFFFF;
3754 *res = (uint32_t)maxread;
3755 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3756 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003757 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003759out_overflow:
3760 print_overflow_msg(__func__, xdr);
3761 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762}
3763
3764static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3765{
Al Viro8687b632006-10-19 23:28:48 -07003766 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767 int status = 0;
3768
3769 *res = 1024;
3770 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3771 return -EIO;
3772 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3773 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003774 p = xdr_inline_decode(xdr, 8);
3775 if (unlikely(!p))
3776 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003777 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778 if (maxwrite > 0x7FFFFFFF)
3779 maxwrite = 0x7FFFFFFF;
3780 *res = (uint32_t)maxwrite;
3781 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3782 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003783 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003785out_overflow:
3786 print_overflow_msg(__func__, xdr);
3787 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788}
3789
Trond Myklebustbca79472009-03-11 14:10:26 -04003790static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791{
Trond Myklebustbca79472009-03-11 14:10:26 -04003792 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003793 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003794 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795
3796 *mode = 0;
3797 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3798 return -EIO;
3799 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003800 p = xdr_inline_decode(xdr, 4);
3801 if (unlikely(!p))
3802 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003803 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003804 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003806 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003808 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003809 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003810out_overflow:
3811 print_overflow_msg(__func__, xdr);
3812 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813}
3814
3815static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3816{
Al Viro8687b632006-10-19 23:28:48 -07003817 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003818 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819
3820 *nlink = 1;
3821 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3822 return -EIO;
3823 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003824 p = xdr_inline_decode(xdr, 4);
3825 if (unlikely(!p))
3826 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003827 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003829 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003831 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003832 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003833out_overflow:
3834 print_overflow_msg(__func__, xdr);
3835 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836}
3837
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003838static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003839 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003840 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841{
Al Viro8687b632006-10-19 23:28:48 -07003842 uint32_t len;
3843 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003844 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845
Eric W. Biedermane5782072013-02-01 14:22:02 -08003846 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3848 return -EIO;
3849 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003850 p = xdr_inline_decode(xdr, 4);
3851 if (unlikely(!p))
3852 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003853 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003854 p = xdr_inline_decode(xdr, len);
3855 if (unlikely(!p))
3856 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003857 if (owner_name != NULL) {
3858 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3859 if (owner_name->data != NULL) {
3860 owner_name->len = len;
3861 ret = NFS_ATTR_FATTR_OWNER_NAME;
3862 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003863 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003864 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003865 ret = NFS_ATTR_FATTR_OWNER;
3866 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003868 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003870 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003871 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3873 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003874 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003875 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003876out_overflow:
3877 print_overflow_msg(__func__, xdr);
3878 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879}
3880
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003881static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003882 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003883 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884{
Al Viro8687b632006-10-19 23:28:48 -07003885 uint32_t len;
3886 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003887 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888
Eric W. Biedermane5782072013-02-01 14:22:02 -08003889 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3891 return -EIO;
3892 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003893 p = xdr_inline_decode(xdr, 4);
3894 if (unlikely(!p))
3895 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003896 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003897 p = xdr_inline_decode(xdr, len);
3898 if (unlikely(!p))
3899 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003900 if (group_name != NULL) {
3901 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3902 if (group_name->data != NULL) {
3903 group_name->len = len;
3904 ret = NFS_ATTR_FATTR_GROUP_NAME;
3905 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003906 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003907 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003908 ret = NFS_ATTR_FATTR_GROUP;
3909 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003911 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003913 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003914 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3916 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003917 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003918 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003919out_overflow:
3920 print_overflow_msg(__func__, xdr);
3921 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922}
3923
3924static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3925{
Al Viro8687b632006-10-19 23:28:48 -07003926 uint32_t major = 0, minor = 0;
3927 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003928 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929
3930 *rdev = MKDEV(0,0);
3931 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3932 return -EIO;
3933 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3934 dev_t tmp;
3935
Benny Halevyc0eae662009-08-14 17:20:14 +03003936 p = xdr_inline_decode(xdr, 8);
3937 if (unlikely(!p))
3938 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003939 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003940 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941 tmp = MKDEV(major, minor);
3942 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3943 *rdev = tmp;
3944 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003945 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003947 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003948 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003949out_overflow:
3950 print_overflow_msg(__func__, xdr);
3951 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952}
3953
3954static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3955{
Al Viro8687b632006-10-19 23:28:48 -07003956 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957 int status = 0;
3958
3959 *res = 0;
3960 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3961 return -EIO;
3962 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003963 p = xdr_inline_decode(xdr, 8);
3964 if (unlikely(!p))
3965 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003966 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3968 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003969 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003971out_overflow:
3972 print_overflow_msg(__func__, xdr);
3973 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974}
3975
3976static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3977{
Al Viro8687b632006-10-19 23:28:48 -07003978 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 int status = 0;
3980
3981 *res = 0;
3982 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3983 return -EIO;
3984 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003985 p = xdr_inline_decode(xdr, 8);
3986 if (unlikely(!p))
3987 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003988 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3990 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003991 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003993out_overflow:
3994 print_overflow_msg(__func__, xdr);
3995 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996}
3997
3998static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3999{
Al Viro8687b632006-10-19 23:28:48 -07004000 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 int status = 0;
4002
4003 *res = 0;
4004 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4005 return -EIO;
4006 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004007 p = xdr_inline_decode(xdr, 8);
4008 if (unlikely(!p))
4009 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004010 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4012 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004013 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004015out_overflow:
4016 print_overflow_msg(__func__, xdr);
4017 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018}
4019
4020static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4021{
Al Viro8687b632006-10-19 23:28:48 -07004022 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004023 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024
4025 *used = 0;
4026 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4027 return -EIO;
4028 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004029 p = xdr_inline_decode(xdr, 8);
4030 if (unlikely(!p))
4031 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004032 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004034 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004036 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004038 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004039out_overflow:
4040 print_overflow_msg(__func__, xdr);
4041 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042}
4043
4044static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4045{
Al Viro8687b632006-10-19 23:28:48 -07004046 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 uint64_t sec;
4048 uint32_t nsec;
4049
Benny Halevyc0eae662009-08-14 17:20:14 +03004050 p = xdr_inline_decode(xdr, 12);
4051 if (unlikely(!p))
4052 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004053 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004054 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055 time->tv_sec = (time_t)sec;
4056 time->tv_nsec = (long)nsec;
4057 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004058out_overflow:
4059 print_overflow_msg(__func__, xdr);
4060 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061}
4062
4063static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4064{
4065 int status = 0;
4066
4067 time->tv_sec = 0;
4068 time->tv_nsec = 0;
4069 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4070 return -EIO;
4071 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4072 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004073 if (status == 0)
4074 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4076 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004077 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078 return status;
4079}
4080
4081static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4082{
4083 int status = 0;
4084
4085 time->tv_sec = 0;
4086 time->tv_nsec = 0;
4087 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4088 return -EIO;
4089 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4090 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004091 if (status == 0)
4092 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4094 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004095 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096 return status;
4097}
4098
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004099static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4100 struct timespec *time)
4101{
4102 int status = 0;
4103
4104 time->tv_sec = 0;
4105 time->tv_nsec = 0;
4106 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4107 return -EIO;
4108 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4109 status = decode_attr_time(xdr, time);
4110 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4111 }
4112 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4113 (long)time->tv_nsec);
4114 return status;
4115}
4116
David Quigleyaa9c2662013-05-22 12:50:44 -04004117static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4118 struct nfs4_label *label)
4119{
4120 uint32_t pi = 0;
4121 uint32_t lfs = 0;
4122 __u32 len;
4123 __be32 *p;
4124 int status = 0;
4125
4126 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4127 return -EIO;
4128 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4129 p = xdr_inline_decode(xdr, 4);
4130 if (unlikely(!p))
4131 goto out_overflow;
4132 lfs = be32_to_cpup(p++);
4133 p = xdr_inline_decode(xdr, 4);
4134 if (unlikely(!p))
4135 goto out_overflow;
4136 pi = be32_to_cpup(p++);
4137 p = xdr_inline_decode(xdr, 4);
4138 if (unlikely(!p))
4139 goto out_overflow;
4140 len = be32_to_cpup(p++);
4141 p = xdr_inline_decode(xdr, len);
4142 if (unlikely(!p))
4143 goto out_overflow;
4144 if (len < NFS4_MAXLABELLEN) {
4145 if (label) {
4146 memcpy(label->label, p, len);
4147 label->len = len;
4148 label->pi = pi;
4149 label->lfs = lfs;
4150 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4151 }
4152 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4153 } else
4154 printk(KERN_WARNING "%s: label too long (%u)!\n",
4155 __func__, len);
4156 }
4157 if (label && label->label)
4158 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4159 (char *)label->label, label->len, label->pi, label->lfs);
4160 return status;
4161
4162out_overflow:
4163 print_overflow_msg(__func__, xdr);
4164 return -EIO;
4165}
4166
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4168{
4169 int status = 0;
4170
4171 time->tv_sec = 0;
4172 time->tv_nsec = 0;
4173 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4174 return -EIO;
4175 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4176 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004177 if (status == 0)
4178 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4180 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004181 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 return status;
4183}
4184
Trond Myklebust256e48b2012-06-21 11:18:13 -04004185static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186{
4187 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004188 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189
4190 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004191 dprintk("%s: server returned incorrect attribute length: "
4192 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004193 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 attrwords << 2,
4195 (attrwords < nwords) ? '<' : '>',
4196 nwords << 2);
4197 return -EIO;
4198 }
4199 return 0;
4200}
4201
4202static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4203{
Al Viro8687b632006-10-19 23:28:48 -07004204 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205
Benny Halevyc0eae662009-08-14 17:20:14 +03004206 p = xdr_inline_decode(xdr, 20);
4207 if (unlikely(!p))
4208 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004209 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004210 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004211 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004213out_overflow:
4214 print_overflow_msg(__func__, xdr);
4215 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216}
4217
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004218static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219{
Al Viro8687b632006-10-19 23:28:48 -07004220 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221 uint32_t supp, acc;
4222 int status;
4223
4224 status = decode_op_hdr(xdr, OP_ACCESS);
4225 if (status)
4226 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004227 p = xdr_inline_decode(xdr, 8);
4228 if (unlikely(!p))
4229 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004230 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004231 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004232 *supported = supp;
4233 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004235out_overflow:
4236 print_overflow_msg(__func__, xdr);
4237 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238}
4239
Benny Halevy07d30432009-08-14 17:19:52 +03004240static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241{
Al Viro8687b632006-10-19 23:28:48 -07004242 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004243
4244 p = xdr_inline_decode(xdr, len);
4245 if (likely(p)) {
4246 memcpy(buf, p, len);
4247 return 0;
4248 }
4249 print_overflow_msg(__func__, xdr);
4250 return -EIO;
4251}
4252
4253static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4254{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004255 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256}
4257
4258static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4259{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260 int status;
4261
4262 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004263 if (status != -EIO)
4264 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004265 if (!status)
4266 status = decode_stateid(xdr, &res->stateid);
4267 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268}
4269
Benny Halevydb942bb2009-08-14 17:19:56 +03004270static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4271{
Chuck Levercd937102012-03-02 17:14:31 -05004272 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273}
4274
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004275static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4276{
4277 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4278}
4279
Fred Isaman0b7c0152012-04-20 14:47:39 -04004280static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282 int status;
4283
4284 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004285 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004286 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004287 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288}
4289
4290static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4291{
Al Viro8687b632006-10-19 23:28:48 -07004292 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293 uint32_t bmlen;
4294 int status;
4295
4296 status = decode_op_hdr(xdr, OP_CREATE);
4297 if (status)
4298 return status;
4299 if ((status = decode_change_info(xdr, cinfo)))
4300 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004301 p = xdr_inline_decode(xdr, 4);
4302 if (unlikely(!p))
4303 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004304 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004305 p = xdr_inline_decode(xdr, bmlen << 2);
4306 if (likely(p))
4307 return 0;
4308out_overflow:
4309 print_overflow_msg(__func__, xdr);
4310 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311}
4312
4313static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4314{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004315 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004316 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317 int status;
4318
4319 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4320 goto xdr_error;
4321 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4322 goto xdr_error;
4323 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4324 goto xdr_error;
4325 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4326 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004327 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4328 &res->fh_expire_type)) != 0)
4329 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4331 goto xdr_error;
4332 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4333 goto xdr_error;
4334 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4335 goto xdr_error;
4336 status = verify_attr_len(xdr, savep, attrlen);
4337xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004338 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004339 return status;
4340}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004341
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4343{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004344 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004345 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004347
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4349 goto xdr_error;
4350 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4351 goto xdr_error;
4352 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4353 goto xdr_error;
4354
4355 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4356 goto xdr_error;
4357 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4358 goto xdr_error;
4359 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4360 goto xdr_error;
4361 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4362 goto xdr_error;
4363 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4364 goto xdr_error;
4365 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4366 goto xdr_error;
4367
4368 status = verify_attr_len(xdr, savep, attrlen);
4369xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004370 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371 return status;
4372}
4373
4374static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4375{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004376 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004377 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004379
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4381 goto xdr_error;
4382 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4383 goto xdr_error;
4384 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4385 goto xdr_error;
4386
4387 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4388 goto xdr_error;
4389 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4390 goto xdr_error;
4391
4392 status = verify_attr_len(xdr, savep, attrlen);
4393xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004394 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395 return status;
4396}
4397
Andy Adamson88034c32012-05-23 05:02:34 -04004398static int decode_threshold_hint(struct xdr_stream *xdr,
4399 uint32_t *bitmap,
4400 uint64_t *res,
4401 uint32_t hint_bit)
4402{
4403 __be32 *p;
4404
4405 *res = 0;
4406 if (likely(bitmap[0] & hint_bit)) {
4407 p = xdr_inline_decode(xdr, 8);
4408 if (unlikely(!p))
4409 goto out_overflow;
4410 xdr_decode_hyper(p, res);
4411 }
4412 return 0;
4413out_overflow:
4414 print_overflow_msg(__func__, xdr);
4415 return -EIO;
4416}
4417
4418static int decode_first_threshold_item4(struct xdr_stream *xdr,
4419 struct nfs4_threshold *res)
4420{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004421 __be32 *p;
4422 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004423 uint32_t bitmap[3] = {0,}, attrlen;
4424 int status;
4425
4426 /* layout type */
4427 p = xdr_inline_decode(xdr, 4);
4428 if (unlikely(!p)) {
4429 print_overflow_msg(__func__, xdr);
4430 return -EIO;
4431 }
4432 res->l_type = be32_to_cpup(p);
4433
4434 /* thi_hintset bitmap */
4435 status = decode_attr_bitmap(xdr, bitmap);
4436 if (status < 0)
4437 goto xdr_error;
4438
4439 /* thi_hintlist length */
4440 status = decode_attr_length(xdr, &attrlen, &savep);
4441 if (status < 0)
4442 goto xdr_error;
4443 /* thi_hintlist */
4444 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4445 if (status < 0)
4446 goto xdr_error;
4447 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4448 if (status < 0)
4449 goto xdr_error;
4450 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4451 THRESHOLD_RD_IO);
4452 if (status < 0)
4453 goto xdr_error;
4454 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4455 THRESHOLD_WR_IO);
4456 if (status < 0)
4457 goto xdr_error;
4458
4459 status = verify_attr_len(xdr, savep, attrlen);
4460 res->bm = bitmap[0];
4461
4462 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4463 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4464 res->wr_io_sz);
4465xdr_error:
4466 dprintk("%s ret=%d!\n", __func__, status);
4467 return status;
4468}
4469
4470/*
4471 * Thresholds on pNFS direct I/O vrs MDS I/O
4472 */
4473static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4474 uint32_t *bitmap,
4475 struct nfs4_threshold *res)
4476{
4477 __be32 *p;
4478 int status = 0;
4479 uint32_t num;
4480
4481 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4482 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004483 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004484 /* Did the server return an unrequested attribute? */
4485 if (unlikely(res == NULL))
4486 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004487 p = xdr_inline_decode(xdr, 4);
4488 if (unlikely(!p))
4489 goto out_overflow;
4490 num = be32_to_cpup(p);
4491 if (num == 0)
4492 return 0;
4493 if (num > 1)
4494 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4495 "drivers per filesystem not supported\n",
4496 __func__);
4497
4498 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004499 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004500 }
4501 return status;
4502out_overflow:
4503 print_overflow_msg(__func__, xdr);
4504 return -EIO;
4505}
4506
Bryan Schumakerae42c702010-10-21 16:33:17 -04004507static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4508 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004509 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004510 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511{
Trond Myklebustbca79472009-03-11 14:10:26 -04004512 int status;
4513 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004514 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004515 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004517 status = decode_attr_type(xdr, bitmap, &type);
4518 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004520 fattr->mode = 0;
4521 if (status != 0) {
4522 fattr->mode |= nfs_type2fmt[type];
4523 fattr->valid |= status;
4524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004526 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4527 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004529 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004530
4531 status = decode_attr_size(xdr, bitmap, &fattr->size);
4532 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004534 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004535
4536 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
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 Myklebustee7b75f2011-06-16 13:15:41 -04004541 err = 0;
4542 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004543 if (status < 0)
4544 goto xdr_error;
4545
4546 status = decode_attr_filehandle(xdr, bitmap, fh);
4547 if (status < 0)
4548 goto xdr_error;
4549
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004550 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4551 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004552 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004553 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004554
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004555 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004556 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004557 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004558 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004559
4560 status = decode_attr_mode(xdr, bitmap, &fmode);
4561 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004563 if (status != 0) {
4564 fattr->mode |= fmode;
4565 fattr->valid |= status;
4566 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004567
4568 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4569 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004571 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004572
Trond Myklebust6926afd2012-01-07 13:22:46 -05004573 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004574 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004575 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004576 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004577
Trond Myklebust6926afd2012-01-07 13:22:46 -05004578 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004579 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004581 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004582
4583 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4584 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004586 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004587
4588 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4589 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004591 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004592
4593 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4594 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004596 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004597
4598 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4599 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004601 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004602
4603 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4604 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004606 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004607
Trond Myklebust28331a42011-04-27 13:47:52 -04004608 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004609 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004610 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004611 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004612
Andy Adamson88034c32012-05-23 05:02:34 -04004613 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4614 if (status < 0)
4615 goto xdr_error;
4616
David Quigleyaa9c2662013-05-22 12:50:44 -04004617 if (label) {
4618 status = decode_attr_security_label(xdr, bitmap, label);
4619 if (status < 0)
4620 goto xdr_error;
4621 fattr->valid |= status;
4622 }
4623
Bryan Schumakerae42c702010-10-21 16:33:17 -04004624xdr_error:
4625 dprintk("%s: xdr returned %d\n", __func__, -status);
4626 return status;
4627}
4628
4629static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004630 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004631 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004632{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004633 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004634 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004635 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004636 int status;
4637
4638 status = decode_op_hdr(xdr, OP_GETATTR);
4639 if (status < 0)
4640 goto xdr_error;
4641
4642 status = decode_attr_bitmap(xdr, bitmap);
4643 if (status < 0)
4644 goto xdr_error;
4645
4646 status = decode_attr_length(xdr, &attrlen, &savep);
4647 if (status < 0)
4648 goto xdr_error;
4649
David Quigleyaa9c2662013-05-22 12:50:44 -04004650 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4651 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004652 if (status < 0)
4653 goto xdr_error;
4654
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004655 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004657 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658 return status;
4659}
4660
David Quigleyaa9c2662013-05-22 12:50:44 -04004661static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4662 struct nfs4_label *label, const struct nfs_server *server)
4663{
4664 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4665}
4666
Bryan Schumakerae42c702010-10-21 16:33:17 -04004667static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004668 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004669{
David Quigleyaa9c2662013-05-22 12:50:44 -04004670 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004671}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004672
Andy Adamson504913f2010-10-20 00:17:57 -04004673/*
4674 * Decode potentially multiple layout types. Currently we only support
4675 * one layout driver per file system.
4676 */
4677static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4678 uint32_t *layouttype)
4679{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004680 __be32 *p;
Andy Adamson504913f2010-10-20 00:17:57 -04004681 int num;
4682
4683 p = xdr_inline_decode(xdr, 4);
4684 if (unlikely(!p))
4685 goto out_overflow;
4686 num = be32_to_cpup(p);
4687
4688 /* pNFS is not supported by the underlying file system */
4689 if (num == 0) {
4690 *layouttype = 0;
4691 return 0;
4692 }
4693 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004694 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4695 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004696
4697 /* Decode and set first layout type, move xdr->p past unused types */
4698 p = xdr_inline_decode(xdr, num * 4);
4699 if (unlikely(!p))
4700 goto out_overflow;
4701 *layouttype = be32_to_cpup(p);
4702 return 0;
4703out_overflow:
4704 print_overflow_msg(__func__, xdr);
4705 return -EIO;
4706}
4707
4708/*
4709 * The type of file system exported.
4710 * Note we must ensure that layouttype is set in any non-error case.
4711 */
4712static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4713 uint32_t *layouttype)
4714{
4715 int status = 0;
4716
4717 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4718 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4719 return -EIO;
4720 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4721 status = decode_first_pnfs_layout_type(xdr, layouttype);
4722 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4723 } else
4724 *layouttype = 0;
4725 return status;
4726}
4727
Fred Isamandae100c2011-07-30 20:52:37 -04004728/*
4729 * The prefered block size for layout directed io
4730 */
4731static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4732 uint32_t *res)
4733{
4734 __be32 *p;
4735
4736 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4737 *res = 0;
4738 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4739 p = xdr_inline_decode(xdr, 4);
4740 if (unlikely(!p)) {
4741 print_overflow_msg(__func__, xdr);
4742 return -EIO;
4743 }
4744 *res = be32_to_cpup(p);
4745 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4746 }
4747 return 0;
4748}
4749
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4751{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004752 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004753 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 int status;
4755
4756 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4757 goto xdr_error;
4758 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4759 goto xdr_error;
4760 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4761 goto xdr_error;
4762
4763 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4764
4765 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4766 goto xdr_error;
4767 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4768 goto xdr_error;
4769 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4770 goto xdr_error;
4771 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4772 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4773 goto xdr_error;
4774 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004775 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4776 if (status != 0)
4777 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004778 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4779 if (status != 0)
4780 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004781 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4782 if (status)
4783 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784
4785 status = verify_attr_len(xdr, savep, attrlen);
4786xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004787 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788 return status;
4789}
4790
4791static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4792{
Al Viro8687b632006-10-19 23:28:48 -07004793 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794 uint32_t len;
4795 int status;
4796
Trond Myklebust99367812007-07-17 21:52:41 -04004797 /* Zero handle first to allow comparisons */
4798 memset(fh, 0, sizeof(*fh));
4799
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800 status = decode_op_hdr(xdr, OP_GETFH);
4801 if (status)
4802 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803
Benny Halevyc0eae662009-08-14 17:20:14 +03004804 p = xdr_inline_decode(xdr, 4);
4805 if (unlikely(!p))
4806 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004807 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808 if (len > NFS4_FHSIZE)
4809 return -EIO;
4810 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004811 p = xdr_inline_decode(xdr, len);
4812 if (unlikely(!p))
4813 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004814 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004816out_overflow:
4817 print_overflow_msg(__func__, xdr);
4818 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004819}
4820
4821static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4822{
4823 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004824
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825 status = decode_op_hdr(xdr, OP_LINK);
4826 if (status)
4827 return status;
4828 return decode_change_info(xdr, cinfo);
4829}
4830
4831/*
4832 * We create the owner, so we know a proper owner.id length is 4.
4833 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004834static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004836 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004837 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004838 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004839
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004840 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004841 if (unlikely(!p))
4842 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004843 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004844 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004845 type = be32_to_cpup(p++); /* 4 byte read */
4846 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004847 fl->fl_start = (loff_t)offset;
4848 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4849 if (length == ~(uint64_t)0)
4850 fl->fl_end = OFFSET_MAX;
4851 fl->fl_type = F_WRLCK;
4852 if (type & 1)
4853 fl->fl_type = F_RDLCK;
4854 fl->fl_pid = 0;
4855 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004856 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4857 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4858 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004859 if (likely(p))
4860 return -NFS4ERR_DENIED;
4861out_overflow:
4862 print_overflow_msg(__func__, xdr);
4863 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864}
4865
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004866static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868 int status;
4869
4870 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004871 if (status == -EIO)
4872 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004874 status = decode_stateid(xdr, &res->stateid);
4875 if (unlikely(status))
4876 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004877 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004878 status = decode_lock_denied(xdr, NULL);
4879 if (res->open_seqid != NULL)
4880 nfs_increment_open_seqid(status, res->open_seqid);
4881 nfs_increment_lock_seqid(status, res->lock_seqid);
4882out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883 return status;
4884}
4885
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004886static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887{
4888 int status;
4889 status = decode_op_hdr(xdr, OP_LOCKT);
4890 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004891 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004892 return status;
4893}
4894
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004895static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004896{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004897 int status;
4898
4899 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004900 if (status != -EIO)
4901 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004902 if (status == 0)
4903 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904 return status;
4905}
4906
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004907static int decode_release_lockowner(struct xdr_stream *xdr)
4908{
4909 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4910}
4911
Linus Torvalds1da177e2005-04-16 15:20:36 -07004912static int decode_lookup(struct xdr_stream *xdr)
4913{
4914 return decode_op_hdr(xdr, OP_LOOKUP);
4915}
4916
4917/* This is too sick! */
4918static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4919{
Andy Adamson05d564f2008-12-23 16:06:15 -05004920 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921 uint32_t limit_type, nblocks, blocksize;
4922
Benny Halevyc0eae662009-08-14 17:20:14 +03004923 p = xdr_inline_decode(xdr, 12);
4924 if (unlikely(!p))
4925 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004926 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004927 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004928 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004929 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004930 break;
4931 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004932 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004933 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004934 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935 }
4936 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004937out_overflow:
4938 print_overflow_msg(__func__, xdr);
4939 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004940}
4941
4942static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4943{
Andy Adamson05d564f2008-12-23 16:06:15 -05004944 __be32 *p;
4945 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004946 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947
Benny Halevyc0eae662009-08-14 17:20:14 +03004948 p = xdr_inline_decode(xdr, 4);
4949 if (unlikely(!p))
4950 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004951 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4953 res->delegation_type = 0;
4954 return 0;
4955 }
Benny Halevy07d30432009-08-14 17:19:52 +03004956 status = decode_stateid(xdr, &res->delegation);
4957 if (unlikely(status))
4958 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004959 p = xdr_inline_decode(xdr, 4);
4960 if (unlikely(!p))
4961 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004962 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004963
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004965 case NFS4_OPEN_DELEGATE_READ:
4966 res->delegation_type = FMODE_READ;
4967 break;
4968 case NFS4_OPEN_DELEGATE_WRITE:
4969 res->delegation_type = FMODE_WRITE|FMODE_READ;
4970 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971 return -EIO;
4972 }
David Howells7539bba2006-08-22 20:06:09 -04004973 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004974out_overflow:
4975 print_overflow_msg(__func__, xdr);
4976 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977}
4978
4979static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4980{
Andy Adamson05d564f2008-12-23 16:06:15 -05004981 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004982 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004983 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984
Trond Myklebustc7848f62013-12-04 17:39:23 -05004985 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
4986 return status;
4987 nfs_increment_open_seqid(status, res->seqid);
4988 if (status)
4989 return status;
4990 status = decode_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004991 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004992 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993
Andy Adamson05d564f2008-12-23 16:06:15 -05004994 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995
Benny Halevyc0eae662009-08-14 17:20:14 +03004996 p = xdr_inline_decode(xdr, 8);
4997 if (unlikely(!p))
4998 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004999 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005000 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005001 if (bmlen > 10)
5002 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003
Benny Halevyc0eae662009-08-14 17:20:14 +03005004 p = xdr_inline_decode(xdr, bmlen << 2);
5005 if (unlikely(!p))
5006 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005007 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5008 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005009 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005010 for (; i < NFS4_BITMAP_SIZE; i++)
5011 res->attrset[i] = 0;
5012
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013 return decode_delegation(xdr, res);
5014xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005015 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005017out_overflow:
5018 print_overflow_msg(__func__, xdr);
5019 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005020}
5021
5022static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5023{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005024 int status;
5025
Andy Adamson05d564f2008-12-23 16:06:15 -05005026 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005027 if (status != -EIO)
5028 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005029 if (!status)
5030 status = decode_stateid(xdr, &res->stateid);
5031 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032}
5033
5034static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5035{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005036 int status;
5037
5038 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005039 if (status != -EIO)
5040 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005041 if (!status)
5042 status = decode_stateid(xdr, &res->stateid);
5043 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044}
5045
5046static int decode_putfh(struct xdr_stream *xdr)
5047{
5048 return decode_op_hdr(xdr, OP_PUTFH);
5049}
5050
5051static int decode_putrootfh(struct xdr_stream *xdr)
5052{
5053 return decode_op_hdr(xdr, OP_PUTROOTFH);
5054}
5055
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005056static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5057 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058{
Al Viro8687b632006-10-19 23:28:48 -07005059 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005060 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061 int status;
5062
5063 status = decode_op_hdr(xdr, OP_READ);
5064 if (status)
5065 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005066 p = xdr_inline_decode(xdr, 8);
5067 if (unlikely(!p))
5068 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005069 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005070 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005071 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005072 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005073 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074 "count %u > recvd %u\n", count, recvd);
5075 count = recvd;
5076 eof = 0;
5077 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078 res->eof = eof;
5079 res->count = count;
5080 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005081out_overflow:
5082 print_overflow_msg(__func__, xdr);
5083 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084}
5085
5086static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5087{
Chuck Leverbcecff72007-10-26 13:32:03 -04005088 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005089 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005090
5091 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005092 if (!status)
5093 status = decode_verifier(xdr, readdir->verifier.data);
5094 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005095 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005096 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005097 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005098 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005099 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005100}
5101
5102static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5103{
5104 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005105 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005106 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107 int status;
5108
5109 status = decode_op_hdr(xdr, OP_READLINK);
5110 if (status)
5111 return status;
5112
5113 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005114 p = xdr_inline_decode(xdr, 4);
5115 if (unlikely(!p))
5116 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005117 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005118 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005119 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120 return -ENAMETOOLONG;
5121 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005122 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005124 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005125 "count %u > recvd %u\n", len, recvd);
5126 return -EIO;
5127 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128 /*
5129 * The XDR encode routine has set things up so that
5130 * the link text will be copied directly into the
5131 * buffer. We just have to do overflow-checking,
5132 * and and null-terminate the text (the VFS expects
5133 * null-termination).
5134 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005135 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005137out_overflow:
5138 print_overflow_msg(__func__, xdr);
5139 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005140}
5141
5142static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5143{
5144 int status;
5145
5146 status = decode_op_hdr(xdr, OP_REMOVE);
5147 if (status)
5148 goto out;
5149 status = decode_change_info(xdr, cinfo);
5150out:
5151 return status;
5152}
5153
5154static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5155 struct nfs4_change_info *new_cinfo)
5156{
5157 int status;
5158
5159 status = decode_op_hdr(xdr, OP_RENAME);
5160 if (status)
5161 goto out;
5162 if ((status = decode_change_info(xdr, old_cinfo)))
5163 goto out;
5164 status = decode_change_info(xdr, new_cinfo);
5165out:
5166 return status;
5167}
5168
5169static int decode_renew(struct xdr_stream *xdr)
5170{
5171 return decode_op_hdr(xdr, OP_RENEW);
5172}
5173
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005174static int
5175decode_restorefh(struct xdr_stream *xdr)
5176{
5177 return decode_op_hdr(xdr, OP_RESTOREFH);
5178}
5179
J. Bruce Fields029d1052005-06-22 17:16:22 +00005180static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005181 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005182{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005183 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005184 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005185 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005186 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005187 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005188
Andy Adamsonbf118a32011-12-07 11:55:27 -05005189 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005190 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5191 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005192
Trond Myklebust519d3952012-08-14 17:30:10 -04005193 xdr_enter_page(xdr, xdr->buf->page_len);
5194
Trond Myklebustcff298c2012-08-14 17:14:17 -04005195 /* Calculate the offset of the page data */
5196 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005197
J. Bruce Fields029d1052005-06-22 17:16:22 +00005198 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5199 goto out;
5200 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5201 goto out;
5202
5203 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5204 return -EIO;
5205 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005206
Andy Adamsonbf118a32011-12-07 11:55:27 -05005207 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5208 * are stored with the acl data to handle the problem of
5209 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005210 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005211 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005212
5213 /* Check for receive buffer overflow */
5214 if (res->acl_len > (xdr->nwords << 2) ||
5215 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5216 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005217 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005218 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005219 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005220 } else
5221 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005222
5223out:
5224 return status;
5225}
5226
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227static int
5228decode_savefh(struct xdr_stream *xdr)
5229{
5230 return decode_op_hdr(xdr, OP_SAVEFH);
5231}
5232
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005233static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234{
Al Viro8687b632006-10-19 23:28:48 -07005235 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005236 uint32_t bmlen;
5237 int status;
5238
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239 status = decode_op_hdr(xdr, OP_SETATTR);
5240 if (status)
5241 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005242 p = xdr_inline_decode(xdr, 4);
5243 if (unlikely(!p))
5244 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005245 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005246 p = xdr_inline_decode(xdr, bmlen << 2);
5247 if (likely(p))
5248 return 0;
5249out_overflow:
5250 print_overflow_msg(__func__, xdr);
5251 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252}
5253
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005254static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005255{
Al Viro8687b632006-10-19 23:28:48 -07005256 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005257 uint32_t opnum;
5258 int32_t nfserr;
5259
Benny Halevyc0eae662009-08-14 17:20:14 +03005260 p = xdr_inline_decode(xdr, 8);
5261 if (unlikely(!p))
5262 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005263 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005264 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005265 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005266 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005267 return -EIO;
5268 }
Benny Halevycccddf42009-08-14 17:20:19 +03005269 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005270 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005271 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5272 if (unlikely(!p))
5273 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005274 p = xdr_decode_hyper(p, &res->clientid);
5275 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276 } else if (nfserr == NFSERR_CLID_INUSE) {
5277 uint32_t len;
5278
5279 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005280 p = xdr_inline_decode(xdr, 4);
5281 if (unlikely(!p))
5282 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005283 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005284 p = xdr_inline_decode(xdr, len);
5285 if (unlikely(!p))
5286 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005287
5288 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005289 p = xdr_inline_decode(xdr, 4);
5290 if (unlikely(!p))
5291 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005292 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005293 p = xdr_inline_decode(xdr, len);
5294 if (unlikely(!p))
5295 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296 return -NFSERR_CLID_INUSE;
5297 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005298 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299
5300 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005301out_overflow:
5302 print_overflow_msg(__func__, xdr);
5303 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005304}
5305
5306static int decode_setclientid_confirm(struct xdr_stream *xdr)
5307{
5308 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5309}
5310
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005311static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005312{
Al Viro8687b632006-10-19 23:28:48 -07005313 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005314 int status;
5315
5316 status = decode_op_hdr(xdr, OP_WRITE);
5317 if (status)
5318 return status;
5319
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005320 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005321 if (unlikely(!p))
5322 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005323 res->count = be32_to_cpup(p++);
5324 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005325 return decode_write_verifier(xdr, &res->verf->verifier);
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_delegreturn(struct xdr_stream *xdr)
5332{
5333 return decode_op_hdr(xdr, OP_DELEGRETURN);
5334}
5335
Chuck Leverfb15b262013-03-16 15:54:34 -04005336static int decode_secinfo_gss(struct xdr_stream *xdr,
5337 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005338{
Chuck Leverfb15b262013-03-16 15:54:34 -04005339 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005340 __be32 *p;
5341
5342 p = xdr_inline_decode(xdr, 4);
5343 if (unlikely(!p))
5344 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005345 oid_len = be32_to_cpup(p);
5346 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005347 goto out_err;
5348
Chuck Leverfb15b262013-03-16 15:54:34 -04005349 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005350 if (unlikely(!p))
5351 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005352 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5353 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005354
5355 p = xdr_inline_decode(xdr, 8);
5356 if (unlikely(!p))
5357 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005358 flavor->flavor_info.qop = be32_to_cpup(p++);
5359 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005360
5361 return 0;
5362
5363out_overflow:
5364 print_overflow_msg(__func__, xdr);
5365 return -EIO;
5366out_err:
5367 return -EINVAL;
5368}
5369
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005370static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005371{
Chuck Leverfb15b262013-03-16 15:54:34 -04005372 struct nfs4_secinfo4 *sec_flavor;
5373 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005374 int status;
5375 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005376
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005377 p = xdr_inline_decode(xdr, 4);
5378 if (unlikely(!p))
5379 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005380
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005381 res->flavors->num_flavors = 0;
5382 num_flavors = be32_to_cpup(p);
5383
5384 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005385 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005386 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005387 break;
5388
5389 p = xdr_inline_decode(xdr, 4);
5390 if (unlikely(!p))
5391 goto out_overflow;
5392 sec_flavor->flavor = be32_to_cpup(p);
5393
5394 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005395 status = decode_secinfo_gss(xdr, sec_flavor);
5396 if (status)
5397 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005398 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005399 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005400 }
5401
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005402 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005403out:
5404 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005405out_overflow:
5406 print_overflow_msg(__func__, xdr);
5407 return -EIO;
5408}
5409
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005410static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5411{
5412 int status = decode_op_hdr(xdr, OP_SECINFO);
5413 if (status)
5414 return status;
5415 return decode_secinfo_common(xdr, res);
5416}
5417
Benny Halevy99fe60d2009-04-01 09:22:29 -04005418#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005419static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5420{
5421 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5422 if (status)
5423 return status;
5424 return decode_secinfo_common(xdr, res);
5425}
5426
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005427static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5428{
5429 __be32 *p;
5430 uint32_t bitmap_words;
5431 unsigned int i;
5432
5433 p = xdr_inline_decode(xdr, 4);
5434 bitmap_words = be32_to_cpup(p++);
5435 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5436 return -EIO;
5437 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5438 for (i = 0; i < bitmap_words; i++)
5439 op_map->u.words[i] = be32_to_cpup(p++);
5440
5441 return 0;
5442}
5443
Benny Halevy99fe60d2009-04-01 09:22:29 -04005444static int decode_exchange_id(struct xdr_stream *xdr,
5445 struct nfs41_exchange_id_res *res)
5446{
5447 __be32 *p;
5448 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005449 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005450 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005451 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005452
5453 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5454 if (status)
5455 return status;
5456
Benny Halevyc0eae662009-08-14 17:20:14 +03005457 p = xdr_inline_decode(xdr, 8);
5458 if (unlikely(!p))
5459 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005460 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005461 p = xdr_inline_decode(xdr, 12);
5462 if (unlikely(!p))
5463 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005464 res->seqid = be32_to_cpup(p++);
5465 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005466
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005467 res->state_protect.how = be32_to_cpup(p);
5468 switch (res->state_protect.how) {
5469 case SP4_NONE:
5470 break;
5471 case SP4_MACH_CRED:
5472 status = decode_op_map(xdr, &res->state_protect.enforce);
5473 if (status)
5474 return status;
5475 status = decode_op_map(xdr, &res->state_protect.allow);
5476 if (status)
5477 return status;
5478 break;
5479 default:
5480 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005481 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005482 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005483
Chuck Leveracdeb692012-05-21 22:46:16 -04005484 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005485 p = xdr_inline_decode(xdr, 8);
5486 if (unlikely(!p))
5487 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005488 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005489
Chuck Leveracdeb692012-05-21 22:46:16 -04005490 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005491 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5492 if (unlikely(status))
5493 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005494 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5495 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005496 memcpy(res->server_owner->major_id, dummy_str, dummy);
5497 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005498
Chuck Leveracdeb692012-05-21 22:46:16 -04005499 /* server_scope4 */
5500 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5501 if (unlikely(status))
5502 return status;
5503 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5504 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005505 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5506 res->server_scope->server_scope_sz = dummy;
5507
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005508 /* Implementation Id */
5509 p = xdr_inline_decode(xdr, 4);
5510 if (unlikely(!p))
5511 goto out_overflow;
5512 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005513
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005514 if (impl_id_count) {
5515 /* nii_domain */
5516 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5517 if (unlikely(status))
5518 return status;
5519 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5520 return -EIO;
5521 memcpy(res->impl_id->domain, dummy_str, dummy);
5522
5523 /* nii_name */
5524 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5525 if (unlikely(status))
5526 return status;
5527 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5528 return -EIO;
5529 memcpy(res->impl_id->name, dummy_str, dummy);
5530
5531 /* nii_date */
5532 p = xdr_inline_decode(xdr, 12);
5533 if (unlikely(!p))
5534 goto out_overflow;
5535 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5536 res->impl_id->date.nseconds = be32_to_cpup(p);
5537
5538 /* if there's more than one entry, ignore the rest */
5539 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005540 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005541out_overflow:
5542 print_overflow_msg(__func__, xdr);
5543 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005544}
Andy Adamsonfc931582009-04-01 09:22:31 -04005545
5546static int decode_chan_attrs(struct xdr_stream *xdr,
5547 struct nfs4_channel_attrs *attrs)
5548{
5549 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005550 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005551
Benny Halevyc0eae662009-08-14 17:20:14 +03005552 p = xdr_inline_decode(xdr, 28);
5553 if (unlikely(!p))
5554 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005555 val = be32_to_cpup(p++); /* headerpadsz */
5556 if (val)
5557 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005558 attrs->max_rqst_sz = be32_to_cpup(p++);
5559 attrs->max_resp_sz = be32_to_cpup(p++);
5560 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5561 attrs->max_ops = be32_to_cpup(p++);
5562 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005563 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005564 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005565 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5566 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005567 return -EINVAL;
5568 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005569 if (nr_attrs == 1) {
5570 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5571 if (unlikely(!p))
5572 goto out_overflow;
5573 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005574 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005575out_overflow:
5576 print_overflow_msg(__func__, xdr);
5577 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005578}
5579
Benny Halevye78291e2009-08-14 17:20:00 +03005580static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5581{
5582 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005583}
5584
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005585static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5586 struct nfs41_bind_conn_to_session_res *res)
5587{
5588 __be32 *p;
5589 int status;
5590
5591 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5592 if (!status)
5593 status = decode_sessionid(xdr, &res->session->sess_id);
5594 if (unlikely(status))
5595 return status;
5596
5597 /* dir flags, rdma mode bool */
5598 p = xdr_inline_decode(xdr, 8);
5599 if (unlikely(!p))
5600 goto out_overflow;
5601
5602 res->dir = be32_to_cpup(p++);
5603 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5604 return -EIO;
5605 if (be32_to_cpup(p) == 0)
5606 res->use_conn_in_rdma_mode = false;
5607 else
5608 res->use_conn_in_rdma_mode = true;
5609
5610 return 0;
5611out_overflow:
5612 print_overflow_msg(__func__, xdr);
5613 return -EIO;
5614}
5615
Andy Adamsonfc931582009-04-01 09:22:31 -04005616static int decode_create_session(struct xdr_stream *xdr,
5617 struct nfs41_create_session_res *res)
5618{
5619 __be32 *p;
5620 int status;
5621 struct nfs_client *clp = res->client;
5622 struct nfs4_session *session = clp->cl_session;
5623
5624 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005625 if (!status)
5626 status = decode_sessionid(xdr, &session->sess_id);
5627 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005628 return status;
5629
Andy Adamsonfc931582009-04-01 09:22:31 -04005630 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005631 p = xdr_inline_decode(xdr, 8);
5632 if (unlikely(!p))
5633 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005634 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005635 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005636
5637 /* Channel attributes */
5638 status = decode_chan_attrs(xdr, &session->fc_attrs);
5639 if (!status)
5640 status = decode_chan_attrs(xdr, &session->bc_attrs);
5641 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005642out_overflow:
5643 print_overflow_msg(__func__, xdr);
5644 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005645}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005646
5647static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5648{
5649 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5650}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005651
Trond Myklebust66245532012-05-25 17:18:09 -04005652static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5653{
5654 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5655}
5656
Ricardo Labiaga180197532009-12-05 16:08:40 -05005657static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5658{
5659 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5660}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005661#endif /* CONFIG_NFS_V4_1 */
5662
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005663static int decode_sequence(struct xdr_stream *xdr,
5664 struct nfs4_sequence_res *res,
5665 struct rpc_rqst *rqstp)
5666{
5667#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005668 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005669 struct nfs4_sessionid id;
5670 u32 dummy;
5671 int status;
5672 __be32 *p;
5673
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005674 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005675 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005676 if (!res->sr_slot->table->session)
5677 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005678
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005679 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005680 if (!status)
5681 status = decode_sessionid(xdr, &id);
5682 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005683 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005684
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005685 /*
5686 * If the server returns different values for sessionID, slotID or
5687 * sequence number, the server is looney tunes.
5688 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005689 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005690 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005691
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005692 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005693 NFS4_MAX_SESSIONID_LEN)) {
5694 dprintk("%s Invalid session id\n", __func__);
5695 goto out_err;
5696 }
Benny Halevye78291e2009-08-14 17:20:00 +03005697
Benny Halevyc0eae662009-08-14 17:20:14 +03005698 p = xdr_inline_decode(xdr, 20);
5699 if (unlikely(!p))
5700 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005701
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005702 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005703 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005704 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005705 dprintk("%s Invalid sequence number\n", __func__);
5706 goto out_err;
5707 }
5708 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005709 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005710 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005711 dprintk("%s Invalid slot id\n", __func__);
5712 goto out_err;
5713 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005714 /* highest slot id */
5715 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005716 /* target highest slot id */
5717 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005718 /* result flags */
5719 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005720 status = 0;
5721out_err:
5722 res->sr_status = status;
5723 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005724out_overflow:
5725 print_overflow_msg(__func__, xdr);
5726 status = -EIO;
5727 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005728#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005729 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005730#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005731}
5732
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005733#if defined(CONFIG_NFS_V4_1)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005734static int decode_getdeviceinfo(struct xdr_stream *xdr,
5735 struct pnfs_device *pdev)
5736{
5737 __be32 *p;
5738 uint32_t len, type;
5739 int status;
5740
5741 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5742 if (status) {
5743 if (status == -ETOOSMALL) {
5744 p = xdr_inline_decode(xdr, 4);
5745 if (unlikely(!p))
5746 goto out_overflow;
5747 pdev->mincount = be32_to_cpup(p);
5748 dprintk("%s: Min count too small. mincnt = %u\n",
5749 __func__, pdev->mincount);
5750 }
5751 return status;
5752 }
5753
5754 p = xdr_inline_decode(xdr, 8);
5755 if (unlikely(!p))
5756 goto out_overflow;
5757 type = be32_to_cpup(p++);
5758 if (type != pdev->layout_type) {
5759 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5760 __func__, pdev->layout_type, type);
5761 return -EINVAL;
5762 }
5763 /*
5764 * Get the length of the opaque device_addr4. xdr_read_pages places
5765 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5766 * and places the remaining xdr data in xdr_buf->tail
5767 */
5768 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005769 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5770 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005771
5772 /* Parse notification bitmap, verifying that it is zero. */
5773 p = xdr_inline_decode(xdr, 4);
5774 if (unlikely(!p))
5775 goto out_overflow;
5776 len = be32_to_cpup(p);
5777 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005778 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005779
5780 p = xdr_inline_decode(xdr, 4 * len);
5781 if (unlikely(!p))
5782 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005783
5784 if (be32_to_cpup(p++) &
5785 ~(NOTIFY_DEVICEID4_CHANGE | NOTIFY_DEVICEID4_DELETE)) {
5786 dprintk("%s: unsupported notification\n",
5787 __func__);
5788 }
5789
5790 for (i = 1; i < len; i++) {
5791 if (be32_to_cpup(p++)) {
5792 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005793 __func__);
5794 return -EIO;
5795 }
5796 }
5797 }
5798 return 0;
5799out_overflow:
5800 print_overflow_msg(__func__, xdr);
5801 return -EIO;
5802}
5803
5804static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5805 struct nfs4_layoutget_res *res)
5806{
5807 __be32 *p;
5808 int status;
5809 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005810 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005811
5812 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5813 if (status)
5814 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005815 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005816 if (unlikely(!p))
5817 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005818 res->return_on_close = be32_to_cpup(p);
5819 decode_stateid(xdr, &res->stateid);
5820 p = xdr_inline_decode(xdr, 4);
5821 if (unlikely(!p))
5822 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005823 layout_count = be32_to_cpup(p);
5824 if (!layout_count) {
5825 dprintk("%s: server responded with empty layout array\n",
5826 __func__);
5827 return -EINVAL;
5828 }
5829
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005830 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005831 if (unlikely(!p))
5832 goto out_overflow;
5833 p = xdr_decode_hyper(p, &res->range.offset);
5834 p = xdr_decode_hyper(p, &res->range.length);
5835 res->range.iomode = be32_to_cpup(p++);
5836 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005837 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005838
5839 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5840 __func__,
5841 (unsigned long)res->range.offset,
5842 (unsigned long)res->range.length,
5843 res->range.iomode,
5844 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005845 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005846
Trond Myklebust64bd5772012-06-20 22:35:05 -04005847 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005848 if (res->layoutp->len > recvd) {
5849 dprintk("NFS: server cheating in layoutget reply: "
5850 "layout len %u > recvd %u\n",
5851 res->layoutp->len, recvd);
5852 return -EINVAL;
5853 }
5854
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005855 if (layout_count > 1) {
5856 /* We only handle a length one array at the moment. Any
5857 * further entries are just ignored. Note that this means
5858 * the client may see a response that is less than the
5859 * minimum it requested.
5860 */
5861 dprintk("%s: server responded with %d layouts, dropping tail\n",
5862 __func__, layout_count);
5863 }
5864
5865 return 0;
5866out_overflow:
5867 print_overflow_msg(__func__, xdr);
5868 return -EIO;
5869}
Andy Adamson863a3c62011-03-23 13:27:54 +00005870
Benny Halevycbe82602011-05-22 19:52:37 +03005871static int decode_layoutreturn(struct xdr_stream *xdr,
5872 struct nfs4_layoutreturn_res *res)
5873{
5874 __be32 *p;
5875 int status;
5876
5877 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5878 if (status)
5879 return status;
5880 p = xdr_inline_decode(xdr, 4);
5881 if (unlikely(!p))
5882 goto out_overflow;
5883 res->lrs_present = be32_to_cpup(p);
5884 if (res->lrs_present)
5885 status = decode_stateid(xdr, &res->stateid);
5886 return status;
5887out_overflow:
5888 print_overflow_msg(__func__, xdr);
5889 return -EIO;
5890}
5891
Andy Adamson863a3c62011-03-23 13:27:54 +00005892static int decode_layoutcommit(struct xdr_stream *xdr,
5893 struct rpc_rqst *req,
5894 struct nfs4_layoutcommit_res *res)
5895{
5896 __be32 *p;
5897 __u32 sizechanged;
5898 int status;
5899
5900 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005901 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005902 if (status)
5903 return status;
5904
5905 p = xdr_inline_decode(xdr, 4);
5906 if (unlikely(!p))
5907 goto out_overflow;
5908 sizechanged = be32_to_cpup(p);
5909
5910 if (sizechanged) {
5911 /* throw away new size */
5912 p = xdr_inline_decode(xdr, 8);
5913 if (unlikely(!p))
5914 goto out_overflow;
5915 }
5916 return 0;
5917out_overflow:
5918 print_overflow_msg(__func__, xdr);
5919 return -EIO;
5920}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005921
5922static int decode_test_stateid(struct xdr_stream *xdr,
5923 struct nfs41_test_stateid_res *res)
5924{
5925 __be32 *p;
5926 int status;
5927 int num_res;
5928
5929 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5930 if (status)
5931 return status;
5932
5933 p = xdr_inline_decode(xdr, 4);
5934 if (unlikely(!p))
5935 goto out_overflow;
5936 num_res = be32_to_cpup(p++);
5937 if (num_res != 1)
5938 goto out;
5939
5940 p = xdr_inline_decode(xdr, 4);
5941 if (unlikely(!p))
5942 goto out_overflow;
5943 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005944
5945 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005946out_overflow:
5947 print_overflow_msg(__func__, xdr);
5948out:
5949 return -EIO;
5950}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005951
5952static int decode_free_stateid(struct xdr_stream *xdr,
5953 struct nfs41_free_stateid_res *res)
5954{
Andy Adamson9f79fb42013-09-10 12:56:29 -04005955 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005956 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005957}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005958#endif /* CONFIG_NFS_V4_1 */
5959
Linus Torvalds1da177e2005-04-16 15:20:36 -07005960/*
Benny Halevy49c25592008-12-23 16:06:16 -05005961 * END OF "GENERIC" DECODE ROUTINES.
5962 */
5963
5964/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005965 * Decode OPEN_DOWNGRADE response
5966 */
Chuck Leverbf269552010-12-14 14:59:29 +00005967static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5968 struct xdr_stream *xdr,
5969 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970{
Andy Adamson05d564f2008-12-23 16:06:15 -05005971 struct compound_hdr hdr;
5972 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005973
Chuck Leverbf269552010-12-14 14:59:29 +00005974 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005975 if (status)
5976 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005977 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005978 if (status)
5979 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005980 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005981 if (status)
5982 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005983 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005984 if (status != 0)
5985 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005986 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005987out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005988 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005989}
5990
5991/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005992 * Decode ACCESS response
5993 */
Chuck Leverbf269552010-12-14 14:59:29 +00005994static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5995 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005996{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997 struct compound_hdr hdr;
5998 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005999
Chuck Leverbf269552010-12-14 14:59:29 +00006000 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006001 if (status)
6002 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006003 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006004 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006005 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006006 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006007 if (status != 0)
6008 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006009 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006010 if (status != 0)
6011 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006012 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013out:
6014 return status;
6015}
6016
6017/*
6018 * Decode LOOKUP response
6019 */
Chuck Leverbf269552010-12-14 14:59:29 +00006020static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6021 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006022{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006023 struct compound_hdr hdr;
6024 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006025
Chuck Leverbf269552010-12-14 14:59:29 +00006026 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006027 if (status)
6028 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006029 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006030 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006031 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006032 status = decode_putfh(xdr);
6033 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006034 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006035 status = decode_lookup(xdr);
6036 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006037 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006038 status = decode_getfh(xdr, res->fh);
6039 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006040 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006041 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006042out:
6043 return status;
6044}
6045
6046/*
6047 * Decode LOOKUP_ROOT response
6048 */
Chuck Leverbf269552010-12-14 14:59:29 +00006049static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6050 struct xdr_stream *xdr,
6051 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006052{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006053 struct compound_hdr hdr;
6054 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006055
Chuck Leverbf269552010-12-14 14:59:29 +00006056 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006057 if (status)
6058 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006059 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006060 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006062 status = decode_putrootfh(xdr);
6063 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006064 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006065 status = decode_getfh(xdr, res->fh);
6066 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006067 status = decode_getfattr_label(xdr, res->fattr,
6068 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006069out:
6070 return status;
6071}
6072
6073/*
6074 * Decode REMOVE response
6075 */
Chuck Leverbf269552010-12-14 14:59:29 +00006076static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6077 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006079 struct compound_hdr hdr;
6080 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006081
Chuck Leverbf269552010-12-14 14:59:29 +00006082 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006083 if (status)
6084 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006085 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006086 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006087 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006088 status = decode_putfh(xdr);
6089 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006090 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006091 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092out:
6093 return status;
6094}
6095
6096/*
6097 * Decode RENAME response
6098 */
Chuck Leverbf269552010-12-14 14:59:29 +00006099static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6100 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006102 struct compound_hdr hdr;
6103 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006104
Chuck Leverbf269552010-12-14 14:59:29 +00006105 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006106 if (status)
6107 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006108 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006109 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006110 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006111 status = decode_putfh(xdr);
6112 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006114 status = decode_savefh(xdr);
6115 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006116 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006117 status = decode_putfh(xdr);
6118 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006119 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006120 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006121out:
6122 return status;
6123}
6124
6125/*
6126 * Decode LINK response
6127 */
Chuck Leverbf269552010-12-14 14:59:29 +00006128static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6129 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006130{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006131 struct compound_hdr hdr;
6132 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006133
Chuck Leverbf269552010-12-14 14:59:29 +00006134 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006135 if (status)
6136 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006137 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006138 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006139 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006140 status = decode_putfh(xdr);
6141 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006142 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006143 status = decode_savefh(xdr);
6144 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006145 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006146 status = decode_putfh(xdr);
6147 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006148 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006149 status = decode_link(xdr, &res->cinfo);
6150 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006151 goto out;
6152 /*
6153 * Note order: OP_LINK leaves the directory as the current
6154 * filehandle.
6155 */
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_restorefh(xdr);
6157 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006158 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006159 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160out:
6161 return status;
6162}
6163
6164/*
6165 * Decode CREATE response
6166 */
Chuck Leverbf269552010-12-14 14:59:29 +00006167static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6168 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170 struct compound_hdr hdr;
6171 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006172
Chuck Leverbf269552010-12-14 14:59:29 +00006173 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006174 if (status)
6175 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006176 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006177 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006178 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006179 status = decode_putfh(xdr);
6180 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006182 status = decode_create(xdr, &res->dir_cinfo);
6183 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006184 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006185 status = decode_getfh(xdr, res->fh);
6186 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006188 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189out:
6190 return status;
6191}
6192
6193/*
6194 * Decode SYMLINK response
6195 */
Chuck Leverbf269552010-12-14 14:59:29 +00006196static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6197 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198{
Chuck Leverbf269552010-12-14 14:59:29 +00006199 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200}
6201
6202/*
6203 * Decode GETATTR response
6204 */
Chuck Leverbf269552010-12-14 14:59:29 +00006205static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6206 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208 struct compound_hdr hdr;
6209 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006210
Chuck Leverbf269552010-12-14 14:59:29 +00006211 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006212 if (status)
6213 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006214 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006215 if (status)
6216 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006217 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218 if (status)
6219 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006220 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221out:
6222 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006223}
6224
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006225/*
6226 * Encode an SETACL request
6227 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006228static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6229 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006230{
Andy Adamson05d564f2008-12-23 16:06:15 -05006231 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006232 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006233 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006234
Chuck Lever9f06c712010-12-14 14:59:18 +00006235 encode_compound_hdr(xdr, req, &hdr);
6236 encode_sequence(xdr, &args->seq_args, &hdr);
6237 encode_putfh(xdr, args->fh, &hdr);
6238 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006239 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006240}
Andy Adamson05d564f2008-12-23 16:06:15 -05006241
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006242/*
6243 * Decode SETACL response
6244 */
6245static int
Chuck Leverbf269552010-12-14 14:59:29 +00006246nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006247 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006248{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006249 struct compound_hdr hdr;
6250 int status;
6251
Chuck Leverbf269552010-12-14 14:59:29 +00006252 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006253 if (status)
6254 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006256 if (status)
6257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006258 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006259 if (status)
6260 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006261 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006262out:
6263 return status;
6264}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006265
6266/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006267 * Decode GETACL response
6268 */
6269static int
Chuck Leverbf269552010-12-14 14:59:29 +00006270nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006271 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006272{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006273 struct compound_hdr hdr;
6274 int status;
6275
Trond Myklebust331818f2012-02-03 18:30:53 -05006276 if (res->acl_scratch != NULL) {
6277 void *p = page_address(res->acl_scratch);
6278 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6279 }
Chuck Leverbf269552010-12-14 14:59:29 +00006280 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006281 if (status)
6282 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006283 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006284 if (status)
6285 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006286 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006287 if (status)
6288 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006289 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006290
6291out:
6292 return status;
6293}
6294
6295/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006296 * Decode CLOSE response
6297 */
Chuck Leverbf269552010-12-14 14:59:29 +00006298static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6299 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006300{
Andy Adamson05d564f2008-12-23 16:06:15 -05006301 struct compound_hdr hdr;
6302 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006303
Chuck Leverbf269552010-12-14 14:59:29 +00006304 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006305 if (status)
6306 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006307 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006308 if (status)
6309 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006311 if (status)
6312 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006313 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006314 if (status != 0)
6315 goto out;
6316 /*
6317 * Note: Server may do delete on close for this file
6318 * in which case the getattr call will fail with
6319 * an ESTALE error. Shouldn't be a problem,
6320 * though, since fattr->valid will remain unset.
6321 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006322 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006324 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325}
6326
6327/*
6328 * Decode OPEN response
6329 */
Chuck Leverbf269552010-12-14 14:59:29 +00006330static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6331 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332{
Andy Adamson05d564f2008-12-23 16:06:15 -05006333 struct compound_hdr hdr;
6334 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335
Chuck Leverbf269552010-12-14 14:59:29 +00006336 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006337 if (status)
6338 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006339 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006340 if (status)
6341 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006342 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006343 if (status)
6344 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006345 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006346 if (status)
6347 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006348 status = decode_getfh(xdr, &res->fh);
6349 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006351 if (res->access_request)
6352 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006353 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006355 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006356}
6357
6358/*
6359 * Decode OPEN_CONFIRM response
6360 */
Chuck Leverbf269552010-12-14 14:59:29 +00006361static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6362 struct xdr_stream *xdr,
6363 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364{
Andy Adamson05d564f2008-12-23 16:06:15 -05006365 struct compound_hdr hdr;
6366 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006367
Chuck Leverbf269552010-12-14 14:59:29 +00006368 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006369 if (status)
6370 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006371 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006372 if (status)
6373 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006374 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006375out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006376 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377}
6378
6379/*
6380 * Decode OPEN response
6381 */
Chuck Leverbf269552010-12-14 14:59:29 +00006382static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6383 struct xdr_stream *xdr,
6384 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006385{
Andy Adamson05d564f2008-12-23 16:06:15 -05006386 struct compound_hdr hdr;
6387 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006388
Chuck Leverbf269552010-12-14 14:59:29 +00006389 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006390 if (status)
6391 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006392 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006393 if (status)
6394 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006395 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006396 if (status)
6397 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006398 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006399 if (status)
6400 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006401 if (res->access_request)
6402 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006403 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006404out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006405 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006406}
6407
6408/*
6409 * Decode SETATTR response
6410 */
Chuck Leverbf269552010-12-14 14:59:29 +00006411static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6412 struct xdr_stream *xdr,
6413 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006414{
Andy Adamson05d564f2008-12-23 16:06:15 -05006415 struct compound_hdr hdr;
6416 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006417
Chuck Leverbf269552010-12-14 14:59:29 +00006418 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006419 if (status)
6420 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006421 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006422 if (status)
6423 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006424 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006425 if (status)
6426 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006427 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006428 if (status)
6429 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006430 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006432 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006433}
6434
6435/*
6436 * Decode LOCK response
6437 */
Chuck Leverbf269552010-12-14 14:59:29 +00006438static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6439 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006441 struct compound_hdr hdr;
6442 int status;
6443
Chuck Leverbf269552010-12-14 14:59:29 +00006444 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006445 if (status)
6446 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006447 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006448 if (status)
6449 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006450 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006451 if (status)
6452 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006453 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454out:
6455 return status;
6456}
6457
6458/*
6459 * Decode LOCKT response
6460 */
Chuck Leverbf269552010-12-14 14:59:29 +00006461static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6462 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006463{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464 struct compound_hdr hdr;
6465 int status;
6466
Chuck Leverbf269552010-12-14 14:59:29 +00006467 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006468 if (status)
6469 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006470 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006471 if (status)
6472 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006473 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006474 if (status)
6475 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006476 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006477out:
6478 return status;
6479}
6480
6481/*
6482 * Decode LOCKU response
6483 */
Chuck Leverbf269552010-12-14 14:59:29 +00006484static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6485 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006486{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006487 struct compound_hdr hdr;
6488 int status;
6489
Chuck Leverbf269552010-12-14 14:59:29 +00006490 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491 if (status)
6492 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006493 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006494 if (status)
6495 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006496 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497 if (status)
6498 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006499 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006500out:
6501 return status;
6502}
6503
Chuck Leverbf269552010-12-14 14:59:29 +00006504static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6505 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006506{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006507 struct compound_hdr hdr;
6508 int status;
6509
Chuck Leverbf269552010-12-14 14:59:29 +00006510 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006511 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006512 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006513 return status;
6514}
6515
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516/*
6517 * Decode READLINK response
6518 */
Chuck Leverbf269552010-12-14 14:59:29 +00006519static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6520 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006521 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006522{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006523 struct compound_hdr hdr;
6524 int status;
6525
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527 if (status)
6528 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006529 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006530 if (status)
6531 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006532 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006533 if (status)
6534 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006535 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536out:
6537 return status;
6538}
6539
6540/*
6541 * Decode READDIR response
6542 */
Chuck Leverbf269552010-12-14 14:59:29 +00006543static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6544 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006546 struct compound_hdr hdr;
6547 int status;
6548
Chuck Leverbf269552010-12-14 14:59:29 +00006549 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550 if (status)
6551 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006552 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006553 if (status)
6554 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006555 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556 if (status)
6557 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559out:
6560 return status;
6561}
6562
6563/*
6564 * Decode Read response
6565 */
Chuck Leverbf269552010-12-14 14:59:29 +00006566static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006567 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006568{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006569 struct compound_hdr hdr;
6570 int status;
6571
Chuck Leverbf269552010-12-14 14:59:29 +00006572 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006573 if (status)
6574 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006575 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006576 if (status)
6577 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006578 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006579 if (status)
6580 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006581 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006582 if (!status)
6583 status = res->count;
6584out:
6585 return status;
6586}
6587
6588/*
6589 * Decode WRITE response
6590 */
Chuck Leverbf269552010-12-14 14:59:29 +00006591static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006592 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006594 struct compound_hdr hdr;
6595 int status;
6596
Chuck Leverbf269552010-12-14 14:59:29 +00006597 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006598 if (status)
6599 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006600 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006601 if (status)
6602 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006603 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006604 if (status)
6605 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006606 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006607 if (status)
6608 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006609 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006610 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006611 if (!status)
6612 status = res->count;
6613out:
6614 return status;
6615}
6616
6617/*
6618 * Decode COMMIT response
6619 */
Chuck Leverbf269552010-12-14 14:59:29 +00006620static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006621 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006623 struct compound_hdr hdr;
6624 int status;
6625
Chuck Leverbf269552010-12-14 14:59:29 +00006626 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006627 if (status)
6628 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006629 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006630 if (status)
6631 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006632 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633 if (status)
6634 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006635 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636out:
6637 return status;
6638}
6639
6640/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006641 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006642 */
Chuck Leverbf269552010-12-14 14:59:29 +00006643static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006644 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006645{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006646 struct compound_hdr hdr;
6647 int status;
6648
Chuck Leverbf269552010-12-14 14:59:29 +00006649 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006651 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006652 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006653 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006654 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006655 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006656 return status;
6657}
6658
6659/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006660 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006661 */
Chuck Leverbf269552010-12-14 14:59:29 +00006662static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006663 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006664{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006665 struct compound_hdr hdr;
6666 int status;
6667
Chuck Leverbf269552010-12-14 14:59:29 +00006668 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006669 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006670 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006671 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006672 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006673 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006674 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006675 return status;
6676}
6677
6678/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006679 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006680 */
Chuck Leverbf269552010-12-14 14:59:29 +00006681static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006682 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006683{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006684 struct compound_hdr hdr;
6685 int status;
6686
Chuck Leverbf269552010-12-14 14:59:29 +00006687 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006688 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006689 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006690 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006691 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006692 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006693 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006694 return status;
6695}
6696
6697/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006698 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699 */
Chuck Leverbf269552010-12-14 14:59:29 +00006700static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6701 struct xdr_stream *xdr,
6702 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006703{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006704 struct compound_hdr hdr;
6705 int status;
6706
Chuck Leverbf269552010-12-14 14:59:29 +00006707 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006708 if (status)
6709 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006710 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006711 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006713 status = decode_putfh(xdr);
6714 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006715 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006716 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006717out:
6718 return status;
6719}
6720
6721/*
6722 * Decode RENEW response
6723 */
Chuck Leverbf269552010-12-14 14:59:29 +00006724static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6725 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006726{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006727 struct compound_hdr hdr;
6728 int status;
6729
Chuck Leverbf269552010-12-14 14:59:29 +00006730 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006731 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006732 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006733 return status;
6734}
6735
6736/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006737 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006738 */
Chuck Leverbf269552010-12-14 14:59:29 +00006739static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6740 struct xdr_stream *xdr,
6741 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006742{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006743 struct compound_hdr hdr;
6744 int status;
6745
Chuck Leverbf269552010-12-14 14:59:29 +00006746 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006747 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006748 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749 return status;
6750}
6751
6752/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006753 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006754 */
Chuck Leverbf269552010-12-14 14:59:29 +00006755static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006756 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006758 struct compound_hdr hdr;
6759 int status;
6760
Chuck Leverbf269552010-12-14 14:59:29 +00006761 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006762 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006763 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006764 return status;
6765}
6766
6767/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006768 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006769 */
Chuck Leverbf269552010-12-14 14:59:29 +00006770static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6771 struct xdr_stream *xdr,
6772 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006773{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006774 struct compound_hdr hdr;
6775 int status;
6776
Chuck Leverbf269552010-12-14 14:59:29 +00006777 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006778 if (status)
6779 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006780 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006781 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006782 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006783 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006784 if (status != 0)
6785 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006786 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006787 if (status != 0)
6788 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006789 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006790out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006791 return status;
6792}
6793
Trond Myklebust683b57b2006-06-09 09:34:22 -04006794/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006795 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006796 */
Chuck Leverbf269552010-12-14 14:59:29 +00006797static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6798 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006799 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006800{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006801 struct compound_hdr hdr;
6802 int status;
6803
Chuck Leverbf269552010-12-14 14:59:29 +00006804 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006805 if (status)
6806 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006807 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006808 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006809 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006810 status = decode_putfh(xdr);
6811 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006812 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006813 if (res->migration) {
6814 xdr_enter_page(xdr, PAGE_SIZE);
6815 status = decode_getfattr_generic(xdr,
6816 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006817 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006818 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006819 if (status)
6820 goto out;
6821 if (res->renew)
6822 status = decode_renew(xdr);
6823 } else {
6824 status = decode_lookup(xdr);
6825 if (status)
6826 goto out;
6827 xdr_enter_page(xdr, PAGE_SIZE);
6828 status = decode_getfattr_generic(xdr,
6829 &res->fs_locations->fattr,
6830 NULL, res->fs_locations,
6831 NULL, res->fs_locations->server);
6832 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006833out:
6834 return status;
6835}
6836
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006837/*
6838 * Decode SECINFO response
6839 */
6840static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6841 struct xdr_stream *xdr,
6842 struct nfs4_secinfo_res *res)
6843{
6844 struct compound_hdr hdr;
6845 int status;
6846
6847 status = decode_compound_hdr(xdr, &hdr);
6848 if (status)
6849 goto out;
6850 status = decode_sequence(xdr, &res->seq_res, rqstp);
6851 if (status)
6852 goto out;
6853 status = decode_putfh(xdr);
6854 if (status)
6855 goto out;
6856 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006857out:
6858 return status;
6859}
6860
Chuck Lever44c99932013-10-17 14:13:30 -04006861/*
6862 * Decode FSID_PRESENT response
6863 */
6864static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6865 struct xdr_stream *xdr,
6866 struct nfs4_fsid_present_res *res)
6867{
6868 struct compound_hdr hdr;
6869 int status;
6870
6871 status = decode_compound_hdr(xdr, &hdr);
6872 if (status)
6873 goto out;
6874 status = decode_sequence(xdr, &res->seq_res, rqstp);
6875 if (status)
6876 goto out;
6877 status = decode_putfh(xdr);
6878 if (status)
6879 goto out;
6880 status = decode_getfh(xdr, res->fh);
6881 if (status)
6882 goto out;
6883 if (res->renew)
6884 status = decode_renew(xdr);
6885out:
6886 return status;
6887}
6888
Benny Halevy99fe60d2009-04-01 09:22:29 -04006889#if defined(CONFIG_NFS_V4_1)
6890/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006891 * Decode BIND_CONN_TO_SESSION response
6892 */
6893static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6894 struct xdr_stream *xdr,
6895 void *res)
6896{
6897 struct compound_hdr hdr;
6898 int status;
6899
6900 status = decode_compound_hdr(xdr, &hdr);
6901 if (!status)
6902 status = decode_bind_conn_to_session(xdr, res);
6903 return status;
6904}
6905
6906/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006907 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006908 */
Chuck Leverbf269552010-12-14 14:59:29 +00006909static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6910 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006911 void *res)
6912{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006913 struct compound_hdr hdr;
6914 int status;
6915
Chuck Leverbf269552010-12-14 14:59:29 +00006916 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006917 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006918 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006919 return status;
6920}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006921
6922/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006923 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006924 */
Chuck Leverbf269552010-12-14 14:59:29 +00006925static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6926 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006927 struct nfs41_create_session_res *res)
6928{
Andy Adamsonfc931582009-04-01 09:22:31 -04006929 struct compound_hdr hdr;
6930 int status;
6931
Chuck Leverbf269552010-12-14 14:59:29 +00006932 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006933 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006934 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006935 return status;
6936}
6937
6938/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006939 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006940 */
Chuck Leverbf269552010-12-14 14:59:29 +00006941static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6942 struct xdr_stream *xdr,
6943 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006944{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006945 struct compound_hdr hdr;
6946 int status;
6947
Chuck Leverbf269552010-12-14 14:59:29 +00006948 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006949 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006950 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006951 return status;
6952}
6953
6954/*
Trond Myklebust66245532012-05-25 17:18:09 -04006955 * Decode DESTROY_CLIENTID response
6956 */
6957static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6958 struct xdr_stream *xdr,
6959 void *res)
6960{
6961 struct compound_hdr hdr;
6962 int status;
6963
6964 status = decode_compound_hdr(xdr, &hdr);
6965 if (!status)
6966 status = decode_destroy_clientid(xdr, res);
6967 return status;
6968}
6969
6970/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006971 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006972 */
Chuck Leverbf269552010-12-14 14:59:29 +00006973static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6974 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006975 struct nfs4_sequence_res *res)
6976{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006977 struct compound_hdr hdr;
6978 int status;
6979
Chuck Leverbf269552010-12-14 14:59:29 +00006980 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006981 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006982 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006983 return status;
6984}
6985
6986/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006987 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006988 */
Chuck Leverbf269552010-12-14 14:59:29 +00006989static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6990 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006991 struct nfs4_get_lease_time_res *res)
6992{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006993 struct compound_hdr hdr;
6994 int status;
6995
Chuck Leverbf269552010-12-14 14:59:29 +00006996 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006997 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006998 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006999 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007000 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007001 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007002 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007003 return status;
7004}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007005
7006/*
7007 * Decode RECLAIM_COMPLETE response
7008 */
Chuck Leverbf269552010-12-14 14:59:29 +00007009static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7010 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007011 struct nfs41_reclaim_complete_res *res)
7012{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007013 struct compound_hdr hdr;
7014 int status;
7015
Chuck Leverbf269552010-12-14 14:59:29 +00007016 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007017 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007018 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007019 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307020 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007021 return status;
7022}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007023
7024/*
7025 * Decode GETDEVINFO response
7026 */
Chuck Leverbf269552010-12-14 14:59:29 +00007027static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7028 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007029 struct nfs4_getdeviceinfo_res *res)
7030{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007031 struct compound_hdr hdr;
7032 int status;
7033
Chuck Leverbf269552010-12-14 14:59:29 +00007034 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007035 if (status != 0)
7036 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007037 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007038 if (status != 0)
7039 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007040 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007041out:
7042 return status;
7043}
7044
7045/*
7046 * Decode LAYOUTGET response
7047 */
Chuck Leverbf269552010-12-14 14:59:29 +00007048static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7049 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007050 struct nfs4_layoutget_res *res)
7051{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007052 struct compound_hdr hdr;
7053 int status;
7054
Chuck Leverbf269552010-12-14 14:59:29 +00007055 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007056 if (status)
7057 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007058 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007059 if (status)
7060 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007061 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007062 if (status)
7063 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007064 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007065out:
7066 return status;
7067}
Andy Adamson863a3c62011-03-23 13:27:54 +00007068
7069/*
Benny Halevycbe82602011-05-22 19:52:37 +03007070 * Decode LAYOUTRETURN response
7071 */
7072static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7073 struct xdr_stream *xdr,
7074 struct nfs4_layoutreturn_res *res)
7075{
7076 struct compound_hdr hdr;
7077 int status;
7078
7079 status = decode_compound_hdr(xdr, &hdr);
7080 if (status)
7081 goto out;
7082 status = decode_sequence(xdr, &res->seq_res, rqstp);
7083 if (status)
7084 goto out;
7085 status = decode_putfh(xdr);
7086 if (status)
7087 goto out;
7088 status = decode_layoutreturn(xdr, res);
7089out:
7090 return status;
7091}
7092
7093/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007094 * Decode LAYOUTCOMMIT response
7095 */
7096static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7097 struct xdr_stream *xdr,
7098 struct nfs4_layoutcommit_res *res)
7099{
7100 struct compound_hdr hdr;
7101 int status;
7102
7103 status = decode_compound_hdr(xdr, &hdr);
7104 if (status)
7105 goto out;
7106 status = decode_sequence(xdr, &res->seq_res, rqstp);
7107 if (status)
7108 goto out;
7109 status = decode_putfh(xdr);
7110 if (status)
7111 goto out;
7112 status = decode_layoutcommit(xdr, rqstp, res);
7113 if (status)
7114 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007115 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007116out:
7117 return status;
7118}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007119
7120/*
7121 * Decode SECINFO_NO_NAME response
7122 */
7123static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7124 struct xdr_stream *xdr,
7125 struct nfs4_secinfo_res *res)
7126{
7127 struct compound_hdr hdr;
7128 int status;
7129
7130 status = decode_compound_hdr(xdr, &hdr);
7131 if (status)
7132 goto out;
7133 status = decode_sequence(xdr, &res->seq_res, rqstp);
7134 if (status)
7135 goto out;
7136 status = decode_putrootfh(xdr);
7137 if (status)
7138 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007139 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007140out:
7141 return status;
7142}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007143
7144/*
7145 * Decode TEST_STATEID response
7146 */
7147static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7148 struct xdr_stream *xdr,
7149 struct nfs41_test_stateid_res *res)
7150{
7151 struct compound_hdr hdr;
7152 int status;
7153
7154 status = decode_compound_hdr(xdr, &hdr);
7155 if (status)
7156 goto out;
7157 status = decode_sequence(xdr, &res->seq_res, rqstp);
7158 if (status)
7159 goto out;
7160 status = decode_test_stateid(xdr, res);
7161out:
7162 return status;
7163}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007164
7165/*
7166 * Decode FREE_STATEID response
7167 */
7168static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7169 struct xdr_stream *xdr,
7170 struct nfs41_free_stateid_res *res)
7171{
7172 struct compound_hdr hdr;
7173 int status;
7174
7175 status = decode_compound_hdr(xdr, &hdr);
7176 if (status)
7177 goto out;
7178 status = decode_sequence(xdr, &res->seq_res, rqstp);
7179 if (status)
7180 goto out;
7181 status = decode_free_stateid(xdr, res);
7182out:
7183 return status;
7184}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007185#endif /* CONFIG_NFS_V4_1 */
7186
Chuck Lever573c4e12010-12-14 14:58:11 +00007187/**
7188 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7189 * the local page cache.
7190 * @xdr: XDR stream where entry resides
7191 * @entry: buffer to fill in with entry data
7192 * @plus: boolean indicating whether this should be a readdirplus entry
7193 *
7194 * Returns zero if successful, otherwise a negative errno value is
7195 * returned.
7196 *
7197 * This function is not invoked during READDIR reply decoding, but
7198 * rather whenever an application invokes the getdents(2) system call
7199 * on a directory already in our cache.
7200 */
7201int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7202 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007203{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007204 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007205 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007206 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007207 __be32 *p = xdr_inline_decode(xdr, 4);
7208 if (unlikely(!p))
7209 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007210 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007211 p = xdr_inline_decode(xdr, 4);
7212 if (unlikely(!p))
7213 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007214 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007215 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007216 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007217 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007218 }
7219
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007220 p = xdr_inline_decode(xdr, 12);
7221 if (unlikely(!p))
7222 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007223 entry->prev_cookie = entry->cookie;
7224 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007225 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007226
Trond Myklebust9af8c222010-10-24 11:52:55 -04007227 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007228 if (unlikely(!p))
7229 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007230 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007231
7232 /*
7233 * In case the server doesn't return an inode number,
7234 * we fake one here. (We don't use inode number 0,
7235 * since glibc seems to choke on it...)
7236 */
7237 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007238 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007239
Trond Myklebust9af8c222010-10-24 11:52:55 -04007240 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007241 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007242
Trond Myklebust256e48b2012-06-21 11:18:13 -04007243 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007244 goto out_overflow;
7245
Chuck Lever573c4e12010-12-14 14:58:11 +00007246 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007247 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007248 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007249 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7250 entry->ino = entry->fattr->mounted_on_fileid;
7251 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007252 entry->ino = entry->fattr->fileid;
7253
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007254 entry->d_type = DT_UNKNOWN;
7255 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7256 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7257
Chuck Lever573c4e12010-12-14 14:58:11 +00007258 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007259
7260out_overflow:
7261 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007262 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007263}
7264
7265/*
7266 * We need to translate between nfs status return values and
7267 * the local errno values which may not be the same.
7268 */
7269static struct {
7270 int stat;
7271 int errno;
7272} nfs_errtbl[] = {
7273 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007274 { NFS4ERR_PERM, -EPERM },
7275 { NFS4ERR_NOENT, -ENOENT },
7276 { NFS4ERR_IO, -errno_NFSERR_IO},
7277 { NFS4ERR_NXIO, -ENXIO },
7278 { NFS4ERR_ACCESS, -EACCES },
7279 { NFS4ERR_EXIST, -EEXIST },
7280 { NFS4ERR_XDEV, -EXDEV },
7281 { NFS4ERR_NOTDIR, -ENOTDIR },
7282 { NFS4ERR_ISDIR, -EISDIR },
7283 { NFS4ERR_INVAL, -EINVAL },
7284 { NFS4ERR_FBIG, -EFBIG },
7285 { NFS4ERR_NOSPC, -ENOSPC },
7286 { NFS4ERR_ROFS, -EROFS },
7287 { NFS4ERR_MLINK, -EMLINK },
7288 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7289 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7290 { NFS4ERR_DQUOT, -EDQUOT },
7291 { NFS4ERR_STALE, -ESTALE },
7292 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007293 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7294 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7295 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007296 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007297 { NFS4ERR_BADTYPE, -EBADTYPE },
7298 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007299 { NFS4ERR_SYMLINK, -ELOOP },
7300 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7301 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007302 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007303};
7304
7305/*
7306 * Convert an NFS error code to a local one.
7307 * This one is used jointly by NFSv2 and NFSv3.
7308 */
7309static int
David Howells0a8ea432006-08-22 20:06:08 -04007310nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007311{
7312 int i;
7313 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7314 if (nfs_errtbl[i].stat == stat)
7315 return nfs_errtbl[i].errno;
7316 }
7317 if (stat <= 10000 || stat > 10100) {
7318 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007319 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007320 }
7321 /* If we cannot translate the error, the recovery routines should
7322 * handle it.
7323 * Note: remaining NFSv4 error codes have values > 10000, so should
7324 * not conflict with native Linux error codes.
7325 */
Benny Halevy856dff32008-03-31 17:39:06 +03007326 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007327}
7328
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007329#ifdef CONFIG_NFS_V4_2
7330#include "nfs42xdr.c"
7331#endif /* CONFIG_NFS_V4_2 */
7332
Linus Torvalds1da177e2005-04-16 15:20:36 -07007333#define PROC(proc, argtype, restype) \
7334[NFSPROC4_CLNT_##proc] = { \
7335 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007336 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007337 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007338 .p_arglen = NFS4_##argtype##_sz, \
7339 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007340 .p_statidx = NFSPROC4_CLNT_##proc, \
7341 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007342}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007343
7344struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007345 PROC(READ, enc_read, dec_read),
7346 PROC(WRITE, enc_write, dec_write),
7347 PROC(COMMIT, enc_commit, dec_commit),
7348 PROC(OPEN, enc_open, dec_open),
7349 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7350 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7351 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7352 PROC(CLOSE, enc_close, dec_close),
7353 PROC(SETATTR, enc_setattr, dec_setattr),
7354 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7355 PROC(RENEW, enc_renew, dec_renew),
7356 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7357 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7358 PROC(LOCK, enc_lock, dec_lock),
7359 PROC(LOCKT, enc_lockt, dec_lockt),
7360 PROC(LOCKU, enc_locku, dec_locku),
7361 PROC(ACCESS, enc_access, dec_access),
7362 PROC(GETATTR, enc_getattr, dec_getattr),
7363 PROC(LOOKUP, enc_lookup, dec_lookup),
7364 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7365 PROC(REMOVE, enc_remove, dec_remove),
7366 PROC(RENAME, enc_rename, dec_rename),
7367 PROC(LINK, enc_link, dec_link),
7368 PROC(SYMLINK, enc_symlink, dec_symlink),
7369 PROC(CREATE, enc_create, dec_create),
7370 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7371 PROC(STATFS, enc_statfs, dec_statfs),
7372 PROC(READLINK, enc_readlink, dec_readlink),
7373 PROC(READDIR, enc_readdir, dec_readdir),
7374 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7375 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7376 PROC(GETACL, enc_getacl, dec_getacl),
7377 PROC(SETACL, enc_setacl, dec_setacl),
7378 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7379 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007380 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007381 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007382#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007383 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7384 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7385 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7386 PROC(SEQUENCE, enc_sequence, dec_sequence),
7387 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7388 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7389 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7390 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007391 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007392 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007393 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007394 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007395 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007396 PROC(BIND_CONN_TO_SESSION,
7397 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007398 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007399#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007400#ifdef CONFIG_NFS_V4_2
7401 PROC(SEEK, enc_seek, dec_seek),
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007402 PROC(ALLOCATE, enc_allocate, dec_allocate),
Anna Schumaker624bd5b2014-11-25 13:18:16 -05007403 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007404#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007405};
7406
Trond Myklebusta613fa12012-01-20 13:53:56 -05007407const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007408 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007409 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007410 .procs = nfs4_procedures
7411};
7412
7413/*
7414 * Local variables:
7415 * c-basic-offset: 8
7416 * End:
7417 */