blob: d10cc2a62dffbe2a529b8ff464be832a4d3963b5 [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>
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -050055#include <linux/fs_struct.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"
Anna Schumaker40c64c22015-04-15 13:00:05 -040059#include "nfs4idmap.h"
Trond Myklebust76e697b2012-11-26 14:20:49 -050060#include "nfs4session.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040061#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040062#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64#define NFSDBG_FACILITY NFSDBG_XDR
65
66/* Mapping from NFS error code to "errno" error code. */
67#define errno_NFSERR_IO EIO
68
David Howells0a8ea432006-08-22 20:06:08 -040069static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
72#ifdef DEBUG
73#define NFS4_MAXTAGLEN 20
74#else
75#define NFS4_MAXTAGLEN 0
76#endif
77
Andy Adamson6c0195a2008-12-23 16:06:15 -050078/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040079 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040081#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050082#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040083#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
86#define op_encode_hdr_maxsz (1)
87#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040088#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
90#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
91#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
93 (NFS4_FHSIZE >> 2))
94#define decode_putfh_maxsz (op_decode_hdr_maxsz)
95#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
96#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
97#define encode_getfh_maxsz (op_encode_hdr_maxsz)
98#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
99 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -0400100#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +0000101#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
103#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400104#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
105#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
David Quigleyaa9c2662013-05-22 12:50:44 -0400106#ifdef CONFIG_NFS_V4_SECURITY_LABEL
107/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
108#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
David Quigleyaa9c2662013-05-22 12:50:44 -0400109#else
110#define nfs4_label_maxsz 0
David Quigleyaa9c2662013-05-22 12:50:44 -0400111#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400112/* We support only one layout type per file system */
113#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000114/* This is based on getfattr, which uses the most attributes: */
115#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400116 3 + 3 + 3 + nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400117 nfs4_group_maxsz + nfs4_label_maxsz + \
118 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000119#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
120 nfs4_fattr_value_maxsz)
121#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400122#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
123 1 + 2 + 1 + \
124 nfs4_owner_maxsz + \
125 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400126 nfs4_label_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400127 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#define encode_savefh_maxsz (op_encode_hdr_maxsz)
129#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400130#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
131#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200132#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400133/* The 5 accounts for the PNFS attributes, and assumes that at most three
134 * layout types will be returned.
135 */
136#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
137 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
139#define decode_renew_maxsz (op_decode_hdr_maxsz)
140#define encode_setclientid_maxsz \
141 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500142 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400143 /* client name */ \
144 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500145 1 /* sc_prog */ + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500146 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
147 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500148 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#define decode_setclientid_maxsz \
150 (op_decode_hdr_maxsz + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500151 2 /* clientid */ + \
152 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
153 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
154 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155#define encode_setclientid_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 3 + (NFS4_VERIFIER_SIZE >> 2))
158#define decode_setclientid_confirm_maxsz \
159 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400160#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
161#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400162#define encode_share_access_maxsz \
163 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500164#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400165#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
166#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
167#define encode_open_maxsz (op_encode_hdr_maxsz + \
168 2 + encode_share_access_maxsz + 2 + \
169 open_owner_id_maxsz + \
170 encode_opentype_maxsz + \
171 encode_claim_null_maxsz)
172#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400173#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400174 decode_ace_maxsz)
175#define decode_change_info_maxsz (5)
176#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400177 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400178 decode_change_info_maxsz + 1 + \
179 nfs4_fattr_bitmap_maxsz + \
180 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400181#define encode_open_confirm_maxsz \
182 (op_encode_hdr_maxsz + \
183 encode_stateid_maxsz + 1)
184#define decode_open_confirm_maxsz \
185 (op_decode_hdr_maxsz + \
186 decode_stateid_maxsz)
187#define encode_open_downgrade_maxsz \
188 (op_encode_hdr_maxsz + \
189 encode_stateid_maxsz + 1 + \
190 encode_share_access_maxsz)
191#define decode_open_downgrade_maxsz \
192 (op_decode_hdr_maxsz + \
193 decode_stateid_maxsz)
194#define encode_close_maxsz (op_encode_hdr_maxsz + \
195 1 + encode_stateid_maxsz)
196#define decode_close_maxsz (op_decode_hdr_maxsz + \
197 decode_stateid_maxsz)
198#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
199 encode_stateid_maxsz + \
200 encode_attrs_maxsz)
201#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
202 nfs4_fattr_bitmap_maxsz)
203#define encode_read_maxsz (op_encode_hdr_maxsz + \
204 encode_stateid_maxsz + 3)
205#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
206#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400207 2 + encode_verifier_maxsz + 5 + \
208 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400209#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Chuck Levera7697f62014-03-12 12:51:17 -0400210 decode_verifier_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400211#define encode_readlink_maxsz (op_encode_hdr_maxsz)
212#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
213#define encode_write_maxsz (op_encode_hdr_maxsz + \
214 encode_stateid_maxsz + 4)
215#define decode_write_maxsz (op_decode_hdr_maxsz + \
216 2 + decode_verifier_maxsz)
217#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
218#define decode_commit_maxsz (op_decode_hdr_maxsz + \
219 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#define encode_remove_maxsz (op_encode_hdr_maxsz + \
221 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400222#define decode_remove_maxsz (op_decode_hdr_maxsz + \
223 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224#define encode_rename_maxsz (op_encode_hdr_maxsz + \
225 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400226#define decode_rename_maxsz (op_decode_hdr_maxsz + \
227 decode_change_info_maxsz + \
228 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229#define encode_link_maxsz (op_encode_hdr_maxsz + \
230 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400231#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400232#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400233#define encode_lock_maxsz (op_encode_hdr_maxsz + \
234 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400235 1 + encode_stateid_maxsz + 1 + \
236 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400237#define decode_lock_denied_maxsz \
238 (8 + decode_lockowner_maxsz)
239#define decode_lock_maxsz (op_decode_hdr_maxsz + \
240 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400241#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
242 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400243#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
244 decode_lock_denied_maxsz)
245#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
246 encode_stateid_maxsz + \
247 4)
248#define decode_locku_maxsz (op_decode_hdr_maxsz + \
249 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400250#define encode_release_lockowner_maxsz \
251 (op_encode_hdr_maxsz + \
252 encode_lockowner_maxsz)
253#define decode_release_lockowner_maxsz \
254 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400255#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
256#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
258 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400259 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000260 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
262#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400263 1 + 2 + nfs4_name_maxsz + \
264 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400265#define decode_create_maxsz (op_decode_hdr_maxsz + \
266 decode_change_info_maxsz + \
267 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400268#define encode_statfs_maxsz (encode_getattr_maxsz)
269#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
271#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400272#define encode_getacl_maxsz (encode_getattr_maxsz)
273#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
274 nfs4_fattr_bitmap_maxsz + 1)
275#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
276 encode_stateid_maxsz + 3)
277#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400278#define encode_fs_locations_maxsz \
279 (encode_getattr_maxsz)
280#define decode_fs_locations_maxsz \
281 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000282#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400283#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 -0400284
285#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400286#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500287#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
288 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400289
Benny Halevy99fe60d2009-04-01 09:22:29 -0400290#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
291 encode_verifier_maxsz + \
292 1 /* co_ownerid.len */ + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400293 /* eia_clientowner */ \
294 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400295 1 /* flags */ + \
296 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400297 /* max is SP4_MACH_CRED (for now) */ + \
298 1 + NFS4_OP_MAP_NUM_WORDS + \
299 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500300 1 /* implementation id array of size 1 */ + \
301 1 /* nii_domain */ + \
302 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
303 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500304 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500305 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400306#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
307 2 /* eir_clientid */ + \
308 1 /* eir_sequenceid */ + \
309 1 /* eir_flags */ + \
310 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400311 /* max is SP4_MACH_CRED (for now) */ + \
312 1 + NFS4_OP_MAP_NUM_WORDS + \
313 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400314 2 /* eir_server_owner.so_minor_id */ + \
315 /* eir_server_owner.so_major_id<> */ \
316 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
317 /* eir_server_scope<> */ \
318 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
319 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500320 1 /* nii_domain */ + \
321 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
322 1 /* nii_name */ + \
323 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
324 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400325#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
326#define decode_channel_attrs_maxsz (6 + \
327 1 /* ca_rdma_ird.len */ + \
328 1 /* ca_rdma_ird */)
329#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
330 2 /* csa_clientid */ + \
331 1 /* csa_sequence */ + \
332 1 /* csa_flags */ + \
333 encode_channel_attrs_maxsz + \
334 encode_channel_attrs_maxsz + \
335 1 /* csa_cb_program */ + \
336 1 /* csa_sec_parms.len (1) */ + \
337 1 /* cb_secflavor (AUTH_SYS) */ + \
338 1 /* stamp */ + \
339 1 /* machinename.len */ + \
340 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
341 1 /* uid */ + \
342 1 /* gid */ + \
343 1 /* gids.len (0) */)
344#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
345 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
346 1 /* csr_sequence */ + \
347 1 /* csr_flags */ + \
348 decode_channel_attrs_maxsz + \
349 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400350#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
351 /* bctsa_sessid */ \
352 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
353 1 /* bctsa_dir */ + \
354 1 /* bctsa_use_conn_in_rdma_mode */)
355#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
356 /* bctsr_sessid */ \
357 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
358 1 /* bctsr_dir */ + \
359 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400360#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
361#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400362#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
363#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400364#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
365 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
366#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
367 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500368#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
369#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700370#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
371 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
372 1 /* layout type */ + \
373 1 /* maxcount */ + \
374 1 /* bitmap size */ + \
375 1 /* notification bitmap length */ + \
376 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400377#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
378 1 /* layout type */ + \
379 1 /* opaque devaddr4 length */ + \
380 /* devaddr4 payload is read into page */ \
381 1 /* notification bitmap length */ + \
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700382 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400383#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
384 encode_stateid_maxsz)
385#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
386 decode_stateid_maxsz + \
387 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000388#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
389 2 /* offset */ + \
390 2 /* length */ + \
391 1 /* reclaim */ + \
392 encode_stateid_maxsz + \
393 1 /* new offset (true) */ + \
394 2 /* last byte written */ + \
395 1 /* nt_timechanged (false) */ + \
396 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500397 1 /* layoutupdate4 opaqueue len */)
398 /* the actual content of layoutupdate4 should
399 be allocated by drivers and spliced in
400 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000401#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300402#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
403 encode_stateid_maxsz + \
Trond Myklebust6669cb82015-08-27 20:43:20 -0400404 1 + \
405 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
Benny Halevycbe82602011-05-22 19:52:37 +0300406#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
407 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400408#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
409#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400410#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
411 XDR_QUADLEN(NFS4_STATEID_SIZE))
412#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400413#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
414 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400415#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400416#else /* CONFIG_NFS_V4_1 */
417#define encode_sequence_maxsz 0
418#define decode_sequence_maxsz 0
Trond Myklebustcf805162016-11-15 14:56:07 -0500419#define encode_layoutreturn_maxsz 0
420#define decode_layoutreturn_maxsz 0
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400421#endif /* CONFIG_NFS_V4_1 */
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
424#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
425#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400426 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400428 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400432 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400434 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400436 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400438 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400440 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400444 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400446 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400448 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400450 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400452 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400453 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400455 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400457 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400458 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400460 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400462 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400464 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400466 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400468 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400469 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400470 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400471 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400472 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400473 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400475 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400477 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400478 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400479 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400480 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400481#define NFS4_enc_open_confirm_sz \
482 (compound_encode_hdr_maxsz + \
483 encode_putfh_maxsz + \
484 encode_open_confirm_maxsz)
485#define NFS4_dec_open_confirm_sz \
486 (compound_decode_hdr_maxsz + \
487 decode_putfh_maxsz + \
488 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400490 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400492 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400493 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400494 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400498 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400499 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400500 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501#define NFS4_enc_open_downgrade_sz \
502 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400503 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400504 encode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500505 encode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400506 encode_open_downgrade_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#define NFS4_dec_open_downgrade_sz \
508 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400509 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400510 decode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500511 decode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400512 decode_open_downgrade_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400513#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400514 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400515 encode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500516 encode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400517 encode_close_maxsz + \
518 encode_getattr_maxsz)
519#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400521 decode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500522 decode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400523 decode_close_maxsz + \
524 decode_getattr_maxsz)
525#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400526 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400527 encode_putfh_maxsz + \
528 encode_setattr_maxsz + \
529 encode_getattr_maxsz)
530#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400531 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400532 decode_putfh_maxsz + \
533 decode_setattr_maxsz + \
534 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400536 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 encode_putfh_maxsz + \
538 encode_fsinfo_maxsz)
539#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400540 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 decode_putfh_maxsz + \
542 decode_fsinfo_maxsz)
543#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
544 encode_renew_maxsz)
545#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
546 decode_renew_maxsz)
547#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
548 encode_setclientid_maxsz)
549#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
550 decode_setclientid_maxsz)
551#define NFS4_enc_setclientid_confirm_sz \
552 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400553 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554#define NFS4_dec_setclientid_confirm_sz \
555 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400556 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#define NFS4_enc_lock_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_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400564 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define NFS4_enc_lockt_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_lockt_maxsz)
569#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400571 decode_putfh_maxsz + \
572 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400576 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400578 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400580 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400581#define NFS4_enc_release_lockowner_sz \
582 (compound_encode_hdr_maxsz + \
583 encode_lockowner_maxsz)
584#define NFS4_dec_release_lockowner_sz \
585 (compound_decode_hdr_maxsz + \
586 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400588 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400590 encode_access_maxsz + \
591 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400593 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400595 decode_access_maxsz + \
596 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400598 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400600 encode_getattr_maxsz + \
601 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400603 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400605 decode_getattr_maxsz + \
606 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400608 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 encode_putfh_maxsz + \
610 encode_lookup_maxsz + \
611 encode_getattr_maxsz + \
612 encode_getfh_maxsz)
613#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400614 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400616 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 decode_getattr_maxsz + \
618 decode_getfh_maxsz)
619#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400620 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 encode_putrootfh_maxsz + \
622 encode_getattr_maxsz + \
623 encode_getfh_maxsz)
624#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400625 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 decode_putrootfh_maxsz + \
627 decode_getattr_maxsz + \
628 decode_getfh_maxsz)
629#define NFS4_enc_remove_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 + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400632 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400634 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400636 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400638 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 encode_putfh_maxsz + \
640 encode_savefh_maxsz + \
641 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400642 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400644 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 decode_putfh_maxsz + \
646 decode_savefh_maxsz + \
647 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400648 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 encode_putfh_maxsz + \
652 encode_savefh_maxsz + \
653 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400654 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400655 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400656 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400658 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 decode_putfh_maxsz + \
660 decode_savefh_maxsz + \
661 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400662 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400663 decode_restorefh_maxsz + \
664 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400666 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 encode_putfh_maxsz + \
668 encode_symlink_maxsz + \
669 encode_getattr_maxsz + \
670 encode_getfh_maxsz)
671#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 decode_putfh_maxsz + \
674 decode_symlink_maxsz + \
675 decode_getattr_maxsz + \
676 decode_getfh_maxsz)
677#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400678 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 encode_putfh_maxsz + \
680 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400681 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400682 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 decode_putfh_maxsz + \
686 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400687 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400688 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689#define NFS4_enc_pathconf_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 + \
692 encode_getattr_maxsz)
693#define NFS4_dec_pathconf_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 + \
696 decode_getattr_maxsz)
697#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400698 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400700 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400702 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400704 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400706 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800707 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 encode_getattr_maxsz)
709#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400710 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800711 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 decode_getattr_maxsz)
713#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400714 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 encode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500716 encode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100717 encode_delegreturn_maxsz + \
718 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400720 decode_sequence_maxsz + \
Trond Myklebustd8434d4c2016-11-16 13:54:00 -0500721 decode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500722 decode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100723 decode_delegreturn_maxsz + \
724 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000725#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400726 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000727 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400728 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000729#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400730 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000731 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400732 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000733#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400734 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000735 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400736 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000737#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400738 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000739 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400740 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400741#define NFS4_enc_fs_locations_sz \
742 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400743 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400744 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400745 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400746 encode_fs_locations_maxsz + \
747 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400748#define NFS4_dec_fs_locations_sz \
749 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400750 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400751 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400752 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400753 decode_fs_locations_maxsz + \
754 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000755#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
756 encode_sequence_maxsz + \
757 encode_putfh_maxsz + \
758 encode_secinfo_maxsz)
759#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
760 decode_sequence_maxsz + \
761 decode_putfh_maxsz + \
762 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400763#define NFS4_enc_fsid_present_sz \
764 (compound_encode_hdr_maxsz + \
765 encode_sequence_maxsz + \
766 encode_putfh_maxsz + \
767 encode_getfh_maxsz + \
768 encode_renew_maxsz)
769#define NFS4_dec_fsid_present_sz \
770 (compound_decode_hdr_maxsz + \
771 decode_sequence_maxsz + \
772 decode_putfh_maxsz + \
773 decode_getfh_maxsz + \
774 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400775#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400776#define NFS4_enc_bind_conn_to_session_sz \
777 (compound_encode_hdr_maxsz + \
778 encode_bind_conn_to_session_maxsz)
779#define NFS4_dec_bind_conn_to_session_sz \
780 (compound_decode_hdr_maxsz + \
781 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400782#define NFS4_enc_exchange_id_sz \
783 (compound_encode_hdr_maxsz + \
784 encode_exchange_id_maxsz)
785#define NFS4_dec_exchange_id_sz \
786 (compound_decode_hdr_maxsz + \
787 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400788#define NFS4_enc_create_session_sz \
789 (compound_encode_hdr_maxsz + \
790 encode_create_session_maxsz)
791#define NFS4_dec_create_session_sz \
792 (compound_decode_hdr_maxsz + \
793 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400794#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
795 encode_destroy_session_maxsz)
796#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
797 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400798#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
799 encode_destroy_clientid_maxsz)
800#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
801 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400802#define NFS4_enc_sequence_sz \
803 (compound_decode_hdr_maxsz + \
804 encode_sequence_maxsz)
805#define NFS4_dec_sequence_sz \
806 (compound_decode_hdr_maxsz + \
807 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400808#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
809 encode_sequence_maxsz + \
810 encode_putrootfh_maxsz + \
811 encode_fsinfo_maxsz)
812#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
813 decode_sequence_maxsz + \
814 decode_putrootfh_maxsz + \
815 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500816#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
817 encode_sequence_maxsz + \
818 encode_reclaim_complete_maxsz)
819#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
820 decode_sequence_maxsz + \
821 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400822#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
823 encode_sequence_maxsz +\
824 encode_getdeviceinfo_maxsz)
825#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
826 decode_sequence_maxsz + \
827 decode_getdeviceinfo_maxsz)
828#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
829 encode_sequence_maxsz + \
830 encode_putfh_maxsz + \
831 encode_layoutget_maxsz)
832#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
833 decode_sequence_maxsz + \
834 decode_putfh_maxsz + \
835 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000836#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
837 encode_sequence_maxsz +\
838 encode_putfh_maxsz + \
839 encode_layoutcommit_maxsz + \
840 encode_getattr_maxsz)
841#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
842 decode_sequence_maxsz + \
843 decode_putfh_maxsz + \
844 decode_layoutcommit_maxsz + \
845 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300846#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
847 encode_sequence_maxsz + \
848 encode_putfh_maxsz + \
849 encode_layoutreturn_maxsz)
850#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
851 decode_sequence_maxsz + \
852 decode_putfh_maxsz + \
853 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400854#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
855 encode_sequence_maxsz + \
856 encode_putrootfh_maxsz +\
857 encode_secinfo_no_name_maxsz)
858#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
859 decode_sequence_maxsz + \
860 decode_putrootfh_maxsz + \
861 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400862#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
863 encode_sequence_maxsz + \
864 encode_test_stateid_maxsz)
865#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
866 decode_sequence_maxsz + \
867 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400868#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
869 encode_sequence_maxsz + \
870 encode_free_stateid_maxsz)
871#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
872 decode_sequence_maxsz + \
873 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500874
875const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
876 compound_encode_hdr_maxsz +
877 encode_sequence_maxsz +
878 encode_putfh_maxsz +
879 encode_getattr_maxsz) *
880 XDR_UNIT);
881
882const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
883 compound_decode_hdr_maxsz +
884 decode_sequence_maxsz +
885 decode_putfh_maxsz) *
886 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400887
888const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
889 compound_decode_hdr_maxsz +
890 decode_sequence_maxsz) *
891 XDR_UNIT);
892EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400893#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
Trond Myklebustbca79472009-03-11 14:10:26 -0400895static const umode_t nfs_type2fmt[] = {
896 [NF4BAD] = 0,
897 [NF4REG] = S_IFREG,
898 [NF4DIR] = S_IFDIR,
899 [NF4BLK] = S_IFBLK,
900 [NF4CHR] = S_IFCHR,
901 [NF4LNK] = S_IFLNK,
902 [NF4SOCK] = S_IFSOCK,
903 [NF4FIFO] = S_IFIFO,
904 [NF4ATTRDIR] = 0,
905 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906};
907
908struct compound_hdr {
909 int32_t status;
910 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500911 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 uint32_t taglen;
913 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400914 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400915 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916};
917
Benny Halevy13c65ce2009-08-14 17:19:25 +0300918static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
919{
920 __be32 *p = xdr_reserve_space(xdr, nbytes);
921 BUG_ON(!p);
922 return p;
923}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Trond Myklebustcb17e552012-03-04 18:13:56 -0500925static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
926{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500927 WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
Trond Myklebustcb17e552012-03-04 18:13:56 -0500928}
929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
931{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500932 WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933}
934
Trond Myklebust4ade9822012-03-04 18:13:57 -0500935static void encode_uint32(struct xdr_stream *xdr, u32 n)
936{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500937 WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500938}
939
Trond Myklebustff2eb682012-03-05 11:40:12 -0500940static void encode_uint64(struct xdr_stream *xdr, u64 n)
941{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500942 WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
Trond Myklebustff2eb682012-03-05 11:40:12 -0500943}
944
Trond Myklebust4ade9822012-03-04 18:13:57 -0500945static void encode_nfs4_seqid(struct xdr_stream *xdr,
946 const struct nfs_seqid *seqid)
947{
Trond Myklebusta6796412015-01-23 19:04:44 -0500948 if (seqid != NULL)
949 encode_uint32(xdr, seqid->sequence->counter);
950 else
951 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500952}
953
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400954static void encode_compound_hdr(struct xdr_stream *xdr,
955 struct rpc_rqst *req,
956 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957{
Al Viro8687b632006-10-19 23:28:48 -0700958 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400959 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400960
961 /* initialize running count of expected bytes in reply.
962 * NOTE: the replied tag SHOULD be the same is the one sent,
963 * but this is not required as a MUST for the server to do so. */
964 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
Trond Myklebust7fc38842012-10-15 11:51:21 -0400966 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500967 encode_string(xdr, hdr->taglen, hdr->tag);
968 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300969 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500970 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300971 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500972}
973
Trond Myklebustab19b482012-03-04 18:13:57 -0500974static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
975 uint32_t replen,
976 struct compound_hdr *hdr)
977{
978 encode_uint32(xdr, op);
979 hdr->nops++;
980 hdr->replen += replen;
981}
982
Andy Adamsond0179312008-12-23 16:06:17 -0500983static void encode_nops(struct compound_hdr *hdr)
984{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400985 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500986 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987}
988
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500989static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
990{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500991 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500992}
993
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
995{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500996 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997}
998
David Quigleyaa9c2662013-05-22 12:50:44 -0400999static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1000 const struct nfs4_label *label,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001001 const struct nfs_server *server,
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001002 bool excl_check, const umode_t *umask)
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.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001017 if (iap->ia_valid & ATTR_SIZE) {
1018 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001020 }
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001021 if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK))
1022 umask = NULL;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001023 if (iap->ia_valid & ATTR_MODE) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001024 if (umask) {
1025 bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1026 len += 8;
1027 } else {
1028 bmval[1] |= FATTR4_WORD1_MODE;
1029 len += 4;
1030 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001031 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001033 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001035 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001036 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 /* XXX */
1038 strcpy(owner_name, "nobody");
1039 owner_namelen = sizeof("nobody") - 1;
1040 /* goto out; */
1041 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001042 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1044 }
1045 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001046 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001048 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001049 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 strcpy(owner_group, "nobody");
1051 owner_grouplen = sizeof("nobody") - 1;
1052 /* goto out; */
1053 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001054 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1056 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001058 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1059 len += 16;
1060 } else if (iap->ia_valid & ATTR_ATIME) {
1061 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1062 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 }
1064 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001065 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1066 len += 16;
1067 } else if (iap->ia_valid & ATTR_MTIME) {
1068 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1069 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001071
1072 if (excl_check) {
1073 const u32 *excl_bmval = server->exclcreat_bitmask;
1074 bmval[0] &= excl_bmval[0];
1075 bmval[1] &= excl_bmval[1];
1076 bmval[2] &= excl_bmval[2];
1077
1078 if (!(excl_bmval[2] & FATTR4_WORD2_SECURITY_LABEL))
1079 label = NULL;
1080 }
1081
David Quigleyaa9c2662013-05-22 12:50:44 -04001082 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001083 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1084 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1085 }
1086
1087 if (bmval[2] != 0)
1088 bmval_len = 3;
1089 else if (bmval[1] != 0)
1090 bmval_len = 2;
1091 else
1092 bmval_len = 1;
1093
1094 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1095
1096 *p++ = cpu_to_be32(bmval_len);
1097 for (i = 0; i < bmval_len; i++)
1098 *p++ = cpu_to_be32(bmval[i]);
1099 *p++ = cpu_to_be32(len);
1100
1101 if (bmval[0] & FATTR4_WORD0_SIZE)
1102 p = xdr_encode_hyper(p, iap->ia_size);
1103 if (bmval[1] & FATTR4_WORD1_MODE)
1104 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1105 if (bmval[1] & FATTR4_WORD1_OWNER)
1106 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1107 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1108 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1109 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1110 if (iap->ia_valid & ATTR_ATIME_SET) {
1111 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1112 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1113 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1114 } else
1115 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1116 }
1117 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1118 if (iap->ia_valid & ATTR_MTIME_SET) {
1119 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1120 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1121 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1122 } else
1123 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1124 }
1125 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001126 *p++ = cpu_to_be32(label->lfs);
1127 *p++ = cpu_to_be32(label->pi);
1128 *p++ = cpu_to_be32(label->len);
1129 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1130 }
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001131 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1132 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1133 *p++ = cpu_to_be32(*umask);
1134 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001135
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137}
1138
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001139static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001141 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1142 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143}
1144
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001145static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146{
Trond Myklebustab19b482012-03-04 18:13:57 -05001147 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001148 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001149 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150}
1151
Fred Isaman0b7c0152012-04-20 14:47:39 -04001152static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153{
Al Viro8687b632006-10-19 23:28:48 -07001154 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001155
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001156 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1157 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001158 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001159 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160}
1161
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001162static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163{
Al Viro8687b632006-10-19 23:28:48 -07001164 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001165
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001166 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1167 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
1169 switch (create->ftype) {
1170 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001171 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001172 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001173 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1174 create->u.symlink.len);
1175 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 break;
1177
1178 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001179 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001180 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001181 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 break;
1183
1184 default:
1185 break;
1186 }
1187
Benny Halevy811652b2009-08-14 17:19:34 +03001188 encode_string(xdr, create->name->len, create->name->name);
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001189 encode_attrs(xdr, create->attrs, create->label, create->server, false,
1190 &create->umask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191}
1192
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001193static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194{
Andy Adamson05d564f2008-12-23 16:06:15 -05001195 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001197 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1198 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001199 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001200 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201}
1202
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001203static 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 -07001204{
Andy Adamson05d564f2008-12-23 16:06:15 -05001205 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001207 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1208 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001209 *p++ = cpu_to_be32(2);
1210 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001211 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212}
1213
Fred Isamandae100c2011-07-30 20:52:37 -04001214static void
1215encode_getattr_three(struct xdr_stream *xdr,
1216 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1217 struct compound_hdr *hdr)
1218{
1219 __be32 *p;
1220
Trond Myklebustab19b482012-03-04 18:13:57 -05001221 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001222 if (bm2) {
1223 p = reserve_space(xdr, 16);
1224 *p++ = cpu_to_be32(3);
1225 *p++ = cpu_to_be32(bm0);
1226 *p++ = cpu_to_be32(bm1);
1227 *p = cpu_to_be32(bm2);
1228 } else if (bm1) {
1229 p = reserve_space(xdr, 12);
1230 *p++ = cpu_to_be32(2);
1231 *p++ = cpu_to_be32(bm0);
1232 *p = cpu_to_be32(bm1);
1233 } else {
1234 p = reserve_space(xdr, 8);
1235 *p++ = cpu_to_be32(1);
1236 *p = cpu_to_be32(bm0);
1237 }
Fred Isamandae100c2011-07-30 20:52:37 -04001238}
1239
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001240static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241{
David Quigleya09df2c2013-05-22 12:50:41 -04001242 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1243 bitmask[1] & nfs4_fattr_bitmap[1],
1244 bitmask[2] & nfs4_fattr_bitmap[2],
1245 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246}
1247
Andy Adamson88034c32012-05-23 05:02:34 -04001248static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001249 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001250 struct compound_hdr *hdr)
1251{
1252 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001253 bitmask[0] & open_bitmap[0],
1254 bitmask[1] & open_bitmap[1],
1255 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001256 hdr);
1257}
1258
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001259static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260{
Fred Isamandae100c2011-07-30 20:52:37 -04001261 encode_getattr_three(xdr,
1262 bitmask[0] & nfs4_fsinfo_bitmap[0],
1263 bitmask[1] & nfs4_fsinfo_bitmap[1],
1264 bitmask[2] & nfs4_fsinfo_bitmap[2],
1265 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266}
1267
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001268static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001269{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001270 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1271 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001272}
1273
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001274static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275{
Trond Myklebustab19b482012-03-04 18:13:57 -05001276 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277}
1278
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001279static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280{
Trond Myklebustab19b482012-03-04 18:13:57 -05001281 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001282 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283}
1284
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001285static inline int nfs4_lock_type(struct file_lock *fl, int block)
1286{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001287 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001288 return block ? NFS4_READW_LT : NFS4_READ_LT;
1289 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1290}
1291
1292static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1293{
1294 if (fl->fl_end == OFFSET_MAX)
1295 return ~(uint64_t)0;
1296 return fl->fl_end - fl->fl_start + 1;
1297}
1298
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001299static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1300{
1301 __be32 *p;
1302
Trond Myklebustd035c362010-12-21 10:45:27 -05001303 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001304 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001305 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001306 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001307 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001308 xdr_encode_hyper(p, lowner->id);
1309}
1310
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311/*
1312 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1313 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1314 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001315static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316{
Al Viro8687b632006-10-19 23:28:48 -07001317 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001319 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1320 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001321 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1322 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001323 p = xdr_encode_hyper(p, args->fl->fl_start);
1324 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001325 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001326 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001327 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001328 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001329 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001330 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 }
1332 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001333 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001334 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336}
1337
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001338static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339{
Al Viro8687b632006-10-19 23:28:48 -07001340 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001342 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1343 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001344 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001345 p = xdr_encode_hyper(p, args->fl->fl_start);
1346 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001347 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348}
1349
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001350static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351{
Al Viro8687b632006-10-19 23:28:48 -07001352 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001354 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1355 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001356 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001357 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001358 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001359 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001360 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361}
1362
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001363static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1364{
Trond Myklebustab19b482012-03-04 18:13:57 -05001365 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001366 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001367}
1368
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001369static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370{
Trond Myklebustab19b482012-03-04 18:13:57 -05001371 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001372 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373}
1374
Trond Myklebust6ae37332015-01-30 14:21:14 -05001375static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376{
Al Viro8687b632006-10-19 23:28:48 -07001377 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Benny Halevy13c65ce2009-08-14 17:19:25 +03001379 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001380 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001381 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382}
1383
1384static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1385{
Al Viro8687b632006-10-19 23:28:48 -07001386 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 /*
1388 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1389 * owner 4 = 32
1390 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001391 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001392 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001393 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001394 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001395 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001396 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001397 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001398 *p++ = cpu_to_be32(arg->id.uniquifier);
1399 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400}
1401
1402static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1403{
Al Viro8687b632006-10-19 23:28:48 -07001404 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Benny Halevy13c65ce2009-08-14 17:19:25 +03001406 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001407 switch(arg->createmode) {
1408 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001409 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001410 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false,
1411 &arg->umask);
Andy Adamson05d564f2008-12-23 16:06:15 -05001412 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001413 case NFS4_CREATE_GUARDED:
1414 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001415 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false,
1416 &arg->umask);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001417 break;
1418 case NFS4_CREATE_EXCLUSIVE:
1419 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1420 encode_nfs4_verifier(xdr, &arg->u.verifier);
1421 break;
1422 case NFS4_CREATE_EXCLUSIVE4_1:
1423 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1424 encode_nfs4_verifier(xdr, &arg->u.verifier);
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001425 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, true,
1426 &arg->umask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 }
1428}
1429
1430static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1431{
Al Viro8687b632006-10-19 23:28:48 -07001432 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Benny Halevy13c65ce2009-08-14 17:19:25 +03001434 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001436 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001437 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001438 break;
1439 default:
Benny Halevy34558512009-08-14 17:19:30 +03001440 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001441 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 }
1443}
1444
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001445static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446{
Al Viro8687b632006-10-19 23:28:48 -07001447 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Benny Halevy13c65ce2009-08-14 17:19:25 +03001449 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001451 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001452 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001453 break;
1454 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001455 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001456 break;
1457 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001458 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001459 break;
1460 default:
1461 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 }
1463}
1464
1465static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1466{
Al Viro8687b632006-10-19 23:28:48 -07001467 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Benny Halevy13c65ce2009-08-14 17:19:25 +03001469 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001470 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 encode_string(xdr, name->len, name->name);
1472}
1473
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001474static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475{
Al Viro8687b632006-10-19 23:28:48 -07001476 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Benny Halevy13c65ce2009-08-14 17:19:25 +03001478 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001479 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 encode_delegation_type(xdr, type);
1481}
1482
1483static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1484{
Al Viro8687b632006-10-19 23:28:48 -07001485 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001487 p = reserve_space(xdr, 4);
1488 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1489 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 encode_string(xdr, name->len, name->name);
1491}
1492
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001493static inline void encode_claim_fh(struct xdr_stream *xdr)
1494{
1495 __be32 *p;
1496
1497 p = reserve_space(xdr, 4);
1498 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1499}
1500
1501static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1502{
1503 __be32 *p;
1504
1505 p = reserve_space(xdr, 4);
1506 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1507 encode_nfs4_stateid(xdr, stateid);
1508}
1509
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001510static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511{
Trond Myklebustab19b482012-03-04 18:13:57 -05001512 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 encode_openhdr(xdr, arg);
1514 encode_opentype(xdr, arg);
1515 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001516 case NFS4_OPEN_CLAIM_NULL:
1517 encode_claim_null(xdr, arg->name);
1518 break;
1519 case NFS4_OPEN_CLAIM_PREVIOUS:
1520 encode_claim_previous(xdr, arg->u.delegation_type);
1521 break;
1522 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1523 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1524 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001525 case NFS4_OPEN_CLAIM_FH:
1526 encode_claim_fh(xdr);
1527 break;
1528 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1529 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1530 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001531 default:
1532 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534}
1535
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001536static 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 -07001537{
Trond Myklebustab19b482012-03-04 18:13:57 -05001538 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001539 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001540 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541}
1542
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001543static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544{
Trond Myklebustab19b482012-03-04 18:13:57 -05001545 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001546 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001547 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001548 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549}
1550
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001551static void
Andy Adamsond0179312008-12-23 16:06:17 -05001552encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553{
Trond Myklebustab19b482012-03-04 18:13:57 -05001554 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001555 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556}
1557
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001558static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559{
Trond Myklebustab19b482012-03-04 18:13:57 -05001560 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561}
1562
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001563static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1564 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565{
Al Viro8687b632006-10-19 23:28:48 -07001566 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
Trond Myklebustab19b482012-03-04 18:13:57 -05001568 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001569 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
Benny Halevy13c65ce2009-08-14 17:19:25 +03001571 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001572 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001573 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574}
1575
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001576static 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 -07001577{
David Quigleyaa9c2662013-05-22 12:50:44 -04001578 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001579 FATTR4_WORD0_RDATTR_ERROR,
1580 FATTR4_WORD1_MOUNTED_ON_FILEID,
1581 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001582 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001583 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001584 uint32_t attrlen = 0;
1585 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001587 if (readdir->plus) {
1588 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001589 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001590 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1591 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1592 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1593 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001594 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001595 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001596 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001597 /* Use mounted_on_fileid only if the server supports it */
1598 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1599 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001600 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1601 attrs[i] &= readdir->bitmask[i];
1602 if (attrs[i] != 0)
1603 attrlen = i+1;
1604 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001605
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001606 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001607 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001608 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001609 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001610 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001611 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001612 *p++ = cpu_to_be32(attrlen);
1613 for (i = 0; i < attrlen; i++)
1614 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001615 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001616
1617 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001618 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001619 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001620 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001621 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001622 attrs[1] & readdir->bitmask[1],
1623 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624}
1625
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001626static 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 -07001627{
Trond Myklebustab19b482012-03-04 18:13:57 -05001628 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629}
1630
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001631static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632{
Trond Myklebustab19b482012-03-04 18:13:57 -05001633 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001634 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635}
1636
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001637static 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 -07001638{
Trond Myklebustab19b482012-03-04 18:13:57 -05001639 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001640 encode_string(xdr, oldname->len, oldname->name);
1641 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642}
1643
Chuck Leverbb4dae52012-03-01 17:01:48 -05001644static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1645 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001647 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001648 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
1650
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001651static void
Andy Adamsond0179312008-12-23 16:06:17 -05001652encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001653{
Trond Myklebustab19b482012-03-04 18:13:57 -05001654 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001655}
1656
Chuck Lever9f06c712010-12-14 14:59:18 +00001657static void
Andy Adamsond0179312008-12-23 16:06:17 -05001658encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001659{
Al Viro8687b632006-10-19 23:28:48 -07001660 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001661
Trond Myklebustab19b482012-03-04 18:13:57 -05001662 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001663 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001664 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001665 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001666 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001667 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001668 *p = cpu_to_be32(arg->acl_len);
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01001669 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001670}
1671
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001672static void
Andy Adamsond0179312008-12-23 16:06:17 -05001673encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674{
Trond Myklebustab19b482012-03-04 18:13:57 -05001675 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676}
1677
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001678static 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 -07001679{
Trond Myklebustab19b482012-03-04 18:13:57 -05001680 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001681 encode_nfs4_stateid(xdr, &arg->stateid);
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001682 encode_attrs(xdr, arg->iap, arg->label, server, false, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683}
1684
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001685static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686{
Al Viro8687b632006-10-19 23:28:48 -07001687 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
Trond Myklebust70019512012-03-04 20:49:32 -05001689 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001690 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
Jeff Layton3a6bb732015-06-09 19:43:57 -04001692 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1693 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001694 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001695 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1697 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001698 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001699 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700}
1701
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001702static 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 -07001703{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001704 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1705 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001706 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001707 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708}
1709
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001710static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1711 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712{
Al Viro8687b632006-10-19 23:28:48 -07001713 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714
Trond Myklebustab19b482012-03-04 18:13:57 -05001715 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001716 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717
Benny Halevy13c65ce2009-08-14 17:19:25 +03001718 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001719 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001720 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001721 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
1723 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724}
1725
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001726static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727{
Trond Myklebustab19b482012-03-04 18:13:57 -05001728 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001729 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001731
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001732static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1733{
Trond Myklebustab19b482012-03-04 18:13:57 -05001734 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001735 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001736}
1737
Benny Halevy99fe60d2009-04-01 09:22:29 -04001738#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001739/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001740static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08001741 struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001742 struct compound_hdr *hdr)
1743{
1744 __be32 *p;
1745
1746 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1747 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001748 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001749 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001750 *p++ = cpu_to_be32(args->dir);
1751 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001752}
1753
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001754static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1755{
1756 unsigned int i;
1757 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1758 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1759 encode_uint32(xdr, op_map->u.words[i]);
1760}
1761
Benny Halevy99fe60d2009-04-01 09:22:29 -04001762static void encode_exchange_id(struct xdr_stream *xdr,
1763 struct nfs41_exchange_id_args *args,
1764 struct compound_hdr *hdr)
1765{
1766 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001767 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001768 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001769
Trond Myklebust70019512012-03-04 20:49:32 -05001770 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001771 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001772
Jeff Layton3a6bb732015-06-09 19:43:57 -04001773 encode_string(xdr, strlen(args->client->cl_owner_id),
1774 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001775
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001776 encode_uint32(xdr, args->flags);
1777 encode_uint32(xdr, args->state_protect.how);
1778
1779 switch (args->state_protect.how) {
1780 case SP4_NONE:
1781 break;
1782 case SP4_MACH_CRED:
1783 encode_op_map(xdr, &args->state_protect.enforce);
1784 encode_op_map(xdr, &args->state_protect.allow);
1785 break;
1786 default:
1787 WARN_ON_ONCE(1);
1788 break;
1789 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001790
1791 if (send_implementation_id &&
1792 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1793 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001794 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001795 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1796 utsname()->sysname, utsname()->release,
1797 utsname()->version, utsname()->machine);
1798
1799 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001800 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001801
1802 encode_string(xdr,
1803 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1804 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1805 encode_string(xdr, len, impl_name);
1806 /* just send zeros for nii_date - the date is in nii_name */
1807 p = reserve_space(xdr, 12);
1808 p = xdr_encode_hyper(p, 0);
1809 *p = cpu_to_be32(0);
1810 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001811 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001812}
Andy Adamsonfc931582009-04-01 09:22:31 -04001813
1814static void encode_create_session(struct xdr_stream *xdr,
1815 struct nfs41_create_session_args *args,
1816 struct compound_hdr *hdr)
1817{
1818 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001819 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001820 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001821 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001822 u32 max_resp_sz_cached;
1823
1824 /*
1825 * Assumes OPEN is the biggest non-idempotent compound.
1826 * 2 is the verifier.
1827 */
1828 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1829 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001830
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001831 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001832 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001833 p = xdr_encode_hyper(p, args->clientid);
1834 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001835 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001836
Andy Adamsonfc931582009-04-01 09:22:31 -04001837 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001838 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001839 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1840 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001841 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001842 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1843 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1844 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001845
1846 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001847 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001848 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1849 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1850 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1851 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1852 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1853 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001854
Benny Halevye75bc1c2009-08-14 17:18:54 +03001855 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001856 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001857 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001858
1859 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001860 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001861 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001862 *p++ = cpu_to_be32(0); /* UID */
1863 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001864 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001865}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001866
1867static void encode_destroy_session(struct xdr_stream *xdr,
1868 struct nfs4_session *session,
1869 struct compound_hdr *hdr)
1870{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001871 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1872 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001873}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001874
Trond Myklebust66245532012-05-25 17:18:09 -04001875static void encode_destroy_clientid(struct xdr_stream *xdr,
1876 uint64_t clientid,
1877 struct compound_hdr *hdr)
1878{
1879 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1880 encode_uint64(xdr, clientid);
1881}
1882
Ricardo Labiaga180197532009-12-05 16:08:40 -05001883static void encode_reclaim_complete(struct xdr_stream *xdr,
1884 struct nfs41_reclaim_complete_args *args,
1885 struct compound_hdr *hdr)
1886{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001887 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1888 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001889}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001890#endif /* CONFIG_NFS_V4_1 */
1891
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001892static void encode_sequence(struct xdr_stream *xdr,
1893 const struct nfs4_sequence_args *args,
1894 struct compound_hdr *hdr)
1895{
1896#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001897 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001898 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001899 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001900 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001901
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001902 tp = slot->table;
1903 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001904 if (!session)
1905 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001906
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001907 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001908
1909 /*
1910 * Sessionid + seqid + slotid + max slotid + cache_this
1911 */
1912 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1913 "max_slotid=%d cache_this=%d\n",
1914 __func__,
1915 ((u32 *)session->sess_id.data)[0],
1916 ((u32 *)session->sess_id.data)[1],
1917 ((u32 *)session->sess_id.data)[2],
1918 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001919 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001920 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001921 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001922 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001923 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001924 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001925 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001926 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001927#endif /* CONFIG_NFS_V4_1 */
1928}
1929
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001930#ifdef CONFIG_NFS_V4_1
1931static void
1932encode_getdeviceinfo(struct xdr_stream *xdr,
1933 const struct nfs4_getdeviceinfo_args *args,
1934 struct compound_hdr *hdr)
1935{
1936 __be32 *p;
1937
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001938 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001939 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001940 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1941 NFS4_DEVICEID4_SIZE);
1942 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001943 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001944
1945 p = reserve_space(xdr, 4 + 4);
1946 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001947 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001948}
1949
1950static void
1951encode_layoutget(struct xdr_stream *xdr,
1952 const struct nfs4_layoutget_args *args,
1953 struct compound_hdr *hdr)
1954{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001955 __be32 *p;
1956
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001957 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1958 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001959 *p++ = cpu_to_be32(0); /* Signal layout available */
1960 *p++ = cpu_to_be32(args->type);
1961 *p++ = cpu_to_be32(args->range.iomode);
1962 p = xdr_encode_hyper(p, args->range.offset);
1963 p = xdr_encode_hyper(p, args->range.length);
1964 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001965 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001966 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001967
1968 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1969 __func__,
1970 args->type,
1971 args->range.iomode,
1972 (unsigned long)args->range.offset,
1973 (unsigned long)args->range.length,
1974 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001975}
Andy Adamson863a3c62011-03-23 13:27:54 +00001976
1977static int
1978encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001979 struct inode *inode,
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001980 struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001981 struct compound_hdr *hdr)
1982{
1983 __be32 *p;
1984
1985 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1986 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1987
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001988 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1989 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001990 /* Only whole file layouts */
1991 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001992 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001993 *p = cpu_to_be32(0); /* reclaim */
1994 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04001995 if (args->lastbytewritten != U64_MAX) {
1996 p = reserve_space(xdr, 20);
1997 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1998 p = xdr_encode_hyper(p, args->lastbytewritten);
1999 } else {
2000 p = reserve_space(xdr, 12);
2001 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2002 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002003 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2004 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002005
Christoph Hellwig5f919c92014-08-21 11:09:25 -05002006 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
Benny Halevyac7db722011-05-22 19:53:48 +03002007 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2008 NFS_I(inode)->layout, xdr, args);
Christoph Hellwig5f919c92014-08-21 11:09:25 -05002009 } else {
2010 encode_uint32(xdr, args->layoutupdate_len);
2011 if (args->layoutupdate_pages) {
2012 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2013 args->layoutupdate_len);
2014 }
2015 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002016
Andy Adamson863a3c62011-03-23 13:27:54 +00002017 return 0;
2018}
Benny Halevycbe82602011-05-22 19:52:37 +03002019
2020static void
2021encode_layoutreturn(struct xdr_stream *xdr,
2022 const struct nfs4_layoutreturn_args *args,
2023 struct compound_hdr *hdr)
2024{
Trond Myklebust94e5c572016-09-15 18:49:52 -04002025 const struct pnfs_layoutdriver_type *lr_ops = NFS_SERVER(args->inode)->pnfs_curr_ld;
Benny Halevycbe82602011-05-22 19:52:37 +03002026 __be32 *p;
2027
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002028 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2029 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002030 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2031 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002032 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002033 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002034 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002035 p = xdr_encode_hyper(p, args->range.offset);
2036 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002037 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002038 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002039 spin_unlock(&args->inode->i_lock);
Trond Myklebust4d796d72016-09-23 11:38:08 -04002040 if (args->ld_private->ops && args->ld_private->ops->encode)
2041 args->ld_private->ops->encode(xdr, args, args->ld_private);
2042 else if (lr_ops->encode_layoutreturn)
Trond Myklebust94e5c572016-09-15 18:49:52 -04002043 lr_ops->encode_layoutreturn(xdr, args);
2044 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002045 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002046}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002047
2048static int
2049encode_secinfo_no_name(struct xdr_stream *xdr,
2050 const struct nfs41_secinfo_no_name_args *args,
2051 struct compound_hdr *hdr)
2052{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002053 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2054 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002055 return 0;
2056}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002057
2058static void encode_test_stateid(struct xdr_stream *xdr,
2059 struct nfs41_test_stateid_args *args,
2060 struct compound_hdr *hdr)
2061{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002062 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2063 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002064 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002065}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002066
2067static void encode_free_stateid(struct xdr_stream *xdr,
2068 struct nfs41_free_stateid_args *args,
2069 struct compound_hdr *hdr)
2070{
Trond Myklebustab19b482012-03-04 18:13:57 -05002071 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002072 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002073}
Trond Myklebustcf805162016-11-15 14:56:07 -05002074#else
2075static inline void
2076encode_layoutreturn(struct xdr_stream *xdr,
2077 const struct nfs4_layoutreturn_args *args,
2078 struct compound_hdr *hdr)
2079{
2080}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002081#endif /* CONFIG_NFS_V4_1 */
2082
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083/*
2084 * END OF "GENERIC" ENCODE ROUTINES.
2085 */
2086
Benny Halevy66cc0422009-04-01 09:22:10 -04002087static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2088{
2089#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002090 struct nfs4_session *session = args->sa_slot->table->session;
2091 if (session)
2092 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002093#endif /* CONFIG_NFS_V4_1 */
2094 return 0;
2095}
2096
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097/*
2098 * Encode an ACCESS request
2099 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002100static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2101 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002104 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106
Chuck Lever9f06c712010-12-14 14:59:18 +00002107 encode_compound_hdr(xdr, req, &hdr);
2108 encode_sequence(xdr, &args->seq_args, &hdr);
2109 encode_putfh(xdr, args->fh, &hdr);
2110 encode_access(xdr, args->access, &hdr);
2111 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002112 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113}
2114
2115/*
2116 * Encode LOOKUP request
2117 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002118static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2119 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002122 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
Chuck Lever9f06c712010-12-14 14:59:18 +00002125 encode_compound_hdr(xdr, req, &hdr);
2126 encode_sequence(xdr, &args->seq_args, &hdr);
2127 encode_putfh(xdr, args->dir_fh, &hdr);
2128 encode_lookup(xdr, args->name, &hdr);
2129 encode_getfh(xdr, &hdr);
2130 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002131 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132}
2133
2134/*
2135 * Encode LOOKUP_ROOT request
2136 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002137static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2138 struct xdr_stream *xdr,
2139 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002142 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144
Chuck Lever9f06c712010-12-14 14:59:18 +00002145 encode_compound_hdr(xdr, req, &hdr);
2146 encode_sequence(xdr, &args->seq_args, &hdr);
2147 encode_putrootfh(xdr, &hdr);
2148 encode_getfh(xdr, &hdr);
2149 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002150 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151}
2152
2153/*
2154 * Encode REMOVE request
2155 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002156static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2157 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002160 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
Chuck Lever9f06c712010-12-14 14:59:18 +00002163 encode_compound_hdr(xdr, req, &hdr);
2164 encode_sequence(xdr, &args->seq_args, &hdr);
2165 encode_putfh(xdr, args->fh, &hdr);
2166 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002167 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168}
2169
2170/*
2171 * Encode RENAME request
2172 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002173static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2174 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002177 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179
Chuck Lever9f06c712010-12-14 14:59:18 +00002180 encode_compound_hdr(xdr, req, &hdr);
2181 encode_sequence(xdr, &args->seq_args, &hdr);
2182 encode_putfh(xdr, args->old_dir, &hdr);
2183 encode_savefh(xdr, &hdr);
2184 encode_putfh(xdr, args->new_dir, &hdr);
2185 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002186 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187}
2188
2189/*
2190 * Encode LINK request
2191 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002192static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2193 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002196 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198
Chuck Lever9f06c712010-12-14 14:59:18 +00002199 encode_compound_hdr(xdr, req, &hdr);
2200 encode_sequence(xdr, &args->seq_args, &hdr);
2201 encode_putfh(xdr, args->fh, &hdr);
2202 encode_savefh(xdr, &hdr);
2203 encode_putfh(xdr, args->dir_fh, &hdr);
2204 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002205 encode_restorefh(xdr, &hdr);
2206 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002207 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208}
2209
2210/*
2211 * Encode CREATE request
2212 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002213static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2214 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002217 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219
Chuck Lever9f06c712010-12-14 14:59:18 +00002220 encode_compound_hdr(xdr, req, &hdr);
2221 encode_sequence(xdr, &args->seq_args, &hdr);
2222 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002223 encode_create(xdr, args, &hdr);
2224 encode_getfh(xdr, &hdr);
2225 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002226 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227}
2228
2229/*
2230 * Encode SYMLINK request
2231 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002232static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2233 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234{
Chuck Lever9f06c712010-12-14 14:59:18 +00002235 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236}
2237
2238/*
2239 * Encode GETATTR request
2240 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002241static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2242 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002245 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247
Chuck Lever9f06c712010-12-14 14:59:18 +00002248 encode_compound_hdr(xdr, req, &hdr);
2249 encode_sequence(xdr, &args->seq_args, &hdr);
2250 encode_putfh(xdr, args->fh, &hdr);
2251 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002252 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253}
2254
2255/*
2256 * Encode a CLOSE request
2257 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002258static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2259 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260{
Andy Adamson05d564f2008-12-23 16:06:15 -05002261 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002262 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002263 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264
Chuck Lever9f06c712010-12-14 14:59:18 +00002265 encode_compound_hdr(xdr, req, &hdr);
2266 encode_sequence(xdr, &args->seq_args, &hdr);
2267 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002268 if (args->lr_args)
2269 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002270 if (args->bitmask != NULL)
2271 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebustd8d84982016-12-19 12:14:44 -05002272 encode_close(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002273 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274}
2275
2276/*
2277 * Encode an OPEN request
2278 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002279static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2280 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002283 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
Chuck Lever9f06c712010-12-14 14:59:18 +00002286 encode_compound_hdr(xdr, req, &hdr);
2287 encode_sequence(xdr, &args->seq_args, &hdr);
2288 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002289 encode_open(xdr, args, &hdr);
2290 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002291 if (args->access)
2292 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002293 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002294 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295}
2296
2297/*
2298 * Encode an OPEN_CONFIRM request
2299 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002300static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2301 struct xdr_stream *xdr,
2302 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002305 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307
Chuck Lever9f06c712010-12-14 14:59:18 +00002308 encode_compound_hdr(xdr, req, &hdr);
2309 encode_putfh(xdr, args->fh, &hdr);
2310 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002311 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312}
2313
2314/*
2315 * Encode an OPEN request with no attributes.
2316 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002317static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2318 struct xdr_stream *xdr,
2319 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002322 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Chuck Lever9f06c712010-12-14 14:59:18 +00002325 encode_compound_hdr(xdr, req, &hdr);
2326 encode_sequence(xdr, &args->seq_args, &hdr);
2327 encode_putfh(xdr, args->fh, &hdr);
2328 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002329 if (args->access)
2330 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002331 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002332 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333}
2334
2335/*
2336 * Encode an OPEN_DOWNGRADE request
2337 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002338static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2339 struct xdr_stream *xdr,
2340 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002343 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
Chuck Lever9f06c712010-12-14 14:59:18 +00002346 encode_compound_hdr(xdr, req, &hdr);
2347 encode_sequence(xdr, &args->seq_args, &hdr);
2348 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustb6808142016-11-20 13:34:16 -05002349 if (args->lr_args)
2350 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002351 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002352 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353}
2354
2355/*
2356 * Encode a LOCK request
2357 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002358static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2359 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002362 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
Chuck Lever9f06c712010-12-14 14:59:18 +00002365 encode_compound_hdr(xdr, req, &hdr);
2366 encode_sequence(xdr, &args->seq_args, &hdr);
2367 encode_putfh(xdr, args->fh, &hdr);
2368 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002369 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370}
2371
2372/*
2373 * Encode a LOCKT request
2374 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002375static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2376 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002379 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
Chuck Lever9f06c712010-12-14 14:59:18 +00002382 encode_compound_hdr(xdr, req, &hdr);
2383 encode_sequence(xdr, &args->seq_args, &hdr);
2384 encode_putfh(xdr, args->fh, &hdr);
2385 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002386 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387}
2388
2389/*
2390 * Encode a LOCKU request
2391 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002392static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2393 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002396 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398
Chuck Lever9f06c712010-12-14 14:59:18 +00002399 encode_compound_hdr(xdr, req, &hdr);
2400 encode_sequence(xdr, &args->seq_args, &hdr);
2401 encode_putfh(xdr, args->fh, &hdr);
2402 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002403 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404}
2405
Chuck Lever9f06c712010-12-14 14:59:18 +00002406static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2407 struct xdr_stream *xdr,
2408 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002409{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002410 struct compound_hdr hdr = {
2411 .minorversion = 0,
2412 };
2413
Chuck Lever9f06c712010-12-14 14:59:18 +00002414 encode_compound_hdr(xdr, req, &hdr);
2415 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002416 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002417}
2418
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419/*
2420 * Encode a READLINK request
2421 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002422static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2423 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002426 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
Chuck Lever9f06c712010-12-14 14:59:18 +00002429 encode_compound_hdr(xdr, req, &hdr);
2430 encode_sequence(xdr, &args->seq_args, &hdr);
2431 encode_putfh(xdr, args->fh, &hdr);
2432 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002433
Benny Halevy28f56692009-04-01 09:22:09 -04002434 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002435 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002436 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437}
2438
2439/*
2440 * Encode a READDIR request
2441 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002442static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2443 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002446 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448
Chuck Lever9f06c712010-12-14 14:59:18 +00002449 encode_compound_hdr(xdr, req, &hdr);
2450 encode_sequence(xdr, &args->seq_args, &hdr);
2451 encode_putfh(xdr, args->fh, &hdr);
2452 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002453
Benny Halevy28f56692009-04-01 09:22:09 -04002454 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002455 args->pgbase, args->count);
2456 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002457 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002458 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002459 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460}
2461
2462/*
2463 * Encode a READ request
2464 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002465static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002466 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002469 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
Chuck Lever9f06c712010-12-14 14:59:18 +00002472 encode_compound_hdr(xdr, req, &hdr);
2473 encode_sequence(xdr, &args->seq_args, &hdr);
2474 encode_putfh(xdr, args->fh, &hdr);
2475 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476
Benny Halevy28f56692009-04-01 09:22:09 -04002477 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002479 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002480 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481}
2482
2483/*
2484 * Encode an SETATTR request
2485 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002486static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2487 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488{
Andy Adamson05d564f2008-12-23 16:06:15 -05002489 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002490 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002491 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492
Chuck Lever9f06c712010-12-14 14:59:18 +00002493 encode_compound_hdr(xdr, req, &hdr);
2494 encode_sequence(xdr, &args->seq_args, &hdr);
2495 encode_putfh(xdr, args->fh, &hdr);
2496 encode_setattr(xdr, args, args->server, &hdr);
2497 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002498 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499}
2500
2501/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002502 * Encode a GETACL request
2503 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002504static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2505 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002506{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002507 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002508 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002509 };
Benny Halevy28f56692009-04-01 09:22:09 -04002510 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002511
Chuck Lever9f06c712010-12-14 14:59:18 +00002512 encode_compound_hdr(xdr, req, &hdr);
2513 encode_sequence(xdr, &args->seq_args, &hdr);
2514 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002515 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002516 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002517
Benny Halevy28f56692009-04-01 09:22:09 -04002518 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01002519 args->acl_pages, 0, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002520
Andy Adamsond0179312008-12-23 16:06:17 -05002521 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002522}
2523
2524/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 * Encode a WRITE request
2526 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002527static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002528 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002531 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533
Chuck Lever9f06c712010-12-14 14:59:18 +00002534 encode_compound_hdr(xdr, req, &hdr);
2535 encode_sequence(xdr, &args->seq_args, &hdr);
2536 encode_putfh(xdr, args->fh, &hdr);
2537 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002538 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002539 if (args->bitmask)
2540 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002541 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542}
2543
2544/*
2545 * a COMMIT request
2546 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002547static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002548 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002551 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553
Chuck Lever9f06c712010-12-14 14:59:18 +00002554 encode_compound_hdr(xdr, req, &hdr);
2555 encode_sequence(xdr, &args->seq_args, &hdr);
2556 encode_putfh(xdr, args->fh, &hdr);
2557 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002558 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559}
2560
2561/*
2562 * FSINFO request
2563 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002564static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2565 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002568 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570
Chuck Lever9f06c712010-12-14 14:59:18 +00002571 encode_compound_hdr(xdr, req, &hdr);
2572 encode_sequence(xdr, &args->seq_args, &hdr);
2573 encode_putfh(xdr, args->fh, &hdr);
2574 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002575 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576}
2577
2578/*
2579 * a PATHCONF request
2580 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002581static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2582 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002585 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587
Chuck Lever9f06c712010-12-14 14:59:18 +00002588 encode_compound_hdr(xdr, req, &hdr);
2589 encode_sequence(xdr, &args->seq_args, &hdr);
2590 encode_putfh(xdr, args->fh, &hdr);
2591 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002592 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002593 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594}
2595
2596/*
2597 * a STATFS request
2598 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002599static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2600 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002603 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605
Chuck Lever9f06c712010-12-14 14:59:18 +00002606 encode_compound_hdr(xdr, req, &hdr);
2607 encode_sequence(xdr, &args->seq_args, &hdr);
2608 encode_putfh(xdr, args->fh, &hdr);
2609 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002610 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002611 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612}
2613
2614/*
2615 * GETATTR_BITMAP request
2616 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002617static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2618 struct xdr_stream *xdr,
2619 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620{
Kinglong Mee8c612822015-08-26 21:12:58 +08002621 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002623 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625
Chuck Lever9f06c712010-12-14 14:59:18 +00002626 encode_compound_hdr(xdr, req, &hdr);
2627 encode_sequence(xdr, &args->seq_args, &hdr);
2628 encode_putfh(xdr, args->fhandle, &hdr);
Kinglong Mee8c612822015-08-26 21:12:58 +08002629 encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002630 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631}
2632
2633/*
2634 * a RENEW request
2635 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002636static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2637 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002640 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 };
2642
Chuck Lever9f06c712010-12-14 14:59:18 +00002643 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002644 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002645 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646}
2647
2648/*
2649 * a SETCLIENTID request
2650 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002651static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2652 struct xdr_stream *xdr,
2653 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002656 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 };
2658
Chuck Lever9f06c712010-12-14 14:59:18 +00002659 encode_compound_hdr(xdr, req, &hdr);
2660 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002661 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662}
2663
2664/*
2665 * a SETCLIENTID_CONFIRM request
2666 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002667static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2668 struct xdr_stream *xdr,
2669 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002672 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674
Chuck Lever9f06c712010-12-14 14:59:18 +00002675 encode_compound_hdr(xdr, req, &hdr);
2676 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002677 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678}
2679
2680/*
2681 * DELEGRETURN request
2682 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002683static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2684 struct xdr_stream *xdr,
2685 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002688 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690
Chuck Lever9f06c712010-12-14 14:59:18 +00002691 encode_compound_hdr(xdr, req, &hdr);
2692 encode_sequence(xdr, &args->seq_args, &hdr);
2693 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust586f1c32016-11-15 15:03:33 -05002694 if (args->lr_args)
2695 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05002696 if (args->bitmask)
2697 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002698 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002699 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700}
2701
2702/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002703 * Encode FS_LOCATIONS request
2704 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002705static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2706 struct xdr_stream *xdr,
2707 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002708{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002709 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002710 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002711 };
Benny Halevy28f56692009-04-01 09:22:09 -04002712 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002713
Chuck Lever9f06c712010-12-14 14:59:18 +00002714 encode_compound_hdr(xdr, req, &hdr);
2715 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002716 if (args->migration) {
2717 encode_putfh(xdr, args->fh, &hdr);
2718 replen = hdr.replen;
2719 encode_fs_locations(xdr, args->bitmask, &hdr);
2720 if (args->renew)
2721 encode_renew(xdr, args->clientid, &hdr);
2722 } else {
2723 encode_putfh(xdr, args->dir_fh, &hdr);
2724 encode_lookup(xdr, args->name, &hdr);
2725 replen = hdr.replen;
2726 encode_fs_locations(xdr, args->bitmask, &hdr);
2727 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002728
Chuck Leverb03d7352013-10-17 14:12:50 -04002729 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002730 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002731 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002732 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002733}
2734
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002735/*
2736 * Encode SECINFO request
2737 */
2738static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2739 struct xdr_stream *xdr,
2740 struct nfs4_secinfo_arg *args)
2741{
2742 struct compound_hdr hdr = {
2743 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2744 };
2745
2746 encode_compound_hdr(xdr, req, &hdr);
2747 encode_sequence(xdr, &args->seq_args, &hdr);
2748 encode_putfh(xdr, args->dir_fh, &hdr);
2749 encode_secinfo(xdr, args->name, &hdr);
2750 encode_nops(&hdr);
2751}
2752
Chuck Lever44c99932013-10-17 14:13:30 -04002753/*
2754 * Encode FSID_PRESENT request
2755 */
2756static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2757 struct xdr_stream *xdr,
2758 struct nfs4_fsid_present_arg *args)
2759{
2760 struct compound_hdr hdr = {
2761 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2762 };
2763
2764 encode_compound_hdr(xdr, req, &hdr);
2765 encode_sequence(xdr, &args->seq_args, &hdr);
2766 encode_putfh(xdr, args->fh, &hdr);
2767 encode_getfh(xdr, &hdr);
2768 if (args->renew)
2769 encode_renew(xdr, args->clientid, &hdr);
2770 encode_nops(&hdr);
2771}
2772
Benny Halevy99fe60d2009-04-01 09:22:29 -04002773#if defined(CONFIG_NFS_V4_1)
2774/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002775 * BIND_CONN_TO_SESSION request
2776 */
2777static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2778 struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08002779 struct nfs41_bind_conn_to_session_args *args)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002780{
2781 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002782 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002783 };
2784
2785 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002786 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002787 encode_nops(&hdr);
2788}
2789
2790/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002791 * EXCHANGE_ID request
2792 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002793static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2794 struct xdr_stream *xdr,
2795 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002796{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002797 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002798 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002799 };
2800
Chuck Lever9f06c712010-12-14 14:59:18 +00002801 encode_compound_hdr(xdr, req, &hdr);
2802 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002803 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002804}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002805
2806/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002807 * a CREATE_SESSION request
2808 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002809static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2810 struct xdr_stream *xdr,
2811 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002812{
Andy Adamsonfc931582009-04-01 09:22:31 -04002813 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002814 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002815 };
2816
Chuck Lever9f06c712010-12-14 14:59:18 +00002817 encode_compound_hdr(xdr, req, &hdr);
2818 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002819 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002820}
2821
2822/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002823 * a DESTROY_SESSION request
2824 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002825static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2826 struct xdr_stream *xdr,
2827 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002828{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002829 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002830 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002831 };
2832
Chuck Lever9f06c712010-12-14 14:59:18 +00002833 encode_compound_hdr(xdr, req, &hdr);
2834 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002835 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002836}
2837
2838/*
Trond Myklebust66245532012-05-25 17:18:09 -04002839 * a DESTROY_CLIENTID request
2840 */
2841static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2842 struct xdr_stream *xdr,
2843 struct nfs_client *clp)
2844{
2845 struct compound_hdr hdr = {
2846 .minorversion = clp->cl_mvops->minor_version,
2847 };
2848
2849 encode_compound_hdr(xdr, req, &hdr);
2850 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2851 encode_nops(&hdr);
2852}
2853
2854/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002855 * a SEQUENCE request
2856 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002857static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2858 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002859{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002860 struct compound_hdr hdr = {
2861 .minorversion = nfs4_xdr_minorversion(args),
2862 };
2863
Chuck Lever9f06c712010-12-14 14:59:18 +00002864 encode_compound_hdr(xdr, req, &hdr);
2865 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002866 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002867}
2868
2869/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002870 * a GET_LEASE_TIME request
2871 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002872static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2873 struct xdr_stream *xdr,
2874 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002875{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002876 struct compound_hdr hdr = {
2877 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2878 };
Fred Isamandae100c2011-07-30 20:52:37 -04002879 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002880
Chuck Lever9f06c712010-12-14 14:59:18 +00002881 encode_compound_hdr(xdr, req, &hdr);
2882 encode_sequence(xdr, &args->la_seq_args, &hdr);
2883 encode_putrootfh(xdr, &hdr);
2884 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002885 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002886}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002887
2888/*
2889 * a RECLAIM_COMPLETE request
2890 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002891static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2892 struct xdr_stream *xdr,
2893 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002894{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002895 struct compound_hdr hdr = {
2896 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2897 };
2898
Chuck Lever9f06c712010-12-14 14:59:18 +00002899 encode_compound_hdr(xdr, req, &hdr);
2900 encode_sequence(xdr, &args->seq_args, &hdr);
2901 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002902 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002903}
2904
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002905/*
2906 * Encode GETDEVICEINFO request
2907 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002908static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2909 struct xdr_stream *xdr,
2910 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002911{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002912 struct compound_hdr hdr = {
2913 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2914 };
2915
Chuck Lever9f06c712010-12-14 14:59:18 +00002916 encode_compound_hdr(xdr, req, &hdr);
2917 encode_sequence(xdr, &args->seq_args, &hdr);
2918 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002919
2920 /* set up reply kvec. Subtract notification bitmap max size (2)
2921 * so that notification bitmap is put in xdr_buf tail */
2922 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2923 args->pdev->pages, args->pdev->pgbase,
2924 args->pdev->pglen);
2925
2926 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002927}
2928
2929/*
2930 * Encode LAYOUTGET request
2931 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002932static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2933 struct xdr_stream *xdr,
2934 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002935{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002936 struct compound_hdr hdr = {
2937 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2938 };
2939
Chuck Lever9f06c712010-12-14 14:59:18 +00002940 encode_compound_hdr(xdr, req, &hdr);
2941 encode_sequence(xdr, &args->seq_args, &hdr);
2942 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2943 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002944
2945 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2946 args->layout.pages, 0, args->layout.pglen);
2947
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002948 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002949}
Andy Adamson863a3c62011-03-23 13:27:54 +00002950
2951/*
2952 * Encode LAYOUTCOMMIT request
2953 */
Benny Halevycbe82602011-05-22 19:52:37 +03002954static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2955 struct xdr_stream *xdr,
2956 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002957{
Benny Halevyac7db722011-05-22 19:53:48 +03002958 struct nfs4_layoutcommit_data *data =
2959 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002960 struct compound_hdr hdr = {
2961 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2962 };
2963
2964 encode_compound_hdr(xdr, req, &hdr);
2965 encode_sequence(xdr, &args->seq_args, &hdr);
2966 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002967 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002968 encode_getfattr(xdr, args->bitmask, &hdr);
2969 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002970}
2971
2972/*
2973 * Encode LAYOUTRETURN request
2974 */
2975static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2976 struct xdr_stream *xdr,
2977 struct nfs4_layoutreturn_args *args)
2978{
2979 struct compound_hdr hdr = {
2980 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2981 };
2982
2983 encode_compound_hdr(xdr, req, &hdr);
2984 encode_sequence(xdr, &args->seq_args, &hdr);
2985 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2986 encode_layoutreturn(xdr, args, &hdr);
2987 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002988}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002989
2990/*
2991 * Encode SECINFO_NO_NAME request
2992 */
2993static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2994 struct xdr_stream *xdr,
2995 struct nfs41_secinfo_no_name_args *args)
2996{
2997 struct compound_hdr hdr = {
2998 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2999 };
3000
3001 encode_compound_hdr(xdr, req, &hdr);
3002 encode_sequence(xdr, &args->seq_args, &hdr);
3003 encode_putrootfh(xdr, &hdr);
3004 encode_secinfo_no_name(xdr, args, &hdr);
3005 encode_nops(&hdr);
3006 return 0;
3007}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003008
3009/*
3010 * Encode TEST_STATEID request
3011 */
3012static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3013 struct xdr_stream *xdr,
3014 struct nfs41_test_stateid_args *args)
3015{
3016 struct compound_hdr hdr = {
3017 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3018 };
3019
3020 encode_compound_hdr(xdr, req, &hdr);
3021 encode_sequence(xdr, &args->seq_args, &hdr);
3022 encode_test_stateid(xdr, args, &hdr);
3023 encode_nops(&hdr);
3024}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003025
3026/*
3027 * Encode FREE_STATEID request
3028 */
3029static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3030 struct xdr_stream *xdr,
3031 struct nfs41_free_stateid_args *args)
3032{
3033 struct compound_hdr hdr = {
3034 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3035 };
3036
3037 encode_compound_hdr(xdr, req, &hdr);
3038 encode_sequence(xdr, &args->seq_args, &hdr);
3039 encode_free_stateid(xdr, args, &hdr);
3040 encode_nops(&hdr);
3041}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003042#endif /* CONFIG_NFS_V4_1 */
3043
Benny Halevy686841b2009-08-14 17:19:48 +03003044static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3045{
3046 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3047 "Remaining buffer length is %tu words.\n",
3048 func, xdr->end - xdr->p);
3049}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050
Trond Myklebust683b57b2006-06-09 09:34:22 -04003051static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052{
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003053 ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3054 NFS4_OPAQUE_LIMIT);
3055 if (unlikely(ret < 0)) {
3056 if (ret == -EBADMSG)
3057 print_overflow_msg(__func__, xdr);
3058 return -EIO;
3059 }
3060 *len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 return 0;
3062}
3063
3064static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3065{
Al Viro8687b632006-10-19 23:28:48 -07003066 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067
Benny Halevyc0eae662009-08-14 17:20:14 +03003068 p = xdr_inline_decode(xdr, 8);
3069 if (unlikely(!p))
3070 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003071 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003072 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003073
Benny Halevyc0eae662009-08-14 17:20:14 +03003074 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3075 if (unlikely(!p))
3076 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 hdr->tag = (char *)p;
3078 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003079 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003080 if (unlikely(hdr->nops < 1))
3081 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003083out_overflow:
3084 print_overflow_msg(__func__, xdr);
3085 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086}
3087
Trond Myklebustc7848f62013-12-04 17:39:23 -05003088static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3089 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090{
Al Viro8687b632006-10-19 23:28:48 -07003091 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 uint32_t opnum;
3093 int32_t nfserr;
3094
Benny Halevyc0eae662009-08-14 17:20:14 +03003095 p = xdr_inline_decode(xdr, 8);
3096 if (unlikely(!p))
3097 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003098 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003099 if (unlikely(opnum != expected))
3100 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003101 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003102 if (nfserr == NFS_OK)
3103 *nfs_retval = 0;
3104 else
3105 *nfs_retval = nfs4_stat_to_errno(nfserr);
3106 return true;
3107out_bad_operation:
3108 dprintk("nfs: Server returned operation"
3109 " %d but we issued a request for %d\n",
3110 opnum, expected);
3111 *nfs_retval = -EREMOTEIO;
3112 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003113out_overflow:
3114 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003115 *nfs_retval = -EIO;
3116 return false;
3117}
3118
3119static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3120{
3121 int retval;
3122
3123 __decode_op_hdr(xdr, expected, &retval);
3124 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125}
3126
3127/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003128static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129{
Al Viro8687b632006-10-19 23:28:48 -07003130 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003131 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 char *str;
3133
Benny Halevyc0eae662009-08-14 17:20:14 +03003134 p = xdr_inline_decode(xdr, 12);
3135 if (likely(p))
3136 return decode_opaque_inline(xdr, &strlen, &str);
3137 print_overflow_msg(__func__, xdr);
3138 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139}
3140
3141static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3142{
Al Viro8687b632006-10-19 23:28:48 -07003143 uint32_t bmlen;
3144 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145
Benny Halevyc0eae662009-08-14 17:20:14 +03003146 p = xdr_inline_decode(xdr, 4);
3147 if (unlikely(!p))
3148 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003149 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150
Fred Isamandae100c2011-07-30 20:52:37 -04003151 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003152 p = xdr_inline_decode(xdr, (bmlen << 2));
3153 if (unlikely(!p))
3154 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003156 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003157 if (bmlen > 1) {
3158 bitmap[1] = be32_to_cpup(p++);
3159 if (bmlen > 2)
3160 bitmap[2] = be32_to_cpup(p);
3161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 }
3163 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003164out_overflow:
3165 print_overflow_msg(__func__, xdr);
3166 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167}
3168
Trond Myklebust256e48b2012-06-21 11:18:13 -04003169static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170{
Al Viro8687b632006-10-19 23:28:48 -07003171 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172
Benny Halevyc0eae662009-08-14 17:20:14 +03003173 p = xdr_inline_decode(xdr, 4);
3174 if (unlikely(!p))
3175 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003176 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003177 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003179out_overflow:
3180 print_overflow_msg(__func__, xdr);
3181 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182}
3183
3184static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3185{
3186 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003187 int ret;
3188 ret = decode_attr_bitmap(xdr, bitmask);
3189 if (unlikely(ret < 0))
3190 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3192 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003193 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3194 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3195 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 return 0;
3197}
3198
3199static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3200{
Al Viro8687b632006-10-19 23:28:48 -07003201 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003202 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203
3204 *type = 0;
3205 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3206 return -EIO;
3207 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003208 p = xdr_inline_decode(xdr, 4);
3209 if (unlikely(!p))
3210 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003211 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003213 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 return -EIO;
3215 }
3216 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003217 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003219 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003220 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003221out_overflow:
3222 print_overflow_msg(__func__, xdr);
3223 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224}
3225
Chuck Lever264e6352012-03-01 17:02:05 -05003226static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3227 uint32_t *bitmap, uint32_t *type)
3228{
3229 __be32 *p;
3230
3231 *type = 0;
3232 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3233 return -EIO;
3234 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3235 p = xdr_inline_decode(xdr, 4);
3236 if (unlikely(!p))
3237 goto out_overflow;
3238 *type = be32_to_cpup(p);
3239 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3240 }
3241 dprintk("%s: expire type=0x%x\n", __func__, *type);
3242 return 0;
3243out_overflow:
3244 print_overflow_msg(__func__, xdr);
3245 return -EIO;
3246}
3247
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3249{
Al Viro8687b632006-10-19 23:28:48 -07003250 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003251 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252
3253 *change = 0;
3254 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3255 return -EIO;
3256 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003257 p = xdr_inline_decode(xdr, 8);
3258 if (unlikely(!p))
3259 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003260 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003262 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003264 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003266 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003267out_overflow:
3268 print_overflow_msg(__func__, xdr);
3269 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270}
3271
3272static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3273{
Al Viro8687b632006-10-19 23:28:48 -07003274 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003275 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276
3277 *size = 0;
3278 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3279 return -EIO;
3280 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003281 p = xdr_inline_decode(xdr, 8);
3282 if (unlikely(!p))
3283 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003284 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003286 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003288 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003289 return ret;
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_link_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_LINK_SUPPORT - 1U)))
3301 return -EIO;
3302 if (likely(bitmap[0] & FATTR4_WORD0_LINK_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_LINK_SUPPORT;
3308 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003309 dprintk("%s: link 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
3316static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3317{
Al Viro8687b632006-10-19 23:28:48 -07003318 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319
3320 *res = 0;
3321 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3322 return -EIO;
3323 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003324 p = xdr_inline_decode(xdr, 4);
3325 if (unlikely(!p))
3326 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003327 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3329 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003330 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003332out_overflow:
3333 print_overflow_msg(__func__, xdr);
3334 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335}
3336
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003337static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338{
Al Viro8687b632006-10-19 23:28:48 -07003339 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003340 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341
3342 fsid->major = 0;
3343 fsid->minor = 0;
3344 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3345 return -EIO;
3346 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003347 p = xdr_inline_decode(xdr, 16);
3348 if (unlikely(!p))
3349 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003350 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003351 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003353 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003355 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 (unsigned long long)fsid->major,
3357 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003358 return ret;
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
3364static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3365{
Al Viro8687b632006-10-19 23:28:48 -07003366 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367
3368 *res = 60;
3369 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3370 return -EIO;
3371 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003372 p = xdr_inline_decode(xdr, 4);
3373 if (unlikely(!p))
3374 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003375 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3377 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003378 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003380out_overflow:
3381 print_overflow_msg(__func__, xdr);
3382 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383}
3384
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003385static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003386{
3387 __be32 *p;
3388
3389 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3390 return -EIO;
3391 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3392 p = xdr_inline_decode(xdr, 4);
3393 if (unlikely(!p))
3394 goto out_overflow;
3395 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003396 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003397 }
3398 return 0;
3399out_overflow:
3400 print_overflow_msg(__func__, xdr);
3401 return -EIO;
3402}
3403
Kinglong Mee8c612822015-08-26 21:12:58 +08003404static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3405 uint32_t *bitmap, uint32_t *bitmask)
3406{
3407 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3408 int ret;
3409 ret = decode_attr_bitmap(xdr, bitmask);
3410 if (unlikely(ret < 0))
3411 return ret;
3412 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3413 } else
3414 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3415 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3416 bitmask[0], bitmask[1], bitmask[2]);
3417 return 0;
3418}
3419
Bryan Schumakerae42c702010-10-21 16:33:17 -04003420static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3421{
3422 __be32 *p;
3423 int len;
3424
Trond Myklebust7ad07352010-10-23 15:34:20 -04003425 if (fh != NULL)
3426 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003427
3428 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3429 return -EIO;
3430 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3431 p = xdr_inline_decode(xdr, 4);
3432 if (unlikely(!p))
3433 goto out_overflow;
3434 len = be32_to_cpup(p);
3435 if (len > NFS4_FHSIZE)
3436 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003437 p = xdr_inline_decode(xdr, len);
3438 if (unlikely(!p))
3439 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003440 if (fh != NULL) {
3441 memcpy(fh->data, p, len);
3442 fh->size = len;
3443 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003444 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3445 }
3446 return 0;
3447out_overflow:
3448 print_overflow_msg(__func__, xdr);
3449 return -EIO;
3450}
3451
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3453{
Al Viro8687b632006-10-19 23:28:48 -07003454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003456 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3458 return -EIO;
3459 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003460 p = xdr_inline_decode(xdr, 4);
3461 if (unlikely(!p))
3462 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003463 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3465 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003466 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003468out_overflow:
3469 print_overflow_msg(__func__, xdr);
3470 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471}
3472
3473static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3474{
Al Viro8687b632006-10-19 23:28:48 -07003475 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003476 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477
3478 *fileid = 0;
3479 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3480 return -EIO;
3481 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003482 p = xdr_inline_decode(xdr, 8);
3483 if (unlikely(!p))
3484 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003485 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003487 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003489 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003490 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003491out_overflow:
3492 print_overflow_msg(__func__, xdr);
3493 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494}
3495
Manoj Naik99baf622006-06-09 09:34:24 -04003496static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3497{
Al Viro8687b632006-10-19 23:28:48 -07003498 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003499 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003500
3501 *fileid = 0;
3502 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3503 return -EIO;
3504 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003505 p = xdr_inline_decode(xdr, 8);
3506 if (unlikely(!p))
3507 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003508 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003509 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003510 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003511 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003512 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003513 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003514out_overflow:
3515 print_overflow_msg(__func__, xdr);
3516 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003517}
3518
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3520{
Al Viro8687b632006-10-19 23:28:48 -07003521 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 int status = 0;
3523
3524 *res = 0;
3525 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3526 return -EIO;
3527 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003528 p = xdr_inline_decode(xdr, 8);
3529 if (unlikely(!p))
3530 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003531 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3533 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003534 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003536out_overflow:
3537 print_overflow_msg(__func__, xdr);
3538 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539}
3540
3541static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3542{
Al Viro8687b632006-10-19 23:28:48 -07003543 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 int status = 0;
3545
3546 *res = 0;
3547 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3548 return -EIO;
3549 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003550 p = xdr_inline_decode(xdr, 8);
3551 if (unlikely(!p))
3552 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003553 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3555 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003556 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003558out_overflow:
3559 print_overflow_msg(__func__, xdr);
3560 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561}
3562
3563static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3564{
Al Viro8687b632006-10-19 23:28:48 -07003565 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566 int status = 0;
3567
3568 *res = 0;
3569 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3570 return -EIO;
3571 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003572 p = xdr_inline_decode(xdr, 8);
3573 if (unlikely(!p))
3574 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003575 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3577 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003578 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003580out_overflow:
3581 print_overflow_msg(__func__, xdr);
3582 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583}
3584
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003585static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3586{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003587 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003588 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003589 int status = 0;
3590
Benny Halevyc0eae662009-08-14 17:20:14 +03003591 p = xdr_inline_decode(xdr, 4);
3592 if (unlikely(!p))
3593 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003594 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003595 if (n == 0)
3596 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003597 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003598 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3599 dprintk("cannot parse %d components in path\n", n);
3600 goto out_eio;
3601 }
3602 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003603 struct nfs4_string *component = &path->components[path->ncomponents];
3604 status = decode_opaque_inline(xdr, &component->len, &component->data);
3605 if (unlikely(status != 0))
3606 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003607 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003608 pr_cont("%s%.*s ",
3609 (path->ncomponents != n ? "/ " : ""),
3610 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003611 }
3612out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003613 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003614root_path:
3615/* a root pathname is sent as a zero component4 */
3616 path->ncomponents = 1;
3617 path->components[0].len=0;
3618 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003619 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003620 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003621out_eio:
3622 dprintk(" status %d", status);
3623 status = -EIO;
3624 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003625out_overflow:
3626 print_overflow_msg(__func__, xdr);
3627 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003628}
3629
3630static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003631{
3632 int n;
Al Viro8687b632006-10-19 23:28:48 -07003633 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003634 int status = -EIO;
3635
3636 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3637 goto out;
3638 status = 0;
3639 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3640 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003641 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003642 status = -EIO;
3643 /* Ignore borken servers that return unrequested attrs */
3644 if (unlikely(res == NULL))
3645 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003646 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003647 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003648 if (unlikely(status != 0))
3649 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003650 p = xdr_inline_decode(xdr, 4);
3651 if (unlikely(!p))
3652 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003653 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003654 if (n <= 0)
3655 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003656 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003657 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003658 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003659
Trond Myklebust809b4262013-03-27 11:54:45 -04003660 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3661 break;
3662 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003663 p = xdr_inline_decode(xdr, 4);
3664 if (unlikely(!p))
3665 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003666 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003667
Chuck Lever02a29762012-03-01 17:00:31 -05003668 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003669 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3670 struct nfs4_string *server;
3671
3672 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003673 unsigned int i;
3674 dprintk("%s: using first %u of %u servers "
3675 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003676 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003677 NFS4_FS_LOCATION_MAXSERVERS,
3678 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003679 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003680 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003681 char *data;
3682 status = decode_opaque_inline(xdr, &len, &data);
3683 if (unlikely(status != 0))
3684 goto out_eio;
3685 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003686 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003687 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003688 server = &loc->servers[loc->nservers];
3689 status = decode_opaque_inline(xdr, &server->len, &server->data);
3690 if (unlikely(status != 0))
3691 goto out_eio;
3692 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003693 }
3694 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003695 if (unlikely(status != 0))
3696 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003697 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003698 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003699 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003700out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003701 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003702 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003703out_overflow:
3704 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003705out_eio:
3706 status = -EIO;
3707 goto out;
3708}
3709
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3711{
Al Viro8687b632006-10-19 23:28:48 -07003712 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 int status = 0;
3714
3715 *res = 0;
3716 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3717 return -EIO;
3718 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003719 p = xdr_inline_decode(xdr, 8);
3720 if (unlikely(!p))
3721 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003722 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3724 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003725 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003727out_overflow:
3728 print_overflow_msg(__func__, xdr);
3729 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730}
3731
3732static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3733{
Al Viro8687b632006-10-19 23:28:48 -07003734 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 int status = 0;
3736
3737 *maxlink = 1;
3738 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3739 return -EIO;
3740 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003741 p = xdr_inline_decode(xdr, 4);
3742 if (unlikely(!p))
3743 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003744 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3746 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003747 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003749out_overflow:
3750 print_overflow_msg(__func__, xdr);
3751 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752}
3753
3754static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3755{
Al Viro8687b632006-10-19 23:28:48 -07003756 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757 int status = 0;
3758
3759 *maxname = 1024;
3760 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3761 return -EIO;
3762 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003763 p = xdr_inline_decode(xdr, 4);
3764 if (unlikely(!p))
3765 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003766 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3768 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003769 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003771out_overflow:
3772 print_overflow_msg(__func__, xdr);
3773 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774}
3775
3776static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3777{
Al Viro8687b632006-10-19 23:28:48 -07003778 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 int status = 0;
3780
3781 *res = 1024;
3782 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3783 return -EIO;
3784 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3785 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003786 p = xdr_inline_decode(xdr, 8);
3787 if (unlikely(!p))
3788 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003789 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 if (maxread > 0x7FFFFFFF)
3791 maxread = 0x7FFFFFFF;
3792 *res = (uint32_t)maxread;
3793 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3794 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003795 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003797out_overflow:
3798 print_overflow_msg(__func__, xdr);
3799 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800}
3801
3802static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3803{
Al Viro8687b632006-10-19 23:28:48 -07003804 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 int status = 0;
3806
3807 *res = 1024;
3808 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3809 return -EIO;
3810 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3811 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003812 p = xdr_inline_decode(xdr, 8);
3813 if (unlikely(!p))
3814 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003815 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 if (maxwrite > 0x7FFFFFFF)
3817 maxwrite = 0x7FFFFFFF;
3818 *res = (uint32_t)maxwrite;
3819 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3820 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003821 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003823out_overflow:
3824 print_overflow_msg(__func__, xdr);
3825 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826}
3827
Trond Myklebustbca79472009-03-11 14:10:26 -04003828static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829{
Trond Myklebustbca79472009-03-11 14:10:26 -04003830 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003831 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003832 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833
3834 *mode = 0;
3835 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3836 return -EIO;
3837 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003838 p = xdr_inline_decode(xdr, 4);
3839 if (unlikely(!p))
3840 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003841 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003842 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003844 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003846 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003847 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003848out_overflow:
3849 print_overflow_msg(__func__, xdr);
3850 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851}
3852
3853static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3854{
Al Viro8687b632006-10-19 23:28:48 -07003855 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003856 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857
3858 *nlink = 1;
3859 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3860 return -EIO;
3861 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003862 p = xdr_inline_decode(xdr, 4);
3863 if (unlikely(!p))
3864 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003865 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003867 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003869 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003870 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003871out_overflow:
3872 print_overflow_msg(__func__, xdr);
3873 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874}
3875
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003876static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003877 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003878 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879{
Al Viro8687b632006-10-19 23:28:48 -07003880 uint32_t len;
3881 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003882 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883
Eric W. Biedermane5782072013-02-01 14:22:02 -08003884 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3886 return -EIO;
3887 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003888 p = xdr_inline_decode(xdr, 4);
3889 if (unlikely(!p))
3890 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003891 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003892 p = xdr_inline_decode(xdr, len);
3893 if (unlikely(!p))
3894 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003895 if (owner_name != NULL) {
3896 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3897 if (owner_name->data != NULL) {
3898 owner_name->len = len;
3899 ret = NFS_ATTR_FATTR_OWNER_NAME;
3900 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003901 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003902 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003903 ret = NFS_ATTR_FATTR_OWNER;
3904 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003906 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003908 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003909 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3911 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003912 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003913 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003914out_overflow:
3915 print_overflow_msg(__func__, xdr);
3916 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917}
3918
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003919static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003920 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003921 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922{
Al Viro8687b632006-10-19 23:28:48 -07003923 uint32_t len;
3924 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003925 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926
Eric W. Biedermane5782072013-02-01 14:22:02 -08003927 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3929 return -EIO;
3930 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003931 p = xdr_inline_decode(xdr, 4);
3932 if (unlikely(!p))
3933 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003934 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003935 p = xdr_inline_decode(xdr, len);
3936 if (unlikely(!p))
3937 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003938 if (group_name != NULL) {
3939 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3940 if (group_name->data != NULL) {
3941 group_name->len = len;
3942 ret = NFS_ATTR_FATTR_GROUP_NAME;
3943 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003944 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003945 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003946 ret = NFS_ATTR_FATTR_GROUP;
3947 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003949 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003951 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003952 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3954 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003955 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003956 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003957out_overflow:
3958 print_overflow_msg(__func__, xdr);
3959 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960}
3961
3962static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3963{
Al Viro8687b632006-10-19 23:28:48 -07003964 uint32_t major = 0, minor = 0;
3965 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003966 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967
3968 *rdev = MKDEV(0,0);
3969 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3970 return -EIO;
3971 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3972 dev_t tmp;
3973
Benny Halevyc0eae662009-08-14 17:20:14 +03003974 p = xdr_inline_decode(xdr, 8);
3975 if (unlikely(!p))
3976 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003977 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003978 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 tmp = MKDEV(major, minor);
3980 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3981 *rdev = tmp;
3982 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003983 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003985 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003986 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003987out_overflow:
3988 print_overflow_msg(__func__, xdr);
3989 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990}
3991
3992static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3993{
Al Viro8687b632006-10-19 23:28:48 -07003994 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 int status = 0;
3996
3997 *res = 0;
3998 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3999 return -EIO;
4000 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004001 p = xdr_inline_decode(xdr, 8);
4002 if (unlikely(!p))
4003 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004004 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4006 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004007 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004009out_overflow:
4010 print_overflow_msg(__func__, xdr);
4011 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012}
4013
4014static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4015{
Al Viro8687b632006-10-19 23:28:48 -07004016 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 int status = 0;
4018
4019 *res = 0;
4020 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4021 return -EIO;
4022 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004023 p = xdr_inline_decode(xdr, 8);
4024 if (unlikely(!p))
4025 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004026 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4028 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004029 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004031out_overflow:
4032 print_overflow_msg(__func__, xdr);
4033 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034}
4035
4036static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4037{
Al Viro8687b632006-10-19 23:28:48 -07004038 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039 int status = 0;
4040
4041 *res = 0;
4042 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4043 return -EIO;
4044 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004045 p = xdr_inline_decode(xdr, 8);
4046 if (unlikely(!p))
4047 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004048 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4050 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004051 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004053out_overflow:
4054 print_overflow_msg(__func__, xdr);
4055 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056}
4057
4058static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4059{
Al Viro8687b632006-10-19 23:28:48 -07004060 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004061 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062
4063 *used = 0;
4064 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4065 return -EIO;
4066 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004067 p = xdr_inline_decode(xdr, 8);
4068 if (unlikely(!p))
4069 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004070 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004072 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004074 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004076 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004077out_overflow:
4078 print_overflow_msg(__func__, xdr);
4079 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080}
4081
4082static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4083{
Al Viro8687b632006-10-19 23:28:48 -07004084 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 uint64_t sec;
4086 uint32_t nsec;
4087
Benny Halevyc0eae662009-08-14 17:20:14 +03004088 p = xdr_inline_decode(xdr, 12);
4089 if (unlikely(!p))
4090 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004091 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004092 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093 time->tv_sec = (time_t)sec;
4094 time->tv_nsec = (long)nsec;
4095 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004096out_overflow:
4097 print_overflow_msg(__func__, xdr);
4098 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099}
4100
4101static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4102{
4103 int status = 0;
4104
4105 time->tv_sec = 0;
4106 time->tv_nsec = 0;
4107 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4108 return -EIO;
4109 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4110 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004111 if (status == 0)
4112 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4114 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004115 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116 return status;
4117}
4118
4119static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4120{
4121 int status = 0;
4122
4123 time->tv_sec = 0;
4124 time->tv_nsec = 0;
4125 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4126 return -EIO;
4127 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4128 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004129 if (status == 0)
4130 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4132 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004133 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 return status;
4135}
4136
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004137static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4138 struct timespec *time)
4139{
4140 int status = 0;
4141
4142 time->tv_sec = 0;
4143 time->tv_nsec = 0;
4144 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4145 return -EIO;
4146 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4147 status = decode_attr_time(xdr, time);
4148 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4149 }
4150 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4151 (long)time->tv_nsec);
4152 return status;
4153}
4154
David Quigleyaa9c2662013-05-22 12:50:44 -04004155static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4156 struct nfs4_label *label)
4157{
4158 uint32_t pi = 0;
4159 uint32_t lfs = 0;
4160 __u32 len;
4161 __be32 *p;
4162 int status = 0;
4163
4164 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4165 return -EIO;
4166 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4167 p = xdr_inline_decode(xdr, 4);
4168 if (unlikely(!p))
4169 goto out_overflow;
4170 lfs = be32_to_cpup(p++);
4171 p = xdr_inline_decode(xdr, 4);
4172 if (unlikely(!p))
4173 goto out_overflow;
4174 pi = be32_to_cpup(p++);
4175 p = xdr_inline_decode(xdr, 4);
4176 if (unlikely(!p))
4177 goto out_overflow;
4178 len = be32_to_cpup(p++);
4179 p = xdr_inline_decode(xdr, len);
4180 if (unlikely(!p))
4181 goto out_overflow;
4182 if (len < NFS4_MAXLABELLEN) {
4183 if (label) {
4184 memcpy(label->label, p, len);
4185 label->len = len;
4186 label->pi = pi;
4187 label->lfs = lfs;
4188 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4189 }
4190 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4191 } else
4192 printk(KERN_WARNING "%s: label too long (%u)!\n",
4193 __func__, len);
4194 }
4195 if (label && label->label)
4196 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4197 (char *)label->label, label->len, label->pi, label->lfs);
4198 return status;
4199
4200out_overflow:
4201 print_overflow_msg(__func__, xdr);
4202 return -EIO;
4203}
4204
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4206{
4207 int status = 0;
4208
4209 time->tv_sec = 0;
4210 time->tv_nsec = 0;
4211 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4212 return -EIO;
4213 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4214 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004215 if (status == 0)
4216 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4218 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004219 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 return status;
4221}
4222
Trond Myklebust256e48b2012-06-21 11:18:13 -04004223static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224{
4225 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004226 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227
4228 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004229 dprintk("%s: server returned incorrect attribute length: "
4230 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004231 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232 attrwords << 2,
4233 (attrwords < nwords) ? '<' : '>',
4234 nwords << 2);
4235 return -EIO;
4236 }
4237 return 0;
4238}
4239
4240static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4241{
Al Viro8687b632006-10-19 23:28:48 -07004242 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243
Benny Halevyc0eae662009-08-14 17:20:14 +03004244 p = xdr_inline_decode(xdr, 20);
4245 if (unlikely(!p))
4246 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004247 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004248 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004249 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004251out_overflow:
4252 print_overflow_msg(__func__, xdr);
4253 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254}
4255
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004256static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257{
Al Viro8687b632006-10-19 23:28:48 -07004258 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004259 uint32_t supp, acc;
4260 int status;
4261
4262 status = decode_op_hdr(xdr, OP_ACCESS);
4263 if (status)
4264 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004265 p = xdr_inline_decode(xdr, 8);
4266 if (unlikely(!p))
4267 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004268 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004269 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004270 *supported = supp;
4271 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004273out_overflow:
4274 print_overflow_msg(__func__, xdr);
4275 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276}
4277
Benny Halevy07d30432009-08-14 17:19:52 +03004278static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004280 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4281 if (unlikely(ret < 0)) {
4282 print_overflow_msg(__func__, xdr);
4283 return -EIO;
Benny Halevy07d30432009-08-14 17:19:52 +03004284 }
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004285 return 0;
Benny Halevy07d30432009-08-14 17:19:52 +03004286}
4287
4288static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4289{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004290 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291}
4292
Trond Myklebust93b717f2016-05-16 17:42:43 -04004293static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4294{
4295 stateid->type = NFS4_OPEN_STATEID_TYPE;
4296 return decode_stateid(xdr, stateid);
4297}
4298
4299static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4300{
4301 stateid->type = NFS4_LOCK_STATEID_TYPE;
4302 return decode_stateid(xdr, stateid);
4303}
4304
4305static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4306{
4307 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4308 return decode_stateid(xdr, stateid);
4309}
4310
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4312{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004313 int status;
4314
4315 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004316 if (status != -EIO)
4317 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004318 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04004319 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004320 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321}
4322
Benny Halevydb942bb2009-08-14 17:19:56 +03004323static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4324{
Chuck Levercd937102012-03-02 17:14:31 -05004325 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326}
4327
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004328static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4329{
4330 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4331}
4332
Fred Isaman0b7c0152012-04-20 14:47:39 -04004333static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004335 int status;
4336
4337 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004338 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004339 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004340 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004341}
4342
4343static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4344{
Al Viro8687b632006-10-19 23:28:48 -07004345 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346 uint32_t bmlen;
4347 int status;
4348
4349 status = decode_op_hdr(xdr, OP_CREATE);
4350 if (status)
4351 return status;
4352 if ((status = decode_change_info(xdr, cinfo)))
4353 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004354 p = xdr_inline_decode(xdr, 4);
4355 if (unlikely(!p))
4356 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004357 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004358 p = xdr_inline_decode(xdr, bmlen << 2);
4359 if (likely(p))
4360 return 0;
4361out_overflow:
4362 print_overflow_msg(__func__, xdr);
4363 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004364}
4365
4366static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4367{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004368 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004369 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004370 int status;
4371
4372 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4373 goto xdr_error;
4374 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4375 goto xdr_error;
4376 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4377 goto xdr_error;
4378 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4379 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004380 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4381 &res->fh_expire_type)) != 0)
4382 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004383 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4384 goto xdr_error;
4385 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4386 goto xdr_error;
4387 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4388 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004389 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4390 res->exclcreat_bitmask)) != 0)
4391 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392 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}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004397
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4399{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004400 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004401 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004403
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4405 goto xdr_error;
4406 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4407 goto xdr_error;
4408 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4409 goto xdr_error;
4410
4411 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4412 goto xdr_error;
4413 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4414 goto xdr_error;
4415 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4416 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004417
4418 status = -EIO;
4419 if (unlikely(bitmap[0]))
4420 goto xdr_error;
4421
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4423 goto xdr_error;
4424 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4425 goto xdr_error;
4426 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4427 goto xdr_error;
4428
4429 status = verify_attr_len(xdr, savep, attrlen);
4430xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004431 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004432 return status;
4433}
4434
4435static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4436{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004437 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004438 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004439 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004440
Linus Torvalds1da177e2005-04-16 15:20:36 -07004441 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4442 goto xdr_error;
4443 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4444 goto xdr_error;
4445 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4446 goto xdr_error;
4447
4448 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4449 goto xdr_error;
4450 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4451 goto xdr_error;
4452
4453 status = verify_attr_len(xdr, savep, attrlen);
4454xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004455 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004456 return status;
4457}
4458
Andy Adamson88034c32012-05-23 05:02:34 -04004459static int decode_threshold_hint(struct xdr_stream *xdr,
4460 uint32_t *bitmap,
4461 uint64_t *res,
4462 uint32_t hint_bit)
4463{
4464 __be32 *p;
4465
4466 *res = 0;
4467 if (likely(bitmap[0] & hint_bit)) {
4468 p = xdr_inline_decode(xdr, 8);
4469 if (unlikely(!p))
4470 goto out_overflow;
4471 xdr_decode_hyper(p, res);
4472 }
4473 return 0;
4474out_overflow:
4475 print_overflow_msg(__func__, xdr);
4476 return -EIO;
4477}
4478
4479static int decode_first_threshold_item4(struct xdr_stream *xdr,
4480 struct nfs4_threshold *res)
4481{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004482 __be32 *p;
4483 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004484 uint32_t bitmap[3] = {0,}, attrlen;
4485 int status;
4486
4487 /* layout type */
4488 p = xdr_inline_decode(xdr, 4);
4489 if (unlikely(!p)) {
4490 print_overflow_msg(__func__, xdr);
4491 return -EIO;
4492 }
4493 res->l_type = be32_to_cpup(p);
4494
4495 /* thi_hintset bitmap */
4496 status = decode_attr_bitmap(xdr, bitmap);
4497 if (status < 0)
4498 goto xdr_error;
4499
4500 /* thi_hintlist length */
4501 status = decode_attr_length(xdr, &attrlen, &savep);
4502 if (status < 0)
4503 goto xdr_error;
4504 /* thi_hintlist */
4505 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4506 if (status < 0)
4507 goto xdr_error;
4508 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4509 if (status < 0)
4510 goto xdr_error;
4511 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4512 THRESHOLD_RD_IO);
4513 if (status < 0)
4514 goto xdr_error;
4515 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4516 THRESHOLD_WR_IO);
4517 if (status < 0)
4518 goto xdr_error;
4519
4520 status = verify_attr_len(xdr, savep, attrlen);
4521 res->bm = bitmap[0];
4522
4523 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4524 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4525 res->wr_io_sz);
4526xdr_error:
4527 dprintk("%s ret=%d!\n", __func__, status);
4528 return status;
4529}
4530
4531/*
4532 * Thresholds on pNFS direct I/O vrs MDS I/O
4533 */
4534static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4535 uint32_t *bitmap,
4536 struct nfs4_threshold *res)
4537{
4538 __be32 *p;
4539 int status = 0;
4540 uint32_t num;
4541
4542 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4543 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004544 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004545 /* Did the server return an unrequested attribute? */
4546 if (unlikely(res == NULL))
4547 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004548 p = xdr_inline_decode(xdr, 4);
4549 if (unlikely(!p))
4550 goto out_overflow;
4551 num = be32_to_cpup(p);
4552 if (num == 0)
4553 return 0;
4554 if (num > 1)
4555 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4556 "drivers per filesystem not supported\n",
4557 __func__);
4558
4559 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004560 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004561 }
4562 return status;
4563out_overflow:
4564 print_overflow_msg(__func__, xdr);
4565 return -EIO;
4566}
4567
Bryan Schumakerae42c702010-10-21 16:33:17 -04004568static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4569 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004570 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004571 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572{
Trond Myklebustbca79472009-03-11 14:10:26 -04004573 int status;
4574 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004575 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004576 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004578 status = decode_attr_type(xdr, bitmap, &type);
4579 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004581 fattr->mode = 0;
4582 if (status != 0) {
4583 fattr->mode |= nfs_type2fmt[type];
4584 fattr->valid |= status;
4585 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004587 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4588 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004589 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004590 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004591
4592 status = decode_attr_size(xdr, bitmap, &fattr->size);
4593 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004594 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004595 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004596
4597 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4598 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004599 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004600 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004601
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004602 err = 0;
4603 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004604 if (status < 0)
4605 goto xdr_error;
4606
4607 status = decode_attr_filehandle(xdr, bitmap, fh);
4608 if (status < 0)
4609 goto xdr_error;
4610
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004611 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4612 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004614 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004615
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004616 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004617 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004618 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004619 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004620
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004621 status = -EIO;
4622 if (unlikely(bitmap[0]))
4623 goto xdr_error;
4624
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004625 status = decode_attr_mode(xdr, bitmap, &fmode);
4626 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004627 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004628 if (status != 0) {
4629 fattr->mode |= fmode;
4630 fattr->valid |= status;
4631 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004632
4633 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4634 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004635 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004636 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004637
Trond Myklebust6926afd2012-01-07 13:22:46 -05004638 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004639 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004641 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004642
Trond Myklebust6926afd2012-01-07 13:22:46 -05004643 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004644 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004646 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004647
4648 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4649 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004650 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004651 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004652
4653 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4654 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004656 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004657
4658 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4659 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004661 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004662
4663 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4664 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004666 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004667
4668 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4669 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004671 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004672
Trond Myklebust28331a42011-04-27 13:47:52 -04004673 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004674 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004675 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004676 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004677
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004678 status = -EIO;
4679 if (unlikely(bitmap[1]))
4680 goto xdr_error;
4681
Andy Adamson88034c32012-05-23 05:02:34 -04004682 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4683 if (status < 0)
4684 goto xdr_error;
4685
David Quigleyaa9c2662013-05-22 12:50:44 -04004686 if (label) {
4687 status = decode_attr_security_label(xdr, bitmap, label);
4688 if (status < 0)
4689 goto xdr_error;
4690 fattr->valid |= status;
4691 }
4692
Bryan Schumakerae42c702010-10-21 16:33:17 -04004693xdr_error:
4694 dprintk("%s: xdr returned %d\n", __func__, -status);
4695 return status;
4696}
4697
4698static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004699 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004700 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004701{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004702 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004703 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004704 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004705 int status;
4706
4707 status = decode_op_hdr(xdr, OP_GETATTR);
4708 if (status < 0)
4709 goto xdr_error;
4710
4711 status = decode_attr_bitmap(xdr, bitmap);
4712 if (status < 0)
4713 goto xdr_error;
4714
4715 status = decode_attr_length(xdr, &attrlen, &savep);
4716 if (status < 0)
4717 goto xdr_error;
4718
David Quigleyaa9c2662013-05-22 12:50:44 -04004719 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4720 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004721 if (status < 0)
4722 goto xdr_error;
4723
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004724 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004726 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004727 return status;
4728}
4729
David Quigleyaa9c2662013-05-22 12:50:44 -04004730static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4731 struct nfs4_label *label, const struct nfs_server *server)
4732{
4733 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4734}
4735
Bryan Schumakerae42c702010-10-21 16:33:17 -04004736static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004737 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004738{
David Quigleyaa9c2662013-05-22 12:50:44 -04004739 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004740}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741
Andy Adamson504913f2010-10-20 00:17:57 -04004742/*
Jeff Layton3132e492016-08-10 15:58:24 -04004743 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004744 */
Jeff Layton3132e492016-08-10 15:58:24 -04004745static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004746 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004747{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004748 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004749 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004750
4751 p = xdr_inline_decode(xdr, 4);
4752 if (unlikely(!p))
4753 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004754 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004755
4756 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004757 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004758 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004759
4760 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004761 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004762 if (unlikely(!p))
4763 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004764
4765 /* If we get too many, then just cap it at the max */
4766 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4767 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4768 __func__, fsinfo->nlayouttypes);
4769 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4770 }
4771
4772 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4773 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004774 return 0;
4775out_overflow:
4776 print_overflow_msg(__func__, xdr);
4777 return -EIO;
4778}
4779
4780/*
4781 * The type of file system exported.
4782 * Note we must ensure that layouttype is set in any non-error case.
4783 */
4784static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004785 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004786{
4787 int status = 0;
4788
4789 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4790 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4791 return -EIO;
4792 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004793 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004794 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004795 }
Andy Adamson504913f2010-10-20 00:17:57 -04004796 return status;
4797}
4798
Fred Isamandae100c2011-07-30 20:52:37 -04004799/*
4800 * The prefered block size for layout directed io
4801 */
4802static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4803 uint32_t *res)
4804{
4805 __be32 *p;
4806
4807 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4808 *res = 0;
4809 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4810 p = xdr_inline_decode(xdr, 4);
4811 if (unlikely(!p)) {
4812 print_overflow_msg(__func__, xdr);
4813 return -EIO;
4814 }
4815 *res = be32_to_cpup(p);
4816 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4817 }
4818 return 0;
4819}
4820
Peng Tao2a92ee92015-09-26 02:24:37 +08004821/*
4822 * The granularity of a CLONE operation.
4823 */
4824static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4825 uint32_t *res)
4826{
4827 __be32 *p;
4828
4829 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4830 *res = 0;
4831 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4832 p = xdr_inline_decode(xdr, 4);
4833 if (unlikely(!p)) {
4834 print_overflow_msg(__func__, xdr);
4835 return -EIO;
4836 }
4837 *res = be32_to_cpup(p);
4838 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4839 }
4840 return 0;
4841}
4842
Linus Torvalds1da177e2005-04-16 15:20:36 -07004843static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4844{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004845 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004846 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847 int status;
4848
4849 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4850 goto xdr_error;
4851 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4852 goto xdr_error;
4853 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4854 goto xdr_error;
4855
4856 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4857
4858 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4859 goto xdr_error;
4860 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4861 goto xdr_error;
4862 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4863 goto xdr_error;
4864 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4865 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4866 goto xdr_error;
4867 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004868
4869 status = -EIO;
4870 if (unlikely(bitmap[0]))
4871 goto xdr_error;
4872
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004873 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4874 if (status != 0)
4875 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004876 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004877 if (status != 0)
4878 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004879
4880 status = -EIO;
4881 if (unlikely(bitmap[1]))
4882 goto xdr_error;
4883
Fred Isamandae100c2011-07-30 20:52:37 -04004884 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4885 if (status)
4886 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004887 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4888 if (status)
4889 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890
4891 status = verify_attr_len(xdr, savep, attrlen);
4892xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004893 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004894 return status;
4895}
4896
4897static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4898{
Al Viro8687b632006-10-19 23:28:48 -07004899 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900 uint32_t len;
4901 int status;
4902
Trond Myklebust99367812007-07-17 21:52:41 -04004903 /* Zero handle first to allow comparisons */
4904 memset(fh, 0, sizeof(*fh));
4905
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906 status = decode_op_hdr(xdr, OP_GETFH);
4907 if (status)
4908 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004909
Benny Halevyc0eae662009-08-14 17:20:14 +03004910 p = xdr_inline_decode(xdr, 4);
4911 if (unlikely(!p))
4912 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004913 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004914 if (len > NFS4_FHSIZE)
4915 return -EIO;
4916 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004917 p = xdr_inline_decode(xdr, len);
4918 if (unlikely(!p))
4919 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004920 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004922out_overflow:
4923 print_overflow_msg(__func__, xdr);
4924 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925}
4926
4927static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4928{
4929 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004930
Linus Torvalds1da177e2005-04-16 15:20:36 -07004931 status = decode_op_hdr(xdr, OP_LINK);
4932 if (status)
4933 return status;
4934 return decode_change_info(xdr, cinfo);
4935}
4936
4937/*
4938 * We create the owner, so we know a proper owner.id length is 4.
4939 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004940static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004941{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004942 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004943 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004944 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004946 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004947 if (unlikely(!p))
4948 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004949 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004950 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004951 type = be32_to_cpup(p++); /* 4 byte read */
4952 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004953 fl->fl_start = (loff_t)offset;
4954 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4955 if (length == ~(uint64_t)0)
4956 fl->fl_end = OFFSET_MAX;
4957 fl->fl_type = F_WRLCK;
4958 if (type & 1)
4959 fl->fl_type = F_RDLCK;
4960 fl->fl_pid = 0;
4961 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004962 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4963 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4964 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004965 if (likely(p))
4966 return -NFS4ERR_DENIED;
4967out_overflow:
4968 print_overflow_msg(__func__, xdr);
4969 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970}
4971
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004972static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974 int status;
4975
4976 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004977 if (status == -EIO)
4978 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04004980 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004981 if (unlikely(status))
4982 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004983 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004984 status = decode_lock_denied(xdr, NULL);
4985 if (res->open_seqid != NULL)
4986 nfs_increment_open_seqid(status, res->open_seqid);
4987 nfs_increment_lock_seqid(status, res->lock_seqid);
4988out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989 return status;
4990}
4991
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004992static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993{
4994 int status;
4995 status = decode_op_hdr(xdr, OP_LOCKT);
4996 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004997 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998 return status;
4999}
5000
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005001static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005002{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003 int status;
5004
5005 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005006 if (status != -EIO)
5007 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005008 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005009 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010 return status;
5011}
5012
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005013static int decode_release_lockowner(struct xdr_stream *xdr)
5014{
5015 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5016}
5017
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018static int decode_lookup(struct xdr_stream *xdr)
5019{
5020 return decode_op_hdr(xdr, OP_LOOKUP);
5021}
5022
5023/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005024static int decode_space_limit(struct xdr_stream *xdr,
5025 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026{
Andy Adamson05d564f2008-12-23 16:06:15 -05005027 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005029 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005030
Benny Halevyc0eae662009-08-14 17:20:14 +03005031 p = xdr_inline_decode(xdr, 12);
5032 if (unlikely(!p))
5033 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005034 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005036 case NFS4_LIMIT_SIZE:
5037 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005038 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005039 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005040 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005041 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005042 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005043 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005044 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005045 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005047out_overflow:
5048 print_overflow_msg(__func__, xdr);
5049 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050}
5051
Trond Myklebust6ae37332015-01-30 14:21:14 -05005052static int decode_rw_delegation(struct xdr_stream *xdr,
5053 uint32_t delegation_type,
5054 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005055{
Andy Adamson05d564f2008-12-23 16:06:15 -05005056 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005057 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058
Trond Myklebust93b717f2016-05-16 17:42:43 -04005059 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005060 if (unlikely(status))
5061 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005062 p = xdr_inline_decode(xdr, 4);
5063 if (unlikely(!p))
5064 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005065 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005066
Linus Torvalds1da177e2005-04-16 15:20:36 -07005067 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005068 case NFS4_OPEN_DELEGATE_READ:
5069 res->delegation_type = FMODE_READ;
5070 break;
5071 case NFS4_OPEN_DELEGATE_WRITE:
5072 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005073 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074 return -EIO;
5075 }
David Howells7539bba2006-08-22 20:06:09 -04005076 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03005077out_overflow:
5078 print_overflow_msg(__func__, xdr);
5079 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005080}
5081
Trond Myklebust6ae37332015-01-30 14:21:14 -05005082static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5083{
5084 __be32 *p;
5085 uint32_t why_no_delegation;
5086
5087 p = xdr_inline_decode(xdr, 4);
5088 if (unlikely(!p))
5089 goto out_overflow;
5090 why_no_delegation = be32_to_cpup(p);
5091 switch (why_no_delegation) {
5092 case WND4_CONTENTION:
5093 case WND4_RESOURCE:
5094 xdr_inline_decode(xdr, 4);
5095 /* Ignore for now */
5096 }
5097 return 0;
5098out_overflow:
5099 print_overflow_msg(__func__, xdr);
5100 return -EIO;
5101}
5102
5103static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5104{
5105 __be32 *p;
5106 uint32_t delegation_type;
5107
5108 p = xdr_inline_decode(xdr, 4);
5109 if (unlikely(!p))
5110 goto out_overflow;
5111 delegation_type = be32_to_cpup(p);
5112 res->delegation_type = 0;
5113 switch (delegation_type) {
5114 case NFS4_OPEN_DELEGATE_NONE:
5115 return 0;
5116 case NFS4_OPEN_DELEGATE_READ:
5117 case NFS4_OPEN_DELEGATE_WRITE:
5118 return decode_rw_delegation(xdr, delegation_type, res);
5119 case NFS4_OPEN_DELEGATE_NONE_EXT:
5120 return decode_no_delegation(xdr, res);
5121 }
5122 return -EIO;
5123out_overflow:
5124 print_overflow_msg(__func__, xdr);
5125 return -EIO;
5126}
5127
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5129{
Andy Adamson05d564f2008-12-23 16:06:15 -05005130 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005131 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005132 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133
Trond Myklebustc7848f62013-12-04 17:39:23 -05005134 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5135 return status;
5136 nfs_increment_open_seqid(status, res->seqid);
5137 if (status)
5138 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005139 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005140 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005141 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005142
Andy Adamson05d564f2008-12-23 16:06:15 -05005143 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144
Benny Halevyc0eae662009-08-14 17:20:14 +03005145 p = xdr_inline_decode(xdr, 8);
5146 if (unlikely(!p))
5147 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005148 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005149 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005150 if (bmlen > 10)
5151 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152
Benny Halevyc0eae662009-08-14 17:20:14 +03005153 p = xdr_inline_decode(xdr, bmlen << 2);
5154 if (unlikely(!p))
5155 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005156 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5157 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005158 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005159 for (; i < NFS4_BITMAP_SIZE; i++)
5160 res->attrset[i] = 0;
5161
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162 return decode_delegation(xdr, res);
5163xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005164 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005165 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005166out_overflow:
5167 print_overflow_msg(__func__, xdr);
5168 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005169}
5170
5171static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5172{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173 int status;
5174
Andy Adamson05d564f2008-12-23 16:06:15 -05005175 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005176 if (status != -EIO)
5177 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005178 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005179 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005180 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181}
5182
5183static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5184{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185 int status;
5186
5187 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005188 if (status != -EIO)
5189 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005190 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005191 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005192 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005193}
5194
5195static int decode_putfh(struct xdr_stream *xdr)
5196{
5197 return decode_op_hdr(xdr, OP_PUTFH);
5198}
5199
5200static int decode_putrootfh(struct xdr_stream *xdr)
5201{
5202 return decode_op_hdr(xdr, OP_PUTROOTFH);
5203}
5204
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005205static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5206 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207{
Al Viro8687b632006-10-19 23:28:48 -07005208 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005209 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005210 int status;
5211
5212 status = decode_op_hdr(xdr, OP_READ);
5213 if (status)
5214 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005215 p = xdr_inline_decode(xdr, 8);
5216 if (unlikely(!p))
5217 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005218 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005219 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005220 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005221 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005222 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223 "count %u > recvd %u\n", count, recvd);
5224 count = recvd;
5225 eof = 0;
5226 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227 res->eof = eof;
5228 res->count = count;
5229 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005230out_overflow:
5231 print_overflow_msg(__func__, xdr);
5232 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005233}
5234
5235static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5236{
Chuck Leverbcecff72007-10-26 13:32:03 -04005237 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005238 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239
5240 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005241 if (!status)
5242 status = decode_verifier(xdr, readdir->verifier.data);
5243 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005244 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005245 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005246 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005247 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005248 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249}
5250
5251static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5252{
5253 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005254 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005255 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005256 int status;
5257
5258 status = decode_op_hdr(xdr, OP_READLINK);
5259 if (status)
5260 return status;
5261
5262 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005263 p = xdr_inline_decode(xdr, 4);
5264 if (unlikely(!p))
5265 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005266 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005267 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005268 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269 return -ENAMETOOLONG;
5270 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005271 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005272 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005273 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274 "count %u > recvd %u\n", len, recvd);
5275 return -EIO;
5276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277 /*
5278 * The XDR encode routine has set things up so that
5279 * the link text will be copied directly into the
5280 * buffer. We just have to do overflow-checking,
5281 * and and null-terminate the text (the VFS expects
5282 * null-termination).
5283 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005284 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005285 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005286out_overflow:
5287 print_overflow_msg(__func__, xdr);
5288 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005289}
5290
5291static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5292{
5293 int status;
5294
5295 status = decode_op_hdr(xdr, OP_REMOVE);
5296 if (status)
5297 goto out;
5298 status = decode_change_info(xdr, cinfo);
5299out:
5300 return status;
5301}
5302
5303static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5304 struct nfs4_change_info *new_cinfo)
5305{
5306 int status;
5307
5308 status = decode_op_hdr(xdr, OP_RENAME);
5309 if (status)
5310 goto out;
5311 if ((status = decode_change_info(xdr, old_cinfo)))
5312 goto out;
5313 status = decode_change_info(xdr, new_cinfo);
5314out:
5315 return status;
5316}
5317
5318static int decode_renew(struct xdr_stream *xdr)
5319{
5320 return decode_op_hdr(xdr, OP_RENEW);
5321}
5322
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005323static int
5324decode_restorefh(struct xdr_stream *xdr)
5325{
5326 return decode_op_hdr(xdr, OP_RESTOREFH);
5327}
5328
J. Bruce Fields029d1052005-06-22 17:16:22 +00005329static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005330 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005331{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005332 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005333 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005334 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005335 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005336 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005337
Andy Adamsonbf118a32011-12-07 11:55:27 -05005338 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005339 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5340 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005341
Trond Myklebust519d3952012-08-14 17:30:10 -04005342 xdr_enter_page(xdr, xdr->buf->page_len);
5343
Trond Myklebustcff298c2012-08-14 17:14:17 -04005344 /* Calculate the offset of the page data */
5345 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005346
J. Bruce Fields029d1052005-06-22 17:16:22 +00005347 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5348 goto out;
5349 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5350 goto out;
5351
5352 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5353 return -EIO;
5354 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005355
Andy Adamsonbf118a32011-12-07 11:55:27 -05005356 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5357 * are stored with the acl data to handle the problem of
5358 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005359 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005360 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005361
5362 /* Check for receive buffer overflow */
5363 if (res->acl_len > (xdr->nwords << 2) ||
5364 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5365 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005366 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005367 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005368 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005369 } else
5370 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005371
5372out:
5373 return status;
5374}
5375
Linus Torvalds1da177e2005-04-16 15:20:36 -07005376static int
5377decode_savefh(struct xdr_stream *xdr)
5378{
5379 return decode_op_hdr(xdr, OP_SAVEFH);
5380}
5381
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005382static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005383{
Al Viro8687b632006-10-19 23:28:48 -07005384 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005385 uint32_t bmlen;
5386 int status;
5387
Linus Torvalds1da177e2005-04-16 15:20:36 -07005388 status = decode_op_hdr(xdr, OP_SETATTR);
5389 if (status)
5390 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005391 p = xdr_inline_decode(xdr, 4);
5392 if (unlikely(!p))
5393 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005394 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005395 p = xdr_inline_decode(xdr, bmlen << 2);
5396 if (likely(p))
5397 return 0;
5398out_overflow:
5399 print_overflow_msg(__func__, xdr);
5400 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005401}
5402
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005403static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005404{
Al Viro8687b632006-10-19 23:28:48 -07005405 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406 uint32_t opnum;
5407 int32_t nfserr;
5408
Benny Halevyc0eae662009-08-14 17:20:14 +03005409 p = xdr_inline_decode(xdr, 8);
5410 if (unlikely(!p))
5411 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005412 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005413 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005414 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005415 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005416 return -EIO;
5417 }
Benny Halevycccddf42009-08-14 17:20:19 +03005418 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005419 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005420 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5421 if (unlikely(!p))
5422 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005423 p = xdr_decode_hyper(p, &res->clientid);
5424 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005425 } else if (nfserr == NFSERR_CLID_INUSE) {
5426 uint32_t len;
5427
5428 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005429 p = xdr_inline_decode(xdr, 4);
5430 if (unlikely(!p))
5431 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005432 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005433 p = xdr_inline_decode(xdr, len);
5434 if (unlikely(!p))
5435 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005436
5437 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005438 p = xdr_inline_decode(xdr, 4);
5439 if (unlikely(!p))
5440 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005441 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005442 p = xdr_inline_decode(xdr, len);
5443 if (unlikely(!p))
5444 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005445 return -NFSERR_CLID_INUSE;
5446 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005447 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005448
5449 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005450out_overflow:
5451 print_overflow_msg(__func__, xdr);
5452 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005453}
5454
5455static int decode_setclientid_confirm(struct xdr_stream *xdr)
5456{
5457 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5458}
5459
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005460static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005461{
Al Viro8687b632006-10-19 23:28:48 -07005462 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005463 int status;
5464
5465 status = decode_op_hdr(xdr, OP_WRITE);
5466 if (status)
5467 return status;
5468
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005469 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005470 if (unlikely(!p))
5471 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005472 res->count = be32_to_cpup(p++);
5473 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005474 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005475out_overflow:
5476 print_overflow_msg(__func__, xdr);
5477 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005478}
5479
5480static int decode_delegreturn(struct xdr_stream *xdr)
5481{
5482 return decode_op_hdr(xdr, OP_DELEGRETURN);
5483}
5484
Chuck Leverfb15b262013-03-16 15:54:34 -04005485static int decode_secinfo_gss(struct xdr_stream *xdr,
5486 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005487{
Chuck Leverfb15b262013-03-16 15:54:34 -04005488 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005489 __be32 *p;
5490
5491 p = xdr_inline_decode(xdr, 4);
5492 if (unlikely(!p))
5493 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005494 oid_len = be32_to_cpup(p);
5495 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005496 goto out_err;
5497
Chuck Leverfb15b262013-03-16 15:54:34 -04005498 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005499 if (unlikely(!p))
5500 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005501 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5502 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005503
5504 p = xdr_inline_decode(xdr, 8);
5505 if (unlikely(!p))
5506 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005507 flavor->flavor_info.qop = be32_to_cpup(p++);
5508 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005509
5510 return 0;
5511
5512out_overflow:
5513 print_overflow_msg(__func__, xdr);
5514 return -EIO;
5515out_err:
5516 return -EINVAL;
5517}
5518
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005519static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005520{
Chuck Leverfb15b262013-03-16 15:54:34 -04005521 struct nfs4_secinfo4 *sec_flavor;
5522 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005523 int status;
5524 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005525
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005526 p = xdr_inline_decode(xdr, 4);
5527 if (unlikely(!p))
5528 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005529
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005530 res->flavors->num_flavors = 0;
5531 num_flavors = be32_to_cpup(p);
5532
5533 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005534 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005535 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005536 break;
5537
5538 p = xdr_inline_decode(xdr, 4);
5539 if (unlikely(!p))
5540 goto out_overflow;
5541 sec_flavor->flavor = be32_to_cpup(p);
5542
5543 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005544 status = decode_secinfo_gss(xdr, sec_flavor);
5545 if (status)
5546 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005547 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005548 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005549 }
5550
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005551 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005552out:
5553 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005554out_overflow:
5555 print_overflow_msg(__func__, xdr);
5556 return -EIO;
5557}
5558
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005559static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5560{
5561 int status = decode_op_hdr(xdr, OP_SECINFO);
5562 if (status)
5563 return status;
5564 return decode_secinfo_common(xdr, res);
5565}
5566
Benny Halevy99fe60d2009-04-01 09:22:29 -04005567#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005568static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5569{
5570 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5571 if (status)
5572 return status;
5573 return decode_secinfo_common(xdr, res);
5574}
5575
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005576static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5577{
5578 __be32 *p;
5579 uint32_t bitmap_words;
5580 unsigned int i;
5581
5582 p = xdr_inline_decode(xdr, 4);
5583 bitmap_words = be32_to_cpup(p++);
5584 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5585 return -EIO;
5586 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5587 for (i = 0; i < bitmap_words; i++)
5588 op_map->u.words[i] = be32_to_cpup(p++);
5589
5590 return 0;
5591}
5592
Benny Halevy99fe60d2009-04-01 09:22:29 -04005593static int decode_exchange_id(struct xdr_stream *xdr,
5594 struct nfs41_exchange_id_res *res)
5595{
5596 __be32 *p;
5597 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005598 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005599 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005600 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005601
5602 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5603 if (status)
5604 return status;
5605
Benny Halevyc0eae662009-08-14 17:20:14 +03005606 p = xdr_inline_decode(xdr, 8);
5607 if (unlikely(!p))
5608 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005609 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005610 p = xdr_inline_decode(xdr, 12);
5611 if (unlikely(!p))
5612 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005613 res->seqid = be32_to_cpup(p++);
5614 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005615
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005616 res->state_protect.how = be32_to_cpup(p);
5617 switch (res->state_protect.how) {
5618 case SP4_NONE:
5619 break;
5620 case SP4_MACH_CRED:
5621 status = decode_op_map(xdr, &res->state_protect.enforce);
5622 if (status)
5623 return status;
5624 status = decode_op_map(xdr, &res->state_protect.allow);
5625 if (status)
5626 return status;
5627 break;
5628 default:
5629 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005630 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005631 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005632
Chuck Leveracdeb692012-05-21 22:46:16 -04005633 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005634 p = xdr_inline_decode(xdr, 8);
5635 if (unlikely(!p))
5636 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005637 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005638
Chuck Leveracdeb692012-05-21 22:46:16 -04005639 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005640 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5641 if (unlikely(status))
5642 return status;
Chuck Leveracdeb692012-05-21 22:46:16 -04005643 memcpy(res->server_owner->major_id, dummy_str, dummy);
5644 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005645
Chuck Leveracdeb692012-05-21 22:46:16 -04005646 /* server_scope4 */
5647 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5648 if (unlikely(status))
5649 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005650 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5651 res->server_scope->server_scope_sz = dummy;
5652
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005653 /* Implementation Id */
5654 p = xdr_inline_decode(xdr, 4);
5655 if (unlikely(!p))
5656 goto out_overflow;
5657 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005658
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005659 if (impl_id_count) {
5660 /* nii_domain */
5661 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5662 if (unlikely(status))
5663 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005664 memcpy(res->impl_id->domain, dummy_str, dummy);
5665
5666 /* nii_name */
5667 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5668 if (unlikely(status))
5669 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005670 memcpy(res->impl_id->name, dummy_str, dummy);
5671
5672 /* nii_date */
5673 p = xdr_inline_decode(xdr, 12);
5674 if (unlikely(!p))
5675 goto out_overflow;
5676 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5677 res->impl_id->date.nseconds = be32_to_cpup(p);
5678
5679 /* if there's more than one entry, ignore the rest */
5680 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005681 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005682out_overflow:
5683 print_overflow_msg(__func__, xdr);
5684 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005685}
Andy Adamsonfc931582009-04-01 09:22:31 -04005686
5687static int decode_chan_attrs(struct xdr_stream *xdr,
5688 struct nfs4_channel_attrs *attrs)
5689{
5690 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005691 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005692
Benny Halevyc0eae662009-08-14 17:20:14 +03005693 p = xdr_inline_decode(xdr, 28);
5694 if (unlikely(!p))
5695 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005696 val = be32_to_cpup(p++); /* headerpadsz */
5697 if (val)
5698 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005699 attrs->max_rqst_sz = be32_to_cpup(p++);
5700 attrs->max_resp_sz = be32_to_cpup(p++);
5701 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5702 attrs->max_ops = be32_to_cpup(p++);
5703 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005704 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005705 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005706 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5707 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005708 return -EINVAL;
5709 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005710 if (nr_attrs == 1) {
5711 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5712 if (unlikely(!p))
5713 goto out_overflow;
5714 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005715 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005716out_overflow:
5717 print_overflow_msg(__func__, xdr);
5718 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005719}
5720
Benny Halevye78291e2009-08-14 17:20:00 +03005721static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5722{
5723 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005724}
5725
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005726static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5727 struct nfs41_bind_conn_to_session_res *res)
5728{
5729 __be32 *p;
5730 int status;
5731
5732 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5733 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005734 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005735 if (unlikely(status))
5736 return status;
5737
5738 /* dir flags, rdma mode bool */
5739 p = xdr_inline_decode(xdr, 8);
5740 if (unlikely(!p))
5741 goto out_overflow;
5742
5743 res->dir = be32_to_cpup(p++);
5744 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5745 return -EIO;
5746 if (be32_to_cpup(p) == 0)
5747 res->use_conn_in_rdma_mode = false;
5748 else
5749 res->use_conn_in_rdma_mode = true;
5750
5751 return 0;
5752out_overflow:
5753 print_overflow_msg(__func__, xdr);
5754 return -EIO;
5755}
5756
Andy Adamsonfc931582009-04-01 09:22:31 -04005757static int decode_create_session(struct xdr_stream *xdr,
5758 struct nfs41_create_session_res *res)
5759{
5760 __be32 *p;
5761 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005762
5763 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005764 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005765 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005766 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005767 return status;
5768
Andy Adamsonfc931582009-04-01 09:22:31 -04005769 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005770 p = xdr_inline_decode(xdr, 8);
5771 if (unlikely(!p))
5772 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005773 res->seqid = be32_to_cpup(p++);
5774 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005775
5776 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005777 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005778 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005779 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005780 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005781out_overflow:
5782 print_overflow_msg(__func__, xdr);
5783 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005784}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005785
5786static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5787{
5788 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5789}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005790
Trond Myklebust66245532012-05-25 17:18:09 -04005791static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5792{
5793 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5794}
5795
Ricardo Labiaga180197532009-12-05 16:08:40 -05005796static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5797{
5798 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5799}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005800#endif /* CONFIG_NFS_V4_1 */
5801
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005802static int decode_sequence(struct xdr_stream *xdr,
5803 struct nfs4_sequence_res *res,
5804 struct rpc_rqst *rqstp)
5805{
5806#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005807 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005808 struct nfs4_sessionid id;
5809 u32 dummy;
5810 int status;
5811 __be32 *p;
5812
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005813 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005814 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005815 if (!res->sr_slot->table->session)
5816 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005817
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005818 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005819 if (!status)
5820 status = decode_sessionid(xdr, &id);
5821 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005822 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005823
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005824 /*
5825 * If the server returns different values for sessionID, slotID or
5826 * sequence number, the server is looney tunes.
5827 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005828 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005829 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005830
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005831 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005832 NFS4_MAX_SESSIONID_LEN)) {
5833 dprintk("%s Invalid session id\n", __func__);
5834 goto out_err;
5835 }
Benny Halevye78291e2009-08-14 17:20:00 +03005836
Benny Halevyc0eae662009-08-14 17:20:14 +03005837 p = xdr_inline_decode(xdr, 20);
5838 if (unlikely(!p))
5839 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005840
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005841 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005842 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005843 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005844 dprintk("%s Invalid sequence number\n", __func__);
5845 goto out_err;
5846 }
5847 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005848 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005849 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005850 dprintk("%s Invalid slot id\n", __func__);
5851 goto out_err;
5852 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005853 /* highest slot id */
5854 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005855 /* target highest slot id */
5856 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005857 /* result flags */
5858 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005859 status = 0;
5860out_err:
5861 res->sr_status = status;
5862 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005863out_overflow:
5864 print_overflow_msg(__func__, xdr);
5865 status = -EIO;
5866 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005867#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005868 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005869#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005870}
5871
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005872#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005873static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5874{
5875 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5876 return decode_stateid(xdr, stateid);
5877}
5878
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005879static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005880 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005881{
Trond Myklebust4e590802015-03-09 14:01:25 -04005882 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005883 __be32 *p;
5884 uint32_t len, type;
5885 int status;
5886
5887 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5888 if (status) {
5889 if (status == -ETOOSMALL) {
5890 p = xdr_inline_decode(xdr, 4);
5891 if (unlikely(!p))
5892 goto out_overflow;
5893 pdev->mincount = be32_to_cpup(p);
5894 dprintk("%s: Min count too small. mincnt = %u\n",
5895 __func__, pdev->mincount);
5896 }
5897 return status;
5898 }
5899
5900 p = xdr_inline_decode(xdr, 8);
5901 if (unlikely(!p))
5902 goto out_overflow;
5903 type = be32_to_cpup(p++);
5904 if (type != pdev->layout_type) {
5905 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5906 __func__, pdev->layout_type, type);
5907 return -EINVAL;
5908 }
5909 /*
5910 * Get the length of the opaque device_addr4. xdr_read_pages places
5911 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5912 * and places the remaining xdr data in xdr_buf->tail
5913 */
5914 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005915 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5916 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005917
5918 /* Parse notification bitmap, verifying that it is zero. */
5919 p = xdr_inline_decode(xdr, 4);
5920 if (unlikely(!p))
5921 goto out_overflow;
5922 len = be32_to_cpup(p);
5923 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005924 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005925
5926 p = xdr_inline_decode(xdr, 4 * len);
5927 if (unlikely(!p))
5928 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005929
Trond Myklebust4e590802015-03-09 14:01:25 -04005930 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005931 for (i = 1; i < len; i++) {
5932 if (be32_to_cpup(p++)) {
5933 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005934 __func__);
5935 return -EIO;
5936 }
5937 }
5938 }
5939 return 0;
5940out_overflow:
5941 print_overflow_msg(__func__, xdr);
5942 return -EIO;
5943}
5944
5945static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5946 struct nfs4_layoutget_res *res)
5947{
5948 __be32 *p;
5949 int status;
5950 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005951 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005952
5953 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5954 if (status)
5955 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005956 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005957 if (unlikely(!p))
5958 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005959 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04005960 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005961 p = xdr_inline_decode(xdr, 4);
5962 if (unlikely(!p))
5963 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005964 layout_count = be32_to_cpup(p);
5965 if (!layout_count) {
5966 dprintk("%s: server responded with empty layout array\n",
5967 __func__);
5968 return -EINVAL;
5969 }
5970
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005971 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005972 if (unlikely(!p))
5973 goto out_overflow;
5974 p = xdr_decode_hyper(p, &res->range.offset);
5975 p = xdr_decode_hyper(p, &res->range.length);
5976 res->range.iomode = be32_to_cpup(p++);
5977 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005978 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005979
5980 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5981 __func__,
5982 (unsigned long)res->range.offset,
5983 (unsigned long)res->range.length,
5984 res->range.iomode,
5985 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005986 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005987
Trond Myklebust64bd5772012-06-20 22:35:05 -04005988 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005989 if (res->layoutp->len > recvd) {
5990 dprintk("NFS: server cheating in layoutget reply: "
5991 "layout len %u > recvd %u\n",
5992 res->layoutp->len, recvd);
5993 return -EINVAL;
5994 }
5995
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005996 if (layout_count > 1) {
5997 /* We only handle a length one array at the moment. Any
5998 * further entries are just ignored. Note that this means
5999 * the client may see a response that is less than the
6000 * minimum it requested.
6001 */
6002 dprintk("%s: server responded with %d layouts, dropping tail\n",
6003 __func__, layout_count);
6004 }
6005
6006 return 0;
6007out_overflow:
6008 print_overflow_msg(__func__, xdr);
6009 return -EIO;
6010}
Andy Adamson863a3c62011-03-23 13:27:54 +00006011
Benny Halevycbe82602011-05-22 19:52:37 +03006012static int decode_layoutreturn(struct xdr_stream *xdr,
6013 struct nfs4_layoutreturn_res *res)
6014{
6015 __be32 *p;
6016 int status;
6017
6018 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6019 if (status)
6020 return status;
6021 p = xdr_inline_decode(xdr, 4);
6022 if (unlikely(!p))
6023 goto out_overflow;
6024 res->lrs_present = be32_to_cpup(p);
6025 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04006026 status = decode_layout_stateid(xdr, &res->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03006027 return status;
6028out_overflow:
6029 print_overflow_msg(__func__, xdr);
6030 return -EIO;
6031}
6032
Andy Adamson863a3c62011-03-23 13:27:54 +00006033static int decode_layoutcommit(struct xdr_stream *xdr,
6034 struct rpc_rqst *req,
6035 struct nfs4_layoutcommit_res *res)
6036{
6037 __be32 *p;
6038 __u32 sizechanged;
6039 int status;
6040
6041 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04006042 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00006043 if (status)
6044 return status;
6045
6046 p = xdr_inline_decode(xdr, 4);
6047 if (unlikely(!p))
6048 goto out_overflow;
6049 sizechanged = be32_to_cpup(p);
6050
6051 if (sizechanged) {
6052 /* throw away new size */
6053 p = xdr_inline_decode(xdr, 8);
6054 if (unlikely(!p))
6055 goto out_overflow;
6056 }
6057 return 0;
6058out_overflow:
6059 print_overflow_msg(__func__, xdr);
6060 return -EIO;
6061}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006062
6063static int decode_test_stateid(struct xdr_stream *xdr,
6064 struct nfs41_test_stateid_res *res)
6065{
6066 __be32 *p;
6067 int status;
6068 int num_res;
6069
6070 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6071 if (status)
6072 return status;
6073
6074 p = xdr_inline_decode(xdr, 4);
6075 if (unlikely(!p))
6076 goto out_overflow;
6077 num_res = be32_to_cpup(p++);
6078 if (num_res != 1)
6079 goto out;
6080
6081 p = xdr_inline_decode(xdr, 4);
6082 if (unlikely(!p))
6083 goto out_overflow;
6084 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006085
6086 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006087out_overflow:
6088 print_overflow_msg(__func__, xdr);
6089out:
6090 return -EIO;
6091}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006092
6093static int decode_free_stateid(struct xdr_stream *xdr,
6094 struct nfs41_free_stateid_res *res)
6095{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006096 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006097 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006098}
Trond Myklebustcf805162016-11-15 14:56:07 -05006099#else
6100static inline
6101int decode_layoutreturn(struct xdr_stream *xdr,
6102 struct nfs4_layoutreturn_res *res)
6103{
6104 return 0;
6105}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006106#endif /* CONFIG_NFS_V4_1 */
6107
Linus Torvalds1da177e2005-04-16 15:20:36 -07006108/*
Benny Halevy49c25592008-12-23 16:06:16 -05006109 * END OF "GENERIC" DECODE ROUTINES.
6110 */
6111
6112/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113 * Decode OPEN_DOWNGRADE response
6114 */
Chuck Leverbf269552010-12-14 14:59:29 +00006115static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6116 struct xdr_stream *xdr,
6117 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118{
Andy Adamson05d564f2008-12-23 16:06:15 -05006119 struct compound_hdr hdr;
6120 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006121
Chuck Leverbf269552010-12-14 14:59:29 +00006122 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006123 if (status)
6124 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006125 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006126 if (status)
6127 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006128 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006129 if (status)
6130 goto out;
Trond Myklebustb6808142016-11-20 13:34:16 -05006131 if (res->lr_res) {
6132 status = decode_layoutreturn(xdr, res->lr_res);
6133 res->lr_ret = status;
6134 if (status)
6135 goto out;
6136 }
Chuck Leverbf269552010-12-14 14:59:29 +00006137 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006138out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006139 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006140}
6141
6142/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143 * Decode ACCESS response
6144 */
Chuck Leverbf269552010-12-14 14:59:29 +00006145static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6146 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006147{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006148 struct compound_hdr hdr;
6149 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006150
Chuck Leverbf269552010-12-14 14:59:29 +00006151 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006152 if (status)
6153 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006154 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006155 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006156 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006157 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006158 if (status != 0)
6159 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006160 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006161 if (status != 0)
6162 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006163 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164out:
6165 return status;
6166}
6167
6168/*
6169 * Decode LOOKUP response
6170 */
Chuck Leverbf269552010-12-14 14:59:29 +00006171static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6172 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006174 struct compound_hdr hdr;
6175 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006176
Chuck Leverbf269552010-12-14 14:59:29 +00006177 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006178 if (status)
6179 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006180 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006181 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006183 status = decode_putfh(xdr);
6184 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006186 status = decode_lookup(xdr);
6187 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006189 status = decode_getfh(xdr, res->fh);
6190 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006192 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193out:
6194 return status;
6195}
6196
6197/*
6198 * Decode LOOKUP_ROOT response
6199 */
Chuck Leverbf269552010-12-14 14:59:29 +00006200static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6201 struct xdr_stream *xdr,
6202 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006204 struct compound_hdr hdr;
6205 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006206
Chuck Leverbf269552010-12-14 14:59:29 +00006207 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006208 if (status)
6209 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006210 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006211 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006212 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006213 status = decode_putrootfh(xdr);
6214 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006215 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006216 status = decode_getfh(xdr, res->fh);
6217 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006218 status = decode_getfattr_label(xdr, res->fattr,
6219 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006220out:
6221 return status;
6222}
6223
6224/*
6225 * Decode REMOVE response
6226 */
Chuck Leverbf269552010-12-14 14:59:29 +00006227static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6228 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006230 struct compound_hdr hdr;
6231 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006232
Chuck Leverbf269552010-12-14 14:59:29 +00006233 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006234 if (status)
6235 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006236 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006237 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006239 status = decode_putfh(xdr);
6240 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006241 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006242 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243out:
6244 return status;
6245}
6246
6247/*
6248 * Decode RENAME response
6249 */
Chuck Leverbf269552010-12-14 14:59:29 +00006250static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6251 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006252{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006253 struct compound_hdr hdr;
6254 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006255
Chuck Leverbf269552010-12-14 14:59:29 +00006256 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006257 if (status)
6258 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006259 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006260 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006261 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006262 status = decode_putfh(xdr);
6263 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006264 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006265 status = decode_savefh(xdr);
6266 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006267 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006268 status = decode_putfh(xdr);
6269 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006271 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006272out:
6273 return status;
6274}
6275
6276/*
6277 * Decode LINK response
6278 */
Chuck Leverbf269552010-12-14 14:59:29 +00006279static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6280 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006282 struct compound_hdr hdr;
6283 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006284
Chuck Leverbf269552010-12-14 14:59:29 +00006285 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006286 if (status)
6287 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006288 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006289 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006291 status = decode_putfh(xdr);
6292 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006293 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006294 status = decode_savefh(xdr);
6295 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006296 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006297 status = decode_putfh(xdr);
6298 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006300 status = decode_link(xdr, &res->cinfo);
6301 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006302 goto out;
6303 /*
6304 * Note order: OP_LINK leaves the directory as the current
6305 * filehandle.
6306 */
Chuck Leverbf269552010-12-14 14:59:29 +00006307 status = decode_restorefh(xdr);
6308 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006309 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006310 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311out:
6312 return status;
6313}
6314
6315/*
6316 * Decode CREATE response
6317 */
Chuck Leverbf269552010-12-14 14:59:29 +00006318static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6319 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006320{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006321 struct compound_hdr hdr;
6322 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006323
Chuck Leverbf269552010-12-14 14:59:29 +00006324 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006325 if (status)
6326 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006327 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006328 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006329 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006330 status = decode_putfh(xdr);
6331 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006333 status = decode_create(xdr, &res->dir_cinfo);
6334 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006336 status = decode_getfh(xdr, res->fh);
6337 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006338 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006339 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006340out:
6341 return status;
6342}
6343
6344/*
6345 * Decode SYMLINK response
6346 */
Chuck Leverbf269552010-12-14 14:59:29 +00006347static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6348 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006349{
Chuck Leverbf269552010-12-14 14:59:29 +00006350 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351}
6352
6353/*
6354 * Decode GETATTR response
6355 */
Chuck Leverbf269552010-12-14 14:59:29 +00006356static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6357 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359 struct compound_hdr hdr;
6360 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006361
Chuck Leverbf269552010-12-14 14:59:29 +00006362 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006363 if (status)
6364 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006365 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006366 if (status)
6367 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006368 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006369 if (status)
6370 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006371 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372out:
6373 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006374}
6375
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006376/*
6377 * Encode an SETACL request
6378 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006379static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6380 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006381{
Andy Adamson05d564f2008-12-23 16:06:15 -05006382 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006383 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006384 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006385
Chuck Lever9f06c712010-12-14 14:59:18 +00006386 encode_compound_hdr(xdr, req, &hdr);
6387 encode_sequence(xdr, &args->seq_args, &hdr);
6388 encode_putfh(xdr, args->fh, &hdr);
6389 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006390 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006391}
Andy Adamson05d564f2008-12-23 16:06:15 -05006392
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006393/*
6394 * Decode SETACL response
6395 */
6396static int
Chuck Leverbf269552010-12-14 14:59:29 +00006397nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006398 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006399{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006400 struct compound_hdr hdr;
6401 int status;
6402
Chuck Leverbf269552010-12-14 14:59:29 +00006403 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006404 if (status)
6405 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006406 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006407 if (status)
6408 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006409 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006410 if (status)
6411 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006412 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006413out:
6414 return status;
6415}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416
6417/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006418 * Decode GETACL response
6419 */
6420static int
Chuck Leverbf269552010-12-14 14:59:29 +00006421nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006422 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006423{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006424 struct compound_hdr hdr;
6425 int status;
6426
Trond Myklebust331818f2012-02-03 18:30:53 -05006427 if (res->acl_scratch != NULL) {
6428 void *p = page_address(res->acl_scratch);
6429 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6430 }
Chuck Leverbf269552010-12-14 14:59:29 +00006431 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006432 if (status)
6433 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006434 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006435 if (status)
6436 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006437 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006438 if (status)
6439 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006440 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006441
6442out:
6443 return status;
6444}
6445
6446/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006447 * Decode CLOSE response
6448 */
Chuck Leverbf269552010-12-14 14:59:29 +00006449static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6450 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006451{
Andy Adamson05d564f2008-12-23 16:06:15 -05006452 struct compound_hdr hdr;
6453 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454
Chuck Leverbf269552010-12-14 14:59:29 +00006455 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006456 if (status)
6457 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006458 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006459 if (status)
6460 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006461 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006462 if (status)
6463 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006464 if (res->lr_res) {
6465 status = decode_layoutreturn(xdr, res->lr_res);
6466 res->lr_ret = status;
6467 if (status)
6468 goto out;
6469 }
Trond Myklebustd8d84982016-12-19 12:14:44 -05006470 if (res->fattr != NULL) {
6471 status = decode_getfattr(xdr, res->fattr, res->server);
6472 if (status != 0)
6473 goto out;
6474 }
Chuck Leverbf269552010-12-14 14:59:29 +00006475 status = decode_close(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006476out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006477 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006478}
6479
6480/*
6481 * Decode OPEN response
6482 */
Chuck Leverbf269552010-12-14 14:59:29 +00006483static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6484 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485{
Andy Adamson05d564f2008-12-23 16:06:15 -05006486 struct compound_hdr hdr;
6487 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006488
Chuck Leverbf269552010-12-14 14:59:29 +00006489 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006490 if (status)
6491 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006492 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006493 if (status)
6494 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006495 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006496 if (status)
6497 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006498 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006499 if (status)
6500 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006501 status = decode_getfh(xdr, &res->fh);
6502 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006503 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006504 if (res->access_request)
6505 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006506 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006508 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006509}
6510
6511/*
6512 * Decode OPEN_CONFIRM response
6513 */
Chuck Leverbf269552010-12-14 14:59:29 +00006514static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6515 struct xdr_stream *xdr,
6516 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006517{
Andy Adamson05d564f2008-12-23 16:06:15 -05006518 struct compound_hdr hdr;
6519 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520
Chuck Leverbf269552010-12-14 14:59:29 +00006521 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006522 if (status)
6523 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006524 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006525 if (status)
6526 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006527 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006528out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006529 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530}
6531
6532/*
6533 * Decode OPEN response
6534 */
Chuck Leverbf269552010-12-14 14:59:29 +00006535static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6536 struct xdr_stream *xdr,
6537 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006538{
Andy Adamson05d564f2008-12-23 16:06:15 -05006539 struct compound_hdr hdr;
6540 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541
Chuck Leverbf269552010-12-14 14:59:29 +00006542 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006543 if (status)
6544 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006545 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006546 if (status)
6547 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006548 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006549 if (status)
6550 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006552 if (status)
6553 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006554 if (res->access_request)
6555 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006556 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006557out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006558 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559}
6560
6561/*
6562 * Decode SETATTR response
6563 */
Chuck Leverbf269552010-12-14 14:59:29 +00006564static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6565 struct xdr_stream *xdr,
6566 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006567{
Andy Adamson05d564f2008-12-23 16:06:15 -05006568 struct compound_hdr hdr;
6569 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006570
Chuck Leverbf269552010-12-14 14:59:29 +00006571 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006572 if (status)
6573 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006574 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006575 if (status)
6576 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006577 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006578 if (status)
6579 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006580 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006581 if (status)
6582 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006583 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006584out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006585 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006586}
6587
6588/*
6589 * Decode LOCK response
6590 */
Chuck Leverbf269552010-12-14 14:59:29 +00006591static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6592 struct nfs_lock_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_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006607out:
6608 return status;
6609}
6610
6611/*
6612 * Decode LOCKT response
6613 */
Chuck Leverbf269552010-12-14 14:59:29 +00006614static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6615 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006616{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617 struct compound_hdr hdr;
6618 int status;
6619
Chuck Leverbf269552010-12-14 14:59:29 +00006620 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006621 if (status)
6622 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006623 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006624 if (status)
6625 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006626 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006627 if (status)
6628 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006629 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006630out:
6631 return status;
6632}
6633
6634/*
6635 * Decode LOCKU response
6636 */
Chuck Leverbf269552010-12-14 14:59:29 +00006637static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6638 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006639{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640 struct compound_hdr hdr;
6641 int status;
6642
Chuck Leverbf269552010-12-14 14:59:29 +00006643 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644 if (status)
6645 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006646 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006647 if (status)
6648 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006649 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650 if (status)
6651 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006652 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653out:
6654 return status;
6655}
6656
Chuck Leverbf269552010-12-14 14:59:29 +00006657static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6658 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006659{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006660 struct compound_hdr hdr;
6661 int status;
6662
Chuck Leverbf269552010-12-14 14:59:29 +00006663 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006664 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006665 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006666 return status;
6667}
6668
Linus Torvalds1da177e2005-04-16 15:20:36 -07006669/*
6670 * Decode READLINK response
6671 */
Chuck Leverbf269552010-12-14 14:59:29 +00006672static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6673 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006674 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006675{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006676 struct compound_hdr hdr;
6677 int status;
6678
Chuck Leverbf269552010-12-14 14:59:29 +00006679 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006680 if (status)
6681 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006682 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006683 if (status)
6684 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006685 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006686 if (status)
6687 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006688 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006689out:
6690 return status;
6691}
6692
6693/*
6694 * Decode READDIR response
6695 */
Chuck Leverbf269552010-12-14 14:59:29 +00006696static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6697 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006698{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699 struct compound_hdr hdr;
6700 int status;
6701
Chuck Leverbf269552010-12-14 14:59:29 +00006702 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006703 if (status)
6704 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006705 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006706 if (status)
6707 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006708 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006709 if (status)
6710 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006711 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712out:
6713 return status;
6714}
6715
6716/*
6717 * Decode Read response
6718 */
Chuck Leverbf269552010-12-14 14:59:29 +00006719static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006720 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006721{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006722 struct compound_hdr hdr;
6723 int status;
6724
Chuck Leverbf269552010-12-14 14:59:29 +00006725 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006726 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006727 if (status)
6728 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006729 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006730 if (status)
6731 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006732 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006733 if (status)
6734 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006735 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736 if (!status)
6737 status = res->count;
6738out:
6739 return status;
6740}
6741
6742/*
6743 * Decode WRITE response
6744 */
Chuck Leverbf269552010-12-14 14:59:29 +00006745static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006746 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006747{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006748 struct compound_hdr hdr;
6749 int status;
6750
Chuck Leverbf269552010-12-14 14:59:29 +00006751 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006752 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006753 if (status)
6754 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006755 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006756 if (status)
6757 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006758 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006759 if (status)
6760 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006761 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006762 if (status)
6763 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006764 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006765 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766 if (!status)
6767 status = res->count;
6768out:
6769 return status;
6770}
6771
6772/*
6773 * Decode COMMIT response
6774 */
Chuck Leverbf269552010-12-14 14:59:29 +00006775static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006776 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006777{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006778 struct compound_hdr hdr;
6779 int status;
6780
Chuck Leverbf269552010-12-14 14:59:29 +00006781 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006782 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006783 if (status)
6784 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006785 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006786 if (status)
6787 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006788 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006789 if (status)
6790 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006791 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006792out:
6793 return status;
6794}
6795
6796/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006797 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006798 */
Chuck Leverbf269552010-12-14 14:59:29 +00006799static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006800 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006801{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006802 struct compound_hdr hdr;
6803 int status;
6804
Chuck Leverbf269552010-12-14 14:59:29 +00006805 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006806 if (!status)
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)
Chuck Leverbf269552010-12-14 14:59:29 +00006809 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006810 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006811 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006812 return status;
6813}
6814
6815/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006816 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006817 */
Chuck Leverbf269552010-12-14 14:59:29 +00006818static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006819 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006820{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006821 struct compound_hdr hdr;
6822 int status;
6823
Chuck Leverbf269552010-12-14 14:59:29 +00006824 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006825 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006826 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006827 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006828 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006829 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006830 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006831 return status;
6832}
6833
6834/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006835 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006836 */
Chuck Leverbf269552010-12-14 14:59:29 +00006837static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006838 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006839{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006840 struct compound_hdr hdr;
6841 int status;
6842
Chuck Leverbf269552010-12-14 14:59:29 +00006843 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006844 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006845 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006846 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006847 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006848 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006849 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006850 return status;
6851}
6852
6853/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006854 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006855 */
Chuck Leverbf269552010-12-14 14:59:29 +00006856static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6857 struct xdr_stream *xdr,
6858 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006859{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006860 struct compound_hdr hdr;
6861 int status;
6862
Chuck Leverbf269552010-12-14 14:59:29 +00006863 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006864 if (status)
6865 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006866 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006867 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006868 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006869 status = decode_putfh(xdr);
6870 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006871 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006872 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006873out:
6874 return status;
6875}
6876
6877/*
6878 * Decode RENEW response
6879 */
Chuck Leverbf269552010-12-14 14:59:29 +00006880static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6881 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006882{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006883 struct compound_hdr hdr;
6884 int status;
6885
Chuck Leverbf269552010-12-14 14:59:29 +00006886 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006887 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006888 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006889 return status;
6890}
6891
6892/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006893 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006894 */
Chuck Leverbf269552010-12-14 14:59:29 +00006895static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6896 struct xdr_stream *xdr,
6897 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006898{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006899 struct compound_hdr hdr;
6900 int status;
6901
Chuck Leverbf269552010-12-14 14:59:29 +00006902 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006903 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006904 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006905 return status;
6906}
6907
6908/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006909 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006910 */
Chuck Leverbf269552010-12-14 14:59:29 +00006911static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006912 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006913{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006914 struct compound_hdr hdr;
6915 int status;
6916
Chuck Leverbf269552010-12-14 14:59:29 +00006917 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006918 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006919 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006920 return status;
6921}
6922
6923/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006924 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006925 */
Chuck Leverbf269552010-12-14 14:59:29 +00006926static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6927 struct xdr_stream *xdr,
6928 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006929{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006930 struct compound_hdr hdr;
6931 int status;
6932
Chuck Leverbf269552010-12-14 14:59:29 +00006933 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006934 if (status)
6935 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006936 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006937 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006938 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006939 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006940 if (status != 0)
6941 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05006942 if (res->lr_res) {
6943 status = decode_layoutreturn(xdr, res->lr_res);
6944 res->lr_ret = status;
6945 if (status)
6946 goto out;
6947 }
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05006948 if (res->fattr) {
6949 status = decode_getfattr(xdr, res->fattr, res->server);
6950 if (status != 0)
6951 goto out;
6952 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006953 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006954out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006955 return status;
6956}
6957
Trond Myklebust683b57b2006-06-09 09:34:22 -04006958/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006959 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006960 */
Chuck Leverbf269552010-12-14 14:59:29 +00006961static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6962 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006963 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006964{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006965 struct compound_hdr hdr;
6966 int status;
6967
Chuck Leverbf269552010-12-14 14:59:29 +00006968 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006969 if (status)
6970 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006971 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006972 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006973 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006974 status = decode_putfh(xdr);
6975 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006976 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006977 if (res->migration) {
6978 xdr_enter_page(xdr, PAGE_SIZE);
6979 status = decode_getfattr_generic(xdr,
6980 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006981 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006982 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006983 if (status)
6984 goto out;
6985 if (res->renew)
6986 status = decode_renew(xdr);
6987 } else {
6988 status = decode_lookup(xdr);
6989 if (status)
6990 goto out;
6991 xdr_enter_page(xdr, PAGE_SIZE);
6992 status = decode_getfattr_generic(xdr,
6993 &res->fs_locations->fattr,
6994 NULL, res->fs_locations,
6995 NULL, res->fs_locations->server);
6996 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006997out:
6998 return status;
6999}
7000
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007001/*
7002 * Decode SECINFO response
7003 */
7004static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7005 struct xdr_stream *xdr,
7006 struct nfs4_secinfo_res *res)
7007{
7008 struct compound_hdr hdr;
7009 int status;
7010
7011 status = decode_compound_hdr(xdr, &hdr);
7012 if (status)
7013 goto out;
7014 status = decode_sequence(xdr, &res->seq_res, rqstp);
7015 if (status)
7016 goto out;
7017 status = decode_putfh(xdr);
7018 if (status)
7019 goto out;
7020 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007021out:
7022 return status;
7023}
7024
Chuck Lever44c99932013-10-17 14:13:30 -04007025/*
7026 * Decode FSID_PRESENT response
7027 */
7028static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7029 struct xdr_stream *xdr,
7030 struct nfs4_fsid_present_res *res)
7031{
7032 struct compound_hdr hdr;
7033 int status;
7034
7035 status = decode_compound_hdr(xdr, &hdr);
7036 if (status)
7037 goto out;
7038 status = decode_sequence(xdr, &res->seq_res, rqstp);
7039 if (status)
7040 goto out;
7041 status = decode_putfh(xdr);
7042 if (status)
7043 goto out;
7044 status = decode_getfh(xdr, res->fh);
7045 if (status)
7046 goto out;
7047 if (res->renew)
7048 status = decode_renew(xdr);
7049out:
7050 return status;
7051}
7052
Benny Halevy99fe60d2009-04-01 09:22:29 -04007053#if defined(CONFIG_NFS_V4_1)
7054/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007055 * Decode BIND_CONN_TO_SESSION response
7056 */
7057static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7058 struct xdr_stream *xdr,
7059 void *res)
7060{
7061 struct compound_hdr hdr;
7062 int status;
7063
7064 status = decode_compound_hdr(xdr, &hdr);
7065 if (!status)
7066 status = decode_bind_conn_to_session(xdr, res);
7067 return status;
7068}
7069
7070/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007071 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007072 */
Chuck Leverbf269552010-12-14 14:59:29 +00007073static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7074 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007075 void *res)
7076{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007077 struct compound_hdr hdr;
7078 int status;
7079
Chuck Leverbf269552010-12-14 14:59:29 +00007080 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007081 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007082 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007083 return status;
7084}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007085
7086/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007087 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007088 */
Chuck Leverbf269552010-12-14 14:59:29 +00007089static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7090 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04007091 struct nfs41_create_session_res *res)
7092{
Andy Adamsonfc931582009-04-01 09:22:31 -04007093 struct compound_hdr hdr;
7094 int status;
7095
Chuck Leverbf269552010-12-14 14:59:29 +00007096 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007097 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007098 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007099 return status;
7100}
7101
7102/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007103 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007104 */
Chuck Leverbf269552010-12-14 14:59:29 +00007105static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7106 struct xdr_stream *xdr,
7107 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007108{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007109 struct compound_hdr hdr;
7110 int status;
7111
Chuck Leverbf269552010-12-14 14:59:29 +00007112 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007113 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007114 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007115 return status;
7116}
7117
7118/*
Trond Myklebust66245532012-05-25 17:18:09 -04007119 * Decode DESTROY_CLIENTID response
7120 */
7121static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7122 struct xdr_stream *xdr,
7123 void *res)
7124{
7125 struct compound_hdr hdr;
7126 int status;
7127
7128 status = decode_compound_hdr(xdr, &hdr);
7129 if (!status)
7130 status = decode_destroy_clientid(xdr, res);
7131 return status;
7132}
7133
7134/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007135 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007136 */
Chuck Leverbf269552010-12-14 14:59:29 +00007137static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7138 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007139 struct nfs4_sequence_res *res)
7140{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007141 struct compound_hdr hdr;
7142 int status;
7143
Chuck Leverbf269552010-12-14 14:59:29 +00007144 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007145 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007146 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007147 return status;
7148}
7149
7150/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007151 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007152 */
Chuck Leverbf269552010-12-14 14:59:29 +00007153static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7154 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04007155 struct nfs4_get_lease_time_res *res)
7156{
Andy Adamson2050f0c2009-04-01 09:22:30 -04007157 struct compound_hdr hdr;
7158 int status;
7159
Chuck Leverbf269552010-12-14 14:59:29 +00007160 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007161 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007162 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007163 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007164 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007165 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007166 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007167 return status;
7168}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007169
7170/*
7171 * Decode RECLAIM_COMPLETE response
7172 */
Chuck Leverbf269552010-12-14 14:59:29 +00007173static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7174 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007175 struct nfs41_reclaim_complete_res *res)
7176{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007177 struct compound_hdr hdr;
7178 int status;
7179
Chuck Leverbf269552010-12-14 14:59:29 +00007180 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007181 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007182 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007183 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307184 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007185 return status;
7186}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007187
7188/*
7189 * Decode GETDEVINFO response
7190 */
Chuck Leverbf269552010-12-14 14:59:29 +00007191static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7192 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007193 struct nfs4_getdeviceinfo_res *res)
7194{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007195 struct compound_hdr hdr;
7196 int status;
7197
Chuck Leverbf269552010-12-14 14:59:29 +00007198 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007199 if (status != 0)
7200 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007201 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007202 if (status != 0)
7203 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007204 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007205out:
7206 return status;
7207}
7208
7209/*
7210 * Decode LAYOUTGET response
7211 */
Chuck Leverbf269552010-12-14 14:59:29 +00007212static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7213 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007214 struct nfs4_layoutget_res *res)
7215{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007216 struct compound_hdr hdr;
7217 int status;
7218
Chuck Leverbf269552010-12-14 14:59:29 +00007219 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007220 if (status)
7221 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007222 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007223 if (status)
7224 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007225 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007226 if (status)
7227 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007228 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007229out:
7230 return status;
7231}
Andy Adamson863a3c62011-03-23 13:27:54 +00007232
7233/*
Benny Halevycbe82602011-05-22 19:52:37 +03007234 * Decode LAYOUTRETURN response
7235 */
7236static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7237 struct xdr_stream *xdr,
7238 struct nfs4_layoutreturn_res *res)
7239{
7240 struct compound_hdr hdr;
7241 int status;
7242
7243 status = decode_compound_hdr(xdr, &hdr);
7244 if (status)
7245 goto out;
7246 status = decode_sequence(xdr, &res->seq_res, rqstp);
7247 if (status)
7248 goto out;
7249 status = decode_putfh(xdr);
7250 if (status)
7251 goto out;
7252 status = decode_layoutreturn(xdr, res);
7253out:
7254 return status;
7255}
7256
7257/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007258 * Decode LAYOUTCOMMIT response
7259 */
7260static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7261 struct xdr_stream *xdr,
7262 struct nfs4_layoutcommit_res *res)
7263{
7264 struct compound_hdr hdr;
7265 int status;
7266
7267 status = decode_compound_hdr(xdr, &hdr);
7268 if (status)
7269 goto out;
7270 status = decode_sequence(xdr, &res->seq_res, rqstp);
7271 if (status)
7272 goto out;
7273 status = decode_putfh(xdr);
7274 if (status)
7275 goto out;
7276 status = decode_layoutcommit(xdr, rqstp, res);
7277 if (status)
7278 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007279 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007280out:
7281 return status;
7282}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007283
7284/*
7285 * Decode SECINFO_NO_NAME response
7286 */
7287static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7288 struct xdr_stream *xdr,
7289 struct nfs4_secinfo_res *res)
7290{
7291 struct compound_hdr hdr;
7292 int status;
7293
7294 status = decode_compound_hdr(xdr, &hdr);
7295 if (status)
7296 goto out;
7297 status = decode_sequence(xdr, &res->seq_res, rqstp);
7298 if (status)
7299 goto out;
7300 status = decode_putrootfh(xdr);
7301 if (status)
7302 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007303 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007304out:
7305 return status;
7306}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007307
7308/*
7309 * Decode TEST_STATEID response
7310 */
7311static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7312 struct xdr_stream *xdr,
7313 struct nfs41_test_stateid_res *res)
7314{
7315 struct compound_hdr hdr;
7316 int status;
7317
7318 status = decode_compound_hdr(xdr, &hdr);
7319 if (status)
7320 goto out;
7321 status = decode_sequence(xdr, &res->seq_res, rqstp);
7322 if (status)
7323 goto out;
7324 status = decode_test_stateid(xdr, res);
7325out:
7326 return status;
7327}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007328
7329/*
7330 * Decode FREE_STATEID response
7331 */
7332static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7333 struct xdr_stream *xdr,
7334 struct nfs41_free_stateid_res *res)
7335{
7336 struct compound_hdr hdr;
7337 int status;
7338
7339 status = decode_compound_hdr(xdr, &hdr);
7340 if (status)
7341 goto out;
7342 status = decode_sequence(xdr, &res->seq_res, rqstp);
7343 if (status)
7344 goto out;
7345 status = decode_free_stateid(xdr, res);
7346out:
7347 return status;
7348}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007349#endif /* CONFIG_NFS_V4_1 */
7350
Chuck Lever573c4e12010-12-14 14:58:11 +00007351/**
7352 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7353 * the local page cache.
7354 * @xdr: XDR stream where entry resides
7355 * @entry: buffer to fill in with entry data
7356 * @plus: boolean indicating whether this should be a readdirplus entry
7357 *
7358 * Returns zero if successful, otherwise a negative errno value is
7359 * returned.
7360 *
7361 * This function is not invoked during READDIR reply decoding, but
7362 * rather whenever an application invokes the getdents(2) system call
7363 * on a directory already in our cache.
7364 */
7365int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7366 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007367{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007368 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007369 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007370 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007371 __be32 *p = xdr_inline_decode(xdr, 4);
7372 if (unlikely(!p))
7373 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007374 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007375 p = xdr_inline_decode(xdr, 4);
7376 if (unlikely(!p))
7377 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007378 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007379 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007380 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007381 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007382 }
7383
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007384 p = xdr_inline_decode(xdr, 12);
7385 if (unlikely(!p))
7386 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007387 entry->prev_cookie = entry->cookie;
7388 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007389 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007390
Trond Myklebust9af8c222010-10-24 11:52:55 -04007391 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007392 if (unlikely(!p))
7393 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007394 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007395
7396 /*
7397 * In case the server doesn't return an inode number,
7398 * we fake one here. (We don't use inode number 0,
7399 * since glibc seems to choke on it...)
7400 */
7401 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007402 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007403
Trond Myklebust9af8c222010-10-24 11:52:55 -04007404 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007405 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007406
Trond Myklebust256e48b2012-06-21 11:18:13 -04007407 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007408 goto out_overflow;
7409
Chuck Lever573c4e12010-12-14 14:58:11 +00007410 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007411 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007412 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007413 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7414 entry->ino = entry->fattr->mounted_on_fileid;
7415 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007416 entry->ino = entry->fattr->fileid;
7417
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007418 entry->d_type = DT_UNKNOWN;
7419 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7420 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7421
Chuck Lever573c4e12010-12-14 14:58:11 +00007422 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007423
7424out_overflow:
7425 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007426 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007427}
7428
7429/*
7430 * We need to translate between nfs status return values and
7431 * the local errno values which may not be the same.
7432 */
7433static struct {
7434 int stat;
7435 int errno;
7436} nfs_errtbl[] = {
7437 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007438 { NFS4ERR_PERM, -EPERM },
7439 { NFS4ERR_NOENT, -ENOENT },
7440 { NFS4ERR_IO, -errno_NFSERR_IO},
7441 { NFS4ERR_NXIO, -ENXIO },
7442 { NFS4ERR_ACCESS, -EACCES },
7443 { NFS4ERR_EXIST, -EEXIST },
7444 { NFS4ERR_XDEV, -EXDEV },
7445 { NFS4ERR_NOTDIR, -ENOTDIR },
7446 { NFS4ERR_ISDIR, -EISDIR },
7447 { NFS4ERR_INVAL, -EINVAL },
7448 { NFS4ERR_FBIG, -EFBIG },
7449 { NFS4ERR_NOSPC, -ENOSPC },
7450 { NFS4ERR_ROFS, -EROFS },
7451 { NFS4ERR_MLINK, -EMLINK },
7452 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7453 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7454 { NFS4ERR_DQUOT, -EDQUOT },
7455 { NFS4ERR_STALE, -ESTALE },
7456 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007457 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7458 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7459 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007460 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007461 { NFS4ERR_BADTYPE, -EBADTYPE },
7462 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007463 { NFS4ERR_SYMLINK, -ELOOP },
7464 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7465 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007466 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007467};
7468
7469/*
7470 * Convert an NFS error code to a local one.
7471 * This one is used jointly by NFSv2 and NFSv3.
7472 */
7473static int
David Howells0a8ea432006-08-22 20:06:08 -04007474nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007475{
7476 int i;
7477 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7478 if (nfs_errtbl[i].stat == stat)
7479 return nfs_errtbl[i].errno;
7480 }
7481 if (stat <= 10000 || stat > 10100) {
7482 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007483 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007484 }
7485 /* If we cannot translate the error, the recovery routines should
7486 * handle it.
7487 * Note: remaining NFSv4 error codes have values > 10000, so should
7488 * not conflict with native Linux error codes.
7489 */
Benny Halevy856dff32008-03-31 17:39:06 +03007490 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007491}
7492
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007493#ifdef CONFIG_NFS_V4_2
7494#include "nfs42xdr.c"
7495#endif /* CONFIG_NFS_V4_2 */
7496
Linus Torvalds1da177e2005-04-16 15:20:36 -07007497#define PROC(proc, argtype, restype) \
7498[NFSPROC4_CLNT_##proc] = { \
7499 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007500 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007501 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007502 .p_arglen = NFS4_##argtype##_sz, \
7503 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007504 .p_statidx = NFSPROC4_CLNT_##proc, \
7505 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007506}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007507
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007508#define STUB(proc) \
7509[NFSPROC4_CLNT_##proc] = { \
7510 .p_name = #proc, \
7511}
7512
Linus Torvalds1da177e2005-04-16 15:20:36 -07007513struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007514 PROC(READ, enc_read, dec_read),
7515 PROC(WRITE, enc_write, dec_write),
7516 PROC(COMMIT, enc_commit, dec_commit),
7517 PROC(OPEN, enc_open, dec_open),
7518 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7519 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7520 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7521 PROC(CLOSE, enc_close, dec_close),
7522 PROC(SETATTR, enc_setattr, dec_setattr),
7523 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7524 PROC(RENEW, enc_renew, dec_renew),
7525 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7526 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7527 PROC(LOCK, enc_lock, dec_lock),
7528 PROC(LOCKT, enc_lockt, dec_lockt),
7529 PROC(LOCKU, enc_locku, dec_locku),
7530 PROC(ACCESS, enc_access, dec_access),
7531 PROC(GETATTR, enc_getattr, dec_getattr),
7532 PROC(LOOKUP, enc_lookup, dec_lookup),
7533 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7534 PROC(REMOVE, enc_remove, dec_remove),
7535 PROC(RENAME, enc_rename, dec_rename),
7536 PROC(LINK, enc_link, dec_link),
7537 PROC(SYMLINK, enc_symlink, dec_symlink),
7538 PROC(CREATE, enc_create, dec_create),
7539 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7540 PROC(STATFS, enc_statfs, dec_statfs),
7541 PROC(READLINK, enc_readlink, dec_readlink),
7542 PROC(READDIR, enc_readdir, dec_readdir),
7543 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7544 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7545 PROC(GETACL, enc_getacl, dec_getacl),
7546 PROC(SETACL, enc_setacl, dec_setacl),
7547 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7548 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007549 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007550 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007551#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007552 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7553 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7554 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7555 PROC(SEQUENCE, enc_sequence, dec_sequence),
7556 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7557 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7558 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7559 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007560 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007561 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007562 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007563 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007564 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007565 STUB(GETDEVICELIST),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007566 PROC(BIND_CONN_TO_SESSION,
7567 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007568 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007569#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007570#ifdef CONFIG_NFS_V4_2
7571 PROC(SEEK, enc_seek, dec_seek),
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007572 PROC(ALLOCATE, enc_allocate, dec_allocate),
Anna Schumaker624bd5b2014-11-25 13:18:16 -05007573 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
Trond Myklebustbe3a5d22015-06-23 19:51:55 +08007574 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
Peng Tao36022772015-09-26 02:24:34 +08007575 PROC(CLONE, enc_clone, dec_clone),
Anna Schumaker2e724482013-05-21 16:53:03 -04007576 PROC(COPY, enc_copy, dec_copy),
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007577#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007578};
7579
Trond Myklebusta613fa12012-01-20 13:53:56 -05007580const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007581 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007582 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007583 .procs = nfs4_procedures
7584};
7585
7586/*
7587 * Local variables:
7588 * c-basic-offset: 8
7589 * End:
7590 */