blob: 1c1768a8fcd15ef5cc606686b49ee33f30223f39 [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 Myklebust4d796d72016-09-23 11:38:08 -04002038 if (args->ld_private->ops && args->ld_private->ops->encode)
2039 args->ld_private->ops->encode(xdr, args, args->ld_private);
2040 else if (lr_ops->encode_layoutreturn)
Trond Myklebust94e5c572016-09-15 18:49:52 -04002041 lr_ops->encode_layoutreturn(xdr, args);
2042 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002043 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002044}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002045
2046static int
2047encode_secinfo_no_name(struct xdr_stream *xdr,
2048 const struct nfs41_secinfo_no_name_args *args,
2049 struct compound_hdr *hdr)
2050{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002051 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2052 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002053 return 0;
2054}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002055
2056static void encode_test_stateid(struct xdr_stream *xdr,
2057 struct nfs41_test_stateid_args *args,
2058 struct compound_hdr *hdr)
2059{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002060 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2061 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002062 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002063}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002064
2065static void encode_free_stateid(struct xdr_stream *xdr,
2066 struct nfs41_free_stateid_args *args,
2067 struct compound_hdr *hdr)
2068{
Trond Myklebustab19b482012-03-04 18:13:57 -05002069 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002070 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002071}
Trond Myklebustcf805162016-11-15 14:56:07 -05002072#else
2073static inline void
2074encode_layoutreturn(struct xdr_stream *xdr,
2075 const struct nfs4_layoutreturn_args *args,
2076 struct compound_hdr *hdr)
2077{
2078}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002079#endif /* CONFIG_NFS_V4_1 */
2080
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081/*
2082 * END OF "GENERIC" ENCODE ROUTINES.
2083 */
2084
Benny Halevy66cc0422009-04-01 09:22:10 -04002085static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2086{
2087#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002088 struct nfs4_session *session = args->sa_slot->table->session;
2089 if (session)
2090 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002091#endif /* CONFIG_NFS_V4_1 */
2092 return 0;
2093}
2094
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095/*
2096 * Encode an ACCESS request
2097 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002098static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2099 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002102 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
Chuck Lever9f06c712010-12-14 14:59:18 +00002105 encode_compound_hdr(xdr, req, &hdr);
2106 encode_sequence(xdr, &args->seq_args, &hdr);
2107 encode_putfh(xdr, args->fh, &hdr);
2108 encode_access(xdr, args->access, &hdr);
2109 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002110 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111}
2112
2113/*
2114 * Encode LOOKUP request
2115 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002116static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2117 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002120 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122
Chuck Lever9f06c712010-12-14 14:59:18 +00002123 encode_compound_hdr(xdr, req, &hdr);
2124 encode_sequence(xdr, &args->seq_args, &hdr);
2125 encode_putfh(xdr, args->dir_fh, &hdr);
2126 encode_lookup(xdr, args->name, &hdr);
2127 encode_getfh(xdr, &hdr);
2128 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002129 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130}
2131
2132/*
2133 * Encode LOOKUP_ROOT request
2134 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002135static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2136 struct xdr_stream *xdr,
2137 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002140 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
Chuck Lever9f06c712010-12-14 14:59:18 +00002143 encode_compound_hdr(xdr, req, &hdr);
2144 encode_sequence(xdr, &args->seq_args, &hdr);
2145 encode_putrootfh(xdr, &hdr);
2146 encode_getfh(xdr, &hdr);
2147 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002148 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149}
2150
2151/*
2152 * Encode REMOVE request
2153 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002154static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2155 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002158 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
Chuck Lever9f06c712010-12-14 14:59:18 +00002161 encode_compound_hdr(xdr, req, &hdr);
2162 encode_sequence(xdr, &args->seq_args, &hdr);
2163 encode_putfh(xdr, args->fh, &hdr);
2164 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002165 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166}
2167
2168/*
2169 * Encode RENAME request
2170 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002171static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2172 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002175 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177
Chuck Lever9f06c712010-12-14 14:59:18 +00002178 encode_compound_hdr(xdr, req, &hdr);
2179 encode_sequence(xdr, &args->seq_args, &hdr);
2180 encode_putfh(xdr, args->old_dir, &hdr);
2181 encode_savefh(xdr, &hdr);
2182 encode_putfh(xdr, args->new_dir, &hdr);
2183 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002184 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185}
2186
2187/*
2188 * Encode LINK request
2189 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002190static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2191 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002194 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196
Chuck Lever9f06c712010-12-14 14:59:18 +00002197 encode_compound_hdr(xdr, req, &hdr);
2198 encode_sequence(xdr, &args->seq_args, &hdr);
2199 encode_putfh(xdr, args->fh, &hdr);
2200 encode_savefh(xdr, &hdr);
2201 encode_putfh(xdr, args->dir_fh, &hdr);
2202 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002203 encode_restorefh(xdr, &hdr);
2204 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002205 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206}
2207
2208/*
2209 * Encode CREATE request
2210 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002211static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2212 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002215 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217
Chuck Lever9f06c712010-12-14 14:59:18 +00002218 encode_compound_hdr(xdr, req, &hdr);
2219 encode_sequence(xdr, &args->seq_args, &hdr);
2220 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002221 encode_create(xdr, args, &hdr);
2222 encode_getfh(xdr, &hdr);
2223 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002224 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225}
2226
2227/*
2228 * Encode SYMLINK request
2229 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002230static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2231 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232{
Chuck Lever9f06c712010-12-14 14:59:18 +00002233 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234}
2235
2236/*
2237 * Encode GETATTR request
2238 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002239static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2240 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002243 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
Chuck Lever9f06c712010-12-14 14:59:18 +00002246 encode_compound_hdr(xdr, req, &hdr);
2247 encode_sequence(xdr, &args->seq_args, &hdr);
2248 encode_putfh(xdr, args->fh, &hdr);
2249 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002250 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251}
2252
2253/*
2254 * Encode a CLOSE request
2255 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002256static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2257 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258{
Andy Adamson05d564f2008-12-23 16:06:15 -05002259 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002260 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002261 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
Chuck Lever9f06c712010-12-14 14:59:18 +00002263 encode_compound_hdr(xdr, req, &hdr);
2264 encode_sequence(xdr, &args->seq_args, &hdr);
2265 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002266 if (args->lr_args)
2267 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002268 encode_close(xdr, args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002269 if (args->bitmask != NULL)
2270 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002271 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272}
2273
2274/*
2275 * Encode an OPEN request
2276 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002277static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2278 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002281 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283
Chuck Lever9f06c712010-12-14 14:59:18 +00002284 encode_compound_hdr(xdr, req, &hdr);
2285 encode_sequence(xdr, &args->seq_args, &hdr);
2286 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002287 encode_open(xdr, args, &hdr);
2288 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002289 if (args->access)
2290 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002291 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002292 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293}
2294
2295/*
2296 * Encode an OPEN_CONFIRM request
2297 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002298static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2299 struct xdr_stream *xdr,
2300 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002303 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305
Chuck Lever9f06c712010-12-14 14:59:18 +00002306 encode_compound_hdr(xdr, req, &hdr);
2307 encode_putfh(xdr, args->fh, &hdr);
2308 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002309 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310}
2311
2312/*
2313 * Encode an OPEN request with no attributes.
2314 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002315static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2316 struct xdr_stream *xdr,
2317 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002320 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322
Chuck Lever9f06c712010-12-14 14:59:18 +00002323 encode_compound_hdr(xdr, req, &hdr);
2324 encode_sequence(xdr, &args->seq_args, &hdr);
2325 encode_putfh(xdr, args->fh, &hdr);
2326 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002327 if (args->access)
2328 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002329 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002330 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331}
2332
2333/*
2334 * Encode an OPEN_DOWNGRADE request
2335 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002336static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2337 struct xdr_stream *xdr,
2338 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002341 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343
Chuck Lever9f06c712010-12-14 14:59:18 +00002344 encode_compound_hdr(xdr, req, &hdr);
2345 encode_sequence(xdr, &args->seq_args, &hdr);
2346 encode_putfh(xdr, args->fh, &hdr);
2347 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002348 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349}
2350
2351/*
2352 * Encode a LOCK request
2353 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002354static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2355 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002358 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360
Chuck Lever9f06c712010-12-14 14:59:18 +00002361 encode_compound_hdr(xdr, req, &hdr);
2362 encode_sequence(xdr, &args->seq_args, &hdr);
2363 encode_putfh(xdr, args->fh, &hdr);
2364 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002365 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366}
2367
2368/*
2369 * Encode a LOCKT request
2370 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002371static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2372 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002375 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377
Chuck Lever9f06c712010-12-14 14:59:18 +00002378 encode_compound_hdr(xdr, req, &hdr);
2379 encode_sequence(xdr, &args->seq_args, &hdr);
2380 encode_putfh(xdr, args->fh, &hdr);
2381 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002382 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383}
2384
2385/*
2386 * Encode a LOCKU request
2387 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002388static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2389 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002392 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
Chuck Lever9f06c712010-12-14 14:59:18 +00002395 encode_compound_hdr(xdr, req, &hdr);
2396 encode_sequence(xdr, &args->seq_args, &hdr);
2397 encode_putfh(xdr, args->fh, &hdr);
2398 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002399 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400}
2401
Chuck Lever9f06c712010-12-14 14:59:18 +00002402static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2403 struct xdr_stream *xdr,
2404 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002405{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002406 struct compound_hdr hdr = {
2407 .minorversion = 0,
2408 };
2409
Chuck Lever9f06c712010-12-14 14:59:18 +00002410 encode_compound_hdr(xdr, req, &hdr);
2411 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002412 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002413}
2414
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415/*
2416 * Encode a READLINK request
2417 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002418static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2419 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002422 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424
Chuck Lever9f06c712010-12-14 14:59:18 +00002425 encode_compound_hdr(xdr, req, &hdr);
2426 encode_sequence(xdr, &args->seq_args, &hdr);
2427 encode_putfh(xdr, args->fh, &hdr);
2428 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002429
Benny Halevy28f56692009-04-01 09:22:09 -04002430 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002431 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002432 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433}
2434
2435/*
2436 * Encode a READDIR request
2437 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002438static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2439 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002442 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
Chuck Lever9f06c712010-12-14 14:59:18 +00002445 encode_compound_hdr(xdr, req, &hdr);
2446 encode_sequence(xdr, &args->seq_args, &hdr);
2447 encode_putfh(xdr, args->fh, &hdr);
2448 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002449
Benny Halevy28f56692009-04-01 09:22:09 -04002450 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002451 args->pgbase, args->count);
2452 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002453 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002454 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002455 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456}
2457
2458/*
2459 * Encode a READ request
2460 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002461static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002462 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002465 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467
Chuck Lever9f06c712010-12-14 14:59:18 +00002468 encode_compound_hdr(xdr, req, &hdr);
2469 encode_sequence(xdr, &args->seq_args, &hdr);
2470 encode_putfh(xdr, args->fh, &hdr);
2471 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472
Benny Halevy28f56692009-04-01 09:22:09 -04002473 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002475 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002476 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477}
2478
2479/*
2480 * Encode an SETATTR request
2481 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002482static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2483 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484{
Andy Adamson05d564f2008-12-23 16:06:15 -05002485 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002486 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002487 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488
Chuck Lever9f06c712010-12-14 14:59:18 +00002489 encode_compound_hdr(xdr, req, &hdr);
2490 encode_sequence(xdr, &args->seq_args, &hdr);
2491 encode_putfh(xdr, args->fh, &hdr);
2492 encode_setattr(xdr, args, args->server, &hdr);
2493 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002494 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495}
2496
2497/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002498 * Encode a GETACL request
2499 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002500static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2501 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002502{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002503 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002504 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002505 };
Benny Halevy28f56692009-04-01 09:22:09 -04002506 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002507
Chuck Lever9f06c712010-12-14 14:59:18 +00002508 encode_compound_hdr(xdr, req, &hdr);
2509 encode_sequence(xdr, &args->seq_args, &hdr);
2510 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002511 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002512 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002513
Benny Halevy28f56692009-04-01 09:22:09 -04002514 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01002515 args->acl_pages, 0, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002516
Andy Adamsond0179312008-12-23 16:06:17 -05002517 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002518}
2519
2520/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 * Encode a WRITE request
2522 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002523static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002524 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002527 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529
Chuck Lever9f06c712010-12-14 14:59:18 +00002530 encode_compound_hdr(xdr, req, &hdr);
2531 encode_sequence(xdr, &args->seq_args, &hdr);
2532 encode_putfh(xdr, args->fh, &hdr);
2533 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002534 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002535 if (args->bitmask)
2536 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002537 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538}
2539
2540/*
2541 * a COMMIT request
2542 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002543static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002544 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002547 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549
Chuck Lever9f06c712010-12-14 14:59:18 +00002550 encode_compound_hdr(xdr, req, &hdr);
2551 encode_sequence(xdr, &args->seq_args, &hdr);
2552 encode_putfh(xdr, args->fh, &hdr);
2553 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002554 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555}
2556
2557/*
2558 * FSINFO request
2559 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002560static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2561 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002564 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566
Chuck Lever9f06c712010-12-14 14:59:18 +00002567 encode_compound_hdr(xdr, req, &hdr);
2568 encode_sequence(xdr, &args->seq_args, &hdr);
2569 encode_putfh(xdr, args->fh, &hdr);
2570 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002571 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572}
2573
2574/*
2575 * a PATHCONF request
2576 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002577static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2578 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002581 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583
Chuck Lever9f06c712010-12-14 14:59:18 +00002584 encode_compound_hdr(xdr, req, &hdr);
2585 encode_sequence(xdr, &args->seq_args, &hdr);
2586 encode_putfh(xdr, args->fh, &hdr);
2587 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002588 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002589 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590}
2591
2592/*
2593 * a STATFS request
2594 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002595static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2596 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002599 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601
Chuck Lever9f06c712010-12-14 14:59:18 +00002602 encode_compound_hdr(xdr, req, &hdr);
2603 encode_sequence(xdr, &args->seq_args, &hdr);
2604 encode_putfh(xdr, args->fh, &hdr);
2605 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002606 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002607 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608}
2609
2610/*
2611 * GETATTR_BITMAP request
2612 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002613static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2614 struct xdr_stream *xdr,
2615 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616{
Kinglong Mee8c612822015-08-26 21:12:58 +08002617 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002619 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621
Chuck Lever9f06c712010-12-14 14:59:18 +00002622 encode_compound_hdr(xdr, req, &hdr);
2623 encode_sequence(xdr, &args->seq_args, &hdr);
2624 encode_putfh(xdr, args->fhandle, &hdr);
Kinglong Mee8c612822015-08-26 21:12:58 +08002625 encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002626 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627}
2628
2629/*
2630 * a RENEW request
2631 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002632static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2633 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002636 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 };
2638
Chuck Lever9f06c712010-12-14 14:59:18 +00002639 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002640 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002641 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642}
2643
2644/*
2645 * a SETCLIENTID request
2646 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002647static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2648 struct xdr_stream *xdr,
2649 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002652 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 };
2654
Chuck Lever9f06c712010-12-14 14:59:18 +00002655 encode_compound_hdr(xdr, req, &hdr);
2656 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002657 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658}
2659
2660/*
2661 * a SETCLIENTID_CONFIRM request
2662 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002663static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2664 struct xdr_stream *xdr,
2665 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002668 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670
Chuck Lever9f06c712010-12-14 14:59:18 +00002671 encode_compound_hdr(xdr, req, &hdr);
2672 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002673 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674}
2675
2676/*
2677 * DELEGRETURN request
2678 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002679static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2680 struct xdr_stream *xdr,
2681 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002684 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686
Chuck Lever9f06c712010-12-14 14:59:18 +00002687 encode_compound_hdr(xdr, req, &hdr);
2688 encode_sequence(xdr, &args->seq_args, &hdr);
2689 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust586f1c32016-11-15 15:03:33 -05002690 if (args->lr_args)
2691 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002692 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002693 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002694 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695}
2696
2697/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002698 * Encode FS_LOCATIONS request
2699 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002700static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2701 struct xdr_stream *xdr,
2702 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002703{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002704 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002705 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002706 };
Benny Halevy28f56692009-04-01 09:22:09 -04002707 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002708
Chuck Lever9f06c712010-12-14 14:59:18 +00002709 encode_compound_hdr(xdr, req, &hdr);
2710 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002711 if (args->migration) {
2712 encode_putfh(xdr, args->fh, &hdr);
2713 replen = hdr.replen;
2714 encode_fs_locations(xdr, args->bitmask, &hdr);
2715 if (args->renew)
2716 encode_renew(xdr, args->clientid, &hdr);
2717 } else {
2718 encode_putfh(xdr, args->dir_fh, &hdr);
2719 encode_lookup(xdr, args->name, &hdr);
2720 replen = hdr.replen;
2721 encode_fs_locations(xdr, args->bitmask, &hdr);
2722 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002723
Chuck Leverb03d7352013-10-17 14:12:50 -04002724 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002725 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002726 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002727 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002728}
2729
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002730/*
2731 * Encode SECINFO request
2732 */
2733static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2734 struct xdr_stream *xdr,
2735 struct nfs4_secinfo_arg *args)
2736{
2737 struct compound_hdr hdr = {
2738 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2739 };
2740
2741 encode_compound_hdr(xdr, req, &hdr);
2742 encode_sequence(xdr, &args->seq_args, &hdr);
2743 encode_putfh(xdr, args->dir_fh, &hdr);
2744 encode_secinfo(xdr, args->name, &hdr);
2745 encode_nops(&hdr);
2746}
2747
Chuck Lever44c99932013-10-17 14:13:30 -04002748/*
2749 * Encode FSID_PRESENT request
2750 */
2751static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2752 struct xdr_stream *xdr,
2753 struct nfs4_fsid_present_arg *args)
2754{
2755 struct compound_hdr hdr = {
2756 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2757 };
2758
2759 encode_compound_hdr(xdr, req, &hdr);
2760 encode_sequence(xdr, &args->seq_args, &hdr);
2761 encode_putfh(xdr, args->fh, &hdr);
2762 encode_getfh(xdr, &hdr);
2763 if (args->renew)
2764 encode_renew(xdr, args->clientid, &hdr);
2765 encode_nops(&hdr);
2766}
2767
Benny Halevy99fe60d2009-04-01 09:22:29 -04002768#if defined(CONFIG_NFS_V4_1)
2769/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002770 * BIND_CONN_TO_SESSION request
2771 */
2772static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2773 struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08002774 struct nfs41_bind_conn_to_session_args *args)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002775{
2776 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002777 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002778 };
2779
2780 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002781 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002782 encode_nops(&hdr);
2783}
2784
2785/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002786 * EXCHANGE_ID request
2787 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002788static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2789 struct xdr_stream *xdr,
2790 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002791{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002792 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002793 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002794 };
2795
Chuck Lever9f06c712010-12-14 14:59:18 +00002796 encode_compound_hdr(xdr, req, &hdr);
2797 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002798 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002799}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002800
2801/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002802 * a CREATE_SESSION request
2803 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002804static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2805 struct xdr_stream *xdr,
2806 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002807{
Andy Adamsonfc931582009-04-01 09:22:31 -04002808 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002809 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002810 };
2811
Chuck Lever9f06c712010-12-14 14:59:18 +00002812 encode_compound_hdr(xdr, req, &hdr);
2813 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002814 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002815}
2816
2817/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002818 * a DESTROY_SESSION request
2819 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002820static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2821 struct xdr_stream *xdr,
2822 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002823{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002824 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002825 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002826 };
2827
Chuck Lever9f06c712010-12-14 14:59:18 +00002828 encode_compound_hdr(xdr, req, &hdr);
2829 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002830 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002831}
2832
2833/*
Trond Myklebust66245532012-05-25 17:18:09 -04002834 * a DESTROY_CLIENTID request
2835 */
2836static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2837 struct xdr_stream *xdr,
2838 struct nfs_client *clp)
2839{
2840 struct compound_hdr hdr = {
2841 .minorversion = clp->cl_mvops->minor_version,
2842 };
2843
2844 encode_compound_hdr(xdr, req, &hdr);
2845 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2846 encode_nops(&hdr);
2847}
2848
2849/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002850 * a SEQUENCE request
2851 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002852static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2853 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002854{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002855 struct compound_hdr hdr = {
2856 .minorversion = nfs4_xdr_minorversion(args),
2857 };
2858
Chuck Lever9f06c712010-12-14 14:59:18 +00002859 encode_compound_hdr(xdr, req, &hdr);
2860 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002861 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002862}
2863
2864/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002865 * a GET_LEASE_TIME request
2866 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002867static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2868 struct xdr_stream *xdr,
2869 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002870{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002871 struct compound_hdr hdr = {
2872 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2873 };
Fred Isamandae100c2011-07-30 20:52:37 -04002874 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002875
Chuck Lever9f06c712010-12-14 14:59:18 +00002876 encode_compound_hdr(xdr, req, &hdr);
2877 encode_sequence(xdr, &args->la_seq_args, &hdr);
2878 encode_putrootfh(xdr, &hdr);
2879 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002880 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002881}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002882
2883/*
2884 * a RECLAIM_COMPLETE request
2885 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002886static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2887 struct xdr_stream *xdr,
2888 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002889{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002890 struct compound_hdr hdr = {
2891 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2892 };
2893
Chuck Lever9f06c712010-12-14 14:59:18 +00002894 encode_compound_hdr(xdr, req, &hdr);
2895 encode_sequence(xdr, &args->seq_args, &hdr);
2896 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002897 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002898}
2899
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002900/*
2901 * Encode GETDEVICEINFO request
2902 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002903static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2904 struct xdr_stream *xdr,
2905 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002906{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002907 struct compound_hdr hdr = {
2908 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2909 };
2910
Chuck Lever9f06c712010-12-14 14:59:18 +00002911 encode_compound_hdr(xdr, req, &hdr);
2912 encode_sequence(xdr, &args->seq_args, &hdr);
2913 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002914
2915 /* set up reply kvec. Subtract notification bitmap max size (2)
2916 * so that notification bitmap is put in xdr_buf tail */
2917 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2918 args->pdev->pages, args->pdev->pgbase,
2919 args->pdev->pglen);
2920
2921 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002922}
2923
2924/*
2925 * Encode LAYOUTGET request
2926 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002927static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2928 struct xdr_stream *xdr,
2929 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002930{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002931 struct compound_hdr hdr = {
2932 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2933 };
2934
Chuck Lever9f06c712010-12-14 14:59:18 +00002935 encode_compound_hdr(xdr, req, &hdr);
2936 encode_sequence(xdr, &args->seq_args, &hdr);
2937 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2938 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002939
2940 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2941 args->layout.pages, 0, args->layout.pglen);
2942
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002943 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002944}
Andy Adamson863a3c62011-03-23 13:27:54 +00002945
2946/*
2947 * Encode LAYOUTCOMMIT request
2948 */
Benny Halevycbe82602011-05-22 19:52:37 +03002949static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2950 struct xdr_stream *xdr,
2951 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002952{
Benny Halevyac7db722011-05-22 19:53:48 +03002953 struct nfs4_layoutcommit_data *data =
2954 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002955 struct compound_hdr hdr = {
2956 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2957 };
2958
2959 encode_compound_hdr(xdr, req, &hdr);
2960 encode_sequence(xdr, &args->seq_args, &hdr);
2961 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002962 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002963 encode_getfattr(xdr, args->bitmask, &hdr);
2964 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002965}
2966
2967/*
2968 * Encode LAYOUTRETURN request
2969 */
2970static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2971 struct xdr_stream *xdr,
2972 struct nfs4_layoutreturn_args *args)
2973{
2974 struct compound_hdr hdr = {
2975 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2976 };
2977
2978 encode_compound_hdr(xdr, req, &hdr);
2979 encode_sequence(xdr, &args->seq_args, &hdr);
2980 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2981 encode_layoutreturn(xdr, args, &hdr);
2982 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002983}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002984
2985/*
2986 * Encode SECINFO_NO_NAME request
2987 */
2988static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2989 struct xdr_stream *xdr,
2990 struct nfs41_secinfo_no_name_args *args)
2991{
2992 struct compound_hdr hdr = {
2993 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2994 };
2995
2996 encode_compound_hdr(xdr, req, &hdr);
2997 encode_sequence(xdr, &args->seq_args, &hdr);
2998 encode_putrootfh(xdr, &hdr);
2999 encode_secinfo_no_name(xdr, args, &hdr);
3000 encode_nops(&hdr);
3001 return 0;
3002}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003003
3004/*
3005 * Encode TEST_STATEID request
3006 */
3007static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3008 struct xdr_stream *xdr,
3009 struct nfs41_test_stateid_args *args)
3010{
3011 struct compound_hdr hdr = {
3012 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3013 };
3014
3015 encode_compound_hdr(xdr, req, &hdr);
3016 encode_sequence(xdr, &args->seq_args, &hdr);
3017 encode_test_stateid(xdr, args, &hdr);
3018 encode_nops(&hdr);
3019}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003020
3021/*
3022 * Encode FREE_STATEID request
3023 */
3024static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3025 struct xdr_stream *xdr,
3026 struct nfs41_free_stateid_args *args)
3027{
3028 struct compound_hdr hdr = {
3029 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3030 };
3031
3032 encode_compound_hdr(xdr, req, &hdr);
3033 encode_sequence(xdr, &args->seq_args, &hdr);
3034 encode_free_stateid(xdr, args, &hdr);
3035 encode_nops(&hdr);
3036}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003037#endif /* CONFIG_NFS_V4_1 */
3038
Benny Halevy686841b2009-08-14 17:19:48 +03003039static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3040{
3041 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3042 "Remaining buffer length is %tu words.\n",
3043 func, xdr->end - xdr->p);
3044}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045
Trond Myklebust683b57b2006-06-09 09:34:22 -04003046static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047{
Al Viro8687b632006-10-19 23:28:48 -07003048 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049
Benny Halevyc0eae662009-08-14 17:20:14 +03003050 p = xdr_inline_decode(xdr, 4);
3051 if (unlikely(!p))
3052 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003053 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003054 p = xdr_inline_decode(xdr, *len);
3055 if (unlikely(!p))
3056 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 *string = (char *)p;
3058 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003059out_overflow:
3060 print_overflow_msg(__func__, xdr);
3061 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062}
3063
3064static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3065{
Al Viro8687b632006-10-19 23:28:48 -07003066 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067
Benny Halevyc0eae662009-08-14 17:20:14 +03003068 p = xdr_inline_decode(xdr, 8);
3069 if (unlikely(!p))
3070 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003071 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003072 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003073
Benny Halevyc0eae662009-08-14 17:20:14 +03003074 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3075 if (unlikely(!p))
3076 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 hdr->tag = (char *)p;
3078 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003079 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003080 if (unlikely(hdr->nops < 1))
3081 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003083out_overflow:
3084 print_overflow_msg(__func__, xdr);
3085 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086}
3087
Trond Myklebustc7848f62013-12-04 17:39:23 -05003088static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3089 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090{
Al Viro8687b632006-10-19 23:28:48 -07003091 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 uint32_t opnum;
3093 int32_t nfserr;
3094
Benny Halevyc0eae662009-08-14 17:20:14 +03003095 p = xdr_inline_decode(xdr, 8);
3096 if (unlikely(!p))
3097 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003098 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003099 if (unlikely(opnum != expected))
3100 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003101 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003102 if (nfserr == NFS_OK)
3103 *nfs_retval = 0;
3104 else
3105 *nfs_retval = nfs4_stat_to_errno(nfserr);
3106 return true;
3107out_bad_operation:
3108 dprintk("nfs: Server returned operation"
3109 " %d but we issued a request for %d\n",
3110 opnum, expected);
3111 *nfs_retval = -EREMOTEIO;
3112 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003113out_overflow:
3114 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003115 *nfs_retval = -EIO;
3116 return false;
3117}
3118
3119static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3120{
3121 int retval;
3122
3123 __decode_op_hdr(xdr, expected, &retval);
3124 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125}
3126
3127/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003128static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129{
Al Viro8687b632006-10-19 23:28:48 -07003130 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003131 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 char *str;
3133
Benny Halevyc0eae662009-08-14 17:20:14 +03003134 p = xdr_inline_decode(xdr, 12);
3135 if (likely(p))
3136 return decode_opaque_inline(xdr, &strlen, &str);
3137 print_overflow_msg(__func__, xdr);
3138 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139}
3140
3141static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3142{
Al Viro8687b632006-10-19 23:28:48 -07003143 uint32_t bmlen;
3144 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145
Benny Halevyc0eae662009-08-14 17:20:14 +03003146 p = xdr_inline_decode(xdr, 4);
3147 if (unlikely(!p))
3148 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003149 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150
Fred Isamandae100c2011-07-30 20:52:37 -04003151 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003152 p = xdr_inline_decode(xdr, (bmlen << 2));
3153 if (unlikely(!p))
3154 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003156 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003157 if (bmlen > 1) {
3158 bitmap[1] = be32_to_cpup(p++);
3159 if (bmlen > 2)
3160 bitmap[2] = be32_to_cpup(p);
3161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 }
3163 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003164out_overflow:
3165 print_overflow_msg(__func__, xdr);
3166 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167}
3168
Trond Myklebust256e48b2012-06-21 11:18:13 -04003169static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170{
Al Viro8687b632006-10-19 23:28:48 -07003171 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172
Benny Halevyc0eae662009-08-14 17:20:14 +03003173 p = xdr_inline_decode(xdr, 4);
3174 if (unlikely(!p))
3175 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003176 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003177 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003179out_overflow:
3180 print_overflow_msg(__func__, xdr);
3181 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182}
3183
3184static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3185{
3186 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003187 int ret;
3188 ret = decode_attr_bitmap(xdr, bitmask);
3189 if (unlikely(ret < 0))
3190 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3192 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003193 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3194 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3195 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 return 0;
3197}
3198
3199static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3200{
Al Viro8687b632006-10-19 23:28:48 -07003201 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003202 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203
3204 *type = 0;
3205 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3206 return -EIO;
3207 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003208 p = xdr_inline_decode(xdr, 4);
3209 if (unlikely(!p))
3210 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003211 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003213 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 return -EIO;
3215 }
3216 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003217 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003219 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003220 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003221out_overflow:
3222 print_overflow_msg(__func__, xdr);
3223 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224}
3225
Chuck Lever264e6352012-03-01 17:02:05 -05003226static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3227 uint32_t *bitmap, uint32_t *type)
3228{
3229 __be32 *p;
3230
3231 *type = 0;
3232 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3233 return -EIO;
3234 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3235 p = xdr_inline_decode(xdr, 4);
3236 if (unlikely(!p))
3237 goto out_overflow;
3238 *type = be32_to_cpup(p);
3239 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3240 }
3241 dprintk("%s: expire type=0x%x\n", __func__, *type);
3242 return 0;
3243out_overflow:
3244 print_overflow_msg(__func__, xdr);
3245 return -EIO;
3246}
3247
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3249{
Al Viro8687b632006-10-19 23:28:48 -07003250 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003251 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252
3253 *change = 0;
3254 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3255 return -EIO;
3256 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003257 p = xdr_inline_decode(xdr, 8);
3258 if (unlikely(!p))
3259 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003260 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003262 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003264 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003266 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003267out_overflow:
3268 print_overflow_msg(__func__, xdr);
3269 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270}
3271
3272static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3273{
Al Viro8687b632006-10-19 23:28:48 -07003274 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003275 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276
3277 *size = 0;
3278 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3279 return -EIO;
3280 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003281 p = xdr_inline_decode(xdr, 8);
3282 if (unlikely(!p))
3283 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003284 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003286 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003288 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003289 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003290out_overflow:
3291 print_overflow_msg(__func__, xdr);
3292 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293}
3294
3295static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3296{
Al Viro8687b632006-10-19 23:28:48 -07003297 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298
3299 *res = 0;
3300 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3301 return -EIO;
3302 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003303 p = xdr_inline_decode(xdr, 4);
3304 if (unlikely(!p))
3305 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003306 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3308 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003309 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003311out_overflow:
3312 print_overflow_msg(__func__, xdr);
3313 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314}
3315
3316static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3317{
Al Viro8687b632006-10-19 23:28:48 -07003318 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319
3320 *res = 0;
3321 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3322 return -EIO;
3323 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003324 p = xdr_inline_decode(xdr, 4);
3325 if (unlikely(!p))
3326 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003327 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3329 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003330 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003332out_overflow:
3333 print_overflow_msg(__func__, xdr);
3334 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335}
3336
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003337static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338{
Al Viro8687b632006-10-19 23:28:48 -07003339 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003340 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341
3342 fsid->major = 0;
3343 fsid->minor = 0;
3344 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3345 return -EIO;
3346 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003347 p = xdr_inline_decode(xdr, 16);
3348 if (unlikely(!p))
3349 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003350 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003351 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003353 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003355 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 (unsigned long long)fsid->major,
3357 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003358 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003359out_overflow:
3360 print_overflow_msg(__func__, xdr);
3361 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362}
3363
3364static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3365{
Al Viro8687b632006-10-19 23:28:48 -07003366 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367
3368 *res = 60;
3369 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3370 return -EIO;
3371 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003372 p = xdr_inline_decode(xdr, 4);
3373 if (unlikely(!p))
3374 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003375 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3377 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003378 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003380out_overflow:
3381 print_overflow_msg(__func__, xdr);
3382 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383}
3384
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003385static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003386{
3387 __be32 *p;
3388
3389 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3390 return -EIO;
3391 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3392 p = xdr_inline_decode(xdr, 4);
3393 if (unlikely(!p))
3394 goto out_overflow;
3395 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003396 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003397 }
3398 return 0;
3399out_overflow:
3400 print_overflow_msg(__func__, xdr);
3401 return -EIO;
3402}
3403
Kinglong Mee8c612822015-08-26 21:12:58 +08003404static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3405 uint32_t *bitmap, uint32_t *bitmask)
3406{
3407 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3408 int ret;
3409 ret = decode_attr_bitmap(xdr, bitmask);
3410 if (unlikely(ret < 0))
3411 return ret;
3412 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3413 } else
3414 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3415 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3416 bitmask[0], bitmask[1], bitmask[2]);
3417 return 0;
3418}
3419
Bryan Schumakerae42c702010-10-21 16:33:17 -04003420static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3421{
3422 __be32 *p;
3423 int len;
3424
Trond Myklebust7ad07352010-10-23 15:34:20 -04003425 if (fh != NULL)
3426 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003427
3428 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3429 return -EIO;
3430 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3431 p = xdr_inline_decode(xdr, 4);
3432 if (unlikely(!p))
3433 goto out_overflow;
3434 len = be32_to_cpup(p);
3435 if (len > NFS4_FHSIZE)
3436 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003437 p = xdr_inline_decode(xdr, len);
3438 if (unlikely(!p))
3439 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003440 if (fh != NULL) {
3441 memcpy(fh->data, p, len);
3442 fh->size = len;
3443 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003444 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3445 }
3446 return 0;
3447out_overflow:
3448 print_overflow_msg(__func__, xdr);
3449 return -EIO;
3450}
3451
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3453{
Al Viro8687b632006-10-19 23:28:48 -07003454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003456 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3458 return -EIO;
3459 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003460 p = xdr_inline_decode(xdr, 4);
3461 if (unlikely(!p))
3462 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003463 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3465 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003466 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003468out_overflow:
3469 print_overflow_msg(__func__, xdr);
3470 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471}
3472
3473static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3474{
Al Viro8687b632006-10-19 23:28:48 -07003475 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003476 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477
3478 *fileid = 0;
3479 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3480 return -EIO;
3481 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003482 p = xdr_inline_decode(xdr, 8);
3483 if (unlikely(!p))
3484 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003485 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003487 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003489 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003490 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003491out_overflow:
3492 print_overflow_msg(__func__, xdr);
3493 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494}
3495
Manoj Naik99baf622006-06-09 09:34:24 -04003496static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3497{
Al Viro8687b632006-10-19 23:28:48 -07003498 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003499 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003500
3501 *fileid = 0;
3502 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3503 return -EIO;
3504 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003505 p = xdr_inline_decode(xdr, 8);
3506 if (unlikely(!p))
3507 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003508 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003509 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003510 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003511 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003512 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003513 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003514out_overflow:
3515 print_overflow_msg(__func__, xdr);
3516 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003517}
3518
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3520{
Al Viro8687b632006-10-19 23:28:48 -07003521 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 int status = 0;
3523
3524 *res = 0;
3525 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3526 return -EIO;
3527 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003528 p = xdr_inline_decode(xdr, 8);
3529 if (unlikely(!p))
3530 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003531 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3533 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003534 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003536out_overflow:
3537 print_overflow_msg(__func__, xdr);
3538 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539}
3540
3541static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3542{
Al Viro8687b632006-10-19 23:28:48 -07003543 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 int status = 0;
3545
3546 *res = 0;
3547 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3548 return -EIO;
3549 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003550 p = xdr_inline_decode(xdr, 8);
3551 if (unlikely(!p))
3552 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003553 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3555 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003556 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003558out_overflow:
3559 print_overflow_msg(__func__, xdr);
3560 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561}
3562
3563static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3564{
Al Viro8687b632006-10-19 23:28:48 -07003565 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566 int status = 0;
3567
3568 *res = 0;
3569 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3570 return -EIO;
3571 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003572 p = xdr_inline_decode(xdr, 8);
3573 if (unlikely(!p))
3574 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003575 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3577 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003578 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003580out_overflow:
3581 print_overflow_msg(__func__, xdr);
3582 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583}
3584
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003585static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3586{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003587 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003588 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003589 int status = 0;
3590
Benny Halevyc0eae662009-08-14 17:20:14 +03003591 p = xdr_inline_decode(xdr, 4);
3592 if (unlikely(!p))
3593 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003594 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003595 if (n == 0)
3596 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003597 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003598 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3599 dprintk("cannot parse %d components in path\n", n);
3600 goto out_eio;
3601 }
3602 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003603 struct nfs4_string *component = &path->components[path->ncomponents];
3604 status = decode_opaque_inline(xdr, &component->len, &component->data);
3605 if (unlikely(status != 0))
3606 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003607 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003608 pr_cont("%s%.*s ",
3609 (path->ncomponents != n ? "/ " : ""),
3610 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003611 }
3612out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003613 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003614root_path:
3615/* a root pathname is sent as a zero component4 */
3616 path->ncomponents = 1;
3617 path->components[0].len=0;
3618 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003619 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003620 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003621out_eio:
3622 dprintk(" status %d", status);
3623 status = -EIO;
3624 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003625out_overflow:
3626 print_overflow_msg(__func__, xdr);
3627 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003628}
3629
3630static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003631{
3632 int n;
Al Viro8687b632006-10-19 23:28:48 -07003633 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003634 int status = -EIO;
3635
3636 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3637 goto out;
3638 status = 0;
3639 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3640 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003641 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003642 status = -EIO;
3643 /* Ignore borken servers that return unrequested attrs */
3644 if (unlikely(res == NULL))
3645 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003646 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003647 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003648 if (unlikely(status != 0))
3649 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003650 p = xdr_inline_decode(xdr, 4);
3651 if (unlikely(!p))
3652 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003653 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003654 if (n <= 0)
3655 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003656 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003657 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003658 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003659
Trond Myklebust809b4262013-03-27 11:54:45 -04003660 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3661 break;
3662 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003663 p = xdr_inline_decode(xdr, 4);
3664 if (unlikely(!p))
3665 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003666 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003667
Chuck Lever02a29762012-03-01 17:00:31 -05003668 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003669 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3670 struct nfs4_string *server;
3671
3672 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003673 unsigned int i;
3674 dprintk("%s: using first %u of %u servers "
3675 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003676 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003677 NFS4_FS_LOCATION_MAXSERVERS,
3678 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003679 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003680 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003681 char *data;
3682 status = decode_opaque_inline(xdr, &len, &data);
3683 if (unlikely(status != 0))
3684 goto out_eio;
3685 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003686 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003687 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003688 server = &loc->servers[loc->nservers];
3689 status = decode_opaque_inline(xdr, &server->len, &server->data);
3690 if (unlikely(status != 0))
3691 goto out_eio;
3692 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003693 }
3694 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003695 if (unlikely(status != 0))
3696 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003697 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003698 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003699 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003700out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003701 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003702 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003703out_overflow:
3704 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003705out_eio:
3706 status = -EIO;
3707 goto out;
3708}
3709
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3711{
Al Viro8687b632006-10-19 23:28:48 -07003712 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 int status = 0;
3714
3715 *res = 0;
3716 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3717 return -EIO;
3718 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003719 p = xdr_inline_decode(xdr, 8);
3720 if (unlikely(!p))
3721 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003722 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3724 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003725 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003727out_overflow:
3728 print_overflow_msg(__func__, xdr);
3729 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730}
3731
3732static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3733{
Al Viro8687b632006-10-19 23:28:48 -07003734 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 int status = 0;
3736
3737 *maxlink = 1;
3738 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3739 return -EIO;
3740 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003741 p = xdr_inline_decode(xdr, 4);
3742 if (unlikely(!p))
3743 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003744 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3746 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003747 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003749out_overflow:
3750 print_overflow_msg(__func__, xdr);
3751 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752}
3753
3754static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3755{
Al Viro8687b632006-10-19 23:28:48 -07003756 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757 int status = 0;
3758
3759 *maxname = 1024;
3760 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3761 return -EIO;
3762 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003763 p = xdr_inline_decode(xdr, 4);
3764 if (unlikely(!p))
3765 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003766 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3768 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003769 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003771out_overflow:
3772 print_overflow_msg(__func__, xdr);
3773 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774}
3775
3776static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3777{
Al Viro8687b632006-10-19 23:28:48 -07003778 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 int status = 0;
3780
3781 *res = 1024;
3782 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3783 return -EIO;
3784 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3785 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003786 p = xdr_inline_decode(xdr, 8);
3787 if (unlikely(!p))
3788 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003789 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 if (maxread > 0x7FFFFFFF)
3791 maxread = 0x7FFFFFFF;
3792 *res = (uint32_t)maxread;
3793 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3794 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003795 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003797out_overflow:
3798 print_overflow_msg(__func__, xdr);
3799 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800}
3801
3802static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3803{
Al Viro8687b632006-10-19 23:28:48 -07003804 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 int status = 0;
3806
3807 *res = 1024;
3808 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3809 return -EIO;
3810 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3811 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003812 p = xdr_inline_decode(xdr, 8);
3813 if (unlikely(!p))
3814 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003815 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 if (maxwrite > 0x7FFFFFFF)
3817 maxwrite = 0x7FFFFFFF;
3818 *res = (uint32_t)maxwrite;
3819 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3820 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003821 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003823out_overflow:
3824 print_overflow_msg(__func__, xdr);
3825 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826}
3827
Trond Myklebustbca79472009-03-11 14:10:26 -04003828static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829{
Trond Myklebustbca79472009-03-11 14:10:26 -04003830 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003831 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003832 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833
3834 *mode = 0;
3835 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3836 return -EIO;
3837 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003838 p = xdr_inline_decode(xdr, 4);
3839 if (unlikely(!p))
3840 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003841 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003842 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003844 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003846 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003847 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003848out_overflow:
3849 print_overflow_msg(__func__, xdr);
3850 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851}
3852
3853static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3854{
Al Viro8687b632006-10-19 23:28:48 -07003855 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003856 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857
3858 *nlink = 1;
3859 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3860 return -EIO;
3861 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003862 p = xdr_inline_decode(xdr, 4);
3863 if (unlikely(!p))
3864 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003865 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003867 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003869 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003870 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003871out_overflow:
3872 print_overflow_msg(__func__, xdr);
3873 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874}
3875
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003876static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003877 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003878 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879{
Al Viro8687b632006-10-19 23:28:48 -07003880 uint32_t len;
3881 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003882 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883
Eric W. Biedermane5782072013-02-01 14:22:02 -08003884 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3886 return -EIO;
3887 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003888 p = xdr_inline_decode(xdr, 4);
3889 if (unlikely(!p))
3890 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003891 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003892 p = xdr_inline_decode(xdr, len);
3893 if (unlikely(!p))
3894 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003895 if (owner_name != NULL) {
3896 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3897 if (owner_name->data != NULL) {
3898 owner_name->len = len;
3899 ret = NFS_ATTR_FATTR_OWNER_NAME;
3900 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003901 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003902 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003903 ret = NFS_ATTR_FATTR_OWNER;
3904 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003906 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003908 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003909 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3911 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003912 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003913 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003914out_overflow:
3915 print_overflow_msg(__func__, xdr);
3916 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917}
3918
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003919static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003920 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003921 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922{
Al Viro8687b632006-10-19 23:28:48 -07003923 uint32_t len;
3924 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003925 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926
Eric W. Biedermane5782072013-02-01 14:22:02 -08003927 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3929 return -EIO;
3930 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003931 p = xdr_inline_decode(xdr, 4);
3932 if (unlikely(!p))
3933 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003934 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003935 p = xdr_inline_decode(xdr, len);
3936 if (unlikely(!p))
3937 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003938 if (group_name != NULL) {
3939 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3940 if (group_name->data != NULL) {
3941 group_name->len = len;
3942 ret = NFS_ATTR_FATTR_GROUP_NAME;
3943 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003944 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003945 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003946 ret = NFS_ATTR_FATTR_GROUP;
3947 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003949 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003951 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003952 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3954 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003955 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003956 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003957out_overflow:
3958 print_overflow_msg(__func__, xdr);
3959 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960}
3961
3962static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3963{
Al Viro8687b632006-10-19 23:28:48 -07003964 uint32_t major = 0, minor = 0;
3965 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003966 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967
3968 *rdev = MKDEV(0,0);
3969 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3970 return -EIO;
3971 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3972 dev_t tmp;
3973
Benny Halevyc0eae662009-08-14 17:20:14 +03003974 p = xdr_inline_decode(xdr, 8);
3975 if (unlikely(!p))
3976 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003977 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003978 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 tmp = MKDEV(major, minor);
3980 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3981 *rdev = tmp;
3982 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003983 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003985 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003986 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003987out_overflow:
3988 print_overflow_msg(__func__, xdr);
3989 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990}
3991
3992static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3993{
Al Viro8687b632006-10-19 23:28:48 -07003994 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 int status = 0;
3996
3997 *res = 0;
3998 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3999 return -EIO;
4000 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004001 p = xdr_inline_decode(xdr, 8);
4002 if (unlikely(!p))
4003 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004004 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4006 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004007 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004009out_overflow:
4010 print_overflow_msg(__func__, xdr);
4011 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012}
4013
4014static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4015{
Al Viro8687b632006-10-19 23:28:48 -07004016 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 int status = 0;
4018
4019 *res = 0;
4020 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4021 return -EIO;
4022 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004023 p = xdr_inline_decode(xdr, 8);
4024 if (unlikely(!p))
4025 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004026 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4028 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004029 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004031out_overflow:
4032 print_overflow_msg(__func__, xdr);
4033 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034}
4035
4036static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4037{
Al Viro8687b632006-10-19 23:28:48 -07004038 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039 int status = 0;
4040
4041 *res = 0;
4042 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4043 return -EIO;
4044 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004045 p = xdr_inline_decode(xdr, 8);
4046 if (unlikely(!p))
4047 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004048 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4050 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004051 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004053out_overflow:
4054 print_overflow_msg(__func__, xdr);
4055 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056}
4057
4058static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4059{
Al Viro8687b632006-10-19 23:28:48 -07004060 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004061 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062
4063 *used = 0;
4064 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4065 return -EIO;
4066 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004067 p = xdr_inline_decode(xdr, 8);
4068 if (unlikely(!p))
4069 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004070 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004072 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004074 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004076 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004077out_overflow:
4078 print_overflow_msg(__func__, xdr);
4079 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080}
4081
4082static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4083{
Al Viro8687b632006-10-19 23:28:48 -07004084 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 uint64_t sec;
4086 uint32_t nsec;
4087
Benny Halevyc0eae662009-08-14 17:20:14 +03004088 p = xdr_inline_decode(xdr, 12);
4089 if (unlikely(!p))
4090 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004091 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004092 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093 time->tv_sec = (time_t)sec;
4094 time->tv_nsec = (long)nsec;
4095 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004096out_overflow:
4097 print_overflow_msg(__func__, xdr);
4098 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099}
4100
4101static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4102{
4103 int status = 0;
4104
4105 time->tv_sec = 0;
4106 time->tv_nsec = 0;
4107 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4108 return -EIO;
4109 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4110 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004111 if (status == 0)
4112 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4114 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004115 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116 return status;
4117}
4118
4119static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4120{
4121 int status = 0;
4122
4123 time->tv_sec = 0;
4124 time->tv_nsec = 0;
4125 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4126 return -EIO;
4127 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4128 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004129 if (status == 0)
4130 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4132 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004133 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 return status;
4135}
4136
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004137static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4138 struct timespec *time)
4139{
4140 int status = 0;
4141
4142 time->tv_sec = 0;
4143 time->tv_nsec = 0;
4144 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4145 return -EIO;
4146 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4147 status = decode_attr_time(xdr, time);
4148 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4149 }
4150 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4151 (long)time->tv_nsec);
4152 return status;
4153}
4154
David Quigleyaa9c2662013-05-22 12:50:44 -04004155static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4156 struct nfs4_label *label)
4157{
4158 uint32_t pi = 0;
4159 uint32_t lfs = 0;
4160 __u32 len;
4161 __be32 *p;
4162 int status = 0;
4163
4164 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4165 return -EIO;
4166 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4167 p = xdr_inline_decode(xdr, 4);
4168 if (unlikely(!p))
4169 goto out_overflow;
4170 lfs = be32_to_cpup(p++);
4171 p = xdr_inline_decode(xdr, 4);
4172 if (unlikely(!p))
4173 goto out_overflow;
4174 pi = be32_to_cpup(p++);
4175 p = xdr_inline_decode(xdr, 4);
4176 if (unlikely(!p))
4177 goto out_overflow;
4178 len = be32_to_cpup(p++);
4179 p = xdr_inline_decode(xdr, len);
4180 if (unlikely(!p))
4181 goto out_overflow;
4182 if (len < NFS4_MAXLABELLEN) {
4183 if (label) {
4184 memcpy(label->label, p, len);
4185 label->len = len;
4186 label->pi = pi;
4187 label->lfs = lfs;
4188 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4189 }
4190 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4191 } else
4192 printk(KERN_WARNING "%s: label too long (%u)!\n",
4193 __func__, len);
4194 }
4195 if (label && label->label)
4196 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4197 (char *)label->label, label->len, label->pi, label->lfs);
4198 return status;
4199
4200out_overflow:
4201 print_overflow_msg(__func__, xdr);
4202 return -EIO;
4203}
4204
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4206{
4207 int status = 0;
4208
4209 time->tv_sec = 0;
4210 time->tv_nsec = 0;
4211 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4212 return -EIO;
4213 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4214 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004215 if (status == 0)
4216 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4218 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004219 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 return status;
4221}
4222
Trond Myklebust256e48b2012-06-21 11:18:13 -04004223static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224{
4225 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004226 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227
4228 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004229 dprintk("%s: server returned incorrect attribute length: "
4230 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004231 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232 attrwords << 2,
4233 (attrwords < nwords) ? '<' : '>',
4234 nwords << 2);
4235 return -EIO;
4236 }
4237 return 0;
4238}
4239
4240static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4241{
Al Viro8687b632006-10-19 23:28:48 -07004242 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243
Benny Halevyc0eae662009-08-14 17:20:14 +03004244 p = xdr_inline_decode(xdr, 20);
4245 if (unlikely(!p))
4246 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004247 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004248 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004249 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004251out_overflow:
4252 print_overflow_msg(__func__, xdr);
4253 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254}
4255
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004256static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257{
Al Viro8687b632006-10-19 23:28:48 -07004258 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004259 uint32_t supp, acc;
4260 int status;
4261
4262 status = decode_op_hdr(xdr, OP_ACCESS);
4263 if (status)
4264 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004265 p = xdr_inline_decode(xdr, 8);
4266 if (unlikely(!p))
4267 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004268 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004269 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004270 *supported = supp;
4271 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004273out_overflow:
4274 print_overflow_msg(__func__, xdr);
4275 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276}
4277
Benny Halevy07d30432009-08-14 17:19:52 +03004278static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279{
Al Viro8687b632006-10-19 23:28:48 -07004280 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004281
4282 p = xdr_inline_decode(xdr, len);
4283 if (likely(p)) {
4284 memcpy(buf, p, len);
4285 return 0;
4286 }
4287 print_overflow_msg(__func__, xdr);
4288 return -EIO;
4289}
4290
4291static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4292{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004293 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294}
4295
Trond Myklebust93b717f2016-05-16 17:42:43 -04004296static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4297{
4298 stateid->type = NFS4_OPEN_STATEID_TYPE;
4299 return decode_stateid(xdr, stateid);
4300}
4301
4302static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4303{
4304 stateid->type = NFS4_LOCK_STATEID_TYPE;
4305 return decode_stateid(xdr, stateid);
4306}
4307
4308static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4309{
4310 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4311 return decode_stateid(xdr, stateid);
4312}
4313
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4315{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 int status;
4317
4318 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004319 if (status != -EIO)
4320 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004321 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04004322 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004323 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324}
4325
Benny Halevydb942bb2009-08-14 17:19:56 +03004326static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4327{
Chuck Levercd937102012-03-02 17:14:31 -05004328 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004329}
4330
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004331static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4332{
4333 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4334}
4335
Fred Isaman0b7c0152012-04-20 14:47:39 -04004336static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338 int status;
4339
4340 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004341 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004342 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004343 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004344}
4345
4346static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4347{
Al Viro8687b632006-10-19 23:28:48 -07004348 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349 uint32_t bmlen;
4350 int status;
4351
4352 status = decode_op_hdr(xdr, OP_CREATE);
4353 if (status)
4354 return status;
4355 if ((status = decode_change_info(xdr, cinfo)))
4356 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004357 p = xdr_inline_decode(xdr, 4);
4358 if (unlikely(!p))
4359 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004360 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004361 p = xdr_inline_decode(xdr, bmlen << 2);
4362 if (likely(p))
4363 return 0;
4364out_overflow:
4365 print_overflow_msg(__func__, xdr);
4366 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367}
4368
4369static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4370{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004371 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004372 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373 int status;
4374
4375 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4376 goto xdr_error;
4377 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4378 goto xdr_error;
4379 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4380 goto xdr_error;
4381 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4382 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004383 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4384 &res->fh_expire_type)) != 0)
4385 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4387 goto xdr_error;
4388 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4389 goto xdr_error;
4390 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4391 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004392 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4393 res->exclcreat_bitmask)) != 0)
4394 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395 status = verify_attr_len(xdr, savep, attrlen);
4396xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004397 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398 return status;
4399}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004400
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4402{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004403 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004404 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004406
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4408 goto xdr_error;
4409 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4410 goto xdr_error;
4411 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4412 goto xdr_error;
4413
4414 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4415 goto xdr_error;
4416 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4417 goto xdr_error;
4418 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4419 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004420
4421 status = -EIO;
4422 if (unlikely(bitmap[0]))
4423 goto xdr_error;
4424
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4426 goto xdr_error;
4427 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4428 goto xdr_error;
4429 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4430 goto xdr_error;
4431
4432 status = verify_attr_len(xdr, savep, attrlen);
4433xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004434 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435 return status;
4436}
4437
4438static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4439{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004440 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004441 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004443
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4445 goto xdr_error;
4446 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4447 goto xdr_error;
4448 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4449 goto xdr_error;
4450
4451 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4452 goto xdr_error;
4453 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4454 goto xdr_error;
4455
4456 status = verify_attr_len(xdr, savep, attrlen);
4457xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004458 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459 return status;
4460}
4461
Andy Adamson88034c32012-05-23 05:02:34 -04004462static int decode_threshold_hint(struct xdr_stream *xdr,
4463 uint32_t *bitmap,
4464 uint64_t *res,
4465 uint32_t hint_bit)
4466{
4467 __be32 *p;
4468
4469 *res = 0;
4470 if (likely(bitmap[0] & hint_bit)) {
4471 p = xdr_inline_decode(xdr, 8);
4472 if (unlikely(!p))
4473 goto out_overflow;
4474 xdr_decode_hyper(p, res);
4475 }
4476 return 0;
4477out_overflow:
4478 print_overflow_msg(__func__, xdr);
4479 return -EIO;
4480}
4481
4482static int decode_first_threshold_item4(struct xdr_stream *xdr,
4483 struct nfs4_threshold *res)
4484{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004485 __be32 *p;
4486 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004487 uint32_t bitmap[3] = {0,}, attrlen;
4488 int status;
4489
4490 /* layout type */
4491 p = xdr_inline_decode(xdr, 4);
4492 if (unlikely(!p)) {
4493 print_overflow_msg(__func__, xdr);
4494 return -EIO;
4495 }
4496 res->l_type = be32_to_cpup(p);
4497
4498 /* thi_hintset bitmap */
4499 status = decode_attr_bitmap(xdr, bitmap);
4500 if (status < 0)
4501 goto xdr_error;
4502
4503 /* thi_hintlist length */
4504 status = decode_attr_length(xdr, &attrlen, &savep);
4505 if (status < 0)
4506 goto xdr_error;
4507 /* thi_hintlist */
4508 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4509 if (status < 0)
4510 goto xdr_error;
4511 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4512 if (status < 0)
4513 goto xdr_error;
4514 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4515 THRESHOLD_RD_IO);
4516 if (status < 0)
4517 goto xdr_error;
4518 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4519 THRESHOLD_WR_IO);
4520 if (status < 0)
4521 goto xdr_error;
4522
4523 status = verify_attr_len(xdr, savep, attrlen);
4524 res->bm = bitmap[0];
4525
4526 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4527 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4528 res->wr_io_sz);
4529xdr_error:
4530 dprintk("%s ret=%d!\n", __func__, status);
4531 return status;
4532}
4533
4534/*
4535 * Thresholds on pNFS direct I/O vrs MDS I/O
4536 */
4537static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4538 uint32_t *bitmap,
4539 struct nfs4_threshold *res)
4540{
4541 __be32 *p;
4542 int status = 0;
4543 uint32_t num;
4544
4545 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4546 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004547 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004548 /* Did the server return an unrequested attribute? */
4549 if (unlikely(res == NULL))
4550 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004551 p = xdr_inline_decode(xdr, 4);
4552 if (unlikely(!p))
4553 goto out_overflow;
4554 num = be32_to_cpup(p);
4555 if (num == 0)
4556 return 0;
4557 if (num > 1)
4558 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4559 "drivers per filesystem not supported\n",
4560 __func__);
4561
4562 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004563 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004564 }
4565 return status;
4566out_overflow:
4567 print_overflow_msg(__func__, xdr);
4568 return -EIO;
4569}
4570
Bryan Schumakerae42c702010-10-21 16:33:17 -04004571static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4572 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004573 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004574 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004575{
Trond Myklebustbca79472009-03-11 14:10:26 -04004576 int status;
4577 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004578 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004579 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004581 status = decode_attr_type(xdr, bitmap, &type);
4582 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004583 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004584 fattr->mode = 0;
4585 if (status != 0) {
4586 fattr->mode |= nfs_type2fmt[type];
4587 fattr->valid |= status;
4588 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004589
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004590 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4591 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004593 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004594
4595 status = decode_attr_size(xdr, bitmap, &fattr->size);
4596 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004597 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004598 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004599
4600 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4601 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004602 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004603 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004604
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004605 err = 0;
4606 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004607 if (status < 0)
4608 goto xdr_error;
4609
4610 status = decode_attr_filehandle(xdr, bitmap, fh);
4611 if (status < 0)
4612 goto xdr_error;
4613
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004614 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4615 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004617 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004618
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004619 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004620 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004621 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004622 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004623
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004624 status = -EIO;
4625 if (unlikely(bitmap[0]))
4626 goto xdr_error;
4627
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004628 status = decode_attr_mode(xdr, bitmap, &fmode);
4629 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004631 if (status != 0) {
4632 fattr->mode |= fmode;
4633 fattr->valid |= status;
4634 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004635
4636 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4637 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004639 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004640
Trond Myklebust6926afd2012-01-07 13:22:46 -05004641 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004642 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004643 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004644 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004645
Trond Myklebust6926afd2012-01-07 13:22:46 -05004646 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004647 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004649 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004650
4651 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4652 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004653 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004654 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004655
4656 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4657 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004659 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004660
4661 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4662 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004663 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004664 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004665
4666 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4667 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004668 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004669 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004670
4671 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4672 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004673 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004674 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004675
Trond Myklebust28331a42011-04-27 13:47:52 -04004676 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004677 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004678 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004679 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004680
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004681 status = -EIO;
4682 if (unlikely(bitmap[1]))
4683 goto xdr_error;
4684
Andy Adamson88034c32012-05-23 05:02:34 -04004685 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4686 if (status < 0)
4687 goto xdr_error;
4688
David Quigleyaa9c2662013-05-22 12:50:44 -04004689 if (label) {
4690 status = decode_attr_security_label(xdr, bitmap, label);
4691 if (status < 0)
4692 goto xdr_error;
4693 fattr->valid |= status;
4694 }
4695
Bryan Schumakerae42c702010-10-21 16:33:17 -04004696xdr_error:
4697 dprintk("%s: xdr returned %d\n", __func__, -status);
4698 return status;
4699}
4700
4701static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004702 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004703 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004704{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004705 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004706 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004707 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004708 int status;
4709
4710 status = decode_op_hdr(xdr, OP_GETATTR);
4711 if (status < 0)
4712 goto xdr_error;
4713
4714 status = decode_attr_bitmap(xdr, bitmap);
4715 if (status < 0)
4716 goto xdr_error;
4717
4718 status = decode_attr_length(xdr, &attrlen, &savep);
4719 if (status < 0)
4720 goto xdr_error;
4721
David Quigleyaa9c2662013-05-22 12:50:44 -04004722 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4723 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004724 if (status < 0)
4725 goto xdr_error;
4726
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004727 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004729 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730 return status;
4731}
4732
David Quigleyaa9c2662013-05-22 12:50:44 -04004733static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4734 struct nfs4_label *label, const struct nfs_server *server)
4735{
4736 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4737}
4738
Bryan Schumakerae42c702010-10-21 16:33:17 -04004739static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004740 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004741{
David Quigleyaa9c2662013-05-22 12:50:44 -04004742 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004743}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744
Andy Adamson504913f2010-10-20 00:17:57 -04004745/*
Jeff Layton3132e492016-08-10 15:58:24 -04004746 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004747 */
Jeff Layton3132e492016-08-10 15:58:24 -04004748static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004749 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004750{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004751 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004752 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004753
4754 p = xdr_inline_decode(xdr, 4);
4755 if (unlikely(!p))
4756 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004757 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004758
4759 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004760 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004761 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004762
4763 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004764 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004765 if (unlikely(!p))
4766 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004767
4768 /* If we get too many, then just cap it at the max */
4769 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4770 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4771 __func__, fsinfo->nlayouttypes);
4772 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4773 }
4774
4775 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4776 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004777 return 0;
4778out_overflow:
4779 print_overflow_msg(__func__, xdr);
4780 return -EIO;
4781}
4782
4783/*
4784 * The type of file system exported.
4785 * Note we must ensure that layouttype is set in any non-error case.
4786 */
4787static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004788 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004789{
4790 int status = 0;
4791
4792 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4793 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4794 return -EIO;
4795 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004796 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004797 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004798 }
Andy Adamson504913f2010-10-20 00:17:57 -04004799 return status;
4800}
4801
Fred Isamandae100c2011-07-30 20:52:37 -04004802/*
4803 * The prefered block size for layout directed io
4804 */
4805static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4806 uint32_t *res)
4807{
4808 __be32 *p;
4809
4810 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4811 *res = 0;
4812 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4813 p = xdr_inline_decode(xdr, 4);
4814 if (unlikely(!p)) {
4815 print_overflow_msg(__func__, xdr);
4816 return -EIO;
4817 }
4818 *res = be32_to_cpup(p);
4819 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4820 }
4821 return 0;
4822}
4823
Peng Tao2a92ee92015-09-26 02:24:37 +08004824/*
4825 * The granularity of a CLONE operation.
4826 */
4827static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4828 uint32_t *res)
4829{
4830 __be32 *p;
4831
4832 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4833 *res = 0;
4834 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4835 p = xdr_inline_decode(xdr, 4);
4836 if (unlikely(!p)) {
4837 print_overflow_msg(__func__, xdr);
4838 return -EIO;
4839 }
4840 *res = be32_to_cpup(p);
4841 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4842 }
4843 return 0;
4844}
4845
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4847{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004848 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004849 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850 int status;
4851
4852 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4853 goto xdr_error;
4854 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4855 goto xdr_error;
4856 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4857 goto xdr_error;
4858
4859 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4860
4861 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4862 goto xdr_error;
4863 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4864 goto xdr_error;
4865 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4866 goto xdr_error;
4867 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4868 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4869 goto xdr_error;
4870 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004871
4872 status = -EIO;
4873 if (unlikely(bitmap[0]))
4874 goto xdr_error;
4875
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004876 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4877 if (status != 0)
4878 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004879 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004880 if (status != 0)
4881 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004882
4883 status = -EIO;
4884 if (unlikely(bitmap[1]))
4885 goto xdr_error;
4886
Fred Isamandae100c2011-07-30 20:52:37 -04004887 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4888 if (status)
4889 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004890 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4891 if (status)
4892 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893
4894 status = verify_attr_len(xdr, savep, attrlen);
4895xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004896 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004897 return status;
4898}
4899
4900static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4901{
Al Viro8687b632006-10-19 23:28:48 -07004902 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903 uint32_t len;
4904 int status;
4905
Trond Myklebust99367812007-07-17 21:52:41 -04004906 /* Zero handle first to allow comparisons */
4907 memset(fh, 0, sizeof(*fh));
4908
Linus Torvalds1da177e2005-04-16 15:20:36 -07004909 status = decode_op_hdr(xdr, OP_GETFH);
4910 if (status)
4911 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004912
Benny Halevyc0eae662009-08-14 17:20:14 +03004913 p = xdr_inline_decode(xdr, 4);
4914 if (unlikely(!p))
4915 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004916 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004917 if (len > NFS4_FHSIZE)
4918 return -EIO;
4919 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004920 p = xdr_inline_decode(xdr, len);
4921 if (unlikely(!p))
4922 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004923 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004924 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004925out_overflow:
4926 print_overflow_msg(__func__, xdr);
4927 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928}
4929
4930static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4931{
4932 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004933
Linus Torvalds1da177e2005-04-16 15:20:36 -07004934 status = decode_op_hdr(xdr, OP_LINK);
4935 if (status)
4936 return status;
4937 return decode_change_info(xdr, cinfo);
4938}
4939
4940/*
4941 * We create the owner, so we know a proper owner.id length is 4.
4942 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004943static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004945 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004946 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004947 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004949 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004950 if (unlikely(!p))
4951 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004952 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004953 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004954 type = be32_to_cpup(p++); /* 4 byte read */
4955 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004956 fl->fl_start = (loff_t)offset;
4957 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4958 if (length == ~(uint64_t)0)
4959 fl->fl_end = OFFSET_MAX;
4960 fl->fl_type = F_WRLCK;
4961 if (type & 1)
4962 fl->fl_type = F_RDLCK;
4963 fl->fl_pid = 0;
4964 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004965 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4966 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4967 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004968 if (likely(p))
4969 return -NFS4ERR_DENIED;
4970out_overflow:
4971 print_overflow_msg(__func__, xdr);
4972 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973}
4974
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004975static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977 int status;
4978
4979 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004980 if (status == -EIO)
4981 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04004983 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004984 if (unlikely(status))
4985 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004987 status = decode_lock_denied(xdr, NULL);
4988 if (res->open_seqid != NULL)
4989 nfs_increment_open_seqid(status, res->open_seqid);
4990 nfs_increment_lock_seqid(status, res->lock_seqid);
4991out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992 return status;
4993}
4994
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004995static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996{
4997 int status;
4998 status = decode_op_hdr(xdr, OP_LOCKT);
4999 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005000 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001 return status;
5002}
5003
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005004static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006 int status;
5007
5008 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005009 if (status != -EIO)
5010 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005011 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005012 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013 return status;
5014}
5015
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005016static int decode_release_lockowner(struct xdr_stream *xdr)
5017{
5018 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5019}
5020
Linus Torvalds1da177e2005-04-16 15:20:36 -07005021static int decode_lookup(struct xdr_stream *xdr)
5022{
5023 return decode_op_hdr(xdr, OP_LOOKUP);
5024}
5025
5026/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005027static int decode_space_limit(struct xdr_stream *xdr,
5028 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029{
Andy Adamson05d564f2008-12-23 16:06:15 -05005030 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005032 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005033
Benny Halevyc0eae662009-08-14 17:20:14 +03005034 p = xdr_inline_decode(xdr, 12);
5035 if (unlikely(!p))
5036 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005037 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005039 case NFS4_LIMIT_SIZE:
5040 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005041 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005042 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005043 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005044 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005045 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005047 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005048 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005050out_overflow:
5051 print_overflow_msg(__func__, xdr);
5052 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053}
5054
Trond Myklebust6ae37332015-01-30 14:21:14 -05005055static int decode_rw_delegation(struct xdr_stream *xdr,
5056 uint32_t delegation_type,
5057 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058{
Andy Adamson05d564f2008-12-23 16:06:15 -05005059 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005060 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061
Trond Myklebust93b717f2016-05-16 17:42:43 -04005062 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005063 if (unlikely(status))
5064 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005065 p = xdr_inline_decode(xdr, 4);
5066 if (unlikely(!p))
5067 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005068 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005069
Linus Torvalds1da177e2005-04-16 15:20:36 -07005070 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005071 case NFS4_OPEN_DELEGATE_READ:
5072 res->delegation_type = FMODE_READ;
5073 break;
5074 case NFS4_OPEN_DELEGATE_WRITE:
5075 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005076 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077 return -EIO;
5078 }
David Howells7539bba2006-08-22 20:06:09 -04005079 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03005080out_overflow:
5081 print_overflow_msg(__func__, xdr);
5082 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083}
5084
Trond Myklebust6ae37332015-01-30 14:21:14 -05005085static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5086{
5087 __be32 *p;
5088 uint32_t why_no_delegation;
5089
5090 p = xdr_inline_decode(xdr, 4);
5091 if (unlikely(!p))
5092 goto out_overflow;
5093 why_no_delegation = be32_to_cpup(p);
5094 switch (why_no_delegation) {
5095 case WND4_CONTENTION:
5096 case WND4_RESOURCE:
5097 xdr_inline_decode(xdr, 4);
5098 /* Ignore for now */
5099 }
5100 return 0;
5101out_overflow:
5102 print_overflow_msg(__func__, xdr);
5103 return -EIO;
5104}
5105
5106static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5107{
5108 __be32 *p;
5109 uint32_t delegation_type;
5110
5111 p = xdr_inline_decode(xdr, 4);
5112 if (unlikely(!p))
5113 goto out_overflow;
5114 delegation_type = be32_to_cpup(p);
5115 res->delegation_type = 0;
5116 switch (delegation_type) {
5117 case NFS4_OPEN_DELEGATE_NONE:
5118 return 0;
5119 case NFS4_OPEN_DELEGATE_READ:
5120 case NFS4_OPEN_DELEGATE_WRITE:
5121 return decode_rw_delegation(xdr, delegation_type, res);
5122 case NFS4_OPEN_DELEGATE_NONE_EXT:
5123 return decode_no_delegation(xdr, res);
5124 }
5125 return -EIO;
5126out_overflow:
5127 print_overflow_msg(__func__, xdr);
5128 return -EIO;
5129}
5130
Linus Torvalds1da177e2005-04-16 15:20:36 -07005131static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5132{
Andy Adamson05d564f2008-12-23 16:06:15 -05005133 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005134 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005135 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136
Trond Myklebustc7848f62013-12-04 17:39:23 -05005137 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5138 return status;
5139 nfs_increment_open_seqid(status, res->seqid);
5140 if (status)
5141 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005142 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005143 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005144 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005145
Andy Adamson05d564f2008-12-23 16:06:15 -05005146 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147
Benny Halevyc0eae662009-08-14 17:20:14 +03005148 p = xdr_inline_decode(xdr, 8);
5149 if (unlikely(!p))
5150 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005151 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005152 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005153 if (bmlen > 10)
5154 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155
Benny Halevyc0eae662009-08-14 17:20:14 +03005156 p = xdr_inline_decode(xdr, bmlen << 2);
5157 if (unlikely(!p))
5158 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005159 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5160 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005161 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005162 for (; i < NFS4_BITMAP_SIZE; i++)
5163 res->attrset[i] = 0;
5164
Linus Torvalds1da177e2005-04-16 15:20:36 -07005165 return decode_delegation(xdr, res);
5166xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005167 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005169out_overflow:
5170 print_overflow_msg(__func__, xdr);
5171 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005172}
5173
5174static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5175{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005176 int status;
5177
Andy Adamson05d564f2008-12-23 16:06:15 -05005178 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005179 if (status != -EIO)
5180 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005181 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005182 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005183 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005184}
5185
5186static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5187{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005188 int status;
5189
5190 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005191 if (status != -EIO)
5192 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005193 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005194 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005195 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005196}
5197
5198static int decode_putfh(struct xdr_stream *xdr)
5199{
5200 return decode_op_hdr(xdr, OP_PUTFH);
5201}
5202
5203static int decode_putrootfh(struct xdr_stream *xdr)
5204{
5205 return decode_op_hdr(xdr, OP_PUTROOTFH);
5206}
5207
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005208static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5209 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005210{
Al Viro8687b632006-10-19 23:28:48 -07005211 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005212 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005213 int status;
5214
5215 status = decode_op_hdr(xdr, OP_READ);
5216 if (status)
5217 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005218 p = xdr_inline_decode(xdr, 8);
5219 if (unlikely(!p))
5220 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005221 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005222 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005223 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005224 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005225 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005226 "count %u > recvd %u\n", count, recvd);
5227 count = recvd;
5228 eof = 0;
5229 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005230 res->eof = eof;
5231 res->count = count;
5232 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005233out_overflow:
5234 print_overflow_msg(__func__, xdr);
5235 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005236}
5237
5238static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5239{
Chuck Leverbcecff72007-10-26 13:32:03 -04005240 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005241 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005242
5243 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005244 if (!status)
5245 status = decode_verifier(xdr, readdir->verifier.data);
5246 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005247 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005248 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005249 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005250 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005251 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252}
5253
5254static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5255{
5256 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005257 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005258 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005259 int status;
5260
5261 status = decode_op_hdr(xdr, OP_READLINK);
5262 if (status)
5263 return status;
5264
5265 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005266 p = xdr_inline_decode(xdr, 4);
5267 if (unlikely(!p))
5268 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005269 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005270 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005271 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005272 return -ENAMETOOLONG;
5273 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005274 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005275 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005276 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277 "count %u > recvd %u\n", len, recvd);
5278 return -EIO;
5279 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005280 /*
5281 * The XDR encode routine has set things up so that
5282 * the link text will be copied directly into the
5283 * buffer. We just have to do overflow-checking,
5284 * and and null-terminate the text (the VFS expects
5285 * null-termination).
5286 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005287 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005288 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005289out_overflow:
5290 print_overflow_msg(__func__, xdr);
5291 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005292}
5293
5294static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5295{
5296 int status;
5297
5298 status = decode_op_hdr(xdr, OP_REMOVE);
5299 if (status)
5300 goto out;
5301 status = decode_change_info(xdr, cinfo);
5302out:
5303 return status;
5304}
5305
5306static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5307 struct nfs4_change_info *new_cinfo)
5308{
5309 int status;
5310
5311 status = decode_op_hdr(xdr, OP_RENAME);
5312 if (status)
5313 goto out;
5314 if ((status = decode_change_info(xdr, old_cinfo)))
5315 goto out;
5316 status = decode_change_info(xdr, new_cinfo);
5317out:
5318 return status;
5319}
5320
5321static int decode_renew(struct xdr_stream *xdr)
5322{
5323 return decode_op_hdr(xdr, OP_RENEW);
5324}
5325
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005326static int
5327decode_restorefh(struct xdr_stream *xdr)
5328{
5329 return decode_op_hdr(xdr, OP_RESTOREFH);
5330}
5331
J. Bruce Fields029d1052005-06-22 17:16:22 +00005332static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005333 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005334{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005335 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005336 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005337 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005338 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005339 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005340
Andy Adamsonbf118a32011-12-07 11:55:27 -05005341 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005342 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5343 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005344
Trond Myklebust519d3952012-08-14 17:30:10 -04005345 xdr_enter_page(xdr, xdr->buf->page_len);
5346
Trond Myklebustcff298c2012-08-14 17:14:17 -04005347 /* Calculate the offset of the page data */
5348 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005349
J. Bruce Fields029d1052005-06-22 17:16:22 +00005350 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5351 goto out;
5352 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5353 goto out;
5354
5355 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5356 return -EIO;
5357 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005358
Andy Adamsonbf118a32011-12-07 11:55:27 -05005359 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5360 * are stored with the acl data to handle the problem of
5361 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005362 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005363 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005364
5365 /* Check for receive buffer overflow */
5366 if (res->acl_len > (xdr->nwords << 2) ||
5367 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5368 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005369 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005370 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005371 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005372 } else
5373 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005374
5375out:
5376 return status;
5377}
5378
Linus Torvalds1da177e2005-04-16 15:20:36 -07005379static int
5380decode_savefh(struct xdr_stream *xdr)
5381{
5382 return decode_op_hdr(xdr, OP_SAVEFH);
5383}
5384
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005385static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005386{
Al Viro8687b632006-10-19 23:28:48 -07005387 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005388 uint32_t bmlen;
5389 int status;
5390
Linus Torvalds1da177e2005-04-16 15:20:36 -07005391 status = decode_op_hdr(xdr, OP_SETATTR);
5392 if (status)
5393 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005394 p = xdr_inline_decode(xdr, 4);
5395 if (unlikely(!p))
5396 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005397 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005398 p = xdr_inline_decode(xdr, bmlen << 2);
5399 if (likely(p))
5400 return 0;
5401out_overflow:
5402 print_overflow_msg(__func__, xdr);
5403 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005404}
5405
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005406static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005407{
Al Viro8687b632006-10-19 23:28:48 -07005408 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005409 uint32_t opnum;
5410 int32_t nfserr;
5411
Benny Halevyc0eae662009-08-14 17:20:14 +03005412 p = xdr_inline_decode(xdr, 8);
5413 if (unlikely(!p))
5414 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005415 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005416 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005417 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005418 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005419 return -EIO;
5420 }
Benny Halevycccddf42009-08-14 17:20:19 +03005421 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005422 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005423 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5424 if (unlikely(!p))
5425 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005426 p = xdr_decode_hyper(p, &res->clientid);
5427 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005428 } else if (nfserr == NFSERR_CLID_INUSE) {
5429 uint32_t len;
5430
5431 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005432 p = xdr_inline_decode(xdr, 4);
5433 if (unlikely(!p))
5434 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005435 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005436 p = xdr_inline_decode(xdr, len);
5437 if (unlikely(!p))
5438 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005439
5440 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005441 p = xdr_inline_decode(xdr, 4);
5442 if (unlikely(!p))
5443 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005444 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005445 p = xdr_inline_decode(xdr, len);
5446 if (unlikely(!p))
5447 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005448 return -NFSERR_CLID_INUSE;
5449 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005450 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005451
5452 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005453out_overflow:
5454 print_overflow_msg(__func__, xdr);
5455 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005456}
5457
5458static int decode_setclientid_confirm(struct xdr_stream *xdr)
5459{
5460 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5461}
5462
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005463static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005464{
Al Viro8687b632006-10-19 23:28:48 -07005465 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005466 int status;
5467
5468 status = decode_op_hdr(xdr, OP_WRITE);
5469 if (status)
5470 return status;
5471
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005472 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005473 if (unlikely(!p))
5474 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005475 res->count = be32_to_cpup(p++);
5476 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005477 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005478out_overflow:
5479 print_overflow_msg(__func__, xdr);
5480 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005481}
5482
5483static int decode_delegreturn(struct xdr_stream *xdr)
5484{
5485 return decode_op_hdr(xdr, OP_DELEGRETURN);
5486}
5487
Chuck Leverfb15b262013-03-16 15:54:34 -04005488static int decode_secinfo_gss(struct xdr_stream *xdr,
5489 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005490{
Chuck Leverfb15b262013-03-16 15:54:34 -04005491 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005492 __be32 *p;
5493
5494 p = xdr_inline_decode(xdr, 4);
5495 if (unlikely(!p))
5496 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005497 oid_len = be32_to_cpup(p);
5498 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005499 goto out_err;
5500
Chuck Leverfb15b262013-03-16 15:54:34 -04005501 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005502 if (unlikely(!p))
5503 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005504 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5505 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005506
5507 p = xdr_inline_decode(xdr, 8);
5508 if (unlikely(!p))
5509 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005510 flavor->flavor_info.qop = be32_to_cpup(p++);
5511 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005512
5513 return 0;
5514
5515out_overflow:
5516 print_overflow_msg(__func__, xdr);
5517 return -EIO;
5518out_err:
5519 return -EINVAL;
5520}
5521
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005522static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005523{
Chuck Leverfb15b262013-03-16 15:54:34 -04005524 struct nfs4_secinfo4 *sec_flavor;
5525 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005526 int status;
5527 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005528
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005529 p = xdr_inline_decode(xdr, 4);
5530 if (unlikely(!p))
5531 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005532
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005533 res->flavors->num_flavors = 0;
5534 num_flavors = be32_to_cpup(p);
5535
5536 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005537 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005538 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005539 break;
5540
5541 p = xdr_inline_decode(xdr, 4);
5542 if (unlikely(!p))
5543 goto out_overflow;
5544 sec_flavor->flavor = be32_to_cpup(p);
5545
5546 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005547 status = decode_secinfo_gss(xdr, sec_flavor);
5548 if (status)
5549 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005550 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005551 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005552 }
5553
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005554 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005555out:
5556 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005557out_overflow:
5558 print_overflow_msg(__func__, xdr);
5559 return -EIO;
5560}
5561
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005562static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5563{
5564 int status = decode_op_hdr(xdr, OP_SECINFO);
5565 if (status)
5566 return status;
5567 return decode_secinfo_common(xdr, res);
5568}
5569
Benny Halevy99fe60d2009-04-01 09:22:29 -04005570#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005571static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5572{
5573 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5574 if (status)
5575 return status;
5576 return decode_secinfo_common(xdr, res);
5577}
5578
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005579static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5580{
5581 __be32 *p;
5582 uint32_t bitmap_words;
5583 unsigned int i;
5584
5585 p = xdr_inline_decode(xdr, 4);
5586 bitmap_words = be32_to_cpup(p++);
5587 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5588 return -EIO;
5589 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5590 for (i = 0; i < bitmap_words; i++)
5591 op_map->u.words[i] = be32_to_cpup(p++);
5592
5593 return 0;
5594}
5595
Benny Halevy99fe60d2009-04-01 09:22:29 -04005596static int decode_exchange_id(struct xdr_stream *xdr,
5597 struct nfs41_exchange_id_res *res)
5598{
5599 __be32 *p;
5600 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005601 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005602 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005603 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005604
5605 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5606 if (status)
5607 return status;
5608
Benny Halevyc0eae662009-08-14 17:20:14 +03005609 p = xdr_inline_decode(xdr, 8);
5610 if (unlikely(!p))
5611 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005612 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005613 p = xdr_inline_decode(xdr, 12);
5614 if (unlikely(!p))
5615 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005616 res->seqid = be32_to_cpup(p++);
5617 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005618
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005619 res->state_protect.how = be32_to_cpup(p);
5620 switch (res->state_protect.how) {
5621 case SP4_NONE:
5622 break;
5623 case SP4_MACH_CRED:
5624 status = decode_op_map(xdr, &res->state_protect.enforce);
5625 if (status)
5626 return status;
5627 status = decode_op_map(xdr, &res->state_protect.allow);
5628 if (status)
5629 return status;
5630 break;
5631 default:
5632 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005633 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005634 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005635
Chuck Leveracdeb692012-05-21 22:46:16 -04005636 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005637 p = xdr_inline_decode(xdr, 8);
5638 if (unlikely(!p))
5639 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005640 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005641
Chuck Leveracdeb692012-05-21 22:46:16 -04005642 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005643 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5644 if (unlikely(status))
5645 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005646 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5647 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005648 memcpy(res->server_owner->major_id, dummy_str, dummy);
5649 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005650
Chuck Leveracdeb692012-05-21 22:46:16 -04005651 /* server_scope4 */
5652 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5653 if (unlikely(status))
5654 return status;
5655 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5656 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005657 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5658 res->server_scope->server_scope_sz = dummy;
5659
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005660 /* Implementation Id */
5661 p = xdr_inline_decode(xdr, 4);
5662 if (unlikely(!p))
5663 goto out_overflow;
5664 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005665
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005666 if (impl_id_count) {
5667 /* nii_domain */
5668 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5669 if (unlikely(status))
5670 return status;
5671 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5672 return -EIO;
5673 memcpy(res->impl_id->domain, dummy_str, dummy);
5674
5675 /* nii_name */
5676 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5677 if (unlikely(status))
5678 return status;
5679 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5680 return -EIO;
5681 memcpy(res->impl_id->name, dummy_str, dummy);
5682
5683 /* nii_date */
5684 p = xdr_inline_decode(xdr, 12);
5685 if (unlikely(!p))
5686 goto out_overflow;
5687 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5688 res->impl_id->date.nseconds = be32_to_cpup(p);
5689
5690 /* if there's more than one entry, ignore the rest */
5691 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005692 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005693out_overflow:
5694 print_overflow_msg(__func__, xdr);
5695 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005696}
Andy Adamsonfc931582009-04-01 09:22:31 -04005697
5698static int decode_chan_attrs(struct xdr_stream *xdr,
5699 struct nfs4_channel_attrs *attrs)
5700{
5701 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005702 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005703
Benny Halevyc0eae662009-08-14 17:20:14 +03005704 p = xdr_inline_decode(xdr, 28);
5705 if (unlikely(!p))
5706 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005707 val = be32_to_cpup(p++); /* headerpadsz */
5708 if (val)
5709 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005710 attrs->max_rqst_sz = be32_to_cpup(p++);
5711 attrs->max_resp_sz = be32_to_cpup(p++);
5712 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5713 attrs->max_ops = be32_to_cpup(p++);
5714 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005715 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005716 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005717 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5718 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005719 return -EINVAL;
5720 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005721 if (nr_attrs == 1) {
5722 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5723 if (unlikely(!p))
5724 goto out_overflow;
5725 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005726 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005727out_overflow:
5728 print_overflow_msg(__func__, xdr);
5729 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005730}
5731
Benny Halevye78291e2009-08-14 17:20:00 +03005732static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5733{
5734 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005735}
5736
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005737static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5738 struct nfs41_bind_conn_to_session_res *res)
5739{
5740 __be32 *p;
5741 int status;
5742
5743 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5744 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005745 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005746 if (unlikely(status))
5747 return status;
5748
5749 /* dir flags, rdma mode bool */
5750 p = xdr_inline_decode(xdr, 8);
5751 if (unlikely(!p))
5752 goto out_overflow;
5753
5754 res->dir = be32_to_cpup(p++);
5755 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5756 return -EIO;
5757 if (be32_to_cpup(p) == 0)
5758 res->use_conn_in_rdma_mode = false;
5759 else
5760 res->use_conn_in_rdma_mode = true;
5761
5762 return 0;
5763out_overflow:
5764 print_overflow_msg(__func__, xdr);
5765 return -EIO;
5766}
5767
Andy Adamsonfc931582009-04-01 09:22:31 -04005768static int decode_create_session(struct xdr_stream *xdr,
5769 struct nfs41_create_session_res *res)
5770{
5771 __be32 *p;
5772 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005773
5774 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005775 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005776 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005777 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005778 return status;
5779
Andy Adamsonfc931582009-04-01 09:22:31 -04005780 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005781 p = xdr_inline_decode(xdr, 8);
5782 if (unlikely(!p))
5783 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005784 res->seqid = be32_to_cpup(p++);
5785 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005786
5787 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005788 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005789 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005790 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005791 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005792out_overflow:
5793 print_overflow_msg(__func__, xdr);
5794 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005795}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005796
5797static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5798{
5799 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5800}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005801
Trond Myklebust66245532012-05-25 17:18:09 -04005802static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5803{
5804 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5805}
5806
Ricardo Labiaga180197532009-12-05 16:08:40 -05005807static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5808{
5809 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5810}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005811#endif /* CONFIG_NFS_V4_1 */
5812
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005813static int decode_sequence(struct xdr_stream *xdr,
5814 struct nfs4_sequence_res *res,
5815 struct rpc_rqst *rqstp)
5816{
5817#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005818 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005819 struct nfs4_sessionid id;
5820 u32 dummy;
5821 int status;
5822 __be32 *p;
5823
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005824 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005825 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005826 if (!res->sr_slot->table->session)
5827 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005828
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005829 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005830 if (!status)
5831 status = decode_sessionid(xdr, &id);
5832 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005833 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005834
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005835 /*
5836 * If the server returns different values for sessionID, slotID or
5837 * sequence number, the server is looney tunes.
5838 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005839 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005840 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005841
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005842 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005843 NFS4_MAX_SESSIONID_LEN)) {
5844 dprintk("%s Invalid session id\n", __func__);
5845 goto out_err;
5846 }
Benny Halevye78291e2009-08-14 17:20:00 +03005847
Benny Halevyc0eae662009-08-14 17:20:14 +03005848 p = xdr_inline_decode(xdr, 20);
5849 if (unlikely(!p))
5850 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005851
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005852 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005853 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005854 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005855 dprintk("%s Invalid sequence number\n", __func__);
5856 goto out_err;
5857 }
5858 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005859 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005860 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005861 dprintk("%s Invalid slot id\n", __func__);
5862 goto out_err;
5863 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005864 /* highest slot id */
5865 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005866 /* target highest slot id */
5867 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005868 /* result flags */
5869 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005870 status = 0;
5871out_err:
5872 res->sr_status = status;
5873 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005874out_overflow:
5875 print_overflow_msg(__func__, xdr);
5876 status = -EIO;
5877 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005878#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005879 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005880#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005881}
5882
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005883#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005884static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5885{
5886 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5887 return decode_stateid(xdr, stateid);
5888}
5889
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005890static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005891 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005892{
Trond Myklebust4e590802015-03-09 14:01:25 -04005893 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005894 __be32 *p;
5895 uint32_t len, type;
5896 int status;
5897
5898 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5899 if (status) {
5900 if (status == -ETOOSMALL) {
5901 p = xdr_inline_decode(xdr, 4);
5902 if (unlikely(!p))
5903 goto out_overflow;
5904 pdev->mincount = be32_to_cpup(p);
5905 dprintk("%s: Min count too small. mincnt = %u\n",
5906 __func__, pdev->mincount);
5907 }
5908 return status;
5909 }
5910
5911 p = xdr_inline_decode(xdr, 8);
5912 if (unlikely(!p))
5913 goto out_overflow;
5914 type = be32_to_cpup(p++);
5915 if (type != pdev->layout_type) {
5916 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5917 __func__, pdev->layout_type, type);
5918 return -EINVAL;
5919 }
5920 /*
5921 * Get the length of the opaque device_addr4. xdr_read_pages places
5922 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5923 * and places the remaining xdr data in xdr_buf->tail
5924 */
5925 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005926 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5927 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005928
5929 /* Parse notification bitmap, verifying that it is zero. */
5930 p = xdr_inline_decode(xdr, 4);
5931 if (unlikely(!p))
5932 goto out_overflow;
5933 len = be32_to_cpup(p);
5934 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005935 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005936
5937 p = xdr_inline_decode(xdr, 4 * len);
5938 if (unlikely(!p))
5939 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005940
Trond Myklebust4e590802015-03-09 14:01:25 -04005941 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005942 for (i = 1; i < len; i++) {
5943 if (be32_to_cpup(p++)) {
5944 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005945 __func__);
5946 return -EIO;
5947 }
5948 }
5949 }
5950 return 0;
5951out_overflow:
5952 print_overflow_msg(__func__, xdr);
5953 return -EIO;
5954}
5955
5956static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5957 struct nfs4_layoutget_res *res)
5958{
5959 __be32 *p;
5960 int status;
5961 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005962 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005963
5964 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5965 if (status)
5966 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005967 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005968 if (unlikely(!p))
5969 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005970 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04005971 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005972 p = xdr_inline_decode(xdr, 4);
5973 if (unlikely(!p))
5974 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005975 layout_count = be32_to_cpup(p);
5976 if (!layout_count) {
5977 dprintk("%s: server responded with empty layout array\n",
5978 __func__);
5979 return -EINVAL;
5980 }
5981
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005982 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005983 if (unlikely(!p))
5984 goto out_overflow;
5985 p = xdr_decode_hyper(p, &res->range.offset);
5986 p = xdr_decode_hyper(p, &res->range.length);
5987 res->range.iomode = be32_to_cpup(p++);
5988 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005989 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005990
5991 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5992 __func__,
5993 (unsigned long)res->range.offset,
5994 (unsigned long)res->range.length,
5995 res->range.iomode,
5996 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005997 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005998
Trond Myklebust64bd5772012-06-20 22:35:05 -04005999 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006000 if (res->layoutp->len > recvd) {
6001 dprintk("NFS: server cheating in layoutget reply: "
6002 "layout len %u > recvd %u\n",
6003 res->layoutp->len, recvd);
6004 return -EINVAL;
6005 }
6006
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006007 if (layout_count > 1) {
6008 /* We only handle a length one array at the moment. Any
6009 * further entries are just ignored. Note that this means
6010 * the client may see a response that is less than the
6011 * minimum it requested.
6012 */
6013 dprintk("%s: server responded with %d layouts, dropping tail\n",
6014 __func__, layout_count);
6015 }
6016
6017 return 0;
6018out_overflow:
6019 print_overflow_msg(__func__, xdr);
6020 return -EIO;
6021}
Andy Adamson863a3c62011-03-23 13:27:54 +00006022
Benny Halevycbe82602011-05-22 19:52:37 +03006023static int decode_layoutreturn(struct xdr_stream *xdr,
6024 struct nfs4_layoutreturn_res *res)
6025{
6026 __be32 *p;
6027 int status;
6028
6029 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6030 if (status)
6031 return status;
6032 p = xdr_inline_decode(xdr, 4);
6033 if (unlikely(!p))
6034 goto out_overflow;
6035 res->lrs_present = be32_to_cpup(p);
6036 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04006037 status = decode_layout_stateid(xdr, &res->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03006038 return status;
6039out_overflow:
6040 print_overflow_msg(__func__, xdr);
6041 return -EIO;
6042}
6043
Andy Adamson863a3c62011-03-23 13:27:54 +00006044static int decode_layoutcommit(struct xdr_stream *xdr,
6045 struct rpc_rqst *req,
6046 struct nfs4_layoutcommit_res *res)
6047{
6048 __be32 *p;
6049 __u32 sizechanged;
6050 int status;
6051
6052 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04006053 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00006054 if (status)
6055 return status;
6056
6057 p = xdr_inline_decode(xdr, 4);
6058 if (unlikely(!p))
6059 goto out_overflow;
6060 sizechanged = be32_to_cpup(p);
6061
6062 if (sizechanged) {
6063 /* throw away new size */
6064 p = xdr_inline_decode(xdr, 8);
6065 if (unlikely(!p))
6066 goto out_overflow;
6067 }
6068 return 0;
6069out_overflow:
6070 print_overflow_msg(__func__, xdr);
6071 return -EIO;
6072}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006073
6074static int decode_test_stateid(struct xdr_stream *xdr,
6075 struct nfs41_test_stateid_res *res)
6076{
6077 __be32 *p;
6078 int status;
6079 int num_res;
6080
6081 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6082 if (status)
6083 return status;
6084
6085 p = xdr_inline_decode(xdr, 4);
6086 if (unlikely(!p))
6087 goto out_overflow;
6088 num_res = be32_to_cpup(p++);
6089 if (num_res != 1)
6090 goto out;
6091
6092 p = xdr_inline_decode(xdr, 4);
6093 if (unlikely(!p))
6094 goto out_overflow;
6095 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006096
6097 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006098out_overflow:
6099 print_overflow_msg(__func__, xdr);
6100out:
6101 return -EIO;
6102}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006103
6104static int decode_free_stateid(struct xdr_stream *xdr,
6105 struct nfs41_free_stateid_res *res)
6106{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006107 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006108 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006109}
Trond Myklebustcf805162016-11-15 14:56:07 -05006110#else
6111static inline
6112int decode_layoutreturn(struct xdr_stream *xdr,
6113 struct nfs4_layoutreturn_res *res)
6114{
6115 return 0;
6116}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006117#endif /* CONFIG_NFS_V4_1 */
6118
Linus Torvalds1da177e2005-04-16 15:20:36 -07006119/*
Benny Halevy49c25592008-12-23 16:06:16 -05006120 * END OF "GENERIC" DECODE ROUTINES.
6121 */
6122
6123/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006124 * Decode OPEN_DOWNGRADE response
6125 */
Chuck Leverbf269552010-12-14 14:59:29 +00006126static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6127 struct xdr_stream *xdr,
6128 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006129{
Andy Adamson05d564f2008-12-23 16:06:15 -05006130 struct compound_hdr hdr;
6131 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006132
Chuck Leverbf269552010-12-14 14:59:29 +00006133 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006134 if (status)
6135 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006137 if (status)
6138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006139 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006140 if (status)
6141 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006142 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006144 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006145}
6146
6147/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006148 * Decode ACCESS response
6149 */
Chuck Leverbf269552010-12-14 14:59:29 +00006150static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6151 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006153 struct compound_hdr hdr;
6154 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006155
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006157 if (status)
6158 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006160 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006161 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006162 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006163 if (status != 0)
6164 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006165 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006166 if (status != 0)
6167 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006168 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169out:
6170 return status;
6171}
6172
6173/*
6174 * Decode LOOKUP response
6175 */
Chuck Leverbf269552010-12-14 14:59:29 +00006176static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6177 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006178{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006179 struct compound_hdr hdr;
6180 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006181
Chuck Leverbf269552010-12-14 14:59:29 +00006182 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006183 if (status)
6184 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006185 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006186 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006188 status = decode_putfh(xdr);
6189 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006190 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006191 status = decode_lookup(xdr);
6192 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006194 status = decode_getfh(xdr, res->fh);
6195 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006197 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198out:
6199 return status;
6200}
6201
6202/*
6203 * Decode LOOKUP_ROOT response
6204 */
Chuck Leverbf269552010-12-14 14:59:29 +00006205static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6206 struct xdr_stream *xdr,
6207 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209 struct compound_hdr hdr;
6210 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006211
Chuck Leverbf269552010-12-14 14:59:29 +00006212 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006213 if (status)
6214 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006215 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006216 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006217 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006218 status = decode_putrootfh(xdr);
6219 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006220 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006221 status = decode_getfh(xdr, res->fh);
6222 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006223 status = decode_getfattr_label(xdr, res->fattr,
6224 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225out:
6226 return status;
6227}
6228
6229/*
6230 * Decode REMOVE response
6231 */
Chuck Leverbf269552010-12-14 14:59:29 +00006232static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6233 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006234{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235 struct compound_hdr hdr;
6236 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006237
Chuck Leverbf269552010-12-14 14:59:29 +00006238 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006239 if (status)
6240 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006241 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006242 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006244 status = decode_putfh(xdr);
6245 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006246 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006247 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248out:
6249 return status;
6250}
6251
6252/*
6253 * Decode RENAME response
6254 */
Chuck Leverbf269552010-12-14 14:59:29 +00006255static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6256 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006257{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006258 struct compound_hdr hdr;
6259 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006260
Chuck Leverbf269552010-12-14 14:59:29 +00006261 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006262 if (status)
6263 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006264 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006265 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006266 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006267 status = decode_putfh(xdr);
6268 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006269 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006270 status = decode_savefh(xdr);
6271 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006272 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006273 status = decode_putfh(xdr);
6274 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006275 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006276 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277out:
6278 return status;
6279}
6280
6281/*
6282 * Decode LINK response
6283 */
Chuck Leverbf269552010-12-14 14:59:29 +00006284static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6285 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006286{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006287 struct compound_hdr hdr;
6288 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006289
Chuck Leverbf269552010-12-14 14:59:29 +00006290 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006291 if (status)
6292 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006293 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006294 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006296 status = decode_putfh(xdr);
6297 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006299 status = decode_savefh(xdr);
6300 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006301 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006302 status = decode_putfh(xdr);
6303 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006304 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006305 status = decode_link(xdr, &res->cinfo);
6306 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006307 goto out;
6308 /*
6309 * Note order: OP_LINK leaves the directory as the current
6310 * filehandle.
6311 */
Chuck Leverbf269552010-12-14 14:59:29 +00006312 status = decode_restorefh(xdr);
6313 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006314 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006315 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006316out:
6317 return status;
6318}
6319
6320/*
6321 * Decode CREATE response
6322 */
Chuck Leverbf269552010-12-14 14:59:29 +00006323static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6324 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006326 struct compound_hdr hdr;
6327 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006328
Chuck Leverbf269552010-12-14 14:59:29 +00006329 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006330 if (status)
6331 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006332 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006333 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006334 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006335 status = decode_putfh(xdr);
6336 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006337 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006338 status = decode_create(xdr, &res->dir_cinfo);
6339 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006340 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006341 status = decode_getfh(xdr, res->fh);
6342 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006343 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006344 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345out:
6346 return status;
6347}
6348
6349/*
6350 * Decode SYMLINK response
6351 */
Chuck Leverbf269552010-12-14 14:59:29 +00006352static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6353 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354{
Chuck Leverbf269552010-12-14 14:59:29 +00006355 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006356}
6357
6358/*
6359 * Decode GETATTR response
6360 */
Chuck Leverbf269552010-12-14 14:59:29 +00006361static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6362 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006363{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364 struct compound_hdr hdr;
6365 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006366
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368 if (status)
6369 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006370 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006371 if (status)
6372 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006373 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006374 if (status)
6375 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006376 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377out:
6378 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006379}
6380
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006381/*
6382 * Encode an SETACL request
6383 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006384static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6385 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006386{
Andy Adamson05d564f2008-12-23 16:06:15 -05006387 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006388 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006389 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006390
Chuck Lever9f06c712010-12-14 14:59:18 +00006391 encode_compound_hdr(xdr, req, &hdr);
6392 encode_sequence(xdr, &args->seq_args, &hdr);
6393 encode_putfh(xdr, args->fh, &hdr);
6394 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006395 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006396}
Andy Adamson05d564f2008-12-23 16:06:15 -05006397
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006398/*
6399 * Decode SETACL response
6400 */
6401static int
Chuck Leverbf269552010-12-14 14:59:29 +00006402nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006403 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006404{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006405 struct compound_hdr hdr;
6406 int status;
6407
Chuck Leverbf269552010-12-14 14:59:29 +00006408 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006409 if (status)
6410 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006411 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006412 if (status)
6413 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006414 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006415 if (status)
6416 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006417 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006418out:
6419 return status;
6420}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006421
6422/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006423 * Decode GETACL response
6424 */
6425static int
Chuck Leverbf269552010-12-14 14:59:29 +00006426nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006427 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006428{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006429 struct compound_hdr hdr;
6430 int status;
6431
Trond Myklebust331818f2012-02-03 18:30:53 -05006432 if (res->acl_scratch != NULL) {
6433 void *p = page_address(res->acl_scratch);
6434 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6435 }
Chuck Leverbf269552010-12-14 14:59:29 +00006436 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006437 if (status)
6438 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006439 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006440 if (status)
6441 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006442 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006443 if (status)
6444 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006445 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006446
6447out:
6448 return status;
6449}
6450
6451/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006452 * Decode CLOSE response
6453 */
Chuck Leverbf269552010-12-14 14:59:29 +00006454static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6455 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006456{
Andy Adamson05d564f2008-12-23 16:06:15 -05006457 struct compound_hdr hdr;
6458 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006459
Chuck Leverbf269552010-12-14 14:59:29 +00006460 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006461 if (status)
6462 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006463 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006464 if (status)
6465 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006466 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006467 if (status)
6468 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006469 if (res->lr_res) {
6470 status = decode_layoutreturn(xdr, res->lr_res);
6471 res->lr_ret = status;
6472 if (status)
6473 goto out;
6474 }
Chuck Leverbf269552010-12-14 14:59:29 +00006475 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006476 if (status != 0)
6477 goto out;
6478 /*
6479 * Note: Server may do delete on close for this file
6480 * in which case the getattr call will fail with
6481 * an ESTALE error. Shouldn't be a problem,
6482 * though, since fattr->valid will remain unset.
6483 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006484 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006486 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006487}
6488
6489/*
6490 * Decode OPEN response
6491 */
Chuck Leverbf269552010-12-14 14:59:29 +00006492static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6493 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006494{
Andy Adamson05d564f2008-12-23 16:06:15 -05006495 struct compound_hdr hdr;
6496 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497
Chuck Leverbf269552010-12-14 14:59:29 +00006498 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006499 if (status)
6500 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006501 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006502 if (status)
6503 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006504 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006505 if (status)
6506 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006507 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006508 if (status)
6509 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006510 status = decode_getfh(xdr, &res->fh);
6511 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006512 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006513 if (res->access_request)
6514 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006515 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006517 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518}
6519
6520/*
6521 * Decode OPEN_CONFIRM response
6522 */
Chuck Leverbf269552010-12-14 14:59:29 +00006523static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6524 struct xdr_stream *xdr,
6525 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006526{
Andy Adamson05d564f2008-12-23 16:06:15 -05006527 struct compound_hdr hdr;
6528 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529
Chuck Leverbf269552010-12-14 14:59:29 +00006530 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006531 if (status)
6532 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006533 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006534 if (status)
6535 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006536 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006537out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006538 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539}
6540
6541/*
6542 * Decode OPEN response
6543 */
Chuck Leverbf269552010-12-14 14:59:29 +00006544static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6545 struct xdr_stream *xdr,
6546 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547{
Andy Adamson05d564f2008-12-23 16:06:15 -05006548 struct compound_hdr hdr;
6549 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006552 if (status)
6553 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006554 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006555 if (status)
6556 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006557 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006558 if (status)
6559 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006560 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006561 if (status)
6562 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006563 if (res->access_request)
6564 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006565 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006566out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006567 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006568}
6569
6570/*
6571 * Decode SETATTR response
6572 */
Chuck Leverbf269552010-12-14 14:59:29 +00006573static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6574 struct xdr_stream *xdr,
6575 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006576{
Andy Adamson05d564f2008-12-23 16:06:15 -05006577 struct compound_hdr hdr;
6578 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006579
Chuck Leverbf269552010-12-14 14:59:29 +00006580 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006581 if (status)
6582 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006583 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006584 if (status)
6585 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006586 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006587 if (status)
6588 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006589 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006590 if (status)
6591 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006592 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006594 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595}
6596
6597/*
6598 * Decode LOCK response
6599 */
Chuck Leverbf269552010-12-14 14:59:29 +00006600static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6601 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006602{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006603 struct compound_hdr hdr;
6604 int status;
6605
Chuck Leverbf269552010-12-14 14:59:29 +00006606 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006607 if (status)
6608 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006609 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006610 if (status)
6611 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006612 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613 if (status)
6614 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006615 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006616out:
6617 return status;
6618}
6619
6620/*
6621 * Decode LOCKT response
6622 */
Chuck Leverbf269552010-12-14 14:59:29 +00006623static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6624 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006625{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006626 struct compound_hdr hdr;
6627 int status;
6628
Chuck Leverbf269552010-12-14 14:59:29 +00006629 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006630 if (status)
6631 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006632 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006633 if (status)
6634 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006635 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636 if (status)
6637 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006638 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006639out:
6640 return status;
6641}
6642
6643/*
6644 * Decode LOCKU response
6645 */
Chuck Leverbf269552010-12-14 14:59:29 +00006646static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6647 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006648{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649 struct compound_hdr hdr;
6650 int status;
6651
Chuck Leverbf269552010-12-14 14:59:29 +00006652 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653 if (status)
6654 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006655 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006656 if (status)
6657 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006658 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006659 if (status)
6660 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006661 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006662out:
6663 return status;
6664}
6665
Chuck Leverbf269552010-12-14 14:59:29 +00006666static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6667 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006668{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006669 struct compound_hdr hdr;
6670 int status;
6671
Chuck Leverbf269552010-12-14 14:59:29 +00006672 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006673 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006674 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006675 return status;
6676}
6677
Linus Torvalds1da177e2005-04-16 15:20:36 -07006678/*
6679 * Decode READLINK response
6680 */
Chuck Leverbf269552010-12-14 14:59:29 +00006681static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6682 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006683 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006684{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006685 struct compound_hdr hdr;
6686 int status;
6687
Chuck Leverbf269552010-12-14 14:59:29 +00006688 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006689 if (status)
6690 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006691 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006692 if (status)
6693 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006694 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006695 if (status)
6696 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006697 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006698out:
6699 return status;
6700}
6701
6702/*
6703 * Decode READDIR response
6704 */
Chuck Leverbf269552010-12-14 14:59:29 +00006705static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6706 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006707{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006708 struct compound_hdr hdr;
6709 int status;
6710
Chuck Leverbf269552010-12-14 14:59:29 +00006711 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712 if (status)
6713 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006714 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006715 if (status)
6716 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006717 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006718 if (status)
6719 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006720 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006721out:
6722 return status;
6723}
6724
6725/*
6726 * Decode Read response
6727 */
Chuck Leverbf269552010-12-14 14:59:29 +00006728static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006729 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006730{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006731 struct compound_hdr hdr;
6732 int status;
6733
Chuck Leverbf269552010-12-14 14:59:29 +00006734 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006735 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736 if (status)
6737 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006738 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006739 if (status)
6740 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006741 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006742 if (status)
6743 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006744 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006745 if (!status)
6746 status = res->count;
6747out:
6748 return status;
6749}
6750
6751/*
6752 * Decode WRITE response
6753 */
Chuck Leverbf269552010-12-14 14:59:29 +00006754static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006755 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006756{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757 struct compound_hdr hdr;
6758 int status;
6759
Chuck Leverbf269552010-12-14 14:59:29 +00006760 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006761 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006762 if (status)
6763 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006764 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006765 if (status)
6766 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006767 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768 if (status)
6769 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006770 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006771 if (status)
6772 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006773 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006774 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006775 if (!status)
6776 status = res->count;
6777out:
6778 return status;
6779}
6780
6781/*
6782 * Decode COMMIT response
6783 */
Chuck Leverbf269552010-12-14 14:59:29 +00006784static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006785 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006786{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006787 struct compound_hdr hdr;
6788 int status;
6789
Chuck Leverbf269552010-12-14 14:59:29 +00006790 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006791 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006792 if (status)
6793 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006794 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006795 if (status)
6796 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006797 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006798 if (status)
6799 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006800 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006801out:
6802 return status;
6803}
6804
6805/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006806 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006807 */
Chuck Leverbf269552010-12-14 14:59:29 +00006808static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006809 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006810{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006811 struct compound_hdr hdr;
6812 int status;
6813
Chuck Leverbf269552010-12-14 14:59:29 +00006814 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006815 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006816 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006817 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006818 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006819 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006820 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006821 return status;
6822}
6823
6824/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006825 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006826 */
Chuck Leverbf269552010-12-14 14:59:29 +00006827static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006828 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006829{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006830 struct compound_hdr hdr;
6831 int status;
6832
Chuck Leverbf269552010-12-14 14:59:29 +00006833 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006834 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006835 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006836 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006837 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006838 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006839 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006840 return status;
6841}
6842
6843/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006844 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006845 */
Chuck Leverbf269552010-12-14 14:59:29 +00006846static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006847 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006848{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006849 struct compound_hdr hdr;
6850 int status;
6851
Chuck Leverbf269552010-12-14 14:59:29 +00006852 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006853 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006854 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006855 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006856 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006857 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006858 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006859 return status;
6860}
6861
6862/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006863 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006864 */
Chuck Leverbf269552010-12-14 14:59:29 +00006865static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6866 struct xdr_stream *xdr,
6867 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006868{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006869 struct compound_hdr hdr;
6870 int status;
6871
Chuck Leverbf269552010-12-14 14:59:29 +00006872 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006873 if (status)
6874 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006875 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006876 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006877 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006878 status = decode_putfh(xdr);
6879 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006880 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006881 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006882out:
6883 return status;
6884}
6885
6886/*
6887 * Decode RENEW response
6888 */
Chuck Leverbf269552010-12-14 14:59:29 +00006889static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6890 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006891{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006892 struct compound_hdr hdr;
6893 int status;
6894
Chuck Leverbf269552010-12-14 14:59:29 +00006895 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006896 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006897 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006898 return status;
6899}
6900
6901/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006902 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006903 */
Chuck Leverbf269552010-12-14 14:59:29 +00006904static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6905 struct xdr_stream *xdr,
6906 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006907{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006908 struct compound_hdr hdr;
6909 int status;
6910
Chuck Leverbf269552010-12-14 14:59:29 +00006911 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006912 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006913 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006914 return status;
6915}
6916
6917/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006918 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006919 */
Chuck Leverbf269552010-12-14 14:59:29 +00006920static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006921 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006922{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006923 struct compound_hdr hdr;
6924 int status;
6925
Chuck Leverbf269552010-12-14 14:59:29 +00006926 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006927 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006928 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006929 return status;
6930}
6931
6932/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006933 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006934 */
Chuck Leverbf269552010-12-14 14:59:29 +00006935static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6936 struct xdr_stream *xdr,
6937 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006938{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006939 struct compound_hdr hdr;
6940 int status;
6941
Chuck Leverbf269552010-12-14 14:59:29 +00006942 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006943 if (status)
6944 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006945 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006946 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006947 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006948 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006949 if (status != 0)
6950 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05006951 if (res->lr_res) {
6952 status = decode_layoutreturn(xdr, res->lr_res);
6953 res->lr_ret = status;
6954 if (status)
6955 goto out;
6956 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006957 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006958 if (status != 0)
6959 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006960 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006961out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006962 return status;
6963}
6964
Trond Myklebust683b57b2006-06-09 09:34:22 -04006965/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006966 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006967 */
Chuck Leverbf269552010-12-14 14:59:29 +00006968static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6969 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006970 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006971{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006972 struct compound_hdr hdr;
6973 int status;
6974
Chuck Leverbf269552010-12-14 14:59:29 +00006975 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006976 if (status)
6977 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006978 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006979 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006980 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006981 status = decode_putfh(xdr);
6982 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006983 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006984 if (res->migration) {
6985 xdr_enter_page(xdr, PAGE_SIZE);
6986 status = decode_getfattr_generic(xdr,
6987 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006988 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006989 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006990 if (status)
6991 goto out;
6992 if (res->renew)
6993 status = decode_renew(xdr);
6994 } else {
6995 status = decode_lookup(xdr);
6996 if (status)
6997 goto out;
6998 xdr_enter_page(xdr, PAGE_SIZE);
6999 status = decode_getfattr_generic(xdr,
7000 &res->fs_locations->fattr,
7001 NULL, res->fs_locations,
7002 NULL, res->fs_locations->server);
7003 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04007004out:
7005 return status;
7006}
7007
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007008/*
7009 * Decode SECINFO response
7010 */
7011static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7012 struct xdr_stream *xdr,
7013 struct nfs4_secinfo_res *res)
7014{
7015 struct compound_hdr hdr;
7016 int status;
7017
7018 status = decode_compound_hdr(xdr, &hdr);
7019 if (status)
7020 goto out;
7021 status = decode_sequence(xdr, &res->seq_res, rqstp);
7022 if (status)
7023 goto out;
7024 status = decode_putfh(xdr);
7025 if (status)
7026 goto out;
7027 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007028out:
7029 return status;
7030}
7031
Chuck Lever44c99932013-10-17 14:13:30 -04007032/*
7033 * Decode FSID_PRESENT response
7034 */
7035static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7036 struct xdr_stream *xdr,
7037 struct nfs4_fsid_present_res *res)
7038{
7039 struct compound_hdr hdr;
7040 int status;
7041
7042 status = decode_compound_hdr(xdr, &hdr);
7043 if (status)
7044 goto out;
7045 status = decode_sequence(xdr, &res->seq_res, rqstp);
7046 if (status)
7047 goto out;
7048 status = decode_putfh(xdr);
7049 if (status)
7050 goto out;
7051 status = decode_getfh(xdr, res->fh);
7052 if (status)
7053 goto out;
7054 if (res->renew)
7055 status = decode_renew(xdr);
7056out:
7057 return status;
7058}
7059
Benny Halevy99fe60d2009-04-01 09:22:29 -04007060#if defined(CONFIG_NFS_V4_1)
7061/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007062 * Decode BIND_CONN_TO_SESSION response
7063 */
7064static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7065 struct xdr_stream *xdr,
7066 void *res)
7067{
7068 struct compound_hdr hdr;
7069 int status;
7070
7071 status = decode_compound_hdr(xdr, &hdr);
7072 if (!status)
7073 status = decode_bind_conn_to_session(xdr, res);
7074 return status;
7075}
7076
7077/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007078 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007079 */
Chuck Leverbf269552010-12-14 14:59:29 +00007080static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7081 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007082 void *res)
7083{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007084 struct compound_hdr hdr;
7085 int status;
7086
Chuck Leverbf269552010-12-14 14:59:29 +00007087 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007088 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007089 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007090 return status;
7091}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007092
7093/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007094 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007095 */
Chuck Leverbf269552010-12-14 14:59:29 +00007096static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7097 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04007098 struct nfs41_create_session_res *res)
7099{
Andy Adamsonfc931582009-04-01 09:22:31 -04007100 struct compound_hdr hdr;
7101 int status;
7102
Chuck Leverbf269552010-12-14 14:59:29 +00007103 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007104 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007105 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007106 return status;
7107}
7108
7109/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007110 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007111 */
Chuck Leverbf269552010-12-14 14:59:29 +00007112static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7113 struct xdr_stream *xdr,
7114 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007115{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007116 struct compound_hdr hdr;
7117 int status;
7118
Chuck Leverbf269552010-12-14 14:59:29 +00007119 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007120 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007121 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007122 return status;
7123}
7124
7125/*
Trond Myklebust66245532012-05-25 17:18:09 -04007126 * Decode DESTROY_CLIENTID response
7127 */
7128static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7129 struct xdr_stream *xdr,
7130 void *res)
7131{
7132 struct compound_hdr hdr;
7133 int status;
7134
7135 status = decode_compound_hdr(xdr, &hdr);
7136 if (!status)
7137 status = decode_destroy_clientid(xdr, res);
7138 return status;
7139}
7140
7141/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007142 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007143 */
Chuck Leverbf269552010-12-14 14:59:29 +00007144static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7145 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007146 struct nfs4_sequence_res *res)
7147{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007148 struct compound_hdr hdr;
7149 int status;
7150
Chuck Leverbf269552010-12-14 14:59:29 +00007151 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007152 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007153 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007154 return status;
7155}
7156
7157/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007158 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007159 */
Chuck Leverbf269552010-12-14 14:59:29 +00007160static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7161 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04007162 struct nfs4_get_lease_time_res *res)
7163{
Andy Adamson2050f0c2009-04-01 09:22:30 -04007164 struct compound_hdr hdr;
7165 int status;
7166
Chuck Leverbf269552010-12-14 14:59:29 +00007167 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007168 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007169 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007170 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007171 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007172 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007173 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007174 return status;
7175}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007176
7177/*
7178 * Decode RECLAIM_COMPLETE response
7179 */
Chuck Leverbf269552010-12-14 14:59:29 +00007180static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7181 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007182 struct nfs41_reclaim_complete_res *res)
7183{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007184 struct compound_hdr hdr;
7185 int status;
7186
Chuck Leverbf269552010-12-14 14:59:29 +00007187 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007188 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007189 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007190 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307191 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007192 return status;
7193}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007194
7195/*
7196 * Decode GETDEVINFO response
7197 */
Chuck Leverbf269552010-12-14 14:59:29 +00007198static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7199 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007200 struct nfs4_getdeviceinfo_res *res)
7201{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007202 struct compound_hdr hdr;
7203 int status;
7204
Chuck Leverbf269552010-12-14 14:59:29 +00007205 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007206 if (status != 0)
7207 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007208 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007209 if (status != 0)
7210 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007211 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007212out:
7213 return status;
7214}
7215
7216/*
7217 * Decode LAYOUTGET response
7218 */
Chuck Leverbf269552010-12-14 14:59:29 +00007219static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7220 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007221 struct nfs4_layoutget_res *res)
7222{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007223 struct compound_hdr hdr;
7224 int status;
7225
Chuck Leverbf269552010-12-14 14:59:29 +00007226 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007227 if (status)
7228 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007229 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007230 if (status)
7231 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007232 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007233 if (status)
7234 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007235 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007236out:
7237 return status;
7238}
Andy Adamson863a3c62011-03-23 13:27:54 +00007239
7240/*
Benny Halevycbe82602011-05-22 19:52:37 +03007241 * Decode LAYOUTRETURN response
7242 */
7243static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7244 struct xdr_stream *xdr,
7245 struct nfs4_layoutreturn_res *res)
7246{
7247 struct compound_hdr hdr;
7248 int status;
7249
7250 status = decode_compound_hdr(xdr, &hdr);
7251 if (status)
7252 goto out;
7253 status = decode_sequence(xdr, &res->seq_res, rqstp);
7254 if (status)
7255 goto out;
7256 status = decode_putfh(xdr);
7257 if (status)
7258 goto out;
7259 status = decode_layoutreturn(xdr, res);
7260out:
7261 return status;
7262}
7263
7264/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007265 * Decode LAYOUTCOMMIT response
7266 */
7267static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7268 struct xdr_stream *xdr,
7269 struct nfs4_layoutcommit_res *res)
7270{
7271 struct compound_hdr hdr;
7272 int status;
7273
7274 status = decode_compound_hdr(xdr, &hdr);
7275 if (status)
7276 goto out;
7277 status = decode_sequence(xdr, &res->seq_res, rqstp);
7278 if (status)
7279 goto out;
7280 status = decode_putfh(xdr);
7281 if (status)
7282 goto out;
7283 status = decode_layoutcommit(xdr, rqstp, res);
7284 if (status)
7285 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007286 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007287out:
7288 return status;
7289}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007290
7291/*
7292 * Decode SECINFO_NO_NAME response
7293 */
7294static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7295 struct xdr_stream *xdr,
7296 struct nfs4_secinfo_res *res)
7297{
7298 struct compound_hdr hdr;
7299 int status;
7300
7301 status = decode_compound_hdr(xdr, &hdr);
7302 if (status)
7303 goto out;
7304 status = decode_sequence(xdr, &res->seq_res, rqstp);
7305 if (status)
7306 goto out;
7307 status = decode_putrootfh(xdr);
7308 if (status)
7309 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007310 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007311out:
7312 return status;
7313}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007314
7315/*
7316 * Decode TEST_STATEID response
7317 */
7318static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7319 struct xdr_stream *xdr,
7320 struct nfs41_test_stateid_res *res)
7321{
7322 struct compound_hdr hdr;
7323 int status;
7324
7325 status = decode_compound_hdr(xdr, &hdr);
7326 if (status)
7327 goto out;
7328 status = decode_sequence(xdr, &res->seq_res, rqstp);
7329 if (status)
7330 goto out;
7331 status = decode_test_stateid(xdr, res);
7332out:
7333 return status;
7334}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007335
7336/*
7337 * Decode FREE_STATEID response
7338 */
7339static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7340 struct xdr_stream *xdr,
7341 struct nfs41_free_stateid_res *res)
7342{
7343 struct compound_hdr hdr;
7344 int status;
7345
7346 status = decode_compound_hdr(xdr, &hdr);
7347 if (status)
7348 goto out;
7349 status = decode_sequence(xdr, &res->seq_res, rqstp);
7350 if (status)
7351 goto out;
7352 status = decode_free_stateid(xdr, res);
7353out:
7354 return status;
7355}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007356#endif /* CONFIG_NFS_V4_1 */
7357
Chuck Lever573c4e12010-12-14 14:58:11 +00007358/**
7359 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7360 * the local page cache.
7361 * @xdr: XDR stream where entry resides
7362 * @entry: buffer to fill in with entry data
7363 * @plus: boolean indicating whether this should be a readdirplus entry
7364 *
7365 * Returns zero if successful, otherwise a negative errno value is
7366 * returned.
7367 *
7368 * This function is not invoked during READDIR reply decoding, but
7369 * rather whenever an application invokes the getdents(2) system call
7370 * on a directory already in our cache.
7371 */
7372int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7373 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007374{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007375 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007376 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007377 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007378 __be32 *p = xdr_inline_decode(xdr, 4);
7379 if (unlikely(!p))
7380 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007381 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007382 p = xdr_inline_decode(xdr, 4);
7383 if (unlikely(!p))
7384 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007385 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007386 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007387 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007388 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007389 }
7390
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007391 p = xdr_inline_decode(xdr, 12);
7392 if (unlikely(!p))
7393 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007394 entry->prev_cookie = entry->cookie;
7395 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007396 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007397
Trond Myklebust9af8c222010-10-24 11:52:55 -04007398 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007399 if (unlikely(!p))
7400 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007401 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007402
7403 /*
7404 * In case the server doesn't return an inode number,
7405 * we fake one here. (We don't use inode number 0,
7406 * since glibc seems to choke on it...)
7407 */
7408 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007409 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007410
Trond Myklebust9af8c222010-10-24 11:52:55 -04007411 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007412 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007413
Trond Myklebust256e48b2012-06-21 11:18:13 -04007414 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007415 goto out_overflow;
7416
Chuck Lever573c4e12010-12-14 14:58:11 +00007417 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007418 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007419 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007420 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7421 entry->ino = entry->fattr->mounted_on_fileid;
7422 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007423 entry->ino = entry->fattr->fileid;
7424
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007425 entry->d_type = DT_UNKNOWN;
7426 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7427 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7428
Chuck Lever573c4e12010-12-14 14:58:11 +00007429 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007430
7431out_overflow:
7432 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007433 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007434}
7435
7436/*
7437 * We need to translate between nfs status return values and
7438 * the local errno values which may not be the same.
7439 */
7440static struct {
7441 int stat;
7442 int errno;
7443} nfs_errtbl[] = {
7444 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007445 { NFS4ERR_PERM, -EPERM },
7446 { NFS4ERR_NOENT, -ENOENT },
7447 { NFS4ERR_IO, -errno_NFSERR_IO},
7448 { NFS4ERR_NXIO, -ENXIO },
7449 { NFS4ERR_ACCESS, -EACCES },
7450 { NFS4ERR_EXIST, -EEXIST },
7451 { NFS4ERR_XDEV, -EXDEV },
7452 { NFS4ERR_NOTDIR, -ENOTDIR },
7453 { NFS4ERR_ISDIR, -EISDIR },
7454 { NFS4ERR_INVAL, -EINVAL },
7455 { NFS4ERR_FBIG, -EFBIG },
7456 { NFS4ERR_NOSPC, -ENOSPC },
7457 { NFS4ERR_ROFS, -EROFS },
7458 { NFS4ERR_MLINK, -EMLINK },
7459 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7460 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7461 { NFS4ERR_DQUOT, -EDQUOT },
7462 { NFS4ERR_STALE, -ESTALE },
7463 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007464 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7465 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7466 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007467 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007468 { NFS4ERR_BADTYPE, -EBADTYPE },
7469 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007470 { NFS4ERR_SYMLINK, -ELOOP },
7471 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7472 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007473 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007474};
7475
7476/*
7477 * Convert an NFS error code to a local one.
7478 * This one is used jointly by NFSv2 and NFSv3.
7479 */
7480static int
David Howells0a8ea432006-08-22 20:06:08 -04007481nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007482{
7483 int i;
7484 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7485 if (nfs_errtbl[i].stat == stat)
7486 return nfs_errtbl[i].errno;
7487 }
7488 if (stat <= 10000 || stat > 10100) {
7489 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007490 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007491 }
7492 /* If we cannot translate the error, the recovery routines should
7493 * handle it.
7494 * Note: remaining NFSv4 error codes have values > 10000, so should
7495 * not conflict with native Linux error codes.
7496 */
Benny Halevy856dff32008-03-31 17:39:06 +03007497 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007498}
7499
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007500#ifdef CONFIG_NFS_V4_2
7501#include "nfs42xdr.c"
7502#endif /* CONFIG_NFS_V4_2 */
7503
Linus Torvalds1da177e2005-04-16 15:20:36 -07007504#define PROC(proc, argtype, restype) \
7505[NFSPROC4_CLNT_##proc] = { \
7506 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007507 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007508 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007509 .p_arglen = NFS4_##argtype##_sz, \
7510 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007511 .p_statidx = NFSPROC4_CLNT_##proc, \
7512 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007513}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007514
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007515#define STUB(proc) \
7516[NFSPROC4_CLNT_##proc] = { \
7517 .p_name = #proc, \
7518}
7519
Linus Torvalds1da177e2005-04-16 15:20:36 -07007520struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007521 PROC(READ, enc_read, dec_read),
7522 PROC(WRITE, enc_write, dec_write),
7523 PROC(COMMIT, enc_commit, dec_commit),
7524 PROC(OPEN, enc_open, dec_open),
7525 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7526 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7527 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7528 PROC(CLOSE, enc_close, dec_close),
7529 PROC(SETATTR, enc_setattr, dec_setattr),
7530 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7531 PROC(RENEW, enc_renew, dec_renew),
7532 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7533 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7534 PROC(LOCK, enc_lock, dec_lock),
7535 PROC(LOCKT, enc_lockt, dec_lockt),
7536 PROC(LOCKU, enc_locku, dec_locku),
7537 PROC(ACCESS, enc_access, dec_access),
7538 PROC(GETATTR, enc_getattr, dec_getattr),
7539 PROC(LOOKUP, enc_lookup, dec_lookup),
7540 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7541 PROC(REMOVE, enc_remove, dec_remove),
7542 PROC(RENAME, enc_rename, dec_rename),
7543 PROC(LINK, enc_link, dec_link),
7544 PROC(SYMLINK, enc_symlink, dec_symlink),
7545 PROC(CREATE, enc_create, dec_create),
7546 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7547 PROC(STATFS, enc_statfs, dec_statfs),
7548 PROC(READLINK, enc_readlink, dec_readlink),
7549 PROC(READDIR, enc_readdir, dec_readdir),
7550 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7551 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7552 PROC(GETACL, enc_getacl, dec_getacl),
7553 PROC(SETACL, enc_setacl, dec_setacl),
7554 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7555 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007556 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007557 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007558#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007559 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7560 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7561 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7562 PROC(SEQUENCE, enc_sequence, dec_sequence),
7563 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7564 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7565 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7566 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007567 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007568 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007569 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007570 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007571 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007572 STUB(GETDEVICELIST),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007573 PROC(BIND_CONN_TO_SESSION,
7574 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007575 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007576#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007577#ifdef CONFIG_NFS_V4_2
7578 PROC(SEEK, enc_seek, dec_seek),
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007579 PROC(ALLOCATE, enc_allocate, dec_allocate),
Anna Schumaker624bd5b2014-11-25 13:18:16 -05007580 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
Trond Myklebustbe3a5d22015-06-23 19:51:55 +08007581 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
Peng Tao36022772015-09-26 02:24:34 +08007582 PROC(CLONE, enc_clone, dec_clone),
Anna Schumaker2e724482013-05-21 16:53:03 -04007583 PROC(COPY, enc_copy, dec_copy),
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007584#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007585};
7586
Trond Myklebusta613fa12012-01-20 13:53:56 -05007587const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007588 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007589 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007590 .procs = nfs4_procedures
7591};
7592
7593/*
7594 * Local variables:
7595 * c-basic-offset: 8
7596 * End:
7597 */