blob: 0a82b3fb2d27026e4ddb00a543d8b998d9d2f4bc [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
418#endif /* CONFIG_NFS_V4_1 */
419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
421#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
422#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400423 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400425 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400429 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400431 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400433 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400435 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400437 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400439 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400441 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400443 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400445 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400447 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400449 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400450 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400452 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400454 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400455 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400457 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400459 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400461 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400463 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400465 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400466 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400467 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400468 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400469 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400470 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400472 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400473 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400474 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400475 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400477 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400478#define NFS4_enc_open_confirm_sz \
479 (compound_encode_hdr_maxsz + \
480 encode_putfh_maxsz + \
481 encode_open_confirm_maxsz)
482#define NFS4_dec_open_confirm_sz \
483 (compound_decode_hdr_maxsz + \
484 decode_putfh_maxsz + \
485 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400487 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400489 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400490 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400491 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400493 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400495 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400496 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400497 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498#define NFS4_enc_open_downgrade_sz \
499 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400500 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400501 encode_putfh_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400502 encode_open_downgrade_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#define NFS4_dec_open_downgrade_sz \
504 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400505 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400506 decode_putfh_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400507 decode_open_downgrade_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400508#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400509 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400510 encode_putfh_maxsz + \
511 encode_close_maxsz + \
512 encode_getattr_maxsz)
513#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400514 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400515 decode_putfh_maxsz + \
516 decode_close_maxsz + \
517 decode_getattr_maxsz)
518#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400519 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400520 encode_putfh_maxsz + \
521 encode_setattr_maxsz + \
522 encode_getattr_maxsz)
523#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400524 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400525 decode_putfh_maxsz + \
526 decode_setattr_maxsz + \
527 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400529 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 encode_putfh_maxsz + \
531 encode_fsinfo_maxsz)
532#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400533 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 decode_putfh_maxsz + \
535 decode_fsinfo_maxsz)
536#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
537 encode_renew_maxsz)
538#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
539 decode_renew_maxsz)
540#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
541 encode_setclientid_maxsz)
542#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
543 decode_setclientid_maxsz)
544#define NFS4_enc_setclientid_confirm_sz \
545 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400546 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547#define NFS4_dec_setclientid_confirm_sz \
548 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400549 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400551 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400553 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400555 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400557 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400559 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400561 encode_lockt_maxsz)
562#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400563 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400564 decode_putfh_maxsz + \
565 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400567 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400569 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400571 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400573 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400574#define NFS4_enc_release_lockowner_sz \
575 (compound_encode_hdr_maxsz + \
576 encode_lockowner_maxsz)
577#define NFS4_dec_release_lockowner_sz \
578 (compound_decode_hdr_maxsz + \
579 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400581 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400583 encode_access_maxsz + \
584 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400588 decode_access_maxsz + \
589 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400591 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400593 encode_getattr_maxsz + \
594 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400598 decode_getattr_maxsz + \
599 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 encode_putfh_maxsz + \
603 encode_lookup_maxsz + \
604 encode_getattr_maxsz + \
605 encode_getfh_maxsz)
606#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400607 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400609 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 decode_getattr_maxsz + \
611 decode_getfh_maxsz)
612#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400613 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 encode_putrootfh_maxsz + \
615 encode_getattr_maxsz + \
616 encode_getfh_maxsz)
617#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400618 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 decode_putrootfh_maxsz + \
620 decode_getattr_maxsz + \
621 decode_getfh_maxsz)
622#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400623 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400625 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400627 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400629 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400631 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 encode_putfh_maxsz + \
633 encode_savefh_maxsz + \
634 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400635 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400637 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 decode_putfh_maxsz + \
639 decode_savefh_maxsz + \
640 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400641 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400643 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 encode_putfh_maxsz + \
645 encode_savefh_maxsz + \
646 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400647 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400648 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400649 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400651 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 decode_putfh_maxsz + \
653 decode_savefh_maxsz + \
654 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400655 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400656 decode_restorefh_maxsz + \
657 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400659 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 encode_putfh_maxsz + \
661 encode_symlink_maxsz + \
662 encode_getattr_maxsz + \
663 encode_getfh_maxsz)
664#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400665 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 decode_putfh_maxsz + \
667 decode_symlink_maxsz + \
668 decode_getattr_maxsz + \
669 decode_getfh_maxsz)
670#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400671 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 encode_putfh_maxsz + \
673 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400674 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400675 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400677 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 decode_putfh_maxsz + \
679 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400680 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400681 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400683 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 encode_putfh_maxsz + \
685 encode_getattr_maxsz)
686#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400687 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 decode_putfh_maxsz + \
689 decode_getattr_maxsz)
690#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400691 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400693 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400695 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400697 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400699 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800700 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 encode_getattr_maxsz)
702#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400703 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800704 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 decode_getattr_maxsz)
706#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400707 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100709 encode_delegreturn_maxsz + \
710 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400712 decode_sequence_maxsz + \
Trond Myklebustd8434d4c2016-11-16 13:54:00 -0500713 decode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100714 decode_delegreturn_maxsz + \
715 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000716#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000718 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400719 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000720#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400721 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000722 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400723 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000724#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400725 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000726 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400727 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000728#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400729 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000730 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400731 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400732#define NFS4_enc_fs_locations_sz \
733 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400734 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400735 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400736 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400737 encode_fs_locations_maxsz + \
738 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400739#define NFS4_dec_fs_locations_sz \
740 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400741 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400742 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400743 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400744 decode_fs_locations_maxsz + \
745 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000746#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
747 encode_sequence_maxsz + \
748 encode_putfh_maxsz + \
749 encode_secinfo_maxsz)
750#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
751 decode_sequence_maxsz + \
752 decode_putfh_maxsz + \
753 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400754#define NFS4_enc_fsid_present_sz \
755 (compound_encode_hdr_maxsz + \
756 encode_sequence_maxsz + \
757 encode_putfh_maxsz + \
758 encode_getfh_maxsz + \
759 encode_renew_maxsz)
760#define NFS4_dec_fsid_present_sz \
761 (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz + \
763 decode_putfh_maxsz + \
764 decode_getfh_maxsz + \
765 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400766#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400767#define NFS4_enc_bind_conn_to_session_sz \
768 (compound_encode_hdr_maxsz + \
769 encode_bind_conn_to_session_maxsz)
770#define NFS4_dec_bind_conn_to_session_sz \
771 (compound_decode_hdr_maxsz + \
772 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400773#define NFS4_enc_exchange_id_sz \
774 (compound_encode_hdr_maxsz + \
775 encode_exchange_id_maxsz)
776#define NFS4_dec_exchange_id_sz \
777 (compound_decode_hdr_maxsz + \
778 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400779#define NFS4_enc_create_session_sz \
780 (compound_encode_hdr_maxsz + \
781 encode_create_session_maxsz)
782#define NFS4_dec_create_session_sz \
783 (compound_decode_hdr_maxsz + \
784 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400785#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
786 encode_destroy_session_maxsz)
787#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
788 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400789#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
790 encode_destroy_clientid_maxsz)
791#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
792 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400793#define NFS4_enc_sequence_sz \
794 (compound_decode_hdr_maxsz + \
795 encode_sequence_maxsz)
796#define NFS4_dec_sequence_sz \
797 (compound_decode_hdr_maxsz + \
798 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400799#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
800 encode_sequence_maxsz + \
801 encode_putrootfh_maxsz + \
802 encode_fsinfo_maxsz)
803#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
804 decode_sequence_maxsz + \
805 decode_putrootfh_maxsz + \
806 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500807#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
808 encode_sequence_maxsz + \
809 encode_reclaim_complete_maxsz)
810#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
811 decode_sequence_maxsz + \
812 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400813#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
814 encode_sequence_maxsz +\
815 encode_getdeviceinfo_maxsz)
816#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
817 decode_sequence_maxsz + \
818 decode_getdeviceinfo_maxsz)
819#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
820 encode_sequence_maxsz + \
821 encode_putfh_maxsz + \
822 encode_layoutget_maxsz)
823#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
824 decode_sequence_maxsz + \
825 decode_putfh_maxsz + \
826 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000827#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
828 encode_sequence_maxsz +\
829 encode_putfh_maxsz + \
830 encode_layoutcommit_maxsz + \
831 encode_getattr_maxsz)
832#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
833 decode_sequence_maxsz + \
834 decode_putfh_maxsz + \
835 decode_layoutcommit_maxsz + \
836 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300837#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
838 encode_sequence_maxsz + \
839 encode_putfh_maxsz + \
840 encode_layoutreturn_maxsz)
841#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
842 decode_sequence_maxsz + \
843 decode_putfh_maxsz + \
844 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400845#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
846 encode_sequence_maxsz + \
847 encode_putrootfh_maxsz +\
848 encode_secinfo_no_name_maxsz)
849#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
850 decode_sequence_maxsz + \
851 decode_putrootfh_maxsz + \
852 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400853#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
854 encode_sequence_maxsz + \
855 encode_test_stateid_maxsz)
856#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
857 decode_sequence_maxsz + \
858 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400859#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
860 encode_sequence_maxsz + \
861 encode_free_stateid_maxsz)
862#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
863 decode_sequence_maxsz + \
864 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500865
866const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
867 compound_encode_hdr_maxsz +
868 encode_sequence_maxsz +
869 encode_putfh_maxsz +
870 encode_getattr_maxsz) *
871 XDR_UNIT);
872
873const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
874 compound_decode_hdr_maxsz +
875 decode_sequence_maxsz +
876 decode_putfh_maxsz) *
877 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400878
879const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
880 compound_decode_hdr_maxsz +
881 decode_sequence_maxsz) *
882 XDR_UNIT);
883EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400884#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Trond Myklebustbca79472009-03-11 14:10:26 -0400886static const umode_t nfs_type2fmt[] = {
887 [NF4BAD] = 0,
888 [NF4REG] = S_IFREG,
889 [NF4DIR] = S_IFDIR,
890 [NF4BLK] = S_IFBLK,
891 [NF4CHR] = S_IFCHR,
892 [NF4LNK] = S_IFLNK,
893 [NF4SOCK] = S_IFSOCK,
894 [NF4FIFO] = S_IFIFO,
895 [NF4ATTRDIR] = 0,
896 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897};
898
899struct compound_hdr {
900 int32_t status;
901 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500902 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 uint32_t taglen;
904 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400905 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400906 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907};
908
Benny Halevy13c65ce2009-08-14 17:19:25 +0300909static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
910{
911 __be32 *p = xdr_reserve_space(xdr, nbytes);
912 BUG_ON(!p);
913 return p;
914}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Trond Myklebustcb17e552012-03-04 18:13:56 -0500916static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
917{
918 __be32 *p;
919
920 p = xdr_reserve_space(xdr, len);
921 xdr_encode_opaque_fixed(p, buf, len);
922}
923
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
925{
Al Viro8687b632006-10-19 23:28:48 -0700926 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500928 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 xdr_encode_opaque(p, str, len);
930}
931
Trond Myklebust4ade9822012-03-04 18:13:57 -0500932static void encode_uint32(struct xdr_stream *xdr, u32 n)
933{
934 __be32 *p;
935
936 p = reserve_space(xdr, 4);
937 *p = cpu_to_be32(n);
938}
939
Trond Myklebustff2eb682012-03-05 11:40:12 -0500940static void encode_uint64(struct xdr_stream *xdr, u64 n)
941{
942 __be32 *p;
943
944 p = reserve_space(xdr, 8);
945 xdr_encode_hyper(p, n);
946}
947
Trond Myklebust4ade9822012-03-04 18:13:57 -0500948static void encode_nfs4_seqid(struct xdr_stream *xdr,
949 const struct nfs_seqid *seqid)
950{
Trond Myklebusta6796412015-01-23 19:04:44 -0500951 if (seqid != NULL)
952 encode_uint32(xdr, seqid->sequence->counter);
953 else
954 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500955}
956
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400957static void encode_compound_hdr(struct xdr_stream *xdr,
958 struct rpc_rqst *req,
959 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960{
Al Viro8687b632006-10-19 23:28:48 -0700961 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400962 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400963
964 /* initialize running count of expected bytes in reply.
965 * NOTE: the replied tag SHOULD be the same is the one sent,
966 * but this is not required as a MUST for the server to do so. */
967 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
Trond Myklebust7fc38842012-10-15 11:51:21 -0400969 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500970 encode_string(xdr, hdr->taglen, hdr->tag);
971 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300972 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500973 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300974 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500975}
976
Trond Myklebustab19b482012-03-04 18:13:57 -0500977static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
978 uint32_t replen,
979 struct compound_hdr *hdr)
980{
981 encode_uint32(xdr, op);
982 hdr->nops++;
983 hdr->replen += replen;
984}
985
Andy Adamsond0179312008-12-23 16:06:17 -0500986static void encode_nops(struct compound_hdr *hdr)
987{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400988 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500989 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990}
991
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500992static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
993{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500994 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500995}
996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
998{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500999 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000}
1001
David Quigleyaa9c2662013-05-22 12:50:44 -04001002static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1003 const struct nfs4_label *label,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001004 const struct nfs_server *server,
1005 bool excl_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006{
1007 char owner_name[IDMAP_NAMESZ];
1008 char owner_group[IDMAP_NAMESZ];
1009 int owner_namelen = 0;
1010 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001011 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001012 unsigned i;
1013 uint32_t len = 0;
1014 uint32_t bmval_len;
1015 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
1017 /*
1018 * We reserve enough space to write the entire attribute buffer at once.
1019 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001020 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1021 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001022 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001024 if (iap->ia_valid & ATTR_SIZE) {
1025 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001027 }
1028 if (iap->ia_valid & ATTR_MODE) {
1029 bmval[1] |= FATTR4_WORD1_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 len += 4;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001031 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001033 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001035 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001036 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 /* XXX */
1038 strcpy(owner_name, "nobody");
1039 owner_namelen = sizeof("nobody") - 1;
1040 /* goto out; */
1041 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001042 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1044 }
1045 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001046 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001048 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001049 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 strcpy(owner_group, "nobody");
1051 owner_grouplen = sizeof("nobody") - 1;
1052 /* goto out; */
1053 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001054 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1056 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001058 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1059 len += 16;
1060 } else if (iap->ia_valid & ATTR_ATIME) {
1061 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1062 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 }
1064 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001065 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1066 len += 16;
1067 } else if (iap->ia_valid & ATTR_MTIME) {
1068 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1069 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001071
1072 if (excl_check) {
1073 const u32 *excl_bmval = server->exclcreat_bitmask;
1074 bmval[0] &= excl_bmval[0];
1075 bmval[1] &= excl_bmval[1];
1076 bmval[2] &= excl_bmval[2];
1077
1078 if (!(excl_bmval[2] & FATTR4_WORD2_SECURITY_LABEL))
1079 label = NULL;
1080 }
1081
David Quigleyaa9c2662013-05-22 12:50:44 -04001082 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001083 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1084 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1085 }
1086
1087 if (bmval[2] != 0)
1088 bmval_len = 3;
1089 else if (bmval[1] != 0)
1090 bmval_len = 2;
1091 else
1092 bmval_len = 1;
1093
1094 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1095
1096 *p++ = cpu_to_be32(bmval_len);
1097 for (i = 0; i < bmval_len; i++)
1098 *p++ = cpu_to_be32(bmval[i]);
1099 *p++ = cpu_to_be32(len);
1100
1101 if (bmval[0] & FATTR4_WORD0_SIZE)
1102 p = xdr_encode_hyper(p, iap->ia_size);
1103 if (bmval[1] & FATTR4_WORD1_MODE)
1104 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1105 if (bmval[1] & FATTR4_WORD1_OWNER)
1106 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1107 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1108 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1109 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1110 if (iap->ia_valid & ATTR_ATIME_SET) {
1111 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1112 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1113 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1114 } else
1115 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1116 }
1117 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1118 if (iap->ia_valid & ATTR_MTIME_SET) {
1119 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1120 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1121 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1122 } else
1123 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1124 }
1125 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001126 *p++ = cpu_to_be32(label->lfs);
1127 *p++ = cpu_to_be32(label->pi);
1128 *p++ = cpu_to_be32(label->len);
1129 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1130 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001131
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133}
1134
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001135static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001137 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1138 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001141static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Trond Myklebustab19b482012-03-04 18:13:57 -05001143 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001144 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001145 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146}
1147
Fred Isaman0b7c0152012-04-20 14:47:39 -04001148static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149{
Al Viro8687b632006-10-19 23:28:48 -07001150 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001151
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001152 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1153 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001154 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001155 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156}
1157
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001158static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159{
Al Viro8687b632006-10-19 23:28:48 -07001160 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001161
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001162 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1163 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
1165 switch (create->ftype) {
1166 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001167 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001168 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001169 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1170 create->u.symlink.len);
1171 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 break;
1173
1174 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001175 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001176 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001177 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 break;
1179
1180 default:
1181 break;
1182 }
1183
Benny Halevy811652b2009-08-14 17:19:34 +03001184 encode_string(xdr, create->name->len, create->name->name);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001185 encode_attrs(xdr, create->attrs, create->label, create->server, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186}
1187
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001188static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189{
Andy Adamson05d564f2008-12-23 16:06:15 -05001190 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001192 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1193 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001194 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001195 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196}
1197
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001198static 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 -07001199{
Andy Adamson05d564f2008-12-23 16:06:15 -05001200 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001202 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1203 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001204 *p++ = cpu_to_be32(2);
1205 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001206 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207}
1208
Fred Isamandae100c2011-07-30 20:52:37 -04001209static void
1210encode_getattr_three(struct xdr_stream *xdr,
1211 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1212 struct compound_hdr *hdr)
1213{
1214 __be32 *p;
1215
Trond Myklebustab19b482012-03-04 18:13:57 -05001216 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001217 if (bm2) {
1218 p = reserve_space(xdr, 16);
1219 *p++ = cpu_to_be32(3);
1220 *p++ = cpu_to_be32(bm0);
1221 *p++ = cpu_to_be32(bm1);
1222 *p = cpu_to_be32(bm2);
1223 } else if (bm1) {
1224 p = reserve_space(xdr, 12);
1225 *p++ = cpu_to_be32(2);
1226 *p++ = cpu_to_be32(bm0);
1227 *p = cpu_to_be32(bm1);
1228 } else {
1229 p = reserve_space(xdr, 8);
1230 *p++ = cpu_to_be32(1);
1231 *p = cpu_to_be32(bm0);
1232 }
Fred Isamandae100c2011-07-30 20:52:37 -04001233}
1234
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001235static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236{
David Quigleya09df2c2013-05-22 12:50:41 -04001237 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1238 bitmask[1] & nfs4_fattr_bitmap[1],
1239 bitmask[2] & nfs4_fattr_bitmap[2],
1240 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241}
1242
Andy Adamson88034c32012-05-23 05:02:34 -04001243static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001244 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001245 struct compound_hdr *hdr)
1246{
1247 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001248 bitmask[0] & open_bitmap[0],
1249 bitmask[1] & open_bitmap[1],
1250 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001251 hdr);
1252}
1253
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001254static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255{
Fred Isamandae100c2011-07-30 20:52:37 -04001256 encode_getattr_three(xdr,
1257 bitmask[0] & nfs4_fsinfo_bitmap[0],
1258 bitmask[1] & nfs4_fsinfo_bitmap[1],
1259 bitmask[2] & nfs4_fsinfo_bitmap[2],
1260 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261}
1262
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001263static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001264{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001265 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1266 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001267}
1268
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001269static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270{
Trond Myklebustab19b482012-03-04 18:13:57 -05001271 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272}
1273
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001274static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275{
Trond Myklebustab19b482012-03-04 18:13:57 -05001276 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001277 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278}
1279
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001280static inline int nfs4_lock_type(struct file_lock *fl, int block)
1281{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001282 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001283 return block ? NFS4_READW_LT : NFS4_READ_LT;
1284 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1285}
1286
1287static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1288{
1289 if (fl->fl_end == OFFSET_MAX)
1290 return ~(uint64_t)0;
1291 return fl->fl_end - fl->fl_start + 1;
1292}
1293
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001294static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1295{
1296 __be32 *p;
1297
Trond Myklebustd035c362010-12-21 10:45:27 -05001298 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001299 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001300 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001301 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001302 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001303 xdr_encode_hyper(p, lowner->id);
1304}
1305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306/*
1307 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1308 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1309 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001310static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311{
Al Viro8687b632006-10-19 23:28:48 -07001312 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001314 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1315 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001316 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1317 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001318 p = xdr_encode_hyper(p, args->fl->fl_start);
1319 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001320 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001321 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001322 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001323 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001324 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001325 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 }
1327 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001328 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001329 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331}
1332
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001333static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334{
Al Viro8687b632006-10-19 23:28:48 -07001335 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001337 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1338 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001339 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001340 p = xdr_encode_hyper(p, args->fl->fl_start);
1341 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001342 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343}
1344
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001345static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346{
Al Viro8687b632006-10-19 23:28:48 -07001347 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001349 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1350 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001351 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001352 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001353 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001354 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001355 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356}
1357
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001358static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1359{
Trond Myklebustab19b482012-03-04 18:13:57 -05001360 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001361 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001362}
1363
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001364static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365{
Trond Myklebustab19b482012-03-04 18:13:57 -05001366 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001367 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368}
1369
Trond Myklebust6ae37332015-01-30 14:21:14 -05001370static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371{
Al Viro8687b632006-10-19 23:28:48 -07001372 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
Benny Halevy13c65ce2009-08-14 17:19:25 +03001374 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001375 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001376 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377}
1378
1379static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1380{
Al Viro8687b632006-10-19 23:28:48 -07001381 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 /*
1383 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1384 * owner 4 = 32
1385 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001386 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001387 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001388 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001389 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001390 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001391 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001392 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001393 *p++ = cpu_to_be32(arg->id.uniquifier);
1394 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395}
1396
1397static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1398{
Al Viro8687b632006-10-19 23:28:48 -07001399 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Benny Halevy13c65ce2009-08-14 17:19:25 +03001401 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001402 switch(arg->createmode) {
1403 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001404 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001405 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false);
Andy Adamson05d564f2008-12-23 16:06:15 -05001406 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001407 case NFS4_CREATE_GUARDED:
1408 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001409 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001410 break;
1411 case NFS4_CREATE_EXCLUSIVE:
1412 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1413 encode_nfs4_verifier(xdr, &arg->u.verifier);
1414 break;
1415 case NFS4_CREATE_EXCLUSIVE4_1:
1416 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1417 encode_nfs4_verifier(xdr, &arg->u.verifier);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001418 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 }
1420}
1421
1422static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1423{
Al Viro8687b632006-10-19 23:28:48 -07001424 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
Benny Halevy13c65ce2009-08-14 17:19:25 +03001426 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001428 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001429 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001430 break;
1431 default:
Benny Halevy34558512009-08-14 17:19:30 +03001432 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001433 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 }
1435}
1436
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001437static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438{
Al Viro8687b632006-10-19 23:28:48 -07001439 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Benny Halevy13c65ce2009-08-14 17:19:25 +03001441 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001443 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001444 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001445 break;
1446 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001447 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001448 break;
1449 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001450 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001451 break;
1452 default:
1453 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 }
1455}
1456
1457static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1458{
Al Viro8687b632006-10-19 23:28:48 -07001459 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
Benny Halevy13c65ce2009-08-14 17:19:25 +03001461 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001462 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 encode_string(xdr, name->len, name->name);
1464}
1465
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001466static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
Al Viro8687b632006-10-19 23:28:48 -07001468 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Benny Halevy13c65ce2009-08-14 17:19:25 +03001470 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001471 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 encode_delegation_type(xdr, type);
1473}
1474
1475static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1476{
Al Viro8687b632006-10-19 23:28:48 -07001477 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001479 p = reserve_space(xdr, 4);
1480 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1481 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 encode_string(xdr, name->len, name->name);
1483}
1484
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001485static inline void encode_claim_fh(struct xdr_stream *xdr)
1486{
1487 __be32 *p;
1488
1489 p = reserve_space(xdr, 4);
1490 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1491}
1492
1493static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1494{
1495 __be32 *p;
1496
1497 p = reserve_space(xdr, 4);
1498 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1499 encode_nfs4_stateid(xdr, stateid);
1500}
1501
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001502static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503{
Trond Myklebustab19b482012-03-04 18:13:57 -05001504 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 encode_openhdr(xdr, arg);
1506 encode_opentype(xdr, arg);
1507 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001508 case NFS4_OPEN_CLAIM_NULL:
1509 encode_claim_null(xdr, arg->name);
1510 break;
1511 case NFS4_OPEN_CLAIM_PREVIOUS:
1512 encode_claim_previous(xdr, arg->u.delegation_type);
1513 break;
1514 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1515 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1516 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001517 case NFS4_OPEN_CLAIM_FH:
1518 encode_claim_fh(xdr);
1519 break;
1520 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1521 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1522 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001523 default:
1524 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526}
1527
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001528static 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 -07001529{
Trond Myklebustab19b482012-03-04 18:13:57 -05001530 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001531 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001532 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533}
1534
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001535static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536{
Trond Myklebustab19b482012-03-04 18:13:57 -05001537 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001538 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001539 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001540 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541}
1542
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001543static void
Andy Adamsond0179312008-12-23 16:06:17 -05001544encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545{
Trond Myklebustab19b482012-03-04 18:13:57 -05001546 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001547 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548}
1549
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001550static void encode_putrootfh(struct xdr_stream *xdr, 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_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553}
1554
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001555static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1556 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
Al Viro8687b632006-10-19 23:28:48 -07001558 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
Trond Myklebustab19b482012-03-04 18:13:57 -05001560 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001561 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
Benny Halevy13c65ce2009-08-14 17:19:25 +03001563 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001564 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001565 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566}
1567
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001568static 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 -07001569{
David Quigleyaa9c2662013-05-22 12:50:44 -04001570 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001571 FATTR4_WORD0_RDATTR_ERROR,
1572 FATTR4_WORD1_MOUNTED_ON_FILEID,
1573 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001574 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001575 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001576 uint32_t attrlen = 0;
1577 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001579 if (readdir->plus) {
1580 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001581 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001582 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1583 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1584 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1585 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001586 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001587 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001588 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001589 /* Use mounted_on_fileid only if the server supports it */
1590 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1591 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001592 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1593 attrs[i] &= readdir->bitmask[i];
1594 if (attrs[i] != 0)
1595 attrlen = i+1;
1596 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001597
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001598 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001599 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001600 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001601 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001602 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001603 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001604 *p++ = cpu_to_be32(attrlen);
1605 for (i = 0; i < attrlen; i++)
1606 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001607 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001608
1609 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001610 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001611 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001612 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001613 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001614 attrs[1] & readdir->bitmask[1],
1615 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616}
1617
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001618static 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 -07001619{
Trond Myklebustab19b482012-03-04 18:13:57 -05001620 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621}
1622
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001623static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624{
Trond Myklebustab19b482012-03-04 18:13:57 -05001625 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001626 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627}
1628
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001629static 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 -07001630{
Trond Myklebustab19b482012-03-04 18:13:57 -05001631 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001632 encode_string(xdr, oldname->len, oldname->name);
1633 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634}
1635
Chuck Leverbb4dae52012-03-01 17:01:48 -05001636static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1637 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001639 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001640 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641}
1642
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001643static void
Andy Adamsond0179312008-12-23 16:06:17 -05001644encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001645{
Trond Myklebustab19b482012-03-04 18:13:57 -05001646 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001647}
1648
Chuck Lever9f06c712010-12-14 14:59:18 +00001649static void
Andy Adamsond0179312008-12-23 16:06:17 -05001650encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001651{
Al Viro8687b632006-10-19 23:28:48 -07001652 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001653
Trond Myklebustab19b482012-03-04 18:13:57 -05001654 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001655 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001656 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001657 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001658 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001659 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001660 *p = cpu_to_be32(arg->acl_len);
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01001661 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001662}
1663
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001664static void
Andy Adamsond0179312008-12-23 16:06:17 -05001665encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666{
Trond Myklebustab19b482012-03-04 18:13:57 -05001667 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668}
1669
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001670static 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 -07001671{
Trond Myklebustab19b482012-03-04 18:13:57 -05001672 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001673 encode_nfs4_stateid(xdr, &arg->stateid);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001674 encode_attrs(xdr, arg->iap, arg->label, server, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675}
1676
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001677static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678{
Al Viro8687b632006-10-19 23:28:48 -07001679 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
Trond Myklebust70019512012-03-04 20:49:32 -05001681 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001682 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683
Jeff Layton3a6bb732015-06-09 19:43:57 -04001684 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1685 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001686 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001687 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1689 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001690 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001691 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692}
1693
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001694static 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 -07001695{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001696 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1697 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001698 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001699 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700}
1701
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001702static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1703 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704{
Al Viro8687b632006-10-19 23:28:48 -07001705 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Trond Myklebustab19b482012-03-04 18:13:57 -05001707 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001708 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
Benny Halevy13c65ce2009-08-14 17:19:25 +03001710 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001711 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001712 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001713 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714
1715 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716}
1717
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001718static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719{
Trond Myklebustab19b482012-03-04 18:13:57 -05001720 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001721 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001723
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001724static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1725{
Trond Myklebustab19b482012-03-04 18:13:57 -05001726 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001727 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001728}
1729
Benny Halevy99fe60d2009-04-01 09:22:29 -04001730#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001731/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001732static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08001733 struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001734 struct compound_hdr *hdr)
1735{
1736 __be32 *p;
1737
1738 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1739 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001740 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001741 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001742 *p++ = cpu_to_be32(args->dir);
1743 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001744}
1745
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001746static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1747{
1748 unsigned int i;
1749 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1750 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1751 encode_uint32(xdr, op_map->u.words[i]);
1752}
1753
Benny Halevy99fe60d2009-04-01 09:22:29 -04001754static void encode_exchange_id(struct xdr_stream *xdr,
1755 struct nfs41_exchange_id_args *args,
1756 struct compound_hdr *hdr)
1757{
1758 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001759 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001760 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001761
Trond Myklebust70019512012-03-04 20:49:32 -05001762 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001763 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001764
Jeff Layton3a6bb732015-06-09 19:43:57 -04001765 encode_string(xdr, strlen(args->client->cl_owner_id),
1766 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001767
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001768 encode_uint32(xdr, args->flags);
1769 encode_uint32(xdr, args->state_protect.how);
1770
1771 switch (args->state_protect.how) {
1772 case SP4_NONE:
1773 break;
1774 case SP4_MACH_CRED:
1775 encode_op_map(xdr, &args->state_protect.enforce);
1776 encode_op_map(xdr, &args->state_protect.allow);
1777 break;
1778 default:
1779 WARN_ON_ONCE(1);
1780 break;
1781 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001782
1783 if (send_implementation_id &&
1784 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1785 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001786 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001787 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1788 utsname()->sysname, utsname()->release,
1789 utsname()->version, utsname()->machine);
1790
1791 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001792 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001793
1794 encode_string(xdr,
1795 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1796 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1797 encode_string(xdr, len, impl_name);
1798 /* just send zeros for nii_date - the date is in nii_name */
1799 p = reserve_space(xdr, 12);
1800 p = xdr_encode_hyper(p, 0);
1801 *p = cpu_to_be32(0);
1802 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001803 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001804}
Andy Adamsonfc931582009-04-01 09:22:31 -04001805
1806static void encode_create_session(struct xdr_stream *xdr,
1807 struct nfs41_create_session_args *args,
1808 struct compound_hdr *hdr)
1809{
1810 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001811 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001812 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001813 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001814 u32 max_resp_sz_cached;
1815
1816 /*
1817 * Assumes OPEN is the biggest non-idempotent compound.
1818 * 2 is the verifier.
1819 */
1820 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1821 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001822
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001823 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001824 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001825 p = xdr_encode_hyper(p, args->clientid);
1826 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001827 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001828
Andy Adamsonfc931582009-04-01 09:22:31 -04001829 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001830 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001831 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1832 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001833 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001834 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1835 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1836 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001837
1838 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001839 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001840 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1841 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1842 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1843 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1844 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1845 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001846
Benny Halevye75bc1c2009-08-14 17:18:54 +03001847 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001848 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001849 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001850
1851 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001852 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001853 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001854 *p++ = cpu_to_be32(0); /* UID */
1855 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001856 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001857}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001858
1859static void encode_destroy_session(struct xdr_stream *xdr,
1860 struct nfs4_session *session,
1861 struct compound_hdr *hdr)
1862{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001863 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1864 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001865}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001866
Trond Myklebust66245532012-05-25 17:18:09 -04001867static void encode_destroy_clientid(struct xdr_stream *xdr,
1868 uint64_t clientid,
1869 struct compound_hdr *hdr)
1870{
1871 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1872 encode_uint64(xdr, clientid);
1873}
1874
Ricardo Labiaga180197532009-12-05 16:08:40 -05001875static void encode_reclaim_complete(struct xdr_stream *xdr,
1876 struct nfs41_reclaim_complete_args *args,
1877 struct compound_hdr *hdr)
1878{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001879 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1880 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001881}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001882#endif /* CONFIG_NFS_V4_1 */
1883
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001884static void encode_sequence(struct xdr_stream *xdr,
1885 const struct nfs4_sequence_args *args,
1886 struct compound_hdr *hdr)
1887{
1888#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001889 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001890 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001891 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001892 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001893
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001894 tp = slot->table;
1895 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001896 if (!session)
1897 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001898
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001899 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001900
1901 /*
1902 * Sessionid + seqid + slotid + max slotid + cache_this
1903 */
1904 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1905 "max_slotid=%d cache_this=%d\n",
1906 __func__,
1907 ((u32 *)session->sess_id.data)[0],
1908 ((u32 *)session->sess_id.data)[1],
1909 ((u32 *)session->sess_id.data)[2],
1910 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001911 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001912 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001913 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001914 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001915 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001916 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001917 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001918 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001919#endif /* CONFIG_NFS_V4_1 */
1920}
1921
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001922#ifdef CONFIG_NFS_V4_1
1923static void
1924encode_getdeviceinfo(struct xdr_stream *xdr,
1925 const struct nfs4_getdeviceinfo_args *args,
1926 struct compound_hdr *hdr)
1927{
1928 __be32 *p;
1929
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001930 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001931 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001932 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1933 NFS4_DEVICEID4_SIZE);
1934 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001935 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001936
1937 p = reserve_space(xdr, 4 + 4);
1938 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001939 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001940}
1941
1942static void
1943encode_layoutget(struct xdr_stream *xdr,
1944 const struct nfs4_layoutget_args *args,
1945 struct compound_hdr *hdr)
1946{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001947 __be32 *p;
1948
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001949 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1950 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001951 *p++ = cpu_to_be32(0); /* Signal layout available */
1952 *p++ = cpu_to_be32(args->type);
1953 *p++ = cpu_to_be32(args->range.iomode);
1954 p = xdr_encode_hyper(p, args->range.offset);
1955 p = xdr_encode_hyper(p, args->range.length);
1956 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001957 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001958 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001959
1960 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1961 __func__,
1962 args->type,
1963 args->range.iomode,
1964 (unsigned long)args->range.offset,
1965 (unsigned long)args->range.length,
1966 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001967}
Andy Adamson863a3c62011-03-23 13:27:54 +00001968
1969static int
1970encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001971 struct inode *inode,
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001972 struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001973 struct compound_hdr *hdr)
1974{
1975 __be32 *p;
1976
1977 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1978 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1979
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001980 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1981 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001982 /* Only whole file layouts */
1983 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001984 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001985 *p = cpu_to_be32(0); /* reclaim */
1986 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04001987 if (args->lastbytewritten != U64_MAX) {
1988 p = reserve_space(xdr, 20);
1989 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1990 p = xdr_encode_hyper(p, args->lastbytewritten);
1991 } else {
1992 p = reserve_space(xdr, 12);
1993 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
1994 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001995 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1996 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001997
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001998 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
Benny Halevyac7db722011-05-22 19:53:48 +03001999 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2000 NFS_I(inode)->layout, xdr, args);
Christoph Hellwig5f919c92014-08-21 11:09:25 -05002001 } else {
2002 encode_uint32(xdr, args->layoutupdate_len);
2003 if (args->layoutupdate_pages) {
2004 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2005 args->layoutupdate_len);
2006 }
2007 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002008
Andy Adamson863a3c62011-03-23 13:27:54 +00002009 return 0;
2010}
Benny Halevycbe82602011-05-22 19:52:37 +03002011
2012static void
2013encode_layoutreturn(struct xdr_stream *xdr,
2014 const struct nfs4_layoutreturn_args *args,
2015 struct compound_hdr *hdr)
2016{
Trond Myklebust94e5c572016-09-15 18:49:52 -04002017 const struct pnfs_layoutdriver_type *lr_ops = NFS_SERVER(args->inode)->pnfs_curr_ld;
Benny Halevycbe82602011-05-22 19:52:37 +03002018 __be32 *p;
2019
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002020 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2021 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002022 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2023 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002024 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002025 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002026 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002027 p = xdr_encode_hyper(p, args->range.offset);
2028 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002029 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002030 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002031 spin_unlock(&args->inode->i_lock);
Trond Myklebust94e5c572016-09-15 18:49:52 -04002032 if (lr_ops->encode_layoutreturn)
2033 lr_ops->encode_layoutreturn(xdr, args);
2034 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002035 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002036}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002037
2038static int
2039encode_secinfo_no_name(struct xdr_stream *xdr,
2040 const struct nfs41_secinfo_no_name_args *args,
2041 struct compound_hdr *hdr)
2042{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002043 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2044 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002045 return 0;
2046}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002047
2048static void encode_test_stateid(struct xdr_stream *xdr,
2049 struct nfs41_test_stateid_args *args,
2050 struct compound_hdr *hdr)
2051{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002052 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2053 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002054 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002055}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002056
2057static void encode_free_stateid(struct xdr_stream *xdr,
2058 struct nfs41_free_stateid_args *args,
2059 struct compound_hdr *hdr)
2060{
Trond Myklebustab19b482012-03-04 18:13:57 -05002061 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002062 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002063}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002064#endif /* CONFIG_NFS_V4_1 */
2065
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066/*
2067 * END OF "GENERIC" ENCODE ROUTINES.
2068 */
2069
Benny Halevy66cc0422009-04-01 09:22:10 -04002070static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2071{
2072#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002073 struct nfs4_session *session = args->sa_slot->table->session;
2074 if (session)
2075 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002076#endif /* CONFIG_NFS_V4_1 */
2077 return 0;
2078}
2079
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080/*
2081 * Encode an ACCESS request
2082 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002083static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2084 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002087 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089
Chuck Lever9f06c712010-12-14 14:59:18 +00002090 encode_compound_hdr(xdr, req, &hdr);
2091 encode_sequence(xdr, &args->seq_args, &hdr);
2092 encode_putfh(xdr, args->fh, &hdr);
2093 encode_access(xdr, args->access, &hdr);
2094 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002095 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096}
2097
2098/*
2099 * Encode LOOKUP request
2100 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002101static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2102 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002105 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
Chuck Lever9f06c712010-12-14 14:59:18 +00002108 encode_compound_hdr(xdr, req, &hdr);
2109 encode_sequence(xdr, &args->seq_args, &hdr);
2110 encode_putfh(xdr, args->dir_fh, &hdr);
2111 encode_lookup(xdr, args->name, &hdr);
2112 encode_getfh(xdr, &hdr);
2113 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002114 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115}
2116
2117/*
2118 * Encode LOOKUP_ROOT request
2119 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002120static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2121 struct xdr_stream *xdr,
2122 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002125 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127
Chuck Lever9f06c712010-12-14 14:59:18 +00002128 encode_compound_hdr(xdr, req, &hdr);
2129 encode_sequence(xdr, &args->seq_args, &hdr);
2130 encode_putrootfh(xdr, &hdr);
2131 encode_getfh(xdr, &hdr);
2132 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002133 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134}
2135
2136/*
2137 * Encode REMOVE request
2138 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002139static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2140 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002143 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145
Chuck Lever9f06c712010-12-14 14:59:18 +00002146 encode_compound_hdr(xdr, req, &hdr);
2147 encode_sequence(xdr, &args->seq_args, &hdr);
2148 encode_putfh(xdr, args->fh, &hdr);
2149 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002150 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151}
2152
2153/*
2154 * Encode RENAME request
2155 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002156static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2157 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002160 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
Chuck Lever9f06c712010-12-14 14:59:18 +00002163 encode_compound_hdr(xdr, req, &hdr);
2164 encode_sequence(xdr, &args->seq_args, &hdr);
2165 encode_putfh(xdr, args->old_dir, &hdr);
2166 encode_savefh(xdr, &hdr);
2167 encode_putfh(xdr, args->new_dir, &hdr);
2168 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002169 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170}
2171
2172/*
2173 * Encode LINK request
2174 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002175static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2176 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002179 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
Chuck Lever9f06c712010-12-14 14:59:18 +00002182 encode_compound_hdr(xdr, req, &hdr);
2183 encode_sequence(xdr, &args->seq_args, &hdr);
2184 encode_putfh(xdr, args->fh, &hdr);
2185 encode_savefh(xdr, &hdr);
2186 encode_putfh(xdr, args->dir_fh, &hdr);
2187 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002188 encode_restorefh(xdr, &hdr);
2189 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002190 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191}
2192
2193/*
2194 * Encode CREATE request
2195 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002196static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2197 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002200 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
Chuck Lever9f06c712010-12-14 14:59:18 +00002203 encode_compound_hdr(xdr, req, &hdr);
2204 encode_sequence(xdr, &args->seq_args, &hdr);
2205 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002206 encode_create(xdr, args, &hdr);
2207 encode_getfh(xdr, &hdr);
2208 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002209 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210}
2211
2212/*
2213 * Encode SYMLINK request
2214 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002215static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2216 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217{
Chuck Lever9f06c712010-12-14 14:59:18 +00002218 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219}
2220
2221/*
2222 * Encode GETATTR request
2223 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002224static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2225 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002228 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
Chuck Lever9f06c712010-12-14 14:59:18 +00002231 encode_compound_hdr(xdr, req, &hdr);
2232 encode_sequence(xdr, &args->seq_args, &hdr);
2233 encode_putfh(xdr, args->fh, &hdr);
2234 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002235 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236}
2237
2238/*
2239 * Encode a CLOSE request
2240 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002241static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2242 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243{
Andy Adamson05d564f2008-12-23 16:06:15 -05002244 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002245 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002246 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247
Chuck Lever9f06c712010-12-14 14:59:18 +00002248 encode_compound_hdr(xdr, req, &hdr);
2249 encode_sequence(xdr, &args->seq_args, &hdr);
2250 encode_putfh(xdr, args->fh, &hdr);
2251 encode_close(xdr, args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002252 if (args->bitmask != NULL)
2253 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002254 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255}
2256
2257/*
2258 * Encode an OPEN request
2259 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002260static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2261 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002264 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
Chuck Lever9f06c712010-12-14 14:59:18 +00002267 encode_compound_hdr(xdr, req, &hdr);
2268 encode_sequence(xdr, &args->seq_args, &hdr);
2269 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002270 encode_open(xdr, args, &hdr);
2271 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002272 if (args->access)
2273 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002274 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002275 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276}
2277
2278/*
2279 * Encode an OPEN_CONFIRM request
2280 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002281static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2282 struct xdr_stream *xdr,
2283 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002286 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288
Chuck Lever9f06c712010-12-14 14:59:18 +00002289 encode_compound_hdr(xdr, req, &hdr);
2290 encode_putfh(xdr, args->fh, &hdr);
2291 encode_open_confirm(xdr, args, &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 request with no attributes.
2297 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002298static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2299 struct xdr_stream *xdr,
2300 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002303 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
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_sequence(xdr, &args->seq_args, &hdr);
2308 encode_putfh(xdr, args->fh, &hdr);
2309 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002310 if (args->access)
2311 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002312 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002313 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314}
2315
2316/*
2317 * Encode an OPEN_DOWNGRADE request
2318 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002319static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2320 struct xdr_stream *xdr,
2321 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002324 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326
Chuck Lever9f06c712010-12-14 14:59:18 +00002327 encode_compound_hdr(xdr, req, &hdr);
2328 encode_sequence(xdr, &args->seq_args, &hdr);
2329 encode_putfh(xdr, args->fh, &hdr);
2330 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002331 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332}
2333
2334/*
2335 * Encode a LOCK request
2336 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002337static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2338 struct nfs_lock_args *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_lock(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 LOCKT request
2353 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002354static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2355 struct nfs_lockt_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_lockt(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 LOCKU request
2370 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002371static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2372 struct nfs_locku_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_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002382 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383}
2384
Chuck Lever9f06c712010-12-14 14:59:18 +00002385static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2386 struct xdr_stream *xdr,
2387 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002388{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002389 struct compound_hdr hdr = {
2390 .minorversion = 0,
2391 };
2392
Chuck Lever9f06c712010-12-14 14:59:18 +00002393 encode_compound_hdr(xdr, req, &hdr);
2394 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002395 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002396}
2397
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398/*
2399 * Encode a READLINK request
2400 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002401static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2402 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002405 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407
Chuck Lever9f06c712010-12-14 14:59:18 +00002408 encode_compound_hdr(xdr, req, &hdr);
2409 encode_sequence(xdr, &args->seq_args, &hdr);
2410 encode_putfh(xdr, args->fh, &hdr);
2411 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002412
Benny Halevy28f56692009-04-01 09:22:09 -04002413 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002414 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002415 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416}
2417
2418/*
2419 * Encode a READDIR request
2420 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002421static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2422 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002425 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
Chuck Lever9f06c712010-12-14 14:59:18 +00002428 encode_compound_hdr(xdr, req, &hdr);
2429 encode_sequence(xdr, &args->seq_args, &hdr);
2430 encode_putfh(xdr, args->fh, &hdr);
2431 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002432
Benny Halevy28f56692009-04-01 09:22:09 -04002433 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002434 args->pgbase, args->count);
2435 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002436 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002437 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002438 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439}
2440
2441/*
2442 * Encode a READ request
2443 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002444static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002445 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002448 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
Chuck Lever9f06c712010-12-14 14:59:18 +00002451 encode_compound_hdr(xdr, req, &hdr);
2452 encode_sequence(xdr, &args->seq_args, &hdr);
2453 encode_putfh(xdr, args->fh, &hdr);
2454 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455
Benny Halevy28f56692009-04-01 09:22:09 -04002456 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002458 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002459 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460}
2461
2462/*
2463 * Encode an SETATTR request
2464 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002465static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2466 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467{
Andy Adamson05d564f2008-12-23 16:06:15 -05002468 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002469 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002470 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
Chuck Lever9f06c712010-12-14 14:59:18 +00002472 encode_compound_hdr(xdr, req, &hdr);
2473 encode_sequence(xdr, &args->seq_args, &hdr);
2474 encode_putfh(xdr, args->fh, &hdr);
2475 encode_setattr(xdr, args, args->server, &hdr);
2476 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002477 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478}
2479
2480/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002481 * Encode a GETACL request
2482 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002483static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2484 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002485{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002486 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002487 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002488 };
Benny Halevy28f56692009-04-01 09:22:09 -04002489 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002490
Chuck Lever9f06c712010-12-14 14:59:18 +00002491 encode_compound_hdr(xdr, req, &hdr);
2492 encode_sequence(xdr, &args->seq_args, &hdr);
2493 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002494 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002495 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002496
Benny Halevy28f56692009-04-01 09:22:09 -04002497 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01002498 args->acl_pages, 0, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002499
Andy Adamsond0179312008-12-23 16:06:17 -05002500 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002501}
2502
2503/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 * Encode a WRITE request
2505 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002506static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002507 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002510 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512
Chuck Lever9f06c712010-12-14 14:59:18 +00002513 encode_compound_hdr(xdr, req, &hdr);
2514 encode_sequence(xdr, &args->seq_args, &hdr);
2515 encode_putfh(xdr, args->fh, &hdr);
2516 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002517 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002518 if (args->bitmask)
2519 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002520 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521}
2522
2523/*
2524 * a COMMIT request
2525 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002526static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002527 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002530 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
Chuck Lever9f06c712010-12-14 14:59:18 +00002533 encode_compound_hdr(xdr, req, &hdr);
2534 encode_sequence(xdr, &args->seq_args, &hdr);
2535 encode_putfh(xdr, args->fh, &hdr);
2536 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002537 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538}
2539
2540/*
2541 * FSINFO request
2542 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002543static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2544 struct nfs4_fsinfo_arg *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_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002554 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555}
2556
2557/*
2558 * a PATHCONF request
2559 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002560static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2561 const struct nfs4_pathconf_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_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002571 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002572 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573}
2574
2575/*
2576 * a STATFS request
2577 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002578static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2579 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002582 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584
Chuck Lever9f06c712010-12-14 14:59:18 +00002585 encode_compound_hdr(xdr, req, &hdr);
2586 encode_sequence(xdr, &args->seq_args, &hdr);
2587 encode_putfh(xdr, args->fh, &hdr);
2588 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002589 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002590 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591}
2592
2593/*
2594 * GETATTR_BITMAP request
2595 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002596static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2597 struct xdr_stream *xdr,
2598 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599{
Kinglong Mee8c612822015-08-26 21:12:58 +08002600 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002602 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604
Chuck Lever9f06c712010-12-14 14:59:18 +00002605 encode_compound_hdr(xdr, req, &hdr);
2606 encode_sequence(xdr, &args->seq_args, &hdr);
2607 encode_putfh(xdr, args->fhandle, &hdr);
Kinglong Mee8c612822015-08-26 21:12:58 +08002608 encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002609 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610}
2611
2612/*
2613 * a RENEW request
2614 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002615static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2616 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002619 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 };
2621
Chuck Lever9f06c712010-12-14 14:59:18 +00002622 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002623 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002624 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625}
2626
2627/*
2628 * a SETCLIENTID request
2629 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002630static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2631 struct xdr_stream *xdr,
2632 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002635 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 };
2637
Chuck Lever9f06c712010-12-14 14:59:18 +00002638 encode_compound_hdr(xdr, req, &hdr);
2639 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002640 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641}
2642
2643/*
2644 * a SETCLIENTID_CONFIRM request
2645 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002646static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2647 struct xdr_stream *xdr,
2648 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002651 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653
Chuck Lever9f06c712010-12-14 14:59:18 +00002654 encode_compound_hdr(xdr, req, &hdr);
2655 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002656 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657}
2658
2659/*
2660 * DELEGRETURN request
2661 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002662static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2663 struct xdr_stream *xdr,
2664 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002667 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669
Chuck Lever9f06c712010-12-14 14:59:18 +00002670 encode_compound_hdr(xdr, req, &hdr);
2671 encode_sequence(xdr, &args->seq_args, &hdr);
2672 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002673 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002674 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002675 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676}
2677
2678/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002679 * Encode FS_LOCATIONS request
2680 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002681static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2682 struct xdr_stream *xdr,
2683 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002684{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002685 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002686 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002687 };
Benny Halevy28f56692009-04-01 09:22:09 -04002688 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002689
Chuck Lever9f06c712010-12-14 14:59:18 +00002690 encode_compound_hdr(xdr, req, &hdr);
2691 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002692 if (args->migration) {
2693 encode_putfh(xdr, args->fh, &hdr);
2694 replen = hdr.replen;
2695 encode_fs_locations(xdr, args->bitmask, &hdr);
2696 if (args->renew)
2697 encode_renew(xdr, args->clientid, &hdr);
2698 } else {
2699 encode_putfh(xdr, args->dir_fh, &hdr);
2700 encode_lookup(xdr, args->name, &hdr);
2701 replen = hdr.replen;
2702 encode_fs_locations(xdr, args->bitmask, &hdr);
2703 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002704
Chuck Leverb03d7352013-10-17 14:12:50 -04002705 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002706 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002707 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002708 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002709}
2710
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002711/*
2712 * Encode SECINFO request
2713 */
2714static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2715 struct xdr_stream *xdr,
2716 struct nfs4_secinfo_arg *args)
2717{
2718 struct compound_hdr hdr = {
2719 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2720 };
2721
2722 encode_compound_hdr(xdr, req, &hdr);
2723 encode_sequence(xdr, &args->seq_args, &hdr);
2724 encode_putfh(xdr, args->dir_fh, &hdr);
2725 encode_secinfo(xdr, args->name, &hdr);
2726 encode_nops(&hdr);
2727}
2728
Chuck Lever44c99932013-10-17 14:13:30 -04002729/*
2730 * Encode FSID_PRESENT request
2731 */
2732static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2733 struct xdr_stream *xdr,
2734 struct nfs4_fsid_present_arg *args)
2735{
2736 struct compound_hdr hdr = {
2737 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2738 };
2739
2740 encode_compound_hdr(xdr, req, &hdr);
2741 encode_sequence(xdr, &args->seq_args, &hdr);
2742 encode_putfh(xdr, args->fh, &hdr);
2743 encode_getfh(xdr, &hdr);
2744 if (args->renew)
2745 encode_renew(xdr, args->clientid, &hdr);
2746 encode_nops(&hdr);
2747}
2748
Benny Halevy99fe60d2009-04-01 09:22:29 -04002749#if defined(CONFIG_NFS_V4_1)
2750/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002751 * BIND_CONN_TO_SESSION request
2752 */
2753static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2754 struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08002755 struct nfs41_bind_conn_to_session_args *args)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002756{
2757 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002758 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002759 };
2760
2761 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002762 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002763 encode_nops(&hdr);
2764}
2765
2766/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002767 * EXCHANGE_ID request
2768 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002769static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2770 struct xdr_stream *xdr,
2771 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002772{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002773 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002774 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002775 };
2776
Chuck Lever9f06c712010-12-14 14:59:18 +00002777 encode_compound_hdr(xdr, req, &hdr);
2778 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002779 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002780}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002781
2782/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002783 * a CREATE_SESSION request
2784 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002785static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2786 struct xdr_stream *xdr,
2787 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002788{
Andy Adamsonfc931582009-04-01 09:22:31 -04002789 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002790 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002791 };
2792
Chuck Lever9f06c712010-12-14 14:59:18 +00002793 encode_compound_hdr(xdr, req, &hdr);
2794 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002795 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002796}
2797
2798/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002799 * a DESTROY_SESSION request
2800 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002801static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2802 struct xdr_stream *xdr,
2803 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002804{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002805 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002806 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002807 };
2808
Chuck Lever9f06c712010-12-14 14:59:18 +00002809 encode_compound_hdr(xdr, req, &hdr);
2810 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002811 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002812}
2813
2814/*
Trond Myklebust66245532012-05-25 17:18:09 -04002815 * a DESTROY_CLIENTID request
2816 */
2817static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2818 struct xdr_stream *xdr,
2819 struct nfs_client *clp)
2820{
2821 struct compound_hdr hdr = {
2822 .minorversion = clp->cl_mvops->minor_version,
2823 };
2824
2825 encode_compound_hdr(xdr, req, &hdr);
2826 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2827 encode_nops(&hdr);
2828}
2829
2830/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002831 * a SEQUENCE request
2832 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002833static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2834 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002835{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002836 struct compound_hdr hdr = {
2837 .minorversion = nfs4_xdr_minorversion(args),
2838 };
2839
Chuck Lever9f06c712010-12-14 14:59:18 +00002840 encode_compound_hdr(xdr, req, &hdr);
2841 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002842 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002843}
2844
2845/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002846 * a GET_LEASE_TIME request
2847 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002848static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2849 struct xdr_stream *xdr,
2850 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002851{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002852 struct compound_hdr hdr = {
2853 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2854 };
Fred Isamandae100c2011-07-30 20:52:37 -04002855 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002856
Chuck Lever9f06c712010-12-14 14:59:18 +00002857 encode_compound_hdr(xdr, req, &hdr);
2858 encode_sequence(xdr, &args->la_seq_args, &hdr);
2859 encode_putrootfh(xdr, &hdr);
2860 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002861 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002862}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002863
2864/*
2865 * a RECLAIM_COMPLETE request
2866 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002867static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2868 struct xdr_stream *xdr,
2869 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002870{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002871 struct compound_hdr hdr = {
2872 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2873 };
2874
Chuck Lever9f06c712010-12-14 14:59:18 +00002875 encode_compound_hdr(xdr, req, &hdr);
2876 encode_sequence(xdr, &args->seq_args, &hdr);
2877 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002878 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002879}
2880
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002881/*
2882 * Encode GETDEVICEINFO request
2883 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002884static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2885 struct xdr_stream *xdr,
2886 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002887{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002888 struct compound_hdr hdr = {
2889 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2890 };
2891
Chuck Lever9f06c712010-12-14 14:59:18 +00002892 encode_compound_hdr(xdr, req, &hdr);
2893 encode_sequence(xdr, &args->seq_args, &hdr);
2894 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002895
2896 /* set up reply kvec. Subtract notification bitmap max size (2)
2897 * so that notification bitmap is put in xdr_buf tail */
2898 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2899 args->pdev->pages, args->pdev->pgbase,
2900 args->pdev->pglen);
2901
2902 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002903}
2904
2905/*
2906 * Encode LAYOUTGET request
2907 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002908static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2909 struct xdr_stream *xdr,
2910 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002911{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002912 struct compound_hdr hdr = {
2913 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2914 };
2915
Chuck Lever9f06c712010-12-14 14:59:18 +00002916 encode_compound_hdr(xdr, req, &hdr);
2917 encode_sequence(xdr, &args->seq_args, &hdr);
2918 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2919 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002920
2921 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2922 args->layout.pages, 0, args->layout.pglen);
2923
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002924 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002925}
Andy Adamson863a3c62011-03-23 13:27:54 +00002926
2927/*
2928 * Encode LAYOUTCOMMIT request
2929 */
Benny Halevycbe82602011-05-22 19:52:37 +03002930static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2931 struct xdr_stream *xdr,
2932 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002933{
Benny Halevyac7db722011-05-22 19:53:48 +03002934 struct nfs4_layoutcommit_data *data =
2935 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002936 struct compound_hdr hdr = {
2937 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2938 };
2939
2940 encode_compound_hdr(xdr, req, &hdr);
2941 encode_sequence(xdr, &args->seq_args, &hdr);
2942 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002943 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002944 encode_getfattr(xdr, args->bitmask, &hdr);
2945 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002946}
2947
2948/*
2949 * Encode LAYOUTRETURN request
2950 */
2951static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2952 struct xdr_stream *xdr,
2953 struct nfs4_layoutreturn_args *args)
2954{
2955 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);
2962 encode_layoutreturn(xdr, args, &hdr);
2963 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002964}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002965
2966/*
2967 * Encode SECINFO_NO_NAME request
2968 */
2969static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2970 struct xdr_stream *xdr,
2971 struct nfs41_secinfo_no_name_args *args)
2972{
2973 struct compound_hdr hdr = {
2974 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2975 };
2976
2977 encode_compound_hdr(xdr, req, &hdr);
2978 encode_sequence(xdr, &args->seq_args, &hdr);
2979 encode_putrootfh(xdr, &hdr);
2980 encode_secinfo_no_name(xdr, args, &hdr);
2981 encode_nops(&hdr);
2982 return 0;
2983}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002984
2985/*
2986 * Encode TEST_STATEID request
2987 */
2988static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2989 struct xdr_stream *xdr,
2990 struct nfs41_test_stateid_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_test_stateid(xdr, args, &hdr);
2999 encode_nops(&hdr);
3000}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003001
3002/*
3003 * Encode FREE_STATEID request
3004 */
3005static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3006 struct xdr_stream *xdr,
3007 struct nfs41_free_stateid_args *args)
3008{
3009 struct compound_hdr hdr = {
3010 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3011 };
3012
3013 encode_compound_hdr(xdr, req, &hdr);
3014 encode_sequence(xdr, &args->seq_args, &hdr);
3015 encode_free_stateid(xdr, args, &hdr);
3016 encode_nops(&hdr);
3017}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003018#endif /* CONFIG_NFS_V4_1 */
3019
Benny Halevy686841b2009-08-14 17:19:48 +03003020static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3021{
3022 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3023 "Remaining buffer length is %tu words.\n",
3024 func, xdr->end - xdr->p);
3025}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026
Trond Myklebust683b57b2006-06-09 09:34:22 -04003027static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028{
Al Viro8687b632006-10-19 23:28:48 -07003029 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030
Benny Halevyc0eae662009-08-14 17:20:14 +03003031 p = xdr_inline_decode(xdr, 4);
3032 if (unlikely(!p))
3033 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003034 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003035 p = xdr_inline_decode(xdr, *len);
3036 if (unlikely(!p))
3037 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 *string = (char *)p;
3039 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003040out_overflow:
3041 print_overflow_msg(__func__, xdr);
3042 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043}
3044
3045static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3046{
Al Viro8687b632006-10-19 23:28:48 -07003047 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048
Benny Halevyc0eae662009-08-14 17:20:14 +03003049 p = xdr_inline_decode(xdr, 8);
3050 if (unlikely(!p))
3051 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003052 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003053 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003054
Benny Halevyc0eae662009-08-14 17:20:14 +03003055 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3056 if (unlikely(!p))
3057 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 hdr->tag = (char *)p;
3059 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003060 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003061 if (unlikely(hdr->nops < 1))
3062 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003064out_overflow:
3065 print_overflow_msg(__func__, xdr);
3066 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067}
3068
Trond Myklebustc7848f62013-12-04 17:39:23 -05003069static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3070 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071{
Al Viro8687b632006-10-19 23:28:48 -07003072 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 uint32_t opnum;
3074 int32_t nfserr;
3075
Benny Halevyc0eae662009-08-14 17:20:14 +03003076 p = xdr_inline_decode(xdr, 8);
3077 if (unlikely(!p))
3078 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003079 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003080 if (unlikely(opnum != expected))
3081 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003082 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003083 if (nfserr == NFS_OK)
3084 *nfs_retval = 0;
3085 else
3086 *nfs_retval = nfs4_stat_to_errno(nfserr);
3087 return true;
3088out_bad_operation:
3089 dprintk("nfs: Server returned operation"
3090 " %d but we issued a request for %d\n",
3091 opnum, expected);
3092 *nfs_retval = -EREMOTEIO;
3093 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003094out_overflow:
3095 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003096 *nfs_retval = -EIO;
3097 return false;
3098}
3099
3100static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3101{
3102 int retval;
3103
3104 __decode_op_hdr(xdr, expected, &retval);
3105 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106}
3107
3108/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003109static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110{
Al Viro8687b632006-10-19 23:28:48 -07003111 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003112 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 char *str;
3114
Benny Halevyc0eae662009-08-14 17:20:14 +03003115 p = xdr_inline_decode(xdr, 12);
3116 if (likely(p))
3117 return decode_opaque_inline(xdr, &strlen, &str);
3118 print_overflow_msg(__func__, xdr);
3119 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120}
3121
3122static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3123{
Al Viro8687b632006-10-19 23:28:48 -07003124 uint32_t bmlen;
3125 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126
Benny Halevyc0eae662009-08-14 17:20:14 +03003127 p = xdr_inline_decode(xdr, 4);
3128 if (unlikely(!p))
3129 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003130 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131
Fred Isamandae100c2011-07-30 20:52:37 -04003132 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003133 p = xdr_inline_decode(xdr, (bmlen << 2));
3134 if (unlikely(!p))
3135 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003137 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003138 if (bmlen > 1) {
3139 bitmap[1] = be32_to_cpup(p++);
3140 if (bmlen > 2)
3141 bitmap[2] = be32_to_cpup(p);
3142 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 }
3144 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003145out_overflow:
3146 print_overflow_msg(__func__, xdr);
3147 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148}
3149
Trond Myklebust256e48b2012-06-21 11:18:13 -04003150static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151{
Al Viro8687b632006-10-19 23:28:48 -07003152 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153
Benny Halevyc0eae662009-08-14 17:20:14 +03003154 p = xdr_inline_decode(xdr, 4);
3155 if (unlikely(!p))
3156 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003157 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003158 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003160out_overflow:
3161 print_overflow_msg(__func__, xdr);
3162 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163}
3164
3165static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3166{
3167 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003168 int ret;
3169 ret = decode_attr_bitmap(xdr, bitmask);
3170 if (unlikely(ret < 0))
3171 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3173 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003174 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3175 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3176 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 return 0;
3178}
3179
3180static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3181{
Al Viro8687b632006-10-19 23:28:48 -07003182 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003183 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184
3185 *type = 0;
3186 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3187 return -EIO;
3188 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003189 p = xdr_inline_decode(xdr, 4);
3190 if (unlikely(!p))
3191 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003192 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003194 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 return -EIO;
3196 }
3197 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003198 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003200 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003201 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003202out_overflow:
3203 print_overflow_msg(__func__, xdr);
3204 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205}
3206
Chuck Lever264e6352012-03-01 17:02:05 -05003207static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3208 uint32_t *bitmap, uint32_t *type)
3209{
3210 __be32 *p;
3211
3212 *type = 0;
3213 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3214 return -EIO;
3215 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3216 p = xdr_inline_decode(xdr, 4);
3217 if (unlikely(!p))
3218 goto out_overflow;
3219 *type = be32_to_cpup(p);
3220 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3221 }
3222 dprintk("%s: expire type=0x%x\n", __func__, *type);
3223 return 0;
3224out_overflow:
3225 print_overflow_msg(__func__, xdr);
3226 return -EIO;
3227}
3228
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3230{
Al Viro8687b632006-10-19 23:28:48 -07003231 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003232 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233
3234 *change = 0;
3235 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3236 return -EIO;
3237 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003238 p = xdr_inline_decode(xdr, 8);
3239 if (unlikely(!p))
3240 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003241 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003243 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003245 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003247 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003248out_overflow:
3249 print_overflow_msg(__func__, xdr);
3250 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251}
3252
3253static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3254{
Al Viro8687b632006-10-19 23:28:48 -07003255 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003256 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257
3258 *size = 0;
3259 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3260 return -EIO;
3261 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003262 p = xdr_inline_decode(xdr, 8);
3263 if (unlikely(!p))
3264 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003265 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003267 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003269 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003270 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003271out_overflow:
3272 print_overflow_msg(__func__, xdr);
3273 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274}
3275
3276static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3277{
Al Viro8687b632006-10-19 23:28:48 -07003278 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279
3280 *res = 0;
3281 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3282 return -EIO;
3283 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003284 p = xdr_inline_decode(xdr, 4);
3285 if (unlikely(!p))
3286 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003287 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3289 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003290 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003292out_overflow:
3293 print_overflow_msg(__func__, xdr);
3294 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295}
3296
3297static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3298{
Al Viro8687b632006-10-19 23:28:48 -07003299 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300
3301 *res = 0;
3302 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3303 return -EIO;
3304 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003305 p = xdr_inline_decode(xdr, 4);
3306 if (unlikely(!p))
3307 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003308 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3310 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003311 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003313out_overflow:
3314 print_overflow_msg(__func__, xdr);
3315 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316}
3317
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003318static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319{
Al Viro8687b632006-10-19 23:28:48 -07003320 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003321 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322
3323 fsid->major = 0;
3324 fsid->minor = 0;
3325 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3326 return -EIO;
3327 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003328 p = xdr_inline_decode(xdr, 16);
3329 if (unlikely(!p))
3330 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003331 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003332 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003334 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003336 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 (unsigned long long)fsid->major,
3338 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003339 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003340out_overflow:
3341 print_overflow_msg(__func__, xdr);
3342 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343}
3344
3345static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3346{
Al Viro8687b632006-10-19 23:28:48 -07003347 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348
3349 *res = 60;
3350 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3351 return -EIO;
3352 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003353 p = xdr_inline_decode(xdr, 4);
3354 if (unlikely(!p))
3355 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003356 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3358 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003359 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003361out_overflow:
3362 print_overflow_msg(__func__, xdr);
3363 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364}
3365
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003366static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003367{
3368 __be32 *p;
3369
3370 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3371 return -EIO;
3372 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3373 p = xdr_inline_decode(xdr, 4);
3374 if (unlikely(!p))
3375 goto out_overflow;
3376 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003377 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003378 }
3379 return 0;
3380out_overflow:
3381 print_overflow_msg(__func__, xdr);
3382 return -EIO;
3383}
3384
Kinglong Mee8c612822015-08-26 21:12:58 +08003385static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3386 uint32_t *bitmap, uint32_t *bitmask)
3387{
3388 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3389 int ret;
3390 ret = decode_attr_bitmap(xdr, bitmask);
3391 if (unlikely(ret < 0))
3392 return ret;
3393 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3394 } else
3395 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3396 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3397 bitmask[0], bitmask[1], bitmask[2]);
3398 return 0;
3399}
3400
Bryan Schumakerae42c702010-10-21 16:33:17 -04003401static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3402{
3403 __be32 *p;
3404 int len;
3405
Trond Myklebust7ad07352010-10-23 15:34:20 -04003406 if (fh != NULL)
3407 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003408
3409 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3410 return -EIO;
3411 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3412 p = xdr_inline_decode(xdr, 4);
3413 if (unlikely(!p))
3414 goto out_overflow;
3415 len = be32_to_cpup(p);
3416 if (len > NFS4_FHSIZE)
3417 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003418 p = xdr_inline_decode(xdr, len);
3419 if (unlikely(!p))
3420 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003421 if (fh != NULL) {
3422 memcpy(fh->data, p, len);
3423 fh->size = len;
3424 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003425 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3426 }
3427 return 0;
3428out_overflow:
3429 print_overflow_msg(__func__, xdr);
3430 return -EIO;
3431}
3432
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3434{
Al Viro8687b632006-10-19 23:28:48 -07003435 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003437 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3439 return -EIO;
3440 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003441 p = xdr_inline_decode(xdr, 4);
3442 if (unlikely(!p))
3443 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003444 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3446 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003447 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003449out_overflow:
3450 print_overflow_msg(__func__, xdr);
3451 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452}
3453
3454static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3455{
Al Viro8687b632006-10-19 23:28:48 -07003456 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003457 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458
3459 *fileid = 0;
3460 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3461 return -EIO;
3462 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003463 p = xdr_inline_decode(xdr, 8);
3464 if (unlikely(!p))
3465 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003466 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003468 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003470 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003471 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003472out_overflow:
3473 print_overflow_msg(__func__, xdr);
3474 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475}
3476
Manoj Naik99baf622006-06-09 09:34:24 -04003477static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3478{
Al Viro8687b632006-10-19 23:28:48 -07003479 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003480 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003481
3482 *fileid = 0;
3483 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3484 return -EIO;
3485 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003486 p = xdr_inline_decode(xdr, 8);
3487 if (unlikely(!p))
3488 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003489 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003490 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003491 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003492 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003493 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003494 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003495out_overflow:
3496 print_overflow_msg(__func__, xdr);
3497 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003498}
3499
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3501{
Al Viro8687b632006-10-19 23:28:48 -07003502 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 int status = 0;
3504
3505 *res = 0;
3506 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3507 return -EIO;
3508 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003509 p = xdr_inline_decode(xdr, 8);
3510 if (unlikely(!p))
3511 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003512 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3514 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003515 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003517out_overflow:
3518 print_overflow_msg(__func__, xdr);
3519 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520}
3521
3522static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3523{
Al Viro8687b632006-10-19 23:28:48 -07003524 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 int status = 0;
3526
3527 *res = 0;
3528 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3529 return -EIO;
3530 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003531 p = xdr_inline_decode(xdr, 8);
3532 if (unlikely(!p))
3533 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003534 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3536 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003537 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003539out_overflow:
3540 print_overflow_msg(__func__, xdr);
3541 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542}
3543
3544static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3545{
Al Viro8687b632006-10-19 23:28:48 -07003546 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 int status = 0;
3548
3549 *res = 0;
3550 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3551 return -EIO;
3552 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003553 p = xdr_inline_decode(xdr, 8);
3554 if (unlikely(!p))
3555 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003556 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3558 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003559 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003561out_overflow:
3562 print_overflow_msg(__func__, xdr);
3563 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564}
3565
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003566static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3567{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003568 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003569 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003570 int status = 0;
3571
Benny Halevyc0eae662009-08-14 17:20:14 +03003572 p = xdr_inline_decode(xdr, 4);
3573 if (unlikely(!p))
3574 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003575 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003576 if (n == 0)
3577 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003578 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003579 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3580 dprintk("cannot parse %d components in path\n", n);
3581 goto out_eio;
3582 }
3583 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003584 struct nfs4_string *component = &path->components[path->ncomponents];
3585 status = decode_opaque_inline(xdr, &component->len, &component->data);
3586 if (unlikely(status != 0))
3587 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003588 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003589 pr_cont("%s%.*s ",
3590 (path->ncomponents != n ? "/ " : ""),
3591 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003592 }
3593out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003594 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003595root_path:
3596/* a root pathname is sent as a zero component4 */
3597 path->ncomponents = 1;
3598 path->components[0].len=0;
3599 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003600 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003601 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003602out_eio:
3603 dprintk(" status %d", status);
3604 status = -EIO;
3605 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003606out_overflow:
3607 print_overflow_msg(__func__, xdr);
3608 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003609}
3610
3611static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003612{
3613 int n;
Al Viro8687b632006-10-19 23:28:48 -07003614 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003615 int status = -EIO;
3616
3617 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3618 goto out;
3619 status = 0;
3620 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3621 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003622 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003623 status = -EIO;
3624 /* Ignore borken servers that return unrequested attrs */
3625 if (unlikely(res == NULL))
3626 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003627 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003628 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003629 if (unlikely(status != 0))
3630 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003631 p = xdr_inline_decode(xdr, 4);
3632 if (unlikely(!p))
3633 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003634 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003635 if (n <= 0)
3636 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003637 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003638 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003639 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003640
Trond Myklebust809b4262013-03-27 11:54:45 -04003641 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3642 break;
3643 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003644 p = xdr_inline_decode(xdr, 4);
3645 if (unlikely(!p))
3646 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003647 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003648
Chuck Lever02a29762012-03-01 17:00:31 -05003649 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003650 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3651 struct nfs4_string *server;
3652
3653 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003654 unsigned int i;
3655 dprintk("%s: using first %u of %u servers "
3656 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003657 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003658 NFS4_FS_LOCATION_MAXSERVERS,
3659 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003660 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003661 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003662 char *data;
3663 status = decode_opaque_inline(xdr, &len, &data);
3664 if (unlikely(status != 0))
3665 goto out_eio;
3666 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003667 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003668 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003669 server = &loc->servers[loc->nservers];
3670 status = decode_opaque_inline(xdr, &server->len, &server->data);
3671 if (unlikely(status != 0))
3672 goto out_eio;
3673 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003674 }
3675 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003676 if (unlikely(status != 0))
3677 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003678 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003679 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003680 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003681out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003682 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003683 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003684out_overflow:
3685 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003686out_eio:
3687 status = -EIO;
3688 goto out;
3689}
3690
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3692{
Al Viro8687b632006-10-19 23:28:48 -07003693 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694 int status = 0;
3695
3696 *res = 0;
3697 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3698 return -EIO;
3699 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003700 p = xdr_inline_decode(xdr, 8);
3701 if (unlikely(!p))
3702 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003703 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3705 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003706 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003708out_overflow:
3709 print_overflow_msg(__func__, xdr);
3710 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711}
3712
3713static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3714{
Al Viro8687b632006-10-19 23:28:48 -07003715 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 int status = 0;
3717
3718 *maxlink = 1;
3719 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3720 return -EIO;
3721 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003722 p = xdr_inline_decode(xdr, 4);
3723 if (unlikely(!p))
3724 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003725 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3727 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003728 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003730out_overflow:
3731 print_overflow_msg(__func__, xdr);
3732 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733}
3734
3735static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3736{
Al Viro8687b632006-10-19 23:28:48 -07003737 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 int status = 0;
3739
3740 *maxname = 1024;
3741 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3742 return -EIO;
3743 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003744 p = xdr_inline_decode(xdr, 4);
3745 if (unlikely(!p))
3746 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003747 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3749 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003750 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003752out_overflow:
3753 print_overflow_msg(__func__, xdr);
3754 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755}
3756
3757static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3758{
Al Viro8687b632006-10-19 23:28:48 -07003759 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760 int status = 0;
3761
3762 *res = 1024;
3763 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3764 return -EIO;
3765 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3766 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003767 p = xdr_inline_decode(xdr, 8);
3768 if (unlikely(!p))
3769 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003770 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 if (maxread > 0x7FFFFFFF)
3772 maxread = 0x7FFFFFFF;
3773 *res = (uint32_t)maxread;
3774 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3775 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003776 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003778out_overflow:
3779 print_overflow_msg(__func__, xdr);
3780 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781}
3782
3783static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3784{
Al Viro8687b632006-10-19 23:28:48 -07003785 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786 int status = 0;
3787
3788 *res = 1024;
3789 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3790 return -EIO;
3791 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3792 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003793 p = xdr_inline_decode(xdr, 8);
3794 if (unlikely(!p))
3795 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003796 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797 if (maxwrite > 0x7FFFFFFF)
3798 maxwrite = 0x7FFFFFFF;
3799 *res = (uint32_t)maxwrite;
3800 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3801 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003802 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003804out_overflow:
3805 print_overflow_msg(__func__, xdr);
3806 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807}
3808
Trond Myklebustbca79472009-03-11 14:10:26 -04003809static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810{
Trond Myklebustbca79472009-03-11 14:10:26 -04003811 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003812 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003813 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814
3815 *mode = 0;
3816 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3817 return -EIO;
3818 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003819 p = xdr_inline_decode(xdr, 4);
3820 if (unlikely(!p))
3821 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003822 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003823 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003825 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003827 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003828 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003829out_overflow:
3830 print_overflow_msg(__func__, xdr);
3831 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832}
3833
3834static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3835{
Al Viro8687b632006-10-19 23:28:48 -07003836 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003837 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838
3839 *nlink = 1;
3840 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3841 return -EIO;
3842 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003843 p = xdr_inline_decode(xdr, 4);
3844 if (unlikely(!p))
3845 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003846 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003848 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003850 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003851 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003852out_overflow:
3853 print_overflow_msg(__func__, xdr);
3854 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855}
3856
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003857static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003858 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003859 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860{
Al Viro8687b632006-10-19 23:28:48 -07003861 uint32_t len;
3862 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003863 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864
Eric W. Biedermane5782072013-02-01 14:22:02 -08003865 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3867 return -EIO;
3868 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003869 p = xdr_inline_decode(xdr, 4);
3870 if (unlikely(!p))
3871 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003872 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003873 p = xdr_inline_decode(xdr, len);
3874 if (unlikely(!p))
3875 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003876 if (owner_name != NULL) {
3877 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3878 if (owner_name->data != NULL) {
3879 owner_name->len = len;
3880 ret = NFS_ATTR_FATTR_OWNER_NAME;
3881 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003882 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003883 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003884 ret = NFS_ATTR_FATTR_OWNER;
3885 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003887 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003889 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003890 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3892 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003893 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003894 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003895out_overflow:
3896 print_overflow_msg(__func__, xdr);
3897 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898}
3899
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003900static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003901 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003902 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903{
Al Viro8687b632006-10-19 23:28:48 -07003904 uint32_t len;
3905 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003906 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907
Eric W. Biedermane5782072013-02-01 14:22:02 -08003908 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3910 return -EIO;
3911 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003912 p = xdr_inline_decode(xdr, 4);
3913 if (unlikely(!p))
3914 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003915 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003916 p = xdr_inline_decode(xdr, len);
3917 if (unlikely(!p))
3918 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003919 if (group_name != NULL) {
3920 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3921 if (group_name->data != NULL) {
3922 group_name->len = len;
3923 ret = NFS_ATTR_FATTR_GROUP_NAME;
3924 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003925 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003926 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003927 ret = NFS_ATTR_FATTR_GROUP;
3928 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003930 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003932 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003933 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3935 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003936 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003937 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003938out_overflow:
3939 print_overflow_msg(__func__, xdr);
3940 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941}
3942
3943static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3944{
Al Viro8687b632006-10-19 23:28:48 -07003945 uint32_t major = 0, minor = 0;
3946 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003947 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948
3949 *rdev = MKDEV(0,0);
3950 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3951 return -EIO;
3952 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3953 dev_t tmp;
3954
Benny Halevyc0eae662009-08-14 17:20:14 +03003955 p = xdr_inline_decode(xdr, 8);
3956 if (unlikely(!p))
3957 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003958 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003959 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960 tmp = MKDEV(major, minor);
3961 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3962 *rdev = tmp;
3963 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003964 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003966 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003967 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003968out_overflow:
3969 print_overflow_msg(__func__, xdr);
3970 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971}
3972
3973static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3974{
Al Viro8687b632006-10-19 23:28:48 -07003975 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 int status = 0;
3977
3978 *res = 0;
3979 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3980 return -EIO;
3981 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003982 p = xdr_inline_decode(xdr, 8);
3983 if (unlikely(!p))
3984 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003985 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3987 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003988 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003990out_overflow:
3991 print_overflow_msg(__func__, xdr);
3992 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993}
3994
3995static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3996{
Al Viro8687b632006-10-19 23:28:48 -07003997 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 int status = 0;
3999
4000 *res = 0;
4001 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4002 return -EIO;
4003 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004004 p = xdr_inline_decode(xdr, 8);
4005 if (unlikely(!p))
4006 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004007 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4009 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004010 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004012out_overflow:
4013 print_overflow_msg(__func__, xdr);
4014 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015}
4016
4017static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4018{
Al Viro8687b632006-10-19 23:28:48 -07004019 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 int status = 0;
4021
4022 *res = 0;
4023 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4024 return -EIO;
4025 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004026 p = xdr_inline_decode(xdr, 8);
4027 if (unlikely(!p))
4028 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004029 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4031 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004032 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004034out_overflow:
4035 print_overflow_msg(__func__, xdr);
4036 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037}
4038
4039static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4040{
Al Viro8687b632006-10-19 23:28:48 -07004041 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004042 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043
4044 *used = 0;
4045 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4046 return -EIO;
4047 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004048 p = xdr_inline_decode(xdr, 8);
4049 if (unlikely(!p))
4050 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004051 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004053 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004055 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004057 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004058out_overflow:
4059 print_overflow_msg(__func__, xdr);
4060 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061}
4062
4063static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4064{
Al Viro8687b632006-10-19 23:28:48 -07004065 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 uint64_t sec;
4067 uint32_t nsec;
4068
Benny Halevyc0eae662009-08-14 17:20:14 +03004069 p = xdr_inline_decode(xdr, 12);
4070 if (unlikely(!p))
4071 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004072 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004073 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074 time->tv_sec = (time_t)sec;
4075 time->tv_nsec = (long)nsec;
4076 return 0;
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_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4083{
4084 int status = 0;
4085
4086 time->tv_sec = 0;
4087 time->tv_nsec = 0;
4088 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4089 return -EIO;
4090 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4091 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004092 if (status == 0)
4093 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4095 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004096 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097 return status;
4098}
4099
4100static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4101{
4102 int status = 0;
4103
4104 time->tv_sec = 0;
4105 time->tv_nsec = 0;
4106 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4107 return -EIO;
4108 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4109 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004110 if (status == 0)
4111 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4113 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004114 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115 return status;
4116}
4117
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004118static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4119 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_DELTA - 1U)))
4126 return -EIO;
4127 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4128 status = decode_attr_time(xdr, time);
4129 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4130 }
4131 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4132 (long)time->tv_nsec);
4133 return status;
4134}
4135
David Quigleyaa9c2662013-05-22 12:50:44 -04004136static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4137 struct nfs4_label *label)
4138{
4139 uint32_t pi = 0;
4140 uint32_t lfs = 0;
4141 __u32 len;
4142 __be32 *p;
4143 int status = 0;
4144
4145 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4146 return -EIO;
4147 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4148 p = xdr_inline_decode(xdr, 4);
4149 if (unlikely(!p))
4150 goto out_overflow;
4151 lfs = be32_to_cpup(p++);
4152 p = xdr_inline_decode(xdr, 4);
4153 if (unlikely(!p))
4154 goto out_overflow;
4155 pi = be32_to_cpup(p++);
4156 p = xdr_inline_decode(xdr, 4);
4157 if (unlikely(!p))
4158 goto out_overflow;
4159 len = be32_to_cpup(p++);
4160 p = xdr_inline_decode(xdr, len);
4161 if (unlikely(!p))
4162 goto out_overflow;
4163 if (len < NFS4_MAXLABELLEN) {
4164 if (label) {
4165 memcpy(label->label, p, len);
4166 label->len = len;
4167 label->pi = pi;
4168 label->lfs = lfs;
4169 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4170 }
4171 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4172 } else
4173 printk(KERN_WARNING "%s: label too long (%u)!\n",
4174 __func__, len);
4175 }
4176 if (label && label->label)
4177 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4178 (char *)label->label, label->len, label->pi, label->lfs);
4179 return status;
4180
4181out_overflow:
4182 print_overflow_msg(__func__, xdr);
4183 return -EIO;
4184}
4185
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4187{
4188 int status = 0;
4189
4190 time->tv_sec = 0;
4191 time->tv_nsec = 0;
4192 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4193 return -EIO;
4194 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4195 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004196 if (status == 0)
4197 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4199 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004200 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201 return status;
4202}
4203
Trond Myklebust256e48b2012-06-21 11:18:13 -04004204static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205{
4206 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004207 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208
4209 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004210 dprintk("%s: server returned incorrect attribute length: "
4211 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004212 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 attrwords << 2,
4214 (attrwords < nwords) ? '<' : '>',
4215 nwords << 2);
4216 return -EIO;
4217 }
4218 return 0;
4219}
4220
4221static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4222{
Al Viro8687b632006-10-19 23:28:48 -07004223 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224
Benny Halevyc0eae662009-08-14 17:20:14 +03004225 p = xdr_inline_decode(xdr, 20);
4226 if (unlikely(!p))
4227 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004228 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004229 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004230 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004232out_overflow:
4233 print_overflow_msg(__func__, xdr);
4234 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235}
4236
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004237static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238{
Al Viro8687b632006-10-19 23:28:48 -07004239 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240 uint32_t supp, acc;
4241 int status;
4242
4243 status = decode_op_hdr(xdr, OP_ACCESS);
4244 if (status)
4245 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004246 p = xdr_inline_decode(xdr, 8);
4247 if (unlikely(!p))
4248 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004249 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004250 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004251 *supported = supp;
4252 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004254out_overflow:
4255 print_overflow_msg(__func__, xdr);
4256 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257}
4258
Benny Halevy07d30432009-08-14 17:19:52 +03004259static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260{
Al Viro8687b632006-10-19 23:28:48 -07004261 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004262
4263 p = xdr_inline_decode(xdr, len);
4264 if (likely(p)) {
4265 memcpy(buf, p, len);
4266 return 0;
4267 }
4268 print_overflow_msg(__func__, xdr);
4269 return -EIO;
4270}
4271
4272static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4273{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004274 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275}
4276
Trond Myklebust93b717f2016-05-16 17:42:43 -04004277static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4278{
4279 stateid->type = NFS4_OPEN_STATEID_TYPE;
4280 return decode_stateid(xdr, stateid);
4281}
4282
4283static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4284{
4285 stateid->type = NFS4_LOCK_STATEID_TYPE;
4286 return decode_stateid(xdr, stateid);
4287}
4288
4289static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4290{
4291 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4292 return decode_stateid(xdr, stateid);
4293}
4294
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4296{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297 int status;
4298
4299 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004300 if (status != -EIO)
4301 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004302 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04004303 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004304 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305}
4306
Benny Halevydb942bb2009-08-14 17:19:56 +03004307static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4308{
Chuck Levercd937102012-03-02 17:14:31 -05004309 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310}
4311
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004312static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4313{
4314 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4315}
4316
Fred Isaman0b7c0152012-04-20 14:47:39 -04004317static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319 int status;
4320
4321 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004322 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004323 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004324 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325}
4326
4327static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4328{
Al Viro8687b632006-10-19 23:28:48 -07004329 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330 uint32_t bmlen;
4331 int status;
4332
4333 status = decode_op_hdr(xdr, OP_CREATE);
4334 if (status)
4335 return status;
4336 if ((status = decode_change_info(xdr, cinfo)))
4337 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004338 p = xdr_inline_decode(xdr, 4);
4339 if (unlikely(!p))
4340 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004341 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004342 p = xdr_inline_decode(xdr, bmlen << 2);
4343 if (likely(p))
4344 return 0;
4345out_overflow:
4346 print_overflow_msg(__func__, xdr);
4347 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348}
4349
4350static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4351{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004352 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004353 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354 int status;
4355
4356 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4357 goto xdr_error;
4358 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4359 goto xdr_error;
4360 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4361 goto xdr_error;
4362 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4363 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004364 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4365 &res->fh_expire_type)) != 0)
4366 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4368 goto xdr_error;
4369 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4370 goto xdr_error;
4371 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4372 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004373 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4374 res->exclcreat_bitmask)) != 0)
4375 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376 status = verify_attr_len(xdr, savep, attrlen);
4377xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004378 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004379 return status;
4380}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004381
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4383{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004384 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004385 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004387
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4389 goto xdr_error;
4390 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4391 goto xdr_error;
4392 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4393 goto xdr_error;
4394
4395 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4396 goto xdr_error;
4397 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4398 goto xdr_error;
4399 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4400 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004401
4402 status = -EIO;
4403 if (unlikely(bitmap[0]))
4404 goto xdr_error;
4405
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4407 goto xdr_error;
4408 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4409 goto xdr_error;
4410 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4411 goto xdr_error;
4412
4413 status = verify_attr_len(xdr, savep, attrlen);
4414xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004415 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416 return status;
4417}
4418
4419static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4420{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004421 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004422 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004423 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004424
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4426 goto xdr_error;
4427 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4428 goto xdr_error;
4429 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4430 goto xdr_error;
4431
4432 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4433 goto xdr_error;
4434 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4435 goto xdr_error;
4436
4437 status = verify_attr_len(xdr, savep, attrlen);
4438xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004439 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440 return status;
4441}
4442
Andy Adamson88034c32012-05-23 05:02:34 -04004443static int decode_threshold_hint(struct xdr_stream *xdr,
4444 uint32_t *bitmap,
4445 uint64_t *res,
4446 uint32_t hint_bit)
4447{
4448 __be32 *p;
4449
4450 *res = 0;
4451 if (likely(bitmap[0] & hint_bit)) {
4452 p = xdr_inline_decode(xdr, 8);
4453 if (unlikely(!p))
4454 goto out_overflow;
4455 xdr_decode_hyper(p, res);
4456 }
4457 return 0;
4458out_overflow:
4459 print_overflow_msg(__func__, xdr);
4460 return -EIO;
4461}
4462
4463static int decode_first_threshold_item4(struct xdr_stream *xdr,
4464 struct nfs4_threshold *res)
4465{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004466 __be32 *p;
4467 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004468 uint32_t bitmap[3] = {0,}, attrlen;
4469 int status;
4470
4471 /* layout type */
4472 p = xdr_inline_decode(xdr, 4);
4473 if (unlikely(!p)) {
4474 print_overflow_msg(__func__, xdr);
4475 return -EIO;
4476 }
4477 res->l_type = be32_to_cpup(p);
4478
4479 /* thi_hintset bitmap */
4480 status = decode_attr_bitmap(xdr, bitmap);
4481 if (status < 0)
4482 goto xdr_error;
4483
4484 /* thi_hintlist length */
4485 status = decode_attr_length(xdr, &attrlen, &savep);
4486 if (status < 0)
4487 goto xdr_error;
4488 /* thi_hintlist */
4489 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4490 if (status < 0)
4491 goto xdr_error;
4492 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4493 if (status < 0)
4494 goto xdr_error;
4495 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4496 THRESHOLD_RD_IO);
4497 if (status < 0)
4498 goto xdr_error;
4499 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4500 THRESHOLD_WR_IO);
4501 if (status < 0)
4502 goto xdr_error;
4503
4504 status = verify_attr_len(xdr, savep, attrlen);
4505 res->bm = bitmap[0];
4506
4507 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4508 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4509 res->wr_io_sz);
4510xdr_error:
4511 dprintk("%s ret=%d!\n", __func__, status);
4512 return status;
4513}
4514
4515/*
4516 * Thresholds on pNFS direct I/O vrs MDS I/O
4517 */
4518static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4519 uint32_t *bitmap,
4520 struct nfs4_threshold *res)
4521{
4522 __be32 *p;
4523 int status = 0;
4524 uint32_t num;
4525
4526 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4527 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004528 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004529 /* Did the server return an unrequested attribute? */
4530 if (unlikely(res == NULL))
4531 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004532 p = xdr_inline_decode(xdr, 4);
4533 if (unlikely(!p))
4534 goto out_overflow;
4535 num = be32_to_cpup(p);
4536 if (num == 0)
4537 return 0;
4538 if (num > 1)
4539 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4540 "drivers per filesystem not supported\n",
4541 __func__);
4542
4543 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004544 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004545 }
4546 return status;
4547out_overflow:
4548 print_overflow_msg(__func__, xdr);
4549 return -EIO;
4550}
4551
Bryan Schumakerae42c702010-10-21 16:33:17 -04004552static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4553 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004554 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004555 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004556{
Trond Myklebustbca79472009-03-11 14:10:26 -04004557 int status;
4558 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004559 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004560 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004562 status = decode_attr_type(xdr, bitmap, &type);
4563 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004564 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004565 fattr->mode = 0;
4566 if (status != 0) {
4567 fattr->mode |= nfs_type2fmt[type];
4568 fattr->valid |= status;
4569 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004571 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4572 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004574 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004575
4576 status = decode_attr_size(xdr, bitmap, &fattr->size);
4577 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004578 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004579 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004580
4581 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4582 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004583 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004584 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004585
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004586 err = 0;
4587 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004588 if (status < 0)
4589 goto xdr_error;
4590
4591 status = decode_attr_filehandle(xdr, bitmap, fh);
4592 if (status < 0)
4593 goto xdr_error;
4594
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004595 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
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
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004600 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004601 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004602 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004603 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004604
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004605 status = -EIO;
4606 if (unlikely(bitmap[0]))
4607 goto xdr_error;
4608
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004609 status = decode_attr_mode(xdr, bitmap, &fmode);
4610 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004612 if (status != 0) {
4613 fattr->mode |= fmode;
4614 fattr->valid |= status;
4615 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004616
4617 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4618 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004620 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004621
Trond Myklebust6926afd2012-01-07 13:22:46 -05004622 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004623 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004625 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004626
Trond Myklebust6926afd2012-01-07 13:22:46 -05004627 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004628 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004630 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004631
4632 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4633 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004635 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004636
4637 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4638 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004640 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004641
4642 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4643 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004645 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004646
4647 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4648 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004650 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004651
4652 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4653 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004655 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004656
Trond Myklebust28331a42011-04-27 13:47:52 -04004657 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004658 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004659 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004660 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004661
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004662 status = -EIO;
4663 if (unlikely(bitmap[1]))
4664 goto xdr_error;
4665
Andy Adamson88034c32012-05-23 05:02:34 -04004666 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4667 if (status < 0)
4668 goto xdr_error;
4669
David Quigleyaa9c2662013-05-22 12:50:44 -04004670 if (label) {
4671 status = decode_attr_security_label(xdr, bitmap, label);
4672 if (status < 0)
4673 goto xdr_error;
4674 fattr->valid |= status;
4675 }
4676
Bryan Schumakerae42c702010-10-21 16:33:17 -04004677xdr_error:
4678 dprintk("%s: xdr returned %d\n", __func__, -status);
4679 return status;
4680}
4681
4682static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004683 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004684 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004685{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004686 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004687 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004688 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004689 int status;
4690
4691 status = decode_op_hdr(xdr, OP_GETATTR);
4692 if (status < 0)
4693 goto xdr_error;
4694
4695 status = decode_attr_bitmap(xdr, bitmap);
4696 if (status < 0)
4697 goto xdr_error;
4698
4699 status = decode_attr_length(xdr, &attrlen, &savep);
4700 if (status < 0)
4701 goto xdr_error;
4702
David Quigleyaa9c2662013-05-22 12:50:44 -04004703 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4704 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004705 if (status < 0)
4706 goto xdr_error;
4707
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004708 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004710 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711 return status;
4712}
4713
David Quigleyaa9c2662013-05-22 12:50:44 -04004714static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4715 struct nfs4_label *label, const struct nfs_server *server)
4716{
4717 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4718}
4719
Bryan Schumakerae42c702010-10-21 16:33:17 -04004720static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004721 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004722{
David Quigleyaa9c2662013-05-22 12:50:44 -04004723 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004724}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725
Andy Adamson504913f2010-10-20 00:17:57 -04004726/*
Jeff Layton3132e492016-08-10 15:58:24 -04004727 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004728 */
Jeff Layton3132e492016-08-10 15:58:24 -04004729static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004730 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004731{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004732 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004733 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004734
4735 p = xdr_inline_decode(xdr, 4);
4736 if (unlikely(!p))
4737 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004738 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004739
4740 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004741 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004742 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004743
4744 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004745 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004746 if (unlikely(!p))
4747 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004748
4749 /* If we get too many, then just cap it at the max */
4750 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4751 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4752 __func__, fsinfo->nlayouttypes);
4753 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4754 }
4755
4756 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4757 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004758 return 0;
4759out_overflow:
4760 print_overflow_msg(__func__, xdr);
4761 return -EIO;
4762}
4763
4764/*
4765 * The type of file system exported.
4766 * Note we must ensure that layouttype is set in any non-error case.
4767 */
4768static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004769 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004770{
4771 int status = 0;
4772
4773 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4774 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4775 return -EIO;
4776 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004777 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004778 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004779 }
Andy Adamson504913f2010-10-20 00:17:57 -04004780 return status;
4781}
4782
Fred Isamandae100c2011-07-30 20:52:37 -04004783/*
4784 * The prefered block size for layout directed io
4785 */
4786static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4787 uint32_t *res)
4788{
4789 __be32 *p;
4790
4791 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4792 *res = 0;
4793 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4794 p = xdr_inline_decode(xdr, 4);
4795 if (unlikely(!p)) {
4796 print_overflow_msg(__func__, xdr);
4797 return -EIO;
4798 }
4799 *res = be32_to_cpup(p);
4800 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4801 }
4802 return 0;
4803}
4804
Peng Tao2a92ee92015-09-26 02:24:37 +08004805/*
4806 * The granularity of a CLONE operation.
4807 */
4808static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4809 uint32_t *res)
4810{
4811 __be32 *p;
4812
4813 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4814 *res = 0;
4815 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4816 p = xdr_inline_decode(xdr, 4);
4817 if (unlikely(!p)) {
4818 print_overflow_msg(__func__, xdr);
4819 return -EIO;
4820 }
4821 *res = be32_to_cpup(p);
4822 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4823 }
4824 return 0;
4825}
4826
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4828{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004829 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004830 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004831 int status;
4832
4833 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4834 goto xdr_error;
4835 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4836 goto xdr_error;
4837 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4838 goto xdr_error;
4839
4840 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4841
4842 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4843 goto xdr_error;
4844 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4845 goto xdr_error;
4846 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4847 goto xdr_error;
4848 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4849 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4850 goto xdr_error;
4851 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004852
4853 status = -EIO;
4854 if (unlikely(bitmap[0]))
4855 goto xdr_error;
4856
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004857 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4858 if (status != 0)
4859 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004860 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004861 if (status != 0)
4862 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004863
4864 status = -EIO;
4865 if (unlikely(bitmap[1]))
4866 goto xdr_error;
4867
Fred Isamandae100c2011-07-30 20:52:37 -04004868 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4869 if (status)
4870 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004871 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4872 if (status)
4873 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874
4875 status = verify_attr_len(xdr, savep, attrlen);
4876xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004877 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 return status;
4879}
4880
4881static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4882{
Al Viro8687b632006-10-19 23:28:48 -07004883 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004884 uint32_t len;
4885 int status;
4886
Trond Myklebust99367812007-07-17 21:52:41 -04004887 /* Zero handle first to allow comparisons */
4888 memset(fh, 0, sizeof(*fh));
4889
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 status = decode_op_hdr(xdr, OP_GETFH);
4891 if (status)
4892 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893
Benny Halevyc0eae662009-08-14 17:20:14 +03004894 p = xdr_inline_decode(xdr, 4);
4895 if (unlikely(!p))
4896 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004897 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 if (len > NFS4_FHSIZE)
4899 return -EIO;
4900 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004901 p = xdr_inline_decode(xdr, len);
4902 if (unlikely(!p))
4903 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004904 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004906out_overflow:
4907 print_overflow_msg(__func__, xdr);
4908 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004909}
4910
4911static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4912{
4913 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004914
Linus Torvalds1da177e2005-04-16 15:20:36 -07004915 status = decode_op_hdr(xdr, OP_LINK);
4916 if (status)
4917 return status;
4918 return decode_change_info(xdr, cinfo);
4919}
4920
4921/*
4922 * We create the owner, so we know a proper owner.id length is 4.
4923 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004924static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004926 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004927 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004928 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004929
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004930 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004931 if (unlikely(!p))
4932 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004933 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004934 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004935 type = be32_to_cpup(p++); /* 4 byte read */
4936 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004937 fl->fl_start = (loff_t)offset;
4938 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4939 if (length == ~(uint64_t)0)
4940 fl->fl_end = OFFSET_MAX;
4941 fl->fl_type = F_WRLCK;
4942 if (type & 1)
4943 fl->fl_type = F_RDLCK;
4944 fl->fl_pid = 0;
4945 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004946 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4947 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4948 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004949 if (likely(p))
4950 return -NFS4ERR_DENIED;
4951out_overflow:
4952 print_overflow_msg(__func__, xdr);
4953 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954}
4955
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004956static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 int status;
4959
4960 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004961 if (status == -EIO)
4962 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04004964 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004965 if (unlikely(status))
4966 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004968 status = decode_lock_denied(xdr, NULL);
4969 if (res->open_seqid != NULL)
4970 nfs_increment_open_seqid(status, res->open_seqid);
4971 nfs_increment_lock_seqid(status, res->lock_seqid);
4972out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973 return status;
4974}
4975
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004976static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977{
4978 int status;
4979 status = decode_op_hdr(xdr, OP_LOCKT);
4980 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004981 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982 return status;
4983}
4984
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004985static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987 int status;
4988
4989 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004990 if (status != -EIO)
4991 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004992 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04004993 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994 return status;
4995}
4996
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004997static int decode_release_lockowner(struct xdr_stream *xdr)
4998{
4999 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5000}
5001
Linus Torvalds1da177e2005-04-16 15:20:36 -07005002static int decode_lookup(struct xdr_stream *xdr)
5003{
5004 return decode_op_hdr(xdr, OP_LOOKUP);
5005}
5006
5007/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005008static int decode_space_limit(struct xdr_stream *xdr,
5009 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010{
Andy Adamson05d564f2008-12-23 16:06:15 -05005011 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005012 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005013 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005014
Benny Halevyc0eae662009-08-14 17:20:14 +03005015 p = xdr_inline_decode(xdr, 12);
5016 if (unlikely(!p))
5017 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005018 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005020 case NFS4_LIMIT_SIZE:
5021 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005022 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005023 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005024 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005025 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005026 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005027 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005028 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005029 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005030 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005031out_overflow:
5032 print_overflow_msg(__func__, xdr);
5033 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034}
5035
Trond Myklebust6ae37332015-01-30 14:21:14 -05005036static int decode_rw_delegation(struct xdr_stream *xdr,
5037 uint32_t delegation_type,
5038 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005039{
Andy Adamson05d564f2008-12-23 16:06:15 -05005040 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005041 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005042
Trond Myklebust93b717f2016-05-16 17:42:43 -04005043 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005044 if (unlikely(status))
5045 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005046 p = xdr_inline_decode(xdr, 4);
5047 if (unlikely(!p))
5048 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005049 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005050
Linus Torvalds1da177e2005-04-16 15:20:36 -07005051 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005052 case NFS4_OPEN_DELEGATE_READ:
5053 res->delegation_type = FMODE_READ;
5054 break;
5055 case NFS4_OPEN_DELEGATE_WRITE:
5056 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005057 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058 return -EIO;
5059 }
David Howells7539bba2006-08-22 20:06:09 -04005060 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03005061out_overflow:
5062 print_overflow_msg(__func__, xdr);
5063 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005064}
5065
Trond Myklebust6ae37332015-01-30 14:21:14 -05005066static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5067{
5068 __be32 *p;
5069 uint32_t why_no_delegation;
5070
5071 p = xdr_inline_decode(xdr, 4);
5072 if (unlikely(!p))
5073 goto out_overflow;
5074 why_no_delegation = be32_to_cpup(p);
5075 switch (why_no_delegation) {
5076 case WND4_CONTENTION:
5077 case WND4_RESOURCE:
5078 xdr_inline_decode(xdr, 4);
5079 /* Ignore for now */
5080 }
5081 return 0;
5082out_overflow:
5083 print_overflow_msg(__func__, xdr);
5084 return -EIO;
5085}
5086
5087static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5088{
5089 __be32 *p;
5090 uint32_t delegation_type;
5091
5092 p = xdr_inline_decode(xdr, 4);
5093 if (unlikely(!p))
5094 goto out_overflow;
5095 delegation_type = be32_to_cpup(p);
5096 res->delegation_type = 0;
5097 switch (delegation_type) {
5098 case NFS4_OPEN_DELEGATE_NONE:
5099 return 0;
5100 case NFS4_OPEN_DELEGATE_READ:
5101 case NFS4_OPEN_DELEGATE_WRITE:
5102 return decode_rw_delegation(xdr, delegation_type, res);
5103 case NFS4_OPEN_DELEGATE_NONE_EXT:
5104 return decode_no_delegation(xdr, res);
5105 }
5106 return -EIO;
5107out_overflow:
5108 print_overflow_msg(__func__, xdr);
5109 return -EIO;
5110}
5111
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5113{
Andy Adamson05d564f2008-12-23 16:06:15 -05005114 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005115 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005116 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117
Trond Myklebustc7848f62013-12-04 17:39:23 -05005118 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5119 return status;
5120 nfs_increment_open_seqid(status, res->seqid);
5121 if (status)
5122 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005123 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005124 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005125 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005126
Andy Adamson05d564f2008-12-23 16:06:15 -05005127 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128
Benny Halevyc0eae662009-08-14 17:20:14 +03005129 p = xdr_inline_decode(xdr, 8);
5130 if (unlikely(!p))
5131 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005132 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005133 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005134 if (bmlen > 10)
5135 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136
Benny Halevyc0eae662009-08-14 17:20:14 +03005137 p = xdr_inline_decode(xdr, bmlen << 2);
5138 if (unlikely(!p))
5139 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005140 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5141 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005142 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005143 for (; i < NFS4_BITMAP_SIZE; i++)
5144 res->attrset[i] = 0;
5145
Linus Torvalds1da177e2005-04-16 15:20:36 -07005146 return decode_delegation(xdr, res);
5147xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005148 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005149 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005150out_overflow:
5151 print_overflow_msg(__func__, xdr);
5152 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153}
5154
5155static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5156{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157 int status;
5158
Andy Adamson05d564f2008-12-23 16:06:15 -05005159 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005160 if (status != -EIO)
5161 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005162 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005163 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005164 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005165}
5166
5167static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5168{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005169 int status;
5170
5171 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005172 if (status != -EIO)
5173 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005174 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005175 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005176 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177}
5178
5179static int decode_putfh(struct xdr_stream *xdr)
5180{
5181 return decode_op_hdr(xdr, OP_PUTFH);
5182}
5183
5184static int decode_putrootfh(struct xdr_stream *xdr)
5185{
5186 return decode_op_hdr(xdr, OP_PUTROOTFH);
5187}
5188
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005189static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5190 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005191{
Al Viro8687b632006-10-19 23:28:48 -07005192 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005193 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194 int status;
5195
5196 status = decode_op_hdr(xdr, OP_READ);
5197 if (status)
5198 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005199 p = xdr_inline_decode(xdr, 8);
5200 if (unlikely(!p))
5201 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005202 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005203 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005204 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005206 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207 "count %u > recvd %u\n", count, recvd);
5208 count = recvd;
5209 eof = 0;
5210 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005211 res->eof = eof;
5212 res->count = count;
5213 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005214out_overflow:
5215 print_overflow_msg(__func__, xdr);
5216 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005217}
5218
5219static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5220{
Chuck Leverbcecff72007-10-26 13:32:03 -04005221 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005222 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223
5224 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005225 if (!status)
5226 status = decode_verifier(xdr, readdir->verifier.data);
5227 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005229 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005230 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005231 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005232 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005233}
5234
5235static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5236{
5237 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005238 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005239 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240 int status;
5241
5242 status = decode_op_hdr(xdr, OP_READLINK);
5243 if (status)
5244 return status;
5245
5246 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005247 p = xdr_inline_decode(xdr, 4);
5248 if (unlikely(!p))
5249 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005250 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005251 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005252 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005253 return -ENAMETOOLONG;
5254 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005255 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005256 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005257 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005258 "count %u > recvd %u\n", len, recvd);
5259 return -EIO;
5260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005261 /*
5262 * The XDR encode routine has set things up so that
5263 * the link text will be copied directly into the
5264 * buffer. We just have to do overflow-checking,
5265 * and and null-terminate the text (the VFS expects
5266 * null-termination).
5267 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005268 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005270out_overflow:
5271 print_overflow_msg(__func__, xdr);
5272 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005273}
5274
5275static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5276{
5277 int status;
5278
5279 status = decode_op_hdr(xdr, OP_REMOVE);
5280 if (status)
5281 goto out;
5282 status = decode_change_info(xdr, cinfo);
5283out:
5284 return status;
5285}
5286
5287static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5288 struct nfs4_change_info *new_cinfo)
5289{
5290 int status;
5291
5292 status = decode_op_hdr(xdr, OP_RENAME);
5293 if (status)
5294 goto out;
5295 if ((status = decode_change_info(xdr, old_cinfo)))
5296 goto out;
5297 status = decode_change_info(xdr, new_cinfo);
5298out:
5299 return status;
5300}
5301
5302static int decode_renew(struct xdr_stream *xdr)
5303{
5304 return decode_op_hdr(xdr, OP_RENEW);
5305}
5306
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005307static int
5308decode_restorefh(struct xdr_stream *xdr)
5309{
5310 return decode_op_hdr(xdr, OP_RESTOREFH);
5311}
5312
J. Bruce Fields029d1052005-06-22 17:16:22 +00005313static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005314 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005315{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005316 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005317 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005318 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005319 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005320 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005321
Andy Adamsonbf118a32011-12-07 11:55:27 -05005322 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005323 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5324 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005325
Trond Myklebust519d3952012-08-14 17:30:10 -04005326 xdr_enter_page(xdr, xdr->buf->page_len);
5327
Trond Myklebustcff298c2012-08-14 17:14:17 -04005328 /* Calculate the offset of the page data */
5329 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005330
J. Bruce Fields029d1052005-06-22 17:16:22 +00005331 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5332 goto out;
5333 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5334 goto out;
5335
5336 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5337 return -EIO;
5338 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005339
Andy Adamsonbf118a32011-12-07 11:55:27 -05005340 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5341 * are stored with the acl data to handle the problem of
5342 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005343 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005344 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005345
5346 /* Check for receive buffer overflow */
5347 if (res->acl_len > (xdr->nwords << 2) ||
5348 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5349 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005350 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005351 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005352 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005353 } else
5354 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005355
5356out:
5357 return status;
5358}
5359
Linus Torvalds1da177e2005-04-16 15:20:36 -07005360static int
5361decode_savefh(struct xdr_stream *xdr)
5362{
5363 return decode_op_hdr(xdr, OP_SAVEFH);
5364}
5365
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005366static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005367{
Al Viro8687b632006-10-19 23:28:48 -07005368 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005369 uint32_t bmlen;
5370 int status;
5371
Linus Torvalds1da177e2005-04-16 15:20:36 -07005372 status = decode_op_hdr(xdr, OP_SETATTR);
5373 if (status)
5374 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005375 p = xdr_inline_decode(xdr, 4);
5376 if (unlikely(!p))
5377 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005378 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005379 p = xdr_inline_decode(xdr, bmlen << 2);
5380 if (likely(p))
5381 return 0;
5382out_overflow:
5383 print_overflow_msg(__func__, xdr);
5384 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005385}
5386
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005387static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005388{
Al Viro8687b632006-10-19 23:28:48 -07005389 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005390 uint32_t opnum;
5391 int32_t nfserr;
5392
Benny Halevyc0eae662009-08-14 17:20:14 +03005393 p = xdr_inline_decode(xdr, 8);
5394 if (unlikely(!p))
5395 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005396 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005397 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005398 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005399 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005400 return -EIO;
5401 }
Benny Halevycccddf42009-08-14 17:20:19 +03005402 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005403 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005404 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5405 if (unlikely(!p))
5406 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005407 p = xdr_decode_hyper(p, &res->clientid);
5408 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005409 } else if (nfserr == NFSERR_CLID_INUSE) {
5410 uint32_t len;
5411
5412 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005413 p = xdr_inline_decode(xdr, 4);
5414 if (unlikely(!p))
5415 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005416 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005417 p = xdr_inline_decode(xdr, len);
5418 if (unlikely(!p))
5419 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005420
5421 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005422 p = xdr_inline_decode(xdr, 4);
5423 if (unlikely(!p))
5424 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005425 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005426 p = xdr_inline_decode(xdr, len);
5427 if (unlikely(!p))
5428 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005429 return -NFSERR_CLID_INUSE;
5430 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005431 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005432
5433 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005434out_overflow:
5435 print_overflow_msg(__func__, xdr);
5436 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005437}
5438
5439static int decode_setclientid_confirm(struct xdr_stream *xdr)
5440{
5441 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5442}
5443
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005444static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005445{
Al Viro8687b632006-10-19 23:28:48 -07005446 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005447 int status;
5448
5449 status = decode_op_hdr(xdr, OP_WRITE);
5450 if (status)
5451 return status;
5452
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005453 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005454 if (unlikely(!p))
5455 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005456 res->count = be32_to_cpup(p++);
5457 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005458 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005459out_overflow:
5460 print_overflow_msg(__func__, xdr);
5461 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005462}
5463
5464static int decode_delegreturn(struct xdr_stream *xdr)
5465{
5466 return decode_op_hdr(xdr, OP_DELEGRETURN);
5467}
5468
Chuck Leverfb15b262013-03-16 15:54:34 -04005469static int decode_secinfo_gss(struct xdr_stream *xdr,
5470 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005471{
Chuck Leverfb15b262013-03-16 15:54:34 -04005472 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005473 __be32 *p;
5474
5475 p = xdr_inline_decode(xdr, 4);
5476 if (unlikely(!p))
5477 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005478 oid_len = be32_to_cpup(p);
5479 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005480 goto out_err;
5481
Chuck Leverfb15b262013-03-16 15:54:34 -04005482 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005483 if (unlikely(!p))
5484 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005485 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5486 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005487
5488 p = xdr_inline_decode(xdr, 8);
5489 if (unlikely(!p))
5490 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005491 flavor->flavor_info.qop = be32_to_cpup(p++);
5492 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005493
5494 return 0;
5495
5496out_overflow:
5497 print_overflow_msg(__func__, xdr);
5498 return -EIO;
5499out_err:
5500 return -EINVAL;
5501}
5502
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005503static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005504{
Chuck Leverfb15b262013-03-16 15:54:34 -04005505 struct nfs4_secinfo4 *sec_flavor;
5506 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005507 int status;
5508 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005509
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005510 p = xdr_inline_decode(xdr, 4);
5511 if (unlikely(!p))
5512 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005513
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005514 res->flavors->num_flavors = 0;
5515 num_flavors = be32_to_cpup(p);
5516
5517 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005518 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005519 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005520 break;
5521
5522 p = xdr_inline_decode(xdr, 4);
5523 if (unlikely(!p))
5524 goto out_overflow;
5525 sec_flavor->flavor = be32_to_cpup(p);
5526
5527 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005528 status = decode_secinfo_gss(xdr, sec_flavor);
5529 if (status)
5530 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005531 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005532 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005533 }
5534
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005535 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005536out:
5537 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005538out_overflow:
5539 print_overflow_msg(__func__, xdr);
5540 return -EIO;
5541}
5542
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005543static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5544{
5545 int status = decode_op_hdr(xdr, OP_SECINFO);
5546 if (status)
5547 return status;
5548 return decode_secinfo_common(xdr, res);
5549}
5550
Benny Halevy99fe60d2009-04-01 09:22:29 -04005551#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005552static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5553{
5554 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5555 if (status)
5556 return status;
5557 return decode_secinfo_common(xdr, res);
5558}
5559
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005560static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5561{
5562 __be32 *p;
5563 uint32_t bitmap_words;
5564 unsigned int i;
5565
5566 p = xdr_inline_decode(xdr, 4);
5567 bitmap_words = be32_to_cpup(p++);
5568 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5569 return -EIO;
5570 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5571 for (i = 0; i < bitmap_words; i++)
5572 op_map->u.words[i] = be32_to_cpup(p++);
5573
5574 return 0;
5575}
5576
Benny Halevy99fe60d2009-04-01 09:22:29 -04005577static int decode_exchange_id(struct xdr_stream *xdr,
5578 struct nfs41_exchange_id_res *res)
5579{
5580 __be32 *p;
5581 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005582 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005583 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005584 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005585
5586 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5587 if (status)
5588 return status;
5589
Benny Halevyc0eae662009-08-14 17:20:14 +03005590 p = xdr_inline_decode(xdr, 8);
5591 if (unlikely(!p))
5592 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005593 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005594 p = xdr_inline_decode(xdr, 12);
5595 if (unlikely(!p))
5596 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005597 res->seqid = be32_to_cpup(p++);
5598 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005599
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005600 res->state_protect.how = be32_to_cpup(p);
5601 switch (res->state_protect.how) {
5602 case SP4_NONE:
5603 break;
5604 case SP4_MACH_CRED:
5605 status = decode_op_map(xdr, &res->state_protect.enforce);
5606 if (status)
5607 return status;
5608 status = decode_op_map(xdr, &res->state_protect.allow);
5609 if (status)
5610 return status;
5611 break;
5612 default:
5613 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005614 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005615 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005616
Chuck Leveracdeb692012-05-21 22:46:16 -04005617 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005618 p = xdr_inline_decode(xdr, 8);
5619 if (unlikely(!p))
5620 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005621 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005622
Chuck Leveracdeb692012-05-21 22:46:16 -04005623 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005624 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5625 if (unlikely(status))
5626 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005627 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5628 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005629 memcpy(res->server_owner->major_id, dummy_str, dummy);
5630 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005631
Chuck Leveracdeb692012-05-21 22:46:16 -04005632 /* server_scope4 */
5633 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5634 if (unlikely(status))
5635 return status;
5636 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5637 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005638 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5639 res->server_scope->server_scope_sz = dummy;
5640
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005641 /* Implementation Id */
5642 p = xdr_inline_decode(xdr, 4);
5643 if (unlikely(!p))
5644 goto out_overflow;
5645 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005646
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005647 if (impl_id_count) {
5648 /* nii_domain */
5649 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5650 if (unlikely(status))
5651 return status;
5652 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5653 return -EIO;
5654 memcpy(res->impl_id->domain, dummy_str, dummy);
5655
5656 /* nii_name */
5657 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5658 if (unlikely(status))
5659 return status;
5660 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5661 return -EIO;
5662 memcpy(res->impl_id->name, dummy_str, dummy);
5663
5664 /* nii_date */
5665 p = xdr_inline_decode(xdr, 12);
5666 if (unlikely(!p))
5667 goto out_overflow;
5668 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5669 res->impl_id->date.nseconds = be32_to_cpup(p);
5670
5671 /* if there's more than one entry, ignore the rest */
5672 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005673 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005674out_overflow:
5675 print_overflow_msg(__func__, xdr);
5676 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005677}
Andy Adamsonfc931582009-04-01 09:22:31 -04005678
5679static int decode_chan_attrs(struct xdr_stream *xdr,
5680 struct nfs4_channel_attrs *attrs)
5681{
5682 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005683 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005684
Benny Halevyc0eae662009-08-14 17:20:14 +03005685 p = xdr_inline_decode(xdr, 28);
5686 if (unlikely(!p))
5687 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005688 val = be32_to_cpup(p++); /* headerpadsz */
5689 if (val)
5690 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005691 attrs->max_rqst_sz = be32_to_cpup(p++);
5692 attrs->max_resp_sz = be32_to_cpup(p++);
5693 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5694 attrs->max_ops = be32_to_cpup(p++);
5695 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005696 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005697 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005698 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5699 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005700 return -EINVAL;
5701 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005702 if (nr_attrs == 1) {
5703 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5704 if (unlikely(!p))
5705 goto out_overflow;
5706 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005707 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005708out_overflow:
5709 print_overflow_msg(__func__, xdr);
5710 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005711}
5712
Benny Halevye78291e2009-08-14 17:20:00 +03005713static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5714{
5715 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005716}
5717
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005718static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5719 struct nfs41_bind_conn_to_session_res *res)
5720{
5721 __be32 *p;
5722 int status;
5723
5724 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5725 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005726 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005727 if (unlikely(status))
5728 return status;
5729
5730 /* dir flags, rdma mode bool */
5731 p = xdr_inline_decode(xdr, 8);
5732 if (unlikely(!p))
5733 goto out_overflow;
5734
5735 res->dir = be32_to_cpup(p++);
5736 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5737 return -EIO;
5738 if (be32_to_cpup(p) == 0)
5739 res->use_conn_in_rdma_mode = false;
5740 else
5741 res->use_conn_in_rdma_mode = true;
5742
5743 return 0;
5744out_overflow:
5745 print_overflow_msg(__func__, xdr);
5746 return -EIO;
5747}
5748
Andy Adamsonfc931582009-04-01 09:22:31 -04005749static int decode_create_session(struct xdr_stream *xdr,
5750 struct nfs41_create_session_res *res)
5751{
5752 __be32 *p;
5753 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005754
5755 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005756 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005757 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005758 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005759 return status;
5760
Andy Adamsonfc931582009-04-01 09:22:31 -04005761 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005762 p = xdr_inline_decode(xdr, 8);
5763 if (unlikely(!p))
5764 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005765 res->seqid = be32_to_cpup(p++);
5766 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005767
5768 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005769 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005770 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005771 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005772 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005773out_overflow:
5774 print_overflow_msg(__func__, xdr);
5775 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005776}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005777
5778static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5779{
5780 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5781}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005782
Trond Myklebust66245532012-05-25 17:18:09 -04005783static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5784{
5785 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5786}
5787
Ricardo Labiaga180197532009-12-05 16:08:40 -05005788static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5789{
5790 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5791}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005792#endif /* CONFIG_NFS_V4_1 */
5793
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005794static int decode_sequence(struct xdr_stream *xdr,
5795 struct nfs4_sequence_res *res,
5796 struct rpc_rqst *rqstp)
5797{
5798#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005799 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005800 struct nfs4_sessionid id;
5801 u32 dummy;
5802 int status;
5803 __be32 *p;
5804
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005805 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005806 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005807 if (!res->sr_slot->table->session)
5808 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005809
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005810 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005811 if (!status)
5812 status = decode_sessionid(xdr, &id);
5813 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005814 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005815
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005816 /*
5817 * If the server returns different values for sessionID, slotID or
5818 * sequence number, the server is looney tunes.
5819 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005820 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005821 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005822
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005823 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005824 NFS4_MAX_SESSIONID_LEN)) {
5825 dprintk("%s Invalid session id\n", __func__);
5826 goto out_err;
5827 }
Benny Halevye78291e2009-08-14 17:20:00 +03005828
Benny Halevyc0eae662009-08-14 17:20:14 +03005829 p = xdr_inline_decode(xdr, 20);
5830 if (unlikely(!p))
5831 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005832
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005833 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005834 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005835 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005836 dprintk("%s Invalid sequence number\n", __func__);
5837 goto out_err;
5838 }
5839 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005840 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005841 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005842 dprintk("%s Invalid slot id\n", __func__);
5843 goto out_err;
5844 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005845 /* highest slot id */
5846 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005847 /* target highest slot id */
5848 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005849 /* result flags */
5850 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005851 status = 0;
5852out_err:
5853 res->sr_status = status;
5854 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005855out_overflow:
5856 print_overflow_msg(__func__, xdr);
5857 status = -EIO;
5858 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005859#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005860 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005861#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005862}
5863
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005864#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005865static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5866{
5867 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5868 return decode_stateid(xdr, stateid);
5869}
5870
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005871static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005872 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005873{
Trond Myklebust4e590802015-03-09 14:01:25 -04005874 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005875 __be32 *p;
5876 uint32_t len, type;
5877 int status;
5878
5879 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5880 if (status) {
5881 if (status == -ETOOSMALL) {
5882 p = xdr_inline_decode(xdr, 4);
5883 if (unlikely(!p))
5884 goto out_overflow;
5885 pdev->mincount = be32_to_cpup(p);
5886 dprintk("%s: Min count too small. mincnt = %u\n",
5887 __func__, pdev->mincount);
5888 }
5889 return status;
5890 }
5891
5892 p = xdr_inline_decode(xdr, 8);
5893 if (unlikely(!p))
5894 goto out_overflow;
5895 type = be32_to_cpup(p++);
5896 if (type != pdev->layout_type) {
5897 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5898 __func__, pdev->layout_type, type);
5899 return -EINVAL;
5900 }
5901 /*
5902 * Get the length of the opaque device_addr4. xdr_read_pages places
5903 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5904 * and places the remaining xdr data in xdr_buf->tail
5905 */
5906 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005907 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5908 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005909
5910 /* Parse notification bitmap, verifying that it is zero. */
5911 p = xdr_inline_decode(xdr, 4);
5912 if (unlikely(!p))
5913 goto out_overflow;
5914 len = be32_to_cpup(p);
5915 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005916 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005917
5918 p = xdr_inline_decode(xdr, 4 * len);
5919 if (unlikely(!p))
5920 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005921
Trond Myklebust4e590802015-03-09 14:01:25 -04005922 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005923 for (i = 1; i < len; i++) {
5924 if (be32_to_cpup(p++)) {
5925 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005926 __func__);
5927 return -EIO;
5928 }
5929 }
5930 }
5931 return 0;
5932out_overflow:
5933 print_overflow_msg(__func__, xdr);
5934 return -EIO;
5935}
5936
5937static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5938 struct nfs4_layoutget_res *res)
5939{
5940 __be32 *p;
5941 int status;
5942 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005943 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005944
5945 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5946 if (status)
5947 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005948 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005949 if (unlikely(!p))
5950 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005951 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04005952 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005953 p = xdr_inline_decode(xdr, 4);
5954 if (unlikely(!p))
5955 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005956 layout_count = be32_to_cpup(p);
5957 if (!layout_count) {
5958 dprintk("%s: server responded with empty layout array\n",
5959 __func__);
5960 return -EINVAL;
5961 }
5962
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005963 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005964 if (unlikely(!p))
5965 goto out_overflow;
5966 p = xdr_decode_hyper(p, &res->range.offset);
5967 p = xdr_decode_hyper(p, &res->range.length);
5968 res->range.iomode = be32_to_cpup(p++);
5969 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005970 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005971
5972 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5973 __func__,
5974 (unsigned long)res->range.offset,
5975 (unsigned long)res->range.length,
5976 res->range.iomode,
5977 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005978 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005979
Trond Myklebust64bd5772012-06-20 22:35:05 -04005980 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005981 if (res->layoutp->len > recvd) {
5982 dprintk("NFS: server cheating in layoutget reply: "
5983 "layout len %u > recvd %u\n",
5984 res->layoutp->len, recvd);
5985 return -EINVAL;
5986 }
5987
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005988 if (layout_count > 1) {
5989 /* We only handle a length one array at the moment. Any
5990 * further entries are just ignored. Note that this means
5991 * the client may see a response that is less than the
5992 * minimum it requested.
5993 */
5994 dprintk("%s: server responded with %d layouts, dropping tail\n",
5995 __func__, layout_count);
5996 }
5997
5998 return 0;
5999out_overflow:
6000 print_overflow_msg(__func__, xdr);
6001 return -EIO;
6002}
Andy Adamson863a3c62011-03-23 13:27:54 +00006003
Benny Halevycbe82602011-05-22 19:52:37 +03006004static int decode_layoutreturn(struct xdr_stream *xdr,
6005 struct nfs4_layoutreturn_res *res)
6006{
6007 __be32 *p;
6008 int status;
6009
6010 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6011 if (status)
6012 return status;
6013 p = xdr_inline_decode(xdr, 4);
6014 if (unlikely(!p))
6015 goto out_overflow;
6016 res->lrs_present = be32_to_cpup(p);
6017 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04006018 status = decode_layout_stateid(xdr, &res->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03006019 return status;
6020out_overflow:
6021 print_overflow_msg(__func__, xdr);
6022 return -EIO;
6023}
6024
Andy Adamson863a3c62011-03-23 13:27:54 +00006025static int decode_layoutcommit(struct xdr_stream *xdr,
6026 struct rpc_rqst *req,
6027 struct nfs4_layoutcommit_res *res)
6028{
6029 __be32 *p;
6030 __u32 sizechanged;
6031 int status;
6032
6033 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04006034 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00006035 if (status)
6036 return status;
6037
6038 p = xdr_inline_decode(xdr, 4);
6039 if (unlikely(!p))
6040 goto out_overflow;
6041 sizechanged = be32_to_cpup(p);
6042
6043 if (sizechanged) {
6044 /* throw away new size */
6045 p = xdr_inline_decode(xdr, 8);
6046 if (unlikely(!p))
6047 goto out_overflow;
6048 }
6049 return 0;
6050out_overflow:
6051 print_overflow_msg(__func__, xdr);
6052 return -EIO;
6053}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006054
6055static int decode_test_stateid(struct xdr_stream *xdr,
6056 struct nfs41_test_stateid_res *res)
6057{
6058 __be32 *p;
6059 int status;
6060 int num_res;
6061
6062 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6063 if (status)
6064 return status;
6065
6066 p = xdr_inline_decode(xdr, 4);
6067 if (unlikely(!p))
6068 goto out_overflow;
6069 num_res = be32_to_cpup(p++);
6070 if (num_res != 1)
6071 goto out;
6072
6073 p = xdr_inline_decode(xdr, 4);
6074 if (unlikely(!p))
6075 goto out_overflow;
6076 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006077
6078 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006079out_overflow:
6080 print_overflow_msg(__func__, xdr);
6081out:
6082 return -EIO;
6083}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006084
6085static int decode_free_stateid(struct xdr_stream *xdr,
6086 struct nfs41_free_stateid_res *res)
6087{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006088 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006089 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006090}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006091#endif /* CONFIG_NFS_V4_1 */
6092
Linus Torvalds1da177e2005-04-16 15:20:36 -07006093/*
Benny Halevy49c25592008-12-23 16:06:16 -05006094 * END OF "GENERIC" DECODE ROUTINES.
6095 */
6096
6097/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098 * Decode OPEN_DOWNGRADE response
6099 */
Chuck Leverbf269552010-12-14 14:59:29 +00006100static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6101 struct xdr_stream *xdr,
6102 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103{
Andy Adamson05d564f2008-12-23 16:06:15 -05006104 struct compound_hdr hdr;
6105 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106
Chuck Leverbf269552010-12-14 14:59:29 +00006107 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006108 if (status)
6109 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006110 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006111 if (status)
6112 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006113 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006114 if (status)
6115 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006116 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006118 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006119}
6120
6121/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006122 * Decode ACCESS response
6123 */
Chuck Leverbf269552010-12-14 14:59:29 +00006124static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6125 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006126{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006127 struct compound_hdr hdr;
6128 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006129
Chuck Leverbf269552010-12-14 14:59:29 +00006130 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006131 if (status)
6132 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006133 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006134 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006135 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006137 if (status != 0)
6138 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006139 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006140 if (status != 0)
6141 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006142 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143out:
6144 return status;
6145}
6146
6147/*
6148 * Decode LOOKUP response
6149 */
Chuck Leverbf269552010-12-14 14:59:29 +00006150static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6151 struct nfs4_lookup_res *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);
6163 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006165 status = decode_lookup(xdr);
6166 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006167 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006168 status = decode_getfh(xdr, res->fh);
6169 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006171 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172out:
6173 return status;
6174}
6175
6176/*
6177 * Decode LOOKUP_ROOT response
6178 */
Chuck Leverbf269552010-12-14 14:59:29 +00006179static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6180 struct xdr_stream *xdr,
6181 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183 struct compound_hdr hdr;
6184 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006185
Chuck Leverbf269552010-12-14 14:59:29 +00006186 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006187 if (status)
6188 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006189 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006190 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006192 status = decode_putrootfh(xdr);
6193 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006195 status = decode_getfh(xdr, res->fh);
6196 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006197 status = decode_getfattr_label(xdr, res->fattr,
6198 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006199out:
6200 return status;
6201}
6202
6203/*
6204 * Decode REMOVE response
6205 */
Chuck Leverbf269552010-12-14 14:59:29 +00006206static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6207 struct nfs_removeres *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_putfh(xdr);
6219 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006220 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006221 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006222out:
6223 return status;
6224}
6225
6226/*
6227 * Decode RENAME response
6228 */
Chuck Leverbf269552010-12-14 14:59:29 +00006229static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6230 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006231{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006232 struct compound_hdr hdr;
6233 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006234
Chuck Leverbf269552010-12-14 14:59:29 +00006235 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006236 if (status)
6237 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006238 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006239 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006240 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006241 status = decode_putfh(xdr);
6242 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006244 status = decode_savefh(xdr);
6245 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006247 status = decode_putfh(xdr);
6248 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006249 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006250 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251out:
6252 return status;
6253}
6254
6255/*
6256 * Decode LINK response
6257 */
Chuck Leverbf269552010-12-14 14:59:29 +00006258static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6259 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006261 struct compound_hdr hdr;
6262 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006263
Chuck Leverbf269552010-12-14 14:59:29 +00006264 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006265 if (status)
6266 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006267 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006268 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006269 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006270 status = decode_putfh(xdr);
6271 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006272 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006273 status = decode_savefh(xdr);
6274 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006275 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006276 status = decode_putfh(xdr);
6277 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006278 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006279 status = decode_link(xdr, &res->cinfo);
6280 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006281 goto out;
6282 /*
6283 * Note order: OP_LINK leaves the directory as the current
6284 * filehandle.
6285 */
Chuck Leverbf269552010-12-14 14:59:29 +00006286 status = decode_restorefh(xdr);
6287 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006288 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006289 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290out:
6291 return status;
6292}
6293
6294/*
6295 * Decode CREATE response
6296 */
Chuck Leverbf269552010-12-14 14:59:29 +00006297static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6298 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006300 struct compound_hdr hdr;
6301 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006302
Chuck Leverbf269552010-12-14 14:59:29 +00006303 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006304 if (status)
6305 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006306 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006307 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006308 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006309 status = decode_putfh(xdr);
6310 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006312 status = decode_create(xdr, &res->dir_cinfo);
6313 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006314 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006315 status = decode_getfh(xdr, res->fh);
6316 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006317 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006318 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006319out:
6320 return status;
6321}
6322
6323/*
6324 * Decode SYMLINK response
6325 */
Chuck Leverbf269552010-12-14 14:59:29 +00006326static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6327 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006328{
Chuck Leverbf269552010-12-14 14:59:29 +00006329 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006330}
6331
6332/*
6333 * Decode GETATTR response
6334 */
Chuck Leverbf269552010-12-14 14:59:29 +00006335static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6336 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006337{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006338 struct compound_hdr hdr;
6339 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006340
Chuck Leverbf269552010-12-14 14:59:29 +00006341 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006342 if (status)
6343 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006344 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006345 if (status)
6346 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006347 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348 if (status)
6349 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006350 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351out:
6352 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353}
6354
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006355/*
6356 * Encode an SETACL request
6357 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006358static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6359 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006360{
Andy Adamson05d564f2008-12-23 16:06:15 -05006361 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006362 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006363 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006364
Chuck Lever9f06c712010-12-14 14:59:18 +00006365 encode_compound_hdr(xdr, req, &hdr);
6366 encode_sequence(xdr, &args->seq_args, &hdr);
6367 encode_putfh(xdr, args->fh, &hdr);
6368 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006369 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006370}
Andy Adamson05d564f2008-12-23 16:06:15 -05006371
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006372/*
6373 * Decode SETACL response
6374 */
6375static int
Chuck Leverbf269552010-12-14 14:59:29 +00006376nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006377 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006378{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006379 struct compound_hdr hdr;
6380 int status;
6381
Chuck Leverbf269552010-12-14 14:59:29 +00006382 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006383 if (status)
6384 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006385 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006386 if (status)
6387 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006388 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006389 if (status)
6390 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006391 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006392out:
6393 return status;
6394}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006395
6396/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006397 * Decode GETACL response
6398 */
6399static int
Chuck Leverbf269552010-12-14 14:59:29 +00006400nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006401 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006402{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006403 struct compound_hdr hdr;
6404 int status;
6405
Trond Myklebust331818f2012-02-03 18:30:53 -05006406 if (res->acl_scratch != NULL) {
6407 void *p = page_address(res->acl_scratch);
6408 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6409 }
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006411 if (status)
6412 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006413 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006414 if (status)
6415 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006416 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006417 if (status)
6418 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006419 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006420
6421out:
6422 return status;
6423}
6424
6425/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426 * Decode CLOSE response
6427 */
Chuck Leverbf269552010-12-14 14:59:29 +00006428static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6429 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006430{
Andy Adamson05d564f2008-12-23 16:06:15 -05006431 struct compound_hdr hdr;
6432 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006433
Chuck Leverbf269552010-12-14 14:59:29 +00006434 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006435 if (status)
6436 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006437 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006438 if (status)
6439 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006440 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006441 if (status)
6442 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006443 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006444 if (status != 0)
6445 goto out;
6446 /*
6447 * Note: Server may do delete on close for this file
6448 * in which case the getattr call will fail with
6449 * an ESTALE error. Shouldn't be a problem,
6450 * though, since fattr->valid will remain unset.
6451 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006452 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006454 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006455}
6456
6457/*
6458 * Decode OPEN response
6459 */
Chuck Leverbf269552010-12-14 14:59:29 +00006460static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6461 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006462{
Andy Adamson05d564f2008-12-23 16:06:15 -05006463 struct compound_hdr hdr;
6464 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465
Chuck Leverbf269552010-12-14 14:59:29 +00006466 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006467 if (status)
6468 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006469 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006470 if (status)
6471 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006472 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006473 if (status)
6474 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006475 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006476 if (status)
6477 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006478 status = decode_getfh(xdr, &res->fh);
6479 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006481 if (res->access_request)
6482 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006483 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006485 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006486}
6487
6488/*
6489 * Decode OPEN_CONFIRM response
6490 */
Chuck Leverbf269552010-12-14 14:59:29 +00006491static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6492 struct xdr_stream *xdr,
6493 struct nfs_open_confirmres *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);
Andy Adamson05d564f2008-12-23 16:06:15 -05006499 if (status)
6500 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006501 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006502 if (status)
6503 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006504 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006505out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006506 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507}
6508
6509/*
6510 * Decode OPEN response
6511 */
Chuck Leverbf269552010-12-14 14:59:29 +00006512static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6513 struct xdr_stream *xdr,
6514 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006515{
Andy Adamson05d564f2008-12-23 16:06:15 -05006516 struct compound_hdr hdr;
6517 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518
Chuck Leverbf269552010-12-14 14:59:29 +00006519 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006520 if (status)
6521 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006522 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006523 if (status)
6524 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006525 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006526 if (status)
6527 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006528 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006529 if (status)
6530 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006531 if (res->access_request)
6532 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006533 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006534out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006535 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536}
6537
6538/*
6539 * Decode SETATTR response
6540 */
Chuck Leverbf269552010-12-14 14:59:29 +00006541static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6542 struct xdr_stream *xdr,
6543 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544{
Andy Adamson05d564f2008-12-23 16:06:15 -05006545 struct compound_hdr hdr;
6546 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547
Chuck Leverbf269552010-12-14 14:59:29 +00006548 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006549 if (status)
6550 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006552 if (status)
6553 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006554 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006555 if (status)
6556 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006557 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006558 if (status)
6559 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006560 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006561out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006562 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006563}
6564
6565/*
6566 * Decode LOCK response
6567 */
Chuck Leverbf269552010-12-14 14:59:29 +00006568static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6569 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006570{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006571 struct compound_hdr hdr;
6572 int status;
6573
Chuck Leverbf269552010-12-14 14:59:29 +00006574 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006575 if (status)
6576 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006577 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006578 if (status)
6579 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006580 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006581 if (status)
6582 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006583 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006584out:
6585 return status;
6586}
6587
6588/*
6589 * Decode LOCKT response
6590 */
Chuck Leverbf269552010-12-14 14:59:29 +00006591static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6592 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006594 struct compound_hdr hdr;
6595 int status;
6596
Chuck Leverbf269552010-12-14 14:59:29 +00006597 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006598 if (status)
6599 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006600 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006601 if (status)
6602 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006603 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006604 if (status)
6605 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006606 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006607out:
6608 return status;
6609}
6610
6611/*
6612 * Decode LOCKU response
6613 */
Chuck Leverbf269552010-12-14 14:59:29 +00006614static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6615 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006616{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617 struct compound_hdr hdr;
6618 int status;
6619
Chuck Leverbf269552010-12-14 14:59:29 +00006620 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006621 if (status)
6622 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006623 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006624 if (status)
6625 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006626 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006627 if (status)
6628 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006629 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006630out:
6631 return status;
6632}
6633
Chuck Leverbf269552010-12-14 14:59:29 +00006634static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6635 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006636{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006637 struct compound_hdr hdr;
6638 int status;
6639
Chuck Leverbf269552010-12-14 14:59:29 +00006640 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006641 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006642 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006643 return status;
6644}
6645
Linus Torvalds1da177e2005-04-16 15:20:36 -07006646/*
6647 * Decode READLINK response
6648 */
Chuck Leverbf269552010-12-14 14:59:29 +00006649static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6650 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006651 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006652{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653 struct compound_hdr hdr;
6654 int status;
6655
Chuck Leverbf269552010-12-14 14:59:29 +00006656 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006657 if (status)
6658 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006659 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006660 if (status)
6661 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006662 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006663 if (status)
6664 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006665 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666out:
6667 return status;
6668}
6669
6670/*
6671 * Decode READDIR response
6672 */
Chuck Leverbf269552010-12-14 14:59:29 +00006673static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6674 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006675{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006676 struct compound_hdr hdr;
6677 int status;
6678
Chuck Leverbf269552010-12-14 14:59:29 +00006679 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006680 if (status)
6681 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006682 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006683 if (status)
6684 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006685 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006686 if (status)
6687 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006688 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006689out:
6690 return status;
6691}
6692
6693/*
6694 * Decode Read response
6695 */
Chuck Leverbf269552010-12-14 14:59:29 +00006696static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006697 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006698{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699 struct compound_hdr hdr;
6700 int status;
6701
Chuck Leverbf269552010-12-14 14:59:29 +00006702 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006703 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006704 if (status)
6705 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006706 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006707 if (status)
6708 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006709 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006710 if (status)
6711 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006712 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006713 if (!status)
6714 status = res->count;
6715out:
6716 return status;
6717}
6718
6719/*
6720 * Decode WRITE response
6721 */
Chuck Leverbf269552010-12-14 14:59:29 +00006722static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006723 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006724{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006725 struct compound_hdr hdr;
6726 int status;
6727
Chuck Leverbf269552010-12-14 14:59:29 +00006728 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006729 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006730 if (status)
6731 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006732 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006733 if (status)
6734 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006735 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736 if (status)
6737 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006738 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006739 if (status)
6740 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006741 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006742 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006743 if (!status)
6744 status = res->count;
6745out:
6746 return status;
6747}
6748
6749/*
6750 * Decode COMMIT response
6751 */
Chuck Leverbf269552010-12-14 14:59:29 +00006752static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006753 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006754{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006755 struct compound_hdr hdr;
6756 int status;
6757
Chuck Leverbf269552010-12-14 14:59:29 +00006758 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006759 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006760 if (status)
6761 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006762 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006763 if (status)
6764 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006765 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766 if (status)
6767 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006768 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006769out:
6770 return status;
6771}
6772
6773/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006774 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006775 */
Chuck Leverbf269552010-12-14 14:59:29 +00006776static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006777 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006778{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006779 struct compound_hdr hdr;
6780 int status;
6781
Chuck Leverbf269552010-12-14 14:59:29 +00006782 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006783 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006784 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006785 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006786 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006787 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006788 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006789 return status;
6790}
6791
6792/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006793 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006794 */
Chuck Leverbf269552010-12-14 14:59:29 +00006795static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006796 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006797{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006798 struct compound_hdr hdr;
6799 int status;
6800
Chuck Leverbf269552010-12-14 14:59:29 +00006801 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006802 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006803 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006804 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006805 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006806 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006807 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006808 return status;
6809}
6810
6811/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006812 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006813 */
Chuck Leverbf269552010-12-14 14:59:29 +00006814static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006815 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006816{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006817 struct compound_hdr hdr;
6818 int status;
6819
Chuck Leverbf269552010-12-14 14:59:29 +00006820 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006821 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006822 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006823 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006824 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006825 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006826 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006827 return status;
6828}
6829
6830/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006831 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006832 */
Chuck Leverbf269552010-12-14 14:59:29 +00006833static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6834 struct xdr_stream *xdr,
6835 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006836{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006837 struct compound_hdr hdr;
6838 int status;
6839
Chuck Leverbf269552010-12-14 14:59:29 +00006840 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006841 if (status)
6842 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006843 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006844 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006845 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006846 status = decode_putfh(xdr);
6847 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006848 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006849 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006850out:
6851 return status;
6852}
6853
6854/*
6855 * Decode RENEW response
6856 */
Chuck Leverbf269552010-12-14 14:59:29 +00006857static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6858 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006859{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006860 struct compound_hdr hdr;
6861 int status;
6862
Chuck Leverbf269552010-12-14 14:59:29 +00006863 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006864 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006865 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006866 return status;
6867}
6868
6869/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006870 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006871 */
Chuck Leverbf269552010-12-14 14:59:29 +00006872static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6873 struct xdr_stream *xdr,
6874 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006875{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006876 struct compound_hdr hdr;
6877 int status;
6878
Chuck Leverbf269552010-12-14 14:59:29 +00006879 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006880 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006881 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006882 return status;
6883}
6884
6885/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006886 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006887 */
Chuck Leverbf269552010-12-14 14:59:29 +00006888static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006889 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006890{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006891 struct compound_hdr hdr;
6892 int status;
6893
Chuck Leverbf269552010-12-14 14:59:29 +00006894 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006895 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006896 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006897 return status;
6898}
6899
6900/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006901 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006902 */
Chuck Leverbf269552010-12-14 14:59:29 +00006903static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6904 struct xdr_stream *xdr,
6905 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006906{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006907 struct compound_hdr hdr;
6908 int status;
6909
Chuck Leverbf269552010-12-14 14:59:29 +00006910 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006911 if (status)
6912 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006913 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006914 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006915 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006916 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006917 if (status != 0)
6918 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006919 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006920 if (status != 0)
6921 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006922 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006923out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006924 return status;
6925}
6926
Trond Myklebust683b57b2006-06-09 09:34:22 -04006927/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006928 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006929 */
Chuck Leverbf269552010-12-14 14:59:29 +00006930static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6931 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006932 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006933{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006934 struct compound_hdr hdr;
6935 int status;
6936
Chuck Leverbf269552010-12-14 14:59:29 +00006937 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006938 if (status)
6939 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006940 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006941 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006942 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006943 status = decode_putfh(xdr);
6944 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006945 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006946 if (res->migration) {
6947 xdr_enter_page(xdr, PAGE_SIZE);
6948 status = decode_getfattr_generic(xdr,
6949 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006950 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006951 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006952 if (status)
6953 goto out;
6954 if (res->renew)
6955 status = decode_renew(xdr);
6956 } else {
6957 status = decode_lookup(xdr);
6958 if (status)
6959 goto out;
6960 xdr_enter_page(xdr, PAGE_SIZE);
6961 status = decode_getfattr_generic(xdr,
6962 &res->fs_locations->fattr,
6963 NULL, res->fs_locations,
6964 NULL, res->fs_locations->server);
6965 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006966out:
6967 return status;
6968}
6969
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006970/*
6971 * Decode SECINFO response
6972 */
6973static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6974 struct xdr_stream *xdr,
6975 struct nfs4_secinfo_res *res)
6976{
6977 struct compound_hdr hdr;
6978 int status;
6979
6980 status = decode_compound_hdr(xdr, &hdr);
6981 if (status)
6982 goto out;
6983 status = decode_sequence(xdr, &res->seq_res, rqstp);
6984 if (status)
6985 goto out;
6986 status = decode_putfh(xdr);
6987 if (status)
6988 goto out;
6989 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006990out:
6991 return status;
6992}
6993
Chuck Lever44c99932013-10-17 14:13:30 -04006994/*
6995 * Decode FSID_PRESENT response
6996 */
6997static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6998 struct xdr_stream *xdr,
6999 struct nfs4_fsid_present_res *res)
7000{
7001 struct compound_hdr hdr;
7002 int status;
7003
7004 status = decode_compound_hdr(xdr, &hdr);
7005 if (status)
7006 goto out;
7007 status = decode_sequence(xdr, &res->seq_res, rqstp);
7008 if (status)
7009 goto out;
7010 status = decode_putfh(xdr);
7011 if (status)
7012 goto out;
7013 status = decode_getfh(xdr, res->fh);
7014 if (status)
7015 goto out;
7016 if (res->renew)
7017 status = decode_renew(xdr);
7018out:
7019 return status;
7020}
7021
Benny Halevy99fe60d2009-04-01 09:22:29 -04007022#if defined(CONFIG_NFS_V4_1)
7023/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007024 * Decode BIND_CONN_TO_SESSION response
7025 */
7026static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7027 struct xdr_stream *xdr,
7028 void *res)
7029{
7030 struct compound_hdr hdr;
7031 int status;
7032
7033 status = decode_compound_hdr(xdr, &hdr);
7034 if (!status)
7035 status = decode_bind_conn_to_session(xdr, res);
7036 return status;
7037}
7038
7039/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007040 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007041 */
Chuck Leverbf269552010-12-14 14:59:29 +00007042static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7043 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007044 void *res)
7045{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007046 struct compound_hdr hdr;
7047 int status;
7048
Chuck Leverbf269552010-12-14 14:59:29 +00007049 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007050 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007051 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007052 return status;
7053}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007054
7055/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007056 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007057 */
Chuck Leverbf269552010-12-14 14:59:29 +00007058static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7059 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04007060 struct nfs41_create_session_res *res)
7061{
Andy Adamsonfc931582009-04-01 09:22:31 -04007062 struct compound_hdr hdr;
7063 int status;
7064
Chuck Leverbf269552010-12-14 14:59:29 +00007065 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007066 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007067 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007068 return status;
7069}
7070
7071/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007072 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007073 */
Chuck Leverbf269552010-12-14 14:59:29 +00007074static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7075 struct xdr_stream *xdr,
7076 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007077{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007078 struct compound_hdr hdr;
7079 int status;
7080
Chuck Leverbf269552010-12-14 14:59:29 +00007081 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007082 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007083 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007084 return status;
7085}
7086
7087/*
Trond Myklebust66245532012-05-25 17:18:09 -04007088 * Decode DESTROY_CLIENTID response
7089 */
7090static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7091 struct xdr_stream *xdr,
7092 void *res)
7093{
7094 struct compound_hdr hdr;
7095 int status;
7096
7097 status = decode_compound_hdr(xdr, &hdr);
7098 if (!status)
7099 status = decode_destroy_clientid(xdr, res);
7100 return status;
7101}
7102
7103/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007104 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007105 */
Chuck Leverbf269552010-12-14 14:59:29 +00007106static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7107 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007108 struct nfs4_sequence_res *res)
7109{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007110 struct compound_hdr hdr;
7111 int status;
7112
Chuck Leverbf269552010-12-14 14:59:29 +00007113 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007114 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007115 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007116 return status;
7117}
7118
7119/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007120 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007121 */
Chuck Leverbf269552010-12-14 14:59:29 +00007122static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7123 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04007124 struct nfs4_get_lease_time_res *res)
7125{
Andy Adamson2050f0c2009-04-01 09:22:30 -04007126 struct compound_hdr hdr;
7127 int status;
7128
Chuck Leverbf269552010-12-14 14:59:29 +00007129 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007130 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007131 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007132 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007133 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007134 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007135 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007136 return status;
7137}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007138
7139/*
7140 * Decode RECLAIM_COMPLETE response
7141 */
Chuck Leverbf269552010-12-14 14:59:29 +00007142static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7143 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007144 struct nfs41_reclaim_complete_res *res)
7145{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007146 struct compound_hdr hdr;
7147 int status;
7148
Chuck Leverbf269552010-12-14 14:59:29 +00007149 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007150 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007151 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007152 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307153 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007154 return status;
7155}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007156
7157/*
7158 * Decode GETDEVINFO response
7159 */
Chuck Leverbf269552010-12-14 14:59:29 +00007160static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7161 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007162 struct nfs4_getdeviceinfo_res *res)
7163{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007164 struct compound_hdr hdr;
7165 int status;
7166
Chuck Leverbf269552010-12-14 14:59:29 +00007167 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007168 if (status != 0)
7169 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007170 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007171 if (status != 0)
7172 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007173 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007174out:
7175 return status;
7176}
7177
7178/*
7179 * Decode LAYOUTGET response
7180 */
Chuck Leverbf269552010-12-14 14:59:29 +00007181static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7182 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007183 struct nfs4_layoutget_res *res)
7184{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007185 struct compound_hdr hdr;
7186 int status;
7187
Chuck Leverbf269552010-12-14 14:59:29 +00007188 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007189 if (status)
7190 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007191 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007192 if (status)
7193 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007194 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007195 if (status)
7196 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007197 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007198out:
7199 return status;
7200}
Andy Adamson863a3c62011-03-23 13:27:54 +00007201
7202/*
Benny Halevycbe82602011-05-22 19:52:37 +03007203 * Decode LAYOUTRETURN response
7204 */
7205static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7206 struct xdr_stream *xdr,
7207 struct nfs4_layoutreturn_res *res)
7208{
7209 struct compound_hdr hdr;
7210 int status;
7211
7212 status = decode_compound_hdr(xdr, &hdr);
7213 if (status)
7214 goto out;
7215 status = decode_sequence(xdr, &res->seq_res, rqstp);
7216 if (status)
7217 goto out;
7218 status = decode_putfh(xdr);
7219 if (status)
7220 goto out;
7221 status = decode_layoutreturn(xdr, res);
7222out:
7223 return status;
7224}
7225
7226/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007227 * Decode LAYOUTCOMMIT response
7228 */
7229static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7230 struct xdr_stream *xdr,
7231 struct nfs4_layoutcommit_res *res)
7232{
7233 struct compound_hdr hdr;
7234 int status;
7235
7236 status = decode_compound_hdr(xdr, &hdr);
7237 if (status)
7238 goto out;
7239 status = decode_sequence(xdr, &res->seq_res, rqstp);
7240 if (status)
7241 goto out;
7242 status = decode_putfh(xdr);
7243 if (status)
7244 goto out;
7245 status = decode_layoutcommit(xdr, rqstp, res);
7246 if (status)
7247 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007248 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007249out:
7250 return status;
7251}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007252
7253/*
7254 * Decode SECINFO_NO_NAME response
7255 */
7256static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7257 struct xdr_stream *xdr,
7258 struct nfs4_secinfo_res *res)
7259{
7260 struct compound_hdr hdr;
7261 int status;
7262
7263 status = decode_compound_hdr(xdr, &hdr);
7264 if (status)
7265 goto out;
7266 status = decode_sequence(xdr, &res->seq_res, rqstp);
7267 if (status)
7268 goto out;
7269 status = decode_putrootfh(xdr);
7270 if (status)
7271 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007272 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007273out:
7274 return status;
7275}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007276
7277/*
7278 * Decode TEST_STATEID response
7279 */
7280static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7281 struct xdr_stream *xdr,
7282 struct nfs41_test_stateid_res *res)
7283{
7284 struct compound_hdr hdr;
7285 int status;
7286
7287 status = decode_compound_hdr(xdr, &hdr);
7288 if (status)
7289 goto out;
7290 status = decode_sequence(xdr, &res->seq_res, rqstp);
7291 if (status)
7292 goto out;
7293 status = decode_test_stateid(xdr, res);
7294out:
7295 return status;
7296}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007297
7298/*
7299 * Decode FREE_STATEID response
7300 */
7301static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7302 struct xdr_stream *xdr,
7303 struct nfs41_free_stateid_res *res)
7304{
7305 struct compound_hdr hdr;
7306 int status;
7307
7308 status = decode_compound_hdr(xdr, &hdr);
7309 if (status)
7310 goto out;
7311 status = decode_sequence(xdr, &res->seq_res, rqstp);
7312 if (status)
7313 goto out;
7314 status = decode_free_stateid(xdr, res);
7315out:
7316 return status;
7317}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007318#endif /* CONFIG_NFS_V4_1 */
7319
Chuck Lever573c4e12010-12-14 14:58:11 +00007320/**
7321 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7322 * the local page cache.
7323 * @xdr: XDR stream where entry resides
7324 * @entry: buffer to fill in with entry data
7325 * @plus: boolean indicating whether this should be a readdirplus entry
7326 *
7327 * Returns zero if successful, otherwise a negative errno value is
7328 * returned.
7329 *
7330 * This function is not invoked during READDIR reply decoding, but
7331 * rather whenever an application invokes the getdents(2) system call
7332 * on a directory already in our cache.
7333 */
7334int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7335 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007336{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007337 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007338 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007339 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007340 __be32 *p = xdr_inline_decode(xdr, 4);
7341 if (unlikely(!p))
7342 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007343 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007344 p = xdr_inline_decode(xdr, 4);
7345 if (unlikely(!p))
7346 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007347 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007348 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007349 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007350 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007351 }
7352
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007353 p = xdr_inline_decode(xdr, 12);
7354 if (unlikely(!p))
7355 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007356 entry->prev_cookie = entry->cookie;
7357 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007358 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007359
Trond Myklebust9af8c222010-10-24 11:52:55 -04007360 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007361 if (unlikely(!p))
7362 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007363 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007364
7365 /*
7366 * In case the server doesn't return an inode number,
7367 * we fake one here. (We don't use inode number 0,
7368 * since glibc seems to choke on it...)
7369 */
7370 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007371 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007372
Trond Myklebust9af8c222010-10-24 11:52:55 -04007373 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007374 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007375
Trond Myklebust256e48b2012-06-21 11:18:13 -04007376 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007377 goto out_overflow;
7378
Chuck Lever573c4e12010-12-14 14:58:11 +00007379 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007380 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007381 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007382 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7383 entry->ino = entry->fattr->mounted_on_fileid;
7384 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007385 entry->ino = entry->fattr->fileid;
7386
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007387 entry->d_type = DT_UNKNOWN;
7388 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7389 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7390
Chuck Lever573c4e12010-12-14 14:58:11 +00007391 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007392
7393out_overflow:
7394 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007395 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007396}
7397
7398/*
7399 * We need to translate between nfs status return values and
7400 * the local errno values which may not be the same.
7401 */
7402static struct {
7403 int stat;
7404 int errno;
7405} nfs_errtbl[] = {
7406 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007407 { NFS4ERR_PERM, -EPERM },
7408 { NFS4ERR_NOENT, -ENOENT },
7409 { NFS4ERR_IO, -errno_NFSERR_IO},
7410 { NFS4ERR_NXIO, -ENXIO },
7411 { NFS4ERR_ACCESS, -EACCES },
7412 { NFS4ERR_EXIST, -EEXIST },
7413 { NFS4ERR_XDEV, -EXDEV },
7414 { NFS4ERR_NOTDIR, -ENOTDIR },
7415 { NFS4ERR_ISDIR, -EISDIR },
7416 { NFS4ERR_INVAL, -EINVAL },
7417 { NFS4ERR_FBIG, -EFBIG },
7418 { NFS4ERR_NOSPC, -ENOSPC },
7419 { NFS4ERR_ROFS, -EROFS },
7420 { NFS4ERR_MLINK, -EMLINK },
7421 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7422 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7423 { NFS4ERR_DQUOT, -EDQUOT },
7424 { NFS4ERR_STALE, -ESTALE },
7425 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007426 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7427 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7428 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007429 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007430 { NFS4ERR_BADTYPE, -EBADTYPE },
7431 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007432 { NFS4ERR_SYMLINK, -ELOOP },
7433 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7434 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007435 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007436};
7437
7438/*
7439 * Convert an NFS error code to a local one.
7440 * This one is used jointly by NFSv2 and NFSv3.
7441 */
7442static int
David Howells0a8ea432006-08-22 20:06:08 -04007443nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007444{
7445 int i;
7446 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7447 if (nfs_errtbl[i].stat == stat)
7448 return nfs_errtbl[i].errno;
7449 }
7450 if (stat <= 10000 || stat > 10100) {
7451 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007452 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007453 }
7454 /* If we cannot translate the error, the recovery routines should
7455 * handle it.
7456 * Note: remaining NFSv4 error codes have values > 10000, so should
7457 * not conflict with native Linux error codes.
7458 */
Benny Halevy856dff32008-03-31 17:39:06 +03007459 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007460}
7461
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007462#ifdef CONFIG_NFS_V4_2
7463#include "nfs42xdr.c"
7464#endif /* CONFIG_NFS_V4_2 */
7465
Linus Torvalds1da177e2005-04-16 15:20:36 -07007466#define PROC(proc, argtype, restype) \
7467[NFSPROC4_CLNT_##proc] = { \
7468 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007469 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007470 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007471 .p_arglen = NFS4_##argtype##_sz, \
7472 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007473 .p_statidx = NFSPROC4_CLNT_##proc, \
7474 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007475}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007476
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007477#define STUB(proc) \
7478[NFSPROC4_CLNT_##proc] = { \
7479 .p_name = #proc, \
7480}
7481
Linus Torvalds1da177e2005-04-16 15:20:36 -07007482struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007483 PROC(READ, enc_read, dec_read),
7484 PROC(WRITE, enc_write, dec_write),
7485 PROC(COMMIT, enc_commit, dec_commit),
7486 PROC(OPEN, enc_open, dec_open),
7487 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7488 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7489 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7490 PROC(CLOSE, enc_close, dec_close),
7491 PROC(SETATTR, enc_setattr, dec_setattr),
7492 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7493 PROC(RENEW, enc_renew, dec_renew),
7494 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7495 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7496 PROC(LOCK, enc_lock, dec_lock),
7497 PROC(LOCKT, enc_lockt, dec_lockt),
7498 PROC(LOCKU, enc_locku, dec_locku),
7499 PROC(ACCESS, enc_access, dec_access),
7500 PROC(GETATTR, enc_getattr, dec_getattr),
7501 PROC(LOOKUP, enc_lookup, dec_lookup),
7502 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7503 PROC(REMOVE, enc_remove, dec_remove),
7504 PROC(RENAME, enc_rename, dec_rename),
7505 PROC(LINK, enc_link, dec_link),
7506 PROC(SYMLINK, enc_symlink, dec_symlink),
7507 PROC(CREATE, enc_create, dec_create),
7508 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7509 PROC(STATFS, enc_statfs, dec_statfs),
7510 PROC(READLINK, enc_readlink, dec_readlink),
7511 PROC(READDIR, enc_readdir, dec_readdir),
7512 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7513 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7514 PROC(GETACL, enc_getacl, dec_getacl),
7515 PROC(SETACL, enc_setacl, dec_setacl),
7516 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7517 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007518 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007519 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007520#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007521 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7522 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7523 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7524 PROC(SEQUENCE, enc_sequence, dec_sequence),
7525 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7526 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7527 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7528 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007529 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007530 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007531 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007532 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007533 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007534 STUB(GETDEVICELIST),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007535 PROC(BIND_CONN_TO_SESSION,
7536 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007537 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007538#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007539#ifdef CONFIG_NFS_V4_2
7540 PROC(SEEK, enc_seek, dec_seek),
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007541 PROC(ALLOCATE, enc_allocate, dec_allocate),
Anna Schumaker624bd5b2014-11-25 13:18:16 -05007542 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
Trond Myklebustbe3a5d22015-06-23 19:51:55 +08007543 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
Peng Tao36022772015-09-26 02:24:34 +08007544 PROC(CLONE, enc_clone, dec_clone),
Anna Schumaker2e724482013-05-21 16:53:03 -04007545 PROC(COPY, enc_copy, dec_copy),
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007546#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007547};
7548
Trond Myklebusta613fa12012-01-20 13:53:56 -05007549const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007550 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007551 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007552 .procs = nfs4_procedures
7553};
7554
7555/*
7556 * Local variables:
7557 * c-basic-offset: 8
7558 * End:
7559 */