blob: 84fdcf27138c1ae128ca234ba90c99187a597fe4 [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 Myklebust586f1c32016-11-15 15:03:33 -0500713 encode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100714 encode_delegreturn_maxsz + \
715 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 decode_sequence_maxsz + \
Trond Myklebustd8434d4c2016-11-16 13:54:00 -0500718 decode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500719 decode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100720 decode_delegreturn_maxsz + \
721 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000722#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400723 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000724 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400725 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000726#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400727 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000728 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400729 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000730#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400731 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000732 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400733 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000734#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400735 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000736 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400737 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400738#define NFS4_enc_fs_locations_sz \
739 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400740 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400741 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400742 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400743 encode_fs_locations_maxsz + \
744 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400745#define NFS4_dec_fs_locations_sz \
746 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400747 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400748 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400749 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400750 decode_fs_locations_maxsz + \
751 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000752#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
753 encode_sequence_maxsz + \
754 encode_putfh_maxsz + \
755 encode_secinfo_maxsz)
756#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
757 decode_sequence_maxsz + \
758 decode_putfh_maxsz + \
759 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400760#define NFS4_enc_fsid_present_sz \
761 (compound_encode_hdr_maxsz + \
762 encode_sequence_maxsz + \
763 encode_putfh_maxsz + \
764 encode_getfh_maxsz + \
765 encode_renew_maxsz)
766#define NFS4_dec_fsid_present_sz \
767 (compound_decode_hdr_maxsz + \
768 decode_sequence_maxsz + \
769 decode_putfh_maxsz + \
770 decode_getfh_maxsz + \
771 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400772#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400773#define NFS4_enc_bind_conn_to_session_sz \
774 (compound_encode_hdr_maxsz + \
775 encode_bind_conn_to_session_maxsz)
776#define NFS4_dec_bind_conn_to_session_sz \
777 (compound_decode_hdr_maxsz + \
778 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400779#define NFS4_enc_exchange_id_sz \
780 (compound_encode_hdr_maxsz + \
781 encode_exchange_id_maxsz)
782#define NFS4_dec_exchange_id_sz \
783 (compound_decode_hdr_maxsz + \
784 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400785#define NFS4_enc_create_session_sz \
786 (compound_encode_hdr_maxsz + \
787 encode_create_session_maxsz)
788#define NFS4_dec_create_session_sz \
789 (compound_decode_hdr_maxsz + \
790 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400791#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
792 encode_destroy_session_maxsz)
793#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
794 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400795#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
796 encode_destroy_clientid_maxsz)
797#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
798 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400799#define NFS4_enc_sequence_sz \
800 (compound_decode_hdr_maxsz + \
801 encode_sequence_maxsz)
802#define NFS4_dec_sequence_sz \
803 (compound_decode_hdr_maxsz + \
804 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400805#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
806 encode_sequence_maxsz + \
807 encode_putrootfh_maxsz + \
808 encode_fsinfo_maxsz)
809#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
810 decode_sequence_maxsz + \
811 decode_putrootfh_maxsz + \
812 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500813#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
814 encode_sequence_maxsz + \
815 encode_reclaim_complete_maxsz)
816#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
817 decode_sequence_maxsz + \
818 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400819#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
820 encode_sequence_maxsz +\
821 encode_getdeviceinfo_maxsz)
822#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
823 decode_sequence_maxsz + \
824 decode_getdeviceinfo_maxsz)
825#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
826 encode_sequence_maxsz + \
827 encode_putfh_maxsz + \
828 encode_layoutget_maxsz)
829#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
830 decode_sequence_maxsz + \
831 decode_putfh_maxsz + \
832 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000833#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
834 encode_sequence_maxsz +\
835 encode_putfh_maxsz + \
836 encode_layoutcommit_maxsz + \
837 encode_getattr_maxsz)
838#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
839 decode_sequence_maxsz + \
840 decode_putfh_maxsz + \
841 decode_layoutcommit_maxsz + \
842 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300843#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
844 encode_sequence_maxsz + \
845 encode_putfh_maxsz + \
846 encode_layoutreturn_maxsz)
847#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
848 decode_sequence_maxsz + \
849 decode_putfh_maxsz + \
850 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400851#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
852 encode_sequence_maxsz + \
853 encode_putrootfh_maxsz +\
854 encode_secinfo_no_name_maxsz)
855#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
856 decode_sequence_maxsz + \
857 decode_putrootfh_maxsz + \
858 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400859#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
860 encode_sequence_maxsz + \
861 encode_test_stateid_maxsz)
862#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
863 decode_sequence_maxsz + \
864 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400865#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
866 encode_sequence_maxsz + \
867 encode_free_stateid_maxsz)
868#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
869 decode_sequence_maxsz + \
870 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500871
872const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
873 compound_encode_hdr_maxsz +
874 encode_sequence_maxsz +
875 encode_putfh_maxsz +
876 encode_getattr_maxsz) *
877 XDR_UNIT);
878
879const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
880 compound_decode_hdr_maxsz +
881 decode_sequence_maxsz +
882 decode_putfh_maxsz) *
883 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400884
885const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
886 compound_decode_hdr_maxsz +
887 decode_sequence_maxsz) *
888 XDR_UNIT);
889EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400890#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Trond Myklebustbca79472009-03-11 14:10:26 -0400892static const umode_t nfs_type2fmt[] = {
893 [NF4BAD] = 0,
894 [NF4REG] = S_IFREG,
895 [NF4DIR] = S_IFDIR,
896 [NF4BLK] = S_IFBLK,
897 [NF4CHR] = S_IFCHR,
898 [NF4LNK] = S_IFLNK,
899 [NF4SOCK] = S_IFSOCK,
900 [NF4FIFO] = S_IFIFO,
901 [NF4ATTRDIR] = 0,
902 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903};
904
905struct compound_hdr {
906 int32_t status;
907 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500908 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 uint32_t taglen;
910 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400911 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400912 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913};
914
Benny Halevy13c65ce2009-08-14 17:19:25 +0300915static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
916{
917 __be32 *p = xdr_reserve_space(xdr, nbytes);
918 BUG_ON(!p);
919 return p;
920}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Trond Myklebustcb17e552012-03-04 18:13:56 -0500922static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
923{
924 __be32 *p;
925
926 p = xdr_reserve_space(xdr, len);
927 xdr_encode_opaque_fixed(p, buf, len);
928}
929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
931{
Al Viro8687b632006-10-19 23:28:48 -0700932 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500934 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 xdr_encode_opaque(p, str, len);
936}
937
Trond Myklebust4ade9822012-03-04 18:13:57 -0500938static void encode_uint32(struct xdr_stream *xdr, u32 n)
939{
940 __be32 *p;
941
942 p = reserve_space(xdr, 4);
943 *p = cpu_to_be32(n);
944}
945
Trond Myklebustff2eb682012-03-05 11:40:12 -0500946static void encode_uint64(struct xdr_stream *xdr, u64 n)
947{
948 __be32 *p;
949
950 p = reserve_space(xdr, 8);
951 xdr_encode_hyper(p, n);
952}
953
Trond Myklebust4ade9822012-03-04 18:13:57 -0500954static void encode_nfs4_seqid(struct xdr_stream *xdr,
955 const struct nfs_seqid *seqid)
956{
Trond Myklebusta6796412015-01-23 19:04:44 -0500957 if (seqid != NULL)
958 encode_uint32(xdr, seqid->sequence->counter);
959 else
960 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500961}
962
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400963static void encode_compound_hdr(struct xdr_stream *xdr,
964 struct rpc_rqst *req,
965 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
Al Viro8687b632006-10-19 23:28:48 -0700967 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400968 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400969
970 /* initialize running count of expected bytes in reply.
971 * NOTE: the replied tag SHOULD be the same is the one sent,
972 * but this is not required as a MUST for the server to do so. */
973 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Trond Myklebust7fc38842012-10-15 11:51:21 -0400975 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500976 encode_string(xdr, hdr->taglen, hdr->tag);
977 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300978 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500979 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300980 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500981}
982
Trond Myklebustab19b482012-03-04 18:13:57 -0500983static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
984 uint32_t replen,
985 struct compound_hdr *hdr)
986{
987 encode_uint32(xdr, op);
988 hdr->nops++;
989 hdr->replen += replen;
990}
991
Andy Adamsond0179312008-12-23 16:06:17 -0500992static void encode_nops(struct compound_hdr *hdr)
993{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400994 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500995 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996}
997
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500998static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
999{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001000 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001001}
1002
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1004{
Trond Myklebustcb17e552012-03-04 18:13:56 -05001005 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006}
1007
David Quigleyaa9c2662013-05-22 12:50:44 -04001008static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1009 const struct nfs4_label *label,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001010 const struct nfs_server *server,
1011 bool excl_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012{
1013 char owner_name[IDMAP_NAMESZ];
1014 char owner_group[IDMAP_NAMESZ];
1015 int owner_namelen = 0;
1016 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001017 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001018 unsigned i;
1019 uint32_t len = 0;
1020 uint32_t bmval_len;
1021 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
1023 /*
1024 * We reserve enough space to write the entire attribute buffer at once.
1025 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001026 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1027 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001028 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001030 if (iap->ia_valid & ATTR_SIZE) {
1031 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001033 }
1034 if (iap->ia_valid & ATTR_MODE) {
1035 bmval[1] |= FATTR4_WORD1_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 len += 4;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001037 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001039 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001041 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001042 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 /* XXX */
1044 strcpy(owner_name, "nobody");
1045 owner_namelen = sizeof("nobody") - 1;
1046 /* goto out; */
1047 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001048 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1050 }
1051 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001052 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001054 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001055 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 strcpy(owner_group, "nobody");
1057 owner_grouplen = sizeof("nobody") - 1;
1058 /* goto out; */
1059 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001060 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1062 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001064 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1065 len += 16;
1066 } else if (iap->ia_valid & ATTR_ATIME) {
1067 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1068 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 }
1070 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001071 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1072 len += 16;
1073 } else if (iap->ia_valid & ATTR_MTIME) {
1074 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1075 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001077
1078 if (excl_check) {
1079 const u32 *excl_bmval = server->exclcreat_bitmask;
1080 bmval[0] &= excl_bmval[0];
1081 bmval[1] &= excl_bmval[1];
1082 bmval[2] &= excl_bmval[2];
1083
1084 if (!(excl_bmval[2] & FATTR4_WORD2_SECURITY_LABEL))
1085 label = NULL;
1086 }
1087
David Quigleyaa9c2662013-05-22 12:50:44 -04001088 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001089 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1090 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1091 }
1092
1093 if (bmval[2] != 0)
1094 bmval_len = 3;
1095 else if (bmval[1] != 0)
1096 bmval_len = 2;
1097 else
1098 bmval_len = 1;
1099
1100 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1101
1102 *p++ = cpu_to_be32(bmval_len);
1103 for (i = 0; i < bmval_len; i++)
1104 *p++ = cpu_to_be32(bmval[i]);
1105 *p++ = cpu_to_be32(len);
1106
1107 if (bmval[0] & FATTR4_WORD0_SIZE)
1108 p = xdr_encode_hyper(p, iap->ia_size);
1109 if (bmval[1] & FATTR4_WORD1_MODE)
1110 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1111 if (bmval[1] & FATTR4_WORD1_OWNER)
1112 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1113 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1114 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1115 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1116 if (iap->ia_valid & ATTR_ATIME_SET) {
1117 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1118 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1119 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1120 } else
1121 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1122 }
1123 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1124 if (iap->ia_valid & ATTR_MTIME_SET) {
1125 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1126 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1127 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1128 } else
1129 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1130 }
1131 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001132 *p++ = cpu_to_be32(label->lfs);
1133 *p++ = cpu_to_be32(label->pi);
1134 *p++ = cpu_to_be32(label->len);
1135 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1136 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001137
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001141static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001143 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1144 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145}
1146
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001147static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148{
Trond Myklebustab19b482012-03-04 18:13:57 -05001149 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001150 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001151 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152}
1153
Fred Isaman0b7c0152012-04-20 14:47:39 -04001154static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155{
Al Viro8687b632006-10-19 23:28:48 -07001156 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001157
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001158 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1159 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001160 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001161 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162}
1163
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001164static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165{
Al Viro8687b632006-10-19 23:28:48 -07001166 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001167
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001168 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1169 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
1171 switch (create->ftype) {
1172 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001173 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001174 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001175 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1176 create->u.symlink.len);
1177 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 break;
1179
1180 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001181 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001182 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001183 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 break;
1185
1186 default:
1187 break;
1188 }
1189
Benny Halevy811652b2009-08-14 17:19:34 +03001190 encode_string(xdr, create->name->len, create->name->name);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001191 encode_attrs(xdr, create->attrs, create->label, create->server, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192}
1193
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001194static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195{
Andy Adamson05d564f2008-12-23 16:06:15 -05001196 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001198 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1199 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001200 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001201 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202}
1203
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001204static 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 -07001205{
Andy Adamson05d564f2008-12-23 16:06:15 -05001206 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001208 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1209 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001210 *p++ = cpu_to_be32(2);
1211 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001212 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213}
1214
Fred Isamandae100c2011-07-30 20:52:37 -04001215static void
1216encode_getattr_three(struct xdr_stream *xdr,
1217 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1218 struct compound_hdr *hdr)
1219{
1220 __be32 *p;
1221
Trond Myklebustab19b482012-03-04 18:13:57 -05001222 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001223 if (bm2) {
1224 p = reserve_space(xdr, 16);
1225 *p++ = cpu_to_be32(3);
1226 *p++ = cpu_to_be32(bm0);
1227 *p++ = cpu_to_be32(bm1);
1228 *p = cpu_to_be32(bm2);
1229 } else if (bm1) {
1230 p = reserve_space(xdr, 12);
1231 *p++ = cpu_to_be32(2);
1232 *p++ = cpu_to_be32(bm0);
1233 *p = cpu_to_be32(bm1);
1234 } else {
1235 p = reserve_space(xdr, 8);
1236 *p++ = cpu_to_be32(1);
1237 *p = cpu_to_be32(bm0);
1238 }
Fred Isamandae100c2011-07-30 20:52:37 -04001239}
1240
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001241static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242{
David Quigleya09df2c2013-05-22 12:50:41 -04001243 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1244 bitmask[1] & nfs4_fattr_bitmap[1],
1245 bitmask[2] & nfs4_fattr_bitmap[2],
1246 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247}
1248
Andy Adamson88034c32012-05-23 05:02:34 -04001249static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001250 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001251 struct compound_hdr *hdr)
1252{
1253 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001254 bitmask[0] & open_bitmap[0],
1255 bitmask[1] & open_bitmap[1],
1256 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001257 hdr);
1258}
1259
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001260static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261{
Fred Isamandae100c2011-07-30 20:52:37 -04001262 encode_getattr_three(xdr,
1263 bitmask[0] & nfs4_fsinfo_bitmap[0],
1264 bitmask[1] & nfs4_fsinfo_bitmap[1],
1265 bitmask[2] & nfs4_fsinfo_bitmap[2],
1266 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267}
1268
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001269static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001270{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001271 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1272 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001273}
1274
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001275static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276{
Trond Myklebustab19b482012-03-04 18:13:57 -05001277 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278}
1279
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001280static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281{
Trond Myklebustab19b482012-03-04 18:13:57 -05001282 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001283 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284}
1285
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001286static inline int nfs4_lock_type(struct file_lock *fl, int block)
1287{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001288 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001289 return block ? NFS4_READW_LT : NFS4_READ_LT;
1290 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1291}
1292
1293static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1294{
1295 if (fl->fl_end == OFFSET_MAX)
1296 return ~(uint64_t)0;
1297 return fl->fl_end - fl->fl_start + 1;
1298}
1299
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001300static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1301{
1302 __be32 *p;
1303
Trond Myklebustd035c362010-12-21 10:45:27 -05001304 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001305 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001306 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001307 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001308 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001309 xdr_encode_hyper(p, lowner->id);
1310}
1311
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312/*
1313 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1314 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1315 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001316static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317{
Al Viro8687b632006-10-19 23:28:48 -07001318 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001320 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1321 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001322 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1323 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001324 p = xdr_encode_hyper(p, args->fl->fl_start);
1325 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001326 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001327 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001328 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001329 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001330 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001331 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 }
1333 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001334 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001335 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337}
1338
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001339static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340{
Al Viro8687b632006-10-19 23:28:48 -07001341 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001343 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1344 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001345 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001346 p = xdr_encode_hyper(p, args->fl->fl_start);
1347 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001348 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349}
1350
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001351static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352{
Al Viro8687b632006-10-19 23:28:48 -07001353 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001355 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1356 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001357 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001358 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001359 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001360 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001361 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362}
1363
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001364static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1365{
Trond Myklebustab19b482012-03-04 18:13:57 -05001366 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001367 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001368}
1369
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001370static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371{
Trond Myklebustab19b482012-03-04 18:13:57 -05001372 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001373 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374}
1375
Trond Myklebust6ae37332015-01-30 14:21:14 -05001376static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377{
Al Viro8687b632006-10-19 23:28:48 -07001378 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
Benny Halevy13c65ce2009-08-14 17:19:25 +03001380 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001381 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001382 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383}
1384
1385static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1386{
Al Viro8687b632006-10-19 23:28:48 -07001387 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 /*
1389 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1390 * owner 4 = 32
1391 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001392 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001393 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001394 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001395 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001396 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001397 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001398 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001399 *p++ = cpu_to_be32(arg->id.uniquifier);
1400 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401}
1402
1403static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1404{
Al Viro8687b632006-10-19 23:28:48 -07001405 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Benny Halevy13c65ce2009-08-14 17:19:25 +03001407 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001408 switch(arg->createmode) {
1409 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001410 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001411 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false);
Andy Adamson05d564f2008-12-23 16:06:15 -05001412 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001413 case NFS4_CREATE_GUARDED:
1414 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001415 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001416 break;
1417 case NFS4_CREATE_EXCLUSIVE:
1418 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1419 encode_nfs4_verifier(xdr, &arg->u.verifier);
1420 break;
1421 case NFS4_CREATE_EXCLUSIVE4_1:
1422 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1423 encode_nfs4_verifier(xdr, &arg->u.verifier);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001424 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 }
1426}
1427
1428static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1429{
Al Viro8687b632006-10-19 23:28:48 -07001430 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
Benny Halevy13c65ce2009-08-14 17:19:25 +03001432 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001434 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001435 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001436 break;
1437 default:
Benny Halevy34558512009-08-14 17:19:30 +03001438 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001439 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 }
1441}
1442
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001443static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
Al Viro8687b632006-10-19 23:28:48 -07001445 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Benny Halevy13c65ce2009-08-14 17:19:25 +03001447 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001449 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001450 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001451 break;
1452 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001453 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001454 break;
1455 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001456 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001457 break;
1458 default:
1459 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 }
1461}
1462
1463static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1464{
Al Viro8687b632006-10-19 23:28:48 -07001465 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Benny Halevy13c65ce2009-08-14 17:19:25 +03001467 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001468 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 encode_string(xdr, name->len, name->name);
1470}
1471
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001472static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473{
Al Viro8687b632006-10-19 23:28:48 -07001474 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
Benny Halevy13c65ce2009-08-14 17:19:25 +03001476 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001477 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 encode_delegation_type(xdr, type);
1479}
1480
1481static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1482{
Al Viro8687b632006-10-19 23:28:48 -07001483 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001485 p = reserve_space(xdr, 4);
1486 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1487 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 encode_string(xdr, name->len, name->name);
1489}
1490
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001491static inline void encode_claim_fh(struct xdr_stream *xdr)
1492{
1493 __be32 *p;
1494
1495 p = reserve_space(xdr, 4);
1496 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1497}
1498
1499static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1500{
1501 __be32 *p;
1502
1503 p = reserve_space(xdr, 4);
1504 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1505 encode_nfs4_stateid(xdr, stateid);
1506}
1507
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001508static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509{
Trond Myklebustab19b482012-03-04 18:13:57 -05001510 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 encode_openhdr(xdr, arg);
1512 encode_opentype(xdr, arg);
1513 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001514 case NFS4_OPEN_CLAIM_NULL:
1515 encode_claim_null(xdr, arg->name);
1516 break;
1517 case NFS4_OPEN_CLAIM_PREVIOUS:
1518 encode_claim_previous(xdr, arg->u.delegation_type);
1519 break;
1520 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1521 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1522 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001523 case NFS4_OPEN_CLAIM_FH:
1524 encode_claim_fh(xdr);
1525 break;
1526 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1527 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1528 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001529 default:
1530 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532}
1533
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001534static 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 -07001535{
Trond Myklebustab19b482012-03-04 18:13:57 -05001536 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001537 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001538 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539}
1540
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001541static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542{
Trond Myklebustab19b482012-03-04 18:13:57 -05001543 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001544 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001545 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001546 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547}
1548
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001549static void
Andy Adamsond0179312008-12-23 16:06:17 -05001550encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
Trond Myklebustab19b482012-03-04 18:13:57 -05001552 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001553 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554}
1555
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001556static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
Trond Myklebustab19b482012-03-04 18:13:57 -05001558 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559}
1560
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001561static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1562 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563{
Al Viro8687b632006-10-19 23:28:48 -07001564 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
Trond Myklebustab19b482012-03-04 18:13:57 -05001566 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001567 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
Benny Halevy13c65ce2009-08-14 17:19:25 +03001569 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001570 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001571 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572}
1573
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001574static 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 -07001575{
David Quigleyaa9c2662013-05-22 12:50:44 -04001576 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001577 FATTR4_WORD0_RDATTR_ERROR,
1578 FATTR4_WORD1_MOUNTED_ON_FILEID,
1579 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001580 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001581 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001582 uint32_t attrlen = 0;
1583 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001585 if (readdir->plus) {
1586 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001587 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001588 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1589 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1590 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1591 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001592 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001593 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001594 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001595 /* Use mounted_on_fileid only if the server supports it */
1596 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1597 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001598 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1599 attrs[i] &= readdir->bitmask[i];
1600 if (attrs[i] != 0)
1601 attrlen = i+1;
1602 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001603
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001604 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001605 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001606 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001607 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001608 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001609 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001610 *p++ = cpu_to_be32(attrlen);
1611 for (i = 0; i < attrlen; i++)
1612 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001613 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001614
1615 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001616 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001617 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001618 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001619 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001620 attrs[1] & readdir->bitmask[1],
1621 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622}
1623
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001624static 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 -07001625{
Trond Myklebustab19b482012-03-04 18:13:57 -05001626 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627}
1628
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001629static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630{
Trond Myklebustab19b482012-03-04 18:13:57 -05001631 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001632 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633}
1634
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001635static 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 -07001636{
Trond Myklebustab19b482012-03-04 18:13:57 -05001637 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001638 encode_string(xdr, oldname->len, oldname->name);
1639 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640}
1641
Chuck Leverbb4dae52012-03-01 17:01:48 -05001642static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1643 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001645 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001646 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647}
1648
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001649static void
Andy Adamsond0179312008-12-23 16:06:17 -05001650encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001651{
Trond Myklebustab19b482012-03-04 18:13:57 -05001652 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001653}
1654
Chuck Lever9f06c712010-12-14 14:59:18 +00001655static void
Andy Adamsond0179312008-12-23 16:06:17 -05001656encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001657{
Al Viro8687b632006-10-19 23:28:48 -07001658 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001659
Trond Myklebustab19b482012-03-04 18:13:57 -05001660 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001661 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001662 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001663 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001664 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001665 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001666 *p = cpu_to_be32(arg->acl_len);
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01001667 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001668}
1669
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001670static void
Andy Adamsond0179312008-12-23 16:06:17 -05001671encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672{
Trond Myklebustab19b482012-03-04 18:13:57 -05001673 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674}
1675
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001676static 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 -07001677{
Trond Myklebustab19b482012-03-04 18:13:57 -05001678 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001679 encode_nfs4_stateid(xdr, &arg->stateid);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001680 encode_attrs(xdr, arg->iap, arg->label, server, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681}
1682
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001683static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684{
Al Viro8687b632006-10-19 23:28:48 -07001685 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686
Trond Myklebust70019512012-03-04 20:49:32 -05001687 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001688 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
Jeff Layton3a6bb732015-06-09 19:43:57 -04001690 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1691 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001692 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001693 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1695 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001696 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001697 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698}
1699
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001700static 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 -07001701{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001702 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1703 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001704 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001705 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706}
1707
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001708static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1709 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710{
Al Viro8687b632006-10-19 23:28:48 -07001711 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712
Trond Myklebustab19b482012-03-04 18:13:57 -05001713 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001714 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
Benny Halevy13c65ce2009-08-14 17:19:25 +03001716 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001717 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001718 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001719 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
1721 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722}
1723
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001724static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725{
Trond Myklebustab19b482012-03-04 18:13:57 -05001726 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001727 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001729
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001730static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1731{
Trond Myklebustab19b482012-03-04 18:13:57 -05001732 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001733 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001734}
1735
Benny Halevy99fe60d2009-04-01 09:22:29 -04001736#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001737/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001738static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08001739 struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001740 struct compound_hdr *hdr)
1741{
1742 __be32 *p;
1743
1744 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1745 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001746 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001747 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001748 *p++ = cpu_to_be32(args->dir);
1749 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001750}
1751
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001752static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1753{
1754 unsigned int i;
1755 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1756 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1757 encode_uint32(xdr, op_map->u.words[i]);
1758}
1759
Benny Halevy99fe60d2009-04-01 09:22:29 -04001760static void encode_exchange_id(struct xdr_stream *xdr,
1761 struct nfs41_exchange_id_args *args,
1762 struct compound_hdr *hdr)
1763{
1764 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001765 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001766 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001767
Trond Myklebust70019512012-03-04 20:49:32 -05001768 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001769 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001770
Jeff Layton3a6bb732015-06-09 19:43:57 -04001771 encode_string(xdr, strlen(args->client->cl_owner_id),
1772 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001773
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001774 encode_uint32(xdr, args->flags);
1775 encode_uint32(xdr, args->state_protect.how);
1776
1777 switch (args->state_protect.how) {
1778 case SP4_NONE:
1779 break;
1780 case SP4_MACH_CRED:
1781 encode_op_map(xdr, &args->state_protect.enforce);
1782 encode_op_map(xdr, &args->state_protect.allow);
1783 break;
1784 default:
1785 WARN_ON_ONCE(1);
1786 break;
1787 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001788
1789 if (send_implementation_id &&
1790 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1791 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001792 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001793 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1794 utsname()->sysname, utsname()->release,
1795 utsname()->version, utsname()->machine);
1796
1797 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001798 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001799
1800 encode_string(xdr,
1801 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1802 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1803 encode_string(xdr, len, impl_name);
1804 /* just send zeros for nii_date - the date is in nii_name */
1805 p = reserve_space(xdr, 12);
1806 p = xdr_encode_hyper(p, 0);
1807 *p = cpu_to_be32(0);
1808 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001809 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001810}
Andy Adamsonfc931582009-04-01 09:22:31 -04001811
1812static void encode_create_session(struct xdr_stream *xdr,
1813 struct nfs41_create_session_args *args,
1814 struct compound_hdr *hdr)
1815{
1816 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001817 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001818 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001819 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001820 u32 max_resp_sz_cached;
1821
1822 /*
1823 * Assumes OPEN is the biggest non-idempotent compound.
1824 * 2 is the verifier.
1825 */
1826 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1827 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001828
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001829 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001830 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001831 p = xdr_encode_hyper(p, args->clientid);
1832 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001833 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001834
Andy Adamsonfc931582009-04-01 09:22:31 -04001835 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001836 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001837 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1838 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001839 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001840 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1841 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1842 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001843
1844 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001845 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001846 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1847 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1848 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1849 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1850 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1851 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001852
Benny Halevye75bc1c2009-08-14 17:18:54 +03001853 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001854 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001855 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001856
1857 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001858 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001859 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001860 *p++ = cpu_to_be32(0); /* UID */
1861 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001862 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001863}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001864
1865static void encode_destroy_session(struct xdr_stream *xdr,
1866 struct nfs4_session *session,
1867 struct compound_hdr *hdr)
1868{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001869 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1870 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001871}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001872
Trond Myklebust66245532012-05-25 17:18:09 -04001873static void encode_destroy_clientid(struct xdr_stream *xdr,
1874 uint64_t clientid,
1875 struct compound_hdr *hdr)
1876{
1877 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1878 encode_uint64(xdr, clientid);
1879}
1880
Ricardo Labiaga180197532009-12-05 16:08:40 -05001881static void encode_reclaim_complete(struct xdr_stream *xdr,
1882 struct nfs41_reclaim_complete_args *args,
1883 struct compound_hdr *hdr)
1884{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001885 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1886 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001887}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001888#endif /* CONFIG_NFS_V4_1 */
1889
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001890static void encode_sequence(struct xdr_stream *xdr,
1891 const struct nfs4_sequence_args *args,
1892 struct compound_hdr *hdr)
1893{
1894#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001895 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001896 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001897 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001898 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001899
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001900 tp = slot->table;
1901 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001902 if (!session)
1903 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001904
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001905 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001906
1907 /*
1908 * Sessionid + seqid + slotid + max slotid + cache_this
1909 */
1910 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1911 "max_slotid=%d cache_this=%d\n",
1912 __func__,
1913 ((u32 *)session->sess_id.data)[0],
1914 ((u32 *)session->sess_id.data)[1],
1915 ((u32 *)session->sess_id.data)[2],
1916 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001917 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001918 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001919 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001920 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001921 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001922 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001923 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001924 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001925#endif /* CONFIG_NFS_V4_1 */
1926}
1927
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001928#ifdef CONFIG_NFS_V4_1
1929static void
1930encode_getdeviceinfo(struct xdr_stream *xdr,
1931 const struct nfs4_getdeviceinfo_args *args,
1932 struct compound_hdr *hdr)
1933{
1934 __be32 *p;
1935
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001936 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001937 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001938 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1939 NFS4_DEVICEID4_SIZE);
1940 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001941 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001942
1943 p = reserve_space(xdr, 4 + 4);
1944 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001945 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001946}
1947
1948static void
1949encode_layoutget(struct xdr_stream *xdr,
1950 const struct nfs4_layoutget_args *args,
1951 struct compound_hdr *hdr)
1952{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001953 __be32 *p;
1954
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001955 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1956 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001957 *p++ = cpu_to_be32(0); /* Signal layout available */
1958 *p++ = cpu_to_be32(args->type);
1959 *p++ = cpu_to_be32(args->range.iomode);
1960 p = xdr_encode_hyper(p, args->range.offset);
1961 p = xdr_encode_hyper(p, args->range.length);
1962 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001963 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001964 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001965
1966 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1967 __func__,
1968 args->type,
1969 args->range.iomode,
1970 (unsigned long)args->range.offset,
1971 (unsigned long)args->range.length,
1972 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001973}
Andy Adamson863a3c62011-03-23 13:27:54 +00001974
1975static int
1976encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001977 struct inode *inode,
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001978 struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001979 struct compound_hdr *hdr)
1980{
1981 __be32 *p;
1982
1983 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1984 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1985
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001986 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1987 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001988 /* Only whole file layouts */
1989 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001990 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001991 *p = cpu_to_be32(0); /* reclaim */
1992 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04001993 if (args->lastbytewritten != U64_MAX) {
1994 p = reserve_space(xdr, 20);
1995 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1996 p = xdr_encode_hyper(p, args->lastbytewritten);
1997 } else {
1998 p = reserve_space(xdr, 12);
1999 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2000 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002001 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2002 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002003
Christoph Hellwig5f919c92014-08-21 11:09:25 -05002004 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
Benny Halevyac7db722011-05-22 19:53:48 +03002005 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2006 NFS_I(inode)->layout, xdr, args);
Christoph Hellwig5f919c92014-08-21 11:09:25 -05002007 } else {
2008 encode_uint32(xdr, args->layoutupdate_len);
2009 if (args->layoutupdate_pages) {
2010 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2011 args->layoutupdate_len);
2012 }
2013 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002014
Andy Adamson863a3c62011-03-23 13:27:54 +00002015 return 0;
2016}
Benny Halevycbe82602011-05-22 19:52:37 +03002017
2018static void
2019encode_layoutreturn(struct xdr_stream *xdr,
2020 const struct nfs4_layoutreturn_args *args,
2021 struct compound_hdr *hdr)
2022{
Trond Myklebust94e5c572016-09-15 18:49:52 -04002023 const struct pnfs_layoutdriver_type *lr_ops = NFS_SERVER(args->inode)->pnfs_curr_ld;
Benny Halevycbe82602011-05-22 19:52:37 +03002024 __be32 *p;
2025
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002026 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2027 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002028 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2029 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002030 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002031 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002032 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002033 p = xdr_encode_hyper(p, args->range.offset);
2034 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002035 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002036 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002037 spin_unlock(&args->inode->i_lock);
Trond Myklebust94e5c572016-09-15 18:49:52 -04002038 if (lr_ops->encode_layoutreturn)
2039 lr_ops->encode_layoutreturn(xdr, args);
2040 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002041 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002042}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002043
2044static int
2045encode_secinfo_no_name(struct xdr_stream *xdr,
2046 const struct nfs41_secinfo_no_name_args *args,
2047 struct compound_hdr *hdr)
2048{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002049 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2050 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002051 return 0;
2052}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002053
2054static void encode_test_stateid(struct xdr_stream *xdr,
2055 struct nfs41_test_stateid_args *args,
2056 struct compound_hdr *hdr)
2057{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002058 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2059 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002060 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002061}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002062
2063static void encode_free_stateid(struct xdr_stream *xdr,
2064 struct nfs41_free_stateid_args *args,
2065 struct compound_hdr *hdr)
2066{
Trond Myklebustab19b482012-03-04 18:13:57 -05002067 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002068 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002069}
Trond Myklebustcf805162016-11-15 14:56:07 -05002070#else
2071static inline void
2072encode_layoutreturn(struct xdr_stream *xdr,
2073 const struct nfs4_layoutreturn_args *args,
2074 struct compound_hdr *hdr)
2075{
2076}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002077#endif /* CONFIG_NFS_V4_1 */
2078
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079/*
2080 * END OF "GENERIC" ENCODE ROUTINES.
2081 */
2082
Benny Halevy66cc0422009-04-01 09:22:10 -04002083static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2084{
2085#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002086 struct nfs4_session *session = args->sa_slot->table->session;
2087 if (session)
2088 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002089#endif /* CONFIG_NFS_V4_1 */
2090 return 0;
2091}
2092
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093/*
2094 * Encode an ACCESS request
2095 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002096static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2097 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002100 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
Chuck Lever9f06c712010-12-14 14:59:18 +00002103 encode_compound_hdr(xdr, req, &hdr);
2104 encode_sequence(xdr, &args->seq_args, &hdr);
2105 encode_putfh(xdr, args->fh, &hdr);
2106 encode_access(xdr, args->access, &hdr);
2107 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002108 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109}
2110
2111/*
2112 * Encode LOOKUP request
2113 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002114static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2115 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002118 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120
Chuck Lever9f06c712010-12-14 14:59:18 +00002121 encode_compound_hdr(xdr, req, &hdr);
2122 encode_sequence(xdr, &args->seq_args, &hdr);
2123 encode_putfh(xdr, args->dir_fh, &hdr);
2124 encode_lookup(xdr, args->name, &hdr);
2125 encode_getfh(xdr, &hdr);
2126 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002127 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128}
2129
2130/*
2131 * Encode LOOKUP_ROOT request
2132 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002133static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2134 struct xdr_stream *xdr,
2135 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002138 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
Chuck Lever9f06c712010-12-14 14:59:18 +00002141 encode_compound_hdr(xdr, req, &hdr);
2142 encode_sequence(xdr, &args->seq_args, &hdr);
2143 encode_putrootfh(xdr, &hdr);
2144 encode_getfh(xdr, &hdr);
2145 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002146 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147}
2148
2149/*
2150 * Encode REMOVE request
2151 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002152static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2153 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002156 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
Chuck Lever9f06c712010-12-14 14:59:18 +00002159 encode_compound_hdr(xdr, req, &hdr);
2160 encode_sequence(xdr, &args->seq_args, &hdr);
2161 encode_putfh(xdr, args->fh, &hdr);
2162 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002163 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164}
2165
2166/*
2167 * Encode RENAME request
2168 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002169static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2170 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002173 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
Chuck Lever9f06c712010-12-14 14:59:18 +00002176 encode_compound_hdr(xdr, req, &hdr);
2177 encode_sequence(xdr, &args->seq_args, &hdr);
2178 encode_putfh(xdr, args->old_dir, &hdr);
2179 encode_savefh(xdr, &hdr);
2180 encode_putfh(xdr, args->new_dir, &hdr);
2181 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002182 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183}
2184
2185/*
2186 * Encode LINK request
2187 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002188static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2189 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002192 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
Chuck Lever9f06c712010-12-14 14:59:18 +00002195 encode_compound_hdr(xdr, req, &hdr);
2196 encode_sequence(xdr, &args->seq_args, &hdr);
2197 encode_putfh(xdr, args->fh, &hdr);
2198 encode_savefh(xdr, &hdr);
2199 encode_putfh(xdr, args->dir_fh, &hdr);
2200 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002201 encode_restorefh(xdr, &hdr);
2202 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002203 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204}
2205
2206/*
2207 * Encode CREATE request
2208 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002209static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2210 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002213 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
Chuck Lever9f06c712010-12-14 14:59:18 +00002216 encode_compound_hdr(xdr, req, &hdr);
2217 encode_sequence(xdr, &args->seq_args, &hdr);
2218 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002219 encode_create(xdr, args, &hdr);
2220 encode_getfh(xdr, &hdr);
2221 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002222 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223}
2224
2225/*
2226 * Encode SYMLINK request
2227 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002228static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2229 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230{
Chuck Lever9f06c712010-12-14 14:59:18 +00002231 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232}
2233
2234/*
2235 * Encode GETATTR request
2236 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002237static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2238 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002241 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
Chuck Lever9f06c712010-12-14 14:59:18 +00002244 encode_compound_hdr(xdr, req, &hdr);
2245 encode_sequence(xdr, &args->seq_args, &hdr);
2246 encode_putfh(xdr, args->fh, &hdr);
2247 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002248 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249}
2250
2251/*
2252 * Encode a CLOSE request
2253 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002254static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2255 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
Andy Adamson05d564f2008-12-23 16:06:15 -05002257 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002258 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002259 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260
Chuck Lever9f06c712010-12-14 14:59:18 +00002261 encode_compound_hdr(xdr, req, &hdr);
2262 encode_sequence(xdr, &args->seq_args, &hdr);
2263 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002264 if (args->lr_args)
2265 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002266 encode_close(xdr, args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002267 if (args->bitmask != NULL)
2268 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002269 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270}
2271
2272/*
2273 * Encode an OPEN request
2274 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002275static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2276 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002279 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
Chuck Lever9f06c712010-12-14 14:59:18 +00002282 encode_compound_hdr(xdr, req, &hdr);
2283 encode_sequence(xdr, &args->seq_args, &hdr);
2284 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002285 encode_open(xdr, args, &hdr);
2286 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002287 if (args->access)
2288 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002289 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002290 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291}
2292
2293/*
2294 * Encode an OPEN_CONFIRM request
2295 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002296static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2297 struct xdr_stream *xdr,
2298 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002301 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303
Chuck Lever9f06c712010-12-14 14:59:18 +00002304 encode_compound_hdr(xdr, req, &hdr);
2305 encode_putfh(xdr, args->fh, &hdr);
2306 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002307 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308}
2309
2310/*
2311 * Encode an OPEN request with no attributes.
2312 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002313static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2314 struct xdr_stream *xdr,
2315 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002318 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
Chuck Lever9f06c712010-12-14 14:59:18 +00002321 encode_compound_hdr(xdr, req, &hdr);
2322 encode_sequence(xdr, &args->seq_args, &hdr);
2323 encode_putfh(xdr, args->fh, &hdr);
2324 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002325 if (args->access)
2326 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002327 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002328 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329}
2330
2331/*
2332 * Encode an OPEN_DOWNGRADE request
2333 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002334static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2335 struct xdr_stream *xdr,
2336 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002339 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Chuck Lever9f06c712010-12-14 14:59:18 +00002342 encode_compound_hdr(xdr, req, &hdr);
2343 encode_sequence(xdr, &args->seq_args, &hdr);
2344 encode_putfh(xdr, args->fh, &hdr);
2345 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002346 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347}
2348
2349/*
2350 * Encode a LOCK request
2351 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002352static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2353 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002356 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358
Chuck Lever9f06c712010-12-14 14:59:18 +00002359 encode_compound_hdr(xdr, req, &hdr);
2360 encode_sequence(xdr, &args->seq_args, &hdr);
2361 encode_putfh(xdr, args->fh, &hdr);
2362 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002363 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364}
2365
2366/*
2367 * Encode a LOCKT request
2368 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002369static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2370 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002373 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375
Chuck Lever9f06c712010-12-14 14:59:18 +00002376 encode_compound_hdr(xdr, req, &hdr);
2377 encode_sequence(xdr, &args->seq_args, &hdr);
2378 encode_putfh(xdr, args->fh, &hdr);
2379 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002380 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381}
2382
2383/*
2384 * Encode a LOCKU request
2385 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002386static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2387 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002390 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
Chuck Lever9f06c712010-12-14 14:59:18 +00002393 encode_compound_hdr(xdr, req, &hdr);
2394 encode_sequence(xdr, &args->seq_args, &hdr);
2395 encode_putfh(xdr, args->fh, &hdr);
2396 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002397 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398}
2399
Chuck Lever9f06c712010-12-14 14:59:18 +00002400static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2401 struct xdr_stream *xdr,
2402 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002403{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002404 struct compound_hdr hdr = {
2405 .minorversion = 0,
2406 };
2407
Chuck Lever9f06c712010-12-14 14:59:18 +00002408 encode_compound_hdr(xdr, req, &hdr);
2409 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002410 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002411}
2412
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413/*
2414 * Encode a READLINK request
2415 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002416static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2417 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002420 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422
Chuck Lever9f06c712010-12-14 14:59:18 +00002423 encode_compound_hdr(xdr, req, &hdr);
2424 encode_sequence(xdr, &args->seq_args, &hdr);
2425 encode_putfh(xdr, args->fh, &hdr);
2426 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002427
Benny Halevy28f56692009-04-01 09:22:09 -04002428 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002429 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002430 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431}
2432
2433/*
2434 * Encode a READDIR request
2435 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002436static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2437 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002440 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442
Chuck Lever9f06c712010-12-14 14:59:18 +00002443 encode_compound_hdr(xdr, req, &hdr);
2444 encode_sequence(xdr, &args->seq_args, &hdr);
2445 encode_putfh(xdr, args->fh, &hdr);
2446 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002447
Benny Halevy28f56692009-04-01 09:22:09 -04002448 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002449 args->pgbase, args->count);
2450 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002451 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002452 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002453 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454}
2455
2456/*
2457 * Encode a READ request
2458 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002459static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002460 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002463 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465
Chuck Lever9f06c712010-12-14 14:59:18 +00002466 encode_compound_hdr(xdr, req, &hdr);
2467 encode_sequence(xdr, &args->seq_args, &hdr);
2468 encode_putfh(xdr, args->fh, &hdr);
2469 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470
Benny Halevy28f56692009-04-01 09:22:09 -04002471 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002473 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002474 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475}
2476
2477/*
2478 * Encode an SETATTR request
2479 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002480static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2481 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482{
Andy Adamson05d564f2008-12-23 16:06:15 -05002483 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002484 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002485 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
Chuck Lever9f06c712010-12-14 14:59:18 +00002487 encode_compound_hdr(xdr, req, &hdr);
2488 encode_sequence(xdr, &args->seq_args, &hdr);
2489 encode_putfh(xdr, args->fh, &hdr);
2490 encode_setattr(xdr, args, args->server, &hdr);
2491 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002492 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493}
2494
2495/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002496 * Encode a GETACL request
2497 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002498static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2499 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002500{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002501 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002502 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002503 };
Benny Halevy28f56692009-04-01 09:22:09 -04002504 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002505
Chuck Lever9f06c712010-12-14 14:59:18 +00002506 encode_compound_hdr(xdr, req, &hdr);
2507 encode_sequence(xdr, &args->seq_args, &hdr);
2508 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002509 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002510 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002511
Benny Halevy28f56692009-04-01 09:22:09 -04002512 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01002513 args->acl_pages, 0, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002514
Andy Adamsond0179312008-12-23 16:06:17 -05002515 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002516}
2517
2518/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 * Encode a WRITE request
2520 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002521static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002522 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002525 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527
Chuck Lever9f06c712010-12-14 14:59:18 +00002528 encode_compound_hdr(xdr, req, &hdr);
2529 encode_sequence(xdr, &args->seq_args, &hdr);
2530 encode_putfh(xdr, args->fh, &hdr);
2531 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002532 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002533 if (args->bitmask)
2534 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002535 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536}
2537
2538/*
2539 * a COMMIT request
2540 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002541static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002542 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002545 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547
Chuck Lever9f06c712010-12-14 14:59:18 +00002548 encode_compound_hdr(xdr, req, &hdr);
2549 encode_sequence(xdr, &args->seq_args, &hdr);
2550 encode_putfh(xdr, args->fh, &hdr);
2551 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002552 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553}
2554
2555/*
2556 * FSINFO request
2557 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002558static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2559 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002562 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564
Chuck Lever9f06c712010-12-14 14:59:18 +00002565 encode_compound_hdr(xdr, req, &hdr);
2566 encode_sequence(xdr, &args->seq_args, &hdr);
2567 encode_putfh(xdr, args->fh, &hdr);
2568 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002569 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570}
2571
2572/*
2573 * a PATHCONF request
2574 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002575static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2576 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002579 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581
Chuck Lever9f06c712010-12-14 14:59:18 +00002582 encode_compound_hdr(xdr, req, &hdr);
2583 encode_sequence(xdr, &args->seq_args, &hdr);
2584 encode_putfh(xdr, args->fh, &hdr);
2585 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002586 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002587 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588}
2589
2590/*
2591 * a STATFS request
2592 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002593static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2594 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002597 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599
Chuck Lever9f06c712010-12-14 14:59:18 +00002600 encode_compound_hdr(xdr, req, &hdr);
2601 encode_sequence(xdr, &args->seq_args, &hdr);
2602 encode_putfh(xdr, args->fh, &hdr);
2603 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002604 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002605 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606}
2607
2608/*
2609 * GETATTR_BITMAP request
2610 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002611static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2612 struct xdr_stream *xdr,
2613 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614{
Kinglong Mee8c612822015-08-26 21:12:58 +08002615 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002617 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619
Chuck Lever9f06c712010-12-14 14:59:18 +00002620 encode_compound_hdr(xdr, req, &hdr);
2621 encode_sequence(xdr, &args->seq_args, &hdr);
2622 encode_putfh(xdr, args->fhandle, &hdr);
Kinglong Mee8c612822015-08-26 21:12:58 +08002623 encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002624 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625}
2626
2627/*
2628 * a RENEW request
2629 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002630static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2631 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002634 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 };
2636
Chuck Lever9f06c712010-12-14 14:59:18 +00002637 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002638 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002639 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640}
2641
2642/*
2643 * a SETCLIENTID request
2644 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002645static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2646 struct xdr_stream *xdr,
2647 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002650 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 };
2652
Chuck Lever9f06c712010-12-14 14:59:18 +00002653 encode_compound_hdr(xdr, req, &hdr);
2654 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002655 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656}
2657
2658/*
2659 * a SETCLIENTID_CONFIRM request
2660 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002661static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2662 struct xdr_stream *xdr,
2663 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002666 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668
Chuck Lever9f06c712010-12-14 14:59:18 +00002669 encode_compound_hdr(xdr, req, &hdr);
2670 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002671 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672}
2673
2674/*
2675 * DELEGRETURN request
2676 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002677static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2678 struct xdr_stream *xdr,
2679 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002682 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
Chuck Lever9f06c712010-12-14 14:59:18 +00002685 encode_compound_hdr(xdr, req, &hdr);
2686 encode_sequence(xdr, &args->seq_args, &hdr);
2687 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust586f1c32016-11-15 15:03:33 -05002688 if (args->lr_args)
2689 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002690 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002691 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002692 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693}
2694
2695/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002696 * Encode FS_LOCATIONS request
2697 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002698static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2699 struct xdr_stream *xdr,
2700 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002701{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002702 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002703 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002704 };
Benny Halevy28f56692009-04-01 09:22:09 -04002705 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002706
Chuck Lever9f06c712010-12-14 14:59:18 +00002707 encode_compound_hdr(xdr, req, &hdr);
2708 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002709 if (args->migration) {
2710 encode_putfh(xdr, args->fh, &hdr);
2711 replen = hdr.replen;
2712 encode_fs_locations(xdr, args->bitmask, &hdr);
2713 if (args->renew)
2714 encode_renew(xdr, args->clientid, &hdr);
2715 } else {
2716 encode_putfh(xdr, args->dir_fh, &hdr);
2717 encode_lookup(xdr, args->name, &hdr);
2718 replen = hdr.replen;
2719 encode_fs_locations(xdr, args->bitmask, &hdr);
2720 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002721
Chuck Leverb03d7352013-10-17 14:12:50 -04002722 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002723 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002724 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002725 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002726}
2727
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002728/*
2729 * Encode SECINFO request
2730 */
2731static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2732 struct xdr_stream *xdr,
2733 struct nfs4_secinfo_arg *args)
2734{
2735 struct compound_hdr hdr = {
2736 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2737 };
2738
2739 encode_compound_hdr(xdr, req, &hdr);
2740 encode_sequence(xdr, &args->seq_args, &hdr);
2741 encode_putfh(xdr, args->dir_fh, &hdr);
2742 encode_secinfo(xdr, args->name, &hdr);
2743 encode_nops(&hdr);
2744}
2745
Chuck Lever44c99932013-10-17 14:13:30 -04002746/*
2747 * Encode FSID_PRESENT request
2748 */
2749static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2750 struct xdr_stream *xdr,
2751 struct nfs4_fsid_present_arg *args)
2752{
2753 struct compound_hdr hdr = {
2754 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2755 };
2756
2757 encode_compound_hdr(xdr, req, &hdr);
2758 encode_sequence(xdr, &args->seq_args, &hdr);
2759 encode_putfh(xdr, args->fh, &hdr);
2760 encode_getfh(xdr, &hdr);
2761 if (args->renew)
2762 encode_renew(xdr, args->clientid, &hdr);
2763 encode_nops(&hdr);
2764}
2765
Benny Halevy99fe60d2009-04-01 09:22:29 -04002766#if defined(CONFIG_NFS_V4_1)
2767/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002768 * BIND_CONN_TO_SESSION request
2769 */
2770static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2771 struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08002772 struct nfs41_bind_conn_to_session_args *args)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002773{
2774 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002775 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002776 };
2777
2778 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002779 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002780 encode_nops(&hdr);
2781}
2782
2783/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002784 * EXCHANGE_ID request
2785 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002786static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2787 struct xdr_stream *xdr,
2788 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002789{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002790 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002791 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002792 };
2793
Chuck Lever9f06c712010-12-14 14:59:18 +00002794 encode_compound_hdr(xdr, req, &hdr);
2795 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002796 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002797}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002798
2799/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002800 * a CREATE_SESSION request
2801 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002802static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2803 struct xdr_stream *xdr,
2804 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002805{
Andy Adamsonfc931582009-04-01 09:22:31 -04002806 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002807 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002808 };
2809
Chuck Lever9f06c712010-12-14 14:59:18 +00002810 encode_compound_hdr(xdr, req, &hdr);
2811 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002812 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002813}
2814
2815/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002816 * a DESTROY_SESSION request
2817 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002818static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2819 struct xdr_stream *xdr,
2820 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002821{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002822 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002823 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002824 };
2825
Chuck Lever9f06c712010-12-14 14:59:18 +00002826 encode_compound_hdr(xdr, req, &hdr);
2827 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002828 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002829}
2830
2831/*
Trond Myklebust66245532012-05-25 17:18:09 -04002832 * a DESTROY_CLIENTID request
2833 */
2834static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2835 struct xdr_stream *xdr,
2836 struct nfs_client *clp)
2837{
2838 struct compound_hdr hdr = {
2839 .minorversion = clp->cl_mvops->minor_version,
2840 };
2841
2842 encode_compound_hdr(xdr, req, &hdr);
2843 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2844 encode_nops(&hdr);
2845}
2846
2847/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002848 * a SEQUENCE request
2849 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002850static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2851 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002852{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002853 struct compound_hdr hdr = {
2854 .minorversion = nfs4_xdr_minorversion(args),
2855 };
2856
Chuck Lever9f06c712010-12-14 14:59:18 +00002857 encode_compound_hdr(xdr, req, &hdr);
2858 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002859 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002860}
2861
2862/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002863 * a GET_LEASE_TIME request
2864 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002865static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2866 struct xdr_stream *xdr,
2867 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002868{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002869 struct compound_hdr hdr = {
2870 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2871 };
Fred Isamandae100c2011-07-30 20:52:37 -04002872 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002873
Chuck Lever9f06c712010-12-14 14:59:18 +00002874 encode_compound_hdr(xdr, req, &hdr);
2875 encode_sequence(xdr, &args->la_seq_args, &hdr);
2876 encode_putrootfh(xdr, &hdr);
2877 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002878 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002879}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002880
2881/*
2882 * a RECLAIM_COMPLETE request
2883 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002884static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2885 struct xdr_stream *xdr,
2886 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002887{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002888 struct compound_hdr hdr = {
2889 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2890 };
2891
Chuck Lever9f06c712010-12-14 14:59:18 +00002892 encode_compound_hdr(xdr, req, &hdr);
2893 encode_sequence(xdr, &args->seq_args, &hdr);
2894 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002895 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002896}
2897
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002898/*
2899 * Encode GETDEVICEINFO request
2900 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002901static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2902 struct xdr_stream *xdr,
2903 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002904{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002905 struct compound_hdr hdr = {
2906 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2907 };
2908
Chuck Lever9f06c712010-12-14 14:59:18 +00002909 encode_compound_hdr(xdr, req, &hdr);
2910 encode_sequence(xdr, &args->seq_args, &hdr);
2911 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002912
2913 /* set up reply kvec. Subtract notification bitmap max size (2)
2914 * so that notification bitmap is put in xdr_buf tail */
2915 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2916 args->pdev->pages, args->pdev->pgbase,
2917 args->pdev->pglen);
2918
2919 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002920}
2921
2922/*
2923 * Encode LAYOUTGET request
2924 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002925static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2926 struct xdr_stream *xdr,
2927 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002928{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002929 struct compound_hdr hdr = {
2930 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2931 };
2932
Chuck Lever9f06c712010-12-14 14:59:18 +00002933 encode_compound_hdr(xdr, req, &hdr);
2934 encode_sequence(xdr, &args->seq_args, &hdr);
2935 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2936 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002937
2938 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2939 args->layout.pages, 0, args->layout.pglen);
2940
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002941 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002942}
Andy Adamson863a3c62011-03-23 13:27:54 +00002943
2944/*
2945 * Encode LAYOUTCOMMIT request
2946 */
Benny Halevycbe82602011-05-22 19:52:37 +03002947static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2948 struct xdr_stream *xdr,
2949 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002950{
Benny Halevyac7db722011-05-22 19:53:48 +03002951 struct nfs4_layoutcommit_data *data =
2952 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002953 struct compound_hdr hdr = {
2954 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2955 };
2956
2957 encode_compound_hdr(xdr, req, &hdr);
2958 encode_sequence(xdr, &args->seq_args, &hdr);
2959 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002960 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002961 encode_getfattr(xdr, args->bitmask, &hdr);
2962 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002963}
2964
2965/*
2966 * Encode LAYOUTRETURN request
2967 */
2968static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2969 struct xdr_stream *xdr,
2970 struct nfs4_layoutreturn_args *args)
2971{
2972 struct compound_hdr hdr = {
2973 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2974 };
2975
2976 encode_compound_hdr(xdr, req, &hdr);
2977 encode_sequence(xdr, &args->seq_args, &hdr);
2978 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2979 encode_layoutreturn(xdr, args, &hdr);
2980 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002981}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002982
2983/*
2984 * Encode SECINFO_NO_NAME request
2985 */
2986static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2987 struct xdr_stream *xdr,
2988 struct nfs41_secinfo_no_name_args *args)
2989{
2990 struct compound_hdr hdr = {
2991 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2992 };
2993
2994 encode_compound_hdr(xdr, req, &hdr);
2995 encode_sequence(xdr, &args->seq_args, &hdr);
2996 encode_putrootfh(xdr, &hdr);
2997 encode_secinfo_no_name(xdr, args, &hdr);
2998 encode_nops(&hdr);
2999 return 0;
3000}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003001
3002/*
3003 * Encode TEST_STATEID request
3004 */
3005static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3006 struct xdr_stream *xdr,
3007 struct nfs41_test_stateid_args *args)
3008{
3009 struct compound_hdr hdr = {
3010 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3011 };
3012
3013 encode_compound_hdr(xdr, req, &hdr);
3014 encode_sequence(xdr, &args->seq_args, &hdr);
3015 encode_test_stateid(xdr, args, &hdr);
3016 encode_nops(&hdr);
3017}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003018
3019/*
3020 * Encode FREE_STATEID request
3021 */
3022static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3023 struct xdr_stream *xdr,
3024 struct nfs41_free_stateid_args *args)
3025{
3026 struct compound_hdr hdr = {
3027 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3028 };
3029
3030 encode_compound_hdr(xdr, req, &hdr);
3031 encode_sequence(xdr, &args->seq_args, &hdr);
3032 encode_free_stateid(xdr, args, &hdr);
3033 encode_nops(&hdr);
3034}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003035#endif /* CONFIG_NFS_V4_1 */
3036
Benny Halevy686841b2009-08-14 17:19:48 +03003037static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3038{
3039 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3040 "Remaining buffer length is %tu words.\n",
3041 func, xdr->end - xdr->p);
3042}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043
Trond Myklebust683b57b2006-06-09 09:34:22 -04003044static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045{
Al Viro8687b632006-10-19 23:28:48 -07003046 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047
Benny Halevyc0eae662009-08-14 17:20:14 +03003048 p = xdr_inline_decode(xdr, 4);
3049 if (unlikely(!p))
3050 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003051 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003052 p = xdr_inline_decode(xdr, *len);
3053 if (unlikely(!p))
3054 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 *string = (char *)p;
3056 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003057out_overflow:
3058 print_overflow_msg(__func__, xdr);
3059 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060}
3061
3062static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3063{
Al Viro8687b632006-10-19 23:28:48 -07003064 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065
Benny Halevyc0eae662009-08-14 17:20:14 +03003066 p = xdr_inline_decode(xdr, 8);
3067 if (unlikely(!p))
3068 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003069 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003070 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003071
Benny Halevyc0eae662009-08-14 17:20:14 +03003072 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3073 if (unlikely(!p))
3074 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 hdr->tag = (char *)p;
3076 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003077 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003078 if (unlikely(hdr->nops < 1))
3079 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003081out_overflow:
3082 print_overflow_msg(__func__, xdr);
3083 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084}
3085
Trond Myklebustc7848f62013-12-04 17:39:23 -05003086static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3087 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088{
Al Viro8687b632006-10-19 23:28:48 -07003089 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 uint32_t opnum;
3091 int32_t nfserr;
3092
Benny Halevyc0eae662009-08-14 17:20:14 +03003093 p = xdr_inline_decode(xdr, 8);
3094 if (unlikely(!p))
3095 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003096 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003097 if (unlikely(opnum != expected))
3098 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003099 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003100 if (nfserr == NFS_OK)
3101 *nfs_retval = 0;
3102 else
3103 *nfs_retval = nfs4_stat_to_errno(nfserr);
3104 return true;
3105out_bad_operation:
3106 dprintk("nfs: Server returned operation"
3107 " %d but we issued a request for %d\n",
3108 opnum, expected);
3109 *nfs_retval = -EREMOTEIO;
3110 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003111out_overflow:
3112 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003113 *nfs_retval = -EIO;
3114 return false;
3115}
3116
3117static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3118{
3119 int retval;
3120
3121 __decode_op_hdr(xdr, expected, &retval);
3122 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123}
3124
3125/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003126static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127{
Al Viro8687b632006-10-19 23:28:48 -07003128 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003129 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 char *str;
3131
Benny Halevyc0eae662009-08-14 17:20:14 +03003132 p = xdr_inline_decode(xdr, 12);
3133 if (likely(p))
3134 return decode_opaque_inline(xdr, &strlen, &str);
3135 print_overflow_msg(__func__, xdr);
3136 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137}
3138
3139static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3140{
Al Viro8687b632006-10-19 23:28:48 -07003141 uint32_t bmlen;
3142 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143
Benny Halevyc0eae662009-08-14 17:20:14 +03003144 p = xdr_inline_decode(xdr, 4);
3145 if (unlikely(!p))
3146 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003147 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
Fred Isamandae100c2011-07-30 20:52:37 -04003149 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003150 p = xdr_inline_decode(xdr, (bmlen << 2));
3151 if (unlikely(!p))
3152 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003154 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003155 if (bmlen > 1) {
3156 bitmap[1] = be32_to_cpup(p++);
3157 if (bmlen > 2)
3158 bitmap[2] = be32_to_cpup(p);
3159 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 }
3161 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003162out_overflow:
3163 print_overflow_msg(__func__, xdr);
3164 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165}
3166
Trond Myklebust256e48b2012-06-21 11:18:13 -04003167static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168{
Al Viro8687b632006-10-19 23:28:48 -07003169 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170
Benny Halevyc0eae662009-08-14 17:20:14 +03003171 p = xdr_inline_decode(xdr, 4);
3172 if (unlikely(!p))
3173 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003174 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003175 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003177out_overflow:
3178 print_overflow_msg(__func__, xdr);
3179 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180}
3181
3182static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3183{
3184 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003185 int ret;
3186 ret = decode_attr_bitmap(xdr, bitmask);
3187 if (unlikely(ret < 0))
3188 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3190 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003191 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3192 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3193 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 return 0;
3195}
3196
3197static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3198{
Al Viro8687b632006-10-19 23:28:48 -07003199 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003200 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201
3202 *type = 0;
3203 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3204 return -EIO;
3205 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003206 p = xdr_inline_decode(xdr, 4);
3207 if (unlikely(!p))
3208 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003209 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003211 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 return -EIO;
3213 }
3214 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003215 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003217 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003218 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003219out_overflow:
3220 print_overflow_msg(__func__, xdr);
3221 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222}
3223
Chuck Lever264e6352012-03-01 17:02:05 -05003224static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3225 uint32_t *bitmap, uint32_t *type)
3226{
3227 __be32 *p;
3228
3229 *type = 0;
3230 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3231 return -EIO;
3232 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3233 p = xdr_inline_decode(xdr, 4);
3234 if (unlikely(!p))
3235 goto out_overflow;
3236 *type = be32_to_cpup(p);
3237 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3238 }
3239 dprintk("%s: expire type=0x%x\n", __func__, *type);
3240 return 0;
3241out_overflow:
3242 print_overflow_msg(__func__, xdr);
3243 return -EIO;
3244}
3245
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3247{
Al Viro8687b632006-10-19 23:28:48 -07003248 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003249 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250
3251 *change = 0;
3252 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3253 return -EIO;
3254 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003255 p = xdr_inline_decode(xdr, 8);
3256 if (unlikely(!p))
3257 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003258 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003260 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003262 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003264 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003265out_overflow:
3266 print_overflow_msg(__func__, xdr);
3267 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268}
3269
3270static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3271{
Al Viro8687b632006-10-19 23:28:48 -07003272 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003273 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274
3275 *size = 0;
3276 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3277 return -EIO;
3278 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003279 p = xdr_inline_decode(xdr, 8);
3280 if (unlikely(!p))
3281 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003282 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003284 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003286 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003287 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003288out_overflow:
3289 print_overflow_msg(__func__, xdr);
3290 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291}
3292
3293static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3294{
Al Viro8687b632006-10-19 23:28:48 -07003295 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296
3297 *res = 0;
3298 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3299 return -EIO;
3300 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003301 p = xdr_inline_decode(xdr, 4);
3302 if (unlikely(!p))
3303 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003304 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3306 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003307 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003309out_overflow:
3310 print_overflow_msg(__func__, xdr);
3311 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312}
3313
3314static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3315{
Al Viro8687b632006-10-19 23:28:48 -07003316 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317
3318 *res = 0;
3319 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3320 return -EIO;
3321 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003322 p = xdr_inline_decode(xdr, 4);
3323 if (unlikely(!p))
3324 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003325 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3327 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003328 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003330out_overflow:
3331 print_overflow_msg(__func__, xdr);
3332 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333}
3334
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003335static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336{
Al Viro8687b632006-10-19 23:28:48 -07003337 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003338 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339
3340 fsid->major = 0;
3341 fsid->minor = 0;
3342 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3343 return -EIO;
3344 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003345 p = xdr_inline_decode(xdr, 16);
3346 if (unlikely(!p))
3347 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003348 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003349 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003351 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003353 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 (unsigned long long)fsid->major,
3355 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003356 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003357out_overflow:
3358 print_overflow_msg(__func__, xdr);
3359 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360}
3361
3362static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3363{
Al Viro8687b632006-10-19 23:28:48 -07003364 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365
3366 *res = 60;
3367 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3368 return -EIO;
3369 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003370 p = xdr_inline_decode(xdr, 4);
3371 if (unlikely(!p))
3372 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003373 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3375 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003376 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003378out_overflow:
3379 print_overflow_msg(__func__, xdr);
3380 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381}
3382
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003383static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003384{
3385 __be32 *p;
3386
3387 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3388 return -EIO;
3389 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3390 p = xdr_inline_decode(xdr, 4);
3391 if (unlikely(!p))
3392 goto out_overflow;
3393 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003394 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003395 }
3396 return 0;
3397out_overflow:
3398 print_overflow_msg(__func__, xdr);
3399 return -EIO;
3400}
3401
Kinglong Mee8c612822015-08-26 21:12:58 +08003402static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3403 uint32_t *bitmap, uint32_t *bitmask)
3404{
3405 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3406 int ret;
3407 ret = decode_attr_bitmap(xdr, bitmask);
3408 if (unlikely(ret < 0))
3409 return ret;
3410 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3411 } else
3412 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3413 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3414 bitmask[0], bitmask[1], bitmask[2]);
3415 return 0;
3416}
3417
Bryan Schumakerae42c702010-10-21 16:33:17 -04003418static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3419{
3420 __be32 *p;
3421 int len;
3422
Trond Myklebust7ad07352010-10-23 15:34:20 -04003423 if (fh != NULL)
3424 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003425
3426 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3427 return -EIO;
3428 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3429 p = xdr_inline_decode(xdr, 4);
3430 if (unlikely(!p))
3431 goto out_overflow;
3432 len = be32_to_cpup(p);
3433 if (len > NFS4_FHSIZE)
3434 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003435 p = xdr_inline_decode(xdr, len);
3436 if (unlikely(!p))
3437 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003438 if (fh != NULL) {
3439 memcpy(fh->data, p, len);
3440 fh->size = len;
3441 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003442 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3443 }
3444 return 0;
3445out_overflow:
3446 print_overflow_msg(__func__, xdr);
3447 return -EIO;
3448}
3449
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3451{
Al Viro8687b632006-10-19 23:28:48 -07003452 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003454 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3456 return -EIO;
3457 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003458 p = xdr_inline_decode(xdr, 4);
3459 if (unlikely(!p))
3460 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003461 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3463 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003464 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003466out_overflow:
3467 print_overflow_msg(__func__, xdr);
3468 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469}
3470
3471static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3472{
Al Viro8687b632006-10-19 23:28:48 -07003473 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003474 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475
3476 *fileid = 0;
3477 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3478 return -EIO;
3479 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003480 p = xdr_inline_decode(xdr, 8);
3481 if (unlikely(!p))
3482 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003483 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003485 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003487 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003488 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003489out_overflow:
3490 print_overflow_msg(__func__, xdr);
3491 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492}
3493
Manoj Naik99baf622006-06-09 09:34:24 -04003494static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3495{
Al Viro8687b632006-10-19 23:28:48 -07003496 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003497 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003498
3499 *fileid = 0;
3500 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3501 return -EIO;
3502 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003503 p = xdr_inline_decode(xdr, 8);
3504 if (unlikely(!p))
3505 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003506 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003507 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003508 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003509 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003510 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003511 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003512out_overflow:
3513 print_overflow_msg(__func__, xdr);
3514 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003515}
3516
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3518{
Al Viro8687b632006-10-19 23:28:48 -07003519 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 int status = 0;
3521
3522 *res = 0;
3523 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3524 return -EIO;
3525 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003526 p = xdr_inline_decode(xdr, 8);
3527 if (unlikely(!p))
3528 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003529 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3531 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003532 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003534out_overflow:
3535 print_overflow_msg(__func__, xdr);
3536 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537}
3538
3539static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3540{
Al Viro8687b632006-10-19 23:28:48 -07003541 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 int status = 0;
3543
3544 *res = 0;
3545 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3546 return -EIO;
3547 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003548 p = xdr_inline_decode(xdr, 8);
3549 if (unlikely(!p))
3550 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003551 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3553 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003554 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003556out_overflow:
3557 print_overflow_msg(__func__, xdr);
3558 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559}
3560
3561static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3562{
Al Viro8687b632006-10-19 23:28:48 -07003563 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564 int status = 0;
3565
3566 *res = 0;
3567 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3568 return -EIO;
3569 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003570 p = xdr_inline_decode(xdr, 8);
3571 if (unlikely(!p))
3572 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003573 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3575 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003576 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003578out_overflow:
3579 print_overflow_msg(__func__, xdr);
3580 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581}
3582
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003583static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3584{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003585 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003586 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003587 int status = 0;
3588
Benny Halevyc0eae662009-08-14 17:20:14 +03003589 p = xdr_inline_decode(xdr, 4);
3590 if (unlikely(!p))
3591 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003592 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003593 if (n == 0)
3594 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003595 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003596 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3597 dprintk("cannot parse %d components in path\n", n);
3598 goto out_eio;
3599 }
3600 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003601 struct nfs4_string *component = &path->components[path->ncomponents];
3602 status = decode_opaque_inline(xdr, &component->len, &component->data);
3603 if (unlikely(status != 0))
3604 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003605 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003606 pr_cont("%s%.*s ",
3607 (path->ncomponents != n ? "/ " : ""),
3608 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003609 }
3610out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003611 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003612root_path:
3613/* a root pathname is sent as a zero component4 */
3614 path->ncomponents = 1;
3615 path->components[0].len=0;
3616 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003617 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003618 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003619out_eio:
3620 dprintk(" status %d", status);
3621 status = -EIO;
3622 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003623out_overflow:
3624 print_overflow_msg(__func__, xdr);
3625 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003626}
3627
3628static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003629{
3630 int n;
Al Viro8687b632006-10-19 23:28:48 -07003631 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003632 int status = -EIO;
3633
3634 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3635 goto out;
3636 status = 0;
3637 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3638 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003639 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003640 status = -EIO;
3641 /* Ignore borken servers that return unrequested attrs */
3642 if (unlikely(res == NULL))
3643 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003644 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003645 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003646 if (unlikely(status != 0))
3647 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003648 p = xdr_inline_decode(xdr, 4);
3649 if (unlikely(!p))
3650 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003651 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003652 if (n <= 0)
3653 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003654 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003655 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003656 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003657
Trond Myklebust809b4262013-03-27 11:54:45 -04003658 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3659 break;
3660 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003661 p = xdr_inline_decode(xdr, 4);
3662 if (unlikely(!p))
3663 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003664 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003665
Chuck Lever02a29762012-03-01 17:00:31 -05003666 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003667 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3668 struct nfs4_string *server;
3669
3670 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003671 unsigned int i;
3672 dprintk("%s: using first %u of %u servers "
3673 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003674 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003675 NFS4_FS_LOCATION_MAXSERVERS,
3676 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003677 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003678 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003679 char *data;
3680 status = decode_opaque_inline(xdr, &len, &data);
3681 if (unlikely(status != 0))
3682 goto out_eio;
3683 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003684 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003685 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003686 server = &loc->servers[loc->nservers];
3687 status = decode_opaque_inline(xdr, &server->len, &server->data);
3688 if (unlikely(status != 0))
3689 goto out_eio;
3690 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003691 }
3692 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003693 if (unlikely(status != 0))
3694 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003695 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003696 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003697 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003698out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003699 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003700 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003701out_overflow:
3702 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003703out_eio:
3704 status = -EIO;
3705 goto out;
3706}
3707
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3709{
Al Viro8687b632006-10-19 23:28:48 -07003710 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 int status = 0;
3712
3713 *res = 0;
3714 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3715 return -EIO;
3716 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003717 p = xdr_inline_decode(xdr, 8);
3718 if (unlikely(!p))
3719 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003720 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3722 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003723 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003725out_overflow:
3726 print_overflow_msg(__func__, xdr);
3727 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728}
3729
3730static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3731{
Al Viro8687b632006-10-19 23:28:48 -07003732 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 int status = 0;
3734
3735 *maxlink = 1;
3736 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3737 return -EIO;
3738 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003739 p = xdr_inline_decode(xdr, 4);
3740 if (unlikely(!p))
3741 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003742 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3744 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003745 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003747out_overflow:
3748 print_overflow_msg(__func__, xdr);
3749 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750}
3751
3752static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3753{
Al Viro8687b632006-10-19 23:28:48 -07003754 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 int status = 0;
3756
3757 *maxname = 1024;
3758 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3759 return -EIO;
3760 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003761 p = xdr_inline_decode(xdr, 4);
3762 if (unlikely(!p))
3763 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003764 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3766 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003767 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003769out_overflow:
3770 print_overflow_msg(__func__, xdr);
3771 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772}
3773
3774static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3775{
Al Viro8687b632006-10-19 23:28:48 -07003776 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 int status = 0;
3778
3779 *res = 1024;
3780 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3781 return -EIO;
3782 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3783 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003784 p = xdr_inline_decode(xdr, 8);
3785 if (unlikely(!p))
3786 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003787 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 if (maxread > 0x7FFFFFFF)
3789 maxread = 0x7FFFFFFF;
3790 *res = (uint32_t)maxread;
3791 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3792 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003793 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003795out_overflow:
3796 print_overflow_msg(__func__, xdr);
3797 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798}
3799
3800static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3801{
Al Viro8687b632006-10-19 23:28:48 -07003802 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 int status = 0;
3804
3805 *res = 1024;
3806 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3807 return -EIO;
3808 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3809 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003810 p = xdr_inline_decode(xdr, 8);
3811 if (unlikely(!p))
3812 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003813 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 if (maxwrite > 0x7FFFFFFF)
3815 maxwrite = 0x7FFFFFFF;
3816 *res = (uint32_t)maxwrite;
3817 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3818 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003819 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003821out_overflow:
3822 print_overflow_msg(__func__, xdr);
3823 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824}
3825
Trond Myklebustbca79472009-03-11 14:10:26 -04003826static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827{
Trond Myklebustbca79472009-03-11 14:10:26 -04003828 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003829 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003830 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831
3832 *mode = 0;
3833 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3834 return -EIO;
3835 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003836 p = xdr_inline_decode(xdr, 4);
3837 if (unlikely(!p))
3838 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003839 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003840 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003842 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003844 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003845 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003846out_overflow:
3847 print_overflow_msg(__func__, xdr);
3848 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849}
3850
3851static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3852{
Al Viro8687b632006-10-19 23:28:48 -07003853 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003854 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855
3856 *nlink = 1;
3857 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3858 return -EIO;
3859 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003860 p = xdr_inline_decode(xdr, 4);
3861 if (unlikely(!p))
3862 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003863 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003865 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003867 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003868 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003869out_overflow:
3870 print_overflow_msg(__func__, xdr);
3871 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872}
3873
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003874static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003875 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003876 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877{
Al Viro8687b632006-10-19 23:28:48 -07003878 uint32_t len;
3879 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003880 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881
Eric W. Biedermane5782072013-02-01 14:22:02 -08003882 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3884 return -EIO;
3885 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003886 p = xdr_inline_decode(xdr, 4);
3887 if (unlikely(!p))
3888 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003889 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003890 p = xdr_inline_decode(xdr, len);
3891 if (unlikely(!p))
3892 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003893 if (owner_name != NULL) {
3894 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3895 if (owner_name->data != NULL) {
3896 owner_name->len = len;
3897 ret = NFS_ATTR_FATTR_OWNER_NAME;
3898 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003899 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003900 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003901 ret = NFS_ATTR_FATTR_OWNER;
3902 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003904 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003906 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003907 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3909 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003910 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003911 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003912out_overflow:
3913 print_overflow_msg(__func__, xdr);
3914 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915}
3916
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003917static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003918 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003919 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920{
Al Viro8687b632006-10-19 23:28:48 -07003921 uint32_t len;
3922 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003923 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924
Eric W. Biedermane5782072013-02-01 14:22:02 -08003925 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3927 return -EIO;
3928 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003929 p = xdr_inline_decode(xdr, 4);
3930 if (unlikely(!p))
3931 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003932 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003933 p = xdr_inline_decode(xdr, len);
3934 if (unlikely(!p))
3935 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003936 if (group_name != NULL) {
3937 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3938 if (group_name->data != NULL) {
3939 group_name->len = len;
3940 ret = NFS_ATTR_FATTR_GROUP_NAME;
3941 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003942 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003943 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003944 ret = NFS_ATTR_FATTR_GROUP;
3945 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003947 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003949 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003950 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3952 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003953 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003954 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003955out_overflow:
3956 print_overflow_msg(__func__, xdr);
3957 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958}
3959
3960static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3961{
Al Viro8687b632006-10-19 23:28:48 -07003962 uint32_t major = 0, minor = 0;
3963 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003964 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965
3966 *rdev = MKDEV(0,0);
3967 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3968 return -EIO;
3969 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3970 dev_t tmp;
3971
Benny Halevyc0eae662009-08-14 17:20:14 +03003972 p = xdr_inline_decode(xdr, 8);
3973 if (unlikely(!p))
3974 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003975 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003976 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977 tmp = MKDEV(major, minor);
3978 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3979 *rdev = tmp;
3980 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003981 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003983 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003984 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003985out_overflow:
3986 print_overflow_msg(__func__, xdr);
3987 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988}
3989
3990static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3991{
Al Viro8687b632006-10-19 23:28:48 -07003992 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993 int status = 0;
3994
3995 *res = 0;
3996 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3997 return -EIO;
3998 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003999 p = xdr_inline_decode(xdr, 8);
4000 if (unlikely(!p))
4001 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004002 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4004 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004005 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004007out_overflow:
4008 print_overflow_msg(__func__, xdr);
4009 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010}
4011
4012static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4013{
Al Viro8687b632006-10-19 23:28:48 -07004014 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015 int status = 0;
4016
4017 *res = 0;
4018 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4019 return -EIO;
4020 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004021 p = xdr_inline_decode(xdr, 8);
4022 if (unlikely(!p))
4023 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004024 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4026 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004027 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004029out_overflow:
4030 print_overflow_msg(__func__, xdr);
4031 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032}
4033
4034static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4035{
Al Viro8687b632006-10-19 23:28:48 -07004036 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 int status = 0;
4038
4039 *res = 0;
4040 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4041 return -EIO;
4042 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004043 p = xdr_inline_decode(xdr, 8);
4044 if (unlikely(!p))
4045 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004046 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4048 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004049 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004051out_overflow:
4052 print_overflow_msg(__func__, xdr);
4053 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054}
4055
4056static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4057{
Al Viro8687b632006-10-19 23:28:48 -07004058 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004059 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060
4061 *used = 0;
4062 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4063 return -EIO;
4064 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004065 p = xdr_inline_decode(xdr, 8);
4066 if (unlikely(!p))
4067 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004068 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004070 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004072 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004074 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004075out_overflow:
4076 print_overflow_msg(__func__, xdr);
4077 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078}
4079
4080static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4081{
Al Viro8687b632006-10-19 23:28:48 -07004082 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083 uint64_t sec;
4084 uint32_t nsec;
4085
Benny Halevyc0eae662009-08-14 17:20:14 +03004086 p = xdr_inline_decode(xdr, 12);
4087 if (unlikely(!p))
4088 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004089 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004090 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 time->tv_sec = (time_t)sec;
4092 time->tv_nsec = (long)nsec;
4093 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004094out_overflow:
4095 print_overflow_msg(__func__, xdr);
4096 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097}
4098
4099static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4100{
4101 int status = 0;
4102
4103 time->tv_sec = 0;
4104 time->tv_nsec = 0;
4105 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4106 return -EIO;
4107 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4108 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004109 if (status == 0)
4110 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4112 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004113 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114 return status;
4115}
4116
4117static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4118{
4119 int status = 0;
4120
4121 time->tv_sec = 0;
4122 time->tv_nsec = 0;
4123 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4124 return -EIO;
4125 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4126 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004127 if (status == 0)
4128 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4130 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004131 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132 return status;
4133}
4134
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004135static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4136 struct timespec *time)
4137{
4138 int status = 0;
4139
4140 time->tv_sec = 0;
4141 time->tv_nsec = 0;
4142 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4143 return -EIO;
4144 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4145 status = decode_attr_time(xdr, time);
4146 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4147 }
4148 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4149 (long)time->tv_nsec);
4150 return status;
4151}
4152
David Quigleyaa9c2662013-05-22 12:50:44 -04004153static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4154 struct nfs4_label *label)
4155{
4156 uint32_t pi = 0;
4157 uint32_t lfs = 0;
4158 __u32 len;
4159 __be32 *p;
4160 int status = 0;
4161
4162 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4163 return -EIO;
4164 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4165 p = xdr_inline_decode(xdr, 4);
4166 if (unlikely(!p))
4167 goto out_overflow;
4168 lfs = be32_to_cpup(p++);
4169 p = xdr_inline_decode(xdr, 4);
4170 if (unlikely(!p))
4171 goto out_overflow;
4172 pi = be32_to_cpup(p++);
4173 p = xdr_inline_decode(xdr, 4);
4174 if (unlikely(!p))
4175 goto out_overflow;
4176 len = be32_to_cpup(p++);
4177 p = xdr_inline_decode(xdr, len);
4178 if (unlikely(!p))
4179 goto out_overflow;
4180 if (len < NFS4_MAXLABELLEN) {
4181 if (label) {
4182 memcpy(label->label, p, len);
4183 label->len = len;
4184 label->pi = pi;
4185 label->lfs = lfs;
4186 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4187 }
4188 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4189 } else
4190 printk(KERN_WARNING "%s: label too long (%u)!\n",
4191 __func__, len);
4192 }
4193 if (label && label->label)
4194 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4195 (char *)label->label, label->len, label->pi, label->lfs);
4196 return status;
4197
4198out_overflow:
4199 print_overflow_msg(__func__, xdr);
4200 return -EIO;
4201}
4202
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4204{
4205 int status = 0;
4206
4207 time->tv_sec = 0;
4208 time->tv_nsec = 0;
4209 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4210 return -EIO;
4211 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4212 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004213 if (status == 0)
4214 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4216 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004217 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218 return status;
4219}
4220
Trond Myklebust256e48b2012-06-21 11:18:13 -04004221static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222{
4223 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004224 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225
4226 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004227 dprintk("%s: server returned incorrect attribute length: "
4228 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004229 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230 attrwords << 2,
4231 (attrwords < nwords) ? '<' : '>',
4232 nwords << 2);
4233 return -EIO;
4234 }
4235 return 0;
4236}
4237
4238static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4239{
Al Viro8687b632006-10-19 23:28:48 -07004240 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241
Benny Halevyc0eae662009-08-14 17:20:14 +03004242 p = xdr_inline_decode(xdr, 20);
4243 if (unlikely(!p))
4244 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004245 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004246 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004247 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004249out_overflow:
4250 print_overflow_msg(__func__, xdr);
4251 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252}
4253
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004254static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004255{
Al Viro8687b632006-10-19 23:28:48 -07004256 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 uint32_t supp, acc;
4258 int status;
4259
4260 status = decode_op_hdr(xdr, OP_ACCESS);
4261 if (status)
4262 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004263 p = xdr_inline_decode(xdr, 8);
4264 if (unlikely(!p))
4265 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004266 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004267 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004268 *supported = supp;
4269 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004271out_overflow:
4272 print_overflow_msg(__func__, xdr);
4273 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274}
4275
Benny Halevy07d30432009-08-14 17:19:52 +03004276static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277{
Al Viro8687b632006-10-19 23:28:48 -07004278 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004279
4280 p = xdr_inline_decode(xdr, len);
4281 if (likely(p)) {
4282 memcpy(buf, p, len);
4283 return 0;
4284 }
4285 print_overflow_msg(__func__, xdr);
4286 return -EIO;
4287}
4288
4289static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4290{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004291 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292}
4293
Trond Myklebust93b717f2016-05-16 17:42:43 -04004294static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4295{
4296 stateid->type = NFS4_OPEN_STATEID_TYPE;
4297 return decode_stateid(xdr, stateid);
4298}
4299
4300static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4301{
4302 stateid->type = NFS4_LOCK_STATEID_TYPE;
4303 return decode_stateid(xdr, stateid);
4304}
4305
4306static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4307{
4308 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4309 return decode_stateid(xdr, stateid);
4310}
4311
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4313{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314 int status;
4315
4316 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004317 if (status != -EIO)
4318 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004319 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04004320 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004321 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322}
4323
Benny Halevydb942bb2009-08-14 17:19:56 +03004324static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4325{
Chuck Levercd937102012-03-02 17:14:31 -05004326 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327}
4328
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004329static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4330{
4331 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4332}
4333
Fred Isaman0b7c0152012-04-20 14:47:39 -04004334static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004335{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 int status;
4337
4338 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004339 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004340 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004341 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342}
4343
4344static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4345{
Al Viro8687b632006-10-19 23:28:48 -07004346 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347 uint32_t bmlen;
4348 int status;
4349
4350 status = decode_op_hdr(xdr, OP_CREATE);
4351 if (status)
4352 return status;
4353 if ((status = decode_change_info(xdr, cinfo)))
4354 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004355 p = xdr_inline_decode(xdr, 4);
4356 if (unlikely(!p))
4357 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004358 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004359 p = xdr_inline_decode(xdr, bmlen << 2);
4360 if (likely(p))
4361 return 0;
4362out_overflow:
4363 print_overflow_msg(__func__, xdr);
4364 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365}
4366
4367static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4368{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004369 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004370 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371 int status;
4372
4373 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4374 goto xdr_error;
4375 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4376 goto xdr_error;
4377 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4378 goto xdr_error;
4379 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4380 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004381 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4382 &res->fh_expire_type)) != 0)
4383 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4385 goto xdr_error;
4386 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4387 goto xdr_error;
4388 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4389 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004390 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4391 res->exclcreat_bitmask)) != 0)
4392 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393 status = verify_attr_len(xdr, savep, attrlen);
4394xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004395 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396 return status;
4397}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004398
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4400{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004401 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004402 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004403 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004404
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4406 goto xdr_error;
4407 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4408 goto xdr_error;
4409 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4410 goto xdr_error;
4411
4412 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4413 goto xdr_error;
4414 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4415 goto xdr_error;
4416 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4417 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004418
4419 status = -EIO;
4420 if (unlikely(bitmap[0]))
4421 goto xdr_error;
4422
Linus Torvalds1da177e2005-04-16 15:20:36 -07004423 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4424 goto xdr_error;
4425 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4426 goto xdr_error;
4427 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4428 goto xdr_error;
4429
4430 status = verify_attr_len(xdr, savep, attrlen);
4431xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004432 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004433 return status;
4434}
4435
4436static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4437{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004438 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004439 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004441
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4443 goto xdr_error;
4444 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4445 goto xdr_error;
4446 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4447 goto xdr_error;
4448
4449 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4450 goto xdr_error;
4451 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4452 goto xdr_error;
4453
4454 status = verify_attr_len(xdr, savep, attrlen);
4455xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004456 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004457 return status;
4458}
4459
Andy Adamson88034c32012-05-23 05:02:34 -04004460static int decode_threshold_hint(struct xdr_stream *xdr,
4461 uint32_t *bitmap,
4462 uint64_t *res,
4463 uint32_t hint_bit)
4464{
4465 __be32 *p;
4466
4467 *res = 0;
4468 if (likely(bitmap[0] & hint_bit)) {
4469 p = xdr_inline_decode(xdr, 8);
4470 if (unlikely(!p))
4471 goto out_overflow;
4472 xdr_decode_hyper(p, res);
4473 }
4474 return 0;
4475out_overflow:
4476 print_overflow_msg(__func__, xdr);
4477 return -EIO;
4478}
4479
4480static int decode_first_threshold_item4(struct xdr_stream *xdr,
4481 struct nfs4_threshold *res)
4482{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004483 __be32 *p;
4484 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004485 uint32_t bitmap[3] = {0,}, attrlen;
4486 int status;
4487
4488 /* layout type */
4489 p = xdr_inline_decode(xdr, 4);
4490 if (unlikely(!p)) {
4491 print_overflow_msg(__func__, xdr);
4492 return -EIO;
4493 }
4494 res->l_type = be32_to_cpup(p);
4495
4496 /* thi_hintset bitmap */
4497 status = decode_attr_bitmap(xdr, bitmap);
4498 if (status < 0)
4499 goto xdr_error;
4500
4501 /* thi_hintlist length */
4502 status = decode_attr_length(xdr, &attrlen, &savep);
4503 if (status < 0)
4504 goto xdr_error;
4505 /* thi_hintlist */
4506 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4507 if (status < 0)
4508 goto xdr_error;
4509 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4510 if (status < 0)
4511 goto xdr_error;
4512 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4513 THRESHOLD_RD_IO);
4514 if (status < 0)
4515 goto xdr_error;
4516 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4517 THRESHOLD_WR_IO);
4518 if (status < 0)
4519 goto xdr_error;
4520
4521 status = verify_attr_len(xdr, savep, attrlen);
4522 res->bm = bitmap[0];
4523
4524 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4525 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4526 res->wr_io_sz);
4527xdr_error:
4528 dprintk("%s ret=%d!\n", __func__, status);
4529 return status;
4530}
4531
4532/*
4533 * Thresholds on pNFS direct I/O vrs MDS I/O
4534 */
4535static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4536 uint32_t *bitmap,
4537 struct nfs4_threshold *res)
4538{
4539 __be32 *p;
4540 int status = 0;
4541 uint32_t num;
4542
4543 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4544 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004545 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004546 /* Did the server return an unrequested attribute? */
4547 if (unlikely(res == NULL))
4548 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004549 p = xdr_inline_decode(xdr, 4);
4550 if (unlikely(!p))
4551 goto out_overflow;
4552 num = be32_to_cpup(p);
4553 if (num == 0)
4554 return 0;
4555 if (num > 1)
4556 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4557 "drivers per filesystem not supported\n",
4558 __func__);
4559
4560 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004561 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004562 }
4563 return status;
4564out_overflow:
4565 print_overflow_msg(__func__, xdr);
4566 return -EIO;
4567}
4568
Bryan Schumakerae42c702010-10-21 16:33:17 -04004569static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4570 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004571 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004572 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573{
Trond Myklebustbca79472009-03-11 14:10:26 -04004574 int status;
4575 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004576 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004577 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004578
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004579 status = decode_attr_type(xdr, bitmap, &type);
4580 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004582 fattr->mode = 0;
4583 if (status != 0) {
4584 fattr->mode |= nfs_type2fmt[type];
4585 fattr->valid |= status;
4586 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004588 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4589 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004591 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004592
4593 status = decode_attr_size(xdr, bitmap, &fattr->size);
4594 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004596 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004597
4598 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4599 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004601 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004602
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004603 err = 0;
4604 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004605 if (status < 0)
4606 goto xdr_error;
4607
4608 status = decode_attr_filehandle(xdr, bitmap, fh);
4609 if (status < 0)
4610 goto xdr_error;
4611
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004612 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4613 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004614 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004615 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004616
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004617 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004618 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004619 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004620 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004621
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004622 status = -EIO;
4623 if (unlikely(bitmap[0]))
4624 goto xdr_error;
4625
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004626 status = decode_attr_mode(xdr, bitmap, &fmode);
4627 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004629 if (status != 0) {
4630 fattr->mode |= fmode;
4631 fattr->valid |= status;
4632 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004633
4634 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4635 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004636 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004637 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004638
Trond Myklebust6926afd2012-01-07 13:22:46 -05004639 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004640 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004642 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004643
Trond Myklebust6926afd2012-01-07 13:22:46 -05004644 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004645 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004647 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004648
4649 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4650 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004652 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004653
4654 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4655 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004657 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004658
4659 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4660 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004661 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004662 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004663
4664 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4665 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004667 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004668
4669 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4670 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004671 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004672 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004673
Trond Myklebust28331a42011-04-27 13:47:52 -04004674 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004675 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004676 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004677 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004678
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004679 status = -EIO;
4680 if (unlikely(bitmap[1]))
4681 goto xdr_error;
4682
Andy Adamson88034c32012-05-23 05:02:34 -04004683 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4684 if (status < 0)
4685 goto xdr_error;
4686
David Quigleyaa9c2662013-05-22 12:50:44 -04004687 if (label) {
4688 status = decode_attr_security_label(xdr, bitmap, label);
4689 if (status < 0)
4690 goto xdr_error;
4691 fattr->valid |= status;
4692 }
4693
Bryan Schumakerae42c702010-10-21 16:33:17 -04004694xdr_error:
4695 dprintk("%s: xdr returned %d\n", __func__, -status);
4696 return status;
4697}
4698
4699static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004700 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004701 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004702{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004703 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004704 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004705 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004706 int status;
4707
4708 status = decode_op_hdr(xdr, OP_GETATTR);
4709 if (status < 0)
4710 goto xdr_error;
4711
4712 status = decode_attr_bitmap(xdr, bitmap);
4713 if (status < 0)
4714 goto xdr_error;
4715
4716 status = decode_attr_length(xdr, &attrlen, &savep);
4717 if (status < 0)
4718 goto xdr_error;
4719
David Quigleyaa9c2662013-05-22 12:50:44 -04004720 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4721 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004722 if (status < 0)
4723 goto xdr_error;
4724
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004725 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004727 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728 return status;
4729}
4730
David Quigleyaa9c2662013-05-22 12:50:44 -04004731static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4732 struct nfs4_label *label, const struct nfs_server *server)
4733{
4734 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4735}
4736
Bryan Schumakerae42c702010-10-21 16:33:17 -04004737static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004738 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004739{
David Quigleyaa9c2662013-05-22 12:50:44 -04004740 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004741}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004742
Andy Adamson504913f2010-10-20 00:17:57 -04004743/*
Jeff Layton3132e492016-08-10 15:58:24 -04004744 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004745 */
Jeff Layton3132e492016-08-10 15:58:24 -04004746static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004747 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004748{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004749 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004750 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004751
4752 p = xdr_inline_decode(xdr, 4);
4753 if (unlikely(!p))
4754 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004755 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004756
4757 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004758 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004759 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004760
4761 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004762 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004763 if (unlikely(!p))
4764 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004765
4766 /* If we get too many, then just cap it at the max */
4767 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4768 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4769 __func__, fsinfo->nlayouttypes);
4770 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4771 }
4772
4773 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4774 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004775 return 0;
4776out_overflow:
4777 print_overflow_msg(__func__, xdr);
4778 return -EIO;
4779}
4780
4781/*
4782 * The type of file system exported.
4783 * Note we must ensure that layouttype is set in any non-error case.
4784 */
4785static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004786 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004787{
4788 int status = 0;
4789
4790 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4791 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4792 return -EIO;
4793 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004794 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004795 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004796 }
Andy Adamson504913f2010-10-20 00:17:57 -04004797 return status;
4798}
4799
Fred Isamandae100c2011-07-30 20:52:37 -04004800/*
4801 * The prefered block size for layout directed io
4802 */
4803static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4804 uint32_t *res)
4805{
4806 __be32 *p;
4807
4808 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4809 *res = 0;
4810 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4811 p = xdr_inline_decode(xdr, 4);
4812 if (unlikely(!p)) {
4813 print_overflow_msg(__func__, xdr);
4814 return -EIO;
4815 }
4816 *res = be32_to_cpup(p);
4817 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4818 }
4819 return 0;
4820}
4821
Peng Tao2a92ee92015-09-26 02:24:37 +08004822/*
4823 * The granularity of a CLONE operation.
4824 */
4825static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4826 uint32_t *res)
4827{
4828 __be32 *p;
4829
4830 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4831 *res = 0;
4832 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4833 p = xdr_inline_decode(xdr, 4);
4834 if (unlikely(!p)) {
4835 print_overflow_msg(__func__, xdr);
4836 return -EIO;
4837 }
4838 *res = be32_to_cpup(p);
4839 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4840 }
4841 return 0;
4842}
4843
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4845{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004846 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004847 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848 int status;
4849
4850 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4851 goto xdr_error;
4852 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4853 goto xdr_error;
4854 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4855 goto xdr_error;
4856
4857 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4858
4859 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4860 goto xdr_error;
4861 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4862 goto xdr_error;
4863 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4864 goto xdr_error;
4865 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4866 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4867 goto xdr_error;
4868 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004869
4870 status = -EIO;
4871 if (unlikely(bitmap[0]))
4872 goto xdr_error;
4873
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004874 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4875 if (status != 0)
4876 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004877 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004878 if (status != 0)
4879 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004880
4881 status = -EIO;
4882 if (unlikely(bitmap[1]))
4883 goto xdr_error;
4884
Fred Isamandae100c2011-07-30 20:52:37 -04004885 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4886 if (status)
4887 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004888 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4889 if (status)
4890 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891
4892 status = verify_attr_len(xdr, savep, attrlen);
4893xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004894 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895 return status;
4896}
4897
4898static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4899{
Al Viro8687b632006-10-19 23:28:48 -07004900 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901 uint32_t len;
4902 int status;
4903
Trond Myklebust99367812007-07-17 21:52:41 -04004904 /* Zero handle first to allow comparisons */
4905 memset(fh, 0, sizeof(*fh));
4906
Linus Torvalds1da177e2005-04-16 15:20:36 -07004907 status = decode_op_hdr(xdr, OP_GETFH);
4908 if (status)
4909 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910
Benny Halevyc0eae662009-08-14 17:20:14 +03004911 p = xdr_inline_decode(xdr, 4);
4912 if (unlikely(!p))
4913 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004914 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004915 if (len > NFS4_FHSIZE)
4916 return -EIO;
4917 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004918 p = xdr_inline_decode(xdr, len);
4919 if (unlikely(!p))
4920 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004921 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004923out_overflow:
4924 print_overflow_msg(__func__, xdr);
4925 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926}
4927
4928static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4929{
4930 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004931
Linus Torvalds1da177e2005-04-16 15:20:36 -07004932 status = decode_op_hdr(xdr, OP_LINK);
4933 if (status)
4934 return status;
4935 return decode_change_info(xdr, cinfo);
4936}
4937
4938/*
4939 * We create the owner, so we know a proper owner.id length is 4.
4940 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004941static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004943 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004944 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004945 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004947 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004948 if (unlikely(!p))
4949 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004950 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004951 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004952 type = be32_to_cpup(p++); /* 4 byte read */
4953 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004954 fl->fl_start = (loff_t)offset;
4955 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4956 if (length == ~(uint64_t)0)
4957 fl->fl_end = OFFSET_MAX;
4958 fl->fl_type = F_WRLCK;
4959 if (type & 1)
4960 fl->fl_type = F_RDLCK;
4961 fl->fl_pid = 0;
4962 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004963 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4964 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4965 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004966 if (likely(p))
4967 return -NFS4ERR_DENIED;
4968out_overflow:
4969 print_overflow_msg(__func__, xdr);
4970 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971}
4972
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004973static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975 int status;
4976
4977 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004978 if (status == -EIO)
4979 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04004981 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004982 if (unlikely(status))
4983 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004985 status = decode_lock_denied(xdr, NULL);
4986 if (res->open_seqid != NULL)
4987 nfs_increment_open_seqid(status, res->open_seqid);
4988 nfs_increment_lock_seqid(status, res->lock_seqid);
4989out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990 return status;
4991}
4992
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004993static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994{
4995 int status;
4996 status = decode_op_hdr(xdr, OP_LOCKT);
4997 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004998 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999 return status;
5000}
5001
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005002static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005004 int status;
5005
5006 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005007 if (status != -EIO)
5008 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005009 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005010 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011 return status;
5012}
5013
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005014static int decode_release_lockowner(struct xdr_stream *xdr)
5015{
5016 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5017}
5018
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019static int decode_lookup(struct xdr_stream *xdr)
5020{
5021 return decode_op_hdr(xdr, OP_LOOKUP);
5022}
5023
5024/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005025static int decode_space_limit(struct xdr_stream *xdr,
5026 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005027{
Andy Adamson05d564f2008-12-23 16:06:15 -05005028 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005030 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031
Benny Halevyc0eae662009-08-14 17:20:14 +03005032 p = xdr_inline_decode(xdr, 12);
5033 if (unlikely(!p))
5034 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005035 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005036 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005037 case NFS4_LIMIT_SIZE:
5038 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005039 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005040 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005041 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005042 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005043 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005045 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005046 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005047 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005048out_overflow:
5049 print_overflow_msg(__func__, xdr);
5050 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005051}
5052
Trond Myklebust6ae37332015-01-30 14:21:14 -05005053static int decode_rw_delegation(struct xdr_stream *xdr,
5054 uint32_t delegation_type,
5055 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056{
Andy Adamson05d564f2008-12-23 16:06:15 -05005057 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005058 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005059
Trond Myklebust93b717f2016-05-16 17:42:43 -04005060 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005061 if (unlikely(status))
5062 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005063 p = xdr_inline_decode(xdr, 4);
5064 if (unlikely(!p))
5065 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005066 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005067
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005069 case NFS4_OPEN_DELEGATE_READ:
5070 res->delegation_type = FMODE_READ;
5071 break;
5072 case NFS4_OPEN_DELEGATE_WRITE:
5073 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005074 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005075 return -EIO;
5076 }
David Howells7539bba2006-08-22 20:06:09 -04005077 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03005078out_overflow:
5079 print_overflow_msg(__func__, xdr);
5080 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081}
5082
Trond Myklebust6ae37332015-01-30 14:21:14 -05005083static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5084{
5085 __be32 *p;
5086 uint32_t why_no_delegation;
5087
5088 p = xdr_inline_decode(xdr, 4);
5089 if (unlikely(!p))
5090 goto out_overflow;
5091 why_no_delegation = be32_to_cpup(p);
5092 switch (why_no_delegation) {
5093 case WND4_CONTENTION:
5094 case WND4_RESOURCE:
5095 xdr_inline_decode(xdr, 4);
5096 /* Ignore for now */
5097 }
5098 return 0;
5099out_overflow:
5100 print_overflow_msg(__func__, xdr);
5101 return -EIO;
5102}
5103
5104static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5105{
5106 __be32 *p;
5107 uint32_t delegation_type;
5108
5109 p = xdr_inline_decode(xdr, 4);
5110 if (unlikely(!p))
5111 goto out_overflow;
5112 delegation_type = be32_to_cpup(p);
5113 res->delegation_type = 0;
5114 switch (delegation_type) {
5115 case NFS4_OPEN_DELEGATE_NONE:
5116 return 0;
5117 case NFS4_OPEN_DELEGATE_READ:
5118 case NFS4_OPEN_DELEGATE_WRITE:
5119 return decode_rw_delegation(xdr, delegation_type, res);
5120 case NFS4_OPEN_DELEGATE_NONE_EXT:
5121 return decode_no_delegation(xdr, res);
5122 }
5123 return -EIO;
5124out_overflow:
5125 print_overflow_msg(__func__, xdr);
5126 return -EIO;
5127}
5128
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5130{
Andy Adamson05d564f2008-12-23 16:06:15 -05005131 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005132 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005133 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005134
Trond Myklebustc7848f62013-12-04 17:39:23 -05005135 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5136 return status;
5137 nfs_increment_open_seqid(status, res->seqid);
5138 if (status)
5139 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005140 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005141 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005142 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143
Andy Adamson05d564f2008-12-23 16:06:15 -05005144 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005145
Benny Halevyc0eae662009-08-14 17:20:14 +03005146 p = xdr_inline_decode(xdr, 8);
5147 if (unlikely(!p))
5148 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005149 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005150 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005151 if (bmlen > 10)
5152 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153
Benny Halevyc0eae662009-08-14 17:20:14 +03005154 p = xdr_inline_decode(xdr, bmlen << 2);
5155 if (unlikely(!p))
5156 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005157 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5158 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005159 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005160 for (; i < NFS4_BITMAP_SIZE; i++)
5161 res->attrset[i] = 0;
5162
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163 return decode_delegation(xdr, res);
5164xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005165 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005166 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005167out_overflow:
5168 print_overflow_msg(__func__, xdr);
5169 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170}
5171
5172static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5173{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005174 int status;
5175
Andy Adamson05d564f2008-12-23 16:06:15 -05005176 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005177 if (status != -EIO)
5178 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005179 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005180 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005181 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182}
5183
5184static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5185{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005186 int status;
5187
5188 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005189 if (status != -EIO)
5190 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005191 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005192 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005193 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194}
5195
5196static int decode_putfh(struct xdr_stream *xdr)
5197{
5198 return decode_op_hdr(xdr, OP_PUTFH);
5199}
5200
5201static int decode_putrootfh(struct xdr_stream *xdr)
5202{
5203 return decode_op_hdr(xdr, OP_PUTROOTFH);
5204}
5205
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005206static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5207 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005208{
Al Viro8687b632006-10-19 23:28:48 -07005209 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005210 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005211 int status;
5212
5213 status = decode_op_hdr(xdr, OP_READ);
5214 if (status)
5215 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005216 p = xdr_inline_decode(xdr, 8);
5217 if (unlikely(!p))
5218 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005219 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005220 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005221 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005222 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005223 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005224 "count %u > recvd %u\n", count, recvd);
5225 count = recvd;
5226 eof = 0;
5227 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228 res->eof = eof;
5229 res->count = count;
5230 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005231out_overflow:
5232 print_overflow_msg(__func__, xdr);
5233 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234}
5235
5236static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5237{
Chuck Leverbcecff72007-10-26 13:32:03 -04005238 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005239 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240
5241 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005242 if (!status)
5243 status = decode_verifier(xdr, readdir->verifier.data);
5244 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005246 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005247 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005248 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005249 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250}
5251
5252static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5253{
5254 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005255 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005256 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005257 int status;
5258
5259 status = decode_op_hdr(xdr, OP_READLINK);
5260 if (status)
5261 return status;
5262
5263 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005264 p = xdr_inline_decode(xdr, 4);
5265 if (unlikely(!p))
5266 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005267 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005268 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005269 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005270 return -ENAMETOOLONG;
5271 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005272 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005273 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005274 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005275 "count %u > recvd %u\n", len, recvd);
5276 return -EIO;
5277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005278 /*
5279 * The XDR encode routine has set things up so that
5280 * the link text will be copied directly into the
5281 * buffer. We just have to do overflow-checking,
5282 * and and null-terminate the text (the VFS expects
5283 * null-termination).
5284 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005285 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005287out_overflow:
5288 print_overflow_msg(__func__, xdr);
5289 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290}
5291
5292static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5293{
5294 int status;
5295
5296 status = decode_op_hdr(xdr, OP_REMOVE);
5297 if (status)
5298 goto out;
5299 status = decode_change_info(xdr, cinfo);
5300out:
5301 return status;
5302}
5303
5304static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5305 struct nfs4_change_info *new_cinfo)
5306{
5307 int status;
5308
5309 status = decode_op_hdr(xdr, OP_RENAME);
5310 if (status)
5311 goto out;
5312 if ((status = decode_change_info(xdr, old_cinfo)))
5313 goto out;
5314 status = decode_change_info(xdr, new_cinfo);
5315out:
5316 return status;
5317}
5318
5319static int decode_renew(struct xdr_stream *xdr)
5320{
5321 return decode_op_hdr(xdr, OP_RENEW);
5322}
5323
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005324static int
5325decode_restorefh(struct xdr_stream *xdr)
5326{
5327 return decode_op_hdr(xdr, OP_RESTOREFH);
5328}
5329
J. Bruce Fields029d1052005-06-22 17:16:22 +00005330static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005331 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005332{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005333 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005334 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005335 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005336 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005337 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005338
Andy Adamsonbf118a32011-12-07 11:55:27 -05005339 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005340 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5341 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005342
Trond Myklebust519d3952012-08-14 17:30:10 -04005343 xdr_enter_page(xdr, xdr->buf->page_len);
5344
Trond Myklebustcff298c2012-08-14 17:14:17 -04005345 /* Calculate the offset of the page data */
5346 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005347
J. Bruce Fields029d1052005-06-22 17:16:22 +00005348 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5349 goto out;
5350 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5351 goto out;
5352
5353 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5354 return -EIO;
5355 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005356
Andy Adamsonbf118a32011-12-07 11:55:27 -05005357 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5358 * are stored with the acl data to handle the problem of
5359 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005360 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005361 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005362
5363 /* Check for receive buffer overflow */
5364 if (res->acl_len > (xdr->nwords << 2) ||
5365 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5366 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005367 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005368 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005369 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005370 } else
5371 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005372
5373out:
5374 return status;
5375}
5376
Linus Torvalds1da177e2005-04-16 15:20:36 -07005377static int
5378decode_savefh(struct xdr_stream *xdr)
5379{
5380 return decode_op_hdr(xdr, OP_SAVEFH);
5381}
5382
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005383static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005384{
Al Viro8687b632006-10-19 23:28:48 -07005385 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005386 uint32_t bmlen;
5387 int status;
5388
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389 status = decode_op_hdr(xdr, OP_SETATTR);
5390 if (status)
5391 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005392 p = xdr_inline_decode(xdr, 4);
5393 if (unlikely(!p))
5394 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005395 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005396 p = xdr_inline_decode(xdr, bmlen << 2);
5397 if (likely(p))
5398 return 0;
5399out_overflow:
5400 print_overflow_msg(__func__, xdr);
5401 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005402}
5403
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005404static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005405{
Al Viro8687b632006-10-19 23:28:48 -07005406 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005407 uint32_t opnum;
5408 int32_t nfserr;
5409
Benny Halevyc0eae662009-08-14 17:20:14 +03005410 p = xdr_inline_decode(xdr, 8);
5411 if (unlikely(!p))
5412 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005413 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005414 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005415 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005416 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005417 return -EIO;
5418 }
Benny Halevycccddf42009-08-14 17:20:19 +03005419 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005420 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005421 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5422 if (unlikely(!p))
5423 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005424 p = xdr_decode_hyper(p, &res->clientid);
5425 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005426 } else if (nfserr == NFSERR_CLID_INUSE) {
5427 uint32_t len;
5428
5429 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005430 p = xdr_inline_decode(xdr, 4);
5431 if (unlikely(!p))
5432 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005433 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005434 p = xdr_inline_decode(xdr, len);
5435 if (unlikely(!p))
5436 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005437
5438 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005439 p = xdr_inline_decode(xdr, 4);
5440 if (unlikely(!p))
5441 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005442 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005443 p = xdr_inline_decode(xdr, len);
5444 if (unlikely(!p))
5445 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005446 return -NFSERR_CLID_INUSE;
5447 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005448 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005449
5450 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005451out_overflow:
5452 print_overflow_msg(__func__, xdr);
5453 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005454}
5455
5456static int decode_setclientid_confirm(struct xdr_stream *xdr)
5457{
5458 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5459}
5460
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005461static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005462{
Al Viro8687b632006-10-19 23:28:48 -07005463 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005464 int status;
5465
5466 status = decode_op_hdr(xdr, OP_WRITE);
5467 if (status)
5468 return status;
5469
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005470 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005471 if (unlikely(!p))
5472 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005473 res->count = be32_to_cpup(p++);
5474 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005475 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005476out_overflow:
5477 print_overflow_msg(__func__, xdr);
5478 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005479}
5480
5481static int decode_delegreturn(struct xdr_stream *xdr)
5482{
5483 return decode_op_hdr(xdr, OP_DELEGRETURN);
5484}
5485
Chuck Leverfb15b262013-03-16 15:54:34 -04005486static int decode_secinfo_gss(struct xdr_stream *xdr,
5487 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005488{
Chuck Leverfb15b262013-03-16 15:54:34 -04005489 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005490 __be32 *p;
5491
5492 p = xdr_inline_decode(xdr, 4);
5493 if (unlikely(!p))
5494 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005495 oid_len = be32_to_cpup(p);
5496 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005497 goto out_err;
5498
Chuck Leverfb15b262013-03-16 15:54:34 -04005499 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005500 if (unlikely(!p))
5501 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005502 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5503 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005504
5505 p = xdr_inline_decode(xdr, 8);
5506 if (unlikely(!p))
5507 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005508 flavor->flavor_info.qop = be32_to_cpup(p++);
5509 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005510
5511 return 0;
5512
5513out_overflow:
5514 print_overflow_msg(__func__, xdr);
5515 return -EIO;
5516out_err:
5517 return -EINVAL;
5518}
5519
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005520static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005521{
Chuck Leverfb15b262013-03-16 15:54:34 -04005522 struct nfs4_secinfo4 *sec_flavor;
5523 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005524 int status;
5525 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005526
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005527 p = xdr_inline_decode(xdr, 4);
5528 if (unlikely(!p))
5529 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005530
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005531 res->flavors->num_flavors = 0;
5532 num_flavors = be32_to_cpup(p);
5533
5534 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005535 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005536 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005537 break;
5538
5539 p = xdr_inline_decode(xdr, 4);
5540 if (unlikely(!p))
5541 goto out_overflow;
5542 sec_flavor->flavor = be32_to_cpup(p);
5543
5544 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005545 status = decode_secinfo_gss(xdr, sec_flavor);
5546 if (status)
5547 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005548 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005549 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005550 }
5551
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005552 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005553out:
5554 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005555out_overflow:
5556 print_overflow_msg(__func__, xdr);
5557 return -EIO;
5558}
5559
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005560static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5561{
5562 int status = decode_op_hdr(xdr, OP_SECINFO);
5563 if (status)
5564 return status;
5565 return decode_secinfo_common(xdr, res);
5566}
5567
Benny Halevy99fe60d2009-04-01 09:22:29 -04005568#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005569static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5570{
5571 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5572 if (status)
5573 return status;
5574 return decode_secinfo_common(xdr, res);
5575}
5576
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005577static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5578{
5579 __be32 *p;
5580 uint32_t bitmap_words;
5581 unsigned int i;
5582
5583 p = xdr_inline_decode(xdr, 4);
5584 bitmap_words = be32_to_cpup(p++);
5585 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5586 return -EIO;
5587 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5588 for (i = 0; i < bitmap_words; i++)
5589 op_map->u.words[i] = be32_to_cpup(p++);
5590
5591 return 0;
5592}
5593
Benny Halevy99fe60d2009-04-01 09:22:29 -04005594static int decode_exchange_id(struct xdr_stream *xdr,
5595 struct nfs41_exchange_id_res *res)
5596{
5597 __be32 *p;
5598 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005599 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005600 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005601 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005602
5603 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5604 if (status)
5605 return status;
5606
Benny Halevyc0eae662009-08-14 17:20:14 +03005607 p = xdr_inline_decode(xdr, 8);
5608 if (unlikely(!p))
5609 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005610 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005611 p = xdr_inline_decode(xdr, 12);
5612 if (unlikely(!p))
5613 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005614 res->seqid = be32_to_cpup(p++);
5615 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005616
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005617 res->state_protect.how = be32_to_cpup(p);
5618 switch (res->state_protect.how) {
5619 case SP4_NONE:
5620 break;
5621 case SP4_MACH_CRED:
5622 status = decode_op_map(xdr, &res->state_protect.enforce);
5623 if (status)
5624 return status;
5625 status = decode_op_map(xdr, &res->state_protect.allow);
5626 if (status)
5627 return status;
5628 break;
5629 default:
5630 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005631 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005632 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005633
Chuck Leveracdeb692012-05-21 22:46:16 -04005634 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005635 p = xdr_inline_decode(xdr, 8);
5636 if (unlikely(!p))
5637 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005638 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005639
Chuck Leveracdeb692012-05-21 22:46:16 -04005640 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005641 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5642 if (unlikely(status))
5643 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005644 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5645 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005646 memcpy(res->server_owner->major_id, dummy_str, dummy);
5647 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005648
Chuck Leveracdeb692012-05-21 22:46:16 -04005649 /* server_scope4 */
5650 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5651 if (unlikely(status))
5652 return status;
5653 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5654 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005655 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5656 res->server_scope->server_scope_sz = dummy;
5657
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005658 /* Implementation Id */
5659 p = xdr_inline_decode(xdr, 4);
5660 if (unlikely(!p))
5661 goto out_overflow;
5662 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005663
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005664 if (impl_id_count) {
5665 /* nii_domain */
5666 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5667 if (unlikely(status))
5668 return status;
5669 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5670 return -EIO;
5671 memcpy(res->impl_id->domain, dummy_str, dummy);
5672
5673 /* nii_name */
5674 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5675 if (unlikely(status))
5676 return status;
5677 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5678 return -EIO;
5679 memcpy(res->impl_id->name, dummy_str, dummy);
5680
5681 /* nii_date */
5682 p = xdr_inline_decode(xdr, 12);
5683 if (unlikely(!p))
5684 goto out_overflow;
5685 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5686 res->impl_id->date.nseconds = be32_to_cpup(p);
5687
5688 /* if there's more than one entry, ignore the rest */
5689 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005690 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005691out_overflow:
5692 print_overflow_msg(__func__, xdr);
5693 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005694}
Andy Adamsonfc931582009-04-01 09:22:31 -04005695
5696static int decode_chan_attrs(struct xdr_stream *xdr,
5697 struct nfs4_channel_attrs *attrs)
5698{
5699 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005700 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005701
Benny Halevyc0eae662009-08-14 17:20:14 +03005702 p = xdr_inline_decode(xdr, 28);
5703 if (unlikely(!p))
5704 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005705 val = be32_to_cpup(p++); /* headerpadsz */
5706 if (val)
5707 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005708 attrs->max_rqst_sz = be32_to_cpup(p++);
5709 attrs->max_resp_sz = be32_to_cpup(p++);
5710 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5711 attrs->max_ops = be32_to_cpup(p++);
5712 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005713 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005714 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005715 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5716 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005717 return -EINVAL;
5718 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005719 if (nr_attrs == 1) {
5720 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5721 if (unlikely(!p))
5722 goto out_overflow;
5723 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005724 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005725out_overflow:
5726 print_overflow_msg(__func__, xdr);
5727 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005728}
5729
Benny Halevye78291e2009-08-14 17:20:00 +03005730static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5731{
5732 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005733}
5734
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005735static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5736 struct nfs41_bind_conn_to_session_res *res)
5737{
5738 __be32 *p;
5739 int status;
5740
5741 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5742 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005743 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005744 if (unlikely(status))
5745 return status;
5746
5747 /* dir flags, rdma mode bool */
5748 p = xdr_inline_decode(xdr, 8);
5749 if (unlikely(!p))
5750 goto out_overflow;
5751
5752 res->dir = be32_to_cpup(p++);
5753 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5754 return -EIO;
5755 if (be32_to_cpup(p) == 0)
5756 res->use_conn_in_rdma_mode = false;
5757 else
5758 res->use_conn_in_rdma_mode = true;
5759
5760 return 0;
5761out_overflow:
5762 print_overflow_msg(__func__, xdr);
5763 return -EIO;
5764}
5765
Andy Adamsonfc931582009-04-01 09:22:31 -04005766static int decode_create_session(struct xdr_stream *xdr,
5767 struct nfs41_create_session_res *res)
5768{
5769 __be32 *p;
5770 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005771
5772 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005773 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005774 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005775 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005776 return status;
5777
Andy Adamsonfc931582009-04-01 09:22:31 -04005778 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005779 p = xdr_inline_decode(xdr, 8);
5780 if (unlikely(!p))
5781 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005782 res->seqid = be32_to_cpup(p++);
5783 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005784
5785 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005786 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005787 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005788 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005789 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005790out_overflow:
5791 print_overflow_msg(__func__, xdr);
5792 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005793}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005794
5795static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5796{
5797 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5798}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005799
Trond Myklebust66245532012-05-25 17:18:09 -04005800static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5801{
5802 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5803}
5804
Ricardo Labiaga180197532009-12-05 16:08:40 -05005805static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5806{
5807 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5808}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005809#endif /* CONFIG_NFS_V4_1 */
5810
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005811static int decode_sequence(struct xdr_stream *xdr,
5812 struct nfs4_sequence_res *res,
5813 struct rpc_rqst *rqstp)
5814{
5815#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005816 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005817 struct nfs4_sessionid id;
5818 u32 dummy;
5819 int status;
5820 __be32 *p;
5821
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005822 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005823 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005824 if (!res->sr_slot->table->session)
5825 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005826
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005827 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005828 if (!status)
5829 status = decode_sessionid(xdr, &id);
5830 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005831 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005832
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005833 /*
5834 * If the server returns different values for sessionID, slotID or
5835 * sequence number, the server is looney tunes.
5836 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005837 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005838 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005839
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005840 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005841 NFS4_MAX_SESSIONID_LEN)) {
5842 dprintk("%s Invalid session id\n", __func__);
5843 goto out_err;
5844 }
Benny Halevye78291e2009-08-14 17:20:00 +03005845
Benny Halevyc0eae662009-08-14 17:20:14 +03005846 p = xdr_inline_decode(xdr, 20);
5847 if (unlikely(!p))
5848 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005849
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005850 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005851 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005852 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005853 dprintk("%s Invalid sequence number\n", __func__);
5854 goto out_err;
5855 }
5856 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005857 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005858 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005859 dprintk("%s Invalid slot id\n", __func__);
5860 goto out_err;
5861 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005862 /* highest slot id */
5863 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005864 /* target highest slot id */
5865 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005866 /* result flags */
5867 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005868 status = 0;
5869out_err:
5870 res->sr_status = status;
5871 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005872out_overflow:
5873 print_overflow_msg(__func__, xdr);
5874 status = -EIO;
5875 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005876#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005877 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005878#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005879}
5880
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005881#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005882static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5883{
5884 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5885 return decode_stateid(xdr, stateid);
5886}
5887
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005888static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005889 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005890{
Trond Myklebust4e590802015-03-09 14:01:25 -04005891 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005892 __be32 *p;
5893 uint32_t len, type;
5894 int status;
5895
5896 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5897 if (status) {
5898 if (status == -ETOOSMALL) {
5899 p = xdr_inline_decode(xdr, 4);
5900 if (unlikely(!p))
5901 goto out_overflow;
5902 pdev->mincount = be32_to_cpup(p);
5903 dprintk("%s: Min count too small. mincnt = %u\n",
5904 __func__, pdev->mincount);
5905 }
5906 return status;
5907 }
5908
5909 p = xdr_inline_decode(xdr, 8);
5910 if (unlikely(!p))
5911 goto out_overflow;
5912 type = be32_to_cpup(p++);
5913 if (type != pdev->layout_type) {
5914 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5915 __func__, pdev->layout_type, type);
5916 return -EINVAL;
5917 }
5918 /*
5919 * Get the length of the opaque device_addr4. xdr_read_pages places
5920 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5921 * and places the remaining xdr data in xdr_buf->tail
5922 */
5923 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005924 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5925 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005926
5927 /* Parse notification bitmap, verifying that it is zero. */
5928 p = xdr_inline_decode(xdr, 4);
5929 if (unlikely(!p))
5930 goto out_overflow;
5931 len = be32_to_cpup(p);
5932 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005933 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005934
5935 p = xdr_inline_decode(xdr, 4 * len);
5936 if (unlikely(!p))
5937 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005938
Trond Myklebust4e590802015-03-09 14:01:25 -04005939 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005940 for (i = 1; i < len; i++) {
5941 if (be32_to_cpup(p++)) {
5942 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005943 __func__);
5944 return -EIO;
5945 }
5946 }
5947 }
5948 return 0;
5949out_overflow:
5950 print_overflow_msg(__func__, xdr);
5951 return -EIO;
5952}
5953
5954static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5955 struct nfs4_layoutget_res *res)
5956{
5957 __be32 *p;
5958 int status;
5959 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005960 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005961
5962 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5963 if (status)
5964 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005965 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005966 if (unlikely(!p))
5967 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005968 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04005969 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005970 p = xdr_inline_decode(xdr, 4);
5971 if (unlikely(!p))
5972 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005973 layout_count = be32_to_cpup(p);
5974 if (!layout_count) {
5975 dprintk("%s: server responded with empty layout array\n",
5976 __func__);
5977 return -EINVAL;
5978 }
5979
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005980 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005981 if (unlikely(!p))
5982 goto out_overflow;
5983 p = xdr_decode_hyper(p, &res->range.offset);
5984 p = xdr_decode_hyper(p, &res->range.length);
5985 res->range.iomode = be32_to_cpup(p++);
5986 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005987 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005988
5989 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5990 __func__,
5991 (unsigned long)res->range.offset,
5992 (unsigned long)res->range.length,
5993 res->range.iomode,
5994 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005995 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005996
Trond Myklebust64bd5772012-06-20 22:35:05 -04005997 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005998 if (res->layoutp->len > recvd) {
5999 dprintk("NFS: server cheating in layoutget reply: "
6000 "layout len %u > recvd %u\n",
6001 res->layoutp->len, recvd);
6002 return -EINVAL;
6003 }
6004
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006005 if (layout_count > 1) {
6006 /* We only handle a length one array at the moment. Any
6007 * further entries are just ignored. Note that this means
6008 * the client may see a response that is less than the
6009 * minimum it requested.
6010 */
6011 dprintk("%s: server responded with %d layouts, dropping tail\n",
6012 __func__, layout_count);
6013 }
6014
6015 return 0;
6016out_overflow:
6017 print_overflow_msg(__func__, xdr);
6018 return -EIO;
6019}
Andy Adamson863a3c62011-03-23 13:27:54 +00006020
Benny Halevycbe82602011-05-22 19:52:37 +03006021static int decode_layoutreturn(struct xdr_stream *xdr,
6022 struct nfs4_layoutreturn_res *res)
6023{
6024 __be32 *p;
6025 int status;
6026
6027 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6028 if (status)
6029 return status;
6030 p = xdr_inline_decode(xdr, 4);
6031 if (unlikely(!p))
6032 goto out_overflow;
6033 res->lrs_present = be32_to_cpup(p);
6034 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04006035 status = decode_layout_stateid(xdr, &res->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03006036 return status;
6037out_overflow:
6038 print_overflow_msg(__func__, xdr);
6039 return -EIO;
6040}
6041
Andy Adamson863a3c62011-03-23 13:27:54 +00006042static int decode_layoutcommit(struct xdr_stream *xdr,
6043 struct rpc_rqst *req,
6044 struct nfs4_layoutcommit_res *res)
6045{
6046 __be32 *p;
6047 __u32 sizechanged;
6048 int status;
6049
6050 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04006051 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00006052 if (status)
6053 return status;
6054
6055 p = xdr_inline_decode(xdr, 4);
6056 if (unlikely(!p))
6057 goto out_overflow;
6058 sizechanged = be32_to_cpup(p);
6059
6060 if (sizechanged) {
6061 /* throw away new size */
6062 p = xdr_inline_decode(xdr, 8);
6063 if (unlikely(!p))
6064 goto out_overflow;
6065 }
6066 return 0;
6067out_overflow:
6068 print_overflow_msg(__func__, xdr);
6069 return -EIO;
6070}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006071
6072static int decode_test_stateid(struct xdr_stream *xdr,
6073 struct nfs41_test_stateid_res *res)
6074{
6075 __be32 *p;
6076 int status;
6077 int num_res;
6078
6079 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6080 if (status)
6081 return status;
6082
6083 p = xdr_inline_decode(xdr, 4);
6084 if (unlikely(!p))
6085 goto out_overflow;
6086 num_res = be32_to_cpup(p++);
6087 if (num_res != 1)
6088 goto out;
6089
6090 p = xdr_inline_decode(xdr, 4);
6091 if (unlikely(!p))
6092 goto out_overflow;
6093 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006094
6095 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006096out_overflow:
6097 print_overflow_msg(__func__, xdr);
6098out:
6099 return -EIO;
6100}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006101
6102static int decode_free_stateid(struct xdr_stream *xdr,
6103 struct nfs41_free_stateid_res *res)
6104{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006105 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006106 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006107}
Trond Myklebustcf805162016-11-15 14:56:07 -05006108#else
6109static inline
6110int decode_layoutreturn(struct xdr_stream *xdr,
6111 struct nfs4_layoutreturn_res *res)
6112{
6113 return 0;
6114}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006115#endif /* CONFIG_NFS_V4_1 */
6116
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117/*
Benny Halevy49c25592008-12-23 16:06:16 -05006118 * END OF "GENERIC" DECODE ROUTINES.
6119 */
6120
6121/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006122 * Decode OPEN_DOWNGRADE response
6123 */
Chuck Leverbf269552010-12-14 14:59:29 +00006124static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6125 struct xdr_stream *xdr,
6126 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006127{
Andy Adamson05d564f2008-12-23 16:06:15 -05006128 struct compound_hdr hdr;
6129 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006130
Chuck Leverbf269552010-12-14 14:59:29 +00006131 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006132 if (status)
6133 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006134 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006135 if (status)
6136 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006137 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006138 if (status)
6139 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006140 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006141out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006142 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143}
6144
6145/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146 * Decode ACCESS response
6147 */
Chuck Leverbf269552010-12-14 14:59:29 +00006148static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6149 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006150{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006151 struct compound_hdr hdr;
6152 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006153
Chuck Leverbf269552010-12-14 14:59:29 +00006154 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006155 if (status)
6156 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006157 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006158 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006159 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006160 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006161 if (status != 0)
6162 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006163 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006164 if (status != 0)
6165 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006166 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006167out:
6168 return status;
6169}
6170
6171/*
6172 * Decode LOOKUP response
6173 */
Chuck Leverbf269552010-12-14 14:59:29 +00006174static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6175 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006176{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006177 struct compound_hdr hdr;
6178 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006179
Chuck Leverbf269552010-12-14 14:59:29 +00006180 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006181 if (status)
6182 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006183 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006184 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006186 status = decode_putfh(xdr);
6187 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006189 status = decode_lookup(xdr);
6190 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006192 status = decode_getfh(xdr, res->fh);
6193 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006195 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196out:
6197 return status;
6198}
6199
6200/*
6201 * Decode LOOKUP_ROOT response
6202 */
Chuck Leverbf269552010-12-14 14:59:29 +00006203static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6204 struct xdr_stream *xdr,
6205 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207 struct compound_hdr hdr;
6208 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006209
Chuck Leverbf269552010-12-14 14:59:29 +00006210 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006211 if (status)
6212 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006213 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006214 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006215 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006216 status = decode_putrootfh(xdr);
6217 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006219 status = decode_getfh(xdr, res->fh);
6220 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006221 status = decode_getfattr_label(xdr, res->fattr,
6222 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006223out:
6224 return status;
6225}
6226
6227/*
6228 * Decode REMOVE response
6229 */
Chuck Leverbf269552010-12-14 14:59:29 +00006230static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6231 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006232{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233 struct compound_hdr hdr;
6234 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006235
Chuck Leverbf269552010-12-14 14:59:29 +00006236 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006237 if (status)
6238 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006239 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006240 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006241 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006242 status = decode_putfh(xdr);
6243 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006244 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006245 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246out:
6247 return status;
6248}
6249
6250/*
6251 * Decode RENAME response
6252 */
Chuck Leverbf269552010-12-14 14:59:29 +00006253static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6254 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006255{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006256 struct compound_hdr hdr;
6257 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006258
Chuck Leverbf269552010-12-14 14:59:29 +00006259 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006260 if (status)
6261 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006262 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006263 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006264 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006265 status = decode_putfh(xdr);
6266 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006267 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006268 status = decode_savefh(xdr);
6269 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006271 status = decode_putfh(xdr);
6272 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006274 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006275out:
6276 return status;
6277}
6278
6279/*
6280 * Decode LINK response
6281 */
Chuck Leverbf269552010-12-14 14:59:29 +00006282static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6283 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006284{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285 struct compound_hdr hdr;
6286 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006287
Chuck Leverbf269552010-12-14 14:59:29 +00006288 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006289 if (status)
6290 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006291 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006292 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006293 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006294 status = decode_putfh(xdr);
6295 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006296 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006297 status = decode_savefh(xdr);
6298 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006300 status = decode_putfh(xdr);
6301 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006302 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006303 status = decode_link(xdr, &res->cinfo);
6304 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006305 goto out;
6306 /*
6307 * Note order: OP_LINK leaves the directory as the current
6308 * filehandle.
6309 */
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_restorefh(xdr);
6311 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006312 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006313 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006314out:
6315 return status;
6316}
6317
6318/*
6319 * Decode CREATE response
6320 */
Chuck Leverbf269552010-12-14 14:59:29 +00006321static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6322 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324 struct compound_hdr hdr;
6325 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006326
Chuck Leverbf269552010-12-14 14:59:29 +00006327 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006328 if (status)
6329 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006330 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006331 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006333 status = decode_putfh(xdr);
6334 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006336 status = decode_create(xdr, &res->dir_cinfo);
6337 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006338 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006339 status = decode_getfh(xdr, res->fh);
6340 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006341 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006342 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006343out:
6344 return status;
6345}
6346
6347/*
6348 * Decode SYMLINK response
6349 */
Chuck Leverbf269552010-12-14 14:59:29 +00006350static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6351 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352{
Chuck Leverbf269552010-12-14 14:59:29 +00006353 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354}
6355
6356/*
6357 * Decode GETATTR response
6358 */
Chuck Leverbf269552010-12-14 14:59:29 +00006359static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6360 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006361{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 struct compound_hdr hdr;
6363 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006364
Chuck Leverbf269552010-12-14 14:59:29 +00006365 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006366 if (status)
6367 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006368 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006369 if (status)
6370 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006371 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372 if (status)
6373 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006374 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006375out:
6376 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377}
6378
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006379/*
6380 * Encode an SETACL request
6381 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006382static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6383 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006384{
Andy Adamson05d564f2008-12-23 16:06:15 -05006385 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006386 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006387 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006388
Chuck Lever9f06c712010-12-14 14:59:18 +00006389 encode_compound_hdr(xdr, req, &hdr);
6390 encode_sequence(xdr, &args->seq_args, &hdr);
6391 encode_putfh(xdr, args->fh, &hdr);
6392 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006393 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006394}
Andy Adamson05d564f2008-12-23 16:06:15 -05006395
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006396/*
6397 * Decode SETACL response
6398 */
6399static int
Chuck Leverbf269552010-12-14 14:59:29 +00006400nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006401 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006402{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006403 struct compound_hdr hdr;
6404 int status;
6405
Chuck Leverbf269552010-12-14 14:59:29 +00006406 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006407 if (status)
6408 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006409 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006410 if (status)
6411 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006412 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006413 if (status)
6414 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006415 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006416out:
6417 return status;
6418}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006419
6420/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006421 * Decode GETACL response
6422 */
6423static int
Chuck Leverbf269552010-12-14 14:59:29 +00006424nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006425 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006426{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006427 struct compound_hdr hdr;
6428 int status;
6429
Trond Myklebust331818f2012-02-03 18:30:53 -05006430 if (res->acl_scratch != NULL) {
6431 void *p = page_address(res->acl_scratch);
6432 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6433 }
Chuck Leverbf269552010-12-14 14:59:29 +00006434 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006435 if (status)
6436 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006437 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006438 if (status)
6439 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006440 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006441 if (status)
6442 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006443 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006444
6445out:
6446 return status;
6447}
6448
6449/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450 * Decode CLOSE response
6451 */
Chuck Leverbf269552010-12-14 14:59:29 +00006452static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6453 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454{
Andy Adamson05d564f2008-12-23 16:06:15 -05006455 struct compound_hdr hdr;
6456 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006457
Chuck Leverbf269552010-12-14 14:59:29 +00006458 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006459 if (status)
6460 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006461 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006462 if (status)
6463 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006464 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006465 if (status)
6466 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006467 if (res->lr_res) {
6468 status = decode_layoutreturn(xdr, res->lr_res);
6469 res->lr_ret = status;
6470 if (status)
6471 goto out;
6472 }
Chuck Leverbf269552010-12-14 14:59:29 +00006473 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006474 if (status != 0)
6475 goto out;
6476 /*
6477 * Note: Server may do delete on close for this file
6478 * in which case the getattr call will fail with
6479 * an ESTALE error. Shouldn't be a problem,
6480 * though, since fattr->valid will remain unset.
6481 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006482 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006483out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006484 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485}
6486
6487/*
6488 * Decode OPEN response
6489 */
Chuck Leverbf269552010-12-14 14:59:29 +00006490static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6491 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006492{
Andy Adamson05d564f2008-12-23 16:06:15 -05006493 struct compound_hdr hdr;
6494 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495
Chuck Leverbf269552010-12-14 14:59:29 +00006496 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006497 if (status)
6498 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006499 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006500 if (status)
6501 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006502 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006503 if (status)
6504 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006505 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006506 if (status)
6507 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006508 status = decode_getfh(xdr, &res->fh);
6509 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006510 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006511 if (res->access_request)
6512 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006513 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006514out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006515 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516}
6517
6518/*
6519 * Decode OPEN_CONFIRM response
6520 */
Chuck Leverbf269552010-12-14 14:59:29 +00006521static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6522 struct xdr_stream *xdr,
6523 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524{
Andy Adamson05d564f2008-12-23 16:06:15 -05006525 struct compound_hdr hdr;
6526 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527
Chuck Leverbf269552010-12-14 14:59:29 +00006528 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006529 if (status)
6530 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006531 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006532 if (status)
6533 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006534 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006536 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006537}
6538
6539/*
6540 * Decode OPEN response
6541 */
Chuck Leverbf269552010-12-14 14:59:29 +00006542static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6543 struct xdr_stream *xdr,
6544 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545{
Andy Adamson05d564f2008-12-23 16:06:15 -05006546 struct compound_hdr hdr;
6547 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548
Chuck Leverbf269552010-12-14 14:59:29 +00006549 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006550 if (status)
6551 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006552 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006553 if (status)
6554 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006555 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006556 if (status)
6557 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006559 if (status)
6560 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006561 if (res->access_request)
6562 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006563 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006564out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006565 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006566}
6567
6568/*
6569 * Decode SETATTR response
6570 */
Chuck Leverbf269552010-12-14 14:59:29 +00006571static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6572 struct xdr_stream *xdr,
6573 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574{
Andy Adamson05d564f2008-12-23 16:06:15 -05006575 struct compound_hdr hdr;
6576 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006577
Chuck Leverbf269552010-12-14 14:59:29 +00006578 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006579 if (status)
6580 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006581 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006582 if (status)
6583 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006584 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006585 if (status)
6586 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006587 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006588 if (status)
6589 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006590 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006591out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006592 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593}
6594
6595/*
6596 * Decode LOCK response
6597 */
Chuck Leverbf269552010-12-14 14:59:29 +00006598static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6599 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006600{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006601 struct compound_hdr hdr;
6602 int status;
6603
Chuck Leverbf269552010-12-14 14:59:29 +00006604 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006605 if (status)
6606 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006607 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006608 if (status)
6609 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006610 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006611 if (status)
6612 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006613 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006614out:
6615 return status;
6616}
6617
6618/*
6619 * Decode LOCKT response
6620 */
Chuck Leverbf269552010-12-14 14:59:29 +00006621static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6622 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006623{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006624 struct compound_hdr hdr;
6625 int status;
6626
Chuck Leverbf269552010-12-14 14:59:29 +00006627 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006628 if (status)
6629 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006630 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006631 if (status)
6632 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006633 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634 if (status)
6635 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006636 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006637out:
6638 return status;
6639}
6640
6641/*
6642 * Decode LOCKU response
6643 */
Chuck Leverbf269552010-12-14 14:59:29 +00006644static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6645 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006646{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647 struct compound_hdr hdr;
6648 int status;
6649
Chuck Leverbf269552010-12-14 14:59:29 +00006650 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006651 if (status)
6652 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006653 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006654 if (status)
6655 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006656 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006657 if (status)
6658 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006659 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006660out:
6661 return status;
6662}
6663
Chuck Leverbf269552010-12-14 14:59:29 +00006664static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6665 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006666{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006667 struct compound_hdr hdr;
6668 int status;
6669
Chuck Leverbf269552010-12-14 14:59:29 +00006670 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006671 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006672 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006673 return status;
6674}
6675
Linus Torvalds1da177e2005-04-16 15:20:36 -07006676/*
6677 * Decode READLINK response
6678 */
Chuck Leverbf269552010-12-14 14:59:29 +00006679static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6680 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006681 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006682{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006683 struct compound_hdr hdr;
6684 int status;
6685
Chuck Leverbf269552010-12-14 14:59:29 +00006686 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006687 if (status)
6688 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006689 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006690 if (status)
6691 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006692 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006693 if (status)
6694 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006695 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006696out:
6697 return status;
6698}
6699
6700/*
6701 * Decode READDIR response
6702 */
Chuck Leverbf269552010-12-14 14:59:29 +00006703static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6704 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006705{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006706 struct compound_hdr hdr;
6707 int status;
6708
Chuck Leverbf269552010-12-14 14:59:29 +00006709 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006710 if (status)
6711 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006712 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006713 if (status)
6714 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006715 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006716 if (status)
6717 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006718 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006719out:
6720 return status;
6721}
6722
6723/*
6724 * Decode Read response
6725 */
Chuck Leverbf269552010-12-14 14:59:29 +00006726static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006727 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006728{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006729 struct compound_hdr hdr;
6730 int status;
6731
Chuck Leverbf269552010-12-14 14:59:29 +00006732 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006733 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006734 if (status)
6735 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006736 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006737 if (status)
6738 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006739 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006740 if (status)
6741 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006742 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006743 if (!status)
6744 status = res->count;
6745out:
6746 return status;
6747}
6748
6749/*
6750 * Decode WRITE response
6751 */
Chuck Leverbf269552010-12-14 14:59:29 +00006752static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006753 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006754{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006755 struct compound_hdr hdr;
6756 int status;
6757
Chuck Leverbf269552010-12-14 14:59:29 +00006758 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006759 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006760 if (status)
6761 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006762 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006763 if (status)
6764 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006765 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766 if (status)
6767 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006768 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006769 if (status)
6770 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006771 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006772 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006773 if (!status)
6774 status = res->count;
6775out:
6776 return status;
6777}
6778
6779/*
6780 * Decode COMMIT response
6781 */
Chuck Leverbf269552010-12-14 14:59:29 +00006782static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006783 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006784{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006785 struct compound_hdr hdr;
6786 int status;
6787
Chuck Leverbf269552010-12-14 14:59:29 +00006788 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006789 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006790 if (status)
6791 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006792 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006793 if (status)
6794 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006795 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006796 if (status)
6797 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006798 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006799out:
6800 return status;
6801}
6802
6803/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006804 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006805 */
Chuck Leverbf269552010-12-14 14:59:29 +00006806static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006807 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006808{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006809 struct compound_hdr hdr;
6810 int status;
6811
Chuck Leverbf269552010-12-14 14:59:29 +00006812 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006813 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006814 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006815 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006816 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006817 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006818 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006819 return status;
6820}
6821
6822/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006823 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006824 */
Chuck Leverbf269552010-12-14 14:59:29 +00006825static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006826 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006827{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006828 struct compound_hdr hdr;
6829 int status;
6830
Chuck Leverbf269552010-12-14 14:59:29 +00006831 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006832 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006833 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006834 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006835 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006836 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006837 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006838 return status;
6839}
6840
6841/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006842 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006843 */
Chuck Leverbf269552010-12-14 14:59:29 +00006844static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006845 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006846{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006847 struct compound_hdr hdr;
6848 int status;
6849
Chuck Leverbf269552010-12-14 14:59:29 +00006850 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006851 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006852 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006853 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006854 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006855 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006856 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006857 return status;
6858}
6859
6860/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006861 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006862 */
Chuck Leverbf269552010-12-14 14:59:29 +00006863static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6864 struct xdr_stream *xdr,
6865 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006866{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006867 struct compound_hdr hdr;
6868 int status;
6869
Chuck Leverbf269552010-12-14 14:59:29 +00006870 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006871 if (status)
6872 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006873 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006874 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006875 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006876 status = decode_putfh(xdr);
6877 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006878 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006879 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006880out:
6881 return status;
6882}
6883
6884/*
6885 * Decode RENEW response
6886 */
Chuck Leverbf269552010-12-14 14:59:29 +00006887static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6888 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006889{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006890 struct compound_hdr hdr;
6891 int status;
6892
Chuck Leverbf269552010-12-14 14:59:29 +00006893 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006894 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006895 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006896 return status;
6897}
6898
6899/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006900 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006901 */
Chuck Leverbf269552010-12-14 14:59:29 +00006902static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6903 struct xdr_stream *xdr,
6904 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006905{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006906 struct compound_hdr hdr;
6907 int status;
6908
Chuck Leverbf269552010-12-14 14:59:29 +00006909 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006910 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006911 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006912 return status;
6913}
6914
6915/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006916 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006917 */
Chuck Leverbf269552010-12-14 14:59:29 +00006918static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006919 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006920{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006921 struct compound_hdr hdr;
6922 int status;
6923
Chuck Leverbf269552010-12-14 14:59:29 +00006924 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006925 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006926 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006927 return status;
6928}
6929
6930/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006931 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006932 */
Chuck Leverbf269552010-12-14 14:59:29 +00006933static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6934 struct xdr_stream *xdr,
6935 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006936{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006937 struct compound_hdr hdr;
6938 int status;
6939
Chuck Leverbf269552010-12-14 14:59:29 +00006940 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006941 if (status)
6942 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006943 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006944 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006945 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006946 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006947 if (status != 0)
6948 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05006949 if (res->lr_res) {
6950 status = decode_layoutreturn(xdr, res->lr_res);
6951 res->lr_ret = status;
6952 if (status)
6953 goto out;
6954 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006955 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006956 if (status != 0)
6957 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006958 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006959out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006960 return status;
6961}
6962
Trond Myklebust683b57b2006-06-09 09:34:22 -04006963/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006964 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006965 */
Chuck Leverbf269552010-12-14 14:59:29 +00006966static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6967 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006968 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006969{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006970 struct compound_hdr hdr;
6971 int status;
6972
Chuck Leverbf269552010-12-14 14:59:29 +00006973 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006974 if (status)
6975 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006976 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006977 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006978 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006979 status = decode_putfh(xdr);
6980 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006981 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006982 if (res->migration) {
6983 xdr_enter_page(xdr, PAGE_SIZE);
6984 status = decode_getfattr_generic(xdr,
6985 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006986 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006987 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006988 if (status)
6989 goto out;
6990 if (res->renew)
6991 status = decode_renew(xdr);
6992 } else {
6993 status = decode_lookup(xdr);
6994 if (status)
6995 goto out;
6996 xdr_enter_page(xdr, PAGE_SIZE);
6997 status = decode_getfattr_generic(xdr,
6998 &res->fs_locations->fattr,
6999 NULL, res->fs_locations,
7000 NULL, res->fs_locations->server);
7001 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04007002out:
7003 return status;
7004}
7005
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007006/*
7007 * Decode SECINFO response
7008 */
7009static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7010 struct xdr_stream *xdr,
7011 struct nfs4_secinfo_res *res)
7012{
7013 struct compound_hdr hdr;
7014 int status;
7015
7016 status = decode_compound_hdr(xdr, &hdr);
7017 if (status)
7018 goto out;
7019 status = decode_sequence(xdr, &res->seq_res, rqstp);
7020 if (status)
7021 goto out;
7022 status = decode_putfh(xdr);
7023 if (status)
7024 goto out;
7025 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007026out:
7027 return status;
7028}
7029
Chuck Lever44c99932013-10-17 14:13:30 -04007030/*
7031 * Decode FSID_PRESENT response
7032 */
7033static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7034 struct xdr_stream *xdr,
7035 struct nfs4_fsid_present_res *res)
7036{
7037 struct compound_hdr hdr;
7038 int status;
7039
7040 status = decode_compound_hdr(xdr, &hdr);
7041 if (status)
7042 goto out;
7043 status = decode_sequence(xdr, &res->seq_res, rqstp);
7044 if (status)
7045 goto out;
7046 status = decode_putfh(xdr);
7047 if (status)
7048 goto out;
7049 status = decode_getfh(xdr, res->fh);
7050 if (status)
7051 goto out;
7052 if (res->renew)
7053 status = decode_renew(xdr);
7054out:
7055 return status;
7056}
7057
Benny Halevy99fe60d2009-04-01 09:22:29 -04007058#if defined(CONFIG_NFS_V4_1)
7059/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007060 * Decode BIND_CONN_TO_SESSION response
7061 */
7062static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7063 struct xdr_stream *xdr,
7064 void *res)
7065{
7066 struct compound_hdr hdr;
7067 int status;
7068
7069 status = decode_compound_hdr(xdr, &hdr);
7070 if (!status)
7071 status = decode_bind_conn_to_session(xdr, res);
7072 return status;
7073}
7074
7075/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007076 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007077 */
Chuck Leverbf269552010-12-14 14:59:29 +00007078static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7079 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007080 void *res)
7081{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007082 struct compound_hdr hdr;
7083 int status;
7084
Chuck Leverbf269552010-12-14 14:59:29 +00007085 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007086 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007087 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007088 return status;
7089}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007090
7091/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007092 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007093 */
Chuck Leverbf269552010-12-14 14:59:29 +00007094static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7095 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04007096 struct nfs41_create_session_res *res)
7097{
Andy Adamsonfc931582009-04-01 09:22:31 -04007098 struct compound_hdr hdr;
7099 int status;
7100
Chuck Leverbf269552010-12-14 14:59:29 +00007101 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007102 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007103 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007104 return status;
7105}
7106
7107/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007108 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007109 */
Chuck Leverbf269552010-12-14 14:59:29 +00007110static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7111 struct xdr_stream *xdr,
7112 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007113{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007114 struct compound_hdr hdr;
7115 int status;
7116
Chuck Leverbf269552010-12-14 14:59:29 +00007117 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007118 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007119 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007120 return status;
7121}
7122
7123/*
Trond Myklebust66245532012-05-25 17:18:09 -04007124 * Decode DESTROY_CLIENTID response
7125 */
7126static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7127 struct xdr_stream *xdr,
7128 void *res)
7129{
7130 struct compound_hdr hdr;
7131 int status;
7132
7133 status = decode_compound_hdr(xdr, &hdr);
7134 if (!status)
7135 status = decode_destroy_clientid(xdr, res);
7136 return status;
7137}
7138
7139/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007140 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007141 */
Chuck Leverbf269552010-12-14 14:59:29 +00007142static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7143 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007144 struct nfs4_sequence_res *res)
7145{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007146 struct compound_hdr hdr;
7147 int status;
7148
Chuck Leverbf269552010-12-14 14:59:29 +00007149 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007150 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007151 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007152 return status;
7153}
7154
7155/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007156 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007157 */
Chuck Leverbf269552010-12-14 14:59:29 +00007158static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7159 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04007160 struct nfs4_get_lease_time_res *res)
7161{
Andy Adamson2050f0c2009-04-01 09:22:30 -04007162 struct compound_hdr hdr;
7163 int status;
7164
Chuck Leverbf269552010-12-14 14:59:29 +00007165 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007166 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007167 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007168 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007169 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007170 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007171 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007172 return status;
7173}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007174
7175/*
7176 * Decode RECLAIM_COMPLETE response
7177 */
Chuck Leverbf269552010-12-14 14:59:29 +00007178static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7179 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007180 struct nfs41_reclaim_complete_res *res)
7181{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007182 struct compound_hdr hdr;
7183 int status;
7184
Chuck Leverbf269552010-12-14 14:59:29 +00007185 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007186 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007187 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007188 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307189 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007190 return status;
7191}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007192
7193/*
7194 * Decode GETDEVINFO response
7195 */
Chuck Leverbf269552010-12-14 14:59:29 +00007196static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7197 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007198 struct nfs4_getdeviceinfo_res *res)
7199{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007200 struct compound_hdr hdr;
7201 int status;
7202
Chuck Leverbf269552010-12-14 14:59:29 +00007203 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007204 if (status != 0)
7205 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007206 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007207 if (status != 0)
7208 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007209 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007210out:
7211 return status;
7212}
7213
7214/*
7215 * Decode LAYOUTGET response
7216 */
Chuck Leverbf269552010-12-14 14:59:29 +00007217static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7218 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007219 struct nfs4_layoutget_res *res)
7220{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007221 struct compound_hdr hdr;
7222 int status;
7223
Chuck Leverbf269552010-12-14 14:59:29 +00007224 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007225 if (status)
7226 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007227 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007228 if (status)
7229 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007230 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007231 if (status)
7232 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007233 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007234out:
7235 return status;
7236}
Andy Adamson863a3c62011-03-23 13:27:54 +00007237
7238/*
Benny Halevycbe82602011-05-22 19:52:37 +03007239 * Decode LAYOUTRETURN response
7240 */
7241static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7242 struct xdr_stream *xdr,
7243 struct nfs4_layoutreturn_res *res)
7244{
7245 struct compound_hdr hdr;
7246 int status;
7247
7248 status = decode_compound_hdr(xdr, &hdr);
7249 if (status)
7250 goto out;
7251 status = decode_sequence(xdr, &res->seq_res, rqstp);
7252 if (status)
7253 goto out;
7254 status = decode_putfh(xdr);
7255 if (status)
7256 goto out;
7257 status = decode_layoutreturn(xdr, res);
7258out:
7259 return status;
7260}
7261
7262/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007263 * Decode LAYOUTCOMMIT response
7264 */
7265static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7266 struct xdr_stream *xdr,
7267 struct nfs4_layoutcommit_res *res)
7268{
7269 struct compound_hdr hdr;
7270 int status;
7271
7272 status = decode_compound_hdr(xdr, &hdr);
7273 if (status)
7274 goto out;
7275 status = decode_sequence(xdr, &res->seq_res, rqstp);
7276 if (status)
7277 goto out;
7278 status = decode_putfh(xdr);
7279 if (status)
7280 goto out;
7281 status = decode_layoutcommit(xdr, rqstp, res);
7282 if (status)
7283 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007284 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007285out:
7286 return status;
7287}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007288
7289/*
7290 * Decode SECINFO_NO_NAME response
7291 */
7292static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7293 struct xdr_stream *xdr,
7294 struct nfs4_secinfo_res *res)
7295{
7296 struct compound_hdr hdr;
7297 int status;
7298
7299 status = decode_compound_hdr(xdr, &hdr);
7300 if (status)
7301 goto out;
7302 status = decode_sequence(xdr, &res->seq_res, rqstp);
7303 if (status)
7304 goto out;
7305 status = decode_putrootfh(xdr);
7306 if (status)
7307 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007308 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007309out:
7310 return status;
7311}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007312
7313/*
7314 * Decode TEST_STATEID response
7315 */
7316static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7317 struct xdr_stream *xdr,
7318 struct nfs41_test_stateid_res *res)
7319{
7320 struct compound_hdr hdr;
7321 int status;
7322
7323 status = decode_compound_hdr(xdr, &hdr);
7324 if (status)
7325 goto out;
7326 status = decode_sequence(xdr, &res->seq_res, rqstp);
7327 if (status)
7328 goto out;
7329 status = decode_test_stateid(xdr, res);
7330out:
7331 return status;
7332}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007333
7334/*
7335 * Decode FREE_STATEID response
7336 */
7337static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7338 struct xdr_stream *xdr,
7339 struct nfs41_free_stateid_res *res)
7340{
7341 struct compound_hdr hdr;
7342 int status;
7343
7344 status = decode_compound_hdr(xdr, &hdr);
7345 if (status)
7346 goto out;
7347 status = decode_sequence(xdr, &res->seq_res, rqstp);
7348 if (status)
7349 goto out;
7350 status = decode_free_stateid(xdr, res);
7351out:
7352 return status;
7353}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007354#endif /* CONFIG_NFS_V4_1 */
7355
Chuck Lever573c4e12010-12-14 14:58:11 +00007356/**
7357 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7358 * the local page cache.
7359 * @xdr: XDR stream where entry resides
7360 * @entry: buffer to fill in with entry data
7361 * @plus: boolean indicating whether this should be a readdirplus entry
7362 *
7363 * Returns zero if successful, otherwise a negative errno value is
7364 * returned.
7365 *
7366 * This function is not invoked during READDIR reply decoding, but
7367 * rather whenever an application invokes the getdents(2) system call
7368 * on a directory already in our cache.
7369 */
7370int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7371 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007372{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007373 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007374 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007375 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007376 __be32 *p = xdr_inline_decode(xdr, 4);
7377 if (unlikely(!p))
7378 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007379 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007380 p = xdr_inline_decode(xdr, 4);
7381 if (unlikely(!p))
7382 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007383 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007384 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007385 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007386 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007387 }
7388
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007389 p = xdr_inline_decode(xdr, 12);
7390 if (unlikely(!p))
7391 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007392 entry->prev_cookie = entry->cookie;
7393 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007394 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007395
Trond Myklebust9af8c222010-10-24 11:52:55 -04007396 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007397 if (unlikely(!p))
7398 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007399 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007400
7401 /*
7402 * In case the server doesn't return an inode number,
7403 * we fake one here. (We don't use inode number 0,
7404 * since glibc seems to choke on it...)
7405 */
7406 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007407 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007408
Trond Myklebust9af8c222010-10-24 11:52:55 -04007409 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007410 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007411
Trond Myklebust256e48b2012-06-21 11:18:13 -04007412 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007413 goto out_overflow;
7414
Chuck Lever573c4e12010-12-14 14:58:11 +00007415 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007416 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007417 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007418 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7419 entry->ino = entry->fattr->mounted_on_fileid;
7420 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007421 entry->ino = entry->fattr->fileid;
7422
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007423 entry->d_type = DT_UNKNOWN;
7424 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7425 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7426
Chuck Lever573c4e12010-12-14 14:58:11 +00007427 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007428
7429out_overflow:
7430 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007431 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007432}
7433
7434/*
7435 * We need to translate between nfs status return values and
7436 * the local errno values which may not be the same.
7437 */
7438static struct {
7439 int stat;
7440 int errno;
7441} nfs_errtbl[] = {
7442 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007443 { NFS4ERR_PERM, -EPERM },
7444 { NFS4ERR_NOENT, -ENOENT },
7445 { NFS4ERR_IO, -errno_NFSERR_IO},
7446 { NFS4ERR_NXIO, -ENXIO },
7447 { NFS4ERR_ACCESS, -EACCES },
7448 { NFS4ERR_EXIST, -EEXIST },
7449 { NFS4ERR_XDEV, -EXDEV },
7450 { NFS4ERR_NOTDIR, -ENOTDIR },
7451 { NFS4ERR_ISDIR, -EISDIR },
7452 { NFS4ERR_INVAL, -EINVAL },
7453 { NFS4ERR_FBIG, -EFBIG },
7454 { NFS4ERR_NOSPC, -ENOSPC },
7455 { NFS4ERR_ROFS, -EROFS },
7456 { NFS4ERR_MLINK, -EMLINK },
7457 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7458 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7459 { NFS4ERR_DQUOT, -EDQUOT },
7460 { NFS4ERR_STALE, -ESTALE },
7461 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007462 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7463 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7464 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007465 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007466 { NFS4ERR_BADTYPE, -EBADTYPE },
7467 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007468 { NFS4ERR_SYMLINK, -ELOOP },
7469 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7470 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007471 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007472};
7473
7474/*
7475 * Convert an NFS error code to a local one.
7476 * This one is used jointly by NFSv2 and NFSv3.
7477 */
7478static int
David Howells0a8ea432006-08-22 20:06:08 -04007479nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007480{
7481 int i;
7482 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7483 if (nfs_errtbl[i].stat == stat)
7484 return nfs_errtbl[i].errno;
7485 }
7486 if (stat <= 10000 || stat > 10100) {
7487 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007488 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007489 }
7490 /* If we cannot translate the error, the recovery routines should
7491 * handle it.
7492 * Note: remaining NFSv4 error codes have values > 10000, so should
7493 * not conflict with native Linux error codes.
7494 */
Benny Halevy856dff32008-03-31 17:39:06 +03007495 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007496}
7497
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007498#ifdef CONFIG_NFS_V4_2
7499#include "nfs42xdr.c"
7500#endif /* CONFIG_NFS_V4_2 */
7501
Linus Torvalds1da177e2005-04-16 15:20:36 -07007502#define PROC(proc, argtype, restype) \
7503[NFSPROC4_CLNT_##proc] = { \
7504 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007505 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007506 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007507 .p_arglen = NFS4_##argtype##_sz, \
7508 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007509 .p_statidx = NFSPROC4_CLNT_##proc, \
7510 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007511}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007512
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007513#define STUB(proc) \
7514[NFSPROC4_CLNT_##proc] = { \
7515 .p_name = #proc, \
7516}
7517
Linus Torvalds1da177e2005-04-16 15:20:36 -07007518struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007519 PROC(READ, enc_read, dec_read),
7520 PROC(WRITE, enc_write, dec_write),
7521 PROC(COMMIT, enc_commit, dec_commit),
7522 PROC(OPEN, enc_open, dec_open),
7523 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7524 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7525 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7526 PROC(CLOSE, enc_close, dec_close),
7527 PROC(SETATTR, enc_setattr, dec_setattr),
7528 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7529 PROC(RENEW, enc_renew, dec_renew),
7530 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7531 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7532 PROC(LOCK, enc_lock, dec_lock),
7533 PROC(LOCKT, enc_lockt, dec_lockt),
7534 PROC(LOCKU, enc_locku, dec_locku),
7535 PROC(ACCESS, enc_access, dec_access),
7536 PROC(GETATTR, enc_getattr, dec_getattr),
7537 PROC(LOOKUP, enc_lookup, dec_lookup),
7538 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7539 PROC(REMOVE, enc_remove, dec_remove),
7540 PROC(RENAME, enc_rename, dec_rename),
7541 PROC(LINK, enc_link, dec_link),
7542 PROC(SYMLINK, enc_symlink, dec_symlink),
7543 PROC(CREATE, enc_create, dec_create),
7544 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7545 PROC(STATFS, enc_statfs, dec_statfs),
7546 PROC(READLINK, enc_readlink, dec_readlink),
7547 PROC(READDIR, enc_readdir, dec_readdir),
7548 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7549 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7550 PROC(GETACL, enc_getacl, dec_getacl),
7551 PROC(SETACL, enc_setacl, dec_setacl),
7552 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7553 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007554 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007555 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007556#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007557 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7558 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7559 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7560 PROC(SEQUENCE, enc_sequence, dec_sequence),
7561 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7562 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7563 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7564 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007565 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007566 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007567 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007568 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007569 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007570 STUB(GETDEVICELIST),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007571 PROC(BIND_CONN_TO_SESSION,
7572 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007573 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007574#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007575#ifdef CONFIG_NFS_V4_2
7576 PROC(SEEK, enc_seek, dec_seek),
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007577 PROC(ALLOCATE, enc_allocate, dec_allocate),
Anna Schumaker624bd5b2014-11-25 13:18:16 -05007578 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
Trond Myklebustbe3a5d22015-06-23 19:51:55 +08007579 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
Peng Tao36022772015-09-26 02:24:34 +08007580 PROC(CLONE, enc_clone, dec_clone),
Anna Schumaker2e724482013-05-21 16:53:03 -04007581 PROC(COPY, enc_copy, dec_copy),
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007582#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007583};
7584
Trond Myklebusta613fa12012-01-20 13:53:56 -05007585const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007586 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007587 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007588 .procs = nfs4_procedures
7589};
7590
7591/*
7592 * Local variables:
7593 * c-basic-offset: 8
7594 * End:
7595 */