blob: 73d2a68f06986da0275f6b88ff761f71aa6a2703 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
Chuck Leverf0920752012-05-21 22:45:41 -040055
Trond Myklebust4ce79712005-06-22 17:16:21 +000056#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050057#include "internal.h"
Anna Schumaker40c64c22015-04-15 13:00:05 -040058#include "nfs4idmap.h"
Trond Myklebust76e697b2012-11-26 14:20:49 -050059#include "nfs4session.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040060#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040061#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63#define NFSDBG_FACILITY NFSDBG_XDR
64
65/* Mapping from NFS error code to "errno" error code. */
66#define errno_NFSERR_IO EIO
67
David Howells0a8ea432006-08-22 20:06:08 -040068static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
71#ifdef DEBUG
72#define NFS4_MAXTAGLEN 20
73#else
74#define NFS4_MAXTAGLEN 0
75#endif
76
Andy Adamson6c0195a2008-12-23 16:06:15 -050077/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040078 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040080#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050081#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040082#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85#define op_encode_hdr_maxsz (1)
86#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040087#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
90#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
92 (NFS4_FHSIZE >> 2))
93#define decode_putfh_maxsz (op_decode_hdr_maxsz)
94#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
95#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
96#define encode_getfh_maxsz (op_encode_hdr_maxsz)
97#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
98 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040099#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +0000100#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
102#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400103#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
104#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
David Quigleyaa9c2662013-05-22 12:50:44 -0400105#ifdef CONFIG_NFS_V4_SECURITY_LABEL
106/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
107#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
David Quigleyaa9c2662013-05-22 12:50:44 -0400108#else
109#define nfs4_label_maxsz 0
David Quigleyaa9c2662013-05-22 12:50:44 -0400110#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400111/* We support only one layout type per file system */
112#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000113/* This is based on getfattr, which uses the most attributes: */
114#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400115 3 + 3 + 3 + nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400116 nfs4_group_maxsz + nfs4_label_maxsz + \
117 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000118#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
119 nfs4_fattr_value_maxsz)
120#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400121#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
122 1 + 2 + 1 + \
123 nfs4_owner_maxsz + \
124 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400125 nfs4_label_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400126 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define encode_savefh_maxsz (op_encode_hdr_maxsz)
128#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400129#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
130#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200131#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400132/* The 5 accounts for the PNFS attributes, and assumes that at most three
133 * layout types will be returned.
134 */
135#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
136 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
138#define decode_renew_maxsz (op_decode_hdr_maxsz)
139#define encode_setclientid_maxsz \
140 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500141 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400142 /* client name */ \
143 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500144 1 /* sc_prog */ + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500145 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
146 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500147 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#define decode_setclientid_maxsz \
149 (op_decode_hdr_maxsz + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500150 2 /* clientid */ + \
151 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
152 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
153 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154#define encode_setclientid_confirm_maxsz \
155 (op_encode_hdr_maxsz + \
156 3 + (NFS4_VERIFIER_SIZE >> 2))
157#define decode_setclientid_confirm_maxsz \
158 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400159#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
160#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400161#define encode_share_access_maxsz \
162 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500163#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400164#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
165#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
166#define encode_open_maxsz (op_encode_hdr_maxsz + \
167 2 + encode_share_access_maxsz + 2 + \
168 open_owner_id_maxsz + \
169 encode_opentype_maxsz + \
170 encode_claim_null_maxsz)
171#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400172#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400173 decode_ace_maxsz)
174#define decode_change_info_maxsz (5)
175#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400176 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400177 decode_change_info_maxsz + 1 + \
178 nfs4_fattr_bitmap_maxsz + \
179 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400180#define encode_open_confirm_maxsz \
181 (op_encode_hdr_maxsz + \
182 encode_stateid_maxsz + 1)
183#define decode_open_confirm_maxsz \
184 (op_decode_hdr_maxsz + \
185 decode_stateid_maxsz)
186#define encode_open_downgrade_maxsz \
187 (op_encode_hdr_maxsz + \
188 encode_stateid_maxsz + 1 + \
189 encode_share_access_maxsz)
190#define decode_open_downgrade_maxsz \
191 (op_decode_hdr_maxsz + \
192 decode_stateid_maxsz)
193#define encode_close_maxsz (op_encode_hdr_maxsz + \
194 1 + encode_stateid_maxsz)
195#define decode_close_maxsz (op_decode_hdr_maxsz + \
196 decode_stateid_maxsz)
197#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
198 encode_stateid_maxsz + \
199 encode_attrs_maxsz)
200#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
201 nfs4_fattr_bitmap_maxsz)
202#define encode_read_maxsz (op_encode_hdr_maxsz + \
203 encode_stateid_maxsz + 3)
204#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
205#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400206 2 + encode_verifier_maxsz + 5 + \
207 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400208#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Chuck Levera7697f62014-03-12 12:51:17 -0400209 decode_verifier_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400210#define encode_readlink_maxsz (op_encode_hdr_maxsz)
211#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
212#define encode_write_maxsz (op_encode_hdr_maxsz + \
213 encode_stateid_maxsz + 4)
214#define decode_write_maxsz (op_decode_hdr_maxsz + \
215 2 + decode_verifier_maxsz)
216#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
217#define decode_commit_maxsz (op_decode_hdr_maxsz + \
218 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219#define encode_remove_maxsz (op_encode_hdr_maxsz + \
220 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400221#define decode_remove_maxsz (op_decode_hdr_maxsz + \
222 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223#define encode_rename_maxsz (op_encode_hdr_maxsz + \
224 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400225#define decode_rename_maxsz (op_decode_hdr_maxsz + \
226 decode_change_info_maxsz + \
227 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228#define encode_link_maxsz (op_encode_hdr_maxsz + \
229 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400230#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400231#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400232#define encode_lock_maxsz (op_encode_hdr_maxsz + \
233 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400234 1 + encode_stateid_maxsz + 1 + \
235 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400236#define decode_lock_denied_maxsz \
237 (8 + decode_lockowner_maxsz)
238#define decode_lock_maxsz (op_decode_hdr_maxsz + \
239 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400240#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
241 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400242#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
243 decode_lock_denied_maxsz)
244#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
245 encode_stateid_maxsz + \
246 4)
247#define decode_locku_maxsz (op_decode_hdr_maxsz + \
248 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400249#define encode_release_lockowner_maxsz \
250 (op_encode_hdr_maxsz + \
251 encode_lockowner_maxsz)
252#define decode_release_lockowner_maxsz \
253 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400254#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
255#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
257 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400258 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000259 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
261#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400262 1 + 2 + nfs4_name_maxsz + \
263 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400264#define decode_create_maxsz (op_decode_hdr_maxsz + \
265 decode_change_info_maxsz + \
266 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400267#define encode_statfs_maxsz (encode_getattr_maxsz)
268#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
270#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400271#define encode_getacl_maxsz (encode_getattr_maxsz)
272#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
273 nfs4_fattr_bitmap_maxsz + 1)
274#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
275 encode_stateid_maxsz + 3)
276#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400277#define encode_fs_locations_maxsz \
278 (encode_getattr_maxsz)
279#define decode_fs_locations_maxsz \
280 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000281#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400282#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 -0400283
284#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400285#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500286#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
287 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400288
Benny Halevy99fe60d2009-04-01 09:22:29 -0400289#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
290 encode_verifier_maxsz + \
291 1 /* co_ownerid.len */ + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400292 /* eia_clientowner */ \
293 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400294 1 /* flags */ + \
295 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400296 /* max is SP4_MACH_CRED (for now) */ + \
297 1 + NFS4_OP_MAP_NUM_WORDS + \
298 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500299 1 /* implementation id array of size 1 */ + \
300 1 /* nii_domain */ + \
301 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
302 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500303 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500304 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400305#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
306 2 /* eir_clientid */ + \
307 1 /* eir_sequenceid */ + \
308 1 /* eir_flags */ + \
309 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400310 /* max is SP4_MACH_CRED (for now) */ + \
311 1 + NFS4_OP_MAP_NUM_WORDS + \
312 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400313 2 /* eir_server_owner.so_minor_id */ + \
314 /* eir_server_owner.so_major_id<> */ \
315 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
316 /* eir_server_scope<> */ \
317 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
318 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500319 1 /* nii_domain */ + \
320 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
321 1 /* nii_name */ + \
322 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
323 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400324#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
325#define decode_channel_attrs_maxsz (6 + \
326 1 /* ca_rdma_ird.len */ + \
327 1 /* ca_rdma_ird */)
328#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
329 2 /* csa_clientid */ + \
330 1 /* csa_sequence */ + \
331 1 /* csa_flags */ + \
332 encode_channel_attrs_maxsz + \
333 encode_channel_attrs_maxsz + \
334 1 /* csa_cb_program */ + \
335 1 /* csa_sec_parms.len (1) */ + \
336 1 /* cb_secflavor (AUTH_SYS) */ + \
337 1 /* stamp */ + \
338 1 /* machinename.len */ + \
339 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
340 1 /* uid */ + \
341 1 /* gid */ + \
342 1 /* gids.len (0) */)
343#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
344 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
345 1 /* csr_sequence */ + \
346 1 /* csr_flags */ + \
347 decode_channel_attrs_maxsz + \
348 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400349#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
350 /* bctsa_sessid */ \
351 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
352 1 /* bctsa_dir */ + \
353 1 /* bctsa_use_conn_in_rdma_mode */)
354#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
355 /* bctsr_sessid */ \
356 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
357 1 /* bctsr_dir */ + \
358 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400359#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
360#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400361#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
362#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400363#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
364 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
365#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
366 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500367#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
368#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700369#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
370 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
371 1 /* layout type */ + \
372 1 /* maxcount */ + \
373 1 /* bitmap size */ + \
374 1 /* notification bitmap length */ + \
375 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400376#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
377 1 /* layout type */ + \
378 1 /* opaque devaddr4 length */ + \
379 /* devaddr4 payload is read into page */ \
380 1 /* notification bitmap length */ + \
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700381 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400382#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
383 encode_stateid_maxsz)
384#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
385 decode_stateid_maxsz + \
386 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000387#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
388 2 /* offset */ + \
389 2 /* length */ + \
390 1 /* reclaim */ + \
391 encode_stateid_maxsz + \
392 1 /* new offset (true) */ + \
393 2 /* last byte written */ + \
394 1 /* nt_timechanged (false) */ + \
395 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500396 1 /* layoutupdate4 opaqueue len */)
397 /* the actual content of layoutupdate4 should
398 be allocated by drivers and spliced in
399 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000400#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300401#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
402 encode_stateid_maxsz + \
Trond Myklebust6669cb82015-08-27 20:43:20 -0400403 1 + \
404 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
Benny Halevycbe82602011-05-22 19:52:37 +0300405#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
406 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400407#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
408#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400409#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
410 XDR_QUADLEN(NFS4_STATEID_SIZE))
411#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400412#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
413 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400414#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400415#else /* CONFIG_NFS_V4_1 */
416#define encode_sequence_maxsz 0
417#define decode_sequence_maxsz 0
Trond Myklebustcf805162016-11-15 14:56:07 -0500418#define encode_layoutreturn_maxsz 0
419#define decode_layoutreturn_maxsz 0
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400420#endif /* CONFIG_NFS_V4_1 */
421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
423#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
424#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400425 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400427 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400429 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400431 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400433 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400435 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400439 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400441 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400443 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400445 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400447 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400449 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400451 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400452 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400454 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400456 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400457 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400459 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400461 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400465 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400467 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400468 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400469 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400470 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400471 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400472 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400474 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400475 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400477 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400478 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400479 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400480#define NFS4_enc_open_confirm_sz \
481 (compound_encode_hdr_maxsz + \
482 encode_putfh_maxsz + \
483 encode_open_confirm_maxsz)
484#define NFS4_dec_open_confirm_sz \
485 (compound_decode_hdr_maxsz + \
486 decode_putfh_maxsz + \
487 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400489 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400491 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400492 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400493 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400495 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400497 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400498 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400499 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500#define NFS4_enc_open_downgrade_sz \
501 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400502 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400503 encode_putfh_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400504 encode_open_downgrade_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505#define NFS4_dec_open_downgrade_sz \
506 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400507 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400508 decode_putfh_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400509 decode_open_downgrade_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400510#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400511 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400512 encode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500513 encode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400514 encode_close_maxsz + \
515 encode_getattr_maxsz)
516#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400517 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400518 decode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500519 decode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400520 decode_close_maxsz + \
521 decode_getattr_maxsz)
522#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400523 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400524 encode_putfh_maxsz + \
525 encode_setattr_maxsz + \
526 encode_getattr_maxsz)
527#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400528 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400529 decode_putfh_maxsz + \
530 decode_setattr_maxsz + \
531 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400533 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 encode_putfh_maxsz + \
535 encode_fsinfo_maxsz)
536#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400537 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 decode_putfh_maxsz + \
539 decode_fsinfo_maxsz)
540#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
541 encode_renew_maxsz)
542#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
543 decode_renew_maxsz)
544#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
545 encode_setclientid_maxsz)
546#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
547 decode_setclientid_maxsz)
548#define NFS4_enc_setclientid_confirm_sz \
549 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400550 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551#define NFS4_dec_setclientid_confirm_sz \
552 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400553 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400555 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400557 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400559 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400561 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400563 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400565 encode_lockt_maxsz)
566#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400567 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400568 decode_putfh_maxsz + \
569 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400571 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400573 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400575 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400577 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400578#define NFS4_enc_release_lockowner_sz \
579 (compound_encode_hdr_maxsz + \
580 encode_lockowner_maxsz)
581#define NFS4_dec_release_lockowner_sz \
582 (compound_decode_hdr_maxsz + \
583 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400585 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400587 encode_access_maxsz + \
588 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400592 decode_access_maxsz + \
593 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400595 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400597 encode_getattr_maxsz + \
598 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400600 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400602 decode_getattr_maxsz + \
603 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400605 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 encode_putfh_maxsz + \
607 encode_lookup_maxsz + \
608 encode_getattr_maxsz + \
609 encode_getfh_maxsz)
610#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400611 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400613 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 decode_getattr_maxsz + \
615 decode_getfh_maxsz)
616#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400617 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 encode_putrootfh_maxsz + \
619 encode_getattr_maxsz + \
620 encode_getfh_maxsz)
621#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 decode_putrootfh_maxsz + \
624 decode_getattr_maxsz + \
625 decode_getfh_maxsz)
626#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400627 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400629 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400631 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400633 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400635 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 encode_putfh_maxsz + \
637 encode_savefh_maxsz + \
638 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400639 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400641 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 decode_putfh_maxsz + \
643 decode_savefh_maxsz + \
644 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400645 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400647 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 encode_putfh_maxsz + \
649 encode_savefh_maxsz + \
650 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400651 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400652 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400653 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400655 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 decode_putfh_maxsz + \
657 decode_savefh_maxsz + \
658 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400659 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400660 decode_restorefh_maxsz + \
661 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400663 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 encode_putfh_maxsz + \
665 encode_symlink_maxsz + \
666 encode_getattr_maxsz + \
667 encode_getfh_maxsz)
668#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400669 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 decode_putfh_maxsz + \
671 decode_symlink_maxsz + \
672 decode_getattr_maxsz + \
673 decode_getfh_maxsz)
674#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400675 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 encode_putfh_maxsz + \
677 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400678 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400679 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400681 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 decode_putfh_maxsz + \
683 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400684 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400685 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400687 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 encode_putfh_maxsz + \
689 encode_getattr_maxsz)
690#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400691 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 decode_putfh_maxsz + \
693 decode_getattr_maxsz)
694#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400695 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400697 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400699 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400701 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400703 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800704 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 encode_getattr_maxsz)
706#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400707 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800708 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 decode_getattr_maxsz)
710#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400711 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100713 encode_delegreturn_maxsz + \
714 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400716 decode_sequence_maxsz + \
Trond Myklebustd8434d4c2016-11-16 13:54:00 -0500717 decode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100718 decode_delegreturn_maxsz + \
719 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000720#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400721 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000722 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400723 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000724#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400725 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000726 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400727 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000728#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400729 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000730 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400731 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000732#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400733 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000734 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400735 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400736#define NFS4_enc_fs_locations_sz \
737 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400738 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400739 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400740 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400741 encode_fs_locations_maxsz + \
742 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400743#define NFS4_dec_fs_locations_sz \
744 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400745 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400746 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400747 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400748 decode_fs_locations_maxsz + \
749 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000750#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
751 encode_sequence_maxsz + \
752 encode_putfh_maxsz + \
753 encode_secinfo_maxsz)
754#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
755 decode_sequence_maxsz + \
756 decode_putfh_maxsz + \
757 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400758#define NFS4_enc_fsid_present_sz \
759 (compound_encode_hdr_maxsz + \
760 encode_sequence_maxsz + \
761 encode_putfh_maxsz + \
762 encode_getfh_maxsz + \
763 encode_renew_maxsz)
764#define NFS4_dec_fsid_present_sz \
765 (compound_decode_hdr_maxsz + \
766 decode_sequence_maxsz + \
767 decode_putfh_maxsz + \
768 decode_getfh_maxsz + \
769 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400770#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400771#define NFS4_enc_bind_conn_to_session_sz \
772 (compound_encode_hdr_maxsz + \
773 encode_bind_conn_to_session_maxsz)
774#define NFS4_dec_bind_conn_to_session_sz \
775 (compound_decode_hdr_maxsz + \
776 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400777#define NFS4_enc_exchange_id_sz \
778 (compound_encode_hdr_maxsz + \
779 encode_exchange_id_maxsz)
780#define NFS4_dec_exchange_id_sz \
781 (compound_decode_hdr_maxsz + \
782 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400783#define NFS4_enc_create_session_sz \
784 (compound_encode_hdr_maxsz + \
785 encode_create_session_maxsz)
786#define NFS4_dec_create_session_sz \
787 (compound_decode_hdr_maxsz + \
788 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400789#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
790 encode_destroy_session_maxsz)
791#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
792 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400793#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
794 encode_destroy_clientid_maxsz)
795#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
796 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400797#define NFS4_enc_sequence_sz \
798 (compound_decode_hdr_maxsz + \
799 encode_sequence_maxsz)
800#define NFS4_dec_sequence_sz \
801 (compound_decode_hdr_maxsz + \
802 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400803#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
804 encode_sequence_maxsz + \
805 encode_putrootfh_maxsz + \
806 encode_fsinfo_maxsz)
807#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
808 decode_sequence_maxsz + \
809 decode_putrootfh_maxsz + \
810 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500811#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
812 encode_sequence_maxsz + \
813 encode_reclaim_complete_maxsz)
814#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
815 decode_sequence_maxsz + \
816 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400817#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
818 encode_sequence_maxsz +\
819 encode_getdeviceinfo_maxsz)
820#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
821 decode_sequence_maxsz + \
822 decode_getdeviceinfo_maxsz)
823#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
824 encode_sequence_maxsz + \
825 encode_putfh_maxsz + \
826 encode_layoutget_maxsz)
827#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
828 decode_sequence_maxsz + \
829 decode_putfh_maxsz + \
830 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000831#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
832 encode_sequence_maxsz +\
833 encode_putfh_maxsz + \
834 encode_layoutcommit_maxsz + \
835 encode_getattr_maxsz)
836#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
837 decode_sequence_maxsz + \
838 decode_putfh_maxsz + \
839 decode_layoutcommit_maxsz + \
840 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300841#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
842 encode_sequence_maxsz + \
843 encode_putfh_maxsz + \
844 encode_layoutreturn_maxsz)
845#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
846 decode_sequence_maxsz + \
847 decode_putfh_maxsz + \
848 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400849#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
850 encode_sequence_maxsz + \
851 encode_putrootfh_maxsz +\
852 encode_secinfo_no_name_maxsz)
853#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
854 decode_sequence_maxsz + \
855 decode_putrootfh_maxsz + \
856 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400857#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
858 encode_sequence_maxsz + \
859 encode_test_stateid_maxsz)
860#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
861 decode_sequence_maxsz + \
862 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400863#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
864 encode_sequence_maxsz + \
865 encode_free_stateid_maxsz)
866#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
867 decode_sequence_maxsz + \
868 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500869
870const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
871 compound_encode_hdr_maxsz +
872 encode_sequence_maxsz +
873 encode_putfh_maxsz +
874 encode_getattr_maxsz) *
875 XDR_UNIT);
876
877const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
878 compound_decode_hdr_maxsz +
879 decode_sequence_maxsz +
880 decode_putfh_maxsz) *
881 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400882
883const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
884 compound_decode_hdr_maxsz +
885 decode_sequence_maxsz) *
886 XDR_UNIT);
887EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400888#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
Trond Myklebustbca79472009-03-11 14:10:26 -0400890static const umode_t nfs_type2fmt[] = {
891 [NF4BAD] = 0,
892 [NF4REG] = S_IFREG,
893 [NF4DIR] = S_IFDIR,
894 [NF4BLK] = S_IFBLK,
895 [NF4CHR] = S_IFCHR,
896 [NF4LNK] = S_IFLNK,
897 [NF4SOCK] = S_IFSOCK,
898 [NF4FIFO] = S_IFIFO,
899 [NF4ATTRDIR] = 0,
900 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901};
902
903struct compound_hdr {
904 int32_t status;
905 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500906 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 uint32_t taglen;
908 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400909 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400910 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911};
912
Benny Halevy13c65ce2009-08-14 17:19:25 +0300913static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
914{
915 __be32 *p = xdr_reserve_space(xdr, nbytes);
916 BUG_ON(!p);
917 return p;
918}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
Trond Myklebustcb17e552012-03-04 18:13:56 -0500920static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
921{
922 __be32 *p;
923
924 p = xdr_reserve_space(xdr, len);
925 xdr_encode_opaque_fixed(p, buf, len);
926}
927
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
929{
Al Viro8687b632006-10-19 23:28:48 -0700930 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500932 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 xdr_encode_opaque(p, str, len);
934}
935
Trond Myklebust4ade9822012-03-04 18:13:57 -0500936static void encode_uint32(struct xdr_stream *xdr, u32 n)
937{
938 __be32 *p;
939
940 p = reserve_space(xdr, 4);
941 *p = cpu_to_be32(n);
942}
943
Trond Myklebustff2eb682012-03-05 11:40:12 -0500944static void encode_uint64(struct xdr_stream *xdr, u64 n)
945{
946 __be32 *p;
947
948 p = reserve_space(xdr, 8);
949 xdr_encode_hyper(p, n);
950}
951
Trond Myklebust4ade9822012-03-04 18:13:57 -0500952static void encode_nfs4_seqid(struct xdr_stream *xdr,
953 const struct nfs_seqid *seqid)
954{
Trond Myklebusta6796412015-01-23 19:04:44 -0500955 if (seqid != NULL)
956 encode_uint32(xdr, seqid->sequence->counter);
957 else
958 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500959}
960
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400961static void encode_compound_hdr(struct xdr_stream *xdr,
962 struct rpc_rqst *req,
963 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964{
Al Viro8687b632006-10-19 23:28:48 -0700965 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400966 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400967
968 /* initialize running count of expected bytes in reply.
969 * NOTE: the replied tag SHOULD be the same is the one sent,
970 * but this is not required as a MUST for the server to do so. */
971 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Trond Myklebust7fc38842012-10-15 11:51:21 -0400973 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500974 encode_string(xdr, hdr->taglen, hdr->tag);
975 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300976 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500977 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300978 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500979}
980
Trond Myklebustab19b482012-03-04 18:13:57 -0500981static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
982 uint32_t replen,
983 struct compound_hdr *hdr)
984{
985 encode_uint32(xdr, op);
986 hdr->nops++;
987 hdr->replen += replen;
988}
989
Andy Adamsond0179312008-12-23 16:06:17 -0500990static void encode_nops(struct compound_hdr *hdr)
991{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400992 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500993 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994}
995
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500996static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
997{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500998 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500999}
1000
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1002{
Trond Myklebustcb17e552012-03-04 18:13:56 -05001003 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004}
1005
David Quigleyaa9c2662013-05-22 12:50:44 -04001006static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1007 const struct nfs4_label *label,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001008 const struct nfs_server *server,
1009 bool excl_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010{
1011 char owner_name[IDMAP_NAMESZ];
1012 char owner_group[IDMAP_NAMESZ];
1013 int owner_namelen = 0;
1014 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001015 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001016 unsigned i;
1017 uint32_t len = 0;
1018 uint32_t bmval_len;
1019 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
1021 /*
1022 * We reserve enough space to write the entire attribute buffer at once.
1023 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001024 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1025 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001026 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001028 if (iap->ia_valid & ATTR_SIZE) {
1029 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001031 }
1032 if (iap->ia_valid & ATTR_MODE) {
1033 bmval[1] |= FATTR4_WORD1_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 len += 4;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001035 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001037 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001039 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001040 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 /* XXX */
1042 strcpy(owner_name, "nobody");
1043 owner_namelen = sizeof("nobody") - 1;
1044 /* goto out; */
1045 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001046 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1048 }
1049 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001050 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001052 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001053 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 strcpy(owner_group, "nobody");
1055 owner_grouplen = sizeof("nobody") - 1;
1056 /* goto out; */
1057 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001058 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001062 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1063 len += 16;
1064 } else if (iap->ia_valid & ATTR_ATIME) {
1065 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1066 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 }
1068 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001069 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1070 len += 16;
1071 } else if (iap->ia_valid & ATTR_MTIME) {
1072 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1073 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001075
1076 if (excl_check) {
1077 const u32 *excl_bmval = server->exclcreat_bitmask;
1078 bmval[0] &= excl_bmval[0];
1079 bmval[1] &= excl_bmval[1];
1080 bmval[2] &= excl_bmval[2];
1081
1082 if (!(excl_bmval[2] & FATTR4_WORD2_SECURITY_LABEL))
1083 label = NULL;
1084 }
1085
David Quigleyaa9c2662013-05-22 12:50:44 -04001086 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001087 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1088 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1089 }
1090
1091 if (bmval[2] != 0)
1092 bmval_len = 3;
1093 else if (bmval[1] != 0)
1094 bmval_len = 2;
1095 else
1096 bmval_len = 1;
1097
1098 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1099
1100 *p++ = cpu_to_be32(bmval_len);
1101 for (i = 0; i < bmval_len; i++)
1102 *p++ = cpu_to_be32(bmval[i]);
1103 *p++ = cpu_to_be32(len);
1104
1105 if (bmval[0] & FATTR4_WORD0_SIZE)
1106 p = xdr_encode_hyper(p, iap->ia_size);
1107 if (bmval[1] & FATTR4_WORD1_MODE)
1108 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1109 if (bmval[1] & FATTR4_WORD1_OWNER)
1110 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1111 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1112 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1113 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1114 if (iap->ia_valid & ATTR_ATIME_SET) {
1115 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1116 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1117 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1118 } else
1119 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1120 }
1121 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1122 if (iap->ia_valid & ATTR_MTIME_SET) {
1123 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1124 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1125 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1126 } else
1127 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1128 }
1129 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001130 *p++ = cpu_to_be32(label->lfs);
1131 *p++ = cpu_to_be32(label->pi);
1132 *p++ = cpu_to_be32(label->len);
1133 p = xdr_encode_opaque_fixed(p, label->label, label->len);
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);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001189 encode_attrs(xdr, create->attrs, create->label, create->server, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190}
1191
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001192static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193{
Andy Adamson05d564f2008-12-23 16:06:15 -05001194 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001196 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1197 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001198 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001199 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200}
1201
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001202static 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 -07001203{
Andy Adamson05d564f2008-12-23 16:06:15 -05001204 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001206 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1207 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001208 *p++ = cpu_to_be32(2);
1209 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001210 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211}
1212
Fred Isamandae100c2011-07-30 20:52:37 -04001213static void
1214encode_getattr_three(struct xdr_stream *xdr,
1215 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1216 struct compound_hdr *hdr)
1217{
1218 __be32 *p;
1219
Trond Myklebustab19b482012-03-04 18:13:57 -05001220 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001221 if (bm2) {
1222 p = reserve_space(xdr, 16);
1223 *p++ = cpu_to_be32(3);
1224 *p++ = cpu_to_be32(bm0);
1225 *p++ = cpu_to_be32(bm1);
1226 *p = cpu_to_be32(bm2);
1227 } else if (bm1) {
1228 p = reserve_space(xdr, 12);
1229 *p++ = cpu_to_be32(2);
1230 *p++ = cpu_to_be32(bm0);
1231 *p = cpu_to_be32(bm1);
1232 } else {
1233 p = reserve_space(xdr, 8);
1234 *p++ = cpu_to_be32(1);
1235 *p = cpu_to_be32(bm0);
1236 }
Fred Isamandae100c2011-07-30 20:52:37 -04001237}
1238
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001239static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240{
David Quigleya09df2c2013-05-22 12:50:41 -04001241 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1242 bitmask[1] & nfs4_fattr_bitmap[1],
1243 bitmask[2] & nfs4_fattr_bitmap[2],
1244 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245}
1246
Andy Adamson88034c32012-05-23 05:02:34 -04001247static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001248 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001249 struct compound_hdr *hdr)
1250{
1251 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001252 bitmask[0] & open_bitmap[0],
1253 bitmask[1] & open_bitmap[1],
1254 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001255 hdr);
1256}
1257
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001258static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259{
Fred Isamandae100c2011-07-30 20:52:37 -04001260 encode_getattr_three(xdr,
1261 bitmask[0] & nfs4_fsinfo_bitmap[0],
1262 bitmask[1] & nfs4_fsinfo_bitmap[1],
1263 bitmask[2] & nfs4_fsinfo_bitmap[2],
1264 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265}
1266
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001267static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001268{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001269 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1270 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001271}
1272
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001273static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274{
Trond Myklebustab19b482012-03-04 18:13:57 -05001275 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276}
1277
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001278static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279{
Trond Myklebustab19b482012-03-04 18:13:57 -05001280 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001281 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282}
1283
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001284static inline int nfs4_lock_type(struct file_lock *fl, int block)
1285{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001286 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001287 return block ? NFS4_READW_LT : NFS4_READ_LT;
1288 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1289}
1290
1291static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1292{
1293 if (fl->fl_end == OFFSET_MAX)
1294 return ~(uint64_t)0;
1295 return fl->fl_end - fl->fl_start + 1;
1296}
1297
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001298static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1299{
1300 __be32 *p;
1301
Trond Myklebustd035c362010-12-21 10:45:27 -05001302 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001303 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001304 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001305 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001306 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001307 xdr_encode_hyper(p, lowner->id);
1308}
1309
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310/*
1311 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1312 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1313 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001314static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315{
Al Viro8687b632006-10-19 23:28:48 -07001316 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001318 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1319 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001320 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1321 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001322 p = xdr_encode_hyper(p, args->fl->fl_start);
1323 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001324 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001325 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001326 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001327 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001328 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001329 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 }
1331 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001332 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001333 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335}
1336
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001337static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338{
Al Viro8687b632006-10-19 23:28:48 -07001339 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001341 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1342 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001343 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001344 p = xdr_encode_hyper(p, args->fl->fl_start);
1345 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001346 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001349static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350{
Al Viro8687b632006-10-19 23:28:48 -07001351 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001353 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1354 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001355 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001356 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001357 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001358 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001359 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360}
1361
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001362static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1363{
Trond Myklebustab19b482012-03-04 18:13:57 -05001364 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001365 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001366}
1367
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001368static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369{
Trond Myklebustab19b482012-03-04 18:13:57 -05001370 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001371 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372}
1373
Trond Myklebust6ae37332015-01-30 14:21:14 -05001374static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375{
Al Viro8687b632006-10-19 23:28:48 -07001376 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
Benny Halevy13c65ce2009-08-14 17:19:25 +03001378 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001379 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001380 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381}
1382
1383static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1384{
Al Viro8687b632006-10-19 23:28:48 -07001385 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 /*
1387 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1388 * owner 4 = 32
1389 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001390 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001391 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001392 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001393 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001394 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001395 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001396 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001397 *p++ = cpu_to_be32(arg->id.uniquifier);
1398 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399}
1400
1401static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1402{
Al Viro8687b632006-10-19 23:28:48 -07001403 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
Benny Halevy13c65ce2009-08-14 17:19:25 +03001405 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001406 switch(arg->createmode) {
1407 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001408 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001409 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false);
Andy Adamson05d564f2008-12-23 16:06:15 -05001410 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001411 case NFS4_CREATE_GUARDED:
1412 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001413 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001414 break;
1415 case NFS4_CREATE_EXCLUSIVE:
1416 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1417 encode_nfs4_verifier(xdr, &arg->u.verifier);
1418 break;
1419 case NFS4_CREATE_EXCLUSIVE4_1:
1420 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1421 encode_nfs4_verifier(xdr, &arg->u.verifier);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001422 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 }
1424}
1425
1426static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1427{
Al Viro8687b632006-10-19 23:28:48 -07001428 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Benny Halevy13c65ce2009-08-14 17:19:25 +03001430 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001432 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001433 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001434 break;
1435 default:
Benny Halevy34558512009-08-14 17:19:30 +03001436 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001437 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 }
1439}
1440
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001441static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442{
Al Viro8687b632006-10-19 23:28:48 -07001443 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
Benny Halevy13c65ce2009-08-14 17:19:25 +03001445 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001447 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001448 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001449 break;
1450 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001451 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001452 break;
1453 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001454 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001455 break;
1456 default:
1457 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 }
1459}
1460
1461static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1462{
Al Viro8687b632006-10-19 23:28:48 -07001463 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Benny Halevy13c65ce2009-08-14 17:19:25 +03001465 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001466 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 encode_string(xdr, name->len, name->name);
1468}
1469
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001470static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471{
Al Viro8687b632006-10-19 23:28:48 -07001472 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Benny Halevy13c65ce2009-08-14 17:19:25 +03001474 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001475 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 encode_delegation_type(xdr, type);
1477}
1478
1479static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1480{
Al Viro8687b632006-10-19 23:28:48 -07001481 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001483 p = reserve_space(xdr, 4);
1484 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1485 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 encode_string(xdr, name->len, name->name);
1487}
1488
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001489static inline void encode_claim_fh(struct xdr_stream *xdr)
1490{
1491 __be32 *p;
1492
1493 p = reserve_space(xdr, 4);
1494 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1495}
1496
1497static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1498{
1499 __be32 *p;
1500
1501 p = reserve_space(xdr, 4);
1502 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1503 encode_nfs4_stateid(xdr, stateid);
1504}
1505
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001506static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507{
Trond Myklebustab19b482012-03-04 18:13:57 -05001508 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 encode_openhdr(xdr, arg);
1510 encode_opentype(xdr, arg);
1511 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001512 case NFS4_OPEN_CLAIM_NULL:
1513 encode_claim_null(xdr, arg->name);
1514 break;
1515 case NFS4_OPEN_CLAIM_PREVIOUS:
1516 encode_claim_previous(xdr, arg->u.delegation_type);
1517 break;
1518 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1519 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1520 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001521 case NFS4_OPEN_CLAIM_FH:
1522 encode_claim_fh(xdr);
1523 break;
1524 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1525 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1526 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001527 default:
1528 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530}
1531
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001532static 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 -07001533{
Trond Myklebustab19b482012-03-04 18:13:57 -05001534 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001535 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001536 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537}
1538
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001539static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540{
Trond Myklebustab19b482012-03-04 18:13:57 -05001541 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001542 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001543 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001544 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545}
1546
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001547static void
Andy Adamsond0179312008-12-23 16:06:17 -05001548encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549{
Trond Myklebustab19b482012-03-04 18:13:57 -05001550 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001551 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552}
1553
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001554static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555{
Trond Myklebustab19b482012-03-04 18:13:57 -05001556 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557}
1558
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001559static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1560 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
Al Viro8687b632006-10-19 23:28:48 -07001562 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
Trond Myklebustab19b482012-03-04 18:13:57 -05001564 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001565 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Benny Halevy13c65ce2009-08-14 17:19:25 +03001567 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001568 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001569 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570}
1571
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001572static 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 -07001573{
David Quigleyaa9c2662013-05-22 12:50:44 -04001574 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001575 FATTR4_WORD0_RDATTR_ERROR,
1576 FATTR4_WORD1_MOUNTED_ON_FILEID,
1577 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001578 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001579 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001580 uint32_t attrlen = 0;
1581 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001583 if (readdir->plus) {
1584 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001585 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001586 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1587 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1588 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1589 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001590 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001591 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001592 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001593 /* Use mounted_on_fileid only if the server supports it */
1594 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1595 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001596 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1597 attrs[i] &= readdir->bitmask[i];
1598 if (attrs[i] != 0)
1599 attrlen = i+1;
1600 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001601
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001602 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001603 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001604 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001605 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001606 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001607 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001608 *p++ = cpu_to_be32(attrlen);
1609 for (i = 0; i < attrlen; i++)
1610 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001611 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001612
1613 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001614 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001615 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001616 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001617 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001618 attrs[1] & readdir->bitmask[1],
1619 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620}
1621
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001622static 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 -07001623{
Trond Myklebustab19b482012-03-04 18:13:57 -05001624 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625}
1626
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001627static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628{
Trond Myklebustab19b482012-03-04 18:13:57 -05001629 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001630 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631}
1632
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001633static 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 -07001634{
Trond Myklebustab19b482012-03-04 18:13:57 -05001635 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001636 encode_string(xdr, oldname->len, oldname->name);
1637 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638}
1639
Chuck Leverbb4dae52012-03-01 17:01:48 -05001640static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1641 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001643 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001644 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645}
1646
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001647static void
Andy Adamsond0179312008-12-23 16:06:17 -05001648encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001649{
Trond Myklebustab19b482012-03-04 18:13:57 -05001650 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001651}
1652
Chuck Lever9f06c712010-12-14 14:59:18 +00001653static void
Andy Adamsond0179312008-12-23 16:06:17 -05001654encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001655{
Al Viro8687b632006-10-19 23:28:48 -07001656 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001657
Trond Myklebustab19b482012-03-04 18:13:57 -05001658 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001659 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001660 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001661 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001662 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001663 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001664 *p = cpu_to_be32(arg->acl_len);
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01001665 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001666}
1667
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001668static void
Andy Adamsond0179312008-12-23 16:06:17 -05001669encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670{
Trond Myklebustab19b482012-03-04 18:13:57 -05001671 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672}
1673
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001674static 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 -07001675{
Trond Myklebustab19b482012-03-04 18:13:57 -05001676 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001677 encode_nfs4_stateid(xdr, &arg->stateid);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001678 encode_attrs(xdr, arg->iap, arg->label, server, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679}
1680
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001681static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682{
Al Viro8687b632006-10-19 23:28:48 -07001683 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
Trond Myklebust70019512012-03-04 20:49:32 -05001685 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001686 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
Jeff Layton3a6bb732015-06-09 19:43:57 -04001688 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1689 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001690 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001691 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1693 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001694 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001695 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696}
1697
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001698static 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 -07001699{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001700 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1701 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001702 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001703 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704}
1705
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001706static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1707 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708{
Al Viro8687b632006-10-19 23:28:48 -07001709 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
Trond Myklebustab19b482012-03-04 18:13:57 -05001711 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001712 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713
Benny Halevy13c65ce2009-08-14 17:19:25 +03001714 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001715 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001716 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001717 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718
1719 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720}
1721
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001722static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723{
Trond Myklebustab19b482012-03-04 18:13:57 -05001724 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001725 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001727
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001728static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1729{
Trond Myklebustab19b482012-03-04 18:13:57 -05001730 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001731 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001732}
1733
Benny Halevy99fe60d2009-04-01 09:22:29 -04001734#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001735/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001736static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08001737 struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001738 struct compound_hdr *hdr)
1739{
1740 __be32 *p;
1741
1742 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1743 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001744 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001745 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001746 *p++ = cpu_to_be32(args->dir);
1747 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001748}
1749
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001750static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1751{
1752 unsigned int i;
1753 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1754 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1755 encode_uint32(xdr, op_map->u.words[i]);
1756}
1757
Benny Halevy99fe60d2009-04-01 09:22:29 -04001758static void encode_exchange_id(struct xdr_stream *xdr,
1759 struct nfs41_exchange_id_args *args,
1760 struct compound_hdr *hdr)
1761{
1762 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001763 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001764 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001765
Trond Myklebust70019512012-03-04 20:49:32 -05001766 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001767 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001768
Jeff Layton3a6bb732015-06-09 19:43:57 -04001769 encode_string(xdr, strlen(args->client->cl_owner_id),
1770 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001771
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001772 encode_uint32(xdr, args->flags);
1773 encode_uint32(xdr, args->state_protect.how);
1774
1775 switch (args->state_protect.how) {
1776 case SP4_NONE:
1777 break;
1778 case SP4_MACH_CRED:
1779 encode_op_map(xdr, &args->state_protect.enforce);
1780 encode_op_map(xdr, &args->state_protect.allow);
1781 break;
1782 default:
1783 WARN_ON_ONCE(1);
1784 break;
1785 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001786
1787 if (send_implementation_id &&
1788 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1789 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001790 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001791 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1792 utsname()->sysname, utsname()->release,
1793 utsname()->version, utsname()->machine);
1794
1795 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001796 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001797
1798 encode_string(xdr,
1799 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1800 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1801 encode_string(xdr, len, impl_name);
1802 /* just send zeros for nii_date - the date is in nii_name */
1803 p = reserve_space(xdr, 12);
1804 p = xdr_encode_hyper(p, 0);
1805 *p = cpu_to_be32(0);
1806 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001807 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001808}
Andy Adamsonfc931582009-04-01 09:22:31 -04001809
1810static void encode_create_session(struct xdr_stream *xdr,
1811 struct nfs41_create_session_args *args,
1812 struct compound_hdr *hdr)
1813{
1814 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001815 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001816 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001817 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001818 u32 max_resp_sz_cached;
1819
1820 /*
1821 * Assumes OPEN is the biggest non-idempotent compound.
1822 * 2 is the verifier.
1823 */
1824 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1825 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001826
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001827 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001828 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001829 p = xdr_encode_hyper(p, args->clientid);
1830 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001831 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001832
Andy Adamsonfc931582009-04-01 09:22:31 -04001833 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001834 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001835 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1836 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001837 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001838 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1839 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1840 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001841
1842 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001843 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001844 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1845 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1846 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1847 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1848 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1849 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001850
Benny Halevye75bc1c2009-08-14 17:18:54 +03001851 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001852 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001853 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001854
1855 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001856 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001857 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001858 *p++ = cpu_to_be32(0); /* UID */
1859 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001860 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001861}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001862
1863static void encode_destroy_session(struct xdr_stream *xdr,
1864 struct nfs4_session *session,
1865 struct compound_hdr *hdr)
1866{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001867 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1868 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001869}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001870
Trond Myklebust66245532012-05-25 17:18:09 -04001871static void encode_destroy_clientid(struct xdr_stream *xdr,
1872 uint64_t clientid,
1873 struct compound_hdr *hdr)
1874{
1875 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1876 encode_uint64(xdr, clientid);
1877}
1878
Ricardo Labiaga180197532009-12-05 16:08:40 -05001879static void encode_reclaim_complete(struct xdr_stream *xdr,
1880 struct nfs41_reclaim_complete_args *args,
1881 struct compound_hdr *hdr)
1882{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001883 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1884 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001885}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001886#endif /* CONFIG_NFS_V4_1 */
1887
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001888static void encode_sequence(struct xdr_stream *xdr,
1889 const struct nfs4_sequence_args *args,
1890 struct compound_hdr *hdr)
1891{
1892#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001893 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001894 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001895 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001896 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001897
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001898 tp = slot->table;
1899 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001900 if (!session)
1901 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001902
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001903 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001904
1905 /*
1906 * Sessionid + seqid + slotid + max slotid + cache_this
1907 */
1908 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1909 "max_slotid=%d cache_this=%d\n",
1910 __func__,
1911 ((u32 *)session->sess_id.data)[0],
1912 ((u32 *)session->sess_id.data)[1],
1913 ((u32 *)session->sess_id.data)[2],
1914 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001915 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001916 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001917 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001918 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001919 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001920 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001921 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001922 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001923#endif /* CONFIG_NFS_V4_1 */
1924}
1925
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001926#ifdef CONFIG_NFS_V4_1
1927static void
1928encode_getdeviceinfo(struct xdr_stream *xdr,
1929 const struct nfs4_getdeviceinfo_args *args,
1930 struct compound_hdr *hdr)
1931{
1932 __be32 *p;
1933
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001934 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001935 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001936 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1937 NFS4_DEVICEID4_SIZE);
1938 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001939 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001940
1941 p = reserve_space(xdr, 4 + 4);
1942 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001943 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001944}
1945
1946static void
1947encode_layoutget(struct xdr_stream *xdr,
1948 const struct nfs4_layoutget_args *args,
1949 struct compound_hdr *hdr)
1950{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001951 __be32 *p;
1952
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001953 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1954 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001955 *p++ = cpu_to_be32(0); /* Signal layout available */
1956 *p++ = cpu_to_be32(args->type);
1957 *p++ = cpu_to_be32(args->range.iomode);
1958 p = xdr_encode_hyper(p, args->range.offset);
1959 p = xdr_encode_hyper(p, args->range.length);
1960 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001961 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001962 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001963
1964 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1965 __func__,
1966 args->type,
1967 args->range.iomode,
1968 (unsigned long)args->range.offset,
1969 (unsigned long)args->range.length,
1970 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001971}
Andy Adamson863a3c62011-03-23 13:27:54 +00001972
1973static int
1974encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001975 struct inode *inode,
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001976 struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001977 struct compound_hdr *hdr)
1978{
1979 __be32 *p;
1980
1981 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1982 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1983
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001984 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1985 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001986 /* Only whole file layouts */
1987 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001988 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001989 *p = cpu_to_be32(0); /* reclaim */
1990 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04001991 if (args->lastbytewritten != U64_MAX) {
1992 p = reserve_space(xdr, 20);
1993 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1994 p = xdr_encode_hyper(p, args->lastbytewritten);
1995 } else {
1996 p = reserve_space(xdr, 12);
1997 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
1998 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001999 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2000 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002001
Christoph Hellwig5f919c92014-08-21 11:09:25 -05002002 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
Benny Halevyac7db722011-05-22 19:53:48 +03002003 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2004 NFS_I(inode)->layout, xdr, args);
Christoph Hellwig5f919c92014-08-21 11:09:25 -05002005 } else {
2006 encode_uint32(xdr, args->layoutupdate_len);
2007 if (args->layoutupdate_pages) {
2008 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2009 args->layoutupdate_len);
2010 }
2011 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002012
Andy Adamson863a3c62011-03-23 13:27:54 +00002013 return 0;
2014}
Benny Halevycbe82602011-05-22 19:52:37 +03002015
2016static void
2017encode_layoutreturn(struct xdr_stream *xdr,
2018 const struct nfs4_layoutreturn_args *args,
2019 struct compound_hdr *hdr)
2020{
Trond Myklebust94e5c572016-09-15 18:49:52 -04002021 const struct pnfs_layoutdriver_type *lr_ops = NFS_SERVER(args->inode)->pnfs_curr_ld;
Benny Halevycbe82602011-05-22 19:52:37 +03002022 __be32 *p;
2023
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002024 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2025 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002026 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2027 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002028 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002029 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002030 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002031 p = xdr_encode_hyper(p, args->range.offset);
2032 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002033 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002034 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002035 spin_unlock(&args->inode->i_lock);
Trond Myklebust94e5c572016-09-15 18:49:52 -04002036 if (lr_ops->encode_layoutreturn)
2037 lr_ops->encode_layoutreturn(xdr, args);
2038 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002039 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002040}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002041
2042static int
2043encode_secinfo_no_name(struct xdr_stream *xdr,
2044 const struct nfs41_secinfo_no_name_args *args,
2045 struct compound_hdr *hdr)
2046{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002047 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2048 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002049 return 0;
2050}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002051
2052static void encode_test_stateid(struct xdr_stream *xdr,
2053 struct nfs41_test_stateid_args *args,
2054 struct compound_hdr *hdr)
2055{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002056 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2057 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002058 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002059}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002060
2061static void encode_free_stateid(struct xdr_stream *xdr,
2062 struct nfs41_free_stateid_args *args,
2063 struct compound_hdr *hdr)
2064{
Trond Myklebustab19b482012-03-04 18:13:57 -05002065 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002066 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002067}
Trond Myklebustcf805162016-11-15 14:56:07 -05002068#else
2069static inline void
2070encode_layoutreturn(struct xdr_stream *xdr,
2071 const struct nfs4_layoutreturn_args *args,
2072 struct compound_hdr *hdr)
2073{
2074}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002075#endif /* CONFIG_NFS_V4_1 */
2076
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077/*
2078 * END OF "GENERIC" ENCODE ROUTINES.
2079 */
2080
Benny Halevy66cc0422009-04-01 09:22:10 -04002081static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2082{
2083#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002084 struct nfs4_session *session = args->sa_slot->table->session;
2085 if (session)
2086 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002087#endif /* CONFIG_NFS_V4_1 */
2088 return 0;
2089}
2090
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091/*
2092 * Encode an ACCESS request
2093 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002094static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2095 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002098 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Chuck Lever9f06c712010-12-14 14:59:18 +00002101 encode_compound_hdr(xdr, req, &hdr);
2102 encode_sequence(xdr, &args->seq_args, &hdr);
2103 encode_putfh(xdr, args->fh, &hdr);
2104 encode_access(xdr, args->access, &hdr);
2105 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002106 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107}
2108
2109/*
2110 * Encode LOOKUP request
2111 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002112static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2113 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002116 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
Chuck Lever9f06c712010-12-14 14:59:18 +00002119 encode_compound_hdr(xdr, req, &hdr);
2120 encode_sequence(xdr, &args->seq_args, &hdr);
2121 encode_putfh(xdr, args->dir_fh, &hdr);
2122 encode_lookup(xdr, args->name, &hdr);
2123 encode_getfh(xdr, &hdr);
2124 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002125 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126}
2127
2128/*
2129 * Encode LOOKUP_ROOT request
2130 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002131static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2132 struct xdr_stream *xdr,
2133 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002136 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
Chuck Lever9f06c712010-12-14 14:59:18 +00002139 encode_compound_hdr(xdr, req, &hdr);
2140 encode_sequence(xdr, &args->seq_args, &hdr);
2141 encode_putrootfh(xdr, &hdr);
2142 encode_getfh(xdr, &hdr);
2143 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002144 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145}
2146
2147/*
2148 * Encode REMOVE request
2149 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002150static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2151 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002154 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156
Chuck Lever9f06c712010-12-14 14:59:18 +00002157 encode_compound_hdr(xdr, req, &hdr);
2158 encode_sequence(xdr, &args->seq_args, &hdr);
2159 encode_putfh(xdr, args->fh, &hdr);
2160 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002161 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162}
2163
2164/*
2165 * Encode RENAME request
2166 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002167static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2168 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002171 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173
Chuck Lever9f06c712010-12-14 14:59:18 +00002174 encode_compound_hdr(xdr, req, &hdr);
2175 encode_sequence(xdr, &args->seq_args, &hdr);
2176 encode_putfh(xdr, args->old_dir, &hdr);
2177 encode_savefh(xdr, &hdr);
2178 encode_putfh(xdr, args->new_dir, &hdr);
2179 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002180 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181}
2182
2183/*
2184 * Encode LINK request
2185 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002186static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2187 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002190 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192
Chuck Lever9f06c712010-12-14 14:59:18 +00002193 encode_compound_hdr(xdr, req, &hdr);
2194 encode_sequence(xdr, &args->seq_args, &hdr);
2195 encode_putfh(xdr, args->fh, &hdr);
2196 encode_savefh(xdr, &hdr);
2197 encode_putfh(xdr, args->dir_fh, &hdr);
2198 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002199 encode_restorefh(xdr, &hdr);
2200 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002201 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202}
2203
2204/*
2205 * Encode CREATE request
2206 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002207static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2208 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002211 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
Chuck Lever9f06c712010-12-14 14:59:18 +00002214 encode_compound_hdr(xdr, req, &hdr);
2215 encode_sequence(xdr, &args->seq_args, &hdr);
2216 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002217 encode_create(xdr, args, &hdr);
2218 encode_getfh(xdr, &hdr);
2219 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002220 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221}
2222
2223/*
2224 * Encode SYMLINK request
2225 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002226static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2227 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228{
Chuck Lever9f06c712010-12-14 14:59:18 +00002229 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230}
2231
2232/*
2233 * Encode GETATTR request
2234 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002235static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2236 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002239 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
Chuck Lever9f06c712010-12-14 14:59:18 +00002242 encode_compound_hdr(xdr, req, &hdr);
2243 encode_sequence(xdr, &args->seq_args, &hdr);
2244 encode_putfh(xdr, args->fh, &hdr);
2245 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002246 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247}
2248
2249/*
2250 * Encode a CLOSE request
2251 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002252static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2253 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254{
Andy Adamson05d564f2008-12-23 16:06:15 -05002255 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002256 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002257 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258
Chuck Lever9f06c712010-12-14 14:59:18 +00002259 encode_compound_hdr(xdr, req, &hdr);
2260 encode_sequence(xdr, &args->seq_args, &hdr);
2261 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002262 if (args->lr_args)
2263 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002264 encode_close(xdr, args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002265 if (args->bitmask != NULL)
2266 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002267 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268}
2269
2270/*
2271 * Encode an OPEN request
2272 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002273static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2274 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002277 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279
Chuck Lever9f06c712010-12-14 14:59:18 +00002280 encode_compound_hdr(xdr, req, &hdr);
2281 encode_sequence(xdr, &args->seq_args, &hdr);
2282 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002283 encode_open(xdr, args, &hdr);
2284 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002285 if (args->access)
2286 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002287 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002288 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289}
2290
2291/*
2292 * Encode an OPEN_CONFIRM request
2293 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002294static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2295 struct xdr_stream *xdr,
2296 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002299 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301
Chuck Lever9f06c712010-12-14 14:59:18 +00002302 encode_compound_hdr(xdr, req, &hdr);
2303 encode_putfh(xdr, args->fh, &hdr);
2304 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002305 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306}
2307
2308/*
2309 * Encode an OPEN request with no attributes.
2310 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002311static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2312 struct xdr_stream *xdr,
2313 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002316 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318
Chuck Lever9f06c712010-12-14 14:59:18 +00002319 encode_compound_hdr(xdr, req, &hdr);
2320 encode_sequence(xdr, &args->seq_args, &hdr);
2321 encode_putfh(xdr, args->fh, &hdr);
2322 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002323 if (args->access)
2324 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002325 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002326 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327}
2328
2329/*
2330 * Encode an OPEN_DOWNGRADE request
2331 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002332static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2333 struct xdr_stream *xdr,
2334 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002337 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339
Chuck Lever9f06c712010-12-14 14:59:18 +00002340 encode_compound_hdr(xdr, req, &hdr);
2341 encode_sequence(xdr, &args->seq_args, &hdr);
2342 encode_putfh(xdr, args->fh, &hdr);
2343 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002344 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345}
2346
2347/*
2348 * Encode a LOCK request
2349 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002350static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2351 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002354 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356
Chuck Lever9f06c712010-12-14 14:59:18 +00002357 encode_compound_hdr(xdr, req, &hdr);
2358 encode_sequence(xdr, &args->seq_args, &hdr);
2359 encode_putfh(xdr, args->fh, &hdr);
2360 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002361 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362}
2363
2364/*
2365 * Encode a LOCKT request
2366 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002367static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2368 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002371 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373
Chuck Lever9f06c712010-12-14 14:59:18 +00002374 encode_compound_hdr(xdr, req, &hdr);
2375 encode_sequence(xdr, &args->seq_args, &hdr);
2376 encode_putfh(xdr, args->fh, &hdr);
2377 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002378 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379}
2380
2381/*
2382 * Encode a LOCKU request
2383 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002384static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2385 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002388 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390
Chuck Lever9f06c712010-12-14 14:59:18 +00002391 encode_compound_hdr(xdr, req, &hdr);
2392 encode_sequence(xdr, &args->seq_args, &hdr);
2393 encode_putfh(xdr, args->fh, &hdr);
2394 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002395 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396}
2397
Chuck Lever9f06c712010-12-14 14:59:18 +00002398static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2399 struct xdr_stream *xdr,
2400 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002401{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002402 struct compound_hdr hdr = {
2403 .minorversion = 0,
2404 };
2405
Chuck Lever9f06c712010-12-14 14:59:18 +00002406 encode_compound_hdr(xdr, req, &hdr);
2407 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002408 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002409}
2410
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411/*
2412 * Encode a READLINK request
2413 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002414static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2415 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002418 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
Chuck Lever9f06c712010-12-14 14:59:18 +00002421 encode_compound_hdr(xdr, req, &hdr);
2422 encode_sequence(xdr, &args->seq_args, &hdr);
2423 encode_putfh(xdr, args->fh, &hdr);
2424 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002425
Benny Halevy28f56692009-04-01 09:22:09 -04002426 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002427 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002428 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429}
2430
2431/*
2432 * Encode a READDIR request
2433 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002434static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2435 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002438 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440
Chuck Lever9f06c712010-12-14 14:59:18 +00002441 encode_compound_hdr(xdr, req, &hdr);
2442 encode_sequence(xdr, &args->seq_args, &hdr);
2443 encode_putfh(xdr, args->fh, &hdr);
2444 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002445
Benny Halevy28f56692009-04-01 09:22:09 -04002446 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002447 args->pgbase, args->count);
2448 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002449 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002450 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002451 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452}
2453
2454/*
2455 * Encode a READ request
2456 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002457static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002458 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002461 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463
Chuck Lever9f06c712010-12-14 14:59:18 +00002464 encode_compound_hdr(xdr, req, &hdr);
2465 encode_sequence(xdr, &args->seq_args, &hdr);
2466 encode_putfh(xdr, args->fh, &hdr);
2467 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468
Benny Halevy28f56692009-04-01 09:22:09 -04002469 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002471 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002472 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473}
2474
2475/*
2476 * Encode an SETATTR request
2477 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002478static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2479 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480{
Andy Adamson05d564f2008-12-23 16:06:15 -05002481 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002482 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002483 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484
Chuck Lever9f06c712010-12-14 14:59:18 +00002485 encode_compound_hdr(xdr, req, &hdr);
2486 encode_sequence(xdr, &args->seq_args, &hdr);
2487 encode_putfh(xdr, args->fh, &hdr);
2488 encode_setattr(xdr, args, args->server, &hdr);
2489 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002490 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491}
2492
2493/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002494 * Encode a GETACL request
2495 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002496static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2497 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002498{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002499 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002500 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002501 };
Benny Halevy28f56692009-04-01 09:22:09 -04002502 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002503
Chuck Lever9f06c712010-12-14 14:59:18 +00002504 encode_compound_hdr(xdr, req, &hdr);
2505 encode_sequence(xdr, &args->seq_args, &hdr);
2506 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002507 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002508 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002509
Benny Halevy28f56692009-04-01 09:22:09 -04002510 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01002511 args->acl_pages, 0, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002512
Andy Adamsond0179312008-12-23 16:06:17 -05002513 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002514}
2515
2516/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 * Encode a WRITE request
2518 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002519static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002520 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002523 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525
Chuck Lever9f06c712010-12-14 14:59:18 +00002526 encode_compound_hdr(xdr, req, &hdr);
2527 encode_sequence(xdr, &args->seq_args, &hdr);
2528 encode_putfh(xdr, args->fh, &hdr);
2529 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002530 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002531 if (args->bitmask)
2532 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002533 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534}
2535
2536/*
2537 * a COMMIT request
2538 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002539static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002540 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002543 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545
Chuck Lever9f06c712010-12-14 14:59:18 +00002546 encode_compound_hdr(xdr, req, &hdr);
2547 encode_sequence(xdr, &args->seq_args, &hdr);
2548 encode_putfh(xdr, args->fh, &hdr);
2549 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002550 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551}
2552
2553/*
2554 * FSINFO request
2555 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002556static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2557 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002560 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562
Chuck Lever9f06c712010-12-14 14:59:18 +00002563 encode_compound_hdr(xdr, req, &hdr);
2564 encode_sequence(xdr, &args->seq_args, &hdr);
2565 encode_putfh(xdr, args->fh, &hdr);
2566 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002567 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568}
2569
2570/*
2571 * a PATHCONF request
2572 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002573static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2574 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002577 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579
Chuck Lever9f06c712010-12-14 14:59:18 +00002580 encode_compound_hdr(xdr, req, &hdr);
2581 encode_sequence(xdr, &args->seq_args, &hdr);
2582 encode_putfh(xdr, args->fh, &hdr);
2583 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002584 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002585 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586}
2587
2588/*
2589 * a STATFS request
2590 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002591static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2592 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002595 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597
Chuck Lever9f06c712010-12-14 14:59:18 +00002598 encode_compound_hdr(xdr, req, &hdr);
2599 encode_sequence(xdr, &args->seq_args, &hdr);
2600 encode_putfh(xdr, args->fh, &hdr);
2601 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002602 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002603 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604}
2605
2606/*
2607 * GETATTR_BITMAP request
2608 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002609static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2610 struct xdr_stream *xdr,
2611 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612{
Kinglong Mee8c612822015-08-26 21:12:58 +08002613 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002615 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617
Chuck Lever9f06c712010-12-14 14:59:18 +00002618 encode_compound_hdr(xdr, req, &hdr);
2619 encode_sequence(xdr, &args->seq_args, &hdr);
2620 encode_putfh(xdr, args->fhandle, &hdr);
Kinglong Mee8c612822015-08-26 21:12:58 +08002621 encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002622 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623}
2624
2625/*
2626 * a RENEW request
2627 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002628static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2629 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002632 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 };
2634
Chuck Lever9f06c712010-12-14 14:59:18 +00002635 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002636 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002637 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638}
2639
2640/*
2641 * a SETCLIENTID request
2642 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002643static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2644 struct xdr_stream *xdr,
2645 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002648 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 };
2650
Chuck Lever9f06c712010-12-14 14:59:18 +00002651 encode_compound_hdr(xdr, req, &hdr);
2652 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002653 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654}
2655
2656/*
2657 * a SETCLIENTID_CONFIRM request
2658 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002659static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2660 struct xdr_stream *xdr,
2661 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002664 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666
Chuck Lever9f06c712010-12-14 14:59:18 +00002667 encode_compound_hdr(xdr, req, &hdr);
2668 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002669 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670}
2671
2672/*
2673 * DELEGRETURN request
2674 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002675static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2676 struct xdr_stream *xdr,
2677 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002680 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
Chuck Lever9f06c712010-12-14 14:59:18 +00002683 encode_compound_hdr(xdr, req, &hdr);
2684 encode_sequence(xdr, &args->seq_args, &hdr);
2685 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002686 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002687 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002688 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689}
2690
2691/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002692 * Encode FS_LOCATIONS request
2693 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002694static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2695 struct xdr_stream *xdr,
2696 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002697{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002698 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002699 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002700 };
Benny Halevy28f56692009-04-01 09:22:09 -04002701 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002702
Chuck Lever9f06c712010-12-14 14:59:18 +00002703 encode_compound_hdr(xdr, req, &hdr);
2704 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002705 if (args->migration) {
2706 encode_putfh(xdr, args->fh, &hdr);
2707 replen = hdr.replen;
2708 encode_fs_locations(xdr, args->bitmask, &hdr);
2709 if (args->renew)
2710 encode_renew(xdr, args->clientid, &hdr);
2711 } else {
2712 encode_putfh(xdr, args->dir_fh, &hdr);
2713 encode_lookup(xdr, args->name, &hdr);
2714 replen = hdr.replen;
2715 encode_fs_locations(xdr, args->bitmask, &hdr);
2716 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002717
Chuck Leverb03d7352013-10-17 14:12:50 -04002718 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002719 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002720 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002721 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002722}
2723
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002724/*
2725 * Encode SECINFO request
2726 */
2727static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2728 struct xdr_stream *xdr,
2729 struct nfs4_secinfo_arg *args)
2730{
2731 struct compound_hdr hdr = {
2732 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2733 };
2734
2735 encode_compound_hdr(xdr, req, &hdr);
2736 encode_sequence(xdr, &args->seq_args, &hdr);
2737 encode_putfh(xdr, args->dir_fh, &hdr);
2738 encode_secinfo(xdr, args->name, &hdr);
2739 encode_nops(&hdr);
2740}
2741
Chuck Lever44c99932013-10-17 14:13:30 -04002742/*
2743 * Encode FSID_PRESENT request
2744 */
2745static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2746 struct xdr_stream *xdr,
2747 struct nfs4_fsid_present_arg *args)
2748{
2749 struct compound_hdr hdr = {
2750 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2751 };
2752
2753 encode_compound_hdr(xdr, req, &hdr);
2754 encode_sequence(xdr, &args->seq_args, &hdr);
2755 encode_putfh(xdr, args->fh, &hdr);
2756 encode_getfh(xdr, &hdr);
2757 if (args->renew)
2758 encode_renew(xdr, args->clientid, &hdr);
2759 encode_nops(&hdr);
2760}
2761
Benny Halevy99fe60d2009-04-01 09:22:29 -04002762#if defined(CONFIG_NFS_V4_1)
2763/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002764 * BIND_CONN_TO_SESSION request
2765 */
2766static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2767 struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08002768 struct nfs41_bind_conn_to_session_args *args)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002769{
2770 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002771 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002772 };
2773
2774 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002775 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002776 encode_nops(&hdr);
2777}
2778
2779/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002780 * EXCHANGE_ID request
2781 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002782static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2783 struct xdr_stream *xdr,
2784 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002785{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002786 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002787 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002788 };
2789
Chuck Lever9f06c712010-12-14 14:59:18 +00002790 encode_compound_hdr(xdr, req, &hdr);
2791 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002792 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002793}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002794
2795/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002796 * a CREATE_SESSION request
2797 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002798static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2799 struct xdr_stream *xdr,
2800 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002801{
Andy Adamsonfc931582009-04-01 09:22:31 -04002802 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002803 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002804 };
2805
Chuck Lever9f06c712010-12-14 14:59:18 +00002806 encode_compound_hdr(xdr, req, &hdr);
2807 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002808 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002809}
2810
2811/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002812 * a DESTROY_SESSION request
2813 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002814static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2815 struct xdr_stream *xdr,
2816 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002817{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002818 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002819 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002820 };
2821
Chuck Lever9f06c712010-12-14 14:59:18 +00002822 encode_compound_hdr(xdr, req, &hdr);
2823 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002824 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002825}
2826
2827/*
Trond Myklebust66245532012-05-25 17:18:09 -04002828 * a DESTROY_CLIENTID request
2829 */
2830static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2831 struct xdr_stream *xdr,
2832 struct nfs_client *clp)
2833{
2834 struct compound_hdr hdr = {
2835 .minorversion = clp->cl_mvops->minor_version,
2836 };
2837
2838 encode_compound_hdr(xdr, req, &hdr);
2839 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2840 encode_nops(&hdr);
2841}
2842
2843/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002844 * a SEQUENCE request
2845 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002846static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2847 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002848{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002849 struct compound_hdr hdr = {
2850 .minorversion = nfs4_xdr_minorversion(args),
2851 };
2852
Chuck Lever9f06c712010-12-14 14:59:18 +00002853 encode_compound_hdr(xdr, req, &hdr);
2854 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002855 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002856}
2857
2858/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002859 * a GET_LEASE_TIME request
2860 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002861static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2862 struct xdr_stream *xdr,
2863 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002864{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002865 struct compound_hdr hdr = {
2866 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2867 };
Fred Isamandae100c2011-07-30 20:52:37 -04002868 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002869
Chuck Lever9f06c712010-12-14 14:59:18 +00002870 encode_compound_hdr(xdr, req, &hdr);
2871 encode_sequence(xdr, &args->la_seq_args, &hdr);
2872 encode_putrootfh(xdr, &hdr);
2873 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002874 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002875}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002876
2877/*
2878 * a RECLAIM_COMPLETE request
2879 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002880static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2881 struct xdr_stream *xdr,
2882 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002883{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002884 struct compound_hdr hdr = {
2885 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2886 };
2887
Chuck Lever9f06c712010-12-14 14:59:18 +00002888 encode_compound_hdr(xdr, req, &hdr);
2889 encode_sequence(xdr, &args->seq_args, &hdr);
2890 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002891 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002892}
2893
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002894/*
2895 * Encode GETDEVICEINFO request
2896 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002897static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2898 struct xdr_stream *xdr,
2899 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002900{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002901 struct compound_hdr hdr = {
2902 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2903 };
2904
Chuck Lever9f06c712010-12-14 14:59:18 +00002905 encode_compound_hdr(xdr, req, &hdr);
2906 encode_sequence(xdr, &args->seq_args, &hdr);
2907 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002908
2909 /* set up reply kvec. Subtract notification bitmap max size (2)
2910 * so that notification bitmap is put in xdr_buf tail */
2911 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2912 args->pdev->pages, args->pdev->pgbase,
2913 args->pdev->pglen);
2914
2915 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002916}
2917
2918/*
2919 * Encode LAYOUTGET request
2920 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002921static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2922 struct xdr_stream *xdr,
2923 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002924{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002925 struct compound_hdr hdr = {
2926 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2927 };
2928
Chuck Lever9f06c712010-12-14 14:59:18 +00002929 encode_compound_hdr(xdr, req, &hdr);
2930 encode_sequence(xdr, &args->seq_args, &hdr);
2931 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2932 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002933
2934 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2935 args->layout.pages, 0, args->layout.pglen);
2936
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002937 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002938}
Andy Adamson863a3c62011-03-23 13:27:54 +00002939
2940/*
2941 * Encode LAYOUTCOMMIT request
2942 */
Benny Halevycbe82602011-05-22 19:52:37 +03002943static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2944 struct xdr_stream *xdr,
2945 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002946{
Benny Halevyac7db722011-05-22 19:53:48 +03002947 struct nfs4_layoutcommit_data *data =
2948 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002949 struct compound_hdr hdr = {
2950 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2951 };
2952
2953 encode_compound_hdr(xdr, req, &hdr);
2954 encode_sequence(xdr, &args->seq_args, &hdr);
2955 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002956 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002957 encode_getfattr(xdr, args->bitmask, &hdr);
2958 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002959}
2960
2961/*
2962 * Encode LAYOUTRETURN request
2963 */
2964static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2965 struct xdr_stream *xdr,
2966 struct nfs4_layoutreturn_args *args)
2967{
2968 struct compound_hdr hdr = {
2969 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2970 };
2971
2972 encode_compound_hdr(xdr, req, &hdr);
2973 encode_sequence(xdr, &args->seq_args, &hdr);
2974 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2975 encode_layoutreturn(xdr, args, &hdr);
2976 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002977}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002978
2979/*
2980 * Encode SECINFO_NO_NAME request
2981 */
2982static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2983 struct xdr_stream *xdr,
2984 struct nfs41_secinfo_no_name_args *args)
2985{
2986 struct compound_hdr hdr = {
2987 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2988 };
2989
2990 encode_compound_hdr(xdr, req, &hdr);
2991 encode_sequence(xdr, &args->seq_args, &hdr);
2992 encode_putrootfh(xdr, &hdr);
2993 encode_secinfo_no_name(xdr, args, &hdr);
2994 encode_nops(&hdr);
2995 return 0;
2996}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002997
2998/*
2999 * Encode TEST_STATEID request
3000 */
3001static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3002 struct xdr_stream *xdr,
3003 struct nfs41_test_stateid_args *args)
3004{
3005 struct compound_hdr hdr = {
3006 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3007 };
3008
3009 encode_compound_hdr(xdr, req, &hdr);
3010 encode_sequence(xdr, &args->seq_args, &hdr);
3011 encode_test_stateid(xdr, args, &hdr);
3012 encode_nops(&hdr);
3013}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003014
3015/*
3016 * Encode FREE_STATEID request
3017 */
3018static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3019 struct xdr_stream *xdr,
3020 struct nfs41_free_stateid_args *args)
3021{
3022 struct compound_hdr hdr = {
3023 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3024 };
3025
3026 encode_compound_hdr(xdr, req, &hdr);
3027 encode_sequence(xdr, &args->seq_args, &hdr);
3028 encode_free_stateid(xdr, args, &hdr);
3029 encode_nops(&hdr);
3030}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003031#endif /* CONFIG_NFS_V4_1 */
3032
Benny Halevy686841b2009-08-14 17:19:48 +03003033static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3034{
3035 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3036 "Remaining buffer length is %tu words.\n",
3037 func, xdr->end - xdr->p);
3038}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039
Trond Myklebust683b57b2006-06-09 09:34:22 -04003040static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041{
Al Viro8687b632006-10-19 23:28:48 -07003042 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043
Benny Halevyc0eae662009-08-14 17:20:14 +03003044 p = xdr_inline_decode(xdr, 4);
3045 if (unlikely(!p))
3046 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003047 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003048 p = xdr_inline_decode(xdr, *len);
3049 if (unlikely(!p))
3050 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 *string = (char *)p;
3052 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003053out_overflow:
3054 print_overflow_msg(__func__, xdr);
3055 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056}
3057
3058static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3059{
Al Viro8687b632006-10-19 23:28:48 -07003060 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061
Benny Halevyc0eae662009-08-14 17:20:14 +03003062 p = xdr_inline_decode(xdr, 8);
3063 if (unlikely(!p))
3064 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003065 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003066 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003067
Benny Halevyc0eae662009-08-14 17:20:14 +03003068 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3069 if (unlikely(!p))
3070 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 hdr->tag = (char *)p;
3072 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003073 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003074 if (unlikely(hdr->nops < 1))
3075 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003077out_overflow:
3078 print_overflow_msg(__func__, xdr);
3079 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080}
3081
Trond Myklebustc7848f62013-12-04 17:39:23 -05003082static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3083 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084{
Al Viro8687b632006-10-19 23:28:48 -07003085 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 uint32_t opnum;
3087 int32_t nfserr;
3088
Benny Halevyc0eae662009-08-14 17:20:14 +03003089 p = xdr_inline_decode(xdr, 8);
3090 if (unlikely(!p))
3091 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003092 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003093 if (unlikely(opnum != expected))
3094 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003095 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003096 if (nfserr == NFS_OK)
3097 *nfs_retval = 0;
3098 else
3099 *nfs_retval = nfs4_stat_to_errno(nfserr);
3100 return true;
3101out_bad_operation:
3102 dprintk("nfs: Server returned operation"
3103 " %d but we issued a request for %d\n",
3104 opnum, expected);
3105 *nfs_retval = -EREMOTEIO;
3106 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003107out_overflow:
3108 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003109 *nfs_retval = -EIO;
3110 return false;
3111}
3112
3113static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3114{
3115 int retval;
3116
3117 __decode_op_hdr(xdr, expected, &retval);
3118 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119}
3120
3121/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003122static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123{
Al Viro8687b632006-10-19 23:28:48 -07003124 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003125 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 char *str;
3127
Benny Halevyc0eae662009-08-14 17:20:14 +03003128 p = xdr_inline_decode(xdr, 12);
3129 if (likely(p))
3130 return decode_opaque_inline(xdr, &strlen, &str);
3131 print_overflow_msg(__func__, xdr);
3132 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133}
3134
3135static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3136{
Al Viro8687b632006-10-19 23:28:48 -07003137 uint32_t bmlen;
3138 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139
Benny Halevyc0eae662009-08-14 17:20:14 +03003140 p = xdr_inline_decode(xdr, 4);
3141 if (unlikely(!p))
3142 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003143 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144
Fred Isamandae100c2011-07-30 20:52:37 -04003145 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003146 p = xdr_inline_decode(xdr, (bmlen << 2));
3147 if (unlikely(!p))
3148 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003150 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003151 if (bmlen > 1) {
3152 bitmap[1] = be32_to_cpup(p++);
3153 if (bmlen > 2)
3154 bitmap[2] = be32_to_cpup(p);
3155 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 }
3157 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003158out_overflow:
3159 print_overflow_msg(__func__, xdr);
3160 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161}
3162
Trond Myklebust256e48b2012-06-21 11:18:13 -04003163static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164{
Al Viro8687b632006-10-19 23:28:48 -07003165 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166
Benny Halevyc0eae662009-08-14 17:20:14 +03003167 p = xdr_inline_decode(xdr, 4);
3168 if (unlikely(!p))
3169 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003170 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003171 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003173out_overflow:
3174 print_overflow_msg(__func__, xdr);
3175 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176}
3177
3178static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3179{
3180 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003181 int ret;
3182 ret = decode_attr_bitmap(xdr, bitmask);
3183 if (unlikely(ret < 0))
3184 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3186 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003187 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3188 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3189 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 return 0;
3191}
3192
3193static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3194{
Al Viro8687b632006-10-19 23:28:48 -07003195 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003196 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197
3198 *type = 0;
3199 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3200 return -EIO;
3201 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003202 p = xdr_inline_decode(xdr, 4);
3203 if (unlikely(!p))
3204 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003205 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003207 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 return -EIO;
3209 }
3210 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003211 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003213 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003214 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003215out_overflow:
3216 print_overflow_msg(__func__, xdr);
3217 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218}
3219
Chuck Lever264e6352012-03-01 17:02:05 -05003220static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3221 uint32_t *bitmap, uint32_t *type)
3222{
3223 __be32 *p;
3224
3225 *type = 0;
3226 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3227 return -EIO;
3228 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3229 p = xdr_inline_decode(xdr, 4);
3230 if (unlikely(!p))
3231 goto out_overflow;
3232 *type = be32_to_cpup(p);
3233 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3234 }
3235 dprintk("%s: expire type=0x%x\n", __func__, *type);
3236 return 0;
3237out_overflow:
3238 print_overflow_msg(__func__, xdr);
3239 return -EIO;
3240}
3241
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3243{
Al Viro8687b632006-10-19 23:28:48 -07003244 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003245 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246
3247 *change = 0;
3248 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3249 return -EIO;
3250 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003251 p = xdr_inline_decode(xdr, 8);
3252 if (unlikely(!p))
3253 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003254 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003256 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003258 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003260 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003261out_overflow:
3262 print_overflow_msg(__func__, xdr);
3263 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264}
3265
3266static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3267{
Al Viro8687b632006-10-19 23:28:48 -07003268 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003269 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270
3271 *size = 0;
3272 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3273 return -EIO;
3274 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003275 p = xdr_inline_decode(xdr, 8);
3276 if (unlikely(!p))
3277 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003278 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003280 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003282 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003283 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003284out_overflow:
3285 print_overflow_msg(__func__, xdr);
3286 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287}
3288
3289static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3290{
Al Viro8687b632006-10-19 23:28:48 -07003291 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292
3293 *res = 0;
3294 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3295 return -EIO;
3296 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003297 p = xdr_inline_decode(xdr, 4);
3298 if (unlikely(!p))
3299 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003300 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3302 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003303 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003305out_overflow:
3306 print_overflow_msg(__func__, xdr);
3307 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308}
3309
3310static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3311{
Al Viro8687b632006-10-19 23:28:48 -07003312 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313
3314 *res = 0;
3315 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3316 return -EIO;
3317 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003318 p = xdr_inline_decode(xdr, 4);
3319 if (unlikely(!p))
3320 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003321 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3323 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003324 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003326out_overflow:
3327 print_overflow_msg(__func__, xdr);
3328 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329}
3330
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003331static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332{
Al Viro8687b632006-10-19 23:28:48 -07003333 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003334 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335
3336 fsid->major = 0;
3337 fsid->minor = 0;
3338 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3339 return -EIO;
3340 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003341 p = xdr_inline_decode(xdr, 16);
3342 if (unlikely(!p))
3343 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003344 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003345 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003347 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003349 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 (unsigned long long)fsid->major,
3351 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003352 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003353out_overflow:
3354 print_overflow_msg(__func__, xdr);
3355 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356}
3357
3358static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3359{
Al Viro8687b632006-10-19 23:28:48 -07003360 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361
3362 *res = 60;
3363 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3364 return -EIO;
3365 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003366 p = xdr_inline_decode(xdr, 4);
3367 if (unlikely(!p))
3368 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003369 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3371 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003372 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003374out_overflow:
3375 print_overflow_msg(__func__, xdr);
3376 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377}
3378
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003379static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003380{
3381 __be32 *p;
3382
3383 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3384 return -EIO;
3385 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3386 p = xdr_inline_decode(xdr, 4);
3387 if (unlikely(!p))
3388 goto out_overflow;
3389 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003390 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003391 }
3392 return 0;
3393out_overflow:
3394 print_overflow_msg(__func__, xdr);
3395 return -EIO;
3396}
3397
Kinglong Mee8c612822015-08-26 21:12:58 +08003398static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3399 uint32_t *bitmap, uint32_t *bitmask)
3400{
3401 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3402 int ret;
3403 ret = decode_attr_bitmap(xdr, bitmask);
3404 if (unlikely(ret < 0))
3405 return ret;
3406 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3407 } else
3408 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3409 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3410 bitmask[0], bitmask[1], bitmask[2]);
3411 return 0;
3412}
3413
Bryan Schumakerae42c702010-10-21 16:33:17 -04003414static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3415{
3416 __be32 *p;
3417 int len;
3418
Trond Myklebust7ad07352010-10-23 15:34:20 -04003419 if (fh != NULL)
3420 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003421
3422 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3423 return -EIO;
3424 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3425 p = xdr_inline_decode(xdr, 4);
3426 if (unlikely(!p))
3427 goto out_overflow;
3428 len = be32_to_cpup(p);
3429 if (len > NFS4_FHSIZE)
3430 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003431 p = xdr_inline_decode(xdr, len);
3432 if (unlikely(!p))
3433 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003434 if (fh != NULL) {
3435 memcpy(fh->data, p, len);
3436 fh->size = len;
3437 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003438 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3439 }
3440 return 0;
3441out_overflow:
3442 print_overflow_msg(__func__, xdr);
3443 return -EIO;
3444}
3445
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3447{
Al Viro8687b632006-10-19 23:28:48 -07003448 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003450 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3452 return -EIO;
3453 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003454 p = xdr_inline_decode(xdr, 4);
3455 if (unlikely(!p))
3456 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003457 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3459 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003460 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003462out_overflow:
3463 print_overflow_msg(__func__, xdr);
3464 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465}
3466
3467static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3468{
Al Viro8687b632006-10-19 23:28:48 -07003469 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003470 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471
3472 *fileid = 0;
3473 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3474 return -EIO;
3475 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003476 p = xdr_inline_decode(xdr, 8);
3477 if (unlikely(!p))
3478 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003479 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003481 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003483 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003484 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003485out_overflow:
3486 print_overflow_msg(__func__, xdr);
3487 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488}
3489
Manoj Naik99baf622006-06-09 09:34:24 -04003490static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3491{
Al Viro8687b632006-10-19 23:28:48 -07003492 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003493 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003494
3495 *fileid = 0;
3496 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3497 return -EIO;
3498 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003499 p = xdr_inline_decode(xdr, 8);
3500 if (unlikely(!p))
3501 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003502 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003503 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003504 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003505 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003506 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003507 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003508out_overflow:
3509 print_overflow_msg(__func__, xdr);
3510 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003511}
3512
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3514{
Al Viro8687b632006-10-19 23:28:48 -07003515 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 int status = 0;
3517
3518 *res = 0;
3519 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3520 return -EIO;
3521 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003522 p = xdr_inline_decode(xdr, 8);
3523 if (unlikely(!p))
3524 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003525 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3527 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003528 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003530out_overflow:
3531 print_overflow_msg(__func__, xdr);
3532 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533}
3534
3535static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3536{
Al Viro8687b632006-10-19 23:28:48 -07003537 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538 int status = 0;
3539
3540 *res = 0;
3541 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3542 return -EIO;
3543 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003544 p = xdr_inline_decode(xdr, 8);
3545 if (unlikely(!p))
3546 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003547 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3549 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003550 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003552out_overflow:
3553 print_overflow_msg(__func__, xdr);
3554 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555}
3556
3557static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3558{
Al Viro8687b632006-10-19 23:28:48 -07003559 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560 int status = 0;
3561
3562 *res = 0;
3563 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3564 return -EIO;
3565 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003566 p = xdr_inline_decode(xdr, 8);
3567 if (unlikely(!p))
3568 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003569 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3571 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003572 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003574out_overflow:
3575 print_overflow_msg(__func__, xdr);
3576 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577}
3578
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003579static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3580{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003581 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003582 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003583 int status = 0;
3584
Benny Halevyc0eae662009-08-14 17:20:14 +03003585 p = xdr_inline_decode(xdr, 4);
3586 if (unlikely(!p))
3587 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003588 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003589 if (n == 0)
3590 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003591 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003592 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3593 dprintk("cannot parse %d components in path\n", n);
3594 goto out_eio;
3595 }
3596 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003597 struct nfs4_string *component = &path->components[path->ncomponents];
3598 status = decode_opaque_inline(xdr, &component->len, &component->data);
3599 if (unlikely(status != 0))
3600 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003601 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003602 pr_cont("%s%.*s ",
3603 (path->ncomponents != n ? "/ " : ""),
3604 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003605 }
3606out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003607 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003608root_path:
3609/* a root pathname is sent as a zero component4 */
3610 path->ncomponents = 1;
3611 path->components[0].len=0;
3612 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003613 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003614 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003615out_eio:
3616 dprintk(" status %d", status);
3617 status = -EIO;
3618 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003619out_overflow:
3620 print_overflow_msg(__func__, xdr);
3621 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003622}
3623
3624static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003625{
3626 int n;
Al Viro8687b632006-10-19 23:28:48 -07003627 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003628 int status = -EIO;
3629
3630 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3631 goto out;
3632 status = 0;
3633 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3634 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003635 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003636 status = -EIO;
3637 /* Ignore borken servers that return unrequested attrs */
3638 if (unlikely(res == NULL))
3639 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003640 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003641 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003642 if (unlikely(status != 0))
3643 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003644 p = xdr_inline_decode(xdr, 4);
3645 if (unlikely(!p))
3646 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003647 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003648 if (n <= 0)
3649 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003650 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003651 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003652 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003653
Trond Myklebust809b4262013-03-27 11:54:45 -04003654 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3655 break;
3656 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003657 p = xdr_inline_decode(xdr, 4);
3658 if (unlikely(!p))
3659 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003660 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003661
Chuck Lever02a29762012-03-01 17:00:31 -05003662 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003663 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3664 struct nfs4_string *server;
3665
3666 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003667 unsigned int i;
3668 dprintk("%s: using first %u of %u servers "
3669 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003670 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003671 NFS4_FS_LOCATION_MAXSERVERS,
3672 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003673 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003674 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003675 char *data;
3676 status = decode_opaque_inline(xdr, &len, &data);
3677 if (unlikely(status != 0))
3678 goto out_eio;
3679 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003680 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003681 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003682 server = &loc->servers[loc->nservers];
3683 status = decode_opaque_inline(xdr, &server->len, &server->data);
3684 if (unlikely(status != 0))
3685 goto out_eio;
3686 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003687 }
3688 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003689 if (unlikely(status != 0))
3690 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003691 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003692 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003693 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003694out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003695 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003696 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003697out_overflow:
3698 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003699out_eio:
3700 status = -EIO;
3701 goto out;
3702}
3703
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3705{
Al Viro8687b632006-10-19 23:28:48 -07003706 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 int status = 0;
3708
3709 *res = 0;
3710 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3711 return -EIO;
3712 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003713 p = xdr_inline_decode(xdr, 8);
3714 if (unlikely(!p))
3715 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003716 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3718 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003719 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003721out_overflow:
3722 print_overflow_msg(__func__, xdr);
3723 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724}
3725
3726static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3727{
Al Viro8687b632006-10-19 23:28:48 -07003728 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729 int status = 0;
3730
3731 *maxlink = 1;
3732 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3733 return -EIO;
3734 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003735 p = xdr_inline_decode(xdr, 4);
3736 if (unlikely(!p))
3737 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003738 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3740 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003741 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003743out_overflow:
3744 print_overflow_msg(__func__, xdr);
3745 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746}
3747
3748static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3749{
Al Viro8687b632006-10-19 23:28:48 -07003750 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751 int status = 0;
3752
3753 *maxname = 1024;
3754 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3755 return -EIO;
3756 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003757 p = xdr_inline_decode(xdr, 4);
3758 if (unlikely(!p))
3759 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003760 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3762 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003763 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003765out_overflow:
3766 print_overflow_msg(__func__, xdr);
3767 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768}
3769
3770static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3771{
Al Viro8687b632006-10-19 23:28:48 -07003772 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773 int status = 0;
3774
3775 *res = 1024;
3776 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3777 return -EIO;
3778 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3779 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003780 p = xdr_inline_decode(xdr, 8);
3781 if (unlikely(!p))
3782 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003783 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 if (maxread > 0x7FFFFFFF)
3785 maxread = 0x7FFFFFFF;
3786 *res = (uint32_t)maxread;
3787 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3788 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003789 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003791out_overflow:
3792 print_overflow_msg(__func__, xdr);
3793 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794}
3795
3796static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3797{
Al Viro8687b632006-10-19 23:28:48 -07003798 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799 int status = 0;
3800
3801 *res = 1024;
3802 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3803 return -EIO;
3804 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3805 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003806 p = xdr_inline_decode(xdr, 8);
3807 if (unlikely(!p))
3808 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003809 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 if (maxwrite > 0x7FFFFFFF)
3811 maxwrite = 0x7FFFFFFF;
3812 *res = (uint32_t)maxwrite;
3813 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3814 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003815 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003817out_overflow:
3818 print_overflow_msg(__func__, xdr);
3819 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820}
3821
Trond Myklebustbca79472009-03-11 14:10:26 -04003822static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823{
Trond Myklebustbca79472009-03-11 14:10:26 -04003824 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003825 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003826 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827
3828 *mode = 0;
3829 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3830 return -EIO;
3831 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003832 p = xdr_inline_decode(xdr, 4);
3833 if (unlikely(!p))
3834 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003835 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003836 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003838 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003840 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003841 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003842out_overflow:
3843 print_overflow_msg(__func__, xdr);
3844 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845}
3846
3847static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3848{
Al Viro8687b632006-10-19 23:28:48 -07003849 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003850 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851
3852 *nlink = 1;
3853 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3854 return -EIO;
3855 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003856 p = xdr_inline_decode(xdr, 4);
3857 if (unlikely(!p))
3858 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003859 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003861 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003863 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003864 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003865out_overflow:
3866 print_overflow_msg(__func__, xdr);
3867 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868}
3869
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003870static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003871 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003872 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873{
Al Viro8687b632006-10-19 23:28:48 -07003874 uint32_t len;
3875 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003876 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877
Eric W. Biedermane5782072013-02-01 14:22:02 -08003878 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3880 return -EIO;
3881 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003882 p = xdr_inline_decode(xdr, 4);
3883 if (unlikely(!p))
3884 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003885 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003886 p = xdr_inline_decode(xdr, len);
3887 if (unlikely(!p))
3888 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003889 if (owner_name != NULL) {
3890 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3891 if (owner_name->data != NULL) {
3892 owner_name->len = len;
3893 ret = NFS_ATTR_FATTR_OWNER_NAME;
3894 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003895 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003896 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003897 ret = NFS_ATTR_FATTR_OWNER;
3898 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003900 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003902 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003903 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3905 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003906 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003907 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003908out_overflow:
3909 print_overflow_msg(__func__, xdr);
3910 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911}
3912
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003913static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003914 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003915 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916{
Al Viro8687b632006-10-19 23:28:48 -07003917 uint32_t len;
3918 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003919 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920
Eric W. Biedermane5782072013-02-01 14:22:02 -08003921 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3923 return -EIO;
3924 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003925 p = xdr_inline_decode(xdr, 4);
3926 if (unlikely(!p))
3927 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003928 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003929 p = xdr_inline_decode(xdr, len);
3930 if (unlikely(!p))
3931 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003932 if (group_name != NULL) {
3933 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3934 if (group_name->data != NULL) {
3935 group_name->len = len;
3936 ret = NFS_ATTR_FATTR_GROUP_NAME;
3937 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003938 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003939 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003940 ret = NFS_ATTR_FATTR_GROUP;
3941 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003943 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003945 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003946 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3948 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003949 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003950 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003951out_overflow:
3952 print_overflow_msg(__func__, xdr);
3953 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954}
3955
3956static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3957{
Al Viro8687b632006-10-19 23:28:48 -07003958 uint32_t major = 0, minor = 0;
3959 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003960 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961
3962 *rdev = MKDEV(0,0);
3963 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3964 return -EIO;
3965 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3966 dev_t tmp;
3967
Benny Halevyc0eae662009-08-14 17:20:14 +03003968 p = xdr_inline_decode(xdr, 8);
3969 if (unlikely(!p))
3970 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003971 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003972 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 tmp = MKDEV(major, minor);
3974 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3975 *rdev = tmp;
3976 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003977 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003979 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003980 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003981out_overflow:
3982 print_overflow_msg(__func__, xdr);
3983 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984}
3985
3986static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3987{
Al Viro8687b632006-10-19 23:28:48 -07003988 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 int status = 0;
3990
3991 *res = 0;
3992 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3993 return -EIO;
3994 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003995 p = xdr_inline_decode(xdr, 8);
3996 if (unlikely(!p))
3997 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003998 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4000 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004001 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004003out_overflow:
4004 print_overflow_msg(__func__, xdr);
4005 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006}
4007
4008static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4009{
Al Viro8687b632006-10-19 23:28:48 -07004010 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 int status = 0;
4012
4013 *res = 0;
4014 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4015 return -EIO;
4016 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004017 p = xdr_inline_decode(xdr, 8);
4018 if (unlikely(!p))
4019 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004020 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4022 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004023 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004025out_overflow:
4026 print_overflow_msg(__func__, xdr);
4027 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028}
4029
4030static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4031{
Al Viro8687b632006-10-19 23:28:48 -07004032 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 int status = 0;
4034
4035 *res = 0;
4036 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4037 return -EIO;
4038 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004039 p = xdr_inline_decode(xdr, 8);
4040 if (unlikely(!p))
4041 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004042 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4044 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004045 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004047out_overflow:
4048 print_overflow_msg(__func__, xdr);
4049 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050}
4051
4052static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4053{
Al Viro8687b632006-10-19 23:28:48 -07004054 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004055 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056
4057 *used = 0;
4058 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4059 return -EIO;
4060 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004061 p = xdr_inline_decode(xdr, 8);
4062 if (unlikely(!p))
4063 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004064 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004066 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004068 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004070 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004071out_overflow:
4072 print_overflow_msg(__func__, xdr);
4073 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074}
4075
4076static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4077{
Al Viro8687b632006-10-19 23:28:48 -07004078 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079 uint64_t sec;
4080 uint32_t nsec;
4081
Benny Halevyc0eae662009-08-14 17:20:14 +03004082 p = xdr_inline_decode(xdr, 12);
4083 if (unlikely(!p))
4084 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004085 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004086 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 time->tv_sec = (time_t)sec;
4088 time->tv_nsec = (long)nsec;
4089 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004090out_overflow:
4091 print_overflow_msg(__func__, xdr);
4092 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093}
4094
4095static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4096{
4097 int status = 0;
4098
4099 time->tv_sec = 0;
4100 time->tv_nsec = 0;
4101 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4102 return -EIO;
4103 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4104 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004105 if (status == 0)
4106 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4108 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004109 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110 return status;
4111}
4112
4113static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4114{
4115 int status = 0;
4116
4117 time->tv_sec = 0;
4118 time->tv_nsec = 0;
4119 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4120 return -EIO;
4121 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4122 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004123 if (status == 0)
4124 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4126 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004127 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128 return status;
4129}
4130
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004131static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4132 struct timespec *time)
4133{
4134 int status = 0;
4135
4136 time->tv_sec = 0;
4137 time->tv_nsec = 0;
4138 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4139 return -EIO;
4140 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4141 status = decode_attr_time(xdr, time);
4142 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4143 }
4144 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4145 (long)time->tv_nsec);
4146 return status;
4147}
4148
David Quigleyaa9c2662013-05-22 12:50:44 -04004149static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4150 struct nfs4_label *label)
4151{
4152 uint32_t pi = 0;
4153 uint32_t lfs = 0;
4154 __u32 len;
4155 __be32 *p;
4156 int status = 0;
4157
4158 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4159 return -EIO;
4160 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4161 p = xdr_inline_decode(xdr, 4);
4162 if (unlikely(!p))
4163 goto out_overflow;
4164 lfs = be32_to_cpup(p++);
4165 p = xdr_inline_decode(xdr, 4);
4166 if (unlikely(!p))
4167 goto out_overflow;
4168 pi = be32_to_cpup(p++);
4169 p = xdr_inline_decode(xdr, 4);
4170 if (unlikely(!p))
4171 goto out_overflow;
4172 len = be32_to_cpup(p++);
4173 p = xdr_inline_decode(xdr, len);
4174 if (unlikely(!p))
4175 goto out_overflow;
4176 if (len < NFS4_MAXLABELLEN) {
4177 if (label) {
4178 memcpy(label->label, p, len);
4179 label->len = len;
4180 label->pi = pi;
4181 label->lfs = lfs;
4182 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4183 }
4184 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4185 } else
4186 printk(KERN_WARNING "%s: label too long (%u)!\n",
4187 __func__, len);
4188 }
4189 if (label && label->label)
4190 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4191 (char *)label->label, label->len, label->pi, label->lfs);
4192 return status;
4193
4194out_overflow:
4195 print_overflow_msg(__func__, xdr);
4196 return -EIO;
4197}
4198
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4200{
4201 int status = 0;
4202
4203 time->tv_sec = 0;
4204 time->tv_nsec = 0;
4205 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4206 return -EIO;
4207 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4208 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004209 if (status == 0)
4210 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4212 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004213 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214 return status;
4215}
4216
Trond Myklebust256e48b2012-06-21 11:18:13 -04004217static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218{
4219 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004220 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221
4222 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004223 dprintk("%s: server returned incorrect attribute length: "
4224 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004225 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226 attrwords << 2,
4227 (attrwords < nwords) ? '<' : '>',
4228 nwords << 2);
4229 return -EIO;
4230 }
4231 return 0;
4232}
4233
4234static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4235{
Al Viro8687b632006-10-19 23:28:48 -07004236 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004237
Benny Halevyc0eae662009-08-14 17:20:14 +03004238 p = xdr_inline_decode(xdr, 20);
4239 if (unlikely(!p))
4240 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004241 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004242 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004243 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004244 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004245out_overflow:
4246 print_overflow_msg(__func__, xdr);
4247 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248}
4249
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004250static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004251{
Al Viro8687b632006-10-19 23:28:48 -07004252 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253 uint32_t supp, acc;
4254 int status;
4255
4256 status = decode_op_hdr(xdr, OP_ACCESS);
4257 if (status)
4258 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004259 p = xdr_inline_decode(xdr, 8);
4260 if (unlikely(!p))
4261 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004262 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004263 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004264 *supported = supp;
4265 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004266 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004267out_overflow:
4268 print_overflow_msg(__func__, xdr);
4269 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270}
4271
Benny Halevy07d30432009-08-14 17:19:52 +03004272static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273{
Al Viro8687b632006-10-19 23:28:48 -07004274 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004275
4276 p = xdr_inline_decode(xdr, len);
4277 if (likely(p)) {
4278 memcpy(buf, p, len);
4279 return 0;
4280 }
4281 print_overflow_msg(__func__, xdr);
4282 return -EIO;
4283}
4284
4285static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4286{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004287 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288}
4289
Trond Myklebust93b717f2016-05-16 17:42:43 -04004290static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4291{
4292 stateid->type = NFS4_OPEN_STATEID_TYPE;
4293 return decode_stateid(xdr, stateid);
4294}
4295
4296static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4297{
4298 stateid->type = NFS4_LOCK_STATEID_TYPE;
4299 return decode_stateid(xdr, stateid);
4300}
4301
4302static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4303{
4304 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4305 return decode_stateid(xdr, stateid);
4306}
4307
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4309{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310 int status;
4311
4312 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004313 if (status != -EIO)
4314 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004315 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04004316 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004317 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318}
4319
Benny Halevydb942bb2009-08-14 17:19:56 +03004320static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4321{
Chuck Levercd937102012-03-02 17:14:31 -05004322 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323}
4324
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004325static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4326{
4327 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4328}
4329
Fred Isaman0b7c0152012-04-20 14:47:39 -04004330static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004331{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332 int status;
4333
4334 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004335 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004336 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004337 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338}
4339
4340static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4341{
Al Viro8687b632006-10-19 23:28:48 -07004342 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 uint32_t bmlen;
4344 int status;
4345
4346 status = decode_op_hdr(xdr, OP_CREATE);
4347 if (status)
4348 return status;
4349 if ((status = decode_change_info(xdr, cinfo)))
4350 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004351 p = xdr_inline_decode(xdr, 4);
4352 if (unlikely(!p))
4353 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004354 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004355 p = xdr_inline_decode(xdr, bmlen << 2);
4356 if (likely(p))
4357 return 0;
4358out_overflow:
4359 print_overflow_msg(__func__, xdr);
4360 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361}
4362
4363static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4364{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004365 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004366 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367 int status;
4368
4369 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4370 goto xdr_error;
4371 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4372 goto xdr_error;
4373 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4374 goto xdr_error;
4375 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4376 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004377 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4378 &res->fh_expire_type)) != 0)
4379 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4381 goto xdr_error;
4382 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4383 goto xdr_error;
4384 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4385 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004386 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4387 res->exclcreat_bitmask)) != 0)
4388 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 status = verify_attr_len(xdr, savep, attrlen);
4390xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004391 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392 return status;
4393}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004394
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4396{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004397 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004398 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004400
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4402 goto xdr_error;
4403 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4404 goto xdr_error;
4405 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4406 goto xdr_error;
4407
4408 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4409 goto xdr_error;
4410 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4411 goto xdr_error;
4412 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4413 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004414
4415 status = -EIO;
4416 if (unlikely(bitmap[0]))
4417 goto xdr_error;
4418
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4420 goto xdr_error;
4421 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4422 goto xdr_error;
4423 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4424 goto xdr_error;
4425
4426 status = verify_attr_len(xdr, savep, attrlen);
4427xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004428 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429 return status;
4430}
4431
4432static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4433{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004434 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004435 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004437
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4439 goto xdr_error;
4440 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4441 goto xdr_error;
4442 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4443 goto xdr_error;
4444
4445 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4446 goto xdr_error;
4447 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4448 goto xdr_error;
4449
4450 status = verify_attr_len(xdr, savep, attrlen);
4451xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004452 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 return status;
4454}
4455
Andy Adamson88034c32012-05-23 05:02:34 -04004456static int decode_threshold_hint(struct xdr_stream *xdr,
4457 uint32_t *bitmap,
4458 uint64_t *res,
4459 uint32_t hint_bit)
4460{
4461 __be32 *p;
4462
4463 *res = 0;
4464 if (likely(bitmap[0] & hint_bit)) {
4465 p = xdr_inline_decode(xdr, 8);
4466 if (unlikely(!p))
4467 goto out_overflow;
4468 xdr_decode_hyper(p, res);
4469 }
4470 return 0;
4471out_overflow:
4472 print_overflow_msg(__func__, xdr);
4473 return -EIO;
4474}
4475
4476static int decode_first_threshold_item4(struct xdr_stream *xdr,
4477 struct nfs4_threshold *res)
4478{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004479 __be32 *p;
4480 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004481 uint32_t bitmap[3] = {0,}, attrlen;
4482 int status;
4483
4484 /* layout type */
4485 p = xdr_inline_decode(xdr, 4);
4486 if (unlikely(!p)) {
4487 print_overflow_msg(__func__, xdr);
4488 return -EIO;
4489 }
4490 res->l_type = be32_to_cpup(p);
4491
4492 /* thi_hintset bitmap */
4493 status = decode_attr_bitmap(xdr, bitmap);
4494 if (status < 0)
4495 goto xdr_error;
4496
4497 /* thi_hintlist length */
4498 status = decode_attr_length(xdr, &attrlen, &savep);
4499 if (status < 0)
4500 goto xdr_error;
4501 /* thi_hintlist */
4502 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4503 if (status < 0)
4504 goto xdr_error;
4505 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4506 if (status < 0)
4507 goto xdr_error;
4508 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4509 THRESHOLD_RD_IO);
4510 if (status < 0)
4511 goto xdr_error;
4512 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4513 THRESHOLD_WR_IO);
4514 if (status < 0)
4515 goto xdr_error;
4516
4517 status = verify_attr_len(xdr, savep, attrlen);
4518 res->bm = bitmap[0];
4519
4520 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4521 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4522 res->wr_io_sz);
4523xdr_error:
4524 dprintk("%s ret=%d!\n", __func__, status);
4525 return status;
4526}
4527
4528/*
4529 * Thresholds on pNFS direct I/O vrs MDS I/O
4530 */
4531static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4532 uint32_t *bitmap,
4533 struct nfs4_threshold *res)
4534{
4535 __be32 *p;
4536 int status = 0;
4537 uint32_t num;
4538
4539 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4540 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004541 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004542 /* Did the server return an unrequested attribute? */
4543 if (unlikely(res == NULL))
4544 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004545 p = xdr_inline_decode(xdr, 4);
4546 if (unlikely(!p))
4547 goto out_overflow;
4548 num = be32_to_cpup(p);
4549 if (num == 0)
4550 return 0;
4551 if (num > 1)
4552 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4553 "drivers per filesystem not supported\n",
4554 __func__);
4555
4556 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004557 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004558 }
4559 return status;
4560out_overflow:
4561 print_overflow_msg(__func__, xdr);
4562 return -EIO;
4563}
4564
Bryan Schumakerae42c702010-10-21 16:33:17 -04004565static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4566 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004567 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004568 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004569{
Trond Myklebustbca79472009-03-11 14:10:26 -04004570 int status;
4571 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004572 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004573 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004575 status = decode_attr_type(xdr, bitmap, &type);
4576 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004578 fattr->mode = 0;
4579 if (status != 0) {
4580 fattr->mode |= nfs_type2fmt[type];
4581 fattr->valid |= status;
4582 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004583
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004584 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4585 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004587 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004588
4589 status = decode_attr_size(xdr, bitmap, &fattr->size);
4590 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004592 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004593
4594 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4595 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004597 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004598
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004599 err = 0;
4600 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004601 if (status < 0)
4602 goto xdr_error;
4603
4604 status = decode_attr_filehandle(xdr, bitmap, fh);
4605 if (status < 0)
4606 goto xdr_error;
4607
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004608 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4609 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004611 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004612
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004613 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004614 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004615 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004616 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004617
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004618 status = -EIO;
4619 if (unlikely(bitmap[0]))
4620 goto xdr_error;
4621
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004622 status = decode_attr_mode(xdr, bitmap, &fmode);
4623 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004625 if (status != 0) {
4626 fattr->mode |= fmode;
4627 fattr->valid |= status;
4628 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004629
4630 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4631 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004633 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004634
Trond Myklebust6926afd2012-01-07 13:22:46 -05004635 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004636 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004638 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004639
Trond Myklebust6926afd2012-01-07 13:22:46 -05004640 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004641 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004643 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004644
4645 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4646 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004648 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004649
4650 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4651 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004653 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004654
4655 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4656 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004658 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004659
4660 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4661 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004663 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004664
4665 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4666 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004667 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004668 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004669
Trond Myklebust28331a42011-04-27 13:47:52 -04004670 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004671 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004672 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004673 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004674
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004675 status = -EIO;
4676 if (unlikely(bitmap[1]))
4677 goto xdr_error;
4678
Andy Adamson88034c32012-05-23 05:02:34 -04004679 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4680 if (status < 0)
4681 goto xdr_error;
4682
David Quigleyaa9c2662013-05-22 12:50:44 -04004683 if (label) {
4684 status = decode_attr_security_label(xdr, bitmap, label);
4685 if (status < 0)
4686 goto xdr_error;
4687 fattr->valid |= status;
4688 }
4689
Bryan Schumakerae42c702010-10-21 16:33:17 -04004690xdr_error:
4691 dprintk("%s: xdr returned %d\n", __func__, -status);
4692 return status;
4693}
4694
4695static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004696 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004697 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004698{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004699 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004700 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004701 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004702 int status;
4703
4704 status = decode_op_hdr(xdr, OP_GETATTR);
4705 if (status < 0)
4706 goto xdr_error;
4707
4708 status = decode_attr_bitmap(xdr, bitmap);
4709 if (status < 0)
4710 goto xdr_error;
4711
4712 status = decode_attr_length(xdr, &attrlen, &savep);
4713 if (status < 0)
4714 goto xdr_error;
4715
David Quigleyaa9c2662013-05-22 12:50:44 -04004716 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4717 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004718 if (status < 0)
4719 goto xdr_error;
4720
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004721 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004722xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004723 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724 return status;
4725}
4726
David Quigleyaa9c2662013-05-22 12:50:44 -04004727static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4728 struct nfs4_label *label, const struct nfs_server *server)
4729{
4730 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4731}
4732
Bryan Schumakerae42c702010-10-21 16:33:17 -04004733static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004734 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004735{
David Quigleyaa9c2662013-05-22 12:50:44 -04004736 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004737}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004738
Andy Adamson504913f2010-10-20 00:17:57 -04004739/*
Jeff Layton3132e492016-08-10 15:58:24 -04004740 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004741 */
Jeff Layton3132e492016-08-10 15:58:24 -04004742static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004743 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004744{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004745 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004746 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004747
4748 p = xdr_inline_decode(xdr, 4);
4749 if (unlikely(!p))
4750 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004751 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004752
4753 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004754 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004755 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004756
4757 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004758 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004759 if (unlikely(!p))
4760 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004761
4762 /* If we get too many, then just cap it at the max */
4763 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4764 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4765 __func__, fsinfo->nlayouttypes);
4766 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4767 }
4768
4769 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4770 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004771 return 0;
4772out_overflow:
4773 print_overflow_msg(__func__, xdr);
4774 return -EIO;
4775}
4776
4777/*
4778 * The type of file system exported.
4779 * Note we must ensure that layouttype is set in any non-error case.
4780 */
4781static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004782 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004783{
4784 int status = 0;
4785
4786 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4787 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4788 return -EIO;
4789 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004790 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004791 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004792 }
Andy Adamson504913f2010-10-20 00:17:57 -04004793 return status;
4794}
4795
Fred Isamandae100c2011-07-30 20:52:37 -04004796/*
4797 * The prefered block size for layout directed io
4798 */
4799static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4800 uint32_t *res)
4801{
4802 __be32 *p;
4803
4804 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4805 *res = 0;
4806 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4807 p = xdr_inline_decode(xdr, 4);
4808 if (unlikely(!p)) {
4809 print_overflow_msg(__func__, xdr);
4810 return -EIO;
4811 }
4812 *res = be32_to_cpup(p);
4813 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4814 }
4815 return 0;
4816}
4817
Peng Tao2a92ee92015-09-26 02:24:37 +08004818/*
4819 * The granularity of a CLONE operation.
4820 */
4821static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4822 uint32_t *res)
4823{
4824 __be32 *p;
4825
4826 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4827 *res = 0;
4828 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4829 p = xdr_inline_decode(xdr, 4);
4830 if (unlikely(!p)) {
4831 print_overflow_msg(__func__, xdr);
4832 return -EIO;
4833 }
4834 *res = be32_to_cpup(p);
4835 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4836 }
4837 return 0;
4838}
4839
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4841{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004842 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004843 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 int status;
4845
4846 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4847 goto xdr_error;
4848 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4849 goto xdr_error;
4850 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4851 goto xdr_error;
4852
4853 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4854
4855 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4856 goto xdr_error;
4857 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4858 goto xdr_error;
4859 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4860 goto xdr_error;
4861 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4862 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4863 goto xdr_error;
4864 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004865
4866 status = -EIO;
4867 if (unlikely(bitmap[0]))
4868 goto xdr_error;
4869
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004870 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4871 if (status != 0)
4872 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004873 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004874 if (status != 0)
4875 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004876
4877 status = -EIO;
4878 if (unlikely(bitmap[1]))
4879 goto xdr_error;
4880
Fred Isamandae100c2011-07-30 20:52:37 -04004881 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4882 if (status)
4883 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004884 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4885 if (status)
4886 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887
4888 status = verify_attr_len(xdr, savep, attrlen);
4889xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004890 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891 return status;
4892}
4893
4894static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4895{
Al Viro8687b632006-10-19 23:28:48 -07004896 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004897 uint32_t len;
4898 int status;
4899
Trond Myklebust99367812007-07-17 21:52:41 -04004900 /* Zero handle first to allow comparisons */
4901 memset(fh, 0, sizeof(*fh));
4902
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903 status = decode_op_hdr(xdr, OP_GETFH);
4904 if (status)
4905 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906
Benny Halevyc0eae662009-08-14 17:20:14 +03004907 p = xdr_inline_decode(xdr, 4);
4908 if (unlikely(!p))
4909 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004910 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004911 if (len > NFS4_FHSIZE)
4912 return -EIO;
4913 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004914 p = xdr_inline_decode(xdr, len);
4915 if (unlikely(!p))
4916 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004917 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004919out_overflow:
4920 print_overflow_msg(__func__, xdr);
4921 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922}
4923
4924static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4925{
4926 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004927
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928 status = decode_op_hdr(xdr, OP_LINK);
4929 if (status)
4930 return status;
4931 return decode_change_info(xdr, cinfo);
4932}
4933
4934/*
4935 * We create the owner, so we know a proper owner.id length is 4.
4936 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004937static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004938{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004939 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004940 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004941 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004943 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004944 if (unlikely(!p))
4945 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004946 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004947 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004948 type = be32_to_cpup(p++); /* 4 byte read */
4949 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004950 fl->fl_start = (loff_t)offset;
4951 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4952 if (length == ~(uint64_t)0)
4953 fl->fl_end = OFFSET_MAX;
4954 fl->fl_type = F_WRLCK;
4955 if (type & 1)
4956 fl->fl_type = F_RDLCK;
4957 fl->fl_pid = 0;
4958 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004959 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4960 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4961 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004962 if (likely(p))
4963 return -NFS4ERR_DENIED;
4964out_overflow:
4965 print_overflow_msg(__func__, xdr);
4966 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967}
4968
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004969static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971 int status;
4972
4973 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004974 if (status == -EIO)
4975 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04004977 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004978 if (unlikely(status))
4979 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004981 status = decode_lock_denied(xdr, NULL);
4982 if (res->open_seqid != NULL)
4983 nfs_increment_open_seqid(status, res->open_seqid);
4984 nfs_increment_lock_seqid(status, res->lock_seqid);
4985out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986 return status;
4987}
4988
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004989static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990{
4991 int status;
4992 status = decode_op_hdr(xdr, OP_LOCKT);
4993 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004994 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995 return status;
4996}
4997
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004998static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005000 int status;
5001
5002 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005003 if (status != -EIO)
5004 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005005 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005006 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007 return status;
5008}
5009
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005010static int decode_release_lockowner(struct xdr_stream *xdr)
5011{
5012 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5013}
5014
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015static int decode_lookup(struct xdr_stream *xdr)
5016{
5017 return decode_op_hdr(xdr, OP_LOOKUP);
5018}
5019
5020/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005021static int decode_space_limit(struct xdr_stream *xdr,
5022 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023{
Andy Adamson05d564f2008-12-23 16:06:15 -05005024 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005026 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005027
Benny Halevyc0eae662009-08-14 17:20:14 +03005028 p = xdr_inline_decode(xdr, 12);
5029 if (unlikely(!p))
5030 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005031 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005033 case NFS4_LIMIT_SIZE:
5034 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005035 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005036 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005037 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005038 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005039 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005040 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005041 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005042 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005043 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005044out_overflow:
5045 print_overflow_msg(__func__, xdr);
5046 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005047}
5048
Trond Myklebust6ae37332015-01-30 14:21:14 -05005049static int decode_rw_delegation(struct xdr_stream *xdr,
5050 uint32_t delegation_type,
5051 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005052{
Andy Adamson05d564f2008-12-23 16:06:15 -05005053 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005054 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005055
Trond Myklebust93b717f2016-05-16 17:42:43 -04005056 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005057 if (unlikely(status))
5058 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005059 p = xdr_inline_decode(xdr, 4);
5060 if (unlikely(!p))
5061 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005062 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005063
Linus Torvalds1da177e2005-04-16 15:20:36 -07005064 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005065 case NFS4_OPEN_DELEGATE_READ:
5066 res->delegation_type = FMODE_READ;
5067 break;
5068 case NFS4_OPEN_DELEGATE_WRITE:
5069 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005070 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071 return -EIO;
5072 }
David Howells7539bba2006-08-22 20:06:09 -04005073 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03005074out_overflow:
5075 print_overflow_msg(__func__, xdr);
5076 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077}
5078
Trond Myklebust6ae37332015-01-30 14:21:14 -05005079static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5080{
5081 __be32 *p;
5082 uint32_t why_no_delegation;
5083
5084 p = xdr_inline_decode(xdr, 4);
5085 if (unlikely(!p))
5086 goto out_overflow;
5087 why_no_delegation = be32_to_cpup(p);
5088 switch (why_no_delegation) {
5089 case WND4_CONTENTION:
5090 case WND4_RESOURCE:
5091 xdr_inline_decode(xdr, 4);
5092 /* Ignore for now */
5093 }
5094 return 0;
5095out_overflow:
5096 print_overflow_msg(__func__, xdr);
5097 return -EIO;
5098}
5099
5100static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5101{
5102 __be32 *p;
5103 uint32_t delegation_type;
5104
5105 p = xdr_inline_decode(xdr, 4);
5106 if (unlikely(!p))
5107 goto out_overflow;
5108 delegation_type = be32_to_cpup(p);
5109 res->delegation_type = 0;
5110 switch (delegation_type) {
5111 case NFS4_OPEN_DELEGATE_NONE:
5112 return 0;
5113 case NFS4_OPEN_DELEGATE_READ:
5114 case NFS4_OPEN_DELEGATE_WRITE:
5115 return decode_rw_delegation(xdr, delegation_type, res);
5116 case NFS4_OPEN_DELEGATE_NONE_EXT:
5117 return decode_no_delegation(xdr, res);
5118 }
5119 return -EIO;
5120out_overflow:
5121 print_overflow_msg(__func__, xdr);
5122 return -EIO;
5123}
5124
Linus Torvalds1da177e2005-04-16 15:20:36 -07005125static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5126{
Andy Adamson05d564f2008-12-23 16:06:15 -05005127 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005128 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005129 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130
Trond Myklebustc7848f62013-12-04 17:39:23 -05005131 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5132 return status;
5133 nfs_increment_open_seqid(status, res->seqid);
5134 if (status)
5135 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005136 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005137 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005138 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139
Andy Adamson05d564f2008-12-23 16:06:15 -05005140 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005141
Benny Halevyc0eae662009-08-14 17:20:14 +03005142 p = xdr_inline_decode(xdr, 8);
5143 if (unlikely(!p))
5144 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005145 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005146 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005147 if (bmlen > 10)
5148 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005149
Benny Halevyc0eae662009-08-14 17:20:14 +03005150 p = xdr_inline_decode(xdr, bmlen << 2);
5151 if (unlikely(!p))
5152 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005153 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5154 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005155 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005156 for (; i < NFS4_BITMAP_SIZE; i++)
5157 res->attrset[i] = 0;
5158
Linus Torvalds1da177e2005-04-16 15:20:36 -07005159 return decode_delegation(xdr, res);
5160xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005161 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005163out_overflow:
5164 print_overflow_msg(__func__, xdr);
5165 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005166}
5167
5168static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5169{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170 int status;
5171
Andy Adamson05d564f2008-12-23 16:06:15 -05005172 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005173 if (status != -EIO)
5174 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005175 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005176 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005177 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178}
5179
5180static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5181{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182 int status;
5183
5184 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005185 if (status != -EIO)
5186 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005187 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005188 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005189 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190}
5191
5192static int decode_putfh(struct xdr_stream *xdr)
5193{
5194 return decode_op_hdr(xdr, OP_PUTFH);
5195}
5196
5197static int decode_putrootfh(struct xdr_stream *xdr)
5198{
5199 return decode_op_hdr(xdr, OP_PUTROOTFH);
5200}
5201
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005202static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5203 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005204{
Al Viro8687b632006-10-19 23:28:48 -07005205 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005206 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207 int status;
5208
5209 status = decode_op_hdr(xdr, OP_READ);
5210 if (status)
5211 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005212 p = xdr_inline_decode(xdr, 8);
5213 if (unlikely(!p))
5214 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005215 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005216 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005217 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005219 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220 "count %u > recvd %u\n", count, recvd);
5221 count = recvd;
5222 eof = 0;
5223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005224 res->eof = eof;
5225 res->count = count;
5226 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005227out_overflow:
5228 print_overflow_msg(__func__, xdr);
5229 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005230}
5231
5232static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5233{
Chuck Leverbcecff72007-10-26 13:32:03 -04005234 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005235 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005236
5237 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005238 if (!status)
5239 status = decode_verifier(xdr, readdir->verifier.data);
5240 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005241 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005242 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005243 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005244 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005245 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005246}
5247
5248static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5249{
5250 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005251 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005252 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005253 int status;
5254
5255 status = decode_op_hdr(xdr, OP_READLINK);
5256 if (status)
5257 return status;
5258
5259 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005260 p = xdr_inline_decode(xdr, 4);
5261 if (unlikely(!p))
5262 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005263 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005264 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005265 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266 return -ENAMETOOLONG;
5267 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005268 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005270 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271 "count %u > recvd %u\n", len, recvd);
5272 return -EIO;
5273 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274 /*
5275 * The XDR encode routine has set things up so that
5276 * the link text will be copied directly into the
5277 * buffer. We just have to do overflow-checking,
5278 * and and null-terminate the text (the VFS expects
5279 * null-termination).
5280 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005281 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005283out_overflow:
5284 print_overflow_msg(__func__, xdr);
5285 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286}
5287
5288static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5289{
5290 int status;
5291
5292 status = decode_op_hdr(xdr, OP_REMOVE);
5293 if (status)
5294 goto out;
5295 status = decode_change_info(xdr, cinfo);
5296out:
5297 return status;
5298}
5299
5300static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5301 struct nfs4_change_info *new_cinfo)
5302{
5303 int status;
5304
5305 status = decode_op_hdr(xdr, OP_RENAME);
5306 if (status)
5307 goto out;
5308 if ((status = decode_change_info(xdr, old_cinfo)))
5309 goto out;
5310 status = decode_change_info(xdr, new_cinfo);
5311out:
5312 return status;
5313}
5314
5315static int decode_renew(struct xdr_stream *xdr)
5316{
5317 return decode_op_hdr(xdr, OP_RENEW);
5318}
5319
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005320static int
5321decode_restorefh(struct xdr_stream *xdr)
5322{
5323 return decode_op_hdr(xdr, OP_RESTOREFH);
5324}
5325
J. Bruce Fields029d1052005-06-22 17:16:22 +00005326static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005327 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005328{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005329 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005330 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005331 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005332 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005333 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005334
Andy Adamsonbf118a32011-12-07 11:55:27 -05005335 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005336 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5337 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005338
Trond Myklebust519d3952012-08-14 17:30:10 -04005339 xdr_enter_page(xdr, xdr->buf->page_len);
5340
Trond Myklebustcff298c2012-08-14 17:14:17 -04005341 /* Calculate the offset of the page data */
5342 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005343
J. Bruce Fields029d1052005-06-22 17:16:22 +00005344 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5345 goto out;
5346 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5347 goto out;
5348
5349 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5350 return -EIO;
5351 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005352
Andy Adamsonbf118a32011-12-07 11:55:27 -05005353 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5354 * are stored with the acl data to handle the problem of
5355 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005356 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005357 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005358
5359 /* Check for receive buffer overflow */
5360 if (res->acl_len > (xdr->nwords << 2) ||
5361 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5362 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005363 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005364 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005365 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005366 } else
5367 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005368
5369out:
5370 return status;
5371}
5372
Linus Torvalds1da177e2005-04-16 15:20:36 -07005373static int
5374decode_savefh(struct xdr_stream *xdr)
5375{
5376 return decode_op_hdr(xdr, OP_SAVEFH);
5377}
5378
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005379static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005380{
Al Viro8687b632006-10-19 23:28:48 -07005381 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005382 uint32_t bmlen;
5383 int status;
5384
Linus Torvalds1da177e2005-04-16 15:20:36 -07005385 status = decode_op_hdr(xdr, OP_SETATTR);
5386 if (status)
5387 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005388 p = xdr_inline_decode(xdr, 4);
5389 if (unlikely(!p))
5390 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005391 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005392 p = xdr_inline_decode(xdr, bmlen << 2);
5393 if (likely(p))
5394 return 0;
5395out_overflow:
5396 print_overflow_msg(__func__, xdr);
5397 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005398}
5399
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005400static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005401{
Al Viro8687b632006-10-19 23:28:48 -07005402 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005403 uint32_t opnum;
5404 int32_t nfserr;
5405
Benny Halevyc0eae662009-08-14 17:20:14 +03005406 p = xdr_inline_decode(xdr, 8);
5407 if (unlikely(!p))
5408 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005409 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005410 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005411 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005412 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005413 return -EIO;
5414 }
Benny Halevycccddf42009-08-14 17:20:19 +03005415 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005416 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005417 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5418 if (unlikely(!p))
5419 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005420 p = xdr_decode_hyper(p, &res->clientid);
5421 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005422 } else if (nfserr == NFSERR_CLID_INUSE) {
5423 uint32_t len;
5424
5425 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005426 p = xdr_inline_decode(xdr, 4);
5427 if (unlikely(!p))
5428 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005429 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005430 p = xdr_inline_decode(xdr, len);
5431 if (unlikely(!p))
5432 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005433
5434 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005435 p = xdr_inline_decode(xdr, 4);
5436 if (unlikely(!p))
5437 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005438 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005439 p = xdr_inline_decode(xdr, len);
5440 if (unlikely(!p))
5441 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005442 return -NFSERR_CLID_INUSE;
5443 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005444 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005445
5446 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005447out_overflow:
5448 print_overflow_msg(__func__, xdr);
5449 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005450}
5451
5452static int decode_setclientid_confirm(struct xdr_stream *xdr)
5453{
5454 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5455}
5456
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005457static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005458{
Al Viro8687b632006-10-19 23:28:48 -07005459 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005460 int status;
5461
5462 status = decode_op_hdr(xdr, OP_WRITE);
5463 if (status)
5464 return status;
5465
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005466 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005467 if (unlikely(!p))
5468 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005469 res->count = be32_to_cpup(p++);
5470 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005471 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005472out_overflow:
5473 print_overflow_msg(__func__, xdr);
5474 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005475}
5476
5477static int decode_delegreturn(struct xdr_stream *xdr)
5478{
5479 return decode_op_hdr(xdr, OP_DELEGRETURN);
5480}
5481
Chuck Leverfb15b262013-03-16 15:54:34 -04005482static int decode_secinfo_gss(struct xdr_stream *xdr,
5483 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005484{
Chuck Leverfb15b262013-03-16 15:54:34 -04005485 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005486 __be32 *p;
5487
5488 p = xdr_inline_decode(xdr, 4);
5489 if (unlikely(!p))
5490 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005491 oid_len = be32_to_cpup(p);
5492 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005493 goto out_err;
5494
Chuck Leverfb15b262013-03-16 15:54:34 -04005495 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005496 if (unlikely(!p))
5497 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005498 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5499 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005500
5501 p = xdr_inline_decode(xdr, 8);
5502 if (unlikely(!p))
5503 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005504 flavor->flavor_info.qop = be32_to_cpup(p++);
5505 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005506
5507 return 0;
5508
5509out_overflow:
5510 print_overflow_msg(__func__, xdr);
5511 return -EIO;
5512out_err:
5513 return -EINVAL;
5514}
5515
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005516static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005517{
Chuck Leverfb15b262013-03-16 15:54:34 -04005518 struct nfs4_secinfo4 *sec_flavor;
5519 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005520 int status;
5521 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005522
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005523 p = xdr_inline_decode(xdr, 4);
5524 if (unlikely(!p))
5525 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005526
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005527 res->flavors->num_flavors = 0;
5528 num_flavors = be32_to_cpup(p);
5529
5530 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005531 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005532 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005533 break;
5534
5535 p = xdr_inline_decode(xdr, 4);
5536 if (unlikely(!p))
5537 goto out_overflow;
5538 sec_flavor->flavor = be32_to_cpup(p);
5539
5540 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005541 status = decode_secinfo_gss(xdr, sec_flavor);
5542 if (status)
5543 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005544 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005545 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005546 }
5547
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005548 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005549out:
5550 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005551out_overflow:
5552 print_overflow_msg(__func__, xdr);
5553 return -EIO;
5554}
5555
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005556static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5557{
5558 int status = decode_op_hdr(xdr, OP_SECINFO);
5559 if (status)
5560 return status;
5561 return decode_secinfo_common(xdr, res);
5562}
5563
Benny Halevy99fe60d2009-04-01 09:22:29 -04005564#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005565static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5566{
5567 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5568 if (status)
5569 return status;
5570 return decode_secinfo_common(xdr, res);
5571}
5572
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005573static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5574{
5575 __be32 *p;
5576 uint32_t bitmap_words;
5577 unsigned int i;
5578
5579 p = xdr_inline_decode(xdr, 4);
5580 bitmap_words = be32_to_cpup(p++);
5581 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5582 return -EIO;
5583 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5584 for (i = 0; i < bitmap_words; i++)
5585 op_map->u.words[i] = be32_to_cpup(p++);
5586
5587 return 0;
5588}
5589
Benny Halevy99fe60d2009-04-01 09:22:29 -04005590static int decode_exchange_id(struct xdr_stream *xdr,
5591 struct nfs41_exchange_id_res *res)
5592{
5593 __be32 *p;
5594 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005595 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005596 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005597 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005598
5599 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5600 if (status)
5601 return status;
5602
Benny Halevyc0eae662009-08-14 17:20:14 +03005603 p = xdr_inline_decode(xdr, 8);
5604 if (unlikely(!p))
5605 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005606 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005607 p = xdr_inline_decode(xdr, 12);
5608 if (unlikely(!p))
5609 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005610 res->seqid = be32_to_cpup(p++);
5611 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005612
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005613 res->state_protect.how = be32_to_cpup(p);
5614 switch (res->state_protect.how) {
5615 case SP4_NONE:
5616 break;
5617 case SP4_MACH_CRED:
5618 status = decode_op_map(xdr, &res->state_protect.enforce);
5619 if (status)
5620 return status;
5621 status = decode_op_map(xdr, &res->state_protect.allow);
5622 if (status)
5623 return status;
5624 break;
5625 default:
5626 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005627 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005628 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005629
Chuck Leveracdeb692012-05-21 22:46:16 -04005630 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005631 p = xdr_inline_decode(xdr, 8);
5632 if (unlikely(!p))
5633 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005634 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005635
Chuck Leveracdeb692012-05-21 22:46:16 -04005636 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005637 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5638 if (unlikely(status))
5639 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005640 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5641 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005642 memcpy(res->server_owner->major_id, dummy_str, dummy);
5643 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005644
Chuck Leveracdeb692012-05-21 22:46:16 -04005645 /* server_scope4 */
5646 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5647 if (unlikely(status))
5648 return status;
5649 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5650 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005651 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5652 res->server_scope->server_scope_sz = dummy;
5653
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005654 /* Implementation Id */
5655 p = xdr_inline_decode(xdr, 4);
5656 if (unlikely(!p))
5657 goto out_overflow;
5658 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005659
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005660 if (impl_id_count) {
5661 /* nii_domain */
5662 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5663 if (unlikely(status))
5664 return status;
5665 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5666 return -EIO;
5667 memcpy(res->impl_id->domain, dummy_str, dummy);
5668
5669 /* nii_name */
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->name, dummy_str, dummy);
5676
5677 /* nii_date */
5678 p = xdr_inline_decode(xdr, 12);
5679 if (unlikely(!p))
5680 goto out_overflow;
5681 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5682 res->impl_id->date.nseconds = be32_to_cpup(p);
5683
5684 /* if there's more than one entry, ignore the rest */
5685 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005686 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005687out_overflow:
5688 print_overflow_msg(__func__, xdr);
5689 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005690}
Andy Adamsonfc931582009-04-01 09:22:31 -04005691
5692static int decode_chan_attrs(struct xdr_stream *xdr,
5693 struct nfs4_channel_attrs *attrs)
5694{
5695 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005696 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005697
Benny Halevyc0eae662009-08-14 17:20:14 +03005698 p = xdr_inline_decode(xdr, 28);
5699 if (unlikely(!p))
5700 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005701 val = be32_to_cpup(p++); /* headerpadsz */
5702 if (val)
5703 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005704 attrs->max_rqst_sz = be32_to_cpup(p++);
5705 attrs->max_resp_sz = be32_to_cpup(p++);
5706 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5707 attrs->max_ops = be32_to_cpup(p++);
5708 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005709 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005710 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005711 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5712 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005713 return -EINVAL;
5714 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005715 if (nr_attrs == 1) {
5716 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5717 if (unlikely(!p))
5718 goto out_overflow;
5719 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005720 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005721out_overflow:
5722 print_overflow_msg(__func__, xdr);
5723 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005724}
5725
Benny Halevye78291e2009-08-14 17:20:00 +03005726static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5727{
5728 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005729}
5730
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005731static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5732 struct nfs41_bind_conn_to_session_res *res)
5733{
5734 __be32 *p;
5735 int status;
5736
5737 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5738 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005739 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005740 if (unlikely(status))
5741 return status;
5742
5743 /* dir flags, rdma mode bool */
5744 p = xdr_inline_decode(xdr, 8);
5745 if (unlikely(!p))
5746 goto out_overflow;
5747
5748 res->dir = be32_to_cpup(p++);
5749 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5750 return -EIO;
5751 if (be32_to_cpup(p) == 0)
5752 res->use_conn_in_rdma_mode = false;
5753 else
5754 res->use_conn_in_rdma_mode = true;
5755
5756 return 0;
5757out_overflow:
5758 print_overflow_msg(__func__, xdr);
5759 return -EIO;
5760}
5761
Andy Adamsonfc931582009-04-01 09:22:31 -04005762static int decode_create_session(struct xdr_stream *xdr,
5763 struct nfs41_create_session_res *res)
5764{
5765 __be32 *p;
5766 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005767
5768 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005769 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005770 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005771 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005772 return status;
5773
Andy Adamsonfc931582009-04-01 09:22:31 -04005774 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005775 p = xdr_inline_decode(xdr, 8);
5776 if (unlikely(!p))
5777 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005778 res->seqid = be32_to_cpup(p++);
5779 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005780
5781 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005782 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005783 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005784 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005785 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005786out_overflow:
5787 print_overflow_msg(__func__, xdr);
5788 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005789}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005790
5791static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5792{
5793 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5794}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005795
Trond Myklebust66245532012-05-25 17:18:09 -04005796static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5797{
5798 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5799}
5800
Ricardo Labiaga180197532009-12-05 16:08:40 -05005801static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5802{
5803 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5804}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005805#endif /* CONFIG_NFS_V4_1 */
5806
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005807static int decode_sequence(struct xdr_stream *xdr,
5808 struct nfs4_sequence_res *res,
5809 struct rpc_rqst *rqstp)
5810{
5811#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005812 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005813 struct nfs4_sessionid id;
5814 u32 dummy;
5815 int status;
5816 __be32 *p;
5817
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005818 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005819 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005820 if (!res->sr_slot->table->session)
5821 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005822
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005823 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005824 if (!status)
5825 status = decode_sessionid(xdr, &id);
5826 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005827 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005828
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005829 /*
5830 * If the server returns different values for sessionID, slotID or
5831 * sequence number, the server is looney tunes.
5832 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005833 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005834 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005835
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005836 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005837 NFS4_MAX_SESSIONID_LEN)) {
5838 dprintk("%s Invalid session id\n", __func__);
5839 goto out_err;
5840 }
Benny Halevye78291e2009-08-14 17:20:00 +03005841
Benny Halevyc0eae662009-08-14 17:20:14 +03005842 p = xdr_inline_decode(xdr, 20);
5843 if (unlikely(!p))
5844 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005845
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005846 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005847 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005848 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005849 dprintk("%s Invalid sequence number\n", __func__);
5850 goto out_err;
5851 }
5852 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005853 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005854 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005855 dprintk("%s Invalid slot id\n", __func__);
5856 goto out_err;
5857 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005858 /* highest slot id */
5859 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005860 /* target highest slot id */
5861 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005862 /* result flags */
5863 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005864 status = 0;
5865out_err:
5866 res->sr_status = status;
5867 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005868out_overflow:
5869 print_overflow_msg(__func__, xdr);
5870 status = -EIO;
5871 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005872#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005873 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005874#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005875}
5876
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005877#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005878static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5879{
5880 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5881 return decode_stateid(xdr, stateid);
5882}
5883
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005884static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005885 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005886{
Trond Myklebust4e590802015-03-09 14:01:25 -04005887 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005888 __be32 *p;
5889 uint32_t len, type;
5890 int status;
5891
5892 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5893 if (status) {
5894 if (status == -ETOOSMALL) {
5895 p = xdr_inline_decode(xdr, 4);
5896 if (unlikely(!p))
5897 goto out_overflow;
5898 pdev->mincount = be32_to_cpup(p);
5899 dprintk("%s: Min count too small. mincnt = %u\n",
5900 __func__, pdev->mincount);
5901 }
5902 return status;
5903 }
5904
5905 p = xdr_inline_decode(xdr, 8);
5906 if (unlikely(!p))
5907 goto out_overflow;
5908 type = be32_to_cpup(p++);
5909 if (type != pdev->layout_type) {
5910 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5911 __func__, pdev->layout_type, type);
5912 return -EINVAL;
5913 }
5914 /*
5915 * Get the length of the opaque device_addr4. xdr_read_pages places
5916 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5917 * and places the remaining xdr data in xdr_buf->tail
5918 */
5919 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005920 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5921 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005922
5923 /* Parse notification bitmap, verifying that it is zero. */
5924 p = xdr_inline_decode(xdr, 4);
5925 if (unlikely(!p))
5926 goto out_overflow;
5927 len = be32_to_cpup(p);
5928 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005929 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005930
5931 p = xdr_inline_decode(xdr, 4 * len);
5932 if (unlikely(!p))
5933 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005934
Trond Myklebust4e590802015-03-09 14:01:25 -04005935 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005936 for (i = 1; i < len; i++) {
5937 if (be32_to_cpup(p++)) {
5938 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005939 __func__);
5940 return -EIO;
5941 }
5942 }
5943 }
5944 return 0;
5945out_overflow:
5946 print_overflow_msg(__func__, xdr);
5947 return -EIO;
5948}
5949
5950static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5951 struct nfs4_layoutget_res *res)
5952{
5953 __be32 *p;
5954 int status;
5955 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005956 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005957
5958 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5959 if (status)
5960 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005961 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005962 if (unlikely(!p))
5963 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005964 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04005965 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005966 p = xdr_inline_decode(xdr, 4);
5967 if (unlikely(!p))
5968 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005969 layout_count = be32_to_cpup(p);
5970 if (!layout_count) {
5971 dprintk("%s: server responded with empty layout array\n",
5972 __func__);
5973 return -EINVAL;
5974 }
5975
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005976 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005977 if (unlikely(!p))
5978 goto out_overflow;
5979 p = xdr_decode_hyper(p, &res->range.offset);
5980 p = xdr_decode_hyper(p, &res->range.length);
5981 res->range.iomode = be32_to_cpup(p++);
5982 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005983 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005984
5985 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5986 __func__,
5987 (unsigned long)res->range.offset,
5988 (unsigned long)res->range.length,
5989 res->range.iomode,
5990 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005991 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005992
Trond Myklebust64bd5772012-06-20 22:35:05 -04005993 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005994 if (res->layoutp->len > recvd) {
5995 dprintk("NFS: server cheating in layoutget reply: "
5996 "layout len %u > recvd %u\n",
5997 res->layoutp->len, recvd);
5998 return -EINVAL;
5999 }
6000
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006001 if (layout_count > 1) {
6002 /* We only handle a length one array at the moment. Any
6003 * further entries are just ignored. Note that this means
6004 * the client may see a response that is less than the
6005 * minimum it requested.
6006 */
6007 dprintk("%s: server responded with %d layouts, dropping tail\n",
6008 __func__, layout_count);
6009 }
6010
6011 return 0;
6012out_overflow:
6013 print_overflow_msg(__func__, xdr);
6014 return -EIO;
6015}
Andy Adamson863a3c62011-03-23 13:27:54 +00006016
Benny Halevycbe82602011-05-22 19:52:37 +03006017static int decode_layoutreturn(struct xdr_stream *xdr,
6018 struct nfs4_layoutreturn_res *res)
6019{
6020 __be32 *p;
6021 int status;
6022
6023 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6024 if (status)
6025 return status;
6026 p = xdr_inline_decode(xdr, 4);
6027 if (unlikely(!p))
6028 goto out_overflow;
6029 res->lrs_present = be32_to_cpup(p);
6030 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04006031 status = decode_layout_stateid(xdr, &res->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03006032 return status;
6033out_overflow:
6034 print_overflow_msg(__func__, xdr);
6035 return -EIO;
6036}
6037
Andy Adamson863a3c62011-03-23 13:27:54 +00006038static int decode_layoutcommit(struct xdr_stream *xdr,
6039 struct rpc_rqst *req,
6040 struct nfs4_layoutcommit_res *res)
6041{
6042 __be32 *p;
6043 __u32 sizechanged;
6044 int status;
6045
6046 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04006047 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00006048 if (status)
6049 return status;
6050
6051 p = xdr_inline_decode(xdr, 4);
6052 if (unlikely(!p))
6053 goto out_overflow;
6054 sizechanged = be32_to_cpup(p);
6055
6056 if (sizechanged) {
6057 /* throw away new size */
6058 p = xdr_inline_decode(xdr, 8);
6059 if (unlikely(!p))
6060 goto out_overflow;
6061 }
6062 return 0;
6063out_overflow:
6064 print_overflow_msg(__func__, xdr);
6065 return -EIO;
6066}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006067
6068static int decode_test_stateid(struct xdr_stream *xdr,
6069 struct nfs41_test_stateid_res *res)
6070{
6071 __be32 *p;
6072 int status;
6073 int num_res;
6074
6075 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6076 if (status)
6077 return status;
6078
6079 p = xdr_inline_decode(xdr, 4);
6080 if (unlikely(!p))
6081 goto out_overflow;
6082 num_res = be32_to_cpup(p++);
6083 if (num_res != 1)
6084 goto out;
6085
6086 p = xdr_inline_decode(xdr, 4);
6087 if (unlikely(!p))
6088 goto out_overflow;
6089 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006090
6091 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006092out_overflow:
6093 print_overflow_msg(__func__, xdr);
6094out:
6095 return -EIO;
6096}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006097
6098static int decode_free_stateid(struct xdr_stream *xdr,
6099 struct nfs41_free_stateid_res *res)
6100{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006101 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006102 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006103}
Trond Myklebustcf805162016-11-15 14:56:07 -05006104#else
6105static inline
6106int decode_layoutreturn(struct xdr_stream *xdr,
6107 struct nfs4_layoutreturn_res *res)
6108{
6109 return 0;
6110}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006111#endif /* CONFIG_NFS_V4_1 */
6112
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113/*
Benny Halevy49c25592008-12-23 16:06:16 -05006114 * END OF "GENERIC" DECODE ROUTINES.
6115 */
6116
6117/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118 * Decode OPEN_DOWNGRADE response
6119 */
Chuck Leverbf269552010-12-14 14:59:29 +00006120static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6121 struct xdr_stream *xdr,
6122 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006123{
Andy Adamson05d564f2008-12-23 16:06:15 -05006124 struct compound_hdr hdr;
6125 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006126
Chuck Leverbf269552010-12-14 14:59:29 +00006127 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006128 if (status)
6129 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006130 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006131 if (status)
6132 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006133 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006134 if (status)
6135 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006138 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006139}
6140
6141/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006142 * Decode ACCESS response
6143 */
Chuck Leverbf269552010-12-14 14:59:29 +00006144static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6145 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006147 struct compound_hdr hdr;
6148 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006149
Chuck Leverbf269552010-12-14 14:59:29 +00006150 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006151 if (status)
6152 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006154 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006157 if (status != 0)
6158 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006159 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006160 if (status != 0)
6161 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006162 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006163out:
6164 return status;
6165}
6166
6167/*
6168 * Decode LOOKUP response
6169 */
Chuck Leverbf269552010-12-14 14:59:29 +00006170static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6171 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173 struct compound_hdr hdr;
6174 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006175
Chuck Leverbf269552010-12-14 14:59:29 +00006176 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006177 if (status)
6178 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006179 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006180 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006182 status = decode_putfh(xdr);
6183 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006184 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006185 status = decode_lookup(xdr);
6186 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006188 status = decode_getfh(xdr, res->fh);
6189 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006190 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006191 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192out:
6193 return status;
6194}
6195
6196/*
6197 * Decode LOOKUP_ROOT response
6198 */
Chuck Leverbf269552010-12-14 14:59:29 +00006199static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6200 struct xdr_stream *xdr,
6201 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203 struct compound_hdr hdr;
6204 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006205
Chuck Leverbf269552010-12-14 14:59:29 +00006206 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006207 if (status)
6208 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006209 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006210 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006211 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006212 status = decode_putrootfh(xdr);
6213 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006215 status = decode_getfh(xdr, res->fh);
6216 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006217 status = decode_getfattr_label(xdr, res->fattr,
6218 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219out:
6220 return status;
6221}
6222
6223/*
6224 * Decode REMOVE response
6225 */
Chuck Leverbf269552010-12-14 14:59:29 +00006226static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6227 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229 struct compound_hdr hdr;
6230 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006231
Chuck Leverbf269552010-12-14 14:59:29 +00006232 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006233 if (status)
6234 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006235 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006236 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006238 status = decode_putfh(xdr);
6239 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006240 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006241 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242out:
6243 return status;
6244}
6245
6246/*
6247 * Decode RENAME response
6248 */
Chuck Leverbf269552010-12-14 14:59:29 +00006249static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6250 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006252 struct compound_hdr hdr;
6253 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006254
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006256 if (status)
6257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006258 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006259 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006261 status = decode_putfh(xdr);
6262 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006263 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006264 status = decode_savefh(xdr);
6265 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006266 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006267 status = decode_putfh(xdr);
6268 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006269 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006270 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271out:
6272 return status;
6273}
6274
6275/*
6276 * Decode LINK response
6277 */
Chuck Leverbf269552010-12-14 14:59:29 +00006278static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6279 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006280{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281 struct compound_hdr hdr;
6282 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006283
Chuck Leverbf269552010-12-14 14:59:29 +00006284 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006285 if (status)
6286 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006287 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006288 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006289 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006290 status = decode_putfh(xdr);
6291 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006292 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006293 status = decode_savefh(xdr);
6294 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006296 status = decode_putfh(xdr);
6297 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006299 status = decode_link(xdr, &res->cinfo);
6300 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006301 goto out;
6302 /*
6303 * Note order: OP_LINK leaves the directory as the current
6304 * filehandle.
6305 */
Chuck Leverbf269552010-12-14 14:59:29 +00006306 status = decode_restorefh(xdr);
6307 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006308 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006309 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006310out:
6311 return status;
6312}
6313
6314/*
6315 * Decode CREATE response
6316 */
Chuck Leverbf269552010-12-14 14:59:29 +00006317static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6318 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006319{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006320 struct compound_hdr hdr;
6321 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006322
Chuck Leverbf269552010-12-14 14:59:29 +00006323 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006324 if (status)
6325 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006326 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006327 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006328 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006329 status = decode_putfh(xdr);
6330 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006331 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006332 status = decode_create(xdr, &res->dir_cinfo);
6333 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006334 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006335 status = decode_getfh(xdr, res->fh);
6336 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006337 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006338 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339out:
6340 return status;
6341}
6342
6343/*
6344 * Decode SYMLINK response
6345 */
Chuck Leverbf269552010-12-14 14:59:29 +00006346static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6347 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348{
Chuck Leverbf269552010-12-14 14:59:29 +00006349 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350}
6351
6352/*
6353 * Decode GETATTR response
6354 */
Chuck Leverbf269552010-12-14 14:59:29 +00006355static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6356 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358 struct compound_hdr hdr;
6359 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006360
Chuck Leverbf269552010-12-14 14:59:29 +00006361 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 if (status)
6363 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006365 if (status)
6366 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368 if (status)
6369 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006370 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371out:
6372 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006373}
6374
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006375/*
6376 * Encode an SETACL request
6377 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006378static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6379 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006380{
Andy Adamson05d564f2008-12-23 16:06:15 -05006381 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006382 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006383 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006384
Chuck Lever9f06c712010-12-14 14:59:18 +00006385 encode_compound_hdr(xdr, req, &hdr);
6386 encode_sequence(xdr, &args->seq_args, &hdr);
6387 encode_putfh(xdr, args->fh, &hdr);
6388 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006389 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006390}
Andy Adamson05d564f2008-12-23 16:06:15 -05006391
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006392/*
6393 * Decode SETACL response
6394 */
6395static int
Chuck Leverbf269552010-12-14 14:59:29 +00006396nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006397 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006398{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006399 struct compound_hdr hdr;
6400 int status;
6401
Chuck Leverbf269552010-12-14 14:59:29 +00006402 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006403 if (status)
6404 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006405 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006406 if (status)
6407 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006408 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006409 if (status)
6410 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006411 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006412out:
6413 return status;
6414}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006415
6416/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006417 * Decode GETACL response
6418 */
6419static int
Chuck Leverbf269552010-12-14 14:59:29 +00006420nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006421 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006422{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006423 struct compound_hdr hdr;
6424 int status;
6425
Trond Myklebust331818f2012-02-03 18:30:53 -05006426 if (res->acl_scratch != NULL) {
6427 void *p = page_address(res->acl_scratch);
6428 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6429 }
Chuck Leverbf269552010-12-14 14:59:29 +00006430 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006431 if (status)
6432 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006433 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006434 if (status)
6435 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006436 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006437 if (status)
6438 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006439 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006440
6441out:
6442 return status;
6443}
6444
6445/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006446 * Decode CLOSE response
6447 */
Chuck Leverbf269552010-12-14 14:59:29 +00006448static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6449 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450{
Andy Adamson05d564f2008-12-23 16:06:15 -05006451 struct compound_hdr hdr;
6452 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453
Chuck Leverbf269552010-12-14 14:59:29 +00006454 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006455 if (status)
6456 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006457 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006458 if (status)
6459 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006460 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006461 if (status)
6462 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006463 if (res->lr_res) {
6464 status = decode_layoutreturn(xdr, res->lr_res);
6465 res->lr_ret = status;
6466 if (status)
6467 goto out;
6468 }
Chuck Leverbf269552010-12-14 14:59:29 +00006469 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006470 if (status != 0)
6471 goto out;
6472 /*
6473 * Note: Server may do delete on close for this file
6474 * in which case the getattr call will fail with
6475 * an ESTALE error. Shouldn't be a problem,
6476 * though, since fattr->valid will remain unset.
6477 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006478 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006480 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006481}
6482
6483/*
6484 * Decode OPEN response
6485 */
Chuck Leverbf269552010-12-14 14:59:29 +00006486static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6487 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006488{
Andy Adamson05d564f2008-12-23 16:06:15 -05006489 struct compound_hdr hdr;
6490 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491
Chuck Leverbf269552010-12-14 14:59:29 +00006492 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006493 if (status)
6494 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006495 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006496 if (status)
6497 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006498 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006499 if (status)
6500 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006501 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006502 if (status)
6503 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006504 status = decode_getfh(xdr, &res->fh);
6505 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006506 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006507 if (res->access_request)
6508 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006509 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006510out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006511 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006512}
6513
6514/*
6515 * Decode OPEN_CONFIRM response
6516 */
Chuck Leverbf269552010-12-14 14:59:29 +00006517static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6518 struct xdr_stream *xdr,
6519 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520{
Andy Adamson05d564f2008-12-23 16:06:15 -05006521 struct compound_hdr hdr;
6522 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006523
Chuck Leverbf269552010-12-14 14:59:29 +00006524 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006525 if (status)
6526 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006527 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006528 if (status)
6529 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006530 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006531out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006532 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006533}
6534
6535/*
6536 * Decode OPEN response
6537 */
Chuck Leverbf269552010-12-14 14:59:29 +00006538static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6539 struct xdr_stream *xdr,
6540 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541{
Andy Adamson05d564f2008-12-23 16:06:15 -05006542 struct compound_hdr hdr;
6543 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544
Chuck Leverbf269552010-12-14 14:59:29 +00006545 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006546 if (status)
6547 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006548 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006549 if (status)
6550 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006552 if (status)
6553 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006554 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006555 if (status)
6556 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006557 if (res->access_request)
6558 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006559 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006560out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006561 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006562}
6563
6564/*
6565 * Decode SETATTR response
6566 */
Chuck Leverbf269552010-12-14 14:59:29 +00006567static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6568 struct xdr_stream *xdr,
6569 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006570{
Andy Adamson05d564f2008-12-23 16:06:15 -05006571 struct compound_hdr hdr;
6572 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006573
Chuck Leverbf269552010-12-14 14:59:29 +00006574 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006575 if (status)
6576 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006577 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006578 if (status)
6579 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006580 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006581 if (status)
6582 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006583 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006584 if (status)
6585 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006586 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006587out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006588 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006589}
6590
6591/*
6592 * Decode LOCK response
6593 */
Chuck Leverbf269552010-12-14 14:59:29 +00006594static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6595 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006596{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597 struct compound_hdr hdr;
6598 int status;
6599
Chuck Leverbf269552010-12-14 14:59:29 +00006600 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006601 if (status)
6602 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006603 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006604 if (status)
6605 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006606 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006607 if (status)
6608 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006609 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006610out:
6611 return status;
6612}
6613
6614/*
6615 * Decode LOCKT response
6616 */
Chuck Leverbf269552010-12-14 14:59:29 +00006617static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6618 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006619{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006620 struct compound_hdr hdr;
6621 int status;
6622
Chuck Leverbf269552010-12-14 14:59:29 +00006623 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006624 if (status)
6625 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006626 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006627 if (status)
6628 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006629 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006630 if (status)
6631 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006632 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633out:
6634 return status;
6635}
6636
6637/*
6638 * Decode LOCKU response
6639 */
Chuck Leverbf269552010-12-14 14:59:29 +00006640static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6641 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006642{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643 struct compound_hdr hdr;
6644 int status;
6645
Chuck Leverbf269552010-12-14 14:59:29 +00006646 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647 if (status)
6648 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006649 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006650 if (status)
6651 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006652 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653 if (status)
6654 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006655 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006656out:
6657 return status;
6658}
6659
Chuck Leverbf269552010-12-14 14:59:29 +00006660static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6661 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006662{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006663 struct compound_hdr hdr;
6664 int status;
6665
Chuck Leverbf269552010-12-14 14:59:29 +00006666 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006667 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006668 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006669 return status;
6670}
6671
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672/*
6673 * Decode READLINK response
6674 */
Chuck Leverbf269552010-12-14 14:59:29 +00006675static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6676 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006677 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006678{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006679 struct compound_hdr hdr;
6680 int status;
6681
Chuck Leverbf269552010-12-14 14:59:29 +00006682 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006683 if (status)
6684 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006685 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006686 if (status)
6687 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006688 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006689 if (status)
6690 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006691 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006692out:
6693 return status;
6694}
6695
6696/*
6697 * Decode READDIR response
6698 */
Chuck Leverbf269552010-12-14 14:59:29 +00006699static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6700 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006701{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006702 struct compound_hdr hdr;
6703 int status;
6704
Chuck Leverbf269552010-12-14 14:59:29 +00006705 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006706 if (status)
6707 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006708 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006709 if (status)
6710 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006711 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712 if (status)
6713 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006714 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006715out:
6716 return status;
6717}
6718
6719/*
6720 * Decode Read response
6721 */
Chuck Leverbf269552010-12-14 14:59:29 +00006722static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006723 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006724{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006725 struct compound_hdr hdr;
6726 int status;
6727
Chuck Leverbf269552010-12-14 14:59:29 +00006728 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006729 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006730 if (status)
6731 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006732 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006733 if (status)
6734 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006735 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736 if (status)
6737 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006738 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006739 if (!status)
6740 status = res->count;
6741out:
6742 return status;
6743}
6744
6745/*
6746 * Decode WRITE response
6747 */
Chuck Leverbf269552010-12-14 14:59:29 +00006748static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006749 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006750{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006751 struct compound_hdr hdr;
6752 int status;
6753
Chuck Leverbf269552010-12-14 14:59:29 +00006754 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006755 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006756 if (status)
6757 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006758 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006759 if (status)
6760 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006761 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006762 if (status)
6763 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006764 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006765 if (status)
6766 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006767 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006768 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006769 if (!status)
6770 status = res->count;
6771out:
6772 return status;
6773}
6774
6775/*
6776 * Decode COMMIT response
6777 */
Chuck Leverbf269552010-12-14 14:59:29 +00006778static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006779 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006780{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006781 struct compound_hdr hdr;
6782 int status;
6783
Chuck Leverbf269552010-12-14 14:59:29 +00006784 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006785 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006786 if (status)
6787 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006788 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006789 if (status)
6790 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006791 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006792 if (status)
6793 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006794 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006795out:
6796 return status;
6797}
6798
6799/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006800 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006801 */
Chuck Leverbf269552010-12-14 14:59:29 +00006802static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006803 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006804{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006805 struct compound_hdr hdr;
6806 int status;
6807
Chuck Leverbf269552010-12-14 14:59:29 +00006808 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006809 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006810 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006811 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006812 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006813 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006814 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006815 return status;
6816}
6817
6818/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006819 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006820 */
Chuck Leverbf269552010-12-14 14:59:29 +00006821static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006822 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006823{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006824 struct compound_hdr hdr;
6825 int status;
6826
Chuck Leverbf269552010-12-14 14:59:29 +00006827 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006828 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006829 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006830 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006831 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006832 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006833 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006834 return status;
6835}
6836
6837/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006838 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006839 */
Chuck Leverbf269552010-12-14 14:59:29 +00006840static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006841 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006842{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006843 struct compound_hdr hdr;
6844 int status;
6845
Chuck Leverbf269552010-12-14 14:59:29 +00006846 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006847 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006848 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006849 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006850 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006851 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006852 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006853 return status;
6854}
6855
6856/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006857 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006858 */
Chuck Leverbf269552010-12-14 14:59:29 +00006859static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6860 struct xdr_stream *xdr,
6861 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006862{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006863 struct compound_hdr hdr;
6864 int status;
6865
Chuck Leverbf269552010-12-14 14:59:29 +00006866 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006867 if (status)
6868 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006869 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006870 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006871 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006872 status = decode_putfh(xdr);
6873 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006874 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006875 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006876out:
6877 return status;
6878}
6879
6880/*
6881 * Decode RENEW response
6882 */
Chuck Leverbf269552010-12-14 14:59:29 +00006883static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6884 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006885{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006886 struct compound_hdr hdr;
6887 int status;
6888
Chuck Leverbf269552010-12-14 14:59:29 +00006889 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006890 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006891 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006892 return status;
6893}
6894
6895/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006896 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006897 */
Chuck Leverbf269552010-12-14 14:59:29 +00006898static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6899 struct xdr_stream *xdr,
6900 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006901{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006902 struct compound_hdr hdr;
6903 int status;
6904
Chuck Leverbf269552010-12-14 14:59:29 +00006905 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006906 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006907 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006908 return status;
6909}
6910
6911/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006912 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006913 */
Chuck Leverbf269552010-12-14 14:59:29 +00006914static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006915 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006916{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006917 struct compound_hdr hdr;
6918 int status;
6919
Chuck Leverbf269552010-12-14 14:59:29 +00006920 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006921 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006922 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006923 return status;
6924}
6925
6926/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006927 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006928 */
Chuck Leverbf269552010-12-14 14:59:29 +00006929static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6930 struct xdr_stream *xdr,
6931 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006932{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006933 struct compound_hdr hdr;
6934 int status;
6935
Chuck Leverbf269552010-12-14 14:59:29 +00006936 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006937 if (status)
6938 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006939 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006940 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006941 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006942 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006943 if (status != 0)
6944 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006945 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006946 if (status != 0)
6947 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006948 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006949out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006950 return status;
6951}
6952
Trond Myklebust683b57b2006-06-09 09:34:22 -04006953/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006954 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006955 */
Chuck Leverbf269552010-12-14 14:59:29 +00006956static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6957 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006958 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006959{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006960 struct compound_hdr hdr;
6961 int status;
6962
Chuck Leverbf269552010-12-14 14:59:29 +00006963 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006964 if (status)
6965 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006966 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006967 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006968 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006969 status = decode_putfh(xdr);
6970 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006971 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006972 if (res->migration) {
6973 xdr_enter_page(xdr, PAGE_SIZE);
6974 status = decode_getfattr_generic(xdr,
6975 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006976 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006977 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006978 if (status)
6979 goto out;
6980 if (res->renew)
6981 status = decode_renew(xdr);
6982 } else {
6983 status = decode_lookup(xdr);
6984 if (status)
6985 goto out;
6986 xdr_enter_page(xdr, PAGE_SIZE);
6987 status = decode_getfattr_generic(xdr,
6988 &res->fs_locations->fattr,
6989 NULL, res->fs_locations,
6990 NULL, res->fs_locations->server);
6991 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006992out:
6993 return status;
6994}
6995
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006996/*
6997 * Decode SECINFO response
6998 */
6999static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7000 struct xdr_stream *xdr,
7001 struct nfs4_secinfo_res *res)
7002{
7003 struct compound_hdr hdr;
7004 int status;
7005
7006 status = decode_compound_hdr(xdr, &hdr);
7007 if (status)
7008 goto out;
7009 status = decode_sequence(xdr, &res->seq_res, rqstp);
7010 if (status)
7011 goto out;
7012 status = decode_putfh(xdr);
7013 if (status)
7014 goto out;
7015 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007016out:
7017 return status;
7018}
7019
Chuck Lever44c99932013-10-17 14:13:30 -04007020/*
7021 * Decode FSID_PRESENT response
7022 */
7023static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7024 struct xdr_stream *xdr,
7025 struct nfs4_fsid_present_res *res)
7026{
7027 struct compound_hdr hdr;
7028 int status;
7029
7030 status = decode_compound_hdr(xdr, &hdr);
7031 if (status)
7032 goto out;
7033 status = decode_sequence(xdr, &res->seq_res, rqstp);
7034 if (status)
7035 goto out;
7036 status = decode_putfh(xdr);
7037 if (status)
7038 goto out;
7039 status = decode_getfh(xdr, res->fh);
7040 if (status)
7041 goto out;
7042 if (res->renew)
7043 status = decode_renew(xdr);
7044out:
7045 return status;
7046}
7047
Benny Halevy99fe60d2009-04-01 09:22:29 -04007048#if defined(CONFIG_NFS_V4_1)
7049/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007050 * Decode BIND_CONN_TO_SESSION response
7051 */
7052static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7053 struct xdr_stream *xdr,
7054 void *res)
7055{
7056 struct compound_hdr hdr;
7057 int status;
7058
7059 status = decode_compound_hdr(xdr, &hdr);
7060 if (!status)
7061 status = decode_bind_conn_to_session(xdr, res);
7062 return status;
7063}
7064
7065/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007066 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007067 */
Chuck Leverbf269552010-12-14 14:59:29 +00007068static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7069 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007070 void *res)
7071{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007072 struct compound_hdr hdr;
7073 int status;
7074
Chuck Leverbf269552010-12-14 14:59:29 +00007075 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007076 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007077 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007078 return status;
7079}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007080
7081/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007082 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007083 */
Chuck Leverbf269552010-12-14 14:59:29 +00007084static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7085 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04007086 struct nfs41_create_session_res *res)
7087{
Andy Adamsonfc931582009-04-01 09:22:31 -04007088 struct compound_hdr hdr;
7089 int status;
7090
Chuck Leverbf269552010-12-14 14:59:29 +00007091 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007092 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007093 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007094 return status;
7095}
7096
7097/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007098 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007099 */
Chuck Leverbf269552010-12-14 14:59:29 +00007100static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7101 struct xdr_stream *xdr,
7102 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007103{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007104 struct compound_hdr hdr;
7105 int status;
7106
Chuck Leverbf269552010-12-14 14:59:29 +00007107 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007108 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007109 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007110 return status;
7111}
7112
7113/*
Trond Myklebust66245532012-05-25 17:18:09 -04007114 * Decode DESTROY_CLIENTID response
7115 */
7116static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7117 struct xdr_stream *xdr,
7118 void *res)
7119{
7120 struct compound_hdr hdr;
7121 int status;
7122
7123 status = decode_compound_hdr(xdr, &hdr);
7124 if (!status)
7125 status = decode_destroy_clientid(xdr, res);
7126 return status;
7127}
7128
7129/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007130 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007131 */
Chuck Leverbf269552010-12-14 14:59:29 +00007132static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7133 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007134 struct nfs4_sequence_res *res)
7135{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007136 struct compound_hdr hdr;
7137 int status;
7138
Chuck Leverbf269552010-12-14 14:59:29 +00007139 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007140 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007141 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007142 return status;
7143}
7144
7145/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007146 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007147 */
Chuck Leverbf269552010-12-14 14:59:29 +00007148static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7149 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04007150 struct nfs4_get_lease_time_res *res)
7151{
Andy Adamson2050f0c2009-04-01 09:22:30 -04007152 struct compound_hdr hdr;
7153 int status;
7154
Chuck Leverbf269552010-12-14 14:59:29 +00007155 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007156 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007157 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007158 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007159 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007160 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007161 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007162 return status;
7163}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007164
7165/*
7166 * Decode RECLAIM_COMPLETE response
7167 */
Chuck Leverbf269552010-12-14 14:59:29 +00007168static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7169 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007170 struct nfs41_reclaim_complete_res *res)
7171{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007172 struct compound_hdr hdr;
7173 int status;
7174
Chuck Leverbf269552010-12-14 14:59:29 +00007175 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007176 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007177 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007178 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307179 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007180 return status;
7181}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007182
7183/*
7184 * Decode GETDEVINFO response
7185 */
Chuck Leverbf269552010-12-14 14:59:29 +00007186static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7187 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007188 struct nfs4_getdeviceinfo_res *res)
7189{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007190 struct compound_hdr hdr;
7191 int status;
7192
Chuck Leverbf269552010-12-14 14:59:29 +00007193 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007194 if (status != 0)
7195 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007196 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007197 if (status != 0)
7198 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007199 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007200out:
7201 return status;
7202}
7203
7204/*
7205 * Decode LAYOUTGET response
7206 */
Chuck Leverbf269552010-12-14 14:59:29 +00007207static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7208 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007209 struct nfs4_layoutget_res *res)
7210{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007211 struct compound_hdr hdr;
7212 int status;
7213
Chuck Leverbf269552010-12-14 14:59:29 +00007214 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007215 if (status)
7216 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007217 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007218 if (status)
7219 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007220 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007221 if (status)
7222 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007223 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007224out:
7225 return status;
7226}
Andy Adamson863a3c62011-03-23 13:27:54 +00007227
7228/*
Benny Halevycbe82602011-05-22 19:52:37 +03007229 * Decode LAYOUTRETURN response
7230 */
7231static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7232 struct xdr_stream *xdr,
7233 struct nfs4_layoutreturn_res *res)
7234{
7235 struct compound_hdr hdr;
7236 int status;
7237
7238 status = decode_compound_hdr(xdr, &hdr);
7239 if (status)
7240 goto out;
7241 status = decode_sequence(xdr, &res->seq_res, rqstp);
7242 if (status)
7243 goto out;
7244 status = decode_putfh(xdr);
7245 if (status)
7246 goto out;
7247 status = decode_layoutreturn(xdr, res);
7248out:
7249 return status;
7250}
7251
7252/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007253 * Decode LAYOUTCOMMIT response
7254 */
7255static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7256 struct xdr_stream *xdr,
7257 struct nfs4_layoutcommit_res *res)
7258{
7259 struct compound_hdr hdr;
7260 int status;
7261
7262 status = decode_compound_hdr(xdr, &hdr);
7263 if (status)
7264 goto out;
7265 status = decode_sequence(xdr, &res->seq_res, rqstp);
7266 if (status)
7267 goto out;
7268 status = decode_putfh(xdr);
7269 if (status)
7270 goto out;
7271 status = decode_layoutcommit(xdr, rqstp, res);
7272 if (status)
7273 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007274 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007275out:
7276 return status;
7277}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007278
7279/*
7280 * Decode SECINFO_NO_NAME response
7281 */
7282static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7283 struct xdr_stream *xdr,
7284 struct nfs4_secinfo_res *res)
7285{
7286 struct compound_hdr hdr;
7287 int status;
7288
7289 status = decode_compound_hdr(xdr, &hdr);
7290 if (status)
7291 goto out;
7292 status = decode_sequence(xdr, &res->seq_res, rqstp);
7293 if (status)
7294 goto out;
7295 status = decode_putrootfh(xdr);
7296 if (status)
7297 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007298 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007299out:
7300 return status;
7301}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007302
7303/*
7304 * Decode TEST_STATEID response
7305 */
7306static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7307 struct xdr_stream *xdr,
7308 struct nfs41_test_stateid_res *res)
7309{
7310 struct compound_hdr hdr;
7311 int status;
7312
7313 status = decode_compound_hdr(xdr, &hdr);
7314 if (status)
7315 goto out;
7316 status = decode_sequence(xdr, &res->seq_res, rqstp);
7317 if (status)
7318 goto out;
7319 status = decode_test_stateid(xdr, res);
7320out:
7321 return status;
7322}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007323
7324/*
7325 * Decode FREE_STATEID response
7326 */
7327static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7328 struct xdr_stream *xdr,
7329 struct nfs41_free_stateid_res *res)
7330{
7331 struct compound_hdr hdr;
7332 int status;
7333
7334 status = decode_compound_hdr(xdr, &hdr);
7335 if (status)
7336 goto out;
7337 status = decode_sequence(xdr, &res->seq_res, rqstp);
7338 if (status)
7339 goto out;
7340 status = decode_free_stateid(xdr, res);
7341out:
7342 return status;
7343}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007344#endif /* CONFIG_NFS_V4_1 */
7345
Chuck Lever573c4e12010-12-14 14:58:11 +00007346/**
7347 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7348 * the local page cache.
7349 * @xdr: XDR stream where entry resides
7350 * @entry: buffer to fill in with entry data
7351 * @plus: boolean indicating whether this should be a readdirplus entry
7352 *
7353 * Returns zero if successful, otherwise a negative errno value is
7354 * returned.
7355 *
7356 * This function is not invoked during READDIR reply decoding, but
7357 * rather whenever an application invokes the getdents(2) system call
7358 * on a directory already in our cache.
7359 */
7360int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7361 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007362{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007363 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007364 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007365 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007366 __be32 *p = xdr_inline_decode(xdr, 4);
7367 if (unlikely(!p))
7368 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007369 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007370 p = xdr_inline_decode(xdr, 4);
7371 if (unlikely(!p))
7372 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007373 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007374 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007375 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007376 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007377 }
7378
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007379 p = xdr_inline_decode(xdr, 12);
7380 if (unlikely(!p))
7381 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007382 entry->prev_cookie = entry->cookie;
7383 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007384 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007385
Trond Myklebust9af8c222010-10-24 11:52:55 -04007386 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007387 if (unlikely(!p))
7388 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007389 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007390
7391 /*
7392 * In case the server doesn't return an inode number,
7393 * we fake one here. (We don't use inode number 0,
7394 * since glibc seems to choke on it...)
7395 */
7396 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007397 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007398
Trond Myklebust9af8c222010-10-24 11:52:55 -04007399 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007400 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007401
Trond Myklebust256e48b2012-06-21 11:18:13 -04007402 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007403 goto out_overflow;
7404
Chuck Lever573c4e12010-12-14 14:58:11 +00007405 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007406 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007407 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007408 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7409 entry->ino = entry->fattr->mounted_on_fileid;
7410 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007411 entry->ino = entry->fattr->fileid;
7412
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007413 entry->d_type = DT_UNKNOWN;
7414 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7415 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7416
Chuck Lever573c4e12010-12-14 14:58:11 +00007417 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007418
7419out_overflow:
7420 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007421 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007422}
7423
7424/*
7425 * We need to translate between nfs status return values and
7426 * the local errno values which may not be the same.
7427 */
7428static struct {
7429 int stat;
7430 int errno;
7431} nfs_errtbl[] = {
7432 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007433 { NFS4ERR_PERM, -EPERM },
7434 { NFS4ERR_NOENT, -ENOENT },
7435 { NFS4ERR_IO, -errno_NFSERR_IO},
7436 { NFS4ERR_NXIO, -ENXIO },
7437 { NFS4ERR_ACCESS, -EACCES },
7438 { NFS4ERR_EXIST, -EEXIST },
7439 { NFS4ERR_XDEV, -EXDEV },
7440 { NFS4ERR_NOTDIR, -ENOTDIR },
7441 { NFS4ERR_ISDIR, -EISDIR },
7442 { NFS4ERR_INVAL, -EINVAL },
7443 { NFS4ERR_FBIG, -EFBIG },
7444 { NFS4ERR_NOSPC, -ENOSPC },
7445 { NFS4ERR_ROFS, -EROFS },
7446 { NFS4ERR_MLINK, -EMLINK },
7447 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7448 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7449 { NFS4ERR_DQUOT, -EDQUOT },
7450 { NFS4ERR_STALE, -ESTALE },
7451 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007452 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7453 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7454 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007455 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007456 { NFS4ERR_BADTYPE, -EBADTYPE },
7457 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007458 { NFS4ERR_SYMLINK, -ELOOP },
7459 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7460 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007461 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007462};
7463
7464/*
7465 * Convert an NFS error code to a local one.
7466 * This one is used jointly by NFSv2 and NFSv3.
7467 */
7468static int
David Howells0a8ea432006-08-22 20:06:08 -04007469nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007470{
7471 int i;
7472 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7473 if (nfs_errtbl[i].stat == stat)
7474 return nfs_errtbl[i].errno;
7475 }
7476 if (stat <= 10000 || stat > 10100) {
7477 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007478 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007479 }
7480 /* If we cannot translate the error, the recovery routines should
7481 * handle it.
7482 * Note: remaining NFSv4 error codes have values > 10000, so should
7483 * not conflict with native Linux error codes.
7484 */
Benny Halevy856dff32008-03-31 17:39:06 +03007485 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007486}
7487
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007488#ifdef CONFIG_NFS_V4_2
7489#include "nfs42xdr.c"
7490#endif /* CONFIG_NFS_V4_2 */
7491
Linus Torvalds1da177e2005-04-16 15:20:36 -07007492#define PROC(proc, argtype, restype) \
7493[NFSPROC4_CLNT_##proc] = { \
7494 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007495 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007496 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007497 .p_arglen = NFS4_##argtype##_sz, \
7498 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007499 .p_statidx = NFSPROC4_CLNT_##proc, \
7500 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007501}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007502
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007503#define STUB(proc) \
7504[NFSPROC4_CLNT_##proc] = { \
7505 .p_name = #proc, \
7506}
7507
Linus Torvalds1da177e2005-04-16 15:20:36 -07007508struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007509 PROC(READ, enc_read, dec_read),
7510 PROC(WRITE, enc_write, dec_write),
7511 PROC(COMMIT, enc_commit, dec_commit),
7512 PROC(OPEN, enc_open, dec_open),
7513 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7514 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7515 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7516 PROC(CLOSE, enc_close, dec_close),
7517 PROC(SETATTR, enc_setattr, dec_setattr),
7518 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7519 PROC(RENEW, enc_renew, dec_renew),
7520 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7521 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7522 PROC(LOCK, enc_lock, dec_lock),
7523 PROC(LOCKT, enc_lockt, dec_lockt),
7524 PROC(LOCKU, enc_locku, dec_locku),
7525 PROC(ACCESS, enc_access, dec_access),
7526 PROC(GETATTR, enc_getattr, dec_getattr),
7527 PROC(LOOKUP, enc_lookup, dec_lookup),
7528 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7529 PROC(REMOVE, enc_remove, dec_remove),
7530 PROC(RENAME, enc_rename, dec_rename),
7531 PROC(LINK, enc_link, dec_link),
7532 PROC(SYMLINK, enc_symlink, dec_symlink),
7533 PROC(CREATE, enc_create, dec_create),
7534 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7535 PROC(STATFS, enc_statfs, dec_statfs),
7536 PROC(READLINK, enc_readlink, dec_readlink),
7537 PROC(READDIR, enc_readdir, dec_readdir),
7538 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7539 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7540 PROC(GETACL, enc_getacl, dec_getacl),
7541 PROC(SETACL, enc_setacl, dec_setacl),
7542 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7543 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007544 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007545 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007546#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007547 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7548 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7549 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7550 PROC(SEQUENCE, enc_sequence, dec_sequence),
7551 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7552 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7553 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7554 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007555 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007556 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007557 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007558 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007559 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007560 STUB(GETDEVICELIST),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007561 PROC(BIND_CONN_TO_SESSION,
7562 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007563 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007564#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007565#ifdef CONFIG_NFS_V4_2
7566 PROC(SEEK, enc_seek, dec_seek),
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007567 PROC(ALLOCATE, enc_allocate, dec_allocate),
Anna Schumaker624bd5b2014-11-25 13:18:16 -05007568 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
Trond Myklebustbe3a5d22015-06-23 19:51:55 +08007569 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
Peng Tao36022772015-09-26 02:24:34 +08007570 PROC(CLONE, enc_clone, dec_clone),
Anna Schumaker2e724482013-05-21 16:53:03 -04007571 PROC(COPY, enc_copy, dec_copy),
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007572#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007573};
7574
Trond Myklebusta613fa12012-01-20 13:53:56 -05007575const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007576 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007577 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007578 .procs = nfs4_procedures
7579};
7580
7581/*
7582 * Local variables:
7583 * c-basic-offset: 8
7584 * End:
7585 */