blob: 5f0a6fcd00307d9051baf74bfdf0f567a2973212 [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{
Al Viro8687b632006-10-19 23:28:48 -07003053 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054
Benny Halevyc0eae662009-08-14 17:20:14 +03003055 p = xdr_inline_decode(xdr, 4);
3056 if (unlikely(!p))
3057 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003058 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003059 p = xdr_inline_decode(xdr, *len);
3060 if (unlikely(!p))
3061 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 *string = (char *)p;
3063 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003064out_overflow:
3065 print_overflow_msg(__func__, xdr);
3066 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067}
3068
3069static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3070{
Al Viro8687b632006-10-19 23:28:48 -07003071 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072
Benny Halevyc0eae662009-08-14 17:20:14 +03003073 p = xdr_inline_decode(xdr, 8);
3074 if (unlikely(!p))
3075 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003076 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003077 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003078
Benny Halevyc0eae662009-08-14 17:20:14 +03003079 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3080 if (unlikely(!p))
3081 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 hdr->tag = (char *)p;
3083 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003084 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003085 if (unlikely(hdr->nops < 1))
3086 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003088out_overflow:
3089 print_overflow_msg(__func__, xdr);
3090 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091}
3092
Trond Myklebustc7848f62013-12-04 17:39:23 -05003093static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3094 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095{
Al Viro8687b632006-10-19 23:28:48 -07003096 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 uint32_t opnum;
3098 int32_t nfserr;
3099
Benny Halevyc0eae662009-08-14 17:20:14 +03003100 p = xdr_inline_decode(xdr, 8);
3101 if (unlikely(!p))
3102 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003103 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003104 if (unlikely(opnum != expected))
3105 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003106 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003107 if (nfserr == NFS_OK)
3108 *nfs_retval = 0;
3109 else
3110 *nfs_retval = nfs4_stat_to_errno(nfserr);
3111 return true;
3112out_bad_operation:
3113 dprintk("nfs: Server returned operation"
3114 " %d but we issued a request for %d\n",
3115 opnum, expected);
3116 *nfs_retval = -EREMOTEIO;
3117 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003118out_overflow:
3119 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003120 *nfs_retval = -EIO;
3121 return false;
3122}
3123
3124static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3125{
3126 int retval;
3127
3128 __decode_op_hdr(xdr, expected, &retval);
3129 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130}
3131
3132/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003133static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134{
Al Viro8687b632006-10-19 23:28:48 -07003135 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003136 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 char *str;
3138
Benny Halevyc0eae662009-08-14 17:20:14 +03003139 p = xdr_inline_decode(xdr, 12);
3140 if (likely(p))
3141 return decode_opaque_inline(xdr, &strlen, &str);
3142 print_overflow_msg(__func__, xdr);
3143 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144}
3145
3146static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3147{
Al Viro8687b632006-10-19 23:28:48 -07003148 uint32_t bmlen;
3149 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150
Benny Halevyc0eae662009-08-14 17:20:14 +03003151 p = xdr_inline_decode(xdr, 4);
3152 if (unlikely(!p))
3153 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003154 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155
Fred Isamandae100c2011-07-30 20:52:37 -04003156 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003157 p = xdr_inline_decode(xdr, (bmlen << 2));
3158 if (unlikely(!p))
3159 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003161 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003162 if (bmlen > 1) {
3163 bitmap[1] = be32_to_cpup(p++);
3164 if (bmlen > 2)
3165 bitmap[2] = be32_to_cpup(p);
3166 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 }
3168 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003169out_overflow:
3170 print_overflow_msg(__func__, xdr);
3171 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172}
3173
Trond Myklebust256e48b2012-06-21 11:18:13 -04003174static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175{
Al Viro8687b632006-10-19 23:28:48 -07003176 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177
Benny Halevyc0eae662009-08-14 17:20:14 +03003178 p = xdr_inline_decode(xdr, 4);
3179 if (unlikely(!p))
3180 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003181 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003182 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003184out_overflow:
3185 print_overflow_msg(__func__, xdr);
3186 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187}
3188
3189static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3190{
3191 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003192 int ret;
3193 ret = decode_attr_bitmap(xdr, bitmask);
3194 if (unlikely(ret < 0))
3195 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3197 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003198 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3199 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3200 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 return 0;
3202}
3203
3204static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3205{
Al Viro8687b632006-10-19 23:28:48 -07003206 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003207 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208
3209 *type = 0;
3210 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3211 return -EIO;
3212 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003213 p = xdr_inline_decode(xdr, 4);
3214 if (unlikely(!p))
3215 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003216 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003218 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 return -EIO;
3220 }
3221 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003222 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003224 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003225 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003226out_overflow:
3227 print_overflow_msg(__func__, xdr);
3228 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229}
3230
Chuck Lever264e6352012-03-01 17:02:05 -05003231static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3232 uint32_t *bitmap, uint32_t *type)
3233{
3234 __be32 *p;
3235
3236 *type = 0;
3237 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3238 return -EIO;
3239 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3240 p = xdr_inline_decode(xdr, 4);
3241 if (unlikely(!p))
3242 goto out_overflow;
3243 *type = be32_to_cpup(p);
3244 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3245 }
3246 dprintk("%s: expire type=0x%x\n", __func__, *type);
3247 return 0;
3248out_overflow:
3249 print_overflow_msg(__func__, xdr);
3250 return -EIO;
3251}
3252
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3254{
Al Viro8687b632006-10-19 23:28:48 -07003255 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003256 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257
3258 *change = 0;
3259 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3260 return -EIO;
3261 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003262 p = xdr_inline_decode(xdr, 8);
3263 if (unlikely(!p))
3264 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003265 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003267 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003269 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003271 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003272out_overflow:
3273 print_overflow_msg(__func__, xdr);
3274 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275}
3276
3277static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3278{
Al Viro8687b632006-10-19 23:28:48 -07003279 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003280 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281
3282 *size = 0;
3283 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3284 return -EIO;
3285 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003286 p = xdr_inline_decode(xdr, 8);
3287 if (unlikely(!p))
3288 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003289 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003291 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003293 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003294 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003295out_overflow:
3296 print_overflow_msg(__func__, xdr);
3297 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298}
3299
3300static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3301{
Al Viro8687b632006-10-19 23:28:48 -07003302 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303
3304 *res = 0;
3305 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3306 return -EIO;
3307 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003308 p = xdr_inline_decode(xdr, 4);
3309 if (unlikely(!p))
3310 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003311 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3313 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003314 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003316out_overflow:
3317 print_overflow_msg(__func__, xdr);
3318 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319}
3320
3321static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3322{
Al Viro8687b632006-10-19 23:28:48 -07003323 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324
3325 *res = 0;
3326 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3327 return -EIO;
3328 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003329 p = xdr_inline_decode(xdr, 4);
3330 if (unlikely(!p))
3331 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003332 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3334 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003335 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003337out_overflow:
3338 print_overflow_msg(__func__, xdr);
3339 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340}
3341
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003342static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343{
Al Viro8687b632006-10-19 23:28:48 -07003344 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003345 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346
3347 fsid->major = 0;
3348 fsid->minor = 0;
3349 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3350 return -EIO;
3351 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003352 p = xdr_inline_decode(xdr, 16);
3353 if (unlikely(!p))
3354 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003355 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003356 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003358 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003360 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 (unsigned long long)fsid->major,
3362 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003363 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003364out_overflow:
3365 print_overflow_msg(__func__, xdr);
3366 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367}
3368
3369static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3370{
Al Viro8687b632006-10-19 23:28:48 -07003371 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372
3373 *res = 60;
3374 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3375 return -EIO;
3376 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003377 p = xdr_inline_decode(xdr, 4);
3378 if (unlikely(!p))
3379 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003380 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3382 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003383 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003385out_overflow:
3386 print_overflow_msg(__func__, xdr);
3387 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388}
3389
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003390static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003391{
3392 __be32 *p;
3393
3394 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3395 return -EIO;
3396 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3397 p = xdr_inline_decode(xdr, 4);
3398 if (unlikely(!p))
3399 goto out_overflow;
3400 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003401 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003402 }
3403 return 0;
3404out_overflow:
3405 print_overflow_msg(__func__, xdr);
3406 return -EIO;
3407}
3408
Kinglong Mee8c612822015-08-26 21:12:58 +08003409static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3410 uint32_t *bitmap, uint32_t *bitmask)
3411{
3412 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3413 int ret;
3414 ret = decode_attr_bitmap(xdr, bitmask);
3415 if (unlikely(ret < 0))
3416 return ret;
3417 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3418 } else
3419 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3420 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3421 bitmask[0], bitmask[1], bitmask[2]);
3422 return 0;
3423}
3424
Bryan Schumakerae42c702010-10-21 16:33:17 -04003425static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3426{
3427 __be32 *p;
3428 int len;
3429
Trond Myklebust7ad07352010-10-23 15:34:20 -04003430 if (fh != NULL)
3431 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003432
3433 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3434 return -EIO;
3435 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3436 p = xdr_inline_decode(xdr, 4);
3437 if (unlikely(!p))
3438 goto out_overflow;
3439 len = be32_to_cpup(p);
3440 if (len > NFS4_FHSIZE)
3441 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003442 p = xdr_inline_decode(xdr, len);
3443 if (unlikely(!p))
3444 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003445 if (fh != NULL) {
3446 memcpy(fh->data, p, len);
3447 fh->size = len;
3448 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003449 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3450 }
3451 return 0;
3452out_overflow:
3453 print_overflow_msg(__func__, xdr);
3454 return -EIO;
3455}
3456
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3458{
Al Viro8687b632006-10-19 23:28:48 -07003459 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003461 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3463 return -EIO;
3464 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003465 p = xdr_inline_decode(xdr, 4);
3466 if (unlikely(!p))
3467 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003468 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3470 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003471 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003473out_overflow:
3474 print_overflow_msg(__func__, xdr);
3475 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476}
3477
3478static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3479{
Al Viro8687b632006-10-19 23:28:48 -07003480 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003481 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482
3483 *fileid = 0;
3484 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3485 return -EIO;
3486 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003487 p = xdr_inline_decode(xdr, 8);
3488 if (unlikely(!p))
3489 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003490 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003492 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003494 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003495 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003496out_overflow:
3497 print_overflow_msg(__func__, xdr);
3498 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499}
3500
Manoj Naik99baf622006-06-09 09:34:24 -04003501static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3502{
Al Viro8687b632006-10-19 23:28:48 -07003503 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003504 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003505
3506 *fileid = 0;
3507 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3508 return -EIO;
3509 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003510 p = xdr_inline_decode(xdr, 8);
3511 if (unlikely(!p))
3512 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003513 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003514 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003515 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003516 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003517 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003518 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003519out_overflow:
3520 print_overflow_msg(__func__, xdr);
3521 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003522}
3523
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3525{
Al Viro8687b632006-10-19 23:28:48 -07003526 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527 int status = 0;
3528
3529 *res = 0;
3530 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3531 return -EIO;
3532 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003533 p = xdr_inline_decode(xdr, 8);
3534 if (unlikely(!p))
3535 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003536 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3538 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003539 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003541out_overflow:
3542 print_overflow_msg(__func__, xdr);
3543 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544}
3545
3546static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3547{
Al Viro8687b632006-10-19 23:28:48 -07003548 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 int status = 0;
3550
3551 *res = 0;
3552 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3553 return -EIO;
3554 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003555 p = xdr_inline_decode(xdr, 8);
3556 if (unlikely(!p))
3557 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003558 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3560 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003561 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003563out_overflow:
3564 print_overflow_msg(__func__, xdr);
3565 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566}
3567
3568static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3569{
Al Viro8687b632006-10-19 23:28:48 -07003570 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571 int status = 0;
3572
3573 *res = 0;
3574 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3575 return -EIO;
3576 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003577 p = xdr_inline_decode(xdr, 8);
3578 if (unlikely(!p))
3579 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003580 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3582 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003583 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003585out_overflow:
3586 print_overflow_msg(__func__, xdr);
3587 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588}
3589
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003590static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3591{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003592 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003593 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003594 int status = 0;
3595
Benny Halevyc0eae662009-08-14 17:20:14 +03003596 p = xdr_inline_decode(xdr, 4);
3597 if (unlikely(!p))
3598 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003599 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003600 if (n == 0)
3601 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003602 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003603 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3604 dprintk("cannot parse %d components in path\n", n);
3605 goto out_eio;
3606 }
3607 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003608 struct nfs4_string *component = &path->components[path->ncomponents];
3609 status = decode_opaque_inline(xdr, &component->len, &component->data);
3610 if (unlikely(status != 0))
3611 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003612 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003613 pr_cont("%s%.*s ",
3614 (path->ncomponents != n ? "/ " : ""),
3615 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003616 }
3617out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003618 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003619root_path:
3620/* a root pathname is sent as a zero component4 */
3621 path->ncomponents = 1;
3622 path->components[0].len=0;
3623 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003624 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003625 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003626out_eio:
3627 dprintk(" status %d", status);
3628 status = -EIO;
3629 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003630out_overflow:
3631 print_overflow_msg(__func__, xdr);
3632 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003633}
3634
3635static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003636{
3637 int n;
Al Viro8687b632006-10-19 23:28:48 -07003638 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003639 int status = -EIO;
3640
3641 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3642 goto out;
3643 status = 0;
3644 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3645 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003646 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003647 status = -EIO;
3648 /* Ignore borken servers that return unrequested attrs */
3649 if (unlikely(res == NULL))
3650 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003651 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003652 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003653 if (unlikely(status != 0))
3654 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003655 p = xdr_inline_decode(xdr, 4);
3656 if (unlikely(!p))
3657 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003658 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003659 if (n <= 0)
3660 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003661 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003662 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003663 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003664
Trond Myklebust809b4262013-03-27 11:54:45 -04003665 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3666 break;
3667 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003668 p = xdr_inline_decode(xdr, 4);
3669 if (unlikely(!p))
3670 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003671 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003672
Chuck Lever02a29762012-03-01 17:00:31 -05003673 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003674 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3675 struct nfs4_string *server;
3676
3677 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003678 unsigned int i;
3679 dprintk("%s: using first %u of %u servers "
3680 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003681 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003682 NFS4_FS_LOCATION_MAXSERVERS,
3683 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003684 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003685 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003686 char *data;
3687 status = decode_opaque_inline(xdr, &len, &data);
3688 if (unlikely(status != 0))
3689 goto out_eio;
3690 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003691 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003692 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003693 server = &loc->servers[loc->nservers];
3694 status = decode_opaque_inline(xdr, &server->len, &server->data);
3695 if (unlikely(status != 0))
3696 goto out_eio;
3697 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003698 }
3699 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003700 if (unlikely(status != 0))
3701 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003702 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003703 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003704 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003705out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003706 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003707 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003708out_overflow:
3709 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003710out_eio:
3711 status = -EIO;
3712 goto out;
3713}
3714
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3716{
Al Viro8687b632006-10-19 23:28:48 -07003717 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718 int status = 0;
3719
3720 *res = 0;
3721 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3722 return -EIO;
3723 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003724 p = xdr_inline_decode(xdr, 8);
3725 if (unlikely(!p))
3726 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003727 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3729 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003730 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003732out_overflow:
3733 print_overflow_msg(__func__, xdr);
3734 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735}
3736
3737static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3738{
Al Viro8687b632006-10-19 23:28:48 -07003739 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740 int status = 0;
3741
3742 *maxlink = 1;
3743 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3744 return -EIO;
3745 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003746 p = xdr_inline_decode(xdr, 4);
3747 if (unlikely(!p))
3748 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003749 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3751 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003752 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003754out_overflow:
3755 print_overflow_msg(__func__, xdr);
3756 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757}
3758
3759static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3760{
Al Viro8687b632006-10-19 23:28:48 -07003761 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762 int status = 0;
3763
3764 *maxname = 1024;
3765 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3766 return -EIO;
3767 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003768 p = xdr_inline_decode(xdr, 4);
3769 if (unlikely(!p))
3770 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003771 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3773 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003774 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003776out_overflow:
3777 print_overflow_msg(__func__, xdr);
3778 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779}
3780
3781static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3782{
Al Viro8687b632006-10-19 23:28:48 -07003783 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 int status = 0;
3785
3786 *res = 1024;
3787 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3788 return -EIO;
3789 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3790 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003791 p = xdr_inline_decode(xdr, 8);
3792 if (unlikely(!p))
3793 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003794 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795 if (maxread > 0x7FFFFFFF)
3796 maxread = 0x7FFFFFFF;
3797 *res = (uint32_t)maxread;
3798 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3799 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003800 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003802out_overflow:
3803 print_overflow_msg(__func__, xdr);
3804 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805}
3806
3807static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3808{
Al Viro8687b632006-10-19 23:28:48 -07003809 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 int status = 0;
3811
3812 *res = 1024;
3813 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3814 return -EIO;
3815 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3816 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003817 p = xdr_inline_decode(xdr, 8);
3818 if (unlikely(!p))
3819 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003820 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821 if (maxwrite > 0x7FFFFFFF)
3822 maxwrite = 0x7FFFFFFF;
3823 *res = (uint32_t)maxwrite;
3824 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3825 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003826 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003828out_overflow:
3829 print_overflow_msg(__func__, xdr);
3830 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831}
3832
Trond Myklebustbca79472009-03-11 14:10:26 -04003833static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834{
Trond Myklebustbca79472009-03-11 14:10:26 -04003835 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003836 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003837 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838
3839 *mode = 0;
3840 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3841 return -EIO;
3842 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003843 p = xdr_inline_decode(xdr, 4);
3844 if (unlikely(!p))
3845 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003846 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003847 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003849 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003851 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003852 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003853out_overflow:
3854 print_overflow_msg(__func__, xdr);
3855 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856}
3857
3858static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3859{
Al Viro8687b632006-10-19 23:28:48 -07003860 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003861 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862
3863 *nlink = 1;
3864 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3865 return -EIO;
3866 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003867 p = xdr_inline_decode(xdr, 4);
3868 if (unlikely(!p))
3869 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003870 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003872 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003874 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003875 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003876out_overflow:
3877 print_overflow_msg(__func__, xdr);
3878 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879}
3880
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003881static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003882 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003883 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884{
Al Viro8687b632006-10-19 23:28:48 -07003885 uint32_t len;
3886 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003887 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888
Eric W. Biedermane5782072013-02-01 14:22:02 -08003889 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3891 return -EIO;
3892 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003893 p = xdr_inline_decode(xdr, 4);
3894 if (unlikely(!p))
3895 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003896 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003897 p = xdr_inline_decode(xdr, len);
3898 if (unlikely(!p))
3899 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003900 if (owner_name != NULL) {
3901 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3902 if (owner_name->data != NULL) {
3903 owner_name->len = len;
3904 ret = NFS_ATTR_FATTR_OWNER_NAME;
3905 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003906 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003907 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003908 ret = NFS_ATTR_FATTR_OWNER;
3909 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003911 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003913 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003914 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3916 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003917 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003918 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003919out_overflow:
3920 print_overflow_msg(__func__, xdr);
3921 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922}
3923
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003924static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003925 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003926 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927{
Al Viro8687b632006-10-19 23:28:48 -07003928 uint32_t len;
3929 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003930 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931
Eric W. Biedermane5782072013-02-01 14:22:02 -08003932 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3934 return -EIO;
3935 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003936 p = xdr_inline_decode(xdr, 4);
3937 if (unlikely(!p))
3938 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003939 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003940 p = xdr_inline_decode(xdr, len);
3941 if (unlikely(!p))
3942 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003943 if (group_name != NULL) {
3944 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3945 if (group_name->data != NULL) {
3946 group_name->len = len;
3947 ret = NFS_ATTR_FATTR_GROUP_NAME;
3948 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003949 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003950 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003951 ret = NFS_ATTR_FATTR_GROUP;
3952 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003954 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003956 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003957 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3959 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003960 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003961 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003962out_overflow:
3963 print_overflow_msg(__func__, xdr);
3964 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965}
3966
3967static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3968{
Al Viro8687b632006-10-19 23:28:48 -07003969 uint32_t major = 0, minor = 0;
3970 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003971 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972
3973 *rdev = MKDEV(0,0);
3974 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3975 return -EIO;
3976 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3977 dev_t tmp;
3978
Benny Halevyc0eae662009-08-14 17:20:14 +03003979 p = xdr_inline_decode(xdr, 8);
3980 if (unlikely(!p))
3981 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003982 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003983 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 tmp = MKDEV(major, minor);
3985 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3986 *rdev = tmp;
3987 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003988 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003990 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003991 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003992out_overflow:
3993 print_overflow_msg(__func__, xdr);
3994 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995}
3996
3997static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3998{
Al Viro8687b632006-10-19 23:28:48 -07003999 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 int status = 0;
4001
4002 *res = 0;
4003 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
4004 return -EIO;
4005 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004006 p = xdr_inline_decode(xdr, 8);
4007 if (unlikely(!p))
4008 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004009 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4011 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004012 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004014out_overflow:
4015 print_overflow_msg(__func__, xdr);
4016 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017}
4018
4019static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4020{
Al Viro8687b632006-10-19 23:28:48 -07004021 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 int status = 0;
4023
4024 *res = 0;
4025 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4026 return -EIO;
4027 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004028 p = xdr_inline_decode(xdr, 8);
4029 if (unlikely(!p))
4030 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004031 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4033 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004034 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004036out_overflow:
4037 print_overflow_msg(__func__, xdr);
4038 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039}
4040
4041static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4042{
Al Viro8687b632006-10-19 23:28:48 -07004043 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044 int status = 0;
4045
4046 *res = 0;
4047 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4048 return -EIO;
4049 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004050 p = xdr_inline_decode(xdr, 8);
4051 if (unlikely(!p))
4052 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004053 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4055 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004056 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004058out_overflow:
4059 print_overflow_msg(__func__, xdr);
4060 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061}
4062
4063static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4064{
Al Viro8687b632006-10-19 23:28:48 -07004065 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004066 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067
4068 *used = 0;
4069 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4070 return -EIO;
4071 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004072 p = xdr_inline_decode(xdr, 8);
4073 if (unlikely(!p))
4074 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004075 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004077 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004079 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004081 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004082out_overflow:
4083 print_overflow_msg(__func__, xdr);
4084 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085}
4086
4087static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4088{
Al Viro8687b632006-10-19 23:28:48 -07004089 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090 uint64_t sec;
4091 uint32_t nsec;
4092
Benny Halevyc0eae662009-08-14 17:20:14 +03004093 p = xdr_inline_decode(xdr, 12);
4094 if (unlikely(!p))
4095 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004096 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004097 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 time->tv_sec = (time_t)sec;
4099 time->tv_nsec = (long)nsec;
4100 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004101out_overflow:
4102 print_overflow_msg(__func__, xdr);
4103 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104}
4105
4106static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4107{
4108 int status = 0;
4109
4110 time->tv_sec = 0;
4111 time->tv_nsec = 0;
4112 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4113 return -EIO;
4114 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4115 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004116 if (status == 0)
4117 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4119 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004120 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 return status;
4122}
4123
4124static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4125{
4126 int status = 0;
4127
4128 time->tv_sec = 0;
4129 time->tv_nsec = 0;
4130 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4131 return -EIO;
4132 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4133 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004134 if (status == 0)
4135 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4137 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004138 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139 return status;
4140}
4141
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004142static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4143 struct timespec *time)
4144{
4145 int status = 0;
4146
4147 time->tv_sec = 0;
4148 time->tv_nsec = 0;
4149 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4150 return -EIO;
4151 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4152 status = decode_attr_time(xdr, time);
4153 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4154 }
4155 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4156 (long)time->tv_nsec);
4157 return status;
4158}
4159
David Quigleyaa9c2662013-05-22 12:50:44 -04004160static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4161 struct nfs4_label *label)
4162{
4163 uint32_t pi = 0;
4164 uint32_t lfs = 0;
4165 __u32 len;
4166 __be32 *p;
4167 int status = 0;
4168
4169 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4170 return -EIO;
4171 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4172 p = xdr_inline_decode(xdr, 4);
4173 if (unlikely(!p))
4174 goto out_overflow;
4175 lfs = be32_to_cpup(p++);
4176 p = xdr_inline_decode(xdr, 4);
4177 if (unlikely(!p))
4178 goto out_overflow;
4179 pi = be32_to_cpup(p++);
4180 p = xdr_inline_decode(xdr, 4);
4181 if (unlikely(!p))
4182 goto out_overflow;
4183 len = be32_to_cpup(p++);
4184 p = xdr_inline_decode(xdr, len);
4185 if (unlikely(!p))
4186 goto out_overflow;
4187 if (len < NFS4_MAXLABELLEN) {
4188 if (label) {
4189 memcpy(label->label, p, len);
4190 label->len = len;
4191 label->pi = pi;
4192 label->lfs = lfs;
4193 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4194 }
4195 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4196 } else
4197 printk(KERN_WARNING "%s: label too long (%u)!\n",
4198 __func__, len);
4199 }
4200 if (label && label->label)
4201 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4202 (char *)label->label, label->len, label->pi, label->lfs);
4203 return status;
4204
4205out_overflow:
4206 print_overflow_msg(__func__, xdr);
4207 return -EIO;
4208}
4209
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4211{
4212 int status = 0;
4213
4214 time->tv_sec = 0;
4215 time->tv_nsec = 0;
4216 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4217 return -EIO;
4218 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4219 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004220 if (status == 0)
4221 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4223 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004224 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225 return status;
4226}
4227
Trond Myklebust256e48b2012-06-21 11:18:13 -04004228static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229{
4230 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004231 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232
4233 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004234 dprintk("%s: server returned incorrect attribute length: "
4235 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004236 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004237 attrwords << 2,
4238 (attrwords < nwords) ? '<' : '>',
4239 nwords << 2);
4240 return -EIO;
4241 }
4242 return 0;
4243}
4244
4245static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4246{
Al Viro8687b632006-10-19 23:28:48 -07004247 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248
Benny Halevyc0eae662009-08-14 17:20:14 +03004249 p = xdr_inline_decode(xdr, 20);
4250 if (unlikely(!p))
4251 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004252 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004253 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004254 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004255 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004256out_overflow:
4257 print_overflow_msg(__func__, xdr);
4258 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004259}
4260
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004261static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262{
Al Viro8687b632006-10-19 23:28:48 -07004263 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264 uint32_t supp, acc;
4265 int status;
4266
4267 status = decode_op_hdr(xdr, OP_ACCESS);
4268 if (status)
4269 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004270 p = xdr_inline_decode(xdr, 8);
4271 if (unlikely(!p))
4272 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004273 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004274 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004275 *supported = supp;
4276 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004278out_overflow:
4279 print_overflow_msg(__func__, xdr);
4280 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281}
4282
Benny Halevy07d30432009-08-14 17:19:52 +03004283static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004284{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004285 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4286 if (unlikely(ret < 0)) {
4287 print_overflow_msg(__func__, xdr);
4288 return -EIO;
Benny Halevy07d30432009-08-14 17:19:52 +03004289 }
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004290 return 0;
Benny Halevy07d30432009-08-14 17:19:52 +03004291}
4292
4293static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4294{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004295 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296}
4297
Trond Myklebust93b717f2016-05-16 17:42:43 -04004298static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4299{
4300 stateid->type = NFS4_OPEN_STATEID_TYPE;
4301 return decode_stateid(xdr, stateid);
4302}
4303
4304static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4305{
4306 stateid->type = NFS4_LOCK_STATEID_TYPE;
4307 return decode_stateid(xdr, stateid);
4308}
4309
4310static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4311{
4312 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4313 return decode_stateid(xdr, stateid);
4314}
4315
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4317{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 int status;
4319
4320 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004321 if (status != -EIO)
4322 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004323 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04004324 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004325 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326}
4327
Benny Halevydb942bb2009-08-14 17:19:56 +03004328static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4329{
Chuck Levercd937102012-03-02 17:14:31 -05004330 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004331}
4332
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004333static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4334{
4335 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4336}
4337
Fred Isaman0b7c0152012-04-20 14:47:39 -04004338static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004339{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004340 int status;
4341
4342 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004343 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004344 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004345 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346}
4347
4348static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4349{
Al Viro8687b632006-10-19 23:28:48 -07004350 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351 uint32_t bmlen;
4352 int status;
4353
4354 status = decode_op_hdr(xdr, OP_CREATE);
4355 if (status)
4356 return status;
4357 if ((status = decode_change_info(xdr, cinfo)))
4358 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004359 p = xdr_inline_decode(xdr, 4);
4360 if (unlikely(!p))
4361 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004362 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004363 p = xdr_inline_decode(xdr, bmlen << 2);
4364 if (likely(p))
4365 return 0;
4366out_overflow:
4367 print_overflow_msg(__func__, xdr);
4368 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004369}
4370
4371static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4372{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004373 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004374 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004375 int status;
4376
4377 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4378 goto xdr_error;
4379 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4380 goto xdr_error;
4381 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4382 goto xdr_error;
4383 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4384 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004385 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4386 &res->fh_expire_type)) != 0)
4387 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4389 goto xdr_error;
4390 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4391 goto xdr_error;
4392 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4393 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004394 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4395 res->exclcreat_bitmask)) != 0)
4396 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397 status = verify_attr_len(xdr, savep, attrlen);
4398xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004399 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400 return status;
4401}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004402
Linus Torvalds1da177e2005-04-16 15:20:36 -07004403static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4404{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004405 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004406 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004408
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4410 goto xdr_error;
4411 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4412 goto xdr_error;
4413 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4414 goto xdr_error;
4415
4416 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4417 goto xdr_error;
4418 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4419 goto xdr_error;
4420 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4421 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004422
4423 status = -EIO;
4424 if (unlikely(bitmap[0]))
4425 goto xdr_error;
4426
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4428 goto xdr_error;
4429 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4430 goto xdr_error;
4431 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4432 goto xdr_error;
4433
4434 status = verify_attr_len(xdr, savep, attrlen);
4435xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004436 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004437 return status;
4438}
4439
4440static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4441{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004442 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004443 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004445
Linus Torvalds1da177e2005-04-16 15:20:36 -07004446 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4447 goto xdr_error;
4448 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4449 goto xdr_error;
4450 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4451 goto xdr_error;
4452
4453 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4454 goto xdr_error;
4455 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4456 goto xdr_error;
4457
4458 status = verify_attr_len(xdr, savep, attrlen);
4459xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004460 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461 return status;
4462}
4463
Andy Adamson88034c32012-05-23 05:02:34 -04004464static int decode_threshold_hint(struct xdr_stream *xdr,
4465 uint32_t *bitmap,
4466 uint64_t *res,
4467 uint32_t hint_bit)
4468{
4469 __be32 *p;
4470
4471 *res = 0;
4472 if (likely(bitmap[0] & hint_bit)) {
4473 p = xdr_inline_decode(xdr, 8);
4474 if (unlikely(!p))
4475 goto out_overflow;
4476 xdr_decode_hyper(p, res);
4477 }
4478 return 0;
4479out_overflow:
4480 print_overflow_msg(__func__, xdr);
4481 return -EIO;
4482}
4483
4484static int decode_first_threshold_item4(struct xdr_stream *xdr,
4485 struct nfs4_threshold *res)
4486{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004487 __be32 *p;
4488 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004489 uint32_t bitmap[3] = {0,}, attrlen;
4490 int status;
4491
4492 /* layout type */
4493 p = xdr_inline_decode(xdr, 4);
4494 if (unlikely(!p)) {
4495 print_overflow_msg(__func__, xdr);
4496 return -EIO;
4497 }
4498 res->l_type = be32_to_cpup(p);
4499
4500 /* thi_hintset bitmap */
4501 status = decode_attr_bitmap(xdr, bitmap);
4502 if (status < 0)
4503 goto xdr_error;
4504
4505 /* thi_hintlist length */
4506 status = decode_attr_length(xdr, &attrlen, &savep);
4507 if (status < 0)
4508 goto xdr_error;
4509 /* thi_hintlist */
4510 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4511 if (status < 0)
4512 goto xdr_error;
4513 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4514 if (status < 0)
4515 goto xdr_error;
4516 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4517 THRESHOLD_RD_IO);
4518 if (status < 0)
4519 goto xdr_error;
4520 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4521 THRESHOLD_WR_IO);
4522 if (status < 0)
4523 goto xdr_error;
4524
4525 status = verify_attr_len(xdr, savep, attrlen);
4526 res->bm = bitmap[0];
4527
4528 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4529 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4530 res->wr_io_sz);
4531xdr_error:
4532 dprintk("%s ret=%d!\n", __func__, status);
4533 return status;
4534}
4535
4536/*
4537 * Thresholds on pNFS direct I/O vrs MDS I/O
4538 */
4539static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4540 uint32_t *bitmap,
4541 struct nfs4_threshold *res)
4542{
4543 __be32 *p;
4544 int status = 0;
4545 uint32_t num;
4546
4547 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4548 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004549 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004550 /* Did the server return an unrequested attribute? */
4551 if (unlikely(res == NULL))
4552 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004553 p = xdr_inline_decode(xdr, 4);
4554 if (unlikely(!p))
4555 goto out_overflow;
4556 num = be32_to_cpup(p);
4557 if (num == 0)
4558 return 0;
4559 if (num > 1)
4560 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4561 "drivers per filesystem not supported\n",
4562 __func__);
4563
4564 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004565 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004566 }
4567 return status;
4568out_overflow:
4569 print_overflow_msg(__func__, xdr);
4570 return -EIO;
4571}
4572
Bryan Schumakerae42c702010-10-21 16:33:17 -04004573static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4574 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004575 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004576 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577{
Trond Myklebustbca79472009-03-11 14:10:26 -04004578 int status;
4579 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004580 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004581 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004583 status = decode_attr_type(xdr, bitmap, &type);
4584 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004586 fattr->mode = 0;
4587 if (status != 0) {
4588 fattr->mode |= nfs_type2fmt[type];
4589 fattr->valid |= status;
4590 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004592 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
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_size(xdr, bitmap, &fattr->size);
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
4602 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4603 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004604 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004605 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004606
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004607 err = 0;
4608 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004609 if (status < 0)
4610 goto xdr_error;
4611
4612 status = decode_attr_filehandle(xdr, bitmap, fh);
4613 if (status < 0)
4614 goto xdr_error;
4615
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004616 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4617 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004618 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004619 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004620
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004621 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004622 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004623 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004624 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004625
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004626 status = -EIO;
4627 if (unlikely(bitmap[0]))
4628 goto xdr_error;
4629
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004630 status = decode_attr_mode(xdr, bitmap, &fmode);
4631 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004633 if (status != 0) {
4634 fattr->mode |= fmode;
4635 fattr->valid |= status;
4636 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004637
4638 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4639 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_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_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
Trond Myklebust6926afd2012-01-07 13:22:46 -05004648 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004649 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_rdev(xdr, bitmap, &fattr->rdev);
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_space_used(xdr, bitmap, &fattr->du.nfs3.used);
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_access(xdr, bitmap, &fattr->atime);
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_metadata(xdr, bitmap, &fattr->ctime);
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
4673 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4674 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004675 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004676 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004677
Trond Myklebust28331a42011-04-27 13:47:52 -04004678 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004679 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004680 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004681 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004682
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004683 status = -EIO;
4684 if (unlikely(bitmap[1]))
4685 goto xdr_error;
4686
Andy Adamson88034c32012-05-23 05:02:34 -04004687 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4688 if (status < 0)
4689 goto xdr_error;
4690
David Quigleyaa9c2662013-05-22 12:50:44 -04004691 if (label) {
4692 status = decode_attr_security_label(xdr, bitmap, label);
4693 if (status < 0)
4694 goto xdr_error;
4695 fattr->valid |= status;
4696 }
4697
Bryan Schumakerae42c702010-10-21 16:33:17 -04004698xdr_error:
4699 dprintk("%s: xdr returned %d\n", __func__, -status);
4700 return status;
4701}
4702
4703static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004704 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004705 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004706{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004707 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004708 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004709 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004710 int status;
4711
4712 status = decode_op_hdr(xdr, OP_GETATTR);
4713 if (status < 0)
4714 goto xdr_error;
4715
4716 status = decode_attr_bitmap(xdr, bitmap);
4717 if (status < 0)
4718 goto xdr_error;
4719
4720 status = decode_attr_length(xdr, &attrlen, &savep);
4721 if (status < 0)
4722 goto xdr_error;
4723
David Quigleyaa9c2662013-05-22 12:50:44 -04004724 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4725 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004726 if (status < 0)
4727 goto xdr_error;
4728
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004729 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004731 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732 return status;
4733}
4734
David Quigleyaa9c2662013-05-22 12:50:44 -04004735static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4736 struct nfs4_label *label, const struct nfs_server *server)
4737{
4738 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4739}
4740
Bryan Schumakerae42c702010-10-21 16:33:17 -04004741static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004742 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004743{
David Quigleyaa9c2662013-05-22 12:50:44 -04004744 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004745}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746
Andy Adamson504913f2010-10-20 00:17:57 -04004747/*
Jeff Layton3132e492016-08-10 15:58:24 -04004748 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004749 */
Jeff Layton3132e492016-08-10 15:58:24 -04004750static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004751 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004752{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004753 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004754 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004755
4756 p = xdr_inline_decode(xdr, 4);
4757 if (unlikely(!p))
4758 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004759 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004760
4761 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004762 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004763 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004764
4765 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004766 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004767 if (unlikely(!p))
4768 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004769
4770 /* If we get too many, then just cap it at the max */
4771 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4772 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4773 __func__, fsinfo->nlayouttypes);
4774 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4775 }
4776
4777 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4778 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004779 return 0;
4780out_overflow:
4781 print_overflow_msg(__func__, xdr);
4782 return -EIO;
4783}
4784
4785/*
4786 * The type of file system exported.
4787 * Note we must ensure that layouttype is set in any non-error case.
4788 */
4789static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004790 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004791{
4792 int status = 0;
4793
4794 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4795 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4796 return -EIO;
4797 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004798 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004799 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004800 }
Andy Adamson504913f2010-10-20 00:17:57 -04004801 return status;
4802}
4803
Fred Isamandae100c2011-07-30 20:52:37 -04004804/*
4805 * The prefered block size for layout directed io
4806 */
4807static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4808 uint32_t *res)
4809{
4810 __be32 *p;
4811
4812 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4813 *res = 0;
4814 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4815 p = xdr_inline_decode(xdr, 4);
4816 if (unlikely(!p)) {
4817 print_overflow_msg(__func__, xdr);
4818 return -EIO;
4819 }
4820 *res = be32_to_cpup(p);
4821 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4822 }
4823 return 0;
4824}
4825
Peng Tao2a92ee92015-09-26 02:24:37 +08004826/*
4827 * The granularity of a CLONE operation.
4828 */
4829static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4830 uint32_t *res)
4831{
4832 __be32 *p;
4833
4834 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4835 *res = 0;
4836 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4837 p = xdr_inline_decode(xdr, 4);
4838 if (unlikely(!p)) {
4839 print_overflow_msg(__func__, xdr);
4840 return -EIO;
4841 }
4842 *res = be32_to_cpup(p);
4843 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4844 }
4845 return 0;
4846}
4847
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4849{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004850 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004851 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004852 int status;
4853
4854 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4855 goto xdr_error;
4856 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4857 goto xdr_error;
4858 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4859 goto xdr_error;
4860
4861 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4862
4863 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4864 goto xdr_error;
4865 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4866 goto xdr_error;
4867 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4868 goto xdr_error;
4869 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4870 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4871 goto xdr_error;
4872 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004873
4874 status = -EIO;
4875 if (unlikely(bitmap[0]))
4876 goto xdr_error;
4877
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004878 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4879 if (status != 0)
4880 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004881 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004882 if (status != 0)
4883 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004884
4885 status = -EIO;
4886 if (unlikely(bitmap[1]))
4887 goto xdr_error;
4888
Fred Isamandae100c2011-07-30 20:52:37 -04004889 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4890 if (status)
4891 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004892 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4893 if (status)
4894 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895
4896 status = verify_attr_len(xdr, savep, attrlen);
4897xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004898 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899 return status;
4900}
4901
4902static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4903{
Al Viro8687b632006-10-19 23:28:48 -07004904 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905 uint32_t len;
4906 int status;
4907
Trond Myklebust99367812007-07-17 21:52:41 -04004908 /* Zero handle first to allow comparisons */
4909 memset(fh, 0, sizeof(*fh));
4910
Linus Torvalds1da177e2005-04-16 15:20:36 -07004911 status = decode_op_hdr(xdr, OP_GETFH);
4912 if (status)
4913 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004914
Benny Halevyc0eae662009-08-14 17:20:14 +03004915 p = xdr_inline_decode(xdr, 4);
4916 if (unlikely(!p))
4917 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004918 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919 if (len > NFS4_FHSIZE)
4920 return -EIO;
4921 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004922 p = xdr_inline_decode(xdr, len);
4923 if (unlikely(!p))
4924 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004925 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004927out_overflow:
4928 print_overflow_msg(__func__, xdr);
4929 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930}
4931
4932static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4933{
4934 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004935
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936 status = decode_op_hdr(xdr, OP_LINK);
4937 if (status)
4938 return status;
4939 return decode_change_info(xdr, cinfo);
4940}
4941
4942/*
4943 * We create the owner, so we know a proper owner.id length is 4.
4944 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004945static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004947 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004948 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004949 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004950
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004951 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004952 if (unlikely(!p))
4953 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004954 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004955 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004956 type = be32_to_cpup(p++); /* 4 byte read */
4957 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004958 fl->fl_start = (loff_t)offset;
4959 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4960 if (length == ~(uint64_t)0)
4961 fl->fl_end = OFFSET_MAX;
4962 fl->fl_type = F_WRLCK;
4963 if (type & 1)
4964 fl->fl_type = F_RDLCK;
4965 fl->fl_pid = 0;
4966 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004967 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4968 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4969 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004970 if (likely(p))
4971 return -NFS4ERR_DENIED;
4972out_overflow:
4973 print_overflow_msg(__func__, xdr);
4974 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975}
4976
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004977static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004978{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979 int status;
4980
4981 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004982 if (status == -EIO)
4983 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04004985 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004986 if (unlikely(status))
4987 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004989 status = decode_lock_denied(xdr, NULL);
4990 if (res->open_seqid != NULL)
4991 nfs_increment_open_seqid(status, res->open_seqid);
4992 nfs_increment_lock_seqid(status, res->lock_seqid);
4993out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994 return status;
4995}
4996
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004997static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998{
4999 int status;
5000 status = decode_op_hdr(xdr, OP_LOCKT);
5001 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005002 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003 return status;
5004}
5005
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005006static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008 int status;
5009
5010 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005011 if (status != -EIO)
5012 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005013 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005014 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015 return status;
5016}
5017
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005018static int decode_release_lockowner(struct xdr_stream *xdr)
5019{
5020 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5021}
5022
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023static int decode_lookup(struct xdr_stream *xdr)
5024{
5025 return decode_op_hdr(xdr, OP_LOOKUP);
5026}
5027
5028/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005029static int decode_space_limit(struct xdr_stream *xdr,
5030 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031{
Andy Adamson05d564f2008-12-23 16:06:15 -05005032 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005033 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005034 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035
Benny Halevyc0eae662009-08-14 17:20:14 +03005036 p = xdr_inline_decode(xdr, 12);
5037 if (unlikely(!p))
5038 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005039 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005040 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005041 case NFS4_LIMIT_SIZE:
5042 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005043 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005044 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005045 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005046 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005047 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005049 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005050 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005051 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005052out_overflow:
5053 print_overflow_msg(__func__, xdr);
5054 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005055}
5056
Trond Myklebust6ae37332015-01-30 14:21:14 -05005057static int decode_rw_delegation(struct xdr_stream *xdr,
5058 uint32_t delegation_type,
5059 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005060{
Andy Adamson05d564f2008-12-23 16:06:15 -05005061 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005062 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005063
Trond Myklebust93b717f2016-05-16 17:42:43 -04005064 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005065 if (unlikely(status))
5066 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005067 p = xdr_inline_decode(xdr, 4);
5068 if (unlikely(!p))
5069 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005070 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005071
Linus Torvalds1da177e2005-04-16 15:20:36 -07005072 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005073 case NFS4_OPEN_DELEGATE_READ:
5074 res->delegation_type = FMODE_READ;
5075 break;
5076 case NFS4_OPEN_DELEGATE_WRITE:
5077 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005078 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079 return -EIO;
5080 }
David Howells7539bba2006-08-22 20:06:09 -04005081 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03005082out_overflow:
5083 print_overflow_msg(__func__, xdr);
5084 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085}
5086
Trond Myklebust6ae37332015-01-30 14:21:14 -05005087static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5088{
5089 __be32 *p;
5090 uint32_t why_no_delegation;
5091
5092 p = xdr_inline_decode(xdr, 4);
5093 if (unlikely(!p))
5094 goto out_overflow;
5095 why_no_delegation = be32_to_cpup(p);
5096 switch (why_no_delegation) {
5097 case WND4_CONTENTION:
5098 case WND4_RESOURCE:
5099 xdr_inline_decode(xdr, 4);
5100 /* Ignore for now */
5101 }
5102 return 0;
5103out_overflow:
5104 print_overflow_msg(__func__, xdr);
5105 return -EIO;
5106}
5107
5108static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5109{
5110 __be32 *p;
5111 uint32_t delegation_type;
5112
5113 p = xdr_inline_decode(xdr, 4);
5114 if (unlikely(!p))
5115 goto out_overflow;
5116 delegation_type = be32_to_cpup(p);
5117 res->delegation_type = 0;
5118 switch (delegation_type) {
5119 case NFS4_OPEN_DELEGATE_NONE:
5120 return 0;
5121 case NFS4_OPEN_DELEGATE_READ:
5122 case NFS4_OPEN_DELEGATE_WRITE:
5123 return decode_rw_delegation(xdr, delegation_type, res);
5124 case NFS4_OPEN_DELEGATE_NONE_EXT:
5125 return decode_no_delegation(xdr, res);
5126 }
5127 return -EIO;
5128out_overflow:
5129 print_overflow_msg(__func__, xdr);
5130 return -EIO;
5131}
5132
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5134{
Andy Adamson05d564f2008-12-23 16:06:15 -05005135 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005136 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005137 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005138
Trond Myklebustc7848f62013-12-04 17:39:23 -05005139 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5140 return status;
5141 nfs_increment_open_seqid(status, res->seqid);
5142 if (status)
5143 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005144 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005145 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005146 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147
Andy Adamson05d564f2008-12-23 16:06:15 -05005148 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005149
Benny Halevyc0eae662009-08-14 17:20:14 +03005150 p = xdr_inline_decode(xdr, 8);
5151 if (unlikely(!p))
5152 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005153 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005154 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005155 if (bmlen > 10)
5156 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157
Benny Halevyc0eae662009-08-14 17:20:14 +03005158 p = xdr_inline_decode(xdr, bmlen << 2);
5159 if (unlikely(!p))
5160 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005161 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5162 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005163 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005164 for (; i < NFS4_BITMAP_SIZE; i++)
5165 res->attrset[i] = 0;
5166
Linus Torvalds1da177e2005-04-16 15:20:36 -07005167 return decode_delegation(xdr, res);
5168xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005169 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005171out_overflow:
5172 print_overflow_msg(__func__, xdr);
5173 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005174}
5175
5176static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5177{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178 int status;
5179
Andy Adamson05d564f2008-12-23 16:06:15 -05005180 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005181 if (status != -EIO)
5182 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005183 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005184 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005185 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005186}
5187
5188static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5189{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190 int status;
5191
5192 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005193 if (status != -EIO)
5194 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005195 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005196 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005197 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005198}
5199
5200static int decode_putfh(struct xdr_stream *xdr)
5201{
5202 return decode_op_hdr(xdr, OP_PUTFH);
5203}
5204
5205static int decode_putrootfh(struct xdr_stream *xdr)
5206{
5207 return decode_op_hdr(xdr, OP_PUTROOTFH);
5208}
5209
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005210static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5211 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005212{
Al Viro8687b632006-10-19 23:28:48 -07005213 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005214 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215 int status;
5216
5217 status = decode_op_hdr(xdr, OP_READ);
5218 if (status)
5219 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005220 p = xdr_inline_decode(xdr, 8);
5221 if (unlikely(!p))
5222 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005223 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005224 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005225 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005226 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005227 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228 "count %u > recvd %u\n", count, recvd);
5229 count = recvd;
5230 eof = 0;
5231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005232 res->eof = eof;
5233 res->count = count;
5234 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005235out_overflow:
5236 print_overflow_msg(__func__, xdr);
5237 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238}
5239
5240static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5241{
Chuck Leverbcecff72007-10-26 13:32:03 -04005242 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005243 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005244
5245 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005246 if (!status)
5247 status = decode_verifier(xdr, readdir->verifier.data);
5248 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005250 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005251 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005252 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005253 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254}
5255
5256static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5257{
5258 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005259 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005260 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005261 int status;
5262
5263 status = decode_op_hdr(xdr, OP_READLINK);
5264 if (status)
5265 return status;
5266
5267 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005268 p = xdr_inline_decode(xdr, 4);
5269 if (unlikely(!p))
5270 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005271 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005272 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005273 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274 return -ENAMETOOLONG;
5275 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005276 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005278 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005279 "count %u > recvd %u\n", len, recvd);
5280 return -EIO;
5281 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282 /*
5283 * The XDR encode routine has set things up so that
5284 * the link text will be copied directly into the
5285 * buffer. We just have to do overflow-checking,
5286 * and and null-terminate the text (the VFS expects
5287 * null-termination).
5288 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005289 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005291out_overflow:
5292 print_overflow_msg(__func__, xdr);
5293 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005294}
5295
5296static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5297{
5298 int status;
5299
5300 status = decode_op_hdr(xdr, OP_REMOVE);
5301 if (status)
5302 goto out;
5303 status = decode_change_info(xdr, cinfo);
5304out:
5305 return status;
5306}
5307
5308static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5309 struct nfs4_change_info *new_cinfo)
5310{
5311 int status;
5312
5313 status = decode_op_hdr(xdr, OP_RENAME);
5314 if (status)
5315 goto out;
5316 if ((status = decode_change_info(xdr, old_cinfo)))
5317 goto out;
5318 status = decode_change_info(xdr, new_cinfo);
5319out:
5320 return status;
5321}
5322
5323static int decode_renew(struct xdr_stream *xdr)
5324{
5325 return decode_op_hdr(xdr, OP_RENEW);
5326}
5327
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005328static int
5329decode_restorefh(struct xdr_stream *xdr)
5330{
5331 return decode_op_hdr(xdr, OP_RESTOREFH);
5332}
5333
J. Bruce Fields029d1052005-06-22 17:16:22 +00005334static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005335 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005336{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005337 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005338 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005339 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005340 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005341 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005342
Andy Adamsonbf118a32011-12-07 11:55:27 -05005343 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005344 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5345 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005346
Trond Myklebust519d3952012-08-14 17:30:10 -04005347 xdr_enter_page(xdr, xdr->buf->page_len);
5348
Trond Myklebustcff298c2012-08-14 17:14:17 -04005349 /* Calculate the offset of the page data */
5350 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005351
J. Bruce Fields029d1052005-06-22 17:16:22 +00005352 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5353 goto out;
5354 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5355 goto out;
5356
5357 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5358 return -EIO;
5359 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005360
Andy Adamsonbf118a32011-12-07 11:55:27 -05005361 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5362 * are stored with the acl data to handle the problem of
5363 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005364 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005365 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005366
5367 /* Check for receive buffer overflow */
5368 if (res->acl_len > (xdr->nwords << 2) ||
5369 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5370 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005371 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005372 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005373 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005374 } else
5375 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005376
5377out:
5378 return status;
5379}
5380
Linus Torvalds1da177e2005-04-16 15:20:36 -07005381static int
5382decode_savefh(struct xdr_stream *xdr)
5383{
5384 return decode_op_hdr(xdr, OP_SAVEFH);
5385}
5386
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005387static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005388{
Al Viro8687b632006-10-19 23:28:48 -07005389 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005390 uint32_t bmlen;
5391 int status;
5392
Linus Torvalds1da177e2005-04-16 15:20:36 -07005393 status = decode_op_hdr(xdr, OP_SETATTR);
5394 if (status)
5395 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005396 p = xdr_inline_decode(xdr, 4);
5397 if (unlikely(!p))
5398 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005399 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005400 p = xdr_inline_decode(xdr, bmlen << 2);
5401 if (likely(p))
5402 return 0;
5403out_overflow:
5404 print_overflow_msg(__func__, xdr);
5405 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406}
5407
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005408static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005409{
Al Viro8687b632006-10-19 23:28:48 -07005410 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005411 uint32_t opnum;
5412 int32_t nfserr;
5413
Benny Halevyc0eae662009-08-14 17:20:14 +03005414 p = xdr_inline_decode(xdr, 8);
5415 if (unlikely(!p))
5416 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005417 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005418 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005419 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005420 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005421 return -EIO;
5422 }
Benny Halevycccddf42009-08-14 17:20:19 +03005423 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005424 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005425 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5426 if (unlikely(!p))
5427 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005428 p = xdr_decode_hyper(p, &res->clientid);
5429 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005430 } else if (nfserr == NFSERR_CLID_INUSE) {
5431 uint32_t len;
5432
5433 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005434 p = xdr_inline_decode(xdr, 4);
5435 if (unlikely(!p))
5436 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005437 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005438 p = xdr_inline_decode(xdr, len);
5439 if (unlikely(!p))
5440 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005441
5442 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005443 p = xdr_inline_decode(xdr, 4);
5444 if (unlikely(!p))
5445 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005446 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005447 p = xdr_inline_decode(xdr, len);
5448 if (unlikely(!p))
5449 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005450 return -NFSERR_CLID_INUSE;
5451 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005452 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005453
5454 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005455out_overflow:
5456 print_overflow_msg(__func__, xdr);
5457 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005458}
5459
5460static int decode_setclientid_confirm(struct xdr_stream *xdr)
5461{
5462 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5463}
5464
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005465static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005466{
Al Viro8687b632006-10-19 23:28:48 -07005467 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005468 int status;
5469
5470 status = decode_op_hdr(xdr, OP_WRITE);
5471 if (status)
5472 return status;
5473
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005474 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005475 if (unlikely(!p))
5476 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005477 res->count = be32_to_cpup(p++);
5478 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005479 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005480out_overflow:
5481 print_overflow_msg(__func__, xdr);
5482 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005483}
5484
5485static int decode_delegreturn(struct xdr_stream *xdr)
5486{
5487 return decode_op_hdr(xdr, OP_DELEGRETURN);
5488}
5489
Chuck Leverfb15b262013-03-16 15:54:34 -04005490static int decode_secinfo_gss(struct xdr_stream *xdr,
5491 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005492{
Chuck Leverfb15b262013-03-16 15:54:34 -04005493 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005494 __be32 *p;
5495
5496 p = xdr_inline_decode(xdr, 4);
5497 if (unlikely(!p))
5498 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005499 oid_len = be32_to_cpup(p);
5500 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005501 goto out_err;
5502
Chuck Leverfb15b262013-03-16 15:54:34 -04005503 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005504 if (unlikely(!p))
5505 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005506 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5507 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005508
5509 p = xdr_inline_decode(xdr, 8);
5510 if (unlikely(!p))
5511 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005512 flavor->flavor_info.qop = be32_to_cpup(p++);
5513 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005514
5515 return 0;
5516
5517out_overflow:
5518 print_overflow_msg(__func__, xdr);
5519 return -EIO;
5520out_err:
5521 return -EINVAL;
5522}
5523
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005524static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005525{
Chuck Leverfb15b262013-03-16 15:54:34 -04005526 struct nfs4_secinfo4 *sec_flavor;
5527 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005528 int status;
5529 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005530
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005531 p = xdr_inline_decode(xdr, 4);
5532 if (unlikely(!p))
5533 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005534
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005535 res->flavors->num_flavors = 0;
5536 num_flavors = be32_to_cpup(p);
5537
5538 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005539 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005540 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005541 break;
5542
5543 p = xdr_inline_decode(xdr, 4);
5544 if (unlikely(!p))
5545 goto out_overflow;
5546 sec_flavor->flavor = be32_to_cpup(p);
5547
5548 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005549 status = decode_secinfo_gss(xdr, sec_flavor);
5550 if (status)
5551 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005552 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005553 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005554 }
5555
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005556 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005557out:
5558 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005559out_overflow:
5560 print_overflow_msg(__func__, xdr);
5561 return -EIO;
5562}
5563
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005564static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5565{
5566 int status = decode_op_hdr(xdr, OP_SECINFO);
5567 if (status)
5568 return status;
5569 return decode_secinfo_common(xdr, res);
5570}
5571
Benny Halevy99fe60d2009-04-01 09:22:29 -04005572#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005573static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5574{
5575 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5576 if (status)
5577 return status;
5578 return decode_secinfo_common(xdr, res);
5579}
5580
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005581static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5582{
5583 __be32 *p;
5584 uint32_t bitmap_words;
5585 unsigned int i;
5586
5587 p = xdr_inline_decode(xdr, 4);
5588 bitmap_words = be32_to_cpup(p++);
5589 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5590 return -EIO;
5591 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5592 for (i = 0; i < bitmap_words; i++)
5593 op_map->u.words[i] = be32_to_cpup(p++);
5594
5595 return 0;
5596}
5597
Benny Halevy99fe60d2009-04-01 09:22:29 -04005598static int decode_exchange_id(struct xdr_stream *xdr,
5599 struct nfs41_exchange_id_res *res)
5600{
5601 __be32 *p;
5602 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005603 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005604 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005605 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005606
5607 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5608 if (status)
5609 return status;
5610
Benny Halevyc0eae662009-08-14 17:20:14 +03005611 p = xdr_inline_decode(xdr, 8);
5612 if (unlikely(!p))
5613 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005614 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005615 p = xdr_inline_decode(xdr, 12);
5616 if (unlikely(!p))
5617 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005618 res->seqid = be32_to_cpup(p++);
5619 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005620
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005621 res->state_protect.how = be32_to_cpup(p);
5622 switch (res->state_protect.how) {
5623 case SP4_NONE:
5624 break;
5625 case SP4_MACH_CRED:
5626 status = decode_op_map(xdr, &res->state_protect.enforce);
5627 if (status)
5628 return status;
5629 status = decode_op_map(xdr, &res->state_protect.allow);
5630 if (status)
5631 return status;
5632 break;
5633 default:
5634 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005635 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005636 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005637
Chuck Leveracdeb692012-05-21 22:46:16 -04005638 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005639 p = xdr_inline_decode(xdr, 8);
5640 if (unlikely(!p))
5641 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005642 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005643
Chuck Leveracdeb692012-05-21 22:46:16 -04005644 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005645 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5646 if (unlikely(status))
5647 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005648 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5649 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005650 memcpy(res->server_owner->major_id, dummy_str, dummy);
5651 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005652
Chuck Leveracdeb692012-05-21 22:46:16 -04005653 /* server_scope4 */
5654 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5655 if (unlikely(status))
5656 return status;
5657 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5658 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005659 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5660 res->server_scope->server_scope_sz = dummy;
5661
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005662 /* Implementation Id */
5663 p = xdr_inline_decode(xdr, 4);
5664 if (unlikely(!p))
5665 goto out_overflow;
5666 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005667
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005668 if (impl_id_count) {
5669 /* nii_domain */
5670 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5671 if (unlikely(status))
5672 return status;
5673 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5674 return -EIO;
5675 memcpy(res->impl_id->domain, dummy_str, dummy);
5676
5677 /* nii_name */
5678 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5679 if (unlikely(status))
5680 return status;
5681 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5682 return -EIO;
5683 memcpy(res->impl_id->name, dummy_str, dummy);
5684
5685 /* nii_date */
5686 p = xdr_inline_decode(xdr, 12);
5687 if (unlikely(!p))
5688 goto out_overflow;
5689 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5690 res->impl_id->date.nseconds = be32_to_cpup(p);
5691
5692 /* if there's more than one entry, ignore the rest */
5693 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005694 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005695out_overflow:
5696 print_overflow_msg(__func__, xdr);
5697 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005698}
Andy Adamsonfc931582009-04-01 09:22:31 -04005699
5700static int decode_chan_attrs(struct xdr_stream *xdr,
5701 struct nfs4_channel_attrs *attrs)
5702{
5703 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005704 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005705
Benny Halevyc0eae662009-08-14 17:20:14 +03005706 p = xdr_inline_decode(xdr, 28);
5707 if (unlikely(!p))
5708 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005709 val = be32_to_cpup(p++); /* headerpadsz */
5710 if (val)
5711 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005712 attrs->max_rqst_sz = be32_to_cpup(p++);
5713 attrs->max_resp_sz = be32_to_cpup(p++);
5714 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5715 attrs->max_ops = be32_to_cpup(p++);
5716 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005717 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005718 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005719 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5720 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005721 return -EINVAL;
5722 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005723 if (nr_attrs == 1) {
5724 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5725 if (unlikely(!p))
5726 goto out_overflow;
5727 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005728 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005729out_overflow:
5730 print_overflow_msg(__func__, xdr);
5731 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005732}
5733
Benny Halevye78291e2009-08-14 17:20:00 +03005734static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5735{
5736 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005737}
5738
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005739static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5740 struct nfs41_bind_conn_to_session_res *res)
5741{
5742 __be32 *p;
5743 int status;
5744
5745 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5746 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005747 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005748 if (unlikely(status))
5749 return status;
5750
5751 /* dir flags, rdma mode bool */
5752 p = xdr_inline_decode(xdr, 8);
5753 if (unlikely(!p))
5754 goto out_overflow;
5755
5756 res->dir = be32_to_cpup(p++);
5757 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5758 return -EIO;
5759 if (be32_to_cpup(p) == 0)
5760 res->use_conn_in_rdma_mode = false;
5761 else
5762 res->use_conn_in_rdma_mode = true;
5763
5764 return 0;
5765out_overflow:
5766 print_overflow_msg(__func__, xdr);
5767 return -EIO;
5768}
5769
Andy Adamsonfc931582009-04-01 09:22:31 -04005770static int decode_create_session(struct xdr_stream *xdr,
5771 struct nfs41_create_session_res *res)
5772{
5773 __be32 *p;
5774 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005775
5776 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005777 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005778 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005779 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005780 return status;
5781
Andy Adamsonfc931582009-04-01 09:22:31 -04005782 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005783 p = xdr_inline_decode(xdr, 8);
5784 if (unlikely(!p))
5785 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005786 res->seqid = be32_to_cpup(p++);
5787 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005788
5789 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005790 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005791 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005792 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005793 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005794out_overflow:
5795 print_overflow_msg(__func__, xdr);
5796 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005797}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005798
5799static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5800{
5801 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5802}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005803
Trond Myklebust66245532012-05-25 17:18:09 -04005804static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5805{
5806 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5807}
5808
Ricardo Labiaga180197532009-12-05 16:08:40 -05005809static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5810{
5811 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5812}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005813#endif /* CONFIG_NFS_V4_1 */
5814
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005815static int decode_sequence(struct xdr_stream *xdr,
5816 struct nfs4_sequence_res *res,
5817 struct rpc_rqst *rqstp)
5818{
5819#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005820 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005821 struct nfs4_sessionid id;
5822 u32 dummy;
5823 int status;
5824 __be32 *p;
5825
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005826 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005827 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005828 if (!res->sr_slot->table->session)
5829 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005830
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005831 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005832 if (!status)
5833 status = decode_sessionid(xdr, &id);
5834 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005835 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005836
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005837 /*
5838 * If the server returns different values for sessionID, slotID or
5839 * sequence number, the server is looney tunes.
5840 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005841 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005842 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005843
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005844 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005845 NFS4_MAX_SESSIONID_LEN)) {
5846 dprintk("%s Invalid session id\n", __func__);
5847 goto out_err;
5848 }
Benny Halevye78291e2009-08-14 17:20:00 +03005849
Benny Halevyc0eae662009-08-14 17:20:14 +03005850 p = xdr_inline_decode(xdr, 20);
5851 if (unlikely(!p))
5852 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005853
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005854 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005855 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005856 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005857 dprintk("%s Invalid sequence number\n", __func__);
5858 goto out_err;
5859 }
5860 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005861 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005862 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005863 dprintk("%s Invalid slot id\n", __func__);
5864 goto out_err;
5865 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005866 /* highest slot id */
5867 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005868 /* target highest slot id */
5869 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005870 /* result flags */
5871 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005872 status = 0;
5873out_err:
5874 res->sr_status = status;
5875 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005876out_overflow:
5877 print_overflow_msg(__func__, xdr);
5878 status = -EIO;
5879 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005880#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005881 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005882#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005883}
5884
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005885#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005886static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5887{
5888 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5889 return decode_stateid(xdr, stateid);
5890}
5891
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005892static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005893 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005894{
Trond Myklebust4e590802015-03-09 14:01:25 -04005895 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005896 __be32 *p;
5897 uint32_t len, type;
5898 int status;
5899
5900 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5901 if (status) {
5902 if (status == -ETOOSMALL) {
5903 p = xdr_inline_decode(xdr, 4);
5904 if (unlikely(!p))
5905 goto out_overflow;
5906 pdev->mincount = be32_to_cpup(p);
5907 dprintk("%s: Min count too small. mincnt = %u\n",
5908 __func__, pdev->mincount);
5909 }
5910 return status;
5911 }
5912
5913 p = xdr_inline_decode(xdr, 8);
5914 if (unlikely(!p))
5915 goto out_overflow;
5916 type = be32_to_cpup(p++);
5917 if (type != pdev->layout_type) {
5918 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5919 __func__, pdev->layout_type, type);
5920 return -EINVAL;
5921 }
5922 /*
5923 * Get the length of the opaque device_addr4. xdr_read_pages places
5924 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5925 * and places the remaining xdr data in xdr_buf->tail
5926 */
5927 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005928 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5929 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005930
5931 /* Parse notification bitmap, verifying that it is zero. */
5932 p = xdr_inline_decode(xdr, 4);
5933 if (unlikely(!p))
5934 goto out_overflow;
5935 len = be32_to_cpup(p);
5936 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005937 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005938
5939 p = xdr_inline_decode(xdr, 4 * len);
5940 if (unlikely(!p))
5941 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005942
Trond Myklebust4e590802015-03-09 14:01:25 -04005943 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005944 for (i = 1; i < len; i++) {
5945 if (be32_to_cpup(p++)) {
5946 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005947 __func__);
5948 return -EIO;
5949 }
5950 }
5951 }
5952 return 0;
5953out_overflow:
5954 print_overflow_msg(__func__, xdr);
5955 return -EIO;
5956}
5957
5958static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5959 struct nfs4_layoutget_res *res)
5960{
5961 __be32 *p;
5962 int status;
5963 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005964 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005965
5966 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5967 if (status)
5968 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005969 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005970 if (unlikely(!p))
5971 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005972 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04005973 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005974 p = xdr_inline_decode(xdr, 4);
5975 if (unlikely(!p))
5976 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005977 layout_count = be32_to_cpup(p);
5978 if (!layout_count) {
5979 dprintk("%s: server responded with empty layout array\n",
5980 __func__);
5981 return -EINVAL;
5982 }
5983
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005984 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005985 if (unlikely(!p))
5986 goto out_overflow;
5987 p = xdr_decode_hyper(p, &res->range.offset);
5988 p = xdr_decode_hyper(p, &res->range.length);
5989 res->range.iomode = be32_to_cpup(p++);
5990 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005991 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005992
5993 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5994 __func__,
5995 (unsigned long)res->range.offset,
5996 (unsigned long)res->range.length,
5997 res->range.iomode,
5998 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005999 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006000
Trond Myklebust64bd5772012-06-20 22:35:05 -04006001 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006002 if (res->layoutp->len > recvd) {
6003 dprintk("NFS: server cheating in layoutget reply: "
6004 "layout len %u > recvd %u\n",
6005 res->layoutp->len, recvd);
6006 return -EINVAL;
6007 }
6008
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006009 if (layout_count > 1) {
6010 /* We only handle a length one array at the moment. Any
6011 * further entries are just ignored. Note that this means
6012 * the client may see a response that is less than the
6013 * minimum it requested.
6014 */
6015 dprintk("%s: server responded with %d layouts, dropping tail\n",
6016 __func__, layout_count);
6017 }
6018
6019 return 0;
6020out_overflow:
6021 print_overflow_msg(__func__, xdr);
6022 return -EIO;
6023}
Andy Adamson863a3c62011-03-23 13:27:54 +00006024
Benny Halevycbe82602011-05-22 19:52:37 +03006025static int decode_layoutreturn(struct xdr_stream *xdr,
6026 struct nfs4_layoutreturn_res *res)
6027{
6028 __be32 *p;
6029 int status;
6030
6031 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6032 if (status)
6033 return status;
6034 p = xdr_inline_decode(xdr, 4);
6035 if (unlikely(!p))
6036 goto out_overflow;
6037 res->lrs_present = be32_to_cpup(p);
6038 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04006039 status = decode_layout_stateid(xdr, &res->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03006040 return status;
6041out_overflow:
6042 print_overflow_msg(__func__, xdr);
6043 return -EIO;
6044}
6045
Andy Adamson863a3c62011-03-23 13:27:54 +00006046static int decode_layoutcommit(struct xdr_stream *xdr,
6047 struct rpc_rqst *req,
6048 struct nfs4_layoutcommit_res *res)
6049{
6050 __be32 *p;
6051 __u32 sizechanged;
6052 int status;
6053
6054 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04006055 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00006056 if (status)
6057 return status;
6058
6059 p = xdr_inline_decode(xdr, 4);
6060 if (unlikely(!p))
6061 goto out_overflow;
6062 sizechanged = be32_to_cpup(p);
6063
6064 if (sizechanged) {
6065 /* throw away new size */
6066 p = xdr_inline_decode(xdr, 8);
6067 if (unlikely(!p))
6068 goto out_overflow;
6069 }
6070 return 0;
6071out_overflow:
6072 print_overflow_msg(__func__, xdr);
6073 return -EIO;
6074}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006075
6076static int decode_test_stateid(struct xdr_stream *xdr,
6077 struct nfs41_test_stateid_res *res)
6078{
6079 __be32 *p;
6080 int status;
6081 int num_res;
6082
6083 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6084 if (status)
6085 return status;
6086
6087 p = xdr_inline_decode(xdr, 4);
6088 if (unlikely(!p))
6089 goto out_overflow;
6090 num_res = be32_to_cpup(p++);
6091 if (num_res != 1)
6092 goto out;
6093
6094 p = xdr_inline_decode(xdr, 4);
6095 if (unlikely(!p))
6096 goto out_overflow;
6097 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006098
6099 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006100out_overflow:
6101 print_overflow_msg(__func__, xdr);
6102out:
6103 return -EIO;
6104}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006105
6106static int decode_free_stateid(struct xdr_stream *xdr,
6107 struct nfs41_free_stateid_res *res)
6108{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006109 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006110 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006111}
Trond Myklebustcf805162016-11-15 14:56:07 -05006112#else
6113static inline
6114int decode_layoutreturn(struct xdr_stream *xdr,
6115 struct nfs4_layoutreturn_res *res)
6116{
6117 return 0;
6118}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006119#endif /* CONFIG_NFS_V4_1 */
6120
Linus Torvalds1da177e2005-04-16 15:20:36 -07006121/*
Benny Halevy49c25592008-12-23 16:06:16 -05006122 * END OF "GENERIC" DECODE ROUTINES.
6123 */
6124
6125/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006126 * Decode OPEN_DOWNGRADE response
6127 */
Chuck Leverbf269552010-12-14 14:59:29 +00006128static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6129 struct xdr_stream *xdr,
6130 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006131{
Andy Adamson05d564f2008-12-23 16:06:15 -05006132 struct compound_hdr hdr;
6133 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006134
Chuck Leverbf269552010-12-14 14:59:29 +00006135 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006136 if (status)
6137 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006138 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006139 if (status)
6140 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006141 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006142 if (status)
6143 goto out;
Trond Myklebustb6808142016-11-20 13:34:16 -05006144 if (res->lr_res) {
6145 status = decode_layoutreturn(xdr, res->lr_res);
6146 res->lr_ret = status;
6147 if (status)
6148 goto out;
6149 }
Chuck Leverbf269552010-12-14 14:59:29 +00006150 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006151out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006152 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006153}
6154
6155/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006156 * Decode ACCESS response
6157 */
Chuck Leverbf269552010-12-14 14:59:29 +00006158static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6159 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006161 struct compound_hdr hdr;
6162 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006163
Chuck Leverbf269552010-12-14 14:59:29 +00006164 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006165 if (status)
6166 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006167 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006168 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006170 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006171 if (status != 0)
6172 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006173 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006174 if (status != 0)
6175 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006176 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006177out:
6178 return status;
6179}
6180
6181/*
6182 * Decode LOOKUP response
6183 */
Chuck Leverbf269552010-12-14 14:59:29 +00006184static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6185 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006186{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187 struct compound_hdr hdr;
6188 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006189
Chuck Leverbf269552010-12-14 14:59:29 +00006190 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006191 if (status)
6192 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006193 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006194 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006196 status = decode_putfh(xdr);
6197 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006199 status = decode_lookup(xdr);
6200 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006201 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006202 status = decode_getfh(xdr, res->fh);
6203 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006204 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006205 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206out:
6207 return status;
6208}
6209
6210/*
6211 * Decode LOOKUP_ROOT response
6212 */
Chuck Leverbf269552010-12-14 14:59:29 +00006213static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6214 struct xdr_stream *xdr,
6215 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006217 struct compound_hdr hdr;
6218 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006219
Chuck Leverbf269552010-12-14 14:59:29 +00006220 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006221 if (status)
6222 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006223 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006224 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006226 status = decode_putrootfh(xdr);
6227 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006229 status = decode_getfh(xdr, res->fh);
6230 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006231 status = decode_getfattr_label(xdr, res->fattr,
6232 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233out:
6234 return status;
6235}
6236
6237/*
6238 * Decode REMOVE response
6239 */
Chuck Leverbf269552010-12-14 14:59:29 +00006240static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6241 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243 struct compound_hdr hdr;
6244 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006245
Chuck Leverbf269552010-12-14 14:59:29 +00006246 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006247 if (status)
6248 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006249 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006250 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006252 status = decode_putfh(xdr);
6253 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006254 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006256out:
6257 return status;
6258}
6259
6260/*
6261 * Decode RENAME response
6262 */
Chuck Leverbf269552010-12-14 14:59:29 +00006263static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6264 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006265{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006266 struct compound_hdr hdr;
6267 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006268
Chuck Leverbf269552010-12-14 14:59:29 +00006269 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006270 if (status)
6271 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006272 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006273 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006274 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006275 status = decode_putfh(xdr);
6276 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006278 status = decode_savefh(xdr);
6279 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006280 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006281 status = decode_putfh(xdr);
6282 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006283 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006284 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285out:
6286 return status;
6287}
6288
6289/*
6290 * Decode LINK response
6291 */
Chuck Leverbf269552010-12-14 14:59:29 +00006292static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6293 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006294{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295 struct compound_hdr hdr;
6296 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006297
Chuck Leverbf269552010-12-14 14:59:29 +00006298 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006299 if (status)
6300 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006301 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006302 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006303 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006304 status = decode_putfh(xdr);
6305 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006307 status = decode_savefh(xdr);
6308 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006309 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_putfh(xdr);
6311 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006312 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006313 status = decode_link(xdr, &res->cinfo);
6314 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006315 goto out;
6316 /*
6317 * Note order: OP_LINK leaves the directory as the current
6318 * filehandle.
6319 */
Chuck Leverbf269552010-12-14 14:59:29 +00006320 status = decode_restorefh(xdr);
6321 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006322 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006323 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324out:
6325 return status;
6326}
6327
6328/*
6329 * Decode CREATE response
6330 */
Chuck Leverbf269552010-12-14 14:59:29 +00006331static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6332 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006333{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006334 struct compound_hdr hdr;
6335 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006336
Chuck Leverbf269552010-12-14 14:59:29 +00006337 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006338 if (status)
6339 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006340 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006341 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006342 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006343 status = decode_putfh(xdr);
6344 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006346 status = decode_create(xdr, &res->dir_cinfo);
6347 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006349 status = decode_getfh(xdr, res->fh);
6350 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006352 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353out:
6354 return status;
6355}
6356
6357/*
6358 * Decode SYMLINK response
6359 */
Chuck Leverbf269552010-12-14 14:59:29 +00006360static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6361 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362{
Chuck Leverbf269552010-12-14 14:59:29 +00006363 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364}
6365
6366/*
6367 * Decode GETATTR response
6368 */
Chuck Leverbf269552010-12-14 14:59:29 +00006369static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6370 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372 struct compound_hdr hdr;
6373 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006374
Chuck Leverbf269552010-12-14 14:59:29 +00006375 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006376 if (status)
6377 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006378 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006379 if (status)
6380 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006381 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006382 if (status)
6383 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006384 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006385out:
6386 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006387}
6388
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006389/*
6390 * Encode an SETACL request
6391 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006392static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6393 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006394{
Andy Adamson05d564f2008-12-23 16:06:15 -05006395 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006396 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006397 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006398
Chuck Lever9f06c712010-12-14 14:59:18 +00006399 encode_compound_hdr(xdr, req, &hdr);
6400 encode_sequence(xdr, &args->seq_args, &hdr);
6401 encode_putfh(xdr, args->fh, &hdr);
6402 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006403 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006404}
Andy Adamson05d564f2008-12-23 16:06:15 -05006405
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006406/*
6407 * Decode SETACL response
6408 */
6409static int
Chuck Leverbf269552010-12-14 14:59:29 +00006410nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006411 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006412{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006413 struct compound_hdr hdr;
6414 int status;
6415
Chuck Leverbf269552010-12-14 14:59:29 +00006416 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006417 if (status)
6418 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006419 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006420 if (status)
6421 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006422 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006423 if (status)
6424 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006425 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006426out:
6427 return status;
6428}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429
6430/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006431 * Decode GETACL response
6432 */
6433static int
Chuck Leverbf269552010-12-14 14:59:29 +00006434nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006435 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006436{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006437 struct compound_hdr hdr;
6438 int status;
6439
Trond Myklebust331818f2012-02-03 18:30:53 -05006440 if (res->acl_scratch != NULL) {
6441 void *p = page_address(res->acl_scratch);
6442 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6443 }
Chuck Leverbf269552010-12-14 14:59:29 +00006444 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006445 if (status)
6446 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006447 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006448 if (status)
6449 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006450 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006451 if (status)
6452 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006453 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006454
6455out:
6456 return status;
6457}
6458
6459/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460 * Decode CLOSE response
6461 */
Chuck Leverbf269552010-12-14 14:59:29 +00006462static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6463 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464{
Andy Adamson05d564f2008-12-23 16:06:15 -05006465 struct compound_hdr hdr;
6466 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467
Chuck Leverbf269552010-12-14 14:59:29 +00006468 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006469 if (status)
6470 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006471 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006472 if (status)
6473 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006474 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006475 if (status)
6476 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006477 if (res->lr_res) {
6478 status = decode_layoutreturn(xdr, res->lr_res);
6479 res->lr_ret = status;
6480 if (status)
6481 goto out;
6482 }
Trond Myklebustd8d84982016-12-19 12:14:44 -05006483 if (res->fattr != NULL) {
6484 status = decode_getfattr(xdr, res->fattr, res->server);
6485 if (status != 0)
6486 goto out;
6487 }
Chuck Leverbf269552010-12-14 14:59:29 +00006488 status = decode_close(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006489out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006490 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491}
6492
6493/*
6494 * Decode OPEN response
6495 */
Chuck Leverbf269552010-12-14 14:59:29 +00006496static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6497 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006498{
Andy Adamson05d564f2008-12-23 16:06:15 -05006499 struct compound_hdr hdr;
6500 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006501
Chuck Leverbf269552010-12-14 14:59:29 +00006502 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006503 if (status)
6504 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006505 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006506 if (status)
6507 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006508 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006509 if (status)
6510 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006511 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006512 if (status)
6513 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006514 status = decode_getfh(xdr, &res->fh);
6515 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006517 if (res->access_request)
6518 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006519 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006521 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006522}
6523
6524/*
6525 * Decode OPEN_CONFIRM response
6526 */
Chuck Leverbf269552010-12-14 14:59:29 +00006527static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6528 struct xdr_stream *xdr,
6529 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530{
Andy Adamson05d564f2008-12-23 16:06:15 -05006531 struct compound_hdr hdr;
6532 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006533
Chuck Leverbf269552010-12-14 14:59:29 +00006534 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006535 if (status)
6536 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006537 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006538 if (status)
6539 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006540 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006542 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543}
6544
6545/*
6546 * Decode OPEN response
6547 */
Chuck Leverbf269552010-12-14 14:59:29 +00006548static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6549 struct xdr_stream *xdr,
6550 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551{
Andy Adamson05d564f2008-12-23 16:06:15 -05006552 struct compound_hdr hdr;
6553 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554
Chuck Leverbf269552010-12-14 14:59:29 +00006555 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006556 if (status)
6557 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006559 if (status)
6560 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006561 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006562 if (status)
6563 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006564 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006565 if (status)
6566 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006567 if (res->access_request)
6568 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006569 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006570out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006571 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006572}
6573
6574/*
6575 * Decode SETATTR response
6576 */
Chuck Leverbf269552010-12-14 14:59:29 +00006577static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6578 struct xdr_stream *xdr,
6579 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006580{
Andy Adamson05d564f2008-12-23 16:06:15 -05006581 struct compound_hdr hdr;
6582 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583
Chuck Leverbf269552010-12-14 14:59:29 +00006584 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006585 if (status)
6586 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006587 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006588 if (status)
6589 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006590 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006591 if (status)
6592 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006593 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006594 if (status)
6595 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006596 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006598 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006599}
6600
6601/*
6602 * Decode LOCK response
6603 */
Chuck Leverbf269552010-12-14 14:59:29 +00006604static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6605 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006607 struct compound_hdr hdr;
6608 int status;
6609
Chuck Leverbf269552010-12-14 14:59:29 +00006610 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006611 if (status)
6612 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006613 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006614 if (status)
6615 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006616 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617 if (status)
6618 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006619 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006620out:
6621 return status;
6622}
6623
6624/*
6625 * Decode LOCKT response
6626 */
Chuck Leverbf269552010-12-14 14:59:29 +00006627static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6628 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006630 struct compound_hdr hdr;
6631 int status;
6632
Chuck Leverbf269552010-12-14 14:59:29 +00006633 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634 if (status)
6635 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006636 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006637 if (status)
6638 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006639 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640 if (status)
6641 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006642 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643out:
6644 return status;
6645}
6646
6647/*
6648 * Decode LOCKU response
6649 */
Chuck Leverbf269552010-12-14 14:59:29 +00006650static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6651 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006652{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653 struct compound_hdr hdr;
6654 int status;
6655
Chuck Leverbf269552010-12-14 14:59:29 +00006656 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006657 if (status)
6658 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006659 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006660 if (status)
6661 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006662 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006663 if (status)
6664 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006665 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666out:
6667 return status;
6668}
6669
Chuck Leverbf269552010-12-14 14:59:29 +00006670static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6671 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006672{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006673 struct compound_hdr hdr;
6674 int status;
6675
Chuck Leverbf269552010-12-14 14:59:29 +00006676 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006677 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006678 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006679 return status;
6680}
6681
Linus Torvalds1da177e2005-04-16 15:20:36 -07006682/*
6683 * Decode READLINK response
6684 */
Chuck Leverbf269552010-12-14 14:59:29 +00006685static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6686 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006687 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006688{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006689 struct compound_hdr hdr;
6690 int status;
6691
Chuck Leverbf269552010-12-14 14:59:29 +00006692 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006693 if (status)
6694 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006695 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006696 if (status)
6697 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006698 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699 if (status)
6700 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006701 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006702out:
6703 return status;
6704}
6705
6706/*
6707 * Decode READDIR response
6708 */
Chuck Leverbf269552010-12-14 14:59:29 +00006709static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6710 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006711{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712 struct compound_hdr hdr;
6713 int status;
6714
Chuck Leverbf269552010-12-14 14:59:29 +00006715 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006716 if (status)
6717 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006718 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006719 if (status)
6720 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006721 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006722 if (status)
6723 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006724 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006725out:
6726 return status;
6727}
6728
6729/*
6730 * Decode Read response
6731 */
Chuck Leverbf269552010-12-14 14:59:29 +00006732static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006733 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006734{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006735 struct compound_hdr hdr;
6736 int status;
6737
Chuck Leverbf269552010-12-14 14:59:29 +00006738 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006739 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006740 if (status)
6741 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006742 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006743 if (status)
6744 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006745 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006746 if (status)
6747 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006748 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749 if (!status)
6750 status = res->count;
6751out:
6752 return status;
6753}
6754
6755/*
6756 * Decode WRITE response
6757 */
Chuck Leverbf269552010-12-14 14:59:29 +00006758static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006759 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006760{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006761 struct compound_hdr hdr;
6762 int status;
6763
Chuck Leverbf269552010-12-14 14:59:29 +00006764 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006765 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766 if (status)
6767 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006768 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006769 if (status)
6770 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006771 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006772 if (status)
6773 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006774 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006775 if (status)
6776 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006777 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006778 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006779 if (!status)
6780 status = res->count;
6781out:
6782 return status;
6783}
6784
6785/*
6786 * Decode COMMIT response
6787 */
Chuck Leverbf269552010-12-14 14:59:29 +00006788static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006789 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006790{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006791 struct compound_hdr hdr;
6792 int status;
6793
Chuck Leverbf269552010-12-14 14:59:29 +00006794 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006795 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006796 if (status)
6797 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006798 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006799 if (status)
6800 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006801 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006802 if (status)
6803 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006804 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006805out:
6806 return status;
6807}
6808
6809/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006810 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006811 */
Chuck Leverbf269552010-12-14 14:59:29 +00006812static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006813 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006814{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006815 struct compound_hdr hdr;
6816 int status;
6817
Chuck Leverbf269552010-12-14 14:59:29 +00006818 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006819 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006820 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006821 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006822 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006823 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006824 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006825 return status;
6826}
6827
6828/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006829 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006830 */
Chuck Leverbf269552010-12-14 14:59:29 +00006831static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006832 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006833{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006834 struct compound_hdr hdr;
6835 int status;
6836
Chuck Leverbf269552010-12-14 14:59:29 +00006837 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006838 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006839 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006840 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006841 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006842 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006843 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006844 return status;
6845}
6846
6847/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006848 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006849 */
Chuck Leverbf269552010-12-14 14:59:29 +00006850static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006851 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006852{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006853 struct compound_hdr hdr;
6854 int status;
6855
Chuck Leverbf269552010-12-14 14:59:29 +00006856 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006857 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006858 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006859 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006860 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006861 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006862 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006863 return status;
6864}
6865
6866/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006867 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006868 */
Chuck Leverbf269552010-12-14 14:59:29 +00006869static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6870 struct xdr_stream *xdr,
6871 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006872{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006873 struct compound_hdr hdr;
6874 int status;
6875
Chuck Leverbf269552010-12-14 14:59:29 +00006876 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006877 if (status)
6878 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006879 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006880 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006881 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006882 status = decode_putfh(xdr);
6883 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006884 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006885 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006886out:
6887 return status;
6888}
6889
6890/*
6891 * Decode RENEW response
6892 */
Chuck Leverbf269552010-12-14 14:59:29 +00006893static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6894 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006895{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006896 struct compound_hdr hdr;
6897 int status;
6898
Chuck Leverbf269552010-12-14 14:59:29 +00006899 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006900 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006901 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006902 return status;
6903}
6904
6905/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006906 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006907 */
Chuck Leverbf269552010-12-14 14:59:29 +00006908static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6909 struct xdr_stream *xdr,
6910 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006911{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006912 struct compound_hdr hdr;
6913 int status;
6914
Chuck Leverbf269552010-12-14 14:59:29 +00006915 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006916 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006917 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006918 return status;
6919}
6920
6921/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006922 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006923 */
Chuck Leverbf269552010-12-14 14:59:29 +00006924static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006925 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006926{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006927 struct compound_hdr hdr;
6928 int status;
6929
Chuck Leverbf269552010-12-14 14:59:29 +00006930 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006931 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006932 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006933 return status;
6934}
6935
6936/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006937 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006938 */
Chuck Leverbf269552010-12-14 14:59:29 +00006939static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6940 struct xdr_stream *xdr,
6941 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006942{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006943 struct compound_hdr hdr;
6944 int status;
6945
Chuck Leverbf269552010-12-14 14:59:29 +00006946 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006947 if (status)
6948 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006949 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006950 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006951 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006952 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006953 if (status != 0)
6954 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05006955 if (res->lr_res) {
6956 status = decode_layoutreturn(xdr, res->lr_res);
6957 res->lr_ret = status;
6958 if (status)
6959 goto out;
6960 }
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05006961 if (res->fattr) {
6962 status = decode_getfattr(xdr, res->fattr, res->server);
6963 if (status != 0)
6964 goto out;
6965 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006966 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006967out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006968 return status;
6969}
6970
Trond Myklebust683b57b2006-06-09 09:34:22 -04006971/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006972 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006973 */
Chuck Leverbf269552010-12-14 14:59:29 +00006974static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6975 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006976 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006977{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006978 struct compound_hdr hdr;
6979 int status;
6980
Chuck Leverbf269552010-12-14 14:59:29 +00006981 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006982 if (status)
6983 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006984 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006985 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006986 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006987 status = decode_putfh(xdr);
6988 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006989 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006990 if (res->migration) {
6991 xdr_enter_page(xdr, PAGE_SIZE);
6992 status = decode_getfattr_generic(xdr,
6993 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006994 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006995 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006996 if (status)
6997 goto out;
6998 if (res->renew)
6999 status = decode_renew(xdr);
7000 } else {
7001 status = decode_lookup(xdr);
7002 if (status)
7003 goto out;
7004 xdr_enter_page(xdr, PAGE_SIZE);
7005 status = decode_getfattr_generic(xdr,
7006 &res->fs_locations->fattr,
7007 NULL, res->fs_locations,
7008 NULL, res->fs_locations->server);
7009 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04007010out:
7011 return status;
7012}
7013
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007014/*
7015 * Decode SECINFO response
7016 */
7017static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7018 struct xdr_stream *xdr,
7019 struct nfs4_secinfo_res *res)
7020{
7021 struct compound_hdr hdr;
7022 int status;
7023
7024 status = decode_compound_hdr(xdr, &hdr);
7025 if (status)
7026 goto out;
7027 status = decode_sequence(xdr, &res->seq_res, rqstp);
7028 if (status)
7029 goto out;
7030 status = decode_putfh(xdr);
7031 if (status)
7032 goto out;
7033 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007034out:
7035 return status;
7036}
7037
Chuck Lever44c99932013-10-17 14:13:30 -04007038/*
7039 * Decode FSID_PRESENT response
7040 */
7041static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7042 struct xdr_stream *xdr,
7043 struct nfs4_fsid_present_res *res)
7044{
7045 struct compound_hdr hdr;
7046 int status;
7047
7048 status = decode_compound_hdr(xdr, &hdr);
7049 if (status)
7050 goto out;
7051 status = decode_sequence(xdr, &res->seq_res, rqstp);
7052 if (status)
7053 goto out;
7054 status = decode_putfh(xdr);
7055 if (status)
7056 goto out;
7057 status = decode_getfh(xdr, res->fh);
7058 if (status)
7059 goto out;
7060 if (res->renew)
7061 status = decode_renew(xdr);
7062out:
7063 return status;
7064}
7065
Benny Halevy99fe60d2009-04-01 09:22:29 -04007066#if defined(CONFIG_NFS_V4_1)
7067/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007068 * Decode BIND_CONN_TO_SESSION response
7069 */
7070static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7071 struct xdr_stream *xdr,
7072 void *res)
7073{
7074 struct compound_hdr hdr;
7075 int status;
7076
7077 status = decode_compound_hdr(xdr, &hdr);
7078 if (!status)
7079 status = decode_bind_conn_to_session(xdr, res);
7080 return status;
7081}
7082
7083/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007084 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007085 */
Chuck Leverbf269552010-12-14 14:59:29 +00007086static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7087 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007088 void *res)
7089{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007090 struct compound_hdr hdr;
7091 int status;
7092
Chuck Leverbf269552010-12-14 14:59:29 +00007093 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007094 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007095 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007096 return status;
7097}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007098
7099/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007100 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007101 */
Chuck Leverbf269552010-12-14 14:59:29 +00007102static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7103 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04007104 struct nfs41_create_session_res *res)
7105{
Andy Adamsonfc931582009-04-01 09:22:31 -04007106 struct compound_hdr hdr;
7107 int status;
7108
Chuck Leverbf269552010-12-14 14:59:29 +00007109 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007110 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007111 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007112 return status;
7113}
7114
7115/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007116 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007117 */
Chuck Leverbf269552010-12-14 14:59:29 +00007118static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7119 struct xdr_stream *xdr,
7120 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007121{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007122 struct compound_hdr hdr;
7123 int status;
7124
Chuck Leverbf269552010-12-14 14:59:29 +00007125 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007126 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007127 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007128 return status;
7129}
7130
7131/*
Trond Myklebust66245532012-05-25 17:18:09 -04007132 * Decode DESTROY_CLIENTID response
7133 */
7134static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7135 struct xdr_stream *xdr,
7136 void *res)
7137{
7138 struct compound_hdr hdr;
7139 int status;
7140
7141 status = decode_compound_hdr(xdr, &hdr);
7142 if (!status)
7143 status = decode_destroy_clientid(xdr, res);
7144 return status;
7145}
7146
7147/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007148 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007149 */
Chuck Leverbf269552010-12-14 14:59:29 +00007150static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7151 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007152 struct nfs4_sequence_res *res)
7153{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007154 struct compound_hdr hdr;
7155 int status;
7156
Chuck Leverbf269552010-12-14 14:59:29 +00007157 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007158 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007159 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007160 return status;
7161}
7162
7163/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007164 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007165 */
Chuck Leverbf269552010-12-14 14:59:29 +00007166static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7167 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04007168 struct nfs4_get_lease_time_res *res)
7169{
Andy Adamson2050f0c2009-04-01 09:22:30 -04007170 struct compound_hdr hdr;
7171 int status;
7172
Chuck Leverbf269552010-12-14 14:59:29 +00007173 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007174 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007175 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007176 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007177 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007178 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007179 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007180 return status;
7181}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007182
7183/*
7184 * Decode RECLAIM_COMPLETE response
7185 */
Chuck Leverbf269552010-12-14 14:59:29 +00007186static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7187 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007188 struct nfs41_reclaim_complete_res *res)
7189{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007190 struct compound_hdr hdr;
7191 int status;
7192
Chuck Leverbf269552010-12-14 14:59:29 +00007193 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007194 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007195 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007196 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307197 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007198 return status;
7199}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007200
7201/*
7202 * Decode GETDEVINFO response
7203 */
Chuck Leverbf269552010-12-14 14:59:29 +00007204static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7205 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007206 struct nfs4_getdeviceinfo_res *res)
7207{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007208 struct compound_hdr hdr;
7209 int status;
7210
Chuck Leverbf269552010-12-14 14:59:29 +00007211 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007212 if (status != 0)
7213 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007214 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007215 if (status != 0)
7216 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007217 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007218out:
7219 return status;
7220}
7221
7222/*
7223 * Decode LAYOUTGET response
7224 */
Chuck Leverbf269552010-12-14 14:59:29 +00007225static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7226 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007227 struct nfs4_layoutget_res *res)
7228{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007229 struct compound_hdr hdr;
7230 int status;
7231
Chuck Leverbf269552010-12-14 14:59:29 +00007232 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007233 if (status)
7234 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007235 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007236 if (status)
7237 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007238 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007239 if (status)
7240 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007241 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007242out:
7243 return status;
7244}
Andy Adamson863a3c62011-03-23 13:27:54 +00007245
7246/*
Benny Halevycbe82602011-05-22 19:52:37 +03007247 * Decode LAYOUTRETURN response
7248 */
7249static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7250 struct xdr_stream *xdr,
7251 struct nfs4_layoutreturn_res *res)
7252{
7253 struct compound_hdr hdr;
7254 int status;
7255
7256 status = decode_compound_hdr(xdr, &hdr);
7257 if (status)
7258 goto out;
7259 status = decode_sequence(xdr, &res->seq_res, rqstp);
7260 if (status)
7261 goto out;
7262 status = decode_putfh(xdr);
7263 if (status)
7264 goto out;
7265 status = decode_layoutreturn(xdr, res);
7266out:
7267 return status;
7268}
7269
7270/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007271 * Decode LAYOUTCOMMIT response
7272 */
7273static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7274 struct xdr_stream *xdr,
7275 struct nfs4_layoutcommit_res *res)
7276{
7277 struct compound_hdr hdr;
7278 int status;
7279
7280 status = decode_compound_hdr(xdr, &hdr);
7281 if (status)
7282 goto out;
7283 status = decode_sequence(xdr, &res->seq_res, rqstp);
7284 if (status)
7285 goto out;
7286 status = decode_putfh(xdr);
7287 if (status)
7288 goto out;
7289 status = decode_layoutcommit(xdr, rqstp, res);
7290 if (status)
7291 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007292 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007293out:
7294 return status;
7295}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007296
7297/*
7298 * Decode SECINFO_NO_NAME response
7299 */
7300static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7301 struct xdr_stream *xdr,
7302 struct nfs4_secinfo_res *res)
7303{
7304 struct compound_hdr hdr;
7305 int status;
7306
7307 status = decode_compound_hdr(xdr, &hdr);
7308 if (status)
7309 goto out;
7310 status = decode_sequence(xdr, &res->seq_res, rqstp);
7311 if (status)
7312 goto out;
7313 status = decode_putrootfh(xdr);
7314 if (status)
7315 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007316 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007317out:
7318 return status;
7319}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007320
7321/*
7322 * Decode TEST_STATEID response
7323 */
7324static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7325 struct xdr_stream *xdr,
7326 struct nfs41_test_stateid_res *res)
7327{
7328 struct compound_hdr hdr;
7329 int status;
7330
7331 status = decode_compound_hdr(xdr, &hdr);
7332 if (status)
7333 goto out;
7334 status = decode_sequence(xdr, &res->seq_res, rqstp);
7335 if (status)
7336 goto out;
7337 status = decode_test_stateid(xdr, res);
7338out:
7339 return status;
7340}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007341
7342/*
7343 * Decode FREE_STATEID response
7344 */
7345static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7346 struct xdr_stream *xdr,
7347 struct nfs41_free_stateid_res *res)
7348{
7349 struct compound_hdr hdr;
7350 int status;
7351
7352 status = decode_compound_hdr(xdr, &hdr);
7353 if (status)
7354 goto out;
7355 status = decode_sequence(xdr, &res->seq_res, rqstp);
7356 if (status)
7357 goto out;
7358 status = decode_free_stateid(xdr, res);
7359out:
7360 return status;
7361}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007362#endif /* CONFIG_NFS_V4_1 */
7363
Chuck Lever573c4e12010-12-14 14:58:11 +00007364/**
7365 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7366 * the local page cache.
7367 * @xdr: XDR stream where entry resides
7368 * @entry: buffer to fill in with entry data
7369 * @plus: boolean indicating whether this should be a readdirplus entry
7370 *
7371 * Returns zero if successful, otherwise a negative errno value is
7372 * returned.
7373 *
7374 * This function is not invoked during READDIR reply decoding, but
7375 * rather whenever an application invokes the getdents(2) system call
7376 * on a directory already in our cache.
7377 */
7378int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7379 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007380{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007381 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007382 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007383 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007384 __be32 *p = xdr_inline_decode(xdr, 4);
7385 if (unlikely(!p))
7386 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007387 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007388 p = xdr_inline_decode(xdr, 4);
7389 if (unlikely(!p))
7390 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007391 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007392 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007393 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007394 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007395 }
7396
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007397 p = xdr_inline_decode(xdr, 12);
7398 if (unlikely(!p))
7399 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007400 entry->prev_cookie = entry->cookie;
7401 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007402 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007403
Trond Myklebust9af8c222010-10-24 11:52:55 -04007404 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007405 if (unlikely(!p))
7406 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007407 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007408
7409 /*
7410 * In case the server doesn't return an inode number,
7411 * we fake one here. (We don't use inode number 0,
7412 * since glibc seems to choke on it...)
7413 */
7414 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007415 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007416
Trond Myklebust9af8c222010-10-24 11:52:55 -04007417 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007418 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007419
Trond Myklebust256e48b2012-06-21 11:18:13 -04007420 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007421 goto out_overflow;
7422
Chuck Lever573c4e12010-12-14 14:58:11 +00007423 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007424 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007425 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007426 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7427 entry->ino = entry->fattr->mounted_on_fileid;
7428 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007429 entry->ino = entry->fattr->fileid;
7430
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007431 entry->d_type = DT_UNKNOWN;
7432 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7433 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7434
Chuck Lever573c4e12010-12-14 14:58:11 +00007435 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007436
7437out_overflow:
7438 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007439 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007440}
7441
7442/*
7443 * We need to translate between nfs status return values and
7444 * the local errno values which may not be the same.
7445 */
7446static struct {
7447 int stat;
7448 int errno;
7449} nfs_errtbl[] = {
7450 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007451 { NFS4ERR_PERM, -EPERM },
7452 { NFS4ERR_NOENT, -ENOENT },
7453 { NFS4ERR_IO, -errno_NFSERR_IO},
7454 { NFS4ERR_NXIO, -ENXIO },
7455 { NFS4ERR_ACCESS, -EACCES },
7456 { NFS4ERR_EXIST, -EEXIST },
7457 { NFS4ERR_XDEV, -EXDEV },
7458 { NFS4ERR_NOTDIR, -ENOTDIR },
7459 { NFS4ERR_ISDIR, -EISDIR },
7460 { NFS4ERR_INVAL, -EINVAL },
7461 { NFS4ERR_FBIG, -EFBIG },
7462 { NFS4ERR_NOSPC, -ENOSPC },
7463 { NFS4ERR_ROFS, -EROFS },
7464 { NFS4ERR_MLINK, -EMLINK },
7465 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7466 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7467 { NFS4ERR_DQUOT, -EDQUOT },
7468 { NFS4ERR_STALE, -ESTALE },
7469 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007470 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7471 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7472 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007473 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007474 { NFS4ERR_BADTYPE, -EBADTYPE },
7475 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007476 { NFS4ERR_SYMLINK, -ELOOP },
7477 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7478 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007479 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007480};
7481
7482/*
7483 * Convert an NFS error code to a local one.
7484 * This one is used jointly by NFSv2 and NFSv3.
7485 */
7486static int
David Howells0a8ea432006-08-22 20:06:08 -04007487nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007488{
7489 int i;
7490 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7491 if (nfs_errtbl[i].stat == stat)
7492 return nfs_errtbl[i].errno;
7493 }
7494 if (stat <= 10000 || stat > 10100) {
7495 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007496 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007497 }
7498 /* If we cannot translate the error, the recovery routines should
7499 * handle it.
7500 * Note: remaining NFSv4 error codes have values > 10000, so should
7501 * not conflict with native Linux error codes.
7502 */
Benny Halevy856dff32008-03-31 17:39:06 +03007503 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007504}
7505
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007506#ifdef CONFIG_NFS_V4_2
7507#include "nfs42xdr.c"
7508#endif /* CONFIG_NFS_V4_2 */
7509
Linus Torvalds1da177e2005-04-16 15:20:36 -07007510#define PROC(proc, argtype, restype) \
7511[NFSPROC4_CLNT_##proc] = { \
7512 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007513 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007514 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007515 .p_arglen = NFS4_##argtype##_sz, \
7516 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007517 .p_statidx = NFSPROC4_CLNT_##proc, \
7518 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007519}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007520
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007521#define STUB(proc) \
7522[NFSPROC4_CLNT_##proc] = { \
7523 .p_name = #proc, \
7524}
7525
Linus Torvalds1da177e2005-04-16 15:20:36 -07007526struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007527 PROC(READ, enc_read, dec_read),
7528 PROC(WRITE, enc_write, dec_write),
7529 PROC(COMMIT, enc_commit, dec_commit),
7530 PROC(OPEN, enc_open, dec_open),
7531 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7532 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7533 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7534 PROC(CLOSE, enc_close, dec_close),
7535 PROC(SETATTR, enc_setattr, dec_setattr),
7536 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7537 PROC(RENEW, enc_renew, dec_renew),
7538 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7539 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7540 PROC(LOCK, enc_lock, dec_lock),
7541 PROC(LOCKT, enc_lockt, dec_lockt),
7542 PROC(LOCKU, enc_locku, dec_locku),
7543 PROC(ACCESS, enc_access, dec_access),
7544 PROC(GETATTR, enc_getattr, dec_getattr),
7545 PROC(LOOKUP, enc_lookup, dec_lookup),
7546 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7547 PROC(REMOVE, enc_remove, dec_remove),
7548 PROC(RENAME, enc_rename, dec_rename),
7549 PROC(LINK, enc_link, dec_link),
7550 PROC(SYMLINK, enc_symlink, dec_symlink),
7551 PROC(CREATE, enc_create, dec_create),
7552 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7553 PROC(STATFS, enc_statfs, dec_statfs),
7554 PROC(READLINK, enc_readlink, dec_readlink),
7555 PROC(READDIR, enc_readdir, dec_readdir),
7556 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7557 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7558 PROC(GETACL, enc_getacl, dec_getacl),
7559 PROC(SETACL, enc_setacl, dec_setacl),
7560 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7561 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007562 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007563 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007564#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007565 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7566 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7567 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7568 PROC(SEQUENCE, enc_sequence, dec_sequence),
7569 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7570 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7571 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7572 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007573 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007574 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007575 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007576 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007577 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007578 STUB(GETDEVICELIST),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007579 PROC(BIND_CONN_TO_SESSION,
7580 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007581 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007582#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007583#ifdef CONFIG_NFS_V4_2
7584 PROC(SEEK, enc_seek, dec_seek),
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007585 PROC(ALLOCATE, enc_allocate, dec_allocate),
Anna Schumaker624bd5b2014-11-25 13:18:16 -05007586 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
Trond Myklebustbe3a5d22015-06-23 19:51:55 +08007587 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
Peng Tao36022772015-09-26 02:24:34 +08007588 PROC(CLONE, enc_clone, dec_clone),
Anna Schumaker2e724482013-05-21 16:53:03 -04007589 PROC(COPY, enc_copy, dec_copy),
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007590#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007591};
7592
Trond Myklebusta613fa12012-01-20 13:53:56 -05007593const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007594 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007595 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007596 .procs = nfs4_procedures
7597};
7598
7599/*
7600 * Local variables:
7601 * c-basic-offset: 8
7602 * End:
7603 */