blob: b993ad282de2002579255914d8bca14698f16854 [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)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700161#define encode_lookupp_maxsz (op_encode_hdr_maxsz)
162#define decode_lookupp_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400163#define encode_share_access_maxsz \
164 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500165#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400166#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
167#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
168#define encode_open_maxsz (op_encode_hdr_maxsz + \
169 2 + encode_share_access_maxsz + 2 + \
170 open_owner_id_maxsz + \
171 encode_opentype_maxsz + \
172 encode_claim_null_maxsz)
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500173#define decode_space_limit_maxsz (3)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400174#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400175#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500176 decode_space_limit_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400177 decode_ace_maxsz)
178#define decode_change_info_maxsz (5)
179#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400180 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400181 decode_change_info_maxsz + 1 + \
182 nfs4_fattr_bitmap_maxsz + \
183 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400184#define encode_open_confirm_maxsz \
185 (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + 1)
187#define decode_open_confirm_maxsz \
188 (op_decode_hdr_maxsz + \
189 decode_stateid_maxsz)
190#define encode_open_downgrade_maxsz \
191 (op_encode_hdr_maxsz + \
192 encode_stateid_maxsz + 1 + \
193 encode_share_access_maxsz)
194#define decode_open_downgrade_maxsz \
195 (op_decode_hdr_maxsz + \
196 decode_stateid_maxsz)
197#define encode_close_maxsz (op_encode_hdr_maxsz + \
198 1 + encode_stateid_maxsz)
199#define decode_close_maxsz (op_decode_hdr_maxsz + \
200 decode_stateid_maxsz)
201#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
202 encode_stateid_maxsz + \
203 encode_attrs_maxsz)
204#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
205 nfs4_fattr_bitmap_maxsz)
206#define encode_read_maxsz (op_encode_hdr_maxsz + \
207 encode_stateid_maxsz + 3)
208#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
209#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400210 2 + encode_verifier_maxsz + 5 + \
211 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400212#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Chuck Levera7697f62014-03-12 12:51:17 -0400213 decode_verifier_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400214#define encode_readlink_maxsz (op_encode_hdr_maxsz)
215#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
216#define encode_write_maxsz (op_encode_hdr_maxsz + \
217 encode_stateid_maxsz + 4)
218#define decode_write_maxsz (op_decode_hdr_maxsz + \
219 2 + decode_verifier_maxsz)
220#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
221#define decode_commit_maxsz (op_decode_hdr_maxsz + \
222 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223#define encode_remove_maxsz (op_encode_hdr_maxsz + \
224 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400225#define decode_remove_maxsz (op_decode_hdr_maxsz + \
226 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227#define encode_rename_maxsz (op_encode_hdr_maxsz + \
228 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400229#define decode_rename_maxsz (op_decode_hdr_maxsz + \
230 decode_change_info_maxsz + \
231 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232#define encode_link_maxsz (op_encode_hdr_maxsz + \
233 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400234#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400235#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400236#define encode_lock_maxsz (op_encode_hdr_maxsz + \
237 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400238 1 + encode_stateid_maxsz + 1 + \
239 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400240#define decode_lock_denied_maxsz \
241 (8 + decode_lockowner_maxsz)
242#define decode_lock_maxsz (op_decode_hdr_maxsz + \
243 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400244#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
245 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400246#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
247 decode_lock_denied_maxsz)
248#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
249 encode_stateid_maxsz + \
250 4)
251#define decode_locku_maxsz (op_decode_hdr_maxsz + \
252 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400253#define encode_release_lockowner_maxsz \
254 (op_encode_hdr_maxsz + \
255 encode_lockowner_maxsz)
256#define decode_release_lockowner_maxsz \
257 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400258#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
259#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
261 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400262 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000263 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
265#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400266 1 + 2 + nfs4_name_maxsz + \
267 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400268#define decode_create_maxsz (op_decode_hdr_maxsz + \
269 decode_change_info_maxsz + \
270 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400271#define encode_statfs_maxsz (encode_getattr_maxsz)
272#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
274#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400275#define encode_getacl_maxsz (encode_getattr_maxsz)
276#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
277 nfs4_fattr_bitmap_maxsz + 1)
278#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
279 encode_stateid_maxsz + 3)
280#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400281#define encode_fs_locations_maxsz \
282 (encode_getattr_maxsz)
283#define decode_fs_locations_maxsz \
284 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000285#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400286#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 -0400287
288#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400289#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500290#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
291 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400292
Benny Halevy99fe60d2009-04-01 09:22:29 -0400293#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
294 encode_verifier_maxsz + \
295 1 /* co_ownerid.len */ + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400296 /* eia_clientowner */ \
297 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400298 1 /* flags */ + \
299 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400300 /* max is SP4_MACH_CRED (for now) */ + \
301 1 + NFS4_OP_MAP_NUM_WORDS + \
302 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500303 1 /* implementation id array of size 1 */ + \
304 1 /* nii_domain */ + \
305 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
306 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500307 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500308 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400309#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
310 2 /* eir_clientid */ + \
311 1 /* eir_sequenceid */ + \
312 1 /* eir_flags */ + \
313 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400314 /* max is SP4_MACH_CRED (for now) */ + \
315 1 + NFS4_OP_MAP_NUM_WORDS + \
316 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400317 2 /* eir_server_owner.so_minor_id */ + \
318 /* eir_server_owner.so_major_id<> */ \
319 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
320 /* eir_server_scope<> */ \
321 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
322 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500323 1 /* nii_domain */ + \
324 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
325 1 /* nii_name */ + \
326 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
327 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400328#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
329#define decode_channel_attrs_maxsz (6 + \
330 1 /* ca_rdma_ird.len */ + \
331 1 /* ca_rdma_ird */)
332#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
333 2 /* csa_clientid */ + \
334 1 /* csa_sequence */ + \
335 1 /* csa_flags */ + \
336 encode_channel_attrs_maxsz + \
337 encode_channel_attrs_maxsz + \
338 1 /* csa_cb_program */ + \
339 1 /* csa_sec_parms.len (1) */ + \
340 1 /* cb_secflavor (AUTH_SYS) */ + \
341 1 /* stamp */ + \
342 1 /* machinename.len */ + \
343 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
344 1 /* uid */ + \
345 1 /* gid */ + \
346 1 /* gids.len (0) */)
347#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
348 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
349 1 /* csr_sequence */ + \
350 1 /* csr_flags */ + \
351 decode_channel_attrs_maxsz + \
352 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400353#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
354 /* bctsa_sessid */ \
355 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
356 1 /* bctsa_dir */ + \
357 1 /* bctsa_use_conn_in_rdma_mode */)
358#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
359 /* bctsr_sessid */ \
360 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
361 1 /* bctsr_dir */ + \
362 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400363#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
364#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400365#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
366#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400367#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
368 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
369#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
370 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500371#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
372#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700373#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
374 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
375 1 /* layout type */ + \
376 1 /* maxcount */ + \
377 1 /* bitmap size */ + \
378 1 /* notification bitmap length */ + \
379 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400380#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
381 1 /* layout type */ + \
382 1 /* opaque devaddr4 length */ + \
383 /* devaddr4 payload is read into page */ \
384 1 /* notification bitmap length */ + \
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700385 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400386#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
387 encode_stateid_maxsz)
388#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
389 decode_stateid_maxsz + \
390 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000391#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
392 2 /* offset */ + \
393 2 /* length */ + \
394 1 /* reclaim */ + \
395 encode_stateid_maxsz + \
396 1 /* new offset (true) */ + \
397 2 /* last byte written */ + \
398 1 /* nt_timechanged (false) */ + \
399 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500400 1 /* layoutupdate4 opaqueue len */)
401 /* the actual content of layoutupdate4 should
402 be allocated by drivers and spliced in
403 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000404#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300405#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
406 encode_stateid_maxsz + \
Trond Myklebust6669cb82015-08-27 20:43:20 -0400407 1 + \
408 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
Benny Halevycbe82602011-05-22 19:52:37 +0300409#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
410 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400411#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
412#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400413#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
414 XDR_QUADLEN(NFS4_STATEID_SIZE))
415#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400416#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
417 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400418#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400419#else /* CONFIG_NFS_V4_1 */
420#define encode_sequence_maxsz 0
421#define decode_sequence_maxsz 0
Trond Myklebustcf805162016-11-15 14:56:07 -0500422#define encode_layoutreturn_maxsz 0
423#define decode_layoutreturn_maxsz 0
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400424#endif /* CONFIG_NFS_V4_1 */
425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
427#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
428#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400429 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400431 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400433 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400435 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400439 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400441 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400443 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400445 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400447 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400449 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400451 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400453 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400455 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400456 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400460 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400461 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400465 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400467 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400469 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400471 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400472 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400473 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400474 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400475 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400478 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400479 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400480 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400481 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400482 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400483 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400484#define NFS4_enc_open_confirm_sz \
485 (compound_encode_hdr_maxsz + \
486 encode_putfh_maxsz + \
487 encode_open_confirm_maxsz)
488#define NFS4_dec_open_confirm_sz \
489 (compound_decode_hdr_maxsz + \
490 decode_putfh_maxsz + \
491 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400493 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400495 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400496 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400497 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400499 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400501 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400502 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400503 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504#define NFS4_enc_open_downgrade_sz \
505 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400506 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400507 encode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500508 encode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400509 encode_open_downgrade_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510#define NFS4_dec_open_downgrade_sz \
511 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400512 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400513 decode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500514 decode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400515 decode_open_downgrade_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400516#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400517 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400518 encode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500519 encode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400520 encode_close_maxsz + \
521 encode_getattr_maxsz)
522#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400523 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400524 decode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500525 decode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400526 decode_close_maxsz + \
527 decode_getattr_maxsz)
528#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400529 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400530 encode_putfh_maxsz + \
531 encode_setattr_maxsz + \
532 encode_getattr_maxsz)
533#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400535 decode_putfh_maxsz + \
536 decode_setattr_maxsz + \
537 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400539 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 encode_putfh_maxsz + \
541 encode_fsinfo_maxsz)
542#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400543 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 decode_putfh_maxsz + \
545 decode_fsinfo_maxsz)
546#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
547 encode_renew_maxsz)
548#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
549 decode_renew_maxsz)
550#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
551 encode_setclientid_maxsz)
552#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
553 decode_setclientid_maxsz)
554#define NFS4_enc_setclientid_confirm_sz \
555 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400556 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#define NFS4_dec_setclientid_confirm_sz \
558 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400559 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400561 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400563 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400565 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400567 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400569 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400571 encode_lockt_maxsz)
572#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400573 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400574 decode_putfh_maxsz + \
575 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400577 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400579 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400581 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400583 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400584#define NFS4_enc_release_lockowner_sz \
585 (compound_encode_hdr_maxsz + \
586 encode_lockowner_maxsz)
587#define NFS4_dec_release_lockowner_sz \
588 (compound_decode_hdr_maxsz + \
589 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590#define NFS4_enc_access_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 + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400593 encode_access_maxsz + \
594 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595#define NFS4_dec_access_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 + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400598 decode_access_maxsz + \
599 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#define NFS4_enc_getattr_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 + \
Chuck Lever44c99932013-10-17 14:13:30 -0400603 encode_getattr_maxsz + \
604 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400608 decode_getattr_maxsz + \
609 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400611 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 encode_putfh_maxsz + \
613 encode_lookup_maxsz + \
614 encode_getattr_maxsz + \
615 encode_getfh_maxsz)
616#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400617 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400619 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 decode_getattr_maxsz + \
621 decode_getfh_maxsz)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700622#define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \
623 encode_sequence_maxsz + \
624 encode_putfh_maxsz + \
625 encode_lookupp_maxsz + \
626 encode_getattr_maxsz + \
627 encode_getfh_maxsz)
628#define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \
629 decode_sequence_maxsz + \
630 decode_putfh_maxsz + \
631 decode_lookupp_maxsz + \
632 decode_getattr_maxsz + \
633 decode_getfh_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400635 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 encode_putrootfh_maxsz + \
637 encode_getattr_maxsz + \
638 encode_getfh_maxsz)
639#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400640 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 decode_putrootfh_maxsz + \
642 decode_getattr_maxsz + \
643 decode_getfh_maxsz)
644#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400645 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400647 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400649 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400651 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400653 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 encode_putfh_maxsz + \
655 encode_savefh_maxsz + \
656 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400657 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400659 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 decode_putfh_maxsz + \
661 decode_savefh_maxsz + \
662 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400663 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400665 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 encode_putfh_maxsz + \
667 encode_savefh_maxsz + \
668 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400669 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400670 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400671 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400673 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 decode_putfh_maxsz + \
675 decode_savefh_maxsz + \
676 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400677 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400678 decode_restorefh_maxsz + \
679 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400681 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 encode_putfh_maxsz + \
683 encode_symlink_maxsz + \
684 encode_getattr_maxsz + \
685 encode_getfh_maxsz)
686#define NFS4_dec_symlink_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_symlink_maxsz + \
690 decode_getattr_maxsz + \
691 decode_getfh_maxsz)
692#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400693 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 encode_putfh_maxsz + \
695 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400696 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400697 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400699 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 decode_putfh_maxsz + \
701 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400702 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400703 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400705 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 encode_putfh_maxsz + \
707 encode_getattr_maxsz)
708#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400709 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 decode_putfh_maxsz + \
711 decode_getattr_maxsz)
712#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400715 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400719 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400721 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800722 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 encode_getattr_maxsz)
724#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400725 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800726 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 decode_getattr_maxsz)
728#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400729 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 encode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500731 encode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100732 encode_delegreturn_maxsz + \
733 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400735 decode_sequence_maxsz + \
Trond Myklebustd8434d4c2016-11-16 13:54:00 -0500736 decode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500737 decode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100738 decode_delegreturn_maxsz + \
739 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000740#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400741 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000742 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400743 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000744#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400745 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000746 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400747 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000748#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400749 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000750 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400751 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000752#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400753 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000754 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400755 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400756#define NFS4_enc_fs_locations_sz \
757 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400758 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400759 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400760 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400761 encode_fs_locations_maxsz + \
762 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400763#define NFS4_dec_fs_locations_sz \
764 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400765 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400766 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400767 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400768 decode_fs_locations_maxsz + \
769 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000770#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
771 encode_sequence_maxsz + \
772 encode_putfh_maxsz + \
773 encode_secinfo_maxsz)
774#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
775 decode_sequence_maxsz + \
776 decode_putfh_maxsz + \
777 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400778#define NFS4_enc_fsid_present_sz \
779 (compound_encode_hdr_maxsz + \
780 encode_sequence_maxsz + \
781 encode_putfh_maxsz + \
782 encode_getfh_maxsz + \
783 encode_renew_maxsz)
784#define NFS4_dec_fsid_present_sz \
785 (compound_decode_hdr_maxsz + \
786 decode_sequence_maxsz + \
787 decode_putfh_maxsz + \
788 decode_getfh_maxsz + \
789 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400790#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400791#define NFS4_enc_bind_conn_to_session_sz \
792 (compound_encode_hdr_maxsz + \
793 encode_bind_conn_to_session_maxsz)
794#define NFS4_dec_bind_conn_to_session_sz \
795 (compound_decode_hdr_maxsz + \
796 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400797#define NFS4_enc_exchange_id_sz \
798 (compound_encode_hdr_maxsz + \
799 encode_exchange_id_maxsz)
800#define NFS4_dec_exchange_id_sz \
801 (compound_decode_hdr_maxsz + \
802 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400803#define NFS4_enc_create_session_sz \
804 (compound_encode_hdr_maxsz + \
805 encode_create_session_maxsz)
806#define NFS4_dec_create_session_sz \
807 (compound_decode_hdr_maxsz + \
808 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400809#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
810 encode_destroy_session_maxsz)
811#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
812 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400813#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
814 encode_destroy_clientid_maxsz)
815#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
816 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400817#define NFS4_enc_sequence_sz \
818 (compound_decode_hdr_maxsz + \
819 encode_sequence_maxsz)
820#define NFS4_dec_sequence_sz \
821 (compound_decode_hdr_maxsz + \
822 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400823#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
824 encode_sequence_maxsz + \
825 encode_putrootfh_maxsz + \
826 encode_fsinfo_maxsz)
827#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
828 decode_sequence_maxsz + \
829 decode_putrootfh_maxsz + \
830 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500831#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
832 encode_sequence_maxsz + \
833 encode_reclaim_complete_maxsz)
834#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
835 decode_sequence_maxsz + \
836 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400837#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
838 encode_sequence_maxsz +\
839 encode_getdeviceinfo_maxsz)
840#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
841 decode_sequence_maxsz + \
842 decode_getdeviceinfo_maxsz)
843#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
844 encode_sequence_maxsz + \
845 encode_putfh_maxsz + \
846 encode_layoutget_maxsz)
847#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
848 decode_sequence_maxsz + \
849 decode_putfh_maxsz + \
850 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000851#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
852 encode_sequence_maxsz +\
853 encode_putfh_maxsz + \
854 encode_layoutcommit_maxsz + \
855 encode_getattr_maxsz)
856#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
857 decode_sequence_maxsz + \
858 decode_putfh_maxsz + \
859 decode_layoutcommit_maxsz + \
860 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300861#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
862 encode_sequence_maxsz + \
863 encode_putfh_maxsz + \
864 encode_layoutreturn_maxsz)
865#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
866 decode_sequence_maxsz + \
867 decode_putfh_maxsz + \
868 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400869#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
870 encode_sequence_maxsz + \
871 encode_putrootfh_maxsz +\
872 encode_secinfo_no_name_maxsz)
873#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
874 decode_sequence_maxsz + \
875 decode_putrootfh_maxsz + \
876 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400877#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
878 encode_sequence_maxsz + \
879 encode_test_stateid_maxsz)
880#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
881 decode_sequence_maxsz + \
882 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400883#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
884 encode_sequence_maxsz + \
885 encode_free_stateid_maxsz)
886#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
887 decode_sequence_maxsz + \
888 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500889
890const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
891 compound_encode_hdr_maxsz +
892 encode_sequence_maxsz +
893 encode_putfh_maxsz +
894 encode_getattr_maxsz) *
895 XDR_UNIT);
896
897const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
898 compound_decode_hdr_maxsz +
899 decode_sequence_maxsz +
900 decode_putfh_maxsz) *
901 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400902
903const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
904 compound_decode_hdr_maxsz +
905 decode_sequence_maxsz) *
906 XDR_UNIT);
907EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400908#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
Trond Myklebustbca79472009-03-11 14:10:26 -0400910static const umode_t nfs_type2fmt[] = {
911 [NF4BAD] = 0,
912 [NF4REG] = S_IFREG,
913 [NF4DIR] = S_IFDIR,
914 [NF4BLK] = S_IFBLK,
915 [NF4CHR] = S_IFCHR,
916 [NF4LNK] = S_IFLNK,
917 [NF4SOCK] = S_IFSOCK,
918 [NF4FIFO] = S_IFIFO,
919 [NF4ATTRDIR] = 0,
920 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921};
922
923struct compound_hdr {
924 int32_t status;
925 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500926 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 uint32_t taglen;
928 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400929 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400930 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931};
932
Benny Halevy13c65ce2009-08-14 17:19:25 +0300933static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
934{
935 __be32 *p = xdr_reserve_space(xdr, nbytes);
936 BUG_ON(!p);
937 return p;
938}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Trond Myklebustcb17e552012-03-04 18:13:56 -0500940static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
941{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500942 WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
Trond Myklebustcb17e552012-03-04 18:13:56 -0500943}
944
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
946{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500947 WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948}
949
Trond Myklebust4ade9822012-03-04 18:13:57 -0500950static void encode_uint32(struct xdr_stream *xdr, u32 n)
951{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500952 WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500953}
954
Trond Myklebustff2eb682012-03-05 11:40:12 -0500955static void encode_uint64(struct xdr_stream *xdr, u64 n)
956{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500957 WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
Trond Myklebustff2eb682012-03-05 11:40:12 -0500958}
959
Trond Myklebust4ade9822012-03-04 18:13:57 -0500960static void encode_nfs4_seqid(struct xdr_stream *xdr,
961 const struct nfs_seqid *seqid)
962{
Trond Myklebusta6796412015-01-23 19:04:44 -0500963 if (seqid != NULL)
964 encode_uint32(xdr, seqid->sequence->counter);
965 else
966 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500967}
968
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400969static void encode_compound_hdr(struct xdr_stream *xdr,
970 struct rpc_rqst *req,
971 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972{
Al Viro8687b632006-10-19 23:28:48 -0700973 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400974 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400975
976 /* initialize running count of expected bytes in reply.
977 * NOTE: the replied tag SHOULD be the same is the one sent,
978 * but this is not required as a MUST for the server to do so. */
979 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
Trond Myklebust7fc38842012-10-15 11:51:21 -0400981 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500982 encode_string(xdr, hdr->taglen, hdr->tag);
983 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300984 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500985 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300986 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500987}
988
Trond Myklebustab19b482012-03-04 18:13:57 -0500989static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
990 uint32_t replen,
991 struct compound_hdr *hdr)
992{
993 encode_uint32(xdr, op);
994 hdr->nops++;
995 hdr->replen += replen;
996}
997
Andy Adamsond0179312008-12-23 16:06:17 -0500998static void encode_nops(struct compound_hdr *hdr)
999{
Trond Myklebust7fc38842012-10-15 11:51:21 -04001000 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -05001001 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002}
1003
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001004static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1005{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001006 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001007}
1008
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1010{
Trond Myklebustcb17e552012-03-04 18:13:56 -05001011 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012}
1013
David Quigleyaa9c2662013-05-22 12:50:44 -04001014static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1015 const struct nfs4_label *label,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001016 const umode_t *umask,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001017 const struct nfs_server *server,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001018 const uint32_t attrmask[])
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019{
1020 char owner_name[IDMAP_NAMESZ];
1021 char owner_group[IDMAP_NAMESZ];
1022 int owner_namelen = 0;
1023 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001024 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001025 unsigned i;
1026 uint32_t len = 0;
1027 uint32_t bmval_len;
1028 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
1030 /*
1031 * We reserve enough space to write the entire attribute buffer at once.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 */
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001033 if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001034 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001036 }
1037 if (iap->ia_valid & ATTR_MODE) {
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001038 if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001039 bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1040 len += 8;
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001041 } else if (attrmask[1] & FATTR4_WORD1_MODE) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001042 bmval[1] |= FATTR4_WORD1_MODE;
1043 len += 4;
1044 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001045 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001046 if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001047 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001049 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001050 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 /* XXX */
1052 strcpy(owner_name, "nobody");
1053 owner_namelen = sizeof("nobody") - 1;
1054 /* goto out; */
1055 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001056 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1058 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001059 if ((iap->ia_valid & ATTR_GID) &&
1060 (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001061 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001063 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001064 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 strcpy(owner_group, "nobody");
1066 owner_grouplen = sizeof("nobody") - 1;
1067 /* goto out; */
1068 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001069 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1071 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001072 if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1073 if (iap->ia_valid & ATTR_ATIME_SET) {
1074 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1075 len += 16;
1076 } else if (iap->ia_valid & ATTR_ATIME) {
1077 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1078 len += 4;
1079 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001081 if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1082 if (iap->ia_valid & ATTR_MTIME_SET) {
1083 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1084 len += 16;
1085 } else if (iap->ia_valid & ATTR_MTIME) {
1086 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1087 len += 4;
1088 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001090
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001091 if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001092 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1093 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1094 }
1095
1096 if (bmval[2] != 0)
1097 bmval_len = 3;
1098 else if (bmval[1] != 0)
1099 bmval_len = 2;
1100 else
1101 bmval_len = 1;
1102
1103 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1104
1105 *p++ = cpu_to_be32(bmval_len);
1106 for (i = 0; i < bmval_len; i++)
1107 *p++ = cpu_to_be32(bmval[i]);
1108 *p++ = cpu_to_be32(len);
1109
1110 if (bmval[0] & FATTR4_WORD0_SIZE)
1111 p = xdr_encode_hyper(p, iap->ia_size);
1112 if (bmval[1] & FATTR4_WORD1_MODE)
1113 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1114 if (bmval[1] & FATTR4_WORD1_OWNER)
1115 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1116 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1117 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1118 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1119 if (iap->ia_valid & ATTR_ATIME_SET) {
1120 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1121 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1122 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1123 } else
1124 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1125 }
1126 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1127 if (iap->ia_valid & ATTR_MTIME_SET) {
1128 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1129 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1130 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1131 } else
1132 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1133 }
1134 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001135 *p++ = cpu_to_be32(label->lfs);
1136 *p++ = cpu_to_be32(label->pi);
1137 *p++ = cpu_to_be32(label->len);
1138 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1139 }
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001140 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1141 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1142 *p++ = cpu_to_be32(*umask);
1143 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001144
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146}
1147
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001148static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001150 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1151 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152}
1153
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001154static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155{
Trond Myklebustab19b482012-03-04 18:13:57 -05001156 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001157 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001158 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159}
1160
Fred Isaman0b7c0152012-04-20 14:47:39 -04001161static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162{
Al Viro8687b632006-10-19 23:28:48 -07001163 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001164
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001165 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1166 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001167 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001168 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169}
1170
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001171static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172{
Al Viro8687b632006-10-19 23:28:48 -07001173 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001174
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001175 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1176 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
1178 switch (create->ftype) {
1179 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001180 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001181 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001182 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1183 create->u.symlink.len);
1184 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 break;
1186
1187 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001188 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001189 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001190 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 break;
1192
1193 default:
1194 break;
1195 }
1196
Benny Halevy811652b2009-08-14 17:19:34 +03001197 encode_string(xdr, create->name->len, create->name->name);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001198 encode_attrs(xdr, create->attrs, create->label, &create->umask,
1199 create->server, create->server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200}
1201
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001202static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203{
Andy Adamson05d564f2008-12-23 16:06:15 -05001204 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001206 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1207 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001208 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001209 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210}
1211
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001212static 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 -07001213{
Andy Adamson05d564f2008-12-23 16:06:15 -05001214 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001216 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1217 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001218 *p++ = cpu_to_be32(2);
1219 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001220 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221}
1222
Fred Isamandae100c2011-07-30 20:52:37 -04001223static void
1224encode_getattr_three(struct xdr_stream *xdr,
1225 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1226 struct compound_hdr *hdr)
1227{
1228 __be32 *p;
1229
Trond Myklebustab19b482012-03-04 18:13:57 -05001230 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001231 if (bm2) {
1232 p = reserve_space(xdr, 16);
1233 *p++ = cpu_to_be32(3);
1234 *p++ = cpu_to_be32(bm0);
1235 *p++ = cpu_to_be32(bm1);
1236 *p = cpu_to_be32(bm2);
1237 } else if (bm1) {
1238 p = reserve_space(xdr, 12);
1239 *p++ = cpu_to_be32(2);
1240 *p++ = cpu_to_be32(bm0);
1241 *p = cpu_to_be32(bm1);
1242 } else {
1243 p = reserve_space(xdr, 8);
1244 *p++ = cpu_to_be32(1);
1245 *p = cpu_to_be32(bm0);
1246 }
Fred Isamandae100c2011-07-30 20:52:37 -04001247}
1248
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001249static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250{
David Quigleya09df2c2013-05-22 12:50:41 -04001251 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1252 bitmask[1] & nfs4_fattr_bitmap[1],
1253 bitmask[2] & nfs4_fattr_bitmap[2],
1254 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255}
1256
Andy Adamson88034c32012-05-23 05:02:34 -04001257static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001258 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001259 struct compound_hdr *hdr)
1260{
1261 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001262 bitmask[0] & open_bitmap[0],
1263 bitmask[1] & open_bitmap[1],
1264 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001265 hdr);
1266}
1267
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001268static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269{
Fred Isamandae100c2011-07-30 20:52:37 -04001270 encode_getattr_three(xdr,
1271 bitmask[0] & nfs4_fsinfo_bitmap[0],
1272 bitmask[1] & nfs4_fsinfo_bitmap[1],
1273 bitmask[2] & nfs4_fsinfo_bitmap[2],
1274 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275}
1276
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001277static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001278{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001279 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1280 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001281}
1282
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001283static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284{
Trond Myklebustab19b482012-03-04 18:13:57 -05001285 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286}
1287
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001288static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
Trond Myklebustab19b482012-03-04 18:13:57 -05001290 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001291 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292}
1293
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001294static inline int nfs4_lock_type(struct file_lock *fl, int block)
1295{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001296 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001297 return block ? NFS4_READW_LT : NFS4_READ_LT;
1298 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1299}
1300
1301static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1302{
1303 if (fl->fl_end == OFFSET_MAX)
1304 return ~(uint64_t)0;
1305 return fl->fl_end - fl->fl_start + 1;
1306}
1307
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001308static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1309{
1310 __be32 *p;
1311
Trond Myklebustd035c362010-12-21 10:45:27 -05001312 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001313 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001314 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001315 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001316 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001317 xdr_encode_hyper(p, lowner->id);
1318}
1319
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320/*
1321 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1322 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1323 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001324static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325{
Al Viro8687b632006-10-19 23:28:48 -07001326 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001328 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1329 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001330 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1331 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001332 p = xdr_encode_hyper(p, args->fl->fl_start);
1333 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001334 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001335 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001336 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001337 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001338 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001339 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 }
1341 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001342 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001343 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345}
1346
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001347static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348{
Al Viro8687b632006-10-19 23:28:48 -07001349 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001351 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1352 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001353 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001354 p = xdr_encode_hyper(p, args->fl->fl_start);
1355 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001356 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357}
1358
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001359static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360{
Al Viro8687b632006-10-19 23:28:48 -07001361 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001363 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1364 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001365 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001366 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001367 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001368 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001369 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370}
1371
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001372static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1373{
Trond Myklebustab19b482012-03-04 18:13:57 -05001374 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001375 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001376}
1377
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001378static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379{
Trond Myklebustab19b482012-03-04 18:13:57 -05001380 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001381 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382}
1383
Jeff Layton5b5faaf2017-06-29 06:34:52 -07001384static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
1385{
1386 encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
1387}
1388
Trond Myklebust6ae37332015-01-30 14:21:14 -05001389static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390{
Al Viro8687b632006-10-19 23:28:48 -07001391 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
Benny Halevy13c65ce2009-08-14 17:19:25 +03001393 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001394 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001395 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396}
1397
1398static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1399{
Al Viro8687b632006-10-19 23:28:48 -07001400 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 /*
1402 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1403 * owner 4 = 32
1404 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001405 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001406 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001407 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001408 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001409 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001410 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001411 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001412 *p++ = cpu_to_be32(arg->id.uniquifier);
1413 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414}
1415
1416static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1417{
Al Viro8687b632006-10-19 23:28:48 -07001418 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
Benny Halevy13c65ce2009-08-14 17:19:25 +03001420 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001421 switch(arg->createmode) {
1422 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001423 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001424 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1425 arg->server, arg->server->attr_bitmask);
Andy Adamson05d564f2008-12-23 16:06:15 -05001426 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001427 case NFS4_CREATE_GUARDED:
1428 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001429 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1430 arg->server, arg->server->attr_bitmask);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001431 break;
1432 case NFS4_CREATE_EXCLUSIVE:
1433 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1434 encode_nfs4_verifier(xdr, &arg->u.verifier);
1435 break;
1436 case NFS4_CREATE_EXCLUSIVE4_1:
1437 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1438 encode_nfs4_verifier(xdr, &arg->u.verifier);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001439 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1440 arg->server, arg->server->exclcreat_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 }
1442}
1443
1444static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1445{
Al Viro8687b632006-10-19 23:28:48 -07001446 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
Benny Halevy13c65ce2009-08-14 17:19:25 +03001448 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001450 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001451 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001452 break;
1453 default:
Benny Halevy34558512009-08-14 17:19:30 +03001454 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001455 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 }
1457}
1458
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001459static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460{
Al Viro8687b632006-10-19 23:28:48 -07001461 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Benny Halevy13c65ce2009-08-14 17:19:25 +03001463 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001465 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001466 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001467 break;
1468 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001469 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001470 break;
1471 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001472 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001473 break;
1474 default:
1475 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 }
1477}
1478
1479static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1480{
Al Viro8687b632006-10-19 23:28:48 -07001481 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Benny Halevy13c65ce2009-08-14 17:19:25 +03001483 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001484 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 encode_string(xdr, name->len, name->name);
1486}
1487
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001488static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489{
Al Viro8687b632006-10-19 23:28:48 -07001490 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Benny Halevy13c65ce2009-08-14 17:19:25 +03001492 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001493 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 encode_delegation_type(xdr, type);
1495}
1496
1497static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1498{
Al Viro8687b632006-10-19 23:28:48 -07001499 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001501 p = reserve_space(xdr, 4);
1502 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1503 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 encode_string(xdr, name->len, name->name);
1505}
1506
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001507static inline void encode_claim_fh(struct xdr_stream *xdr)
1508{
1509 __be32 *p;
1510
1511 p = reserve_space(xdr, 4);
1512 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1513}
1514
1515static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1516{
1517 __be32 *p;
1518
1519 p = reserve_space(xdr, 4);
1520 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1521 encode_nfs4_stateid(xdr, stateid);
1522}
1523
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001524static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525{
Trond Myklebustab19b482012-03-04 18:13:57 -05001526 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 encode_openhdr(xdr, arg);
1528 encode_opentype(xdr, arg);
1529 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001530 case NFS4_OPEN_CLAIM_NULL:
1531 encode_claim_null(xdr, arg->name);
1532 break;
1533 case NFS4_OPEN_CLAIM_PREVIOUS:
1534 encode_claim_previous(xdr, arg->u.delegation_type);
1535 break;
1536 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1537 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1538 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001539 case NFS4_OPEN_CLAIM_FH:
1540 encode_claim_fh(xdr);
1541 break;
1542 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1543 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1544 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001545 default:
1546 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548}
1549
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001550static 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 -07001551{
Trond Myklebustab19b482012-03-04 18:13:57 -05001552 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001553 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001554 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555}
1556
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001557static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558{
Trond Myklebustab19b482012-03-04 18:13:57 -05001559 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001560 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001561 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001562 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563}
1564
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001565static void
Andy Adamsond0179312008-12-23 16:06:17 -05001566encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567{
Trond Myklebustab19b482012-03-04 18:13:57 -05001568 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001569 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570}
1571
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001572static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573{
Trond Myklebustab19b482012-03-04 18:13:57 -05001574 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575}
1576
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001577static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1578 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579{
Al Viro8687b632006-10-19 23:28:48 -07001580 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
Trond Myklebustab19b482012-03-04 18:13:57 -05001582 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001583 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Benny Halevy13c65ce2009-08-14 17:19:25 +03001585 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001586 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001587 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588}
1589
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001590static 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 -07001591{
David Quigleyaa9c2662013-05-22 12:50:44 -04001592 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001593 FATTR4_WORD0_RDATTR_ERROR,
1594 FATTR4_WORD1_MOUNTED_ON_FILEID,
1595 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001596 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001597 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001598 uint32_t attrlen = 0;
1599 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001601 if (readdir->plus) {
1602 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001603 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001604 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1605 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1606 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1607 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001608 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001609 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001610 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001611 /* Use mounted_on_fileid only if the server supports it */
1612 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1613 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001614 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1615 attrs[i] &= readdir->bitmask[i];
1616 if (attrs[i] != 0)
1617 attrlen = i+1;
1618 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001619
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001620 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001621 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001622 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001623 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001624 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001625 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001626 *p++ = cpu_to_be32(attrlen);
1627 for (i = 0; i < attrlen; i++)
1628 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001629 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001630
1631 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001632 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001633 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001634 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001635 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001636 attrs[1] & readdir->bitmask[1],
1637 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638}
1639
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001640static 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 -07001641{
Trond Myklebustab19b482012-03-04 18:13:57 -05001642 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643}
1644
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001645static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646{
Trond Myklebustab19b482012-03-04 18:13:57 -05001647 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001648 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
1650
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001651static 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 -07001652{
Trond Myklebustab19b482012-03-04 18:13:57 -05001653 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001654 encode_string(xdr, oldname->len, oldname->name);
1655 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656}
1657
Chuck Leverbb4dae52012-03-01 17:01:48 -05001658static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1659 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001661 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001662 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663}
1664
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001665static void
Andy Adamsond0179312008-12-23 16:06:17 -05001666encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001667{
Trond Myklebustab19b482012-03-04 18:13:57 -05001668 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001669}
1670
Chuck Lever9f06c712010-12-14 14:59:18 +00001671static void
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001672encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1673 struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001674{
Al Viro8687b632006-10-19 23:28:48 -07001675 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001676
Trond Myklebustab19b482012-03-04 18:13:57 -05001677 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001678 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001679 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001680 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001681 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001682 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001683 *p = cpu_to_be32(arg->acl_len);
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01001684 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001685}
1686
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001687static void
Andy Adamsond0179312008-12-23 16:06:17 -05001688encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689{
Trond Myklebustab19b482012-03-04 18:13:57 -05001690 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691}
1692
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001693static 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 -07001694{
Trond Myklebustab19b482012-03-04 18:13:57 -05001695 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001696 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001697 encode_attrs(xdr, arg->iap, arg->label, NULL, server,
1698 server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699}
1700
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001701static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702{
Al Viro8687b632006-10-19 23:28:48 -07001703 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
Trond Myklebust70019512012-03-04 20:49:32 -05001705 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001706 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
Jeff Layton3a6bb732015-06-09 19:43:57 -04001708 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1709 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001710 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001711 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1713 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001714 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001715 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716}
1717
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001718static 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 -07001719{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001720 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1721 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001722 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001723 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724}
1725
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001726static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1727 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728{
Al Viro8687b632006-10-19 23:28:48 -07001729 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
Trond Myklebustab19b482012-03-04 18:13:57 -05001731 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001732 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
Benny Halevy13c65ce2009-08-14 17:19:25 +03001734 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001735 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001736 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001737 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
1739 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740}
1741
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001742static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743{
Trond Myklebustab19b482012-03-04 18:13:57 -05001744 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001745 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001747
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001748static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1749{
Trond Myklebustab19b482012-03-04 18:13:57 -05001750 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001751 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001752}
1753
Benny Halevy99fe60d2009-04-01 09:22:29 -04001754#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001755/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001756static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001757 const struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001758 struct compound_hdr *hdr)
1759{
1760 __be32 *p;
1761
1762 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1763 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001764 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001765 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001766 *p++ = cpu_to_be32(args->dir);
1767 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001768}
1769
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001770static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001771{
1772 unsigned int i;
1773 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1774 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1775 encode_uint32(xdr, op_map->u.words[i]);
1776}
1777
Benny Halevy99fe60d2009-04-01 09:22:29 -04001778static void encode_exchange_id(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001779 const struct nfs41_exchange_id_args *args,
Benny Halevy99fe60d2009-04-01 09:22:29 -04001780 struct compound_hdr *hdr)
1781{
1782 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001783 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001784 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001785
Trond Myklebust70019512012-03-04 20:49:32 -05001786 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Trond Myklebustfd405592017-08-01 16:02:47 -04001787 encode_nfs4_verifier(xdr, &args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001788
Jeff Layton3a6bb732015-06-09 19:43:57 -04001789 encode_string(xdr, strlen(args->client->cl_owner_id),
1790 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001791
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001792 encode_uint32(xdr, args->flags);
1793 encode_uint32(xdr, args->state_protect.how);
1794
1795 switch (args->state_protect.how) {
1796 case SP4_NONE:
1797 break;
1798 case SP4_MACH_CRED:
1799 encode_op_map(xdr, &args->state_protect.enforce);
1800 encode_op_map(xdr, &args->state_protect.allow);
1801 break;
1802 default:
1803 WARN_ON_ONCE(1);
1804 break;
1805 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001806
1807 if (send_implementation_id &&
1808 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1809 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001810 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001811 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1812 utsname()->sysname, utsname()->release,
1813 utsname()->version, utsname()->machine);
1814
1815 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001816 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001817
1818 encode_string(xdr,
1819 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1820 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1821 encode_string(xdr, len, impl_name);
1822 /* just send zeros for nii_date - the date is in nii_name */
1823 p = reserve_space(xdr, 12);
1824 p = xdr_encode_hyper(p, 0);
1825 *p = cpu_to_be32(0);
1826 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001827 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001828}
Andy Adamsonfc931582009-04-01 09:22:31 -04001829
1830static void encode_create_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001831 const struct nfs41_create_session_args *args,
Andy Adamsonfc931582009-04-01 09:22:31 -04001832 struct compound_hdr *hdr)
1833{
1834 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001835 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001836 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001837 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001838 u32 max_resp_sz_cached;
1839
1840 /*
1841 * Assumes OPEN is the biggest non-idempotent compound.
1842 * 2 is the verifier.
1843 */
J. Bruce Fields35c036e2017-09-20 12:42:13 -04001844 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
1845 * XDR_UNIT + RPC_MAX_AUTH_SIZE;
Andy Adamsonfc931582009-04-01 09:22:31 -04001846
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001847 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001848 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001849 p = xdr_encode_hyper(p, args->clientid);
1850 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001851 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001852
Andy Adamsonfc931582009-04-01 09:22:31 -04001853 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001854 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001855 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1856 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001857 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001858 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1859 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1860 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001861
1862 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001863 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001864 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1865 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1866 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1867 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1868 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1869 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001870
Benny Halevye75bc1c2009-08-14 17:18:54 +03001871 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001872 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001873 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001874
1875 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001876 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001877 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001878 *p++ = cpu_to_be32(0); /* UID */
1879 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001880 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001881}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001882
1883static void encode_destroy_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001884 const struct nfs4_session *session,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001885 struct compound_hdr *hdr)
1886{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001887 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1888 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001889}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001890
Trond Myklebust66245532012-05-25 17:18:09 -04001891static void encode_destroy_clientid(struct xdr_stream *xdr,
1892 uint64_t clientid,
1893 struct compound_hdr *hdr)
1894{
1895 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1896 encode_uint64(xdr, clientid);
1897}
1898
Ricardo Labiaga180197532009-12-05 16:08:40 -05001899static void encode_reclaim_complete(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001900 const struct nfs41_reclaim_complete_args *args,
Ricardo Labiaga180197532009-12-05 16:08:40 -05001901 struct compound_hdr *hdr)
1902{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001903 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1904 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001905}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001906#endif /* CONFIG_NFS_V4_1 */
1907
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001908static void encode_sequence(struct xdr_stream *xdr,
1909 const struct nfs4_sequence_args *args,
1910 struct compound_hdr *hdr)
1911{
1912#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001913 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001914 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001915 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001916 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001917
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001918 tp = slot->table;
1919 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001920 if (!session)
1921 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001922
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001923 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001924
1925 /*
1926 * Sessionid + seqid + slotid + max slotid + cache_this
1927 */
1928 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1929 "max_slotid=%d cache_this=%d\n",
1930 __func__,
1931 ((u32 *)session->sess_id.data)[0],
1932 ((u32 *)session->sess_id.data)[1],
1933 ((u32 *)session->sess_id.data)[2],
1934 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001935 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001936 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001937 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001938 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001939 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001940 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001941 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001942 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001943#endif /* CONFIG_NFS_V4_1 */
1944}
1945
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001946#ifdef CONFIG_NFS_V4_1
1947static void
1948encode_getdeviceinfo(struct xdr_stream *xdr,
1949 const struct nfs4_getdeviceinfo_args *args,
1950 struct compound_hdr *hdr)
1951{
1952 __be32 *p;
1953
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001954 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001955 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001956 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1957 NFS4_DEVICEID4_SIZE);
1958 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001959 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001960
1961 p = reserve_space(xdr, 4 + 4);
1962 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001963 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001964}
1965
1966static void
1967encode_layoutget(struct xdr_stream *xdr,
1968 const struct nfs4_layoutget_args *args,
1969 struct compound_hdr *hdr)
1970{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001971 __be32 *p;
1972
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001973 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1974 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001975 *p++ = cpu_to_be32(0); /* Signal layout available */
1976 *p++ = cpu_to_be32(args->type);
1977 *p++ = cpu_to_be32(args->range.iomode);
1978 p = xdr_encode_hyper(p, args->range.offset);
1979 p = xdr_encode_hyper(p, args->range.length);
1980 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001981 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001982 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001983
1984 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1985 __func__,
1986 args->type,
1987 args->range.iomode,
1988 (unsigned long)args->range.offset,
1989 (unsigned long)args->range.length,
1990 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001991}
Andy Adamson863a3c62011-03-23 13:27:54 +00001992
1993static int
1994encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001995 struct inode *inode,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001996 const struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001997 struct compound_hdr *hdr)
1998{
1999 __be32 *p;
2000
2001 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2002 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2003
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002004 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2005 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00002006 /* Only whole file layouts */
2007 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002008 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002009 *p = cpu_to_be32(0); /* reclaim */
2010 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04002011 if (args->lastbytewritten != U64_MAX) {
2012 p = reserve_space(xdr, 20);
2013 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2014 p = xdr_encode_hyper(p, args->lastbytewritten);
2015 } else {
2016 p = reserve_space(xdr, 12);
2017 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2018 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002019 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2020 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002021
Trond Myklebust73504742017-04-20 16:48:14 -04002022 encode_uint32(xdr, args->layoutupdate_len);
2023 if (args->layoutupdate_pages)
2024 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2025 args->layoutupdate_len);
Andy Adamson863a3c62011-03-23 13:27:54 +00002026
Andy Adamson863a3c62011-03-23 13:27:54 +00002027 return 0;
2028}
Benny Halevycbe82602011-05-22 19:52:37 +03002029
2030static void
2031encode_layoutreturn(struct xdr_stream *xdr,
2032 const struct nfs4_layoutreturn_args *args,
2033 struct compound_hdr *hdr)
2034{
2035 __be32 *p;
2036
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002037 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2038 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002039 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2040 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002041 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002042 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002043 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002044 p = xdr_encode_hyper(p, args->range.offset);
2045 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002046 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002047 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002048 spin_unlock(&args->inode->i_lock);
Trond Myklebust4d796d72016-09-23 11:38:08 -04002049 if (args->ld_private->ops && args->ld_private->ops->encode)
2050 args->ld_private->ops->encode(xdr, args, args->ld_private);
Trond Myklebust94e5c572016-09-15 18:49:52 -04002051 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002052 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002053}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002054
2055static int
2056encode_secinfo_no_name(struct xdr_stream *xdr,
2057 const struct nfs41_secinfo_no_name_args *args,
2058 struct compound_hdr *hdr)
2059{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002060 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2061 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002062 return 0;
2063}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002064
2065static void encode_test_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002066 const struct nfs41_test_stateid_args *args,
Bryan Schumaker7d974792011-06-02 14:59:08 -04002067 struct compound_hdr *hdr)
2068{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002069 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2070 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002071 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002072}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002073
2074static void encode_free_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002075 const struct nfs41_free_stateid_args *args,
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002076 struct compound_hdr *hdr)
2077{
Trond Myklebustab19b482012-03-04 18:13:57 -05002078 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002079 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002080}
Trond Myklebustcf805162016-11-15 14:56:07 -05002081#else
2082static inline void
2083encode_layoutreturn(struct xdr_stream *xdr,
2084 const struct nfs4_layoutreturn_args *args,
2085 struct compound_hdr *hdr)
2086{
2087}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002088#endif /* CONFIG_NFS_V4_1 */
2089
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090/*
2091 * END OF "GENERIC" ENCODE ROUTINES.
2092 */
2093
Benny Halevy66cc0422009-04-01 09:22:10 -04002094static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2095{
2096#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002097 struct nfs4_session *session = args->sa_slot->table->session;
2098 if (session)
2099 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002100#endif /* CONFIG_NFS_V4_1 */
2101 return 0;
2102}
2103
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104/*
2105 * Encode an ACCESS request
2106 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002107static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002108 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002110 const struct nfs4_accessargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002112 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114
Chuck Lever9f06c712010-12-14 14:59:18 +00002115 encode_compound_hdr(xdr, req, &hdr);
2116 encode_sequence(xdr, &args->seq_args, &hdr);
2117 encode_putfh(xdr, args->fh, &hdr);
2118 encode_access(xdr, args->access, &hdr);
2119 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002120 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121}
2122
2123/*
2124 * Encode LOOKUP request
2125 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002126static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002127 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002129 const struct nfs4_lookup_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002131 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133
Chuck Lever9f06c712010-12-14 14:59:18 +00002134 encode_compound_hdr(xdr, req, &hdr);
2135 encode_sequence(xdr, &args->seq_args, &hdr);
2136 encode_putfh(xdr, args->dir_fh, &hdr);
2137 encode_lookup(xdr, args->name, &hdr);
2138 encode_getfh(xdr, &hdr);
2139 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002140 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141}
2142
2143/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07002144 * Encode LOOKUPP request
2145 */
2146static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
2147 const void *data)
2148{
2149 const struct nfs4_lookupp_arg *args = data;
2150 struct compound_hdr hdr = {
2151 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2152 };
2153
2154 encode_compound_hdr(xdr, req, &hdr);
2155 encode_sequence(xdr, &args->seq_args, &hdr);
2156 encode_putfh(xdr, args->fh, &hdr);
2157 encode_lookupp(xdr, &hdr);
2158 encode_getfh(xdr, &hdr);
2159 encode_getfattr(xdr, args->bitmask, &hdr);
2160 encode_nops(&hdr);
2161}
2162
2163/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 * Encode LOOKUP_ROOT request
2165 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002166static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2167 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002168 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002170 const struct nfs4_lookup_root_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002172 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
Chuck Lever9f06c712010-12-14 14:59:18 +00002175 encode_compound_hdr(xdr, req, &hdr);
2176 encode_sequence(xdr, &args->seq_args, &hdr);
2177 encode_putrootfh(xdr, &hdr);
2178 encode_getfh(xdr, &hdr);
2179 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002180 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181}
2182
2183/*
2184 * Encode REMOVE request
2185 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002186static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002187 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002189 const struct nfs_removeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002191 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193
Chuck Lever9f06c712010-12-14 14:59:18 +00002194 encode_compound_hdr(xdr, req, &hdr);
2195 encode_sequence(xdr, &args->seq_args, &hdr);
2196 encode_putfh(xdr, args->fh, &hdr);
2197 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002198 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199}
2200
2201/*
2202 * Encode RENAME request
2203 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002204static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002205 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002207 const struct nfs_renameargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002209 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
Chuck Lever9f06c712010-12-14 14:59:18 +00002212 encode_compound_hdr(xdr, req, &hdr);
2213 encode_sequence(xdr, &args->seq_args, &hdr);
2214 encode_putfh(xdr, args->old_dir, &hdr);
2215 encode_savefh(xdr, &hdr);
2216 encode_putfh(xdr, args->new_dir, &hdr);
2217 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002218 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219}
2220
2221/*
2222 * Encode LINK request
2223 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002224static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002225 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002227 const struct nfs4_link_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002229 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
Chuck Lever9f06c712010-12-14 14:59:18 +00002232 encode_compound_hdr(xdr, req, &hdr);
2233 encode_sequence(xdr, &args->seq_args, &hdr);
2234 encode_putfh(xdr, args->fh, &hdr);
2235 encode_savefh(xdr, &hdr);
2236 encode_putfh(xdr, args->dir_fh, &hdr);
2237 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002238 encode_restorefh(xdr, &hdr);
2239 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002240 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241}
2242
2243/*
2244 * Encode CREATE request
2245 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002246static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002247 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002249 const struct nfs4_create_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002251 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253
Chuck Lever9f06c712010-12-14 14:59:18 +00002254 encode_compound_hdr(xdr, req, &hdr);
2255 encode_sequence(xdr, &args->seq_args, &hdr);
2256 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002257 encode_create(xdr, args, &hdr);
2258 encode_getfh(xdr, &hdr);
2259 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002260 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261}
2262
2263/*
2264 * Encode SYMLINK request
2265 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002266static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002267 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002269 const struct nfs4_create_arg *args = data;
2270
Chuck Lever9f06c712010-12-14 14:59:18 +00002271 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272}
2273
2274/*
2275 * Encode GETATTR request
2276 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002277static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002278 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002280 const struct nfs4_getattr_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002282 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284
Chuck Lever9f06c712010-12-14 14:59:18 +00002285 encode_compound_hdr(xdr, req, &hdr);
2286 encode_sequence(xdr, &args->seq_args, &hdr);
2287 encode_putfh(xdr, args->fh, &hdr);
2288 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002289 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290}
2291
2292/*
2293 * Encode a CLOSE request
2294 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002295static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002296 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002298 const struct nfs_closeargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002299 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002300 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002301 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302
Chuck Lever9f06c712010-12-14 14:59:18 +00002303 encode_compound_hdr(xdr, req, &hdr);
2304 encode_sequence(xdr, &args->seq_args, &hdr);
2305 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002306 if (args->lr_args)
2307 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002308 if (args->bitmask != NULL)
2309 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebustd8d84982016-12-19 12:14:44 -05002310 encode_close(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002311 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312}
2313
2314/*
2315 * Encode an OPEN request
2316 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002317static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002318 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002320 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002322 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Chuck Lever9f06c712010-12-14 14:59:18 +00002325 encode_compound_hdr(xdr, req, &hdr);
2326 encode_sequence(xdr, &args->seq_args, &hdr);
2327 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002328 encode_open(xdr, args, &hdr);
2329 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002330 if (args->access)
2331 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002332 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002333 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334}
2335
2336/*
2337 * Encode an OPEN_CONFIRM request
2338 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002339static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2340 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002341 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002343 const struct nfs_open_confirmargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002345 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347
Chuck Lever9f06c712010-12-14 14:59:18 +00002348 encode_compound_hdr(xdr, req, &hdr);
2349 encode_putfh(xdr, args->fh, &hdr);
2350 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002351 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352}
2353
2354/*
2355 * Encode an OPEN request with no attributes.
2356 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002357static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2358 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002359 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002361 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002363 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365
Chuck Lever9f06c712010-12-14 14:59:18 +00002366 encode_compound_hdr(xdr, req, &hdr);
2367 encode_sequence(xdr, &args->seq_args, &hdr);
2368 encode_putfh(xdr, args->fh, &hdr);
2369 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002370 if (args->access)
2371 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002372 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002373 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374}
2375
2376/*
2377 * Encode an OPEN_DOWNGRADE request
2378 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002379static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2380 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002381 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002383 const struct nfs_closeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002385 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387
Chuck Lever9f06c712010-12-14 14:59:18 +00002388 encode_compound_hdr(xdr, req, &hdr);
2389 encode_sequence(xdr, &args->seq_args, &hdr);
2390 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustb6808142016-11-20 13:34:16 -05002391 if (args->lr_args)
2392 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002393 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002394 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395}
2396
2397/*
2398 * Encode a LOCK request
2399 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002400static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002401 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002403 const struct nfs_lock_args *args = data;
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_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002412 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413}
2414
2415/*
2416 * Encode a LOCKT request
2417 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002418static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002419 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002421 const struct nfs_lockt_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002423 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425
Chuck Lever9f06c712010-12-14 14:59:18 +00002426 encode_compound_hdr(xdr, req, &hdr);
2427 encode_sequence(xdr, &args->seq_args, &hdr);
2428 encode_putfh(xdr, args->fh, &hdr);
2429 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002430 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431}
2432
2433/*
2434 * Encode a LOCKU request
2435 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002436static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002437 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002439 const struct nfs_locku_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002441 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443
Chuck Lever9f06c712010-12-14 14:59:18 +00002444 encode_compound_hdr(xdr, req, &hdr);
2445 encode_sequence(xdr, &args->seq_args, &hdr);
2446 encode_putfh(xdr, args->fh, &hdr);
2447 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002448 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449}
2450
Chuck Lever9f06c712010-12-14 14:59:18 +00002451static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2452 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002453 const void *data)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002454{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002455 const struct nfs_release_lockowner_args *args = data;
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002456 struct compound_hdr hdr = {
2457 .minorversion = 0,
2458 };
2459
Chuck Lever9f06c712010-12-14 14:59:18 +00002460 encode_compound_hdr(xdr, req, &hdr);
2461 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002462 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002463}
2464
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465/*
2466 * Encode a READLINK request
2467 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002468static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002469 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002471 const struct nfs4_readlink *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002473 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
Chuck Lever9f06c712010-12-14 14:59:18 +00002476 encode_compound_hdr(xdr, req, &hdr);
2477 encode_sequence(xdr, &args->seq_args, &hdr);
2478 encode_putfh(xdr, args->fh, &hdr);
2479 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002480
Benny Halevy28f56692009-04-01 09:22:09 -04002481 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002482 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002483 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484}
2485
2486/*
2487 * Encode a READDIR request
2488 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002489static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002490 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002492 const struct nfs4_readdir_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002494 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496
Chuck Lever9f06c712010-12-14 14:59:18 +00002497 encode_compound_hdr(xdr, req, &hdr);
2498 encode_sequence(xdr, &args->seq_args, &hdr);
2499 encode_putfh(xdr, args->fh, &hdr);
2500 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002501
Benny Halevy28f56692009-04-01 09:22:09 -04002502 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002503 args->pgbase, args->count);
2504 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002505 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002506 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002507 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508}
2509
2510/*
2511 * Encode a READ request
2512 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002513static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002514 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002516 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002518 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520
Chuck Lever9f06c712010-12-14 14:59:18 +00002521 encode_compound_hdr(xdr, req, &hdr);
2522 encode_sequence(xdr, &args->seq_args, &hdr);
2523 encode_putfh(xdr, args->fh, &hdr);
2524 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525
Benny Halevy28f56692009-04-01 09:22:09 -04002526 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002528 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002529 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530}
2531
2532/*
2533 * Encode an SETATTR request
2534 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002535static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002536 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002538 const struct nfs_setattrargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002539 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002540 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002541 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542
Chuck Lever9f06c712010-12-14 14:59:18 +00002543 encode_compound_hdr(xdr, req, &hdr);
2544 encode_sequence(xdr, &args->seq_args, &hdr);
2545 encode_putfh(xdr, args->fh, &hdr);
2546 encode_setattr(xdr, args, args->server, &hdr);
2547 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002548 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549}
2550
2551/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002552 * Encode a GETACL request
2553 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002554static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002555 const void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002556{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002557 const struct nfs_getaclargs *args = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002558 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002559 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002560 };
Benny Halevy28f56692009-04-01 09:22:09 -04002561 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002562
Chuck Lever9f06c712010-12-14 14:59:18 +00002563 encode_compound_hdr(xdr, req, &hdr);
2564 encode_sequence(xdr, &args->seq_args, &hdr);
2565 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fields6682c142017-02-23 14:53:39 -05002566 replen = hdr.replen + op_decode_hdr_maxsz;
Chuck Lever9f06c712010-12-14 14:59:18 +00002567 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002568
Benny Halevy28f56692009-04-01 09:22:09 -04002569 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01002570 args->acl_pages, 0, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002571
Andy Adamsond0179312008-12-23 16:06:17 -05002572 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002573}
2574
2575/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 * Encode a WRITE request
2577 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002578static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002579 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002581 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002583 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585
Chuck Lever9f06c712010-12-14 14:59:18 +00002586 encode_compound_hdr(xdr, req, &hdr);
2587 encode_sequence(xdr, &args->seq_args, &hdr);
2588 encode_putfh(xdr, args->fh, &hdr);
2589 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002590 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002591 if (args->bitmask)
2592 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002593 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594}
2595
2596/*
2597 * a COMMIT request
2598 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002599static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002600 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002602 const struct nfs_commitargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002604 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606
Chuck Lever9f06c712010-12-14 14:59:18 +00002607 encode_compound_hdr(xdr, req, &hdr);
2608 encode_sequence(xdr, &args->seq_args, &hdr);
2609 encode_putfh(xdr, args->fh, &hdr);
2610 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002611 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612}
2613
2614/*
2615 * FSINFO request
2616 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002617static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002618 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002620 const struct nfs4_fsinfo_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002622 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624
Chuck Lever9f06c712010-12-14 14:59:18 +00002625 encode_compound_hdr(xdr, req, &hdr);
2626 encode_sequence(xdr, &args->seq_args, &hdr);
2627 encode_putfh(xdr, args->fh, &hdr);
2628 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002629 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630}
2631
2632/*
2633 * a PATHCONF request
2634 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002635static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002636 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002638 const struct nfs4_pathconf_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002640 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642
Chuck Lever9f06c712010-12-14 14:59:18 +00002643 encode_compound_hdr(xdr, req, &hdr);
2644 encode_sequence(xdr, &args->seq_args, &hdr);
2645 encode_putfh(xdr, args->fh, &hdr);
2646 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002647 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002648 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649}
2650
2651/*
2652 * a STATFS request
2653 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002654static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002655 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002657 const struct nfs4_statfs_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002659 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661
Chuck Lever9f06c712010-12-14 14:59:18 +00002662 encode_compound_hdr(xdr, req, &hdr);
2663 encode_sequence(xdr, &args->seq_args, &hdr);
2664 encode_putfh(xdr, args->fh, &hdr);
2665 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002666 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002667 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668}
2669
2670/*
2671 * GETATTR_BITMAP request
2672 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002673static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2674 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002675 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002677 const struct nfs4_server_caps_arg *args = data;
Kinglong Mee8c612822015-08-26 21:12:58 +08002678 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002680 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
Chuck Lever9f06c712010-12-14 14:59:18 +00002683 encode_compound_hdr(xdr, req, &hdr);
2684 encode_sequence(xdr, &args->seq_args, &hdr);
2685 encode_putfh(xdr, args->fhandle, &hdr);
Kinglong Mee8c612822015-08-26 21:12:58 +08002686 encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002687 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688}
2689
2690/*
2691 * a RENEW request
2692 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002693static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002694 const void *data)
2695
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002697 const struct nfs_client *clp = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002699 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 };
2701
Chuck Lever9f06c712010-12-14 14:59:18 +00002702 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002703 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002704 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705}
2706
2707/*
2708 * a SETCLIENTID request
2709 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002710static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2711 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002712 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002714 const struct nfs4_setclientid *sc = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002716 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 };
2718
Chuck Lever9f06c712010-12-14 14:59:18 +00002719 encode_compound_hdr(xdr, req, &hdr);
2720 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002721 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722}
2723
2724/*
2725 * a SETCLIENTID_CONFIRM request
2726 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002727static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2728 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002729 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002731 const struct nfs4_setclientid_res *arg = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002733 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735
Chuck Lever9f06c712010-12-14 14:59:18 +00002736 encode_compound_hdr(xdr, req, &hdr);
2737 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002738 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739}
2740
2741/*
2742 * DELEGRETURN request
2743 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002744static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2745 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002746 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002748 const struct nfs4_delegreturnargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002750 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752
Chuck Lever9f06c712010-12-14 14:59:18 +00002753 encode_compound_hdr(xdr, req, &hdr);
2754 encode_sequence(xdr, &args->seq_args, &hdr);
2755 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust586f1c32016-11-15 15:03:33 -05002756 if (args->lr_args)
2757 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05002758 if (args->bitmask)
2759 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002760 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002761 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762}
2763
2764/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002765 * Encode FS_LOCATIONS request
2766 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002767static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2768 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002769 const void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002770{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002771 const struct nfs4_fs_locations_arg *args = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002772 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002773 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002774 };
Benny Halevy28f56692009-04-01 09:22:09 -04002775 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002776
Chuck Lever9f06c712010-12-14 14:59:18 +00002777 encode_compound_hdr(xdr, req, &hdr);
2778 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002779 if (args->migration) {
2780 encode_putfh(xdr, args->fh, &hdr);
2781 replen = hdr.replen;
2782 encode_fs_locations(xdr, args->bitmask, &hdr);
2783 if (args->renew)
2784 encode_renew(xdr, args->clientid, &hdr);
2785 } else {
2786 encode_putfh(xdr, args->dir_fh, &hdr);
2787 encode_lookup(xdr, args->name, &hdr);
2788 replen = hdr.replen;
2789 encode_fs_locations(xdr, args->bitmask, &hdr);
2790 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002791
Chuck Leverb03d7352013-10-17 14:12:50 -04002792 /* Set up reply kvec to capture returned fs_locations array. */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002793 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2794 (struct page **)&args->page, 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002795 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002796}
2797
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002798/*
2799 * Encode SECINFO request
2800 */
2801static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2802 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002803 const void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002804{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002805 const struct nfs4_secinfo_arg *args = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002806 struct compound_hdr hdr = {
2807 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2808 };
2809
2810 encode_compound_hdr(xdr, req, &hdr);
2811 encode_sequence(xdr, &args->seq_args, &hdr);
2812 encode_putfh(xdr, args->dir_fh, &hdr);
2813 encode_secinfo(xdr, args->name, &hdr);
2814 encode_nops(&hdr);
2815}
2816
Chuck Lever44c99932013-10-17 14:13:30 -04002817/*
2818 * Encode FSID_PRESENT request
2819 */
2820static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2821 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002822 const void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04002823{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002824 const struct nfs4_fsid_present_arg *args = data;
Chuck Lever44c99932013-10-17 14:13:30 -04002825 struct compound_hdr hdr = {
2826 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2827 };
2828
2829 encode_compound_hdr(xdr, req, &hdr);
2830 encode_sequence(xdr, &args->seq_args, &hdr);
2831 encode_putfh(xdr, args->fh, &hdr);
2832 encode_getfh(xdr, &hdr);
2833 if (args->renew)
2834 encode_renew(xdr, args->clientid, &hdr);
2835 encode_nops(&hdr);
2836}
2837
Benny Halevy99fe60d2009-04-01 09:22:29 -04002838#if defined(CONFIG_NFS_V4_1)
2839/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002840 * BIND_CONN_TO_SESSION request
2841 */
2842static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2843 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002844 const void *data)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002845{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002846 const struct nfs41_bind_conn_to_session_args *args = data;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002847 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002848 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002849 };
2850
2851 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002852 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002853 encode_nops(&hdr);
2854}
2855
2856/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002857 * EXCHANGE_ID request
2858 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002859static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2860 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002861 const void *data)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002862{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002863 const struct nfs41_exchange_id_args *args = data;
Benny Halevy99fe60d2009-04-01 09:22:29 -04002864 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002865 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002866 };
2867
Chuck Lever9f06c712010-12-14 14:59:18 +00002868 encode_compound_hdr(xdr, req, &hdr);
2869 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002870 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002871}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002872
2873/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002874 * a CREATE_SESSION request
2875 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002876static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2877 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002878 const void *data)
Andy Adamsonfc931582009-04-01 09:22:31 -04002879{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002880 const struct nfs41_create_session_args *args = data;
Andy Adamsonfc931582009-04-01 09:22:31 -04002881 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002882 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002883 };
2884
Chuck Lever9f06c712010-12-14 14:59:18 +00002885 encode_compound_hdr(xdr, req, &hdr);
2886 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002887 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002888}
2889
2890/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002891 * a DESTROY_SESSION request
2892 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002893static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2894 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002895 const void *data)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002896{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002897 const struct nfs4_session *session = data;
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002898 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002899 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002900 };
2901
Chuck Lever9f06c712010-12-14 14:59:18 +00002902 encode_compound_hdr(xdr, req, &hdr);
2903 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002904 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002905}
2906
2907/*
Trond Myklebust66245532012-05-25 17:18:09 -04002908 * a DESTROY_CLIENTID request
2909 */
2910static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2911 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002912 const void *data)
Trond Myklebust66245532012-05-25 17:18:09 -04002913{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002914 const struct nfs_client *clp = data;
Trond Myklebust66245532012-05-25 17:18:09 -04002915 struct compound_hdr hdr = {
2916 .minorversion = clp->cl_mvops->minor_version,
2917 };
2918
2919 encode_compound_hdr(xdr, req, &hdr);
2920 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2921 encode_nops(&hdr);
2922}
2923
2924/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002925 * a SEQUENCE request
2926 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002927static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002928 const void *data)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002929{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002930 const struct nfs4_sequence_args *args = data;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002931 struct compound_hdr hdr = {
2932 .minorversion = nfs4_xdr_minorversion(args),
2933 };
2934
Chuck Lever9f06c712010-12-14 14:59:18 +00002935 encode_compound_hdr(xdr, req, &hdr);
2936 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002937 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002938}
2939
2940/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002941 * a GET_LEASE_TIME request
2942 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002943static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2944 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002945 const void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002946{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002947 const struct nfs4_get_lease_time_args *args = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04002948 struct compound_hdr hdr = {
2949 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2950 };
Fred Isamandae100c2011-07-30 20:52:37 -04002951 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002952
Chuck Lever9f06c712010-12-14 14:59:18 +00002953 encode_compound_hdr(xdr, req, &hdr);
2954 encode_sequence(xdr, &args->la_seq_args, &hdr);
2955 encode_putrootfh(xdr, &hdr);
2956 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002957 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002958}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002959
2960/*
2961 * a RECLAIM_COMPLETE request
2962 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002963static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2964 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002965 const void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002966{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002967 const struct nfs41_reclaim_complete_args *args = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05002968 struct compound_hdr hdr = {
2969 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2970 };
2971
Chuck Lever9f06c712010-12-14 14:59:18 +00002972 encode_compound_hdr(xdr, req, &hdr);
2973 encode_sequence(xdr, &args->seq_args, &hdr);
2974 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002975 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002976}
2977
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002978/*
2979 * Encode GETDEVICEINFO request
2980 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002981static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2982 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002983 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002984{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002985 const struct nfs4_getdeviceinfo_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002986 struct compound_hdr hdr = {
2987 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2988 };
2989
Chuck Lever9f06c712010-12-14 14:59:18 +00002990 encode_compound_hdr(xdr, req, &hdr);
2991 encode_sequence(xdr, &args->seq_args, &hdr);
2992 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002993
2994 /* set up reply kvec. Subtract notification bitmap max size (2)
2995 * so that notification bitmap is put in xdr_buf tail */
2996 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2997 args->pdev->pages, args->pdev->pgbase,
2998 args->pdev->pglen);
2999
3000 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003001}
3002
3003/*
3004 * Encode LAYOUTGET request
3005 */
Chuck Lever9f06c712010-12-14 14:59:18 +00003006static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
3007 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003008 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003009{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003010 const struct nfs4_layoutget_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003011 struct compound_hdr hdr = {
3012 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3013 };
3014
Chuck Lever9f06c712010-12-14 14:59:18 +00003015 encode_compound_hdr(xdr, req, &hdr);
3016 encode_sequence(xdr, &args->seq_args, &hdr);
3017 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3018 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04003019
3020 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
3021 args->layout.pages, 0, args->layout.pglen);
3022
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003023 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003024}
Andy Adamson863a3c62011-03-23 13:27:54 +00003025
3026/*
3027 * Encode LAYOUTCOMMIT request
3028 */
Benny Halevycbe82602011-05-22 19:52:37 +03003029static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3030 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003031 const void *priv)
Andy Adamson863a3c62011-03-23 13:27:54 +00003032{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003033 const struct nfs4_layoutcommit_args *args = priv;
Benny Halevyac7db722011-05-22 19:53:48 +03003034 struct nfs4_layoutcommit_data *data =
3035 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00003036 struct compound_hdr hdr = {
3037 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3038 };
3039
3040 encode_compound_hdr(xdr, req, &hdr);
3041 encode_sequence(xdr, &args->seq_args, &hdr);
3042 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03003043 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003044 encode_getfattr(xdr, args->bitmask, &hdr);
3045 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03003046}
3047
3048/*
3049 * Encode LAYOUTRETURN request
3050 */
3051static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3052 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003053 const void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03003054{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003055 const struct nfs4_layoutreturn_args *args = data;
Benny Halevycbe82602011-05-22 19:52:37 +03003056 struct compound_hdr hdr = {
3057 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3058 };
3059
3060 encode_compound_hdr(xdr, req, &hdr);
3061 encode_sequence(xdr, &args->seq_args, &hdr);
3062 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3063 encode_layoutreturn(xdr, args, &hdr);
3064 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003065}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003066
3067/*
3068 * Encode SECINFO_NO_NAME request
3069 */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003070static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003071 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003072 const void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003073{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003074 const struct nfs41_secinfo_no_name_args *args = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003075 struct compound_hdr hdr = {
3076 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3077 };
3078
3079 encode_compound_hdr(xdr, req, &hdr);
3080 encode_sequence(xdr, &args->seq_args, &hdr);
3081 encode_putrootfh(xdr, &hdr);
3082 encode_secinfo_no_name(xdr, args, &hdr);
3083 encode_nops(&hdr);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003084}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003085
3086/*
3087 * Encode TEST_STATEID request
3088 */
3089static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3090 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003091 const void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04003092{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003093 const struct nfs41_test_stateid_args *args = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04003094 struct compound_hdr hdr = {
3095 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3096 };
3097
3098 encode_compound_hdr(xdr, req, &hdr);
3099 encode_sequence(xdr, &args->seq_args, &hdr);
3100 encode_test_stateid(xdr, args, &hdr);
3101 encode_nops(&hdr);
3102}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003103
3104/*
3105 * Encode FREE_STATEID request
3106 */
3107static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3108 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003109 const void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003110{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003111 const struct nfs41_free_stateid_args *args = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003112 struct compound_hdr hdr = {
3113 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3114 };
3115
3116 encode_compound_hdr(xdr, req, &hdr);
3117 encode_sequence(xdr, &args->seq_args, &hdr);
3118 encode_free_stateid(xdr, args, &hdr);
3119 encode_nops(&hdr);
3120}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003121#endif /* CONFIG_NFS_V4_1 */
3122
Benny Halevy686841b2009-08-14 17:19:48 +03003123static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3124{
3125 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3126 "Remaining buffer length is %tu words.\n",
3127 func, xdr->end - xdr->p);
3128}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129
Trond Myklebust683b57b2006-06-09 09:34:22 -04003130static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131{
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003132 ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3133 NFS4_OPAQUE_LIMIT);
3134 if (unlikely(ret < 0)) {
3135 if (ret == -EBADMSG)
3136 print_overflow_msg(__func__, xdr);
3137 return -EIO;
3138 }
3139 *len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140 return 0;
3141}
3142
3143static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3144{
Al Viro8687b632006-10-19 23:28:48 -07003145 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146
Benny Halevyc0eae662009-08-14 17:20:14 +03003147 p = xdr_inline_decode(xdr, 8);
3148 if (unlikely(!p))
3149 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003150 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003151 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003152
Benny Halevyc0eae662009-08-14 17:20:14 +03003153 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3154 if (unlikely(!p))
3155 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 hdr->tag = (char *)p;
3157 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003158 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003159 if (unlikely(hdr->nops < 1))
3160 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003162out_overflow:
3163 print_overflow_msg(__func__, xdr);
3164 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165}
3166
Trond Myklebustc7848f62013-12-04 17:39:23 -05003167static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3168 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169{
Al Viro8687b632006-10-19 23:28:48 -07003170 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 uint32_t opnum;
3172 int32_t nfserr;
3173
Benny Halevyc0eae662009-08-14 17:20:14 +03003174 p = xdr_inline_decode(xdr, 8);
3175 if (unlikely(!p))
3176 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003177 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003178 if (unlikely(opnum != expected))
3179 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003180 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003181 if (nfserr == NFS_OK)
3182 *nfs_retval = 0;
3183 else
3184 *nfs_retval = nfs4_stat_to_errno(nfserr);
3185 return true;
3186out_bad_operation:
3187 dprintk("nfs: Server returned operation"
3188 " %d but we issued a request for %d\n",
3189 opnum, expected);
3190 *nfs_retval = -EREMOTEIO;
3191 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003192out_overflow:
3193 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003194 *nfs_retval = -EIO;
3195 return false;
3196}
3197
3198static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3199{
3200 int retval;
3201
3202 __decode_op_hdr(xdr, expected, &retval);
3203 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204}
3205
3206/* Dummy routine */
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05003207static int decode_ace(struct xdr_stream *xdr, void *ace)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208{
Al Viro8687b632006-10-19 23:28:48 -07003209 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003210 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 char *str;
3212
Benny Halevyc0eae662009-08-14 17:20:14 +03003213 p = xdr_inline_decode(xdr, 12);
3214 if (likely(p))
3215 return decode_opaque_inline(xdr, &strlen, &str);
3216 print_overflow_msg(__func__, xdr);
3217 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218}
3219
3220static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3221{
Al Viro8687b632006-10-19 23:28:48 -07003222 uint32_t bmlen;
3223 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224
Benny Halevyc0eae662009-08-14 17:20:14 +03003225 p = xdr_inline_decode(xdr, 4);
3226 if (unlikely(!p))
3227 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003228 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229
Fred Isamandae100c2011-07-30 20:52:37 -04003230 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003231 p = xdr_inline_decode(xdr, (bmlen << 2));
3232 if (unlikely(!p))
3233 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003235 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003236 if (bmlen > 1) {
3237 bitmap[1] = be32_to_cpup(p++);
3238 if (bmlen > 2)
3239 bitmap[2] = be32_to_cpup(p);
3240 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 }
3242 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003243out_overflow:
3244 print_overflow_msg(__func__, xdr);
3245 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246}
3247
Trond Myklebust256e48b2012-06-21 11:18:13 -04003248static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249{
Al Viro8687b632006-10-19 23:28:48 -07003250 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251
Benny Halevyc0eae662009-08-14 17:20:14 +03003252 p = xdr_inline_decode(xdr, 4);
3253 if (unlikely(!p))
3254 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003255 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003256 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003258out_overflow:
3259 print_overflow_msg(__func__, xdr);
3260 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261}
3262
3263static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3264{
3265 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003266 int ret;
3267 ret = decode_attr_bitmap(xdr, bitmask);
3268 if (unlikely(ret < 0))
3269 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3271 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003272 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3273 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3274 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 return 0;
3276}
3277
3278static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3279{
Al Viro8687b632006-10-19 23:28:48 -07003280 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003281 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282
3283 *type = 0;
3284 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3285 return -EIO;
3286 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003287 p = xdr_inline_decode(xdr, 4);
3288 if (unlikely(!p))
3289 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003290 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003292 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 return -EIO;
3294 }
3295 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003296 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003298 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003299 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003300out_overflow:
3301 print_overflow_msg(__func__, xdr);
3302 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303}
3304
Chuck Lever264e6352012-03-01 17:02:05 -05003305static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3306 uint32_t *bitmap, uint32_t *type)
3307{
3308 __be32 *p;
3309
3310 *type = 0;
3311 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3312 return -EIO;
3313 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3314 p = xdr_inline_decode(xdr, 4);
3315 if (unlikely(!p))
3316 goto out_overflow;
3317 *type = be32_to_cpup(p);
3318 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3319 }
3320 dprintk("%s: expire type=0x%x\n", __func__, *type);
3321 return 0;
3322out_overflow:
3323 print_overflow_msg(__func__, xdr);
3324 return -EIO;
3325}
3326
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3328{
Al Viro8687b632006-10-19 23:28:48 -07003329 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003330 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331
3332 *change = 0;
3333 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3334 return -EIO;
3335 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003336 p = xdr_inline_decode(xdr, 8);
3337 if (unlikely(!p))
3338 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003339 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003341 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003343 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003345 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003346out_overflow:
3347 print_overflow_msg(__func__, xdr);
3348 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349}
3350
3351static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3352{
Al Viro8687b632006-10-19 23:28:48 -07003353 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003354 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355
3356 *size = 0;
3357 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3358 return -EIO;
3359 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003360 p = xdr_inline_decode(xdr, 8);
3361 if (unlikely(!p))
3362 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003363 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003365 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003367 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003368 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003369out_overflow:
3370 print_overflow_msg(__func__, xdr);
3371 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372}
3373
3374static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3375{
Al Viro8687b632006-10-19 23:28:48 -07003376 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377
3378 *res = 0;
3379 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3380 return -EIO;
3381 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003382 p = xdr_inline_decode(xdr, 4);
3383 if (unlikely(!p))
3384 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003385 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3387 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003388 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003390out_overflow:
3391 print_overflow_msg(__func__, xdr);
3392 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393}
3394
3395static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3396{
Al Viro8687b632006-10-19 23:28:48 -07003397 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398
3399 *res = 0;
3400 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3401 return -EIO;
3402 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003403 p = xdr_inline_decode(xdr, 4);
3404 if (unlikely(!p))
3405 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003406 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3408 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003409 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003411out_overflow:
3412 print_overflow_msg(__func__, xdr);
3413 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414}
3415
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003416static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417{
Al Viro8687b632006-10-19 23:28:48 -07003418 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003419 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420
3421 fsid->major = 0;
3422 fsid->minor = 0;
3423 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3424 return -EIO;
3425 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003426 p = xdr_inline_decode(xdr, 16);
3427 if (unlikely(!p))
3428 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003429 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003430 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003432 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003434 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 (unsigned long long)fsid->major,
3436 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003437 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003438out_overflow:
3439 print_overflow_msg(__func__, xdr);
3440 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441}
3442
3443static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3444{
Al Viro8687b632006-10-19 23:28:48 -07003445 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446
3447 *res = 60;
3448 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3449 return -EIO;
3450 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003451 p = xdr_inline_decode(xdr, 4);
3452 if (unlikely(!p))
3453 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003454 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3456 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003457 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003459out_overflow:
3460 print_overflow_msg(__func__, xdr);
3461 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462}
3463
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003464static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003465{
3466 __be32 *p;
3467
3468 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3469 return -EIO;
3470 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3471 p = xdr_inline_decode(xdr, 4);
3472 if (unlikely(!p))
3473 goto out_overflow;
3474 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003475 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003476 }
3477 return 0;
3478out_overflow:
3479 print_overflow_msg(__func__, xdr);
3480 return -EIO;
3481}
3482
Kinglong Mee8c612822015-08-26 21:12:58 +08003483static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3484 uint32_t *bitmap, uint32_t *bitmask)
3485{
3486 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3487 int ret;
3488 ret = decode_attr_bitmap(xdr, bitmask);
3489 if (unlikely(ret < 0))
3490 return ret;
3491 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3492 } else
3493 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3494 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3495 bitmask[0], bitmask[1], bitmask[2]);
3496 return 0;
3497}
3498
Bryan Schumakerae42c702010-10-21 16:33:17 -04003499static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3500{
3501 __be32 *p;
3502 int len;
3503
Trond Myklebust7ad07352010-10-23 15:34:20 -04003504 if (fh != NULL)
3505 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003506
3507 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3508 return -EIO;
3509 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3510 p = xdr_inline_decode(xdr, 4);
3511 if (unlikely(!p))
3512 goto out_overflow;
3513 len = be32_to_cpup(p);
3514 if (len > NFS4_FHSIZE)
3515 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003516 p = xdr_inline_decode(xdr, len);
3517 if (unlikely(!p))
3518 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003519 if (fh != NULL) {
3520 memcpy(fh->data, p, len);
3521 fh->size = len;
3522 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003523 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3524 }
3525 return 0;
3526out_overflow:
3527 print_overflow_msg(__func__, xdr);
3528 return -EIO;
3529}
3530
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3532{
Al Viro8687b632006-10-19 23:28:48 -07003533 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003535 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3537 return -EIO;
3538 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003539 p = xdr_inline_decode(xdr, 4);
3540 if (unlikely(!p))
3541 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003542 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3544 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003545 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003547out_overflow:
3548 print_overflow_msg(__func__, xdr);
3549 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550}
3551
3552static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3553{
Al Viro8687b632006-10-19 23:28:48 -07003554 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003555 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556
3557 *fileid = 0;
3558 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3559 return -EIO;
3560 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003561 p = xdr_inline_decode(xdr, 8);
3562 if (unlikely(!p))
3563 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003564 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003566 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003568 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003569 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003570out_overflow:
3571 print_overflow_msg(__func__, xdr);
3572 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573}
3574
Manoj Naik99baf622006-06-09 09:34:24 -04003575static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3576{
Al Viro8687b632006-10-19 23:28:48 -07003577 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003578 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003579
3580 *fileid = 0;
3581 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3582 return -EIO;
3583 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003584 p = xdr_inline_decode(xdr, 8);
3585 if (unlikely(!p))
3586 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003587 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003588 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003589 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003590 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003591 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003592 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003593out_overflow:
3594 print_overflow_msg(__func__, xdr);
3595 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003596}
3597
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3599{
Al Viro8687b632006-10-19 23:28:48 -07003600 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 int status = 0;
3602
3603 *res = 0;
3604 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3605 return -EIO;
3606 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003607 p = xdr_inline_decode(xdr, 8);
3608 if (unlikely(!p))
3609 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003610 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3612 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003613 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003615out_overflow:
3616 print_overflow_msg(__func__, xdr);
3617 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618}
3619
3620static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3621{
Al Viro8687b632006-10-19 23:28:48 -07003622 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623 int status = 0;
3624
3625 *res = 0;
3626 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3627 return -EIO;
3628 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003629 p = xdr_inline_decode(xdr, 8);
3630 if (unlikely(!p))
3631 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003632 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3634 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003635 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003637out_overflow:
3638 print_overflow_msg(__func__, xdr);
3639 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640}
3641
3642static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3643{
Al Viro8687b632006-10-19 23:28:48 -07003644 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 int status = 0;
3646
3647 *res = 0;
3648 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3649 return -EIO;
3650 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003651 p = xdr_inline_decode(xdr, 8);
3652 if (unlikely(!p))
3653 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003654 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3656 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003657 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003659out_overflow:
3660 print_overflow_msg(__func__, xdr);
3661 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662}
3663
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003664static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3665{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003666 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003667 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003668 int status = 0;
3669
Benny Halevyc0eae662009-08-14 17:20:14 +03003670 p = xdr_inline_decode(xdr, 4);
3671 if (unlikely(!p))
3672 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003673 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003674 if (n == 0)
3675 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003676 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003677 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3678 dprintk("cannot parse %d components in path\n", n);
3679 goto out_eio;
3680 }
3681 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003682 struct nfs4_string *component = &path->components[path->ncomponents];
3683 status = decode_opaque_inline(xdr, &component->len, &component->data);
3684 if (unlikely(status != 0))
3685 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003686 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003687 pr_cont("%s%.*s ",
3688 (path->ncomponents != n ? "/ " : ""),
3689 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003690 }
3691out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003692 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003693root_path:
3694/* a root pathname is sent as a zero component4 */
3695 path->ncomponents = 1;
3696 path->components[0].len=0;
3697 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003698 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003699 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003700out_eio:
3701 dprintk(" status %d", status);
3702 status = -EIO;
3703 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003704out_overflow:
3705 print_overflow_msg(__func__, xdr);
3706 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003707}
3708
3709static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003710{
3711 int n;
Al Viro8687b632006-10-19 23:28:48 -07003712 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003713 int status = -EIO;
3714
3715 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3716 goto out;
3717 status = 0;
3718 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3719 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003720 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003721 status = -EIO;
3722 /* Ignore borken servers that return unrequested attrs */
3723 if (unlikely(res == NULL))
3724 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003725 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003726 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003727 if (unlikely(status != 0))
3728 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003729 p = xdr_inline_decode(xdr, 4);
3730 if (unlikely(!p))
3731 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003732 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003733 if (n <= 0)
3734 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003735 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003736 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003737 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003738
Trond Myklebust809b4262013-03-27 11:54:45 -04003739 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3740 break;
3741 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003742 p = xdr_inline_decode(xdr, 4);
3743 if (unlikely(!p))
3744 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003745 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003746
Chuck Lever02a29762012-03-01 17:00:31 -05003747 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003748 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3749 struct nfs4_string *server;
3750
3751 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003752 unsigned int i;
3753 dprintk("%s: using first %u of %u servers "
3754 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003755 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003756 NFS4_FS_LOCATION_MAXSERVERS,
3757 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003758 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003759 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003760 char *data;
3761 status = decode_opaque_inline(xdr, &len, &data);
3762 if (unlikely(status != 0))
3763 goto out_eio;
3764 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003765 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003766 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003767 server = &loc->servers[loc->nservers];
3768 status = decode_opaque_inline(xdr, &server->len, &server->data);
3769 if (unlikely(status != 0))
3770 goto out_eio;
3771 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003772 }
3773 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003774 if (unlikely(status != 0))
3775 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003776 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003777 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003778 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003779out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003780 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003781 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003782out_overflow:
3783 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003784out_eio:
3785 status = -EIO;
3786 goto out;
3787}
3788
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3790{
Al Viro8687b632006-10-19 23:28:48 -07003791 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 int status = 0;
3793
3794 *res = 0;
3795 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3796 return -EIO;
3797 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003798 p = xdr_inline_decode(xdr, 8);
3799 if (unlikely(!p))
3800 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003801 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3803 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003804 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003806out_overflow:
3807 print_overflow_msg(__func__, xdr);
3808 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809}
3810
3811static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3812{
Al Viro8687b632006-10-19 23:28:48 -07003813 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 int status = 0;
3815
3816 *maxlink = 1;
3817 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3818 return -EIO;
3819 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003820 p = xdr_inline_decode(xdr, 4);
3821 if (unlikely(!p))
3822 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003823 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3825 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003826 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003828out_overflow:
3829 print_overflow_msg(__func__, xdr);
3830 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831}
3832
3833static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3834{
Al Viro8687b632006-10-19 23:28:48 -07003835 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836 int status = 0;
3837
3838 *maxname = 1024;
3839 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3840 return -EIO;
3841 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003842 p = xdr_inline_decode(xdr, 4);
3843 if (unlikely(!p))
3844 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003845 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3847 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003848 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003850out_overflow:
3851 print_overflow_msg(__func__, xdr);
3852 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853}
3854
3855static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3856{
Al Viro8687b632006-10-19 23:28:48 -07003857 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 int status = 0;
3859
3860 *res = 1024;
3861 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3862 return -EIO;
3863 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3864 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003865 p = xdr_inline_decode(xdr, 8);
3866 if (unlikely(!p))
3867 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003868 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 if (maxread > 0x7FFFFFFF)
3870 maxread = 0x7FFFFFFF;
3871 *res = (uint32_t)maxread;
3872 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3873 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003874 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003876out_overflow:
3877 print_overflow_msg(__func__, xdr);
3878 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879}
3880
3881static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3882{
Al Viro8687b632006-10-19 23:28:48 -07003883 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 int status = 0;
3885
3886 *res = 1024;
3887 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3888 return -EIO;
3889 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3890 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003891 p = xdr_inline_decode(xdr, 8);
3892 if (unlikely(!p))
3893 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003894 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 if (maxwrite > 0x7FFFFFFF)
3896 maxwrite = 0x7FFFFFFF;
3897 *res = (uint32_t)maxwrite;
3898 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3899 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003900 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003902out_overflow:
3903 print_overflow_msg(__func__, xdr);
3904 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905}
3906
Trond Myklebustbca79472009-03-11 14:10:26 -04003907static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908{
Trond Myklebustbca79472009-03-11 14:10:26 -04003909 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003910 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003911 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912
3913 *mode = 0;
3914 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3915 return -EIO;
3916 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003917 p = xdr_inline_decode(xdr, 4);
3918 if (unlikely(!p))
3919 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003920 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003921 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003923 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003925 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003926 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003927out_overflow:
3928 print_overflow_msg(__func__, xdr);
3929 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930}
3931
3932static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3933{
Al Viro8687b632006-10-19 23:28:48 -07003934 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003935 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936
3937 *nlink = 1;
3938 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3939 return -EIO;
3940 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003941 p = xdr_inline_decode(xdr, 4);
3942 if (unlikely(!p))
3943 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003944 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003946 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003948 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003949 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003950out_overflow:
3951 print_overflow_msg(__func__, xdr);
3952 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953}
3954
Trond Myklebust686a8162017-02-19 16:08:32 -05003955static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3956 struct nfs4_string *name, gfp_t gfp_flags)
3957{
3958 ssize_t ret;
3959
3960 ret = xdr_stream_decode_string_dup(xdr, &name->data,
3961 XDR_MAX_NETOBJ, gfp_flags);
3962 name->len = 0;
3963 if (ret > 0)
3964 name->len = ret;
3965 return ret;
3966}
3967
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003968static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003969 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003970 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971{
Trond Myklebust686a8162017-02-19 16:08:32 -05003972 ssize_t len;
3973 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974
Eric W. Biedermane5782072013-02-01 14:22:02 -08003975 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3977 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003978 if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3979 return 0;
3980 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3981
3982 if (owner_name != NULL) {
3983 len = decode_nfs4_string(xdr, owner_name, GFP_NOWAIT);
3984 if (len <= 0)
3985 goto out;
3986 dprintk("%s: name=%s\n", __func__, owner_name->data);
3987 return NFS_ATTR_FATTR_OWNER_NAME;
3988 } else {
3989 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3990 XDR_MAX_NETOBJ);
3991 if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3992 goto out;
3993 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3994 return NFS_ATTR_FATTR_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003996out:
3997 if (len != -EBADMSG)
3998 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003999 print_overflow_msg(__func__, xdr);
4000 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001}
4002
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004003static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08004004 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004005 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006{
Trond Myklebust686a8162017-02-19 16:08:32 -05004007 ssize_t len;
4008 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009
Eric W. Biedermane5782072013-02-01 14:22:02 -08004010 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
4012 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05004013 if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
4014 return 0;
4015 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
4016
4017 if (group_name != NULL) {
4018 len = decode_nfs4_string(xdr, group_name, GFP_NOWAIT);
4019 if (len <= 0)
4020 goto out;
4021 dprintk("%s: name=%s\n", __func__, group_name->data);
Kinglong Mee6f1f6222017-03-06 17:49:42 +08004022 return NFS_ATTR_FATTR_GROUP_NAME;
Trond Myklebust686a8162017-02-19 16:08:32 -05004023 } else {
4024 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
4025 XDR_MAX_NETOBJ);
4026 if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
4027 goto out;
4028 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
4029 return NFS_ATTR_FATTR_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 }
Trond Myklebust686a8162017-02-19 16:08:32 -05004031out:
4032 if (len != -EBADMSG)
4033 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004034 print_overflow_msg(__func__, xdr);
4035 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036}
4037
4038static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
4039{
Al Viro8687b632006-10-19 23:28:48 -07004040 uint32_t major = 0, minor = 0;
4041 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004042 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043
4044 *rdev = MKDEV(0,0);
4045 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
4046 return -EIO;
4047 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
4048 dev_t tmp;
4049
Benny Halevyc0eae662009-08-14 17:20:14 +03004050 p = xdr_inline_decode(xdr, 8);
4051 if (unlikely(!p))
4052 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004053 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004054 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055 tmp = MKDEV(major, minor);
4056 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
4057 *rdev = tmp;
4058 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04004059 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004061 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04004062 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004063out_overflow:
4064 print_overflow_msg(__func__, xdr);
4065 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066}
4067
4068static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4069{
Al Viro8687b632006-10-19 23:28:48 -07004070 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 int status = 0;
4072
4073 *res = 0;
4074 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
4075 return -EIO;
4076 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004077 p = xdr_inline_decode(xdr, 8);
4078 if (unlikely(!p))
4079 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004080 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4082 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004083 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004085out_overflow:
4086 print_overflow_msg(__func__, xdr);
4087 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088}
4089
4090static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4091{
Al Viro8687b632006-10-19 23:28:48 -07004092 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093 int status = 0;
4094
4095 *res = 0;
4096 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4097 return -EIO;
4098 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004099 p = xdr_inline_decode(xdr, 8);
4100 if (unlikely(!p))
4101 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004102 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4104 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004105 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004107out_overflow:
4108 print_overflow_msg(__func__, xdr);
4109 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110}
4111
4112static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4113{
Al Viro8687b632006-10-19 23:28:48 -07004114 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115 int status = 0;
4116
4117 *res = 0;
4118 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4119 return -EIO;
4120 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004121 p = xdr_inline_decode(xdr, 8);
4122 if (unlikely(!p))
4123 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004124 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4126 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004127 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004129out_overflow:
4130 print_overflow_msg(__func__, xdr);
4131 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132}
4133
4134static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4135{
Al Viro8687b632006-10-19 23:28:48 -07004136 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004137 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138
4139 *used = 0;
4140 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4141 return -EIO;
4142 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004143 p = xdr_inline_decode(xdr, 8);
4144 if (unlikely(!p))
4145 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004146 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004148 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004150 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004152 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004153out_overflow:
4154 print_overflow_msg(__func__, xdr);
4155 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156}
4157
4158static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4159{
Al Viro8687b632006-10-19 23:28:48 -07004160 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161 uint64_t sec;
4162 uint32_t nsec;
4163
Benny Halevyc0eae662009-08-14 17:20:14 +03004164 p = xdr_inline_decode(xdr, 12);
4165 if (unlikely(!p))
4166 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004167 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004168 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 time->tv_sec = (time_t)sec;
4170 time->tv_nsec = (long)nsec;
4171 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004172out_overflow:
4173 print_overflow_msg(__func__, xdr);
4174 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175}
4176
4177static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4178{
4179 int status = 0;
4180
4181 time->tv_sec = 0;
4182 time->tv_nsec = 0;
4183 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4184 return -EIO;
4185 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4186 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004187 if (status == 0)
4188 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4190 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004191 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192 return status;
4193}
4194
4195static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4196{
4197 int status = 0;
4198
4199 time->tv_sec = 0;
4200 time->tv_nsec = 0;
4201 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4202 return -EIO;
4203 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4204 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004205 if (status == 0)
4206 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4208 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004209 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210 return status;
4211}
4212
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004213static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4214 struct timespec *time)
4215{
4216 int status = 0;
4217
4218 time->tv_sec = 0;
4219 time->tv_nsec = 0;
4220 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4221 return -EIO;
4222 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4223 status = decode_attr_time(xdr, time);
4224 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4225 }
4226 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4227 (long)time->tv_nsec);
4228 return status;
4229}
4230
David Quigleyaa9c2662013-05-22 12:50:44 -04004231static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4232 struct nfs4_label *label)
4233{
4234 uint32_t pi = 0;
4235 uint32_t lfs = 0;
4236 __u32 len;
4237 __be32 *p;
4238 int status = 0;
4239
4240 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4241 return -EIO;
4242 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4243 p = xdr_inline_decode(xdr, 4);
4244 if (unlikely(!p))
4245 goto out_overflow;
4246 lfs = be32_to_cpup(p++);
4247 p = xdr_inline_decode(xdr, 4);
4248 if (unlikely(!p))
4249 goto out_overflow;
4250 pi = be32_to_cpup(p++);
4251 p = xdr_inline_decode(xdr, 4);
4252 if (unlikely(!p))
4253 goto out_overflow;
4254 len = be32_to_cpup(p++);
4255 p = xdr_inline_decode(xdr, len);
4256 if (unlikely(!p))
4257 goto out_overflow;
4258 if (len < NFS4_MAXLABELLEN) {
4259 if (label) {
4260 memcpy(label->label, p, len);
4261 label->len = len;
4262 label->pi = pi;
4263 label->lfs = lfs;
4264 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4265 }
4266 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4267 } else
4268 printk(KERN_WARNING "%s: label too long (%u)!\n",
4269 __func__, len);
4270 }
4271 if (label && label->label)
4272 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4273 (char *)label->label, label->len, label->pi, label->lfs);
4274 return status;
4275
4276out_overflow:
4277 print_overflow_msg(__func__, xdr);
4278 return -EIO;
4279}
4280
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4282{
4283 int status = 0;
4284
4285 time->tv_sec = 0;
4286 time->tv_nsec = 0;
4287 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4288 return -EIO;
4289 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4290 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004291 if (status == 0)
4292 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4294 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004295 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296 return status;
4297}
4298
Trond Myklebust256e48b2012-06-21 11:18:13 -04004299static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300{
4301 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004302 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303
4304 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004305 dprintk("%s: server returned incorrect attribute length: "
4306 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004307 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308 attrwords << 2,
4309 (attrwords < nwords) ? '<' : '>',
4310 nwords << 2);
4311 return -EIO;
4312 }
4313 return 0;
4314}
4315
4316static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4317{
Al Viro8687b632006-10-19 23:28:48 -07004318 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319
Benny Halevyc0eae662009-08-14 17:20:14 +03004320 p = xdr_inline_decode(xdr, 20);
4321 if (unlikely(!p))
4322 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004323 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004324 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004325 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004327out_overflow:
4328 print_overflow_msg(__func__, xdr);
4329 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330}
4331
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004332static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333{
Al Viro8687b632006-10-19 23:28:48 -07004334 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004335 uint32_t supp, acc;
4336 int status;
4337
4338 status = decode_op_hdr(xdr, OP_ACCESS);
4339 if (status)
4340 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004341 p = xdr_inline_decode(xdr, 8);
4342 if (unlikely(!p))
4343 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004344 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004345 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004346 *supported = supp;
4347 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004349out_overflow:
4350 print_overflow_msg(__func__, xdr);
4351 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352}
4353
Benny Halevy07d30432009-08-14 17:19:52 +03004354static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004356 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4357 if (unlikely(ret < 0)) {
4358 print_overflow_msg(__func__, xdr);
4359 return -EIO;
Benny Halevy07d30432009-08-14 17:19:52 +03004360 }
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004361 return 0;
Benny Halevy07d30432009-08-14 17:19:52 +03004362}
4363
4364static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4365{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004366 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367}
4368
Trond Myklebust93b717f2016-05-16 17:42:43 -04004369static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4370{
4371 stateid->type = NFS4_OPEN_STATEID_TYPE;
4372 return decode_stateid(xdr, stateid);
4373}
4374
4375static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4376{
4377 stateid->type = NFS4_LOCK_STATEID_TYPE;
4378 return decode_stateid(xdr, stateid);
4379}
4380
4381static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4382{
4383 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4384 return decode_stateid(xdr, stateid);
4385}
4386
Trond Myklebustfcd88432017-11-07 12:39:44 -05004387static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4388{
4389 nfs4_stateid dummy;
4390
4391 nfs4_stateid_copy(stateid, &invalid_stateid);
4392 return decode_stateid(xdr, &dummy);
4393}
4394
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4396{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397 int status;
4398
4399 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004400 if (status != -EIO)
4401 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004402 if (!status)
Trond Myklebustfcd88432017-11-07 12:39:44 -05004403 status = decode_invalid_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004404 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405}
4406
Benny Halevydb942bb2009-08-14 17:19:56 +03004407static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4408{
Chuck Levercd937102012-03-02 17:14:31 -05004409 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410}
4411
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004412static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4413{
4414 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4415}
4416
Fred Isaman0b7c0152012-04-20 14:47:39 -04004417static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004418{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419 int status;
4420
4421 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004422 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004423 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004424 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425}
4426
4427static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4428{
Al Viro8687b632006-10-19 23:28:48 -07004429 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430 uint32_t bmlen;
4431 int status;
4432
4433 status = decode_op_hdr(xdr, OP_CREATE);
4434 if (status)
4435 return status;
4436 if ((status = decode_change_info(xdr, cinfo)))
4437 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004438 p = xdr_inline_decode(xdr, 4);
4439 if (unlikely(!p))
4440 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004441 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004442 p = xdr_inline_decode(xdr, bmlen << 2);
4443 if (likely(p))
4444 return 0;
4445out_overflow:
4446 print_overflow_msg(__func__, xdr);
4447 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448}
4449
4450static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4451{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004452 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004453 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454 int status;
4455
4456 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4457 goto xdr_error;
4458 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4459 goto xdr_error;
4460 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4461 goto xdr_error;
4462 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4463 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004464 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4465 &res->fh_expire_type)) != 0)
4466 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4468 goto xdr_error;
4469 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4470 goto xdr_error;
4471 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4472 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004473 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4474 res->exclcreat_bitmask)) != 0)
4475 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476 status = verify_attr_len(xdr, savep, attrlen);
4477xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004478 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004479 return status;
4480}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004481
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4483{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004484 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004485 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004487
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4489 goto xdr_error;
4490 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4491 goto xdr_error;
4492 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4493 goto xdr_error;
4494
4495 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4496 goto xdr_error;
4497 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4498 goto xdr_error;
4499 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4500 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004501
4502 status = -EIO;
4503 if (unlikely(bitmap[0]))
4504 goto xdr_error;
4505
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4507 goto xdr_error;
4508 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4509 goto xdr_error;
4510 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4511 goto xdr_error;
4512
4513 status = verify_attr_len(xdr, savep, attrlen);
4514xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004515 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516 return status;
4517}
4518
4519static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4520{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004521 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004522 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004524
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4526 goto xdr_error;
4527 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4528 goto xdr_error;
4529 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4530 goto xdr_error;
4531
4532 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4533 goto xdr_error;
4534 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4535 goto xdr_error;
4536
4537 status = verify_attr_len(xdr, savep, attrlen);
4538xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004539 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004540 return status;
4541}
4542
Andy Adamson88034c32012-05-23 05:02:34 -04004543static int decode_threshold_hint(struct xdr_stream *xdr,
4544 uint32_t *bitmap,
4545 uint64_t *res,
4546 uint32_t hint_bit)
4547{
4548 __be32 *p;
4549
4550 *res = 0;
4551 if (likely(bitmap[0] & hint_bit)) {
4552 p = xdr_inline_decode(xdr, 8);
4553 if (unlikely(!p))
4554 goto out_overflow;
4555 xdr_decode_hyper(p, res);
4556 }
4557 return 0;
4558out_overflow:
4559 print_overflow_msg(__func__, xdr);
4560 return -EIO;
4561}
4562
4563static int decode_first_threshold_item4(struct xdr_stream *xdr,
4564 struct nfs4_threshold *res)
4565{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004566 __be32 *p;
4567 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004568 uint32_t bitmap[3] = {0,}, attrlen;
4569 int status;
4570
4571 /* layout type */
4572 p = xdr_inline_decode(xdr, 4);
4573 if (unlikely(!p)) {
4574 print_overflow_msg(__func__, xdr);
4575 return -EIO;
4576 }
4577 res->l_type = be32_to_cpup(p);
4578
4579 /* thi_hintset bitmap */
4580 status = decode_attr_bitmap(xdr, bitmap);
4581 if (status < 0)
4582 goto xdr_error;
4583
4584 /* thi_hintlist length */
4585 status = decode_attr_length(xdr, &attrlen, &savep);
4586 if (status < 0)
4587 goto xdr_error;
4588 /* thi_hintlist */
4589 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4590 if (status < 0)
4591 goto xdr_error;
4592 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4593 if (status < 0)
4594 goto xdr_error;
4595 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4596 THRESHOLD_RD_IO);
4597 if (status < 0)
4598 goto xdr_error;
4599 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4600 THRESHOLD_WR_IO);
4601 if (status < 0)
4602 goto xdr_error;
4603
4604 status = verify_attr_len(xdr, savep, attrlen);
4605 res->bm = bitmap[0];
4606
4607 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4608 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4609 res->wr_io_sz);
4610xdr_error:
4611 dprintk("%s ret=%d!\n", __func__, status);
4612 return status;
4613}
4614
4615/*
4616 * Thresholds on pNFS direct I/O vrs MDS I/O
4617 */
4618static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4619 uint32_t *bitmap,
4620 struct nfs4_threshold *res)
4621{
4622 __be32 *p;
4623 int status = 0;
4624 uint32_t num;
4625
4626 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4627 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004628 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004629 /* Did the server return an unrequested attribute? */
4630 if (unlikely(res == NULL))
4631 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004632 p = xdr_inline_decode(xdr, 4);
4633 if (unlikely(!p))
4634 goto out_overflow;
4635 num = be32_to_cpup(p);
4636 if (num == 0)
4637 return 0;
4638 if (num > 1)
4639 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4640 "drivers per filesystem not supported\n",
4641 __func__);
4642
4643 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004644 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004645 }
4646 return status;
4647out_overflow:
4648 print_overflow_msg(__func__, xdr);
4649 return -EIO;
4650}
4651
Bryan Schumakerae42c702010-10-21 16:33:17 -04004652static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4653 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004654 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004655 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656{
Trond Myklebustbca79472009-03-11 14:10:26 -04004657 int status;
4658 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004659 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004660 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004661
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004662 status = decode_attr_type(xdr, bitmap, &type);
4663 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004664 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004665 fattr->mode = 0;
4666 if (status != 0) {
4667 fattr->mode |= nfs_type2fmt[type];
4668 fattr->valid |= status;
4669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004671 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4672 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004673 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004674 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004675
4676 status = decode_attr_size(xdr, bitmap, &fattr->size);
4677 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004679 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004680
4681 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4682 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004683 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004684 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004685
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004686 err = 0;
4687 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004688 if (status < 0)
4689 goto xdr_error;
4690
4691 status = decode_attr_filehandle(xdr, bitmap, fh);
4692 if (status < 0)
4693 goto xdr_error;
4694
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004695 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4696 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004697 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004698 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004699
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004700 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004701 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004702 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004703 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004704
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004705 status = -EIO;
4706 if (unlikely(bitmap[0]))
4707 goto xdr_error;
4708
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004709 status = decode_attr_mode(xdr, bitmap, &fmode);
4710 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004712 if (status != 0) {
4713 fattr->mode |= fmode;
4714 fattr->valid |= status;
4715 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004716
4717 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4718 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004720 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004721
Trond Myklebust6926afd2012-01-07 13:22:46 -05004722 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004723 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004725 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004726
Trond Myklebust6926afd2012-01-07 13:22:46 -05004727 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004728 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004729 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004730 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004731
4732 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4733 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004734 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004735 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004736
4737 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4738 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004740 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004741
4742 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4743 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004745 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004746
4747 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4748 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004750 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004751
4752 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4753 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004755 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004756
Trond Myklebust28331a42011-04-27 13:47:52 -04004757 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004758 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004759 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004760 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004761
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004762 status = -EIO;
4763 if (unlikely(bitmap[1]))
4764 goto xdr_error;
4765
Andy Adamson88034c32012-05-23 05:02:34 -04004766 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4767 if (status < 0)
4768 goto xdr_error;
4769
David Quigleyaa9c2662013-05-22 12:50:44 -04004770 if (label) {
4771 status = decode_attr_security_label(xdr, bitmap, label);
4772 if (status < 0)
4773 goto xdr_error;
4774 fattr->valid |= status;
4775 }
4776
Bryan Schumakerae42c702010-10-21 16:33:17 -04004777xdr_error:
4778 dprintk("%s: xdr returned %d\n", __func__, -status);
4779 return status;
4780}
4781
4782static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004783 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004784 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004785{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004786 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004787 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004788 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004789 int status;
4790
4791 status = decode_op_hdr(xdr, OP_GETATTR);
4792 if (status < 0)
4793 goto xdr_error;
4794
4795 status = decode_attr_bitmap(xdr, bitmap);
4796 if (status < 0)
4797 goto xdr_error;
4798
4799 status = decode_attr_length(xdr, &attrlen, &savep);
4800 if (status < 0)
4801 goto xdr_error;
4802
David Quigleyaa9c2662013-05-22 12:50:44 -04004803 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4804 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004805 if (status < 0)
4806 goto xdr_error;
4807
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004808 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004809xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004810 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811 return status;
4812}
4813
David Quigleyaa9c2662013-05-22 12:50:44 -04004814static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4815 struct nfs4_label *label, const struct nfs_server *server)
4816{
4817 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4818}
4819
Bryan Schumakerae42c702010-10-21 16:33:17 -04004820static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004821 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004822{
David Quigleyaa9c2662013-05-22 12:50:44 -04004823 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004824}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825
Andy Adamson504913f2010-10-20 00:17:57 -04004826/*
Jeff Layton3132e492016-08-10 15:58:24 -04004827 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004828 */
Jeff Layton3132e492016-08-10 15:58:24 -04004829static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004830 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004831{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004832 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004833 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004834
4835 p = xdr_inline_decode(xdr, 4);
4836 if (unlikely(!p))
4837 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004838 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004839
4840 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004841 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004842 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004843
4844 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004845 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004846 if (unlikely(!p))
4847 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004848
4849 /* If we get too many, then just cap it at the max */
4850 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4851 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4852 __func__, fsinfo->nlayouttypes);
4853 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4854 }
4855
4856 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4857 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004858 return 0;
4859out_overflow:
4860 print_overflow_msg(__func__, xdr);
4861 return -EIO;
4862}
4863
4864/*
4865 * The type of file system exported.
4866 * Note we must ensure that layouttype is set in any non-error case.
4867 */
4868static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004869 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004870{
4871 int status = 0;
4872
4873 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4874 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4875 return -EIO;
4876 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004877 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004878 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004879 }
Andy Adamson504913f2010-10-20 00:17:57 -04004880 return status;
4881}
4882
Fred Isamandae100c2011-07-30 20:52:37 -04004883/*
4884 * The prefered block size for layout directed io
4885 */
4886static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4887 uint32_t *res)
4888{
4889 __be32 *p;
4890
4891 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4892 *res = 0;
4893 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4894 p = xdr_inline_decode(xdr, 4);
4895 if (unlikely(!p)) {
4896 print_overflow_msg(__func__, xdr);
4897 return -EIO;
4898 }
4899 *res = be32_to_cpup(p);
4900 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4901 }
4902 return 0;
4903}
4904
Peng Tao2a92ee92015-09-26 02:24:37 +08004905/*
4906 * The granularity of a CLONE operation.
4907 */
4908static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4909 uint32_t *res)
4910{
4911 __be32 *p;
4912
4913 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4914 *res = 0;
4915 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4916 p = xdr_inline_decode(xdr, 4);
4917 if (unlikely(!p)) {
4918 print_overflow_msg(__func__, xdr);
4919 return -EIO;
4920 }
4921 *res = be32_to_cpup(p);
4922 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4923 }
4924 return 0;
4925}
4926
Linus Torvalds1da177e2005-04-16 15:20:36 -07004927static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4928{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004929 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004930 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004931 int status;
4932
4933 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4934 goto xdr_error;
4935 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4936 goto xdr_error;
4937 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4938 goto xdr_error;
4939
4940 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4941
4942 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4943 goto xdr_error;
4944 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4945 goto xdr_error;
4946 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4947 goto xdr_error;
4948 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4949 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4950 goto xdr_error;
4951 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004952
4953 status = -EIO;
4954 if (unlikely(bitmap[0]))
4955 goto xdr_error;
4956
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004957 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4958 if (status != 0)
4959 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004960 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004961 if (status != 0)
4962 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004963
4964 status = -EIO;
4965 if (unlikely(bitmap[1]))
4966 goto xdr_error;
4967
Fred Isamandae100c2011-07-30 20:52:37 -04004968 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4969 if (status)
4970 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004971 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4972 if (status)
4973 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974
4975 status = verify_attr_len(xdr, savep, attrlen);
4976xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004977 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004978 return status;
4979}
4980
4981static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4982{
Al Viro8687b632006-10-19 23:28:48 -07004983 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984 uint32_t len;
4985 int status;
4986
Trond Myklebust99367812007-07-17 21:52:41 -04004987 /* Zero handle first to allow comparisons */
4988 memset(fh, 0, sizeof(*fh));
4989
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990 status = decode_op_hdr(xdr, OP_GETFH);
4991 if (status)
4992 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993
Benny Halevyc0eae662009-08-14 17:20:14 +03004994 p = xdr_inline_decode(xdr, 4);
4995 if (unlikely(!p))
4996 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004997 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998 if (len > NFS4_FHSIZE)
4999 return -EIO;
5000 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03005001 p = xdr_inline_decode(xdr, len);
5002 if (unlikely(!p))
5003 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03005004 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005006out_overflow:
5007 print_overflow_msg(__func__, xdr);
5008 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009}
5010
5011static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5012{
5013 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005014
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015 status = decode_op_hdr(xdr, OP_LINK);
5016 if (status)
5017 return status;
5018 return decode_change_info(xdr, cinfo);
5019}
5020
5021/*
5022 * We create the owner, so we know a proper owner.id length is 4.
5023 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005024static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005026 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07005027 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005028 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005030 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03005031 if (unlikely(!p))
5032 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005033 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03005034 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005035 type = be32_to_cpup(p++); /* 4 byte read */
5036 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005037 fl->fl_start = (loff_t)offset;
5038 fl->fl_end = fl->fl_start + (loff_t)length - 1;
5039 if (length == ~(uint64_t)0)
5040 fl->fl_end = OFFSET_MAX;
5041 fl->fl_type = F_WRLCK;
5042 if (type & 1)
5043 fl->fl_type = F_RDLCK;
5044 fl->fl_pid = 0;
5045 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005046 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
5047 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
5048 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03005049 if (likely(p))
5050 return -NFS4ERR_DENIED;
5051out_overflow:
5052 print_overflow_msg(__func__, xdr);
5053 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054}
5055
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005056static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058 int status;
5059
5060 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005061 if (status == -EIO)
5062 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005063 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04005064 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005065 if (unlikely(status))
5066 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005067 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04005068 status = decode_lock_denied(xdr, NULL);
5069 if (res->open_seqid != NULL)
5070 nfs_increment_open_seqid(status, res->open_seqid);
5071 nfs_increment_lock_seqid(status, res->lock_seqid);
5072out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073 return status;
5074}
5075
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005076static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077{
5078 int status;
5079 status = decode_op_hdr(xdr, OP_LOCKT);
5080 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005081 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082 return status;
5083}
5084
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005085static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087 int status;
5088
5089 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005090 if (status != -EIO)
5091 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005092 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005093 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005094 return status;
5095}
5096
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005097static int decode_release_lockowner(struct xdr_stream *xdr)
5098{
5099 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5100}
5101
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102static int decode_lookup(struct xdr_stream *xdr)
5103{
5104 return decode_op_hdr(xdr, OP_LOOKUP);
5105}
5106
Jeff Layton5b5faaf2017-06-29 06:34:52 -07005107static int decode_lookupp(struct xdr_stream *xdr)
5108{
5109 return decode_op_hdr(xdr, OP_LOOKUPP);
5110}
5111
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005113static int decode_space_limit(struct xdr_stream *xdr,
5114 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115{
Andy Adamson05d564f2008-12-23 16:06:15 -05005116 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005118 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119
Benny Halevyc0eae662009-08-14 17:20:14 +03005120 p = xdr_inline_decode(xdr, 12);
5121 if (unlikely(!p))
5122 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005123 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005124 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005125 case NFS4_LIMIT_SIZE:
5126 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005127 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005128 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005129 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005130 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005131 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005133 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005134 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005135 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005136out_overflow:
5137 print_overflow_msg(__func__, xdr);
5138 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139}
5140
Trond Myklebust6ae37332015-01-30 14:21:14 -05005141static int decode_rw_delegation(struct xdr_stream *xdr,
5142 uint32_t delegation_type,
5143 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144{
Andy Adamson05d564f2008-12-23 16:06:15 -05005145 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005146 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147
Trond Myklebust93b717f2016-05-16 17:42:43 -04005148 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005149 if (unlikely(status))
5150 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005151 p = xdr_inline_decode(xdr, 4);
5152 if (unlikely(!p))
5153 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005154 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005155
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005157 case NFS4_OPEN_DELEGATE_READ:
5158 res->delegation_type = FMODE_READ;
5159 break;
5160 case NFS4_OPEN_DELEGATE_WRITE:
5161 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005162 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163 return -EIO;
5164 }
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05005165 return decode_ace(xdr, NULL);
Benny Halevyc0eae662009-08-14 17:20:14 +03005166out_overflow:
5167 print_overflow_msg(__func__, xdr);
5168 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005169}
5170
Trond Myklebust6ae37332015-01-30 14:21:14 -05005171static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5172{
5173 __be32 *p;
5174 uint32_t why_no_delegation;
5175
5176 p = xdr_inline_decode(xdr, 4);
5177 if (unlikely(!p))
5178 goto out_overflow;
5179 why_no_delegation = be32_to_cpup(p);
5180 switch (why_no_delegation) {
5181 case WND4_CONTENTION:
5182 case WND4_RESOURCE:
5183 xdr_inline_decode(xdr, 4);
5184 /* Ignore for now */
5185 }
5186 return 0;
5187out_overflow:
5188 print_overflow_msg(__func__, xdr);
5189 return -EIO;
5190}
5191
5192static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5193{
5194 __be32 *p;
5195 uint32_t delegation_type;
5196
5197 p = xdr_inline_decode(xdr, 4);
5198 if (unlikely(!p))
5199 goto out_overflow;
5200 delegation_type = be32_to_cpup(p);
5201 res->delegation_type = 0;
5202 switch (delegation_type) {
5203 case NFS4_OPEN_DELEGATE_NONE:
5204 return 0;
5205 case NFS4_OPEN_DELEGATE_READ:
5206 case NFS4_OPEN_DELEGATE_WRITE:
5207 return decode_rw_delegation(xdr, delegation_type, res);
5208 case NFS4_OPEN_DELEGATE_NONE_EXT:
5209 return decode_no_delegation(xdr, res);
5210 }
5211 return -EIO;
5212out_overflow:
5213 print_overflow_msg(__func__, xdr);
5214 return -EIO;
5215}
5216
Linus Torvalds1da177e2005-04-16 15:20:36 -07005217static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5218{
Andy Adamson05d564f2008-12-23 16:06:15 -05005219 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005220 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005221 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005222
Trond Myklebustc7848f62013-12-04 17:39:23 -05005223 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5224 return status;
5225 nfs_increment_open_seqid(status, res->seqid);
5226 if (status)
5227 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005228 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005229 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005230 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005231
Andy Adamson05d564f2008-12-23 16:06:15 -05005232 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005233
Benny Halevyc0eae662009-08-14 17:20:14 +03005234 p = xdr_inline_decode(xdr, 8);
5235 if (unlikely(!p))
5236 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005237 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005238 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005239 if (bmlen > 10)
5240 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005241
Benny Halevyc0eae662009-08-14 17:20:14 +03005242 p = xdr_inline_decode(xdr, bmlen << 2);
5243 if (unlikely(!p))
5244 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005245 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5246 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005247 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005248 for (; i < NFS4_BITMAP_SIZE; i++)
5249 res->attrset[i] = 0;
5250
Linus Torvalds1da177e2005-04-16 15:20:36 -07005251 return decode_delegation(xdr, res);
5252xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005253 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005255out_overflow:
5256 print_overflow_msg(__func__, xdr);
5257 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005258}
5259
5260static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5261{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262 int status;
5263
Andy Adamson05d564f2008-12-23 16:06:15 -05005264 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005265 if (status != -EIO)
5266 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005267 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005268 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005269 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005270}
5271
5272static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5273{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274 int status;
5275
5276 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005277 if (status != -EIO)
5278 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005279 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005280 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005281 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282}
5283
5284static int decode_putfh(struct xdr_stream *xdr)
5285{
5286 return decode_op_hdr(xdr, OP_PUTFH);
5287}
5288
5289static int decode_putrootfh(struct xdr_stream *xdr)
5290{
5291 return decode_op_hdr(xdr, OP_PUTROOTFH);
5292}
5293
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005294static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5295 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296{
Al Viro8687b632006-10-19 23:28:48 -07005297 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005298 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299 int status;
5300
5301 status = decode_op_hdr(xdr, OP_READ);
5302 if (status)
5303 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005304 p = xdr_inline_decode(xdr, 8);
5305 if (unlikely(!p))
5306 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005307 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005308 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005309 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005310 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005311 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005312 "count %u > recvd %u\n", count, recvd);
5313 count = recvd;
5314 eof = 0;
5315 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005316 res->eof = eof;
5317 res->count = count;
5318 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005319out_overflow:
5320 print_overflow_msg(__func__, xdr);
5321 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005322}
5323
5324static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5325{
Chuck Leverbcecff72007-10-26 13:32:03 -04005326 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005327 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005328
5329 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005330 if (!status)
5331 status = decode_verifier(xdr, readdir->verifier.data);
5332 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005333 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005334 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005335 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005336 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005337 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005338}
5339
5340static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5341{
5342 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005343 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005344 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005345 int status;
5346
5347 status = decode_op_hdr(xdr, OP_READLINK);
5348 if (status)
5349 return status;
5350
5351 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005352 p = xdr_inline_decode(xdr, 4);
5353 if (unlikely(!p))
5354 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005355 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005356 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005357 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005358 return -ENAMETOOLONG;
5359 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005360 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005361 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005362 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005363 "count %u > recvd %u\n", len, recvd);
5364 return -EIO;
5365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005366 /*
5367 * The XDR encode routine has set things up so that
5368 * the link text will be copied directly into the
5369 * buffer. We just have to do overflow-checking,
5370 * and and null-terminate the text (the VFS expects
5371 * null-termination).
5372 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005373 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005374 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005375out_overflow:
5376 print_overflow_msg(__func__, xdr);
5377 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378}
5379
5380static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5381{
5382 int status;
5383
5384 status = decode_op_hdr(xdr, OP_REMOVE);
5385 if (status)
5386 goto out;
5387 status = decode_change_info(xdr, cinfo);
5388out:
5389 return status;
5390}
5391
5392static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5393 struct nfs4_change_info *new_cinfo)
5394{
5395 int status;
5396
5397 status = decode_op_hdr(xdr, OP_RENAME);
5398 if (status)
5399 goto out;
5400 if ((status = decode_change_info(xdr, old_cinfo)))
5401 goto out;
5402 status = decode_change_info(xdr, new_cinfo);
5403out:
5404 return status;
5405}
5406
5407static int decode_renew(struct xdr_stream *xdr)
5408{
5409 return decode_op_hdr(xdr, OP_RENEW);
5410}
5411
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005412static int
5413decode_restorefh(struct xdr_stream *xdr)
5414{
5415 return decode_op_hdr(xdr, OP_RESTOREFH);
5416}
5417
J. Bruce Fields029d1052005-06-22 17:16:22 +00005418static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005419 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005420{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005421 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005422 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005423 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005424 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005425 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005426
Andy Adamsonbf118a32011-12-07 11:55:27 -05005427 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005428 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5429 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005430
Trond Myklebust519d3952012-08-14 17:30:10 -04005431 xdr_enter_page(xdr, xdr->buf->page_len);
5432
Trond Myklebustcff298c2012-08-14 17:14:17 -04005433 /* Calculate the offset of the page data */
5434 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005435
J. Bruce Fields029d1052005-06-22 17:16:22 +00005436 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5437 goto out;
5438 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5439 goto out;
5440
5441 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5442 return -EIO;
5443 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005444
Andy Adamsonbf118a32011-12-07 11:55:27 -05005445 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5446 * are stored with the acl data to handle the problem of
5447 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005448 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005449 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005450
5451 /* Check for receive buffer overflow */
5452 if (res->acl_len > (xdr->nwords << 2) ||
5453 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5454 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005455 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005456 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005457 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005458 } else
5459 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005460
5461out:
5462 return status;
5463}
5464
Linus Torvalds1da177e2005-04-16 15:20:36 -07005465static int
5466decode_savefh(struct xdr_stream *xdr)
5467{
5468 return decode_op_hdr(xdr, OP_SAVEFH);
5469}
5470
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005471static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005472{
Al Viro8687b632006-10-19 23:28:48 -07005473 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005474 uint32_t bmlen;
5475 int status;
5476
Linus Torvalds1da177e2005-04-16 15:20:36 -07005477 status = decode_op_hdr(xdr, OP_SETATTR);
5478 if (status)
5479 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005480 p = xdr_inline_decode(xdr, 4);
5481 if (unlikely(!p))
5482 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005483 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005484 p = xdr_inline_decode(xdr, bmlen << 2);
5485 if (likely(p))
5486 return 0;
5487out_overflow:
5488 print_overflow_msg(__func__, xdr);
5489 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005490}
5491
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005492static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005493{
Al Viro8687b632006-10-19 23:28:48 -07005494 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005495 uint32_t opnum;
5496 int32_t nfserr;
5497
Benny Halevyc0eae662009-08-14 17:20:14 +03005498 p = xdr_inline_decode(xdr, 8);
5499 if (unlikely(!p))
5500 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005501 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005502 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005503 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005504 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005505 return -EIO;
5506 }
Benny Halevycccddf42009-08-14 17:20:19 +03005507 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005508 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005509 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5510 if (unlikely(!p))
5511 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005512 p = xdr_decode_hyper(p, &res->clientid);
5513 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005514 } else if (nfserr == NFSERR_CLID_INUSE) {
5515 uint32_t len;
5516
5517 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005518 p = xdr_inline_decode(xdr, 4);
5519 if (unlikely(!p))
5520 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005521 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005522 p = xdr_inline_decode(xdr, len);
5523 if (unlikely(!p))
5524 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005525
5526 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005527 p = xdr_inline_decode(xdr, 4);
5528 if (unlikely(!p))
5529 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005530 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005531 p = xdr_inline_decode(xdr, len);
5532 if (unlikely(!p))
5533 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005534 return -NFSERR_CLID_INUSE;
5535 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005536 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005537
5538 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005539out_overflow:
5540 print_overflow_msg(__func__, xdr);
5541 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005542}
5543
5544static int decode_setclientid_confirm(struct xdr_stream *xdr)
5545{
5546 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5547}
5548
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005549static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005550{
Al Viro8687b632006-10-19 23:28:48 -07005551 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005552 int status;
5553
5554 status = decode_op_hdr(xdr, OP_WRITE);
5555 if (status)
5556 return status;
5557
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005558 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005559 if (unlikely(!p))
5560 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005561 res->count = be32_to_cpup(p++);
5562 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005563 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005564out_overflow:
5565 print_overflow_msg(__func__, xdr);
5566 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005567}
5568
5569static int decode_delegreturn(struct xdr_stream *xdr)
5570{
5571 return decode_op_hdr(xdr, OP_DELEGRETURN);
5572}
5573
Chuck Leverfb15b262013-03-16 15:54:34 -04005574static int decode_secinfo_gss(struct xdr_stream *xdr,
5575 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005576{
Chuck Leverfb15b262013-03-16 15:54:34 -04005577 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005578 __be32 *p;
5579
5580 p = xdr_inline_decode(xdr, 4);
5581 if (unlikely(!p))
5582 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005583 oid_len = be32_to_cpup(p);
5584 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005585 goto out_err;
5586
Chuck Leverfb15b262013-03-16 15:54:34 -04005587 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005588 if (unlikely(!p))
5589 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005590 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5591 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005592
5593 p = xdr_inline_decode(xdr, 8);
5594 if (unlikely(!p))
5595 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005596 flavor->flavor_info.qop = be32_to_cpup(p++);
5597 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005598
5599 return 0;
5600
5601out_overflow:
5602 print_overflow_msg(__func__, xdr);
5603 return -EIO;
5604out_err:
5605 return -EINVAL;
5606}
5607
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005608static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005609{
Chuck Leverfb15b262013-03-16 15:54:34 -04005610 struct nfs4_secinfo4 *sec_flavor;
5611 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005612 int status;
5613 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005614
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005615 p = xdr_inline_decode(xdr, 4);
5616 if (unlikely(!p))
5617 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005618
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005619 res->flavors->num_flavors = 0;
5620 num_flavors = be32_to_cpup(p);
5621
5622 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005623 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005624 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005625 break;
5626
5627 p = xdr_inline_decode(xdr, 4);
5628 if (unlikely(!p))
5629 goto out_overflow;
5630 sec_flavor->flavor = be32_to_cpup(p);
5631
5632 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005633 status = decode_secinfo_gss(xdr, sec_flavor);
5634 if (status)
5635 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005636 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005637 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005638 }
5639
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005640 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005641out:
5642 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005643out_overflow:
5644 print_overflow_msg(__func__, xdr);
5645 return -EIO;
5646}
5647
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005648static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5649{
5650 int status = decode_op_hdr(xdr, OP_SECINFO);
5651 if (status)
5652 return status;
5653 return decode_secinfo_common(xdr, res);
5654}
5655
Benny Halevy99fe60d2009-04-01 09:22:29 -04005656#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005657static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5658{
5659 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5660 if (status)
5661 return status;
5662 return decode_secinfo_common(xdr, res);
5663}
5664
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005665static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5666{
5667 __be32 *p;
5668 uint32_t bitmap_words;
5669 unsigned int i;
5670
5671 p = xdr_inline_decode(xdr, 4);
Pan Bian4edabfd2017-04-23 14:49:41 +08005672 if (!p)
5673 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005674 bitmap_words = be32_to_cpup(p++);
5675 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5676 return -EIO;
5677 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5678 for (i = 0; i < bitmap_words; i++)
5679 op_map->u.words[i] = be32_to_cpup(p++);
5680
5681 return 0;
5682}
5683
Benny Halevy99fe60d2009-04-01 09:22:29 -04005684static int decode_exchange_id(struct xdr_stream *xdr,
5685 struct nfs41_exchange_id_res *res)
5686{
5687 __be32 *p;
5688 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005689 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005690 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005691 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005692
5693 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5694 if (status)
5695 return status;
5696
Benny Halevyc0eae662009-08-14 17:20:14 +03005697 p = xdr_inline_decode(xdr, 8);
5698 if (unlikely(!p))
5699 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005700 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005701 p = xdr_inline_decode(xdr, 12);
5702 if (unlikely(!p))
5703 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005704 res->seqid = be32_to_cpup(p++);
5705 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005706
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005707 res->state_protect.how = be32_to_cpup(p);
5708 switch (res->state_protect.how) {
5709 case SP4_NONE:
5710 break;
5711 case SP4_MACH_CRED:
5712 status = decode_op_map(xdr, &res->state_protect.enforce);
5713 if (status)
5714 return status;
5715 status = decode_op_map(xdr, &res->state_protect.allow);
5716 if (status)
5717 return status;
5718 break;
5719 default:
5720 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005721 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005722 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005723
Chuck Leveracdeb692012-05-21 22:46:16 -04005724 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005725 p = xdr_inline_decode(xdr, 8);
5726 if (unlikely(!p))
5727 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005728 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005729
Chuck Leveracdeb692012-05-21 22:46:16 -04005730 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005731 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5732 if (unlikely(status))
5733 return status;
Chuck Leveracdeb692012-05-21 22:46:16 -04005734 memcpy(res->server_owner->major_id, dummy_str, dummy);
5735 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005736
Chuck Leveracdeb692012-05-21 22:46:16 -04005737 /* server_scope4 */
5738 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5739 if (unlikely(status))
5740 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005741 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5742 res->server_scope->server_scope_sz = dummy;
5743
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005744 /* Implementation Id */
5745 p = xdr_inline_decode(xdr, 4);
5746 if (unlikely(!p))
5747 goto out_overflow;
5748 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005749
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005750 if (impl_id_count) {
5751 /* nii_domain */
5752 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5753 if (unlikely(status))
5754 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005755 memcpy(res->impl_id->domain, dummy_str, dummy);
5756
5757 /* nii_name */
5758 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5759 if (unlikely(status))
5760 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005761 memcpy(res->impl_id->name, dummy_str, dummy);
5762
5763 /* nii_date */
5764 p = xdr_inline_decode(xdr, 12);
5765 if (unlikely(!p))
5766 goto out_overflow;
5767 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5768 res->impl_id->date.nseconds = be32_to_cpup(p);
5769
5770 /* if there's more than one entry, ignore the rest */
5771 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005772 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005773out_overflow:
5774 print_overflow_msg(__func__, xdr);
5775 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005776}
Andy Adamsonfc931582009-04-01 09:22:31 -04005777
5778static int decode_chan_attrs(struct xdr_stream *xdr,
5779 struct nfs4_channel_attrs *attrs)
5780{
5781 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005782 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005783
Benny Halevyc0eae662009-08-14 17:20:14 +03005784 p = xdr_inline_decode(xdr, 28);
5785 if (unlikely(!p))
5786 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005787 val = be32_to_cpup(p++); /* headerpadsz */
5788 if (val)
5789 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005790 attrs->max_rqst_sz = be32_to_cpup(p++);
5791 attrs->max_resp_sz = be32_to_cpup(p++);
5792 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5793 attrs->max_ops = be32_to_cpup(p++);
5794 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005795 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005796 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005797 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5798 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005799 return -EINVAL;
5800 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005801 if (nr_attrs == 1) {
5802 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5803 if (unlikely(!p))
5804 goto out_overflow;
5805 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005806 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005807out_overflow:
5808 print_overflow_msg(__func__, xdr);
5809 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005810}
5811
Benny Halevye78291e2009-08-14 17:20:00 +03005812static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5813{
5814 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005815}
5816
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005817static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5818 struct nfs41_bind_conn_to_session_res *res)
5819{
5820 __be32 *p;
5821 int status;
5822
5823 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5824 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005825 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005826 if (unlikely(status))
5827 return status;
5828
5829 /* dir flags, rdma mode bool */
5830 p = xdr_inline_decode(xdr, 8);
5831 if (unlikely(!p))
5832 goto out_overflow;
5833
5834 res->dir = be32_to_cpup(p++);
5835 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5836 return -EIO;
5837 if (be32_to_cpup(p) == 0)
5838 res->use_conn_in_rdma_mode = false;
5839 else
5840 res->use_conn_in_rdma_mode = true;
5841
5842 return 0;
5843out_overflow:
5844 print_overflow_msg(__func__, xdr);
5845 return -EIO;
5846}
5847
Andy Adamsonfc931582009-04-01 09:22:31 -04005848static int decode_create_session(struct xdr_stream *xdr,
5849 struct nfs41_create_session_res *res)
5850{
5851 __be32 *p;
5852 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005853
5854 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005855 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005856 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005857 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005858 return status;
5859
Andy Adamsonfc931582009-04-01 09:22:31 -04005860 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005861 p = xdr_inline_decode(xdr, 8);
5862 if (unlikely(!p))
5863 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005864 res->seqid = be32_to_cpup(p++);
5865 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005866
5867 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005868 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005869 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005870 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005871 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005872out_overflow:
5873 print_overflow_msg(__func__, xdr);
5874 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005875}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005876
5877static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5878{
5879 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5880}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005881
Trond Myklebust66245532012-05-25 17:18:09 -04005882static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5883{
5884 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5885}
5886
Ricardo Labiaga180197532009-12-05 16:08:40 -05005887static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5888{
5889 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5890}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005891#endif /* CONFIG_NFS_V4_1 */
5892
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005893static int decode_sequence(struct xdr_stream *xdr,
5894 struct nfs4_sequence_res *res,
5895 struct rpc_rqst *rqstp)
5896{
5897#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005898 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005899 struct nfs4_sessionid id;
5900 u32 dummy;
5901 int status;
5902 __be32 *p;
5903
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005904 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005905 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005906 if (!res->sr_slot->table->session)
5907 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005908
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005909 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005910 if (!status)
5911 status = decode_sessionid(xdr, &id);
5912 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005913 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005914
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005915 /*
5916 * If the server returns different values for sessionID, slotID or
5917 * sequence number, the server is looney tunes.
5918 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005919 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005920 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005921
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005922 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005923 NFS4_MAX_SESSIONID_LEN)) {
5924 dprintk("%s Invalid session id\n", __func__);
5925 goto out_err;
5926 }
Benny Halevye78291e2009-08-14 17:20:00 +03005927
Benny Halevyc0eae662009-08-14 17:20:14 +03005928 p = xdr_inline_decode(xdr, 20);
5929 if (unlikely(!p))
5930 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005931
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005932 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005933 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005934 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005935 dprintk("%s Invalid sequence number\n", __func__);
5936 goto out_err;
5937 }
5938 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005939 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005940 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005941 dprintk("%s Invalid slot id\n", __func__);
5942 goto out_err;
5943 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005944 /* highest slot id */
5945 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005946 /* target highest slot id */
5947 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005948 /* result flags */
5949 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005950 status = 0;
5951out_err:
5952 res->sr_status = status;
5953 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005954out_overflow:
5955 print_overflow_msg(__func__, xdr);
5956 status = -EIO;
5957 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005958#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005959 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005960#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005961}
5962
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005963#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005964static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5965{
5966 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5967 return decode_stateid(xdr, stateid);
5968}
5969
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005970static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005971 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005972{
Trond Myklebust4e590802015-03-09 14:01:25 -04005973 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005974 __be32 *p;
5975 uint32_t len, type;
5976 int status;
5977
5978 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5979 if (status) {
5980 if (status == -ETOOSMALL) {
5981 p = xdr_inline_decode(xdr, 4);
5982 if (unlikely(!p))
5983 goto out_overflow;
5984 pdev->mincount = be32_to_cpup(p);
5985 dprintk("%s: Min count too small. mincnt = %u\n",
5986 __func__, pdev->mincount);
5987 }
5988 return status;
5989 }
5990
5991 p = xdr_inline_decode(xdr, 8);
5992 if (unlikely(!p))
5993 goto out_overflow;
5994 type = be32_to_cpup(p++);
5995 if (type != pdev->layout_type) {
5996 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5997 __func__, pdev->layout_type, type);
5998 return -EINVAL;
5999 }
6000 /*
6001 * Get the length of the opaque device_addr4. xdr_read_pages places
6002 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
6003 * and places the remaining xdr data in xdr_buf->tail
6004 */
6005 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04006006 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
6007 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006008
6009 /* Parse notification bitmap, verifying that it is zero. */
6010 p = xdr_inline_decode(xdr, 4);
6011 if (unlikely(!p))
6012 goto out_overflow;
6013 len = be32_to_cpup(p);
6014 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00006015 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006016
6017 p = xdr_inline_decode(xdr, 4 * len);
6018 if (unlikely(!p))
6019 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07006020
Trond Myklebust4e590802015-03-09 14:01:25 -04006021 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07006022 for (i = 1; i < len; i++) {
6023 if (be32_to_cpup(p++)) {
6024 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006025 __func__);
6026 return -EIO;
6027 }
6028 }
6029 }
6030 return 0;
6031out_overflow:
6032 print_overflow_msg(__func__, xdr);
6033 return -EIO;
6034}
6035
6036static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6037 struct nfs4_layoutget_res *res)
6038{
6039 __be32 *p;
6040 int status;
6041 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04006042 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006043
6044 status = decode_op_hdr(xdr, OP_LAYOUTGET);
6045 if (status)
6046 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006047 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006048 if (unlikely(!p))
6049 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006050 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04006051 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006052 p = xdr_inline_decode(xdr, 4);
6053 if (unlikely(!p))
6054 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006055 layout_count = be32_to_cpup(p);
6056 if (!layout_count) {
6057 dprintk("%s: server responded with empty layout array\n",
6058 __func__);
6059 return -EINVAL;
6060 }
6061
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006062 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006063 if (unlikely(!p))
6064 goto out_overflow;
6065 p = xdr_decode_hyper(p, &res->range.offset);
6066 p = xdr_decode_hyper(p, &res->range.length);
6067 res->range.iomode = be32_to_cpup(p++);
6068 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006069 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006070
6071 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
6072 __func__,
6073 (unsigned long)res->range.offset,
6074 (unsigned long)res->range.length,
6075 res->range.iomode,
6076 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006077 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006078
Trond Myklebust64bd5772012-06-20 22:35:05 -04006079 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006080 if (res->layoutp->len > recvd) {
6081 dprintk("NFS: server cheating in layoutget reply: "
6082 "layout len %u > recvd %u\n",
6083 res->layoutp->len, recvd);
6084 return -EINVAL;
6085 }
6086
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006087 if (layout_count > 1) {
6088 /* We only handle a length one array at the moment. Any
6089 * further entries are just ignored. Note that this means
6090 * the client may see a response that is less than the
6091 * minimum it requested.
6092 */
6093 dprintk("%s: server responded with %d layouts, dropping tail\n",
6094 __func__, layout_count);
6095 }
6096
6097 return 0;
6098out_overflow:
6099 print_overflow_msg(__func__, xdr);
6100 return -EIO;
6101}
Andy Adamson863a3c62011-03-23 13:27:54 +00006102
Benny Halevycbe82602011-05-22 19:52:37 +03006103static int decode_layoutreturn(struct xdr_stream *xdr,
6104 struct nfs4_layoutreturn_res *res)
6105{
6106 __be32 *p;
6107 int status;
6108
6109 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6110 if (status)
6111 return status;
6112 p = xdr_inline_decode(xdr, 4);
6113 if (unlikely(!p))
6114 goto out_overflow;
6115 res->lrs_present = be32_to_cpup(p);
6116 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04006117 status = decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustfcd88432017-11-07 12:39:44 -05006118 else
6119 nfs4_stateid_copy(&res->stateid, &invalid_stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03006120 return status;
6121out_overflow:
6122 print_overflow_msg(__func__, xdr);
6123 return -EIO;
6124}
6125
Andy Adamson863a3c62011-03-23 13:27:54 +00006126static int decode_layoutcommit(struct xdr_stream *xdr,
6127 struct rpc_rqst *req,
6128 struct nfs4_layoutcommit_res *res)
6129{
6130 __be32 *p;
6131 __u32 sizechanged;
6132 int status;
6133
6134 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04006135 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00006136 if (status)
6137 return status;
6138
6139 p = xdr_inline_decode(xdr, 4);
6140 if (unlikely(!p))
6141 goto out_overflow;
6142 sizechanged = be32_to_cpup(p);
6143
6144 if (sizechanged) {
6145 /* throw away new size */
6146 p = xdr_inline_decode(xdr, 8);
6147 if (unlikely(!p))
6148 goto out_overflow;
6149 }
6150 return 0;
6151out_overflow:
6152 print_overflow_msg(__func__, xdr);
6153 return -EIO;
6154}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006155
6156static int decode_test_stateid(struct xdr_stream *xdr,
6157 struct nfs41_test_stateid_res *res)
6158{
6159 __be32 *p;
6160 int status;
6161 int num_res;
6162
6163 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6164 if (status)
6165 return status;
6166
6167 p = xdr_inline_decode(xdr, 4);
6168 if (unlikely(!p))
6169 goto out_overflow;
6170 num_res = be32_to_cpup(p++);
6171 if (num_res != 1)
6172 goto out;
6173
6174 p = xdr_inline_decode(xdr, 4);
6175 if (unlikely(!p))
6176 goto out_overflow;
6177 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006178
6179 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006180out_overflow:
6181 print_overflow_msg(__func__, xdr);
6182out:
6183 return -EIO;
6184}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006185
6186static int decode_free_stateid(struct xdr_stream *xdr,
6187 struct nfs41_free_stateid_res *res)
6188{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006189 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006190 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006191}
Trond Myklebustcf805162016-11-15 14:56:07 -05006192#else
6193static inline
6194int decode_layoutreturn(struct xdr_stream *xdr,
6195 struct nfs4_layoutreturn_res *res)
6196{
6197 return 0;
6198}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006199#endif /* CONFIG_NFS_V4_1 */
6200
Linus Torvalds1da177e2005-04-16 15:20:36 -07006201/*
Benny Halevy49c25592008-12-23 16:06:16 -05006202 * END OF "GENERIC" DECODE ROUTINES.
6203 */
6204
6205/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206 * Decode OPEN_DOWNGRADE response
6207 */
Chuck Leverbf269552010-12-14 14:59:29 +00006208static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6209 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006210 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006211{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006212 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006213 struct compound_hdr hdr;
6214 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006215
Chuck Leverbf269552010-12-14 14:59:29 +00006216 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006217 if (status)
6218 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006219 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006220 if (status)
6221 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006222 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006223 if (status)
6224 goto out;
Trond Myklebustb6808142016-11-20 13:34:16 -05006225 if (res->lr_res) {
6226 status = decode_layoutreturn(xdr, res->lr_res);
6227 res->lr_ret = status;
6228 if (status)
6229 goto out;
6230 }
Chuck Leverbf269552010-12-14 14:59:29 +00006231 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006232out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006233 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006234}
6235
6236/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237 * Decode ACCESS response
6238 */
Chuck Leverbf269552010-12-14 14:59:29 +00006239static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006240 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006241{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006242 struct nfs4_accessres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243 struct compound_hdr hdr;
6244 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006245
Chuck Leverbf269552010-12-14 14:59:29 +00006246 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006247 if (status)
6248 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006249 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006250 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006252 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006253 if (status != 0)
6254 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006255 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006256 if (status != 0)
6257 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006258 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006259out:
6260 return status;
6261}
6262
6263/*
6264 * Decode LOOKUP response
6265 */
Chuck Leverbf269552010-12-14 14:59:29 +00006266static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006267 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006268{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006269 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270 struct compound_hdr hdr;
6271 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006272
Chuck Leverbf269552010-12-14 14:59:29 +00006273 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006274 if (status)
6275 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006276 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006277 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006278 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006279 status = decode_putfh(xdr);
6280 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006282 status = decode_lookup(xdr);
6283 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006284 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006285 status = decode_getfh(xdr, res->fh);
6286 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006287 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006288 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006289out:
6290 return status;
6291}
6292
6293/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07006294 * Decode LOOKUPP response
6295 */
6296static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6297 void *data)
6298{
6299 struct nfs4_lookupp_res *res = data;
6300 struct compound_hdr hdr;
6301 int status;
6302
6303 status = decode_compound_hdr(xdr, &hdr);
6304 if (status)
6305 goto out;
6306 status = decode_sequence(xdr, &res->seq_res, rqstp);
6307 if (status)
6308 goto out;
6309 status = decode_putfh(xdr);
6310 if (status)
6311 goto out;
6312 status = decode_lookupp(xdr);
6313 if (status)
6314 goto out;
6315 status = decode_getfh(xdr, res->fh);
6316 if (status)
6317 goto out;
6318 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6319out:
6320 return status;
6321}
6322
6323/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324 * Decode LOOKUP_ROOT response
6325 */
Chuck Leverbf269552010-12-14 14:59:29 +00006326static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6327 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006328 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006329{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006330 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006331 struct compound_hdr hdr;
6332 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006333
Chuck Leverbf269552010-12-14 14:59:29 +00006334 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006335 if (status)
6336 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006337 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006338 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006340 status = decode_putrootfh(xdr);
6341 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006342 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006343 status = decode_getfh(xdr, res->fh);
6344 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006345 status = decode_getfattr_label(xdr, res->fattr,
6346 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006347out:
6348 return status;
6349}
6350
6351/*
6352 * Decode REMOVE response
6353 */
Chuck Leverbf269552010-12-14 14:59:29 +00006354static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006355 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006356{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006357 struct nfs_removeres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358 struct compound_hdr hdr;
6359 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006360
Chuck Leverbf269552010-12-14 14:59:29 +00006361 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006362 if (status)
6363 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006365 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006366 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_putfh(xdr);
6368 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006369 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006370 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371out:
6372 return status;
6373}
6374
6375/*
6376 * Decode RENAME response
6377 */
Chuck Leverbf269552010-12-14 14:59:29 +00006378static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006379 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006380{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006381 struct nfs_renameres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006382 struct compound_hdr hdr;
6383 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006384
Chuck Leverbf269552010-12-14 14:59:29 +00006385 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006386 if (status)
6387 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006388 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006389 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006390 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006391 status = decode_putfh(xdr);
6392 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006393 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006394 status = decode_savefh(xdr);
6395 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006397 status = decode_putfh(xdr);
6398 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006399 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006400 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006401out:
6402 return status;
6403}
6404
6405/*
6406 * Decode LINK response
6407 */
Chuck Leverbf269552010-12-14 14:59:29 +00006408static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006409 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006410{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006411 struct nfs4_link_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006412 struct compound_hdr hdr;
6413 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006414
Chuck Leverbf269552010-12-14 14:59:29 +00006415 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006416 if (status)
6417 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006418 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006419 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006421 status = decode_putfh(xdr);
6422 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006423 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006424 status = decode_savefh(xdr);
6425 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006427 status = decode_putfh(xdr);
6428 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006430 status = decode_link(xdr, &res->cinfo);
6431 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006432 goto out;
6433 /*
6434 * Note order: OP_LINK leaves the directory as the current
6435 * filehandle.
6436 */
Chuck Leverbf269552010-12-14 14:59:29 +00006437 status = decode_restorefh(xdr);
6438 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006439 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006440 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006441out:
6442 return status;
6443}
6444
6445/*
6446 * Decode CREATE response
6447 */
Chuck Leverbf269552010-12-14 14:59:29 +00006448static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006449 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006451 struct nfs4_create_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006452 struct compound_hdr hdr;
6453 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006454
Chuck Leverbf269552010-12-14 14:59:29 +00006455 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006456 if (status)
6457 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006458 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006459 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006461 status = decode_putfh(xdr);
6462 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006463 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006464 status = decode_create(xdr, &res->dir_cinfo);
6465 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006467 status = decode_getfh(xdr, res->fh);
6468 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006469 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006470 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471out:
6472 return status;
6473}
6474
6475/*
6476 * Decode SYMLINK response
6477 */
Chuck Leverbf269552010-12-14 14:59:29 +00006478static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006479 void *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480{
Chuck Leverbf269552010-12-14 14:59:29 +00006481 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482}
6483
6484/*
6485 * Decode GETATTR response
6486 */
Chuck Leverbf269552010-12-14 14:59:29 +00006487static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006488 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006489{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006490 struct nfs4_getattr_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491 struct compound_hdr hdr;
6492 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006493
Chuck Leverbf269552010-12-14 14:59:29 +00006494 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495 if (status)
6496 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006497 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006498 if (status)
6499 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006500 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006501 if (status)
6502 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006503 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006504out:
6505 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006506}
6507
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006508/*
6509 * Encode an SETACL request
6510 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006511static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006512 const void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006513{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006514 const struct nfs_setaclargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006515 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006516 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006517 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006518
Chuck Lever9f06c712010-12-14 14:59:18 +00006519 encode_compound_hdr(xdr, req, &hdr);
6520 encode_sequence(xdr, &args->seq_args, &hdr);
6521 encode_putfh(xdr, args->fh, &hdr);
6522 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006523 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006524}
Andy Adamson05d564f2008-12-23 16:06:15 -05006525
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006526/*
6527 * Decode SETACL response
6528 */
6529static int
Chuck Leverbf269552010-12-14 14:59:29 +00006530nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006531 void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006532{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006533 struct nfs_setaclres *res = data;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006534 struct compound_hdr hdr;
6535 int status;
6536
Chuck Leverbf269552010-12-14 14:59:29 +00006537 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006538 if (status)
6539 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006540 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006541 if (status)
6542 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006543 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006544 if (status)
6545 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006546 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006547out:
6548 return status;
6549}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550
6551/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006552 * Decode GETACL response
6553 */
6554static int
Chuck Leverbf269552010-12-14 14:59:29 +00006555nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006556 void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006557{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006558 struct nfs_getaclres *res = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00006559 struct compound_hdr hdr;
6560 int status;
6561
Trond Myklebust331818f2012-02-03 18:30:53 -05006562 if (res->acl_scratch != NULL) {
6563 void *p = page_address(res->acl_scratch);
6564 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6565 }
Chuck Leverbf269552010-12-14 14:59:29 +00006566 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006567 if (status)
6568 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006569 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006570 if (status)
6571 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006572 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006573 if (status)
6574 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006575 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006576
6577out:
6578 return status;
6579}
6580
6581/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006582 * Decode CLOSE response
6583 */
Chuck Leverbf269552010-12-14 14:59:29 +00006584static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006585 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006586{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006587 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006588 struct compound_hdr hdr;
6589 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006590
Chuck Leverbf269552010-12-14 14:59:29 +00006591 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006592 if (status)
6593 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006594 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006595 if (status)
6596 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006597 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006598 if (status)
6599 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006600 if (res->lr_res) {
6601 status = decode_layoutreturn(xdr, res->lr_res);
6602 res->lr_ret = status;
6603 if (status)
6604 goto out;
6605 }
Trond Myklebustd8d84982016-12-19 12:14:44 -05006606 if (res->fattr != NULL) {
6607 status = decode_getfattr(xdr, res->fattr, res->server);
6608 if (status != 0)
6609 goto out;
6610 }
Chuck Leverbf269552010-12-14 14:59:29 +00006611 status = decode_close(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006612out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006613 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006614}
6615
6616/*
6617 * Decode OPEN response
6618 */
Chuck Leverbf269552010-12-14 14:59:29 +00006619static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006620 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006621{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006622 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006623 struct compound_hdr hdr;
6624 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006625
Chuck Leverbf269552010-12-14 14:59:29 +00006626 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006627 if (status)
6628 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006629 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006630 if (status)
6631 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006632 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006633 if (status)
6634 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006635 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006636 if (status)
6637 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006638 status = decode_getfh(xdr, &res->fh);
6639 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006641 if (res->access_request)
6642 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006643 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006645 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006646}
6647
6648/*
6649 * Decode OPEN_CONFIRM response
6650 */
Chuck Leverbf269552010-12-14 14:59:29 +00006651static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6652 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006653 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006654{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006655 struct nfs_open_confirmres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006656 struct compound_hdr hdr;
6657 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006658
Chuck Leverbf269552010-12-14 14:59:29 +00006659 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006660 if (status)
6661 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006662 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006663 if (status)
6664 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006665 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006667 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006668}
6669
6670/*
6671 * Decode OPEN response
6672 */
Chuck Leverbf269552010-12-14 14:59:29 +00006673static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6674 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006675 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006676{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006677 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006678 struct compound_hdr hdr;
6679 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006680
Chuck Leverbf269552010-12-14 14:59:29 +00006681 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006682 if (status)
6683 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006684 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006685 if (status)
6686 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006687 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006688 if (status)
6689 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006690 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006691 if (status)
6692 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006693 if (res->access_request)
6694 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006695 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006696out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006697 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006698}
6699
6700/*
6701 * Decode SETATTR response
6702 */
Chuck Leverbf269552010-12-14 14:59:29 +00006703static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6704 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006705 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006706{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006707 struct nfs_setattrres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006708 struct compound_hdr hdr;
6709 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006710
Chuck Leverbf269552010-12-14 14:59:29 +00006711 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006712 if (status)
6713 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006714 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006715 if (status)
6716 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006717 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006718 if (status)
6719 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006720 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006721 if (status)
6722 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006723 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006724out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006725 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006726}
6727
6728/*
6729 * Decode LOCK response
6730 */
Chuck Leverbf269552010-12-14 14:59:29 +00006731static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006732 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006733{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006734 struct nfs_lock_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006735 struct compound_hdr hdr;
6736 int status;
6737
Chuck Leverbf269552010-12-14 14:59:29 +00006738 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006739 if (status)
6740 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006741 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006742 if (status)
6743 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006744 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006745 if (status)
6746 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006747 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006748out:
6749 return status;
6750}
6751
6752/*
6753 * Decode LOCKT response
6754 */
Chuck Leverbf269552010-12-14 14:59:29 +00006755static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006756 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006758 struct nfs_lockt_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006759 struct compound_hdr hdr;
6760 int status;
6761
Chuck Leverbf269552010-12-14 14:59:29 +00006762 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006763 if (status)
6764 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006765 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006766 if (status)
6767 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006768 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006769 if (status)
6770 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006771 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006772out:
6773 return status;
6774}
6775
6776/*
6777 * Decode LOCKU response
6778 */
Chuck Leverbf269552010-12-14 14:59:29 +00006779static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006780 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006781{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006782 struct nfs_locku_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006783 struct compound_hdr hdr;
6784 int status;
6785
Chuck Leverbf269552010-12-14 14:59:29 +00006786 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006787 if (status)
6788 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006789 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006790 if (status)
6791 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006792 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006793 if (status)
6794 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006795 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006796out:
6797 return status;
6798}
6799
Chuck Leverbf269552010-12-14 14:59:29 +00006800static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6801 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006802{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006803 struct compound_hdr hdr;
6804 int status;
6805
Chuck Leverbf269552010-12-14 14:59:29 +00006806 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006807 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006808 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006809 return status;
6810}
6811
Linus Torvalds1da177e2005-04-16 15:20:36 -07006812/*
6813 * Decode READLINK response
6814 */
Chuck Leverbf269552010-12-14 14:59:29 +00006815static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6816 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006817 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006818{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006819 struct nfs4_readlink_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006820 struct compound_hdr hdr;
6821 int status;
6822
Chuck Leverbf269552010-12-14 14:59:29 +00006823 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006824 if (status)
6825 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006826 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006827 if (status)
6828 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006829 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006830 if (status)
6831 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006832 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006833out:
6834 return status;
6835}
6836
6837/*
6838 * Decode READDIR response
6839 */
Chuck Leverbf269552010-12-14 14:59:29 +00006840static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006841 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006842{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006843 struct nfs4_readdir_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006844 struct compound_hdr hdr;
6845 int status;
6846
Chuck Leverbf269552010-12-14 14:59:29 +00006847 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006848 if (status)
6849 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006850 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006851 if (status)
6852 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006853 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006854 if (status)
6855 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006856 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006857out:
6858 return status;
6859}
6860
6861/*
6862 * Decode Read response
6863 */
Chuck Leverbf269552010-12-14 14:59:29 +00006864static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006865 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006866{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006867 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006868 struct compound_hdr hdr;
6869 int status;
6870
Chuck Leverbf269552010-12-14 14:59:29 +00006871 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006872 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006873 if (status)
6874 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006875 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006876 if (status)
6877 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006878 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006879 if (status)
6880 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006881 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006882 if (!status)
6883 status = res->count;
6884out:
6885 return status;
6886}
6887
6888/*
6889 * Decode WRITE response
6890 */
Chuck Leverbf269552010-12-14 14:59:29 +00006891static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006892 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006893{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006894 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006895 struct compound_hdr hdr;
6896 int status;
6897
Chuck Leverbf269552010-12-14 14:59:29 +00006898 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006899 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006900 if (status)
6901 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006902 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006903 if (status)
6904 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006905 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006906 if (status)
6907 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006908 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006909 if (status)
6910 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006911 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006912 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006913 if (!status)
6914 status = res->count;
6915out:
6916 return status;
6917}
6918
6919/*
6920 * Decode COMMIT response
6921 */
Chuck Leverbf269552010-12-14 14:59:29 +00006922static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006923 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006924{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006925 struct nfs_commitres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006926 struct compound_hdr hdr;
6927 int status;
6928
Chuck Leverbf269552010-12-14 14:59:29 +00006929 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006930 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006931 if (status)
6932 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006933 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006934 if (status)
6935 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006936 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006937 if (status)
6938 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006939 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006940out:
6941 return status;
6942}
6943
6944/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006945 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006946 */
Chuck Leverbf269552010-12-14 14:59:29 +00006947static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006948 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006949{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006950 struct nfs4_fsinfo_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006951 struct compound_hdr hdr;
6952 int status;
6953
Chuck Leverbf269552010-12-14 14:59:29 +00006954 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006955 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006956 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006957 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006958 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006959 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006960 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006961 return status;
6962}
6963
6964/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006965 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006966 */
Chuck Leverbf269552010-12-14 14:59:29 +00006967static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006968 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006969{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006970 struct nfs4_pathconf_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006971 struct compound_hdr hdr;
6972 int status;
6973
Chuck Leverbf269552010-12-14 14:59:29 +00006974 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006975 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006976 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006977 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006978 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006979 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006980 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006981 return status;
6982}
6983
6984/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006985 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006986 */
Chuck Leverbf269552010-12-14 14:59:29 +00006987static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006988 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006989{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006990 struct nfs4_statfs_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006991 struct compound_hdr hdr;
6992 int status;
6993
Chuck Leverbf269552010-12-14 14:59:29 +00006994 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006995 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006996 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006997 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006998 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006999 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007000 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007001 return status;
7002}
7003
7004/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007005 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007006 */
Chuck Leverbf269552010-12-14 14:59:29 +00007007static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
7008 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007009 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007010{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007011 struct nfs4_server_caps_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007012 struct compound_hdr hdr;
7013 int status;
7014
Chuck Leverbf269552010-12-14 14:59:29 +00007015 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007016 if (status)
7017 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007018 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007019 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007020 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007021 status = decode_putfh(xdr);
7022 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007023 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007024 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007025out:
7026 return status;
7027}
7028
7029/*
7030 * Decode RENEW response
7031 */
Chuck Leverbf269552010-12-14 14:59:29 +00007032static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
7033 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007034{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007035 struct compound_hdr hdr;
7036 int status;
7037
Chuck Leverbf269552010-12-14 14:59:29 +00007038 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007039 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007040 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007041 return status;
7042}
7043
7044/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007045 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007046 */
Chuck Leverbf269552010-12-14 14:59:29 +00007047static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
7048 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007049 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007050{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007051 struct nfs4_setclientid_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007052 struct compound_hdr hdr;
7053 int status;
7054
Chuck Leverbf269552010-12-14 14:59:29 +00007055 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007056 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007057 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007058 return status;
7059}
7060
7061/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007062 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007063 */
Chuck Leverbf269552010-12-14 14:59:29 +00007064static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007065 struct xdr_stream *xdr,
7066 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007067{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007068 struct compound_hdr hdr;
7069 int status;
7070
Chuck Leverbf269552010-12-14 14:59:29 +00007071 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007072 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007073 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007074 return status;
7075}
7076
7077/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007078 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007079 */
Chuck Leverbf269552010-12-14 14:59:29 +00007080static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
7081 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007082 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007083{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007084 struct nfs4_delegreturnres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007085 struct compound_hdr hdr;
7086 int status;
7087
Chuck Leverbf269552010-12-14 14:59:29 +00007088 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007089 if (status)
7090 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007091 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007092 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01007093 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007094 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01007095 if (status != 0)
7096 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05007097 if (res->lr_res) {
7098 status = decode_layoutreturn(xdr, res->lr_res);
7099 res->lr_ret = status;
7100 if (status)
7101 goto out;
7102 }
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05007103 if (res->fattr) {
7104 status = decode_getfattr(xdr, res->fattr, res->server);
7105 if (status != 0)
7106 goto out;
7107 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04007108 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01007109out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07007110 return status;
7111}
7112
Trond Myklebust683b57b2006-06-09 09:34:22 -04007113/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007114 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04007115 */
Chuck Leverbf269552010-12-14 14:59:29 +00007116static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
7117 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007118 void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007119{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007120 struct nfs4_fs_locations_res *res = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04007121 struct compound_hdr hdr;
7122 int status;
7123
Chuck Leverbf269552010-12-14 14:59:29 +00007124 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007125 if (status)
7126 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007127 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007128 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007129 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007130 status = decode_putfh(xdr);
7131 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007132 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04007133 if (res->migration) {
7134 xdr_enter_page(xdr, PAGE_SIZE);
7135 status = decode_getfattr_generic(xdr,
7136 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007137 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04007138 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04007139 if (status)
7140 goto out;
7141 if (res->renew)
7142 status = decode_renew(xdr);
7143 } else {
7144 status = decode_lookup(xdr);
7145 if (status)
7146 goto out;
7147 xdr_enter_page(xdr, PAGE_SIZE);
7148 status = decode_getfattr_generic(xdr,
7149 &res->fs_locations->fattr,
7150 NULL, res->fs_locations,
7151 NULL, res->fs_locations->server);
7152 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04007153out:
7154 return status;
7155}
7156
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007157/*
7158 * Decode SECINFO response
7159 */
7160static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7161 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007162 void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007163{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007164 struct nfs4_secinfo_res *res = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007165 struct compound_hdr hdr;
7166 int status;
7167
7168 status = decode_compound_hdr(xdr, &hdr);
7169 if (status)
7170 goto out;
7171 status = decode_sequence(xdr, &res->seq_res, rqstp);
7172 if (status)
7173 goto out;
7174 status = decode_putfh(xdr);
7175 if (status)
7176 goto out;
7177 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007178out:
7179 return status;
7180}
7181
Chuck Lever44c99932013-10-17 14:13:30 -04007182/*
7183 * Decode FSID_PRESENT response
7184 */
7185static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7186 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007187 void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04007188{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007189 struct nfs4_fsid_present_res *res = data;
Chuck Lever44c99932013-10-17 14:13:30 -04007190 struct compound_hdr hdr;
7191 int status;
7192
7193 status = decode_compound_hdr(xdr, &hdr);
7194 if (status)
7195 goto out;
7196 status = decode_sequence(xdr, &res->seq_res, rqstp);
7197 if (status)
7198 goto out;
7199 status = decode_putfh(xdr);
7200 if (status)
7201 goto out;
7202 status = decode_getfh(xdr, res->fh);
7203 if (status)
7204 goto out;
7205 if (res->renew)
7206 status = decode_renew(xdr);
7207out:
7208 return status;
7209}
7210
Benny Halevy99fe60d2009-04-01 09:22:29 -04007211#if defined(CONFIG_NFS_V4_1)
7212/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007213 * Decode BIND_CONN_TO_SESSION response
7214 */
7215static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7216 struct xdr_stream *xdr,
7217 void *res)
7218{
7219 struct compound_hdr hdr;
7220 int status;
7221
7222 status = decode_compound_hdr(xdr, &hdr);
7223 if (!status)
7224 status = decode_bind_conn_to_session(xdr, res);
7225 return status;
7226}
7227
7228/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007229 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007230 */
Chuck Leverbf269552010-12-14 14:59:29 +00007231static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7232 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007233 void *res)
7234{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007235 struct compound_hdr hdr;
7236 int status;
7237
Chuck Leverbf269552010-12-14 14:59:29 +00007238 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007239 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007240 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007241 return status;
7242}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007243
7244/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007245 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007246 */
Chuck Leverbf269552010-12-14 14:59:29 +00007247static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7248 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007249 void *res)
Andy Adamsonfc931582009-04-01 09:22:31 -04007250{
Andy Adamsonfc931582009-04-01 09:22:31 -04007251 struct compound_hdr hdr;
7252 int status;
7253
Chuck Leverbf269552010-12-14 14:59:29 +00007254 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007255 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007256 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007257 return status;
7258}
7259
7260/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007261 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007262 */
Chuck Leverbf269552010-12-14 14:59:29 +00007263static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7264 struct xdr_stream *xdr,
7265 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007266{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007267 struct compound_hdr hdr;
7268 int status;
7269
Chuck Leverbf269552010-12-14 14:59:29 +00007270 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007271 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007272 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007273 return status;
7274}
7275
7276/*
Trond Myklebust66245532012-05-25 17:18:09 -04007277 * Decode DESTROY_CLIENTID response
7278 */
7279static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7280 struct xdr_stream *xdr,
7281 void *res)
7282{
7283 struct compound_hdr hdr;
7284 int status;
7285
7286 status = decode_compound_hdr(xdr, &hdr);
7287 if (!status)
7288 status = decode_destroy_clientid(xdr, res);
7289 return status;
7290}
7291
7292/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007293 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007294 */
Chuck Leverbf269552010-12-14 14:59:29 +00007295static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7296 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007297 void *res)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007298{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007299 struct compound_hdr hdr;
7300 int status;
7301
Chuck Leverbf269552010-12-14 14:59:29 +00007302 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007303 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007304 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007305 return status;
7306}
7307
7308/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007309 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007310 */
Chuck Leverbf269552010-12-14 14:59:29 +00007311static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7312 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007313 void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04007314{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007315 struct nfs4_get_lease_time_res *res = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04007316 struct compound_hdr hdr;
7317 int status;
7318
Chuck Leverbf269552010-12-14 14:59:29 +00007319 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007320 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007321 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007322 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007323 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007324 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007325 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007326 return status;
7327}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007328
7329/*
7330 * Decode RECLAIM_COMPLETE response
7331 */
Chuck Leverbf269552010-12-14 14:59:29 +00007332static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7333 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007334 void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05007335{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007336 struct nfs41_reclaim_complete_res *res = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05007337 struct compound_hdr hdr;
7338 int status;
7339
Chuck Leverbf269552010-12-14 14:59:29 +00007340 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007341 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007342 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007343 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307344 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007345 return status;
7346}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007347
7348/*
7349 * Decode GETDEVINFO response
7350 */
Chuck Leverbf269552010-12-14 14:59:29 +00007351static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7352 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007353 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007354{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007355 struct nfs4_getdeviceinfo_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007356 struct compound_hdr hdr;
7357 int status;
7358
Chuck Leverbf269552010-12-14 14:59:29 +00007359 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007360 if (status != 0)
7361 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007362 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007363 if (status != 0)
7364 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007365 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007366out:
7367 return status;
7368}
7369
7370/*
7371 * Decode LAYOUTGET response
7372 */
Chuck Leverbf269552010-12-14 14:59:29 +00007373static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7374 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007375 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007376{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007377 struct nfs4_layoutget_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007378 struct compound_hdr hdr;
7379 int status;
7380
Chuck Leverbf269552010-12-14 14:59:29 +00007381 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007382 if (status)
7383 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007384 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007385 if (status)
7386 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007387 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007388 if (status)
7389 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007390 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007391out:
7392 return status;
7393}
Andy Adamson863a3c62011-03-23 13:27:54 +00007394
7395/*
Benny Halevycbe82602011-05-22 19:52:37 +03007396 * Decode LAYOUTRETURN response
7397 */
7398static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7399 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007400 void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03007401{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007402 struct nfs4_layoutreturn_res *res = data;
Benny Halevycbe82602011-05-22 19:52:37 +03007403 struct compound_hdr hdr;
7404 int status;
7405
7406 status = decode_compound_hdr(xdr, &hdr);
7407 if (status)
7408 goto out;
7409 status = decode_sequence(xdr, &res->seq_res, rqstp);
7410 if (status)
7411 goto out;
7412 status = decode_putfh(xdr);
7413 if (status)
7414 goto out;
7415 status = decode_layoutreturn(xdr, res);
7416out:
7417 return status;
7418}
7419
7420/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007421 * Decode LAYOUTCOMMIT response
7422 */
7423static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7424 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007425 void *data)
Andy Adamson863a3c62011-03-23 13:27:54 +00007426{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007427 struct nfs4_layoutcommit_res *res = data;
Andy Adamson863a3c62011-03-23 13:27:54 +00007428 struct compound_hdr hdr;
7429 int status;
7430
7431 status = decode_compound_hdr(xdr, &hdr);
7432 if (status)
7433 goto out;
7434 status = decode_sequence(xdr, &res->seq_res, rqstp);
7435 if (status)
7436 goto out;
7437 status = decode_putfh(xdr);
7438 if (status)
7439 goto out;
7440 status = decode_layoutcommit(xdr, rqstp, res);
7441 if (status)
7442 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007443 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007444out:
7445 return status;
7446}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007447
7448/*
7449 * Decode SECINFO_NO_NAME response
7450 */
7451static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7452 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007453 void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007454{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007455 struct nfs4_secinfo_res *res = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007456 struct compound_hdr hdr;
7457 int status;
7458
7459 status = decode_compound_hdr(xdr, &hdr);
7460 if (status)
7461 goto out;
7462 status = decode_sequence(xdr, &res->seq_res, rqstp);
7463 if (status)
7464 goto out;
7465 status = decode_putrootfh(xdr);
7466 if (status)
7467 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007468 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007469out:
7470 return status;
7471}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007472
7473/*
7474 * Decode TEST_STATEID response
7475 */
7476static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7477 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007478 void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04007479{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007480 struct nfs41_test_stateid_res *res = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04007481 struct compound_hdr hdr;
7482 int status;
7483
7484 status = decode_compound_hdr(xdr, &hdr);
7485 if (status)
7486 goto out;
7487 status = decode_sequence(xdr, &res->seq_res, rqstp);
7488 if (status)
7489 goto out;
7490 status = decode_test_stateid(xdr, res);
7491out:
7492 return status;
7493}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007494
7495/*
7496 * Decode FREE_STATEID response
7497 */
7498static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7499 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007500 void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007501{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007502 struct nfs41_free_stateid_res *res = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007503 struct compound_hdr hdr;
7504 int status;
7505
7506 status = decode_compound_hdr(xdr, &hdr);
7507 if (status)
7508 goto out;
7509 status = decode_sequence(xdr, &res->seq_res, rqstp);
7510 if (status)
7511 goto out;
7512 status = decode_free_stateid(xdr, res);
7513out:
7514 return status;
7515}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007516#endif /* CONFIG_NFS_V4_1 */
7517
Chuck Lever573c4e12010-12-14 14:58:11 +00007518/**
7519 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7520 * the local page cache.
7521 * @xdr: XDR stream where entry resides
7522 * @entry: buffer to fill in with entry data
7523 * @plus: boolean indicating whether this should be a readdirplus entry
7524 *
7525 * Returns zero if successful, otherwise a negative errno value is
7526 * returned.
7527 *
7528 * This function is not invoked during READDIR reply decoding, but
7529 * rather whenever an application invokes the getdents(2) system call
7530 * on a directory already in our cache.
7531 */
7532int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -04007533 bool plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007534{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007535 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007536 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007537 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007538 __be32 *p = xdr_inline_decode(xdr, 4);
7539 if (unlikely(!p))
7540 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007541 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007542 p = xdr_inline_decode(xdr, 4);
7543 if (unlikely(!p))
7544 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007545 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007546 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007547 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007548 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007549 }
7550
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007551 p = xdr_inline_decode(xdr, 12);
7552 if (unlikely(!p))
7553 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007554 entry->prev_cookie = entry->cookie;
7555 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007556 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007557
Trond Myklebust9af8c222010-10-24 11:52:55 -04007558 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007559 if (unlikely(!p))
7560 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007561 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007562
7563 /*
7564 * In case the server doesn't return an inode number,
7565 * we fake one here. (We don't use inode number 0,
7566 * since glibc seems to choke on it...)
7567 */
7568 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007569 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007570
Trond Myklebust9af8c222010-10-24 11:52:55 -04007571 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007572 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007573
Trond Myklebust256e48b2012-06-21 11:18:13 -04007574 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007575 goto out_overflow;
7576
Chuck Lever573c4e12010-12-14 14:58:11 +00007577 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007578 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007579 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007580 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7581 entry->ino = entry->fattr->mounted_on_fileid;
7582 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007583 entry->ino = entry->fattr->fileid;
7584
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007585 entry->d_type = DT_UNKNOWN;
7586 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7587 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7588
Chuck Lever573c4e12010-12-14 14:58:11 +00007589 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007590
7591out_overflow:
7592 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007593 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007594}
7595
7596/*
7597 * We need to translate between nfs status return values and
7598 * the local errno values which may not be the same.
7599 */
7600static struct {
7601 int stat;
7602 int errno;
7603} nfs_errtbl[] = {
7604 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007605 { NFS4ERR_PERM, -EPERM },
7606 { NFS4ERR_NOENT, -ENOENT },
7607 { NFS4ERR_IO, -errno_NFSERR_IO},
7608 { NFS4ERR_NXIO, -ENXIO },
7609 { NFS4ERR_ACCESS, -EACCES },
7610 { NFS4ERR_EXIST, -EEXIST },
7611 { NFS4ERR_XDEV, -EXDEV },
7612 { NFS4ERR_NOTDIR, -ENOTDIR },
7613 { NFS4ERR_ISDIR, -EISDIR },
7614 { NFS4ERR_INVAL, -EINVAL },
7615 { NFS4ERR_FBIG, -EFBIG },
7616 { NFS4ERR_NOSPC, -ENOSPC },
7617 { NFS4ERR_ROFS, -EROFS },
7618 { NFS4ERR_MLINK, -EMLINK },
7619 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7620 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7621 { NFS4ERR_DQUOT, -EDQUOT },
7622 { NFS4ERR_STALE, -ESTALE },
7623 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007624 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7625 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7626 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007627 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007628 { NFS4ERR_BADTYPE, -EBADTYPE },
7629 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007630 { NFS4ERR_SYMLINK, -ELOOP },
7631 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7632 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007633 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007634};
7635
7636/*
7637 * Convert an NFS error code to a local one.
7638 * This one is used jointly by NFSv2 and NFSv3.
7639 */
7640static int
David Howells0a8ea432006-08-22 20:06:08 -04007641nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007642{
7643 int i;
7644 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7645 if (nfs_errtbl[i].stat == stat)
7646 return nfs_errtbl[i].errno;
7647 }
7648 if (stat <= 10000 || stat > 10100) {
7649 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007650 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007651 }
7652 /* If we cannot translate the error, the recovery routines should
7653 * handle it.
7654 * Note: remaining NFSv4 error codes have values > 10000, so should
7655 * not conflict with native Linux error codes.
7656 */
Benny Halevy856dff32008-03-31 17:39:06 +03007657 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007658}
7659
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007660#ifdef CONFIG_NFS_V4_2
7661#include "nfs42xdr.c"
7662#endif /* CONFIG_NFS_V4_2 */
7663
Linus Torvalds1da177e2005-04-16 15:20:36 -07007664#define PROC(proc, argtype, restype) \
7665[NFSPROC4_CLNT_##proc] = { \
7666 .p_proc = NFSPROC4_COMPOUND, \
Christoph Hellwigfcc85812017-05-08 10:01:49 +02007667 .p_encode = nfs4_xdr_##argtype, \
Christoph Hellwigfc016482017-05-08 15:09:02 +02007668 .p_decode = nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007669 .p_arglen = NFS4_##argtype##_sz, \
7670 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007671 .p_statidx = NFSPROC4_CLNT_##proc, \
7672 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007673}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007674
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007675#define STUB(proc) \
7676[NFSPROC4_CLNT_##proc] = { \
7677 .p_name = #proc, \
7678}
7679
Trond Myklebust8634ef52018-01-06 09:53:49 -05007680#if defined(CONFIG_NFS_V4_1)
7681#define PROC41(proc, argtype, restype) \
7682 PROC(proc, argtype, restype)
7683#else
7684#define PROC41(proc, argtype, restype) \
7685 STUB(proc)
7686#endif
7687
7688#if defined(CONFIG_NFS_V4_2)
7689#define PROC42(proc, argtype, restype) \
7690 PROC(proc, argtype, restype)
7691#else
7692#define PROC42(proc, argtype, restype) \
7693 STUB(proc)
7694#endif
7695
Christoph Hellwig511e9362017-05-12 15:36:49 +02007696const struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007697 PROC(READ, enc_read, dec_read),
7698 PROC(WRITE, enc_write, dec_write),
7699 PROC(COMMIT, enc_commit, dec_commit),
7700 PROC(OPEN, enc_open, dec_open),
7701 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7702 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7703 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7704 PROC(CLOSE, enc_close, dec_close),
7705 PROC(SETATTR, enc_setattr, dec_setattr),
7706 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7707 PROC(RENEW, enc_renew, dec_renew),
7708 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7709 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7710 PROC(LOCK, enc_lock, dec_lock),
7711 PROC(LOCKT, enc_lockt, dec_lockt),
7712 PROC(LOCKU, enc_locku, dec_locku),
7713 PROC(ACCESS, enc_access, dec_access),
7714 PROC(GETATTR, enc_getattr, dec_getattr),
7715 PROC(LOOKUP, enc_lookup, dec_lookup),
7716 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7717 PROC(REMOVE, enc_remove, dec_remove),
7718 PROC(RENAME, enc_rename, dec_rename),
7719 PROC(LINK, enc_link, dec_link),
7720 PROC(SYMLINK, enc_symlink, dec_symlink),
7721 PROC(CREATE, enc_create, dec_create),
7722 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7723 PROC(STATFS, enc_statfs, dec_statfs),
7724 PROC(READLINK, enc_readlink, dec_readlink),
7725 PROC(READDIR, enc_readdir, dec_readdir),
7726 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7727 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7728 PROC(GETACL, enc_getacl, dec_getacl),
7729 PROC(SETACL, enc_setacl, dec_setacl),
7730 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7731 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007732 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007733 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007734 PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7735 PROC41(CREATE_SESSION, enc_create_session, dec_create_session),
7736 PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7737 PROC41(SEQUENCE, enc_sequence, dec_sequence),
7738 PROC41(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7739 PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete),
7740 PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7741 PROC41(LAYOUTGET, enc_layoutget, dec_layoutget),
7742 PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7743 PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7744 PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7745 PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7746 PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007747 STUB(GETDEVICELIST),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007748 PROC41(BIND_CONN_TO_SESSION,
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007749 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007750 PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid),
7751 PROC42(SEEK, enc_seek, dec_seek),
7752 PROC42(ALLOCATE, enc_allocate, dec_allocate),
7753 PROC42(DEALLOCATE, enc_deallocate, dec_deallocate),
7754 PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
7755 PROC42(CLONE, enc_clone, dec_clone),
7756 PROC42(COPY, enc_copy, dec_copy),
7757 PROC(LOOKUPP, enc_lookupp, dec_lookupp),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007758};
7759
Christoph Hellwigc5518582017-05-08 23:27:10 +02007760static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
Trond Myklebusta613fa12012-01-20 13:53:56 -05007761const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007762 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007763 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Christoph Hellwigc5518582017-05-08 23:27:10 +02007764 .procs = nfs4_procedures,
7765 .counts = nfs_version4_counts,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007766};
7767
7768/*
7769 * Local variables:
7770 * c-basic-offset: 8
7771 * End:
7772 */