blob: 481426e9e6f05de893ace0eab80d94fa57ea04ca [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)
Trond Myklebust36b37432018-03-20 17:03:10 -0400101#define nfstime4_maxsz (3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
103#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400104#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
105#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
David Quigleyaa9c2662013-05-22 12:50:44 -0400106#ifdef CONFIG_NFS_V4_SECURITY_LABEL
107/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
108#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
David Quigleyaa9c2662013-05-22 12:50:44 -0400109#else
110#define nfs4_label_maxsz 0
David Quigleyaa9c2662013-05-22 12:50:44 -0400111#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400112/* We support only one layout type per file system */
113#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000114/* This is based on getfattr, which uses the most attributes: */
115#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebust36b37432018-03-20 17:03:10 -0400116 3*nfstime4_maxsz + \
117 nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400118 nfs4_group_maxsz + nfs4_label_maxsz + \
119 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000120#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
121 nfs4_fattr_value_maxsz)
122#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400123#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
124 1 + 2 + 1 + \
125 nfs4_owner_maxsz + \
126 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400127 nfs4_label_maxsz + \
Trond Myklebust36b37432018-03-20 17:03:10 -0400128 1 + nfstime4_maxsz + \
129 1 + nfstime4_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#define encode_savefh_maxsz (op_encode_hdr_maxsz)
131#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400132#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
133#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200134#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400135/* The 5 accounts for the PNFS attributes, and assumes that at most three
136 * layout types will be returned.
137 */
138#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
139 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
141#define decode_renew_maxsz (op_decode_hdr_maxsz)
142#define encode_setclientid_maxsz \
143 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500144 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400145 /* client name */ \
146 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500147 1 /* sc_prog */ + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500148 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
149 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500150 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#define decode_setclientid_maxsz \
152 (op_decode_hdr_maxsz + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500153 2 /* clientid */ + \
154 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
155 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
156 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157#define encode_setclientid_confirm_maxsz \
158 (op_encode_hdr_maxsz + \
159 3 + (NFS4_VERIFIER_SIZE >> 2))
160#define decode_setclientid_confirm_maxsz \
161 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400162#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
163#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700164#define encode_lookupp_maxsz (op_encode_hdr_maxsz)
165#define decode_lookupp_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400166#define encode_share_access_maxsz \
167 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500168#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400169#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
170#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
171#define encode_open_maxsz (op_encode_hdr_maxsz + \
172 2 + encode_share_access_maxsz + 2 + \
173 open_owner_id_maxsz + \
174 encode_opentype_maxsz + \
175 encode_claim_null_maxsz)
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500176#define decode_space_limit_maxsz (3)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400177#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400178#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500179 decode_space_limit_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400180 decode_ace_maxsz)
181#define decode_change_info_maxsz (5)
182#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400183 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400184 decode_change_info_maxsz + 1 + \
185 nfs4_fattr_bitmap_maxsz + \
186 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400187#define encode_open_confirm_maxsz \
188 (op_encode_hdr_maxsz + \
189 encode_stateid_maxsz + 1)
190#define decode_open_confirm_maxsz \
191 (op_decode_hdr_maxsz + \
192 decode_stateid_maxsz)
193#define encode_open_downgrade_maxsz \
194 (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + 1 + \
196 encode_share_access_maxsz)
197#define decode_open_downgrade_maxsz \
198 (op_decode_hdr_maxsz + \
199 decode_stateid_maxsz)
200#define encode_close_maxsz (op_encode_hdr_maxsz + \
201 1 + encode_stateid_maxsz)
202#define decode_close_maxsz (op_decode_hdr_maxsz + \
203 decode_stateid_maxsz)
204#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
205 encode_stateid_maxsz + \
206 encode_attrs_maxsz)
207#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
208 nfs4_fattr_bitmap_maxsz)
209#define encode_read_maxsz (op_encode_hdr_maxsz + \
210 encode_stateid_maxsz + 3)
211#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
212#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400213 2 + encode_verifier_maxsz + 5 + \
214 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400215#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Chuck Levera7697f62014-03-12 12:51:17 -0400216 decode_verifier_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400217#define encode_readlink_maxsz (op_encode_hdr_maxsz)
218#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
219#define encode_write_maxsz (op_encode_hdr_maxsz + \
220 encode_stateid_maxsz + 4)
221#define decode_write_maxsz (op_decode_hdr_maxsz + \
222 2 + decode_verifier_maxsz)
223#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
224#define decode_commit_maxsz (op_decode_hdr_maxsz + \
225 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#define encode_remove_maxsz (op_encode_hdr_maxsz + \
227 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400228#define decode_remove_maxsz (op_decode_hdr_maxsz + \
229 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230#define encode_rename_maxsz (op_encode_hdr_maxsz + \
231 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400232#define decode_rename_maxsz (op_decode_hdr_maxsz + \
233 decode_change_info_maxsz + \
234 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235#define encode_link_maxsz (op_encode_hdr_maxsz + \
236 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400237#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400238#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400239#define encode_lock_maxsz (op_encode_hdr_maxsz + \
240 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400241 1 + encode_stateid_maxsz + 1 + \
242 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400243#define decode_lock_denied_maxsz \
244 (8 + decode_lockowner_maxsz)
245#define decode_lock_maxsz (op_decode_hdr_maxsz + \
246 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400247#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
248 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400249#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
250 decode_lock_denied_maxsz)
251#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
252 encode_stateid_maxsz + \
253 4)
254#define decode_locku_maxsz (op_decode_hdr_maxsz + \
255 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400256#define encode_release_lockowner_maxsz \
257 (op_encode_hdr_maxsz + \
258 encode_lockowner_maxsz)
259#define decode_release_lockowner_maxsz \
260 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400261#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
262#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
264 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400265 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000266 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
268#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400269 1 + 2 + nfs4_name_maxsz + \
270 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400271#define decode_create_maxsz (op_decode_hdr_maxsz + \
272 decode_change_info_maxsz + \
273 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400274#define encode_statfs_maxsz (encode_getattr_maxsz)
275#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
277#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400278#define encode_getacl_maxsz (encode_getattr_maxsz)
279#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
280 nfs4_fattr_bitmap_maxsz + 1)
281#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
282 encode_stateid_maxsz + 3)
283#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400284#define encode_fs_locations_maxsz \
285 (encode_getattr_maxsz)
286#define decode_fs_locations_maxsz \
287 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000288#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400289#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 -0400290
291#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400292#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500293#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
294 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400295
Benny Halevy99fe60d2009-04-01 09:22:29 -0400296#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
297 encode_verifier_maxsz + \
298 1 /* co_ownerid.len */ + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400299 /* eia_clientowner */ \
300 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400301 1 /* flags */ + \
302 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400303 /* max is SP4_MACH_CRED (for now) */ + \
304 1 + NFS4_OP_MAP_NUM_WORDS + \
305 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500306 1 /* implementation id array of size 1 */ + \
307 1 /* nii_domain */ + \
308 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
309 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500310 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500311 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400312#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
313 2 /* eir_clientid */ + \
314 1 /* eir_sequenceid */ + \
315 1 /* eir_flags */ + \
316 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400317 /* max is SP4_MACH_CRED (for now) */ + \
318 1 + NFS4_OP_MAP_NUM_WORDS + \
319 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400320 2 /* eir_server_owner.so_minor_id */ + \
321 /* eir_server_owner.so_major_id<> */ \
322 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
323 /* eir_server_scope<> */ \
324 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
325 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500326 1 /* nii_domain */ + \
327 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
328 1 /* nii_name */ + \
329 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
330 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400331#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
332#define decode_channel_attrs_maxsz (6 + \
333 1 /* ca_rdma_ird.len */ + \
334 1 /* ca_rdma_ird */)
335#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
336 2 /* csa_clientid */ + \
337 1 /* csa_sequence */ + \
338 1 /* csa_flags */ + \
339 encode_channel_attrs_maxsz + \
340 encode_channel_attrs_maxsz + \
341 1 /* csa_cb_program */ + \
342 1 /* csa_sec_parms.len (1) */ + \
343 1 /* cb_secflavor (AUTH_SYS) */ + \
344 1 /* stamp */ + \
345 1 /* machinename.len */ + \
346 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
347 1 /* uid */ + \
348 1 /* gid */ + \
349 1 /* gids.len (0) */)
350#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
351 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
352 1 /* csr_sequence */ + \
353 1 /* csr_flags */ + \
354 decode_channel_attrs_maxsz + \
355 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400356#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
357 /* bctsa_sessid */ \
358 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
359 1 /* bctsa_dir */ + \
360 1 /* bctsa_use_conn_in_rdma_mode */)
361#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
362 /* bctsr_sessid */ \
363 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
364 1 /* bctsr_dir */ + \
365 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400366#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
367#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400368#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
369#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400370#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
371 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
372#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
373 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500374#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
375#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700376#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
377 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
378 1 /* layout type */ + \
379 1 /* maxcount */ + \
380 1 /* bitmap size */ + \
381 1 /* notification bitmap length */ + \
382 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400383#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
384 1 /* layout type */ + \
385 1 /* opaque devaddr4 length */ + \
386 /* devaddr4 payload is read into page */ \
387 1 /* notification bitmap length */ + \
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700388 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400389#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
390 encode_stateid_maxsz)
391#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
392 decode_stateid_maxsz + \
393 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000394#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
395 2 /* offset */ + \
396 2 /* length */ + \
397 1 /* reclaim */ + \
398 encode_stateid_maxsz + \
399 1 /* new offset (true) */ + \
400 2 /* last byte written */ + \
401 1 /* nt_timechanged (false) */ + \
402 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500403 1 /* layoutupdate4 opaqueue len */)
404 /* the actual content of layoutupdate4 should
405 be allocated by drivers and spliced in
406 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000407#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300408#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
409 encode_stateid_maxsz + \
Trond Myklebust6669cb82015-08-27 20:43:20 -0400410 1 + \
411 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
Benny Halevycbe82602011-05-22 19:52:37 +0300412#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
413 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400414#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
415#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400416#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
417 XDR_QUADLEN(NFS4_STATEID_SIZE))
418#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400419#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
420 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400421#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422#else /* CONFIG_NFS_V4_1 */
423#define encode_sequence_maxsz 0
424#define decode_sequence_maxsz 0
Trond Myklebustcf805162016-11-15 14:56:07 -0500425#define encode_layoutreturn_maxsz 0
426#define decode_layoutreturn_maxsz 0
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427#endif /* CONFIG_NFS_V4_1 */
428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
430#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
431#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400434 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400436 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400438 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400440 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400442 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400444 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400446 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400448 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400450 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400452 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400454 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400456 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400458 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400459 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400461 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400463 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400464 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400466 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400468 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400470 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400472 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400474 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400475 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400477 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400478 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400479 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400481 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400482 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400483 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400484 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400485 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400486 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400487#define NFS4_enc_open_confirm_sz \
488 (compound_encode_hdr_maxsz + \
489 encode_putfh_maxsz + \
490 encode_open_confirm_maxsz)
491#define NFS4_dec_open_confirm_sz \
492 (compound_decode_hdr_maxsz + \
493 decode_putfh_maxsz + \
494 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400498 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400499 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400500 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400502 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400504 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400505 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400506 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#define NFS4_enc_open_downgrade_sz \
508 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400509 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400510 encode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500511 encode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400512 encode_open_downgrade_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513#define NFS4_dec_open_downgrade_sz \
514 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400515 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400516 decode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500517 decode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400518 decode_open_downgrade_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400519#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400521 encode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500522 encode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400523 encode_close_maxsz + \
524 encode_getattr_maxsz)
525#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400526 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400527 decode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500528 decode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400529 decode_close_maxsz + \
530 decode_getattr_maxsz)
531#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400532 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400533 encode_putfh_maxsz + \
534 encode_setattr_maxsz + \
535 encode_getattr_maxsz)
536#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400537 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400538 decode_putfh_maxsz + \
539 decode_setattr_maxsz + \
540 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 encode_putfh_maxsz + \
544 encode_fsinfo_maxsz)
545#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 decode_putfh_maxsz + \
548 decode_fsinfo_maxsz)
549#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
550 encode_renew_maxsz)
551#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
552 decode_renew_maxsz)
553#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
554 encode_setclientid_maxsz)
555#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
556 decode_setclientid_maxsz)
557#define NFS4_enc_setclientid_confirm_sz \
558 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400559 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#define NFS4_dec_setclientid_confirm_sz \
561 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400562 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400566 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400570 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400574 encode_lockt_maxsz)
575#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400576 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400577 decode_putfh_maxsz + \
578 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400582 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400584 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400586 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400587#define NFS4_enc_release_lockowner_sz \
588 (compound_encode_hdr_maxsz + \
589 encode_lockowner_maxsz)
590#define NFS4_dec_release_lockowner_sz \
591 (compound_decode_hdr_maxsz + \
592 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400594 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400596 encode_access_maxsz + \
597 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400599 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400601 decode_access_maxsz + \
602 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400604 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400606 encode_getattr_maxsz + \
607 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400609 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400611 decode_getattr_maxsz + \
612 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400614 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 encode_putfh_maxsz + \
616 encode_lookup_maxsz + \
617 encode_getattr_maxsz + \
618 encode_getfh_maxsz)
619#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400620 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400622 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 decode_getattr_maxsz + \
624 decode_getfh_maxsz)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700625#define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \
626 encode_sequence_maxsz + \
627 encode_putfh_maxsz + \
628 encode_lookupp_maxsz + \
629 encode_getattr_maxsz + \
630 encode_getfh_maxsz)
631#define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \
632 decode_sequence_maxsz + \
633 decode_putfh_maxsz + \
634 decode_lookupp_maxsz + \
635 decode_getattr_maxsz + \
636 decode_getfh_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400638 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 encode_putrootfh_maxsz + \
640 encode_getattr_maxsz + \
641 encode_getfh_maxsz)
642#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400643 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 decode_putrootfh_maxsz + \
645 decode_getattr_maxsz + \
646 decode_getfh_maxsz)
647#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400650 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400652 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400654 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400656 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 encode_putfh_maxsz + \
658 encode_savefh_maxsz + \
659 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400660 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400662 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 decode_putfh_maxsz + \
664 decode_savefh_maxsz + \
665 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400666 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400668 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 encode_putfh_maxsz + \
670 encode_savefh_maxsz + \
671 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400672 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400673 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400674 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 decode_putfh_maxsz + \
678 decode_savefh_maxsz + \
679 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400680 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400681 decode_restorefh_maxsz + \
682 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 encode_putfh_maxsz + \
686 encode_symlink_maxsz + \
687 encode_getattr_maxsz + \
688 encode_getfh_maxsz)
689#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400690 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 decode_putfh_maxsz + \
692 decode_symlink_maxsz + \
693 decode_getattr_maxsz + \
694 decode_getfh_maxsz)
695#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 encode_putfh_maxsz + \
698 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400699 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400700 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400702 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 decode_putfh_maxsz + \
704 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400705 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400706 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400708 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 encode_putfh_maxsz + \
710 encode_getattr_maxsz)
711#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400712 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 decode_putfh_maxsz + \
714 decode_getattr_maxsz)
715#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400716 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400718 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400720 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400722 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400724 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800725 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 encode_getattr_maxsz)
727#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400728 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800729 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 decode_getattr_maxsz)
731#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400732 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 encode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500734 encode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100735 encode_delegreturn_maxsz + \
736 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400738 decode_sequence_maxsz + \
Trond Myklebustd8434d4c2016-11-16 13:54:00 -0500739 decode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500740 decode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100741 decode_delegreturn_maxsz + \
742 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000743#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400744 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000745 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400746 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000747#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400748 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000749 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400750 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000751#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400752 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000753 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400754 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000755#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400756 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000757 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400758 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400759#define NFS4_enc_fs_locations_sz \
760 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400761 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400762 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400763 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400764 encode_fs_locations_maxsz + \
765 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400766#define NFS4_dec_fs_locations_sz \
767 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400768 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400769 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400770 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400771 decode_fs_locations_maxsz + \
772 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000773#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
774 encode_sequence_maxsz + \
775 encode_putfh_maxsz + \
776 encode_secinfo_maxsz)
777#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
778 decode_sequence_maxsz + \
779 decode_putfh_maxsz + \
780 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400781#define NFS4_enc_fsid_present_sz \
782 (compound_encode_hdr_maxsz + \
783 encode_sequence_maxsz + \
784 encode_putfh_maxsz + \
785 encode_getfh_maxsz + \
786 encode_renew_maxsz)
787#define NFS4_dec_fsid_present_sz \
788 (compound_decode_hdr_maxsz + \
789 decode_sequence_maxsz + \
790 decode_putfh_maxsz + \
791 decode_getfh_maxsz + \
792 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400793#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400794#define NFS4_enc_bind_conn_to_session_sz \
795 (compound_encode_hdr_maxsz + \
796 encode_bind_conn_to_session_maxsz)
797#define NFS4_dec_bind_conn_to_session_sz \
798 (compound_decode_hdr_maxsz + \
799 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400800#define NFS4_enc_exchange_id_sz \
801 (compound_encode_hdr_maxsz + \
802 encode_exchange_id_maxsz)
803#define NFS4_dec_exchange_id_sz \
804 (compound_decode_hdr_maxsz + \
805 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400806#define NFS4_enc_create_session_sz \
807 (compound_encode_hdr_maxsz + \
808 encode_create_session_maxsz)
809#define NFS4_dec_create_session_sz \
810 (compound_decode_hdr_maxsz + \
811 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400812#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
813 encode_destroy_session_maxsz)
814#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
815 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400816#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
817 encode_destroy_clientid_maxsz)
818#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
819 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400820#define NFS4_enc_sequence_sz \
821 (compound_decode_hdr_maxsz + \
822 encode_sequence_maxsz)
823#define NFS4_dec_sequence_sz \
824 (compound_decode_hdr_maxsz + \
825 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400826#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
827 encode_sequence_maxsz + \
828 encode_putrootfh_maxsz + \
829 encode_fsinfo_maxsz)
830#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
831 decode_sequence_maxsz + \
832 decode_putrootfh_maxsz + \
833 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500834#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
835 encode_sequence_maxsz + \
836 encode_reclaim_complete_maxsz)
837#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
838 decode_sequence_maxsz + \
839 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400840#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
841 encode_sequence_maxsz +\
842 encode_getdeviceinfo_maxsz)
843#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
844 decode_sequence_maxsz + \
845 decode_getdeviceinfo_maxsz)
846#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
847 encode_sequence_maxsz + \
848 encode_putfh_maxsz + \
849 encode_layoutget_maxsz)
850#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
851 decode_sequence_maxsz + \
852 decode_putfh_maxsz + \
853 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000854#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
855 encode_sequence_maxsz +\
856 encode_putfh_maxsz + \
857 encode_layoutcommit_maxsz + \
858 encode_getattr_maxsz)
859#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
860 decode_sequence_maxsz + \
861 decode_putfh_maxsz + \
862 decode_layoutcommit_maxsz + \
863 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300864#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
865 encode_sequence_maxsz + \
866 encode_putfh_maxsz + \
867 encode_layoutreturn_maxsz)
868#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
869 decode_sequence_maxsz + \
870 decode_putfh_maxsz + \
871 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400872#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
873 encode_sequence_maxsz + \
874 encode_putrootfh_maxsz +\
875 encode_secinfo_no_name_maxsz)
876#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
877 decode_sequence_maxsz + \
878 decode_putrootfh_maxsz + \
879 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400880#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
881 encode_sequence_maxsz + \
882 encode_test_stateid_maxsz)
883#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
884 decode_sequence_maxsz + \
885 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400886#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
887 encode_sequence_maxsz + \
888 encode_free_stateid_maxsz)
889#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
890 decode_sequence_maxsz + \
891 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500892
893const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
894 compound_encode_hdr_maxsz +
895 encode_sequence_maxsz +
896 encode_putfh_maxsz +
897 encode_getattr_maxsz) *
898 XDR_UNIT);
899
900const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
901 compound_decode_hdr_maxsz +
902 decode_sequence_maxsz +
903 decode_putfh_maxsz) *
904 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400905
906const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
907 compound_decode_hdr_maxsz +
908 decode_sequence_maxsz) *
909 XDR_UNIT);
910EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400911#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Trond Myklebustbca79472009-03-11 14:10:26 -0400913static const umode_t nfs_type2fmt[] = {
914 [NF4BAD] = 0,
915 [NF4REG] = S_IFREG,
916 [NF4DIR] = S_IFDIR,
917 [NF4BLK] = S_IFBLK,
918 [NF4CHR] = S_IFCHR,
919 [NF4LNK] = S_IFLNK,
920 [NF4SOCK] = S_IFSOCK,
921 [NF4FIFO] = S_IFIFO,
922 [NF4ATTRDIR] = 0,
923 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924};
925
926struct compound_hdr {
927 int32_t status;
928 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500929 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 uint32_t taglen;
931 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400932 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400933 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934};
935
Benny Halevy13c65ce2009-08-14 17:19:25 +0300936static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
937{
938 __be32 *p = xdr_reserve_space(xdr, nbytes);
939 BUG_ON(!p);
940 return p;
941}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
Trond Myklebustcb17e552012-03-04 18:13:56 -0500943static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
944{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500945 WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
Trond Myklebustcb17e552012-03-04 18:13:56 -0500946}
947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
949{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500950 WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951}
952
Trond Myklebust4ade9822012-03-04 18:13:57 -0500953static void encode_uint32(struct xdr_stream *xdr, u32 n)
954{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500955 WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500956}
957
Trond Myklebustff2eb682012-03-05 11:40:12 -0500958static void encode_uint64(struct xdr_stream *xdr, u64 n)
959{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500960 WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
Trond Myklebustff2eb682012-03-05 11:40:12 -0500961}
962
Trond Myklebust37c88762018-03-20 17:03:08 -0400963static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
964 const __u32 *bitmap, size_t len)
965{
966 ssize_t ret;
967
968 /* Trim empty words */
969 while (len > 0 && bitmap[len-1] == 0)
970 len--;
971 ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
972 if (WARN_ON_ONCE(ret < 0))
973 return ret;
974 return len;
975}
976
977static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
978 __u32 *res, size_t len)
979{
980 size_t i;
981 __u32 tmp;
982
983 while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
984 len--;
985 for (i = len; i-- > 0;) {
986 tmp = bitmap[i] & mask[i];
987 res[i] = tmp;
988 }
989 return len;
990}
991
Trond Myklebust4ade9822012-03-04 18:13:57 -0500992static void encode_nfs4_seqid(struct xdr_stream *xdr,
993 const struct nfs_seqid *seqid)
994{
Trond Myklebusta6796412015-01-23 19:04:44 -0500995 if (seqid != NULL)
996 encode_uint32(xdr, seqid->sequence->counter);
997 else
998 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500999}
1000
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001001static void encode_compound_hdr(struct xdr_stream *xdr,
1002 struct rpc_rqst *req,
1003 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004{
Al Viro8687b632006-10-19 23:28:48 -07001005 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -04001006 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001007
1008 /* initialize running count of expected bytes in reply.
1009 * NOTE: the replied tag SHOULD be the same is the one sent,
1010 * but this is not required as a MUST for the server to do so. */
1011 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Trond Myklebust7fc38842012-10-15 11:51:21 -04001013 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001014 encode_string(xdr, hdr->taglen, hdr->tag);
1015 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001016 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -05001017 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +03001018 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -05001019}
1020
Trond Myklebustab19b482012-03-04 18:13:57 -05001021static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
1022 uint32_t replen,
1023 struct compound_hdr *hdr)
1024{
1025 encode_uint32(xdr, op);
1026 hdr->nops++;
1027 hdr->replen += replen;
1028}
1029
Andy Adamsond0179312008-12-23 16:06:17 -05001030static void encode_nops(struct compound_hdr *hdr)
1031{
Trond Myklebust7fc38842012-10-15 11:51:21 -04001032 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -05001033 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034}
1035
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001036static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1037{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001038 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001039}
1040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1042{
Trond Myklebustcb17e552012-03-04 18:13:56 -05001043 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044}
1045
Trond Myklebust36b37432018-03-20 17:03:10 -04001046static __be32 *
1047xdr_encode_nfstime4(__be32 *p, const struct timespec *t)
1048{
1049 p = xdr_encode_hyper(p, (__s64)t->tv_sec);
1050 *p++ = cpu_to_be32(t->tv_nsec);
1051 return p;
1052}
1053
David Quigleyaa9c2662013-05-22 12:50:44 -04001054static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1055 const struct nfs4_label *label,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001056 const umode_t *umask,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001057 const struct nfs_server *server,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001058 const uint32_t attrmask[])
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059{
Deepa Dinamani95582b02018-05-08 19:36:02 -07001060 struct timespec ts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 char owner_name[IDMAP_NAMESZ];
1062 char owner_group[IDMAP_NAMESZ];
1063 int owner_namelen = 0;
1064 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001065 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001066 uint32_t len = 0;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001067 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
1069 /*
1070 * We reserve enough space to write the entire attribute buffer at once.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 */
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001072 if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001073 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001075 }
1076 if (iap->ia_valid & ATTR_MODE) {
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001077 if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001078 bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1079 len += 8;
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001080 } else if (attrmask[1] & FATTR4_WORD1_MODE) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001081 bmval[1] |= FATTR4_WORD1_MODE;
1082 len += 4;
1083 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001084 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001085 if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001086 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001088 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001089 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 /* XXX */
1091 strcpy(owner_name, "nobody");
1092 owner_namelen = sizeof("nobody") - 1;
1093 /* goto out; */
1094 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001095 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1097 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001098 if ((iap->ia_valid & ATTR_GID) &&
1099 (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001100 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001102 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001103 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 strcpy(owner_group, "nobody");
1105 owner_grouplen = sizeof("nobody") - 1;
1106 /* goto out; */
1107 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001108 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1110 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001111 if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1112 if (iap->ia_valid & ATTR_ATIME_SET) {
1113 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
Trond Myklebust36b37432018-03-20 17:03:10 -04001114 len += 4 + (nfstime4_maxsz << 2);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001115 } else if (iap->ia_valid & ATTR_ATIME) {
1116 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1117 len += 4;
1118 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001120 if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1121 if (iap->ia_valid & ATTR_MTIME_SET) {
1122 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
Trond Myklebust36b37432018-03-20 17:03:10 -04001123 len += 4 + (nfstime4_maxsz << 2);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001124 } else if (iap->ia_valid & ATTR_MTIME) {
1125 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1126 len += 4;
1127 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001129
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001130 if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001131 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1132 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1133 }
1134
Trond Myklebust40a3426c2018-03-20 17:03:09 -04001135 xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
1136 xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001137
1138 if (bmval[0] & FATTR4_WORD0_SIZE)
1139 p = xdr_encode_hyper(p, iap->ia_size);
1140 if (bmval[1] & FATTR4_WORD1_MODE)
1141 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1142 if (bmval[1] & FATTR4_WORD1_OWNER)
1143 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1144 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1145 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1146 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1147 if (iap->ia_valid & ATTR_ATIME_SET) {
1148 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Deepa Dinamani95582b02018-05-08 19:36:02 -07001149 ts = timespec64_to_timespec(iap->ia_atime);
1150 p = xdr_encode_nfstime4(p, &ts);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001151 } else
1152 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1153 }
1154 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1155 if (iap->ia_valid & ATTR_MTIME_SET) {
1156 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Deepa Dinamani95582b02018-05-08 19:36:02 -07001157 ts = timespec64_to_timespec(iap->ia_mtime);
1158 p = xdr_encode_nfstime4(p, &ts);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001159 } else
1160 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1161 }
1162 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001163 *p++ = cpu_to_be32(label->lfs);
1164 *p++ = cpu_to_be32(label->pi);
1165 *p++ = cpu_to_be32(label->len);
1166 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1167 }
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001168 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1169 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1170 *p++ = cpu_to_be32(*umask);
1171 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001172
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174}
1175
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001176static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001178 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1179 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180}
1181
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001182static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183{
Trond Myklebustab19b482012-03-04 18:13:57 -05001184 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001185 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001186 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187}
1188
Fred Isaman0b7c0152012-04-20 14:47:39 -04001189static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190{
Al Viro8687b632006-10-19 23:28:48 -07001191 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001192
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001193 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1194 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001195 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001196 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197}
1198
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001199static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200{
Al Viro8687b632006-10-19 23:28:48 -07001201 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001202
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001203 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1204 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
1206 switch (create->ftype) {
1207 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001208 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001209 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001210 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1211 create->u.symlink.len);
1212 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 break;
1214
1215 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001216 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001217 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001218 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 break;
1220
1221 default:
1222 break;
1223 }
1224
Benny Halevy811652b2009-08-14 17:19:34 +03001225 encode_string(xdr, create->name->len, create->name->name);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001226 encode_attrs(xdr, create->attrs, create->label, &create->umask,
1227 create->server, create->server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228}
1229
Trond Myklebust37c88762018-03-20 17:03:08 -04001230static void encode_getattr(struct xdr_stream *xdr,
1231 const __u32 *bitmap, const __u32 *mask, size_t len,
1232 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233{
Trond Myklebust37c88762018-03-20 17:03:08 -04001234 __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001236 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04001237 if (mask) {
1238 if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
1239 len = ARRAY_SIZE(masked_bitmap);
1240 len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
1241 bitmap = masked_bitmap;
Fred Isamandae100c2011-07-30 20:52:37 -04001242 }
Trond Myklebust37c88762018-03-20 17:03:08 -04001243 xdr_encode_bitmap4(xdr, bitmap, len);
Fred Isamandae100c2011-07-30 20:52:37 -04001244}
1245
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001246static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247{
Trond Myklebust37c88762018-03-20 17:03:08 -04001248 encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
1249 ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250}
1251
Andy Adamson88034c32012-05-23 05:02:34 -04001252static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001253 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001254 struct compound_hdr *hdr)
1255{
Trond Myklebust37c88762018-03-20 17:03:08 -04001256 encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
Andy Adamson88034c32012-05-23 05:02:34 -04001257}
1258
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001259static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260{
Trond Myklebust37c88762018-03-20 17:03:08 -04001261 encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
1262 ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263}
1264
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001265static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001266{
Trond Myklebust37c88762018-03-20 17:03:08 -04001267 encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
1268 ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001269}
1270
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001271static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272{
Trond Myklebustab19b482012-03-04 18:13:57 -05001273 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274}
1275
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001276static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277{
Trond Myklebustab19b482012-03-04 18:13:57 -05001278 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001279 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280}
1281
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001282static inline int nfs4_lock_type(struct file_lock *fl, int block)
1283{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001284 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001285 return block ? NFS4_READW_LT : NFS4_READ_LT;
1286 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1287}
1288
1289static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1290{
1291 if (fl->fl_end == OFFSET_MAX)
1292 return ~(uint64_t)0;
1293 return fl->fl_end - fl->fl_start + 1;
1294}
1295
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001296static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1297{
1298 __be32 *p;
1299
Trond Myklebustd035c362010-12-21 10:45:27 -05001300 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001301 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001302 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001303 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001304 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001305 xdr_encode_hyper(p, lowner->id);
1306}
1307
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308/*
1309 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1310 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1311 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001312static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313{
Al Viro8687b632006-10-19 23:28:48 -07001314 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001316 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1317 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001318 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1319 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001320 p = xdr_encode_hyper(p, args->fl->fl_start);
1321 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001322 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001323 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001324 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001325 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001326 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001327 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 }
1329 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001330 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001331 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333}
1334
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001335static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336{
Al Viro8687b632006-10-19 23:28:48 -07001337 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001339 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1340 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001341 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001342 p = xdr_encode_hyper(p, args->fl->fl_start);
1343 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001344 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345}
1346
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001347static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_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_LOCKU, decode_locku_maxsz, hdr);
1352 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001353 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001354 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001355 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001356 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001357 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358}
1359
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001360static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1361{
Trond Myklebustab19b482012-03-04 18:13:57 -05001362 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001363 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001364}
1365
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001366static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367{
Trond Myklebustab19b482012-03-04 18:13:57 -05001368 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001369 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370}
1371
Jeff Layton5b5faaf2017-06-29 06:34:52 -07001372static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
1373{
1374 encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
1375}
1376
Trond Myklebust6ae37332015-01-30 14:21:14 -05001377static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
Al Viro8687b632006-10-19 23:28:48 -07001379 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Benny Halevy13c65ce2009-08-14 17:19:25 +03001381 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001382 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001383 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384}
1385
1386static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1387{
Al Viro8687b632006-10-19 23:28:48 -07001388 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 /*
1390 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1391 * owner 4 = 32
1392 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001393 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001394 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001395 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001396 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001397 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001398 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001399 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001400 *p++ = cpu_to_be32(arg->id.uniquifier);
1401 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402}
1403
1404static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1405{
Al Viro8687b632006-10-19 23:28:48 -07001406 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
Benny Halevy13c65ce2009-08-14 17:19:25 +03001408 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001409 switch(arg->createmode) {
1410 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001411 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001412 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1413 arg->server, arg->server->attr_bitmask);
Andy Adamson05d564f2008-12-23 16:06:15 -05001414 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001415 case NFS4_CREATE_GUARDED:
1416 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001417 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1418 arg->server, arg->server->attr_bitmask);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001419 break;
1420 case NFS4_CREATE_EXCLUSIVE:
1421 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1422 encode_nfs4_verifier(xdr, &arg->u.verifier);
1423 break;
1424 case NFS4_CREATE_EXCLUSIVE4_1:
1425 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1426 encode_nfs4_verifier(xdr, &arg->u.verifier);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001427 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1428 arg->server, arg->server->exclcreat_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 }
1430}
1431
1432static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1433{
Al Viro8687b632006-10-19 23:28:48 -07001434 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Benny Halevy13c65ce2009-08-14 17:19:25 +03001436 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001438 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001439 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001440 break;
1441 default:
Benny Halevy34558512009-08-14 17:19:30 +03001442 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001443 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 }
1445}
1446
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001447static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448{
Al Viro8687b632006-10-19 23:28:48 -07001449 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Benny Halevy13c65ce2009-08-14 17:19:25 +03001451 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001453 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001454 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001455 break;
1456 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001457 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001458 break;
1459 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001460 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001461 break;
1462 default:
1463 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 }
1465}
1466
1467static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1468{
Al Viro8687b632006-10-19 23:28:48 -07001469 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470
Benny Halevy13c65ce2009-08-14 17:19:25 +03001471 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001472 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 encode_string(xdr, name->len, name->name);
1474}
1475
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001476static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477{
Al Viro8687b632006-10-19 23:28:48 -07001478 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Benny Halevy13c65ce2009-08-14 17:19:25 +03001480 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001481 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 encode_delegation_type(xdr, type);
1483}
1484
1485static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1486{
Al Viro8687b632006-10-19 23:28:48 -07001487 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001489 p = reserve_space(xdr, 4);
1490 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1491 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 encode_string(xdr, name->len, name->name);
1493}
1494
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001495static inline void encode_claim_fh(struct xdr_stream *xdr)
1496{
1497 __be32 *p;
1498
1499 p = reserve_space(xdr, 4);
1500 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1501}
1502
1503static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1504{
1505 __be32 *p;
1506
1507 p = reserve_space(xdr, 4);
1508 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1509 encode_nfs4_stateid(xdr, stateid);
1510}
1511
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001512static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513{
Trond Myklebustab19b482012-03-04 18:13:57 -05001514 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 encode_openhdr(xdr, arg);
1516 encode_opentype(xdr, arg);
1517 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001518 case NFS4_OPEN_CLAIM_NULL:
1519 encode_claim_null(xdr, arg->name);
1520 break;
1521 case NFS4_OPEN_CLAIM_PREVIOUS:
1522 encode_claim_previous(xdr, arg->u.delegation_type);
1523 break;
1524 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1525 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1526 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001527 case NFS4_OPEN_CLAIM_FH:
1528 encode_claim_fh(xdr);
1529 break;
1530 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1531 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1532 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001533 default:
1534 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536}
1537
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001538static 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 -07001539{
Trond Myklebustab19b482012-03-04 18:13:57 -05001540 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001541 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001542 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543}
1544
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001545static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546{
Trond Myklebustab19b482012-03-04 18:13:57 -05001547 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001548 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001549 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001550 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551}
1552
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001553static void
Andy Adamsond0179312008-12-23 16:06:17 -05001554encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555{
Trond Myklebustab19b482012-03-04 18:13:57 -05001556 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001557 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558}
1559
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001560static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
Trond Myklebustab19b482012-03-04 18:13:57 -05001562 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563}
1564
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001565static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1566 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567{
Al Viro8687b632006-10-19 23:28:48 -07001568 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
Trond Myklebustab19b482012-03-04 18:13:57 -05001570 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001571 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
Benny Halevy13c65ce2009-08-14 17:19:25 +03001573 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001574 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001575 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
1577
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001578static 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 -07001579{
David Quigleyaa9c2662013-05-22 12:50:44 -04001580 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001581 FATTR4_WORD0_RDATTR_ERROR,
1582 FATTR4_WORD1_MOUNTED_ON_FILEID,
1583 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001584 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001585 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001586 uint32_t attrlen = 0;
1587 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001589 if (readdir->plus) {
1590 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001591 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001592 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1593 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1594 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1595 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001596 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001597 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001598 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001599 /* Use mounted_on_fileid only if the server supports it */
1600 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1601 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001602 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1603 attrs[i] &= readdir->bitmask[i];
1604 if (attrs[i] != 0)
1605 attrlen = i+1;
1606 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001607
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001608 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001609 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001610 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001611 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001612 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001613 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001614 *p++ = cpu_to_be32(attrlen);
1615 for (i = 0; i < attrlen; i++)
1616 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001617 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001618
1619 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001620 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001621 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001622 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001623 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001624 attrs[1] & readdir->bitmask[1],
1625 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626}
1627
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001628static 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 -07001629{
Trond Myklebustab19b482012-03-04 18:13:57 -05001630 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631}
1632
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001633static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634{
Trond Myklebustab19b482012-03-04 18:13:57 -05001635 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001636 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637}
1638
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001639static 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 -07001640{
Trond Myklebustab19b482012-03-04 18:13:57 -05001641 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001642 encode_string(xdr, oldname->len, oldname->name);
1643 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644}
1645
Chuck Leverbb4dae52012-03-01 17:01:48 -05001646static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1647 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001649 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001650 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651}
1652
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001653static void
Andy Adamsond0179312008-12-23 16:06:17 -05001654encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001655{
Trond Myklebustab19b482012-03-04 18:13:57 -05001656 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001657}
1658
Chuck Lever9f06c712010-12-14 14:59:18 +00001659static void
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001660encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1661 struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001662{
Al Viro8687b632006-10-19 23:28:48 -07001663 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001664
Trond Myklebustab19b482012-03-04 18:13:57 -05001665 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001666 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001667 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001668 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001669 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001670 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001671 *p = cpu_to_be32(arg->acl_len);
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01001672 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001673}
1674
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001675static void
Andy Adamsond0179312008-12-23 16:06:17 -05001676encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677{
Trond Myklebustab19b482012-03-04 18:13:57 -05001678 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679}
1680
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001681static 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 -07001682{
Trond Myklebustab19b482012-03-04 18:13:57 -05001683 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001684 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001685 encode_attrs(xdr, arg->iap, arg->label, NULL, server,
1686 server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687}
1688
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001689static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690{
Al Viro8687b632006-10-19 23:28:48 -07001691 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
Trond Myklebust70019512012-03-04 20:49:32 -05001693 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001694 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
Jeff Layton3a6bb732015-06-09 19:43:57 -04001696 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1697 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001698 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001699 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1701 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001702 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001703 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704}
1705
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001706static 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 -07001707{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001708 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1709 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001710 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001711 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712}
1713
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001714static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1715 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716{
Al Viro8687b632006-10-19 23:28:48 -07001717 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718
Trond Myklebustab19b482012-03-04 18:13:57 -05001719 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001720 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
Benny Halevy13c65ce2009-08-14 17:19:25 +03001722 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001723 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001724 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001725 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
1727 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728}
1729
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001730static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731{
Trond Myklebustab19b482012-03-04 18:13:57 -05001732 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001733 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001735
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001736static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1737{
Trond Myklebustab19b482012-03-04 18:13:57 -05001738 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001739 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001740}
1741
Benny Halevy99fe60d2009-04-01 09:22:29 -04001742#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001743/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001744static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001745 const struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001746 struct compound_hdr *hdr)
1747{
1748 __be32 *p;
1749
1750 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1751 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001752 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001753 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001754 *p++ = cpu_to_be32(args->dir);
1755 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001756}
1757
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001758static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001759{
1760 unsigned int i;
1761 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1762 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1763 encode_uint32(xdr, op_map->u.words[i]);
1764}
1765
Benny Halevy99fe60d2009-04-01 09:22:29 -04001766static void encode_exchange_id(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001767 const struct nfs41_exchange_id_args *args,
Benny Halevy99fe60d2009-04-01 09:22:29 -04001768 struct compound_hdr *hdr)
1769{
1770 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001771 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001772 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001773
Trond Myklebust70019512012-03-04 20:49:32 -05001774 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Trond Myklebustfd405592017-08-01 16:02:47 -04001775 encode_nfs4_verifier(xdr, &args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001776
Jeff Layton3a6bb732015-06-09 19:43:57 -04001777 encode_string(xdr, strlen(args->client->cl_owner_id),
1778 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001779
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001780 encode_uint32(xdr, args->flags);
1781 encode_uint32(xdr, args->state_protect.how);
1782
1783 switch (args->state_protect.how) {
1784 case SP4_NONE:
1785 break;
1786 case SP4_MACH_CRED:
1787 encode_op_map(xdr, &args->state_protect.enforce);
1788 encode_op_map(xdr, &args->state_protect.allow);
1789 break;
1790 default:
1791 WARN_ON_ONCE(1);
1792 break;
1793 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001794
1795 if (send_implementation_id &&
1796 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1797 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001798 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001799 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1800 utsname()->sysname, utsname()->release,
1801 utsname()->version, utsname()->machine);
1802
1803 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001804 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001805
1806 encode_string(xdr,
1807 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1808 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1809 encode_string(xdr, len, impl_name);
1810 /* just send zeros for nii_date - the date is in nii_name */
1811 p = reserve_space(xdr, 12);
1812 p = xdr_encode_hyper(p, 0);
1813 *p = cpu_to_be32(0);
1814 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001815 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001816}
Andy Adamsonfc931582009-04-01 09:22:31 -04001817
1818static void encode_create_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001819 const struct nfs41_create_session_args *args,
Andy Adamsonfc931582009-04-01 09:22:31 -04001820 struct compound_hdr *hdr)
1821{
1822 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001823 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001824 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001825 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001826 u32 max_resp_sz_cached;
1827
1828 /*
1829 * Assumes OPEN is the biggest non-idempotent compound.
1830 * 2 is the verifier.
1831 */
J. Bruce Fields35c036e2017-09-20 12:42:13 -04001832 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
1833 * XDR_UNIT + RPC_MAX_AUTH_SIZE;
Andy Adamsonfc931582009-04-01 09:22:31 -04001834
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001835 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001836 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001837 p = xdr_encode_hyper(p, args->clientid);
1838 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001839 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001840
Andy Adamsonfc931582009-04-01 09:22:31 -04001841 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001842 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001843 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1844 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001845 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001846 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1847 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1848 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001849
1850 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001851 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001852 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1853 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1854 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1855 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1856 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1857 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001858
Benny Halevye75bc1c2009-08-14 17:18:54 +03001859 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001860 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001861 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001862
1863 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001864 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001865 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001866 *p++ = cpu_to_be32(0); /* UID */
1867 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001868 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001869}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001870
1871static void encode_destroy_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001872 const struct nfs4_session *session,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001873 struct compound_hdr *hdr)
1874{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001875 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1876 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001877}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001878
Trond Myklebust66245532012-05-25 17:18:09 -04001879static void encode_destroy_clientid(struct xdr_stream *xdr,
1880 uint64_t clientid,
1881 struct compound_hdr *hdr)
1882{
1883 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1884 encode_uint64(xdr, clientid);
1885}
1886
Ricardo Labiaga180197532009-12-05 16:08:40 -05001887static void encode_reclaim_complete(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001888 const struct nfs41_reclaim_complete_args *args,
Ricardo Labiaga180197532009-12-05 16:08:40 -05001889 struct compound_hdr *hdr)
1890{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001891 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1892 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001893}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001894#endif /* CONFIG_NFS_V4_1 */
1895
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001896static void encode_sequence(struct xdr_stream *xdr,
1897 const struct nfs4_sequence_args *args,
1898 struct compound_hdr *hdr)
1899{
1900#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001901 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001902 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001903 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001904 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001905
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001906 tp = slot->table;
1907 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001908 if (!session)
1909 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001910
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001911 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001912
1913 /*
1914 * Sessionid + seqid + slotid + max slotid + cache_this
1915 */
1916 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1917 "max_slotid=%d cache_this=%d\n",
1918 __func__,
1919 ((u32 *)session->sess_id.data)[0],
1920 ((u32 *)session->sess_id.data)[1],
1921 ((u32 *)session->sess_id.data)[2],
1922 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001923 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001924 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001925 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001926 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001927 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001928 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001929 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001930 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001931#endif /* CONFIG_NFS_V4_1 */
1932}
1933
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001934#ifdef CONFIG_NFS_V4_1
1935static void
1936encode_getdeviceinfo(struct xdr_stream *xdr,
1937 const struct nfs4_getdeviceinfo_args *args,
1938 struct compound_hdr *hdr)
1939{
1940 __be32 *p;
1941
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001942 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001943 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001944 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1945 NFS4_DEVICEID4_SIZE);
1946 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001947 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001948
1949 p = reserve_space(xdr, 4 + 4);
1950 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001951 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001952}
1953
1954static void
1955encode_layoutget(struct xdr_stream *xdr,
1956 const struct nfs4_layoutget_args *args,
1957 struct compound_hdr *hdr)
1958{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001959 __be32 *p;
1960
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001961 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1962 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001963 *p++ = cpu_to_be32(0); /* Signal layout available */
1964 *p++ = cpu_to_be32(args->type);
1965 *p++ = cpu_to_be32(args->range.iomode);
1966 p = xdr_encode_hyper(p, args->range.offset);
1967 p = xdr_encode_hyper(p, args->range.length);
1968 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001969 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001970 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001971
1972 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1973 __func__,
1974 args->type,
1975 args->range.iomode,
1976 (unsigned long)args->range.offset,
1977 (unsigned long)args->range.length,
1978 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001979}
Andy Adamson863a3c62011-03-23 13:27:54 +00001980
1981static int
1982encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001983 struct inode *inode,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001984 const struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001985 struct compound_hdr *hdr)
1986{
1987 __be32 *p;
1988
1989 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1990 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1991
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001992 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1993 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001994 /* Only whole file layouts */
1995 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001996 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001997 *p = cpu_to_be32(0); /* reclaim */
1998 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04001999 if (args->lastbytewritten != U64_MAX) {
2000 p = reserve_space(xdr, 20);
2001 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2002 p = xdr_encode_hyper(p, args->lastbytewritten);
2003 } else {
2004 p = reserve_space(xdr, 12);
2005 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2006 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002007 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2008 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002009
Trond Myklebust73504742017-04-20 16:48:14 -04002010 encode_uint32(xdr, args->layoutupdate_len);
2011 if (args->layoutupdate_pages)
2012 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2013 args->layoutupdate_len);
Andy Adamson863a3c62011-03-23 13:27:54 +00002014
Andy Adamson863a3c62011-03-23 13:27:54 +00002015 return 0;
2016}
Benny Halevycbe82602011-05-22 19:52:37 +03002017
2018static void
2019encode_layoutreturn(struct xdr_stream *xdr,
2020 const struct nfs4_layoutreturn_args *args,
2021 struct compound_hdr *hdr)
2022{
2023 __be32 *p;
2024
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002025 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2026 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002027 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2028 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002029 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002030 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002031 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002032 p = xdr_encode_hyper(p, args->range.offset);
2033 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002034 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002035 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002036 spin_unlock(&args->inode->i_lock);
Trond Myklebust4d796d72016-09-23 11:38:08 -04002037 if (args->ld_private->ops && args->ld_private->ops->encode)
2038 args->ld_private->ops->encode(xdr, args, args->ld_private);
Trond Myklebust94e5c572016-09-15 18:49:52 -04002039 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002040 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002041}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002042
2043static int
2044encode_secinfo_no_name(struct xdr_stream *xdr,
2045 const struct nfs41_secinfo_no_name_args *args,
2046 struct compound_hdr *hdr)
2047{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002048 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2049 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002050 return 0;
2051}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002052
2053static void encode_test_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002054 const struct nfs41_test_stateid_args *args,
Bryan Schumaker7d974792011-06-02 14:59:08 -04002055 struct compound_hdr *hdr)
2056{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002057 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2058 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002059 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002060}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002061
2062static void encode_free_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002063 const struct nfs41_free_stateid_args *args,
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002064 struct compound_hdr *hdr)
2065{
Trond Myklebustab19b482012-03-04 18:13:57 -05002066 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002067 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002068}
Trond Myklebustcf805162016-11-15 14:56:07 -05002069#else
2070static inline void
2071encode_layoutreturn(struct xdr_stream *xdr,
2072 const struct nfs4_layoutreturn_args *args,
2073 struct compound_hdr *hdr)
2074{
2075}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002076#endif /* CONFIG_NFS_V4_1 */
2077
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078/*
2079 * END OF "GENERIC" ENCODE ROUTINES.
2080 */
2081
Benny Halevy66cc0422009-04-01 09:22:10 -04002082static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2083{
2084#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002085 struct nfs4_session *session = args->sa_slot->table->session;
2086 if (session)
2087 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002088#endif /* CONFIG_NFS_V4_1 */
2089 return 0;
2090}
2091
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092/*
2093 * Encode an ACCESS request
2094 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002095static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002096 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002098 const struct nfs4_accessargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002100 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
Chuck Lever9f06c712010-12-14 14:59:18 +00002103 encode_compound_hdr(xdr, req, &hdr);
2104 encode_sequence(xdr, &args->seq_args, &hdr);
2105 encode_putfh(xdr, args->fh, &hdr);
2106 encode_access(xdr, args->access, &hdr);
Trond Myklebust8bcbe7d2018-03-20 17:03:11 -04002107 if (args->bitmask)
2108 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002109 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110}
2111
2112/*
2113 * Encode LOOKUP request
2114 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002115static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002116 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002118 const struct nfs4_lookup_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002120 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122
Chuck Lever9f06c712010-12-14 14:59:18 +00002123 encode_compound_hdr(xdr, req, &hdr);
2124 encode_sequence(xdr, &args->seq_args, &hdr);
2125 encode_putfh(xdr, args->dir_fh, &hdr);
2126 encode_lookup(xdr, args->name, &hdr);
2127 encode_getfh(xdr, &hdr);
2128 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002129 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130}
2131
2132/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07002133 * Encode LOOKUPP request
2134 */
2135static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
2136 const void *data)
2137{
2138 const struct nfs4_lookupp_arg *args = data;
2139 struct compound_hdr hdr = {
2140 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2141 };
2142
2143 encode_compound_hdr(xdr, req, &hdr);
2144 encode_sequence(xdr, &args->seq_args, &hdr);
2145 encode_putfh(xdr, args->fh, &hdr);
2146 encode_lookupp(xdr, &hdr);
2147 encode_getfh(xdr, &hdr);
2148 encode_getfattr(xdr, args->bitmask, &hdr);
2149 encode_nops(&hdr);
2150}
2151
2152/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 * Encode LOOKUP_ROOT request
2154 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002155static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2156 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002157 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002159 const struct nfs4_lookup_root_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002161 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
Chuck Lever9f06c712010-12-14 14:59:18 +00002164 encode_compound_hdr(xdr, req, &hdr);
2165 encode_sequence(xdr, &args->seq_args, &hdr);
2166 encode_putrootfh(xdr, &hdr);
2167 encode_getfh(xdr, &hdr);
2168 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002169 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170}
2171
2172/*
2173 * Encode REMOVE request
2174 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002175static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002176 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002178 const struct nfs_removeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002180 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
Chuck Lever9f06c712010-12-14 14:59:18 +00002183 encode_compound_hdr(xdr, req, &hdr);
2184 encode_sequence(xdr, &args->seq_args, &hdr);
2185 encode_putfh(xdr, args->fh, &hdr);
2186 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002187 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188}
2189
2190/*
2191 * Encode RENAME request
2192 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002193static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002194 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002196 const struct nfs_renameargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002198 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
Chuck Lever9f06c712010-12-14 14:59:18 +00002201 encode_compound_hdr(xdr, req, &hdr);
2202 encode_sequence(xdr, &args->seq_args, &hdr);
2203 encode_putfh(xdr, args->old_dir, &hdr);
2204 encode_savefh(xdr, &hdr);
2205 encode_putfh(xdr, args->new_dir, &hdr);
2206 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002207 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208}
2209
2210/*
2211 * Encode LINK request
2212 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002213static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002214 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002216 const struct nfs4_link_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002218 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
Chuck Lever9f06c712010-12-14 14:59:18 +00002221 encode_compound_hdr(xdr, req, &hdr);
2222 encode_sequence(xdr, &args->seq_args, &hdr);
2223 encode_putfh(xdr, args->fh, &hdr);
2224 encode_savefh(xdr, &hdr);
2225 encode_putfh(xdr, args->dir_fh, &hdr);
2226 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002227 encode_restorefh(xdr, &hdr);
2228 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002229 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230}
2231
2232/*
2233 * Encode CREATE request
2234 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002235static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002236 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002238 const struct nfs4_create_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002240 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
Chuck Lever9f06c712010-12-14 14:59:18 +00002243 encode_compound_hdr(xdr, req, &hdr);
2244 encode_sequence(xdr, &args->seq_args, &hdr);
2245 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002246 encode_create(xdr, args, &hdr);
2247 encode_getfh(xdr, &hdr);
2248 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002249 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250}
2251
2252/*
2253 * Encode SYMLINK request
2254 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002255static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002256 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002258 const struct nfs4_create_arg *args = data;
2259
Chuck Lever9f06c712010-12-14 14:59:18 +00002260 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261}
2262
2263/*
2264 * Encode GETATTR request
2265 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002266static void nfs4_xdr_enc_getattr(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_getattr_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002271 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273
Chuck Lever9f06c712010-12-14 14:59:18 +00002274 encode_compound_hdr(xdr, req, &hdr);
2275 encode_sequence(xdr, &args->seq_args, &hdr);
2276 encode_putfh(xdr, args->fh, &hdr);
2277 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002278 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279}
2280
2281/*
2282 * Encode a CLOSE request
2283 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002284static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002285 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002287 const struct nfs_closeargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002288 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002289 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002290 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
Chuck Lever9f06c712010-12-14 14:59:18 +00002292 encode_compound_hdr(xdr, req, &hdr);
2293 encode_sequence(xdr, &args->seq_args, &hdr);
2294 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002295 if (args->lr_args)
2296 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002297 if (args->bitmask != NULL)
2298 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebustd8d84982016-12-19 12:14:44 -05002299 encode_close(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002300 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301}
2302
2303/*
2304 * Encode an OPEN request
2305 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002306static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002307 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002309 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002311 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313
Chuck Lever9f06c712010-12-14 14:59:18 +00002314 encode_compound_hdr(xdr, req, &hdr);
2315 encode_sequence(xdr, &args->seq_args, &hdr);
2316 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002317 encode_open(xdr, args, &hdr);
2318 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002319 if (args->access)
2320 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002321 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002322 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323}
2324
2325/*
2326 * Encode an OPEN_CONFIRM request
2327 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002328static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2329 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002330 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002332 const struct nfs_open_confirmargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002334 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336
Chuck Lever9f06c712010-12-14 14:59:18 +00002337 encode_compound_hdr(xdr, req, &hdr);
2338 encode_putfh(xdr, args->fh, &hdr);
2339 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002340 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341}
2342
2343/*
2344 * Encode an OPEN request with no attributes.
2345 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002346static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2347 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002348 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002350 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002352 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
Chuck Lever9f06c712010-12-14 14:59:18 +00002355 encode_compound_hdr(xdr, req, &hdr);
2356 encode_sequence(xdr, &args->seq_args, &hdr);
2357 encode_putfh(xdr, args->fh, &hdr);
2358 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002359 if (args->access)
2360 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002361 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002362 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363}
2364
2365/*
2366 * Encode an OPEN_DOWNGRADE request
2367 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002368static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2369 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002370 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002372 const struct nfs_closeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002374 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376
Chuck Lever9f06c712010-12-14 14:59:18 +00002377 encode_compound_hdr(xdr, req, &hdr);
2378 encode_sequence(xdr, &args->seq_args, &hdr);
2379 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustb6808142016-11-20 13:34:16 -05002380 if (args->lr_args)
2381 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002382 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002383 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384}
2385
2386/*
2387 * Encode a LOCK request
2388 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002389static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002390 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002392 const struct nfs_lock_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002394 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396
Chuck Lever9f06c712010-12-14 14:59:18 +00002397 encode_compound_hdr(xdr, req, &hdr);
2398 encode_sequence(xdr, &args->seq_args, &hdr);
2399 encode_putfh(xdr, args->fh, &hdr);
2400 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002401 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402}
2403
2404/*
2405 * Encode a LOCKT request
2406 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002407static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002408 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002410 const struct nfs_lockt_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002412 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414
Chuck Lever9f06c712010-12-14 14:59:18 +00002415 encode_compound_hdr(xdr, req, &hdr);
2416 encode_sequence(xdr, &args->seq_args, &hdr);
2417 encode_putfh(xdr, args->fh, &hdr);
2418 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002419 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420}
2421
2422/*
2423 * Encode a LOCKU request
2424 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002425static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002426 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002428 const struct nfs_locku_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002430 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432
Chuck Lever9f06c712010-12-14 14:59:18 +00002433 encode_compound_hdr(xdr, req, &hdr);
2434 encode_sequence(xdr, &args->seq_args, &hdr);
2435 encode_putfh(xdr, args->fh, &hdr);
2436 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002437 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438}
2439
Chuck Lever9f06c712010-12-14 14:59:18 +00002440static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2441 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002442 const void *data)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002443{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002444 const struct nfs_release_lockowner_args *args = data;
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002445 struct compound_hdr hdr = {
2446 .minorversion = 0,
2447 };
2448
Chuck Lever9f06c712010-12-14 14:59:18 +00002449 encode_compound_hdr(xdr, req, &hdr);
2450 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002451 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002452}
2453
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454/*
2455 * Encode a READLINK request
2456 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002457static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002458 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002460 const struct nfs4_readlink *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002462 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464
Chuck Lever9f06c712010-12-14 14:59:18 +00002465 encode_compound_hdr(xdr, req, &hdr);
2466 encode_sequence(xdr, &args->seq_args, &hdr);
2467 encode_putfh(xdr, args->fh, &hdr);
2468 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002469
Benny Halevy28f56692009-04-01 09:22:09 -04002470 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002471 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002472 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473}
2474
2475/*
2476 * Encode a READDIR request
2477 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002478static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002479 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002481 const struct nfs4_readdir_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002483 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485
Chuck Lever9f06c712010-12-14 14:59:18 +00002486 encode_compound_hdr(xdr, req, &hdr);
2487 encode_sequence(xdr, &args->seq_args, &hdr);
2488 encode_putfh(xdr, args->fh, &hdr);
2489 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002490
Benny Halevy28f56692009-04-01 09:22:09 -04002491 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002492 args->pgbase, args->count);
2493 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002494 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002495 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002496 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497}
2498
2499/*
2500 * Encode a READ request
2501 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002502static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002503 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002505 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002507 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509
Chuck Lever9f06c712010-12-14 14:59:18 +00002510 encode_compound_hdr(xdr, req, &hdr);
2511 encode_sequence(xdr, &args->seq_args, &hdr);
2512 encode_putfh(xdr, args->fh, &hdr);
2513 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514
Benny Halevy28f56692009-04-01 09:22:09 -04002515 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002517 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002518 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519}
2520
2521/*
2522 * Encode an SETATTR request
2523 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002524static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002525 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002527 const struct nfs_setattrargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002528 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002529 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002530 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
Chuck Lever9f06c712010-12-14 14:59:18 +00002532 encode_compound_hdr(xdr, req, &hdr);
2533 encode_sequence(xdr, &args->seq_args, &hdr);
2534 encode_putfh(xdr, args->fh, &hdr);
2535 encode_setattr(xdr, args, args->server, &hdr);
2536 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002537 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538}
2539
2540/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002541 * Encode a GETACL request
2542 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002543static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002544 const void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002545{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002546 const struct nfs_getaclargs *args = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002547 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002548 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002549 };
Trond Myklebust37c88762018-03-20 17:03:08 -04002550 const __u32 nfs4_acl_bitmap[1] = {
2551 [0] = FATTR4_WORD0_ACL,
2552 };
Benny Halevy28f56692009-04-01 09:22:09 -04002553 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002554
Chuck Lever9f06c712010-12-14 14:59:18 +00002555 encode_compound_hdr(xdr, req, &hdr);
2556 encode_sequence(xdr, &args->seq_args, &hdr);
2557 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fields6682c142017-02-23 14:53:39 -05002558 replen = hdr.replen + op_decode_hdr_maxsz;
Trond Myklebust37c88762018-03-20 17:03:08 -04002559 encode_getattr(xdr, nfs4_acl_bitmap, NULL,
2560 ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002561
Benny Halevy28f56692009-04-01 09:22:09 -04002562 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01002563 args->acl_pages, 0, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002564
Andy Adamsond0179312008-12-23 16:06:17 -05002565 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002566}
2567
2568/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 * Encode a WRITE request
2570 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002571static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002572 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002574 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002576 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578
Chuck Lever9f06c712010-12-14 14:59:18 +00002579 encode_compound_hdr(xdr, req, &hdr);
2580 encode_sequence(xdr, &args->seq_args, &hdr);
2581 encode_putfh(xdr, args->fh, &hdr);
2582 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002583 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002584 if (args->bitmask)
2585 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002586 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587}
2588
2589/*
2590 * a COMMIT request
2591 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002592static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002593 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002595 const struct nfs_commitargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002597 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599
Chuck Lever9f06c712010-12-14 14:59:18 +00002600 encode_compound_hdr(xdr, req, &hdr);
2601 encode_sequence(xdr, &args->seq_args, &hdr);
2602 encode_putfh(xdr, args->fh, &hdr);
2603 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002604 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605}
2606
2607/*
2608 * FSINFO request
2609 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002610static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002611 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002613 const struct nfs4_fsinfo_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002615 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617
Chuck Lever9f06c712010-12-14 14:59:18 +00002618 encode_compound_hdr(xdr, req, &hdr);
2619 encode_sequence(xdr, &args->seq_args, &hdr);
2620 encode_putfh(xdr, args->fh, &hdr);
2621 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002622 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623}
2624
2625/*
2626 * a PATHCONF request
2627 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002628static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002629 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002631 const struct nfs4_pathconf_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002633 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
Chuck Lever9f06c712010-12-14 14:59:18 +00002636 encode_compound_hdr(xdr, req, &hdr);
2637 encode_sequence(xdr, &args->seq_args, &hdr);
2638 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002639 encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
2640 ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002641 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642}
2643
2644/*
2645 * a STATFS request
2646 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002647static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002648 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002650 const struct nfs4_statfs_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002652 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
Chuck Lever9f06c712010-12-14 14:59:18 +00002655 encode_compound_hdr(xdr, req, &hdr);
2656 encode_sequence(xdr, &args->seq_args, &hdr);
2657 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002658 encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
2659 ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002660 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661}
2662
2663/*
2664 * GETATTR_BITMAP request
2665 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002666static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2667 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002668 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002670 const struct nfs4_server_caps_arg *args = data;
Kinglong Mee8c612822015-08-26 21:12:58 +08002671 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002673 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675
Chuck Lever9f06c712010-12-14 14:59:18 +00002676 encode_compound_hdr(xdr, req, &hdr);
2677 encode_sequence(xdr, &args->seq_args, &hdr);
2678 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002679 encode_getattr(xdr, bitmask, NULL, 3, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002680 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681}
2682
2683/*
2684 * a RENEW request
2685 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002686static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002687 const void *data)
2688
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002690 const struct nfs_client *clp = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002692 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 };
2694
Chuck Lever9f06c712010-12-14 14:59:18 +00002695 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002696 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002697 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698}
2699
2700/*
2701 * a SETCLIENTID request
2702 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002703static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2704 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002705 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002707 const struct nfs4_setclientid *sc = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002709 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 };
2711
Chuck Lever9f06c712010-12-14 14:59:18 +00002712 encode_compound_hdr(xdr, req, &hdr);
2713 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002714 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715}
2716
2717/*
2718 * a SETCLIENTID_CONFIRM request
2719 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002720static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2721 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002722 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002724 const struct nfs4_setclientid_res *arg = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002726 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
Chuck Lever9f06c712010-12-14 14:59:18 +00002729 encode_compound_hdr(xdr, req, &hdr);
2730 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002731 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732}
2733
2734/*
2735 * DELEGRETURN request
2736 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002737static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2738 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002739 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002741 const struct nfs4_delegreturnargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002743 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
Chuck Lever9f06c712010-12-14 14:59:18 +00002746 encode_compound_hdr(xdr, req, &hdr);
2747 encode_sequence(xdr, &args->seq_args, &hdr);
2748 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust586f1c32016-11-15 15:03:33 -05002749 if (args->lr_args)
2750 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05002751 if (args->bitmask)
2752 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002753 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002754 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755}
2756
2757/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002758 * Encode FS_LOCATIONS request
2759 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002760static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2761 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002762 const void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002763{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002764 const struct nfs4_fs_locations_arg *args = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002765 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002766 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002767 };
Benny Halevy28f56692009-04-01 09:22:09 -04002768 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002769
Chuck Lever9f06c712010-12-14 14:59:18 +00002770 encode_compound_hdr(xdr, req, &hdr);
2771 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002772 if (args->migration) {
2773 encode_putfh(xdr, args->fh, &hdr);
2774 replen = hdr.replen;
2775 encode_fs_locations(xdr, args->bitmask, &hdr);
2776 if (args->renew)
2777 encode_renew(xdr, args->clientid, &hdr);
2778 } else {
2779 encode_putfh(xdr, args->dir_fh, &hdr);
2780 encode_lookup(xdr, args->name, &hdr);
2781 replen = hdr.replen;
2782 encode_fs_locations(xdr, args->bitmask, &hdr);
2783 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002784
Chuck Leverb03d7352013-10-17 14:12:50 -04002785 /* Set up reply kvec to capture returned fs_locations array. */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002786 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2787 (struct page **)&args->page, 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002788 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002789}
2790
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002791/*
2792 * Encode SECINFO request
2793 */
2794static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2795 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002796 const void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002797{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002798 const struct nfs4_secinfo_arg *args = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002799 struct compound_hdr hdr = {
2800 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2801 };
2802
2803 encode_compound_hdr(xdr, req, &hdr);
2804 encode_sequence(xdr, &args->seq_args, &hdr);
2805 encode_putfh(xdr, args->dir_fh, &hdr);
2806 encode_secinfo(xdr, args->name, &hdr);
2807 encode_nops(&hdr);
2808}
2809
Chuck Lever44c99932013-10-17 14:13:30 -04002810/*
2811 * Encode FSID_PRESENT request
2812 */
2813static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2814 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002815 const void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04002816{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002817 const struct nfs4_fsid_present_arg *args = data;
Chuck Lever44c99932013-10-17 14:13:30 -04002818 struct compound_hdr hdr = {
2819 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2820 };
2821
2822 encode_compound_hdr(xdr, req, &hdr);
2823 encode_sequence(xdr, &args->seq_args, &hdr);
2824 encode_putfh(xdr, args->fh, &hdr);
2825 encode_getfh(xdr, &hdr);
2826 if (args->renew)
2827 encode_renew(xdr, args->clientid, &hdr);
2828 encode_nops(&hdr);
2829}
2830
Benny Halevy99fe60d2009-04-01 09:22:29 -04002831#if defined(CONFIG_NFS_V4_1)
2832/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002833 * BIND_CONN_TO_SESSION request
2834 */
2835static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2836 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002837 const void *data)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002838{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002839 const struct nfs41_bind_conn_to_session_args *args = data;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002840 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002841 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002842 };
2843
2844 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002845 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002846 encode_nops(&hdr);
2847}
2848
2849/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002850 * EXCHANGE_ID request
2851 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002852static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2853 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002854 const void *data)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002855{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002856 const struct nfs41_exchange_id_args *args = data;
Benny Halevy99fe60d2009-04-01 09:22:29 -04002857 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002858 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002859 };
2860
Chuck Lever9f06c712010-12-14 14:59:18 +00002861 encode_compound_hdr(xdr, req, &hdr);
2862 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002863 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002864}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002865
2866/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002867 * a CREATE_SESSION request
2868 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002869static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2870 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002871 const void *data)
Andy Adamsonfc931582009-04-01 09:22:31 -04002872{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002873 const struct nfs41_create_session_args *args = data;
Andy Adamsonfc931582009-04-01 09:22:31 -04002874 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002875 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002876 };
2877
Chuck Lever9f06c712010-12-14 14:59:18 +00002878 encode_compound_hdr(xdr, req, &hdr);
2879 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002880 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002881}
2882
2883/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002884 * a DESTROY_SESSION request
2885 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002886static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2887 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002888 const void *data)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002889{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002890 const struct nfs4_session *session = data;
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002891 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002892 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002893 };
2894
Chuck Lever9f06c712010-12-14 14:59:18 +00002895 encode_compound_hdr(xdr, req, &hdr);
2896 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002897 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002898}
2899
2900/*
Trond Myklebust66245532012-05-25 17:18:09 -04002901 * a DESTROY_CLIENTID request
2902 */
2903static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2904 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002905 const void *data)
Trond Myklebust66245532012-05-25 17:18:09 -04002906{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002907 const struct nfs_client *clp = data;
Trond Myklebust66245532012-05-25 17:18:09 -04002908 struct compound_hdr hdr = {
2909 .minorversion = clp->cl_mvops->minor_version,
2910 };
2911
2912 encode_compound_hdr(xdr, req, &hdr);
2913 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2914 encode_nops(&hdr);
2915}
2916
2917/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002918 * a SEQUENCE request
2919 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002920static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002921 const void *data)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002922{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002923 const struct nfs4_sequence_args *args = data;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002924 struct compound_hdr hdr = {
2925 .minorversion = nfs4_xdr_minorversion(args),
2926 };
2927
Chuck Lever9f06c712010-12-14 14:59:18 +00002928 encode_compound_hdr(xdr, req, &hdr);
2929 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002930 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002931}
2932
2933/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002934 * a GET_LEASE_TIME request
2935 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002936static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2937 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002938 const void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002939{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002940 const struct nfs4_get_lease_time_args *args = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04002941 struct compound_hdr hdr = {
2942 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2943 };
Fred Isamandae100c2011-07-30 20:52:37 -04002944 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002945
Chuck Lever9f06c712010-12-14 14:59:18 +00002946 encode_compound_hdr(xdr, req, &hdr);
2947 encode_sequence(xdr, &args->la_seq_args, &hdr);
2948 encode_putrootfh(xdr, &hdr);
2949 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002950 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002951}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002952
2953/*
2954 * a RECLAIM_COMPLETE request
2955 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002956static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2957 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002958 const void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002959{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002960 const struct nfs41_reclaim_complete_args *args = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05002961 struct compound_hdr hdr = {
2962 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2963 };
2964
Chuck Lever9f06c712010-12-14 14:59:18 +00002965 encode_compound_hdr(xdr, req, &hdr);
2966 encode_sequence(xdr, &args->seq_args, &hdr);
2967 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002968 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002969}
2970
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002971/*
2972 * Encode GETDEVICEINFO request
2973 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002974static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2975 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002976 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002977{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002978 const struct nfs4_getdeviceinfo_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002979 struct compound_hdr hdr = {
2980 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2981 };
2982
Chuck Lever9f06c712010-12-14 14:59:18 +00002983 encode_compound_hdr(xdr, req, &hdr);
2984 encode_sequence(xdr, &args->seq_args, &hdr);
2985 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002986
2987 /* set up reply kvec. Subtract notification bitmap max size (2)
2988 * so that notification bitmap is put in xdr_buf tail */
2989 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2990 args->pdev->pages, args->pdev->pgbase,
2991 args->pdev->pglen);
2992
2993 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002994}
2995
2996/*
2997 * Encode LAYOUTGET request
2998 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002999static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
3000 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003001 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003002{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003003 const struct nfs4_layoutget_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003004 struct compound_hdr hdr = {
3005 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3006 };
3007
Chuck Lever9f06c712010-12-14 14:59:18 +00003008 encode_compound_hdr(xdr, req, &hdr);
3009 encode_sequence(xdr, &args->seq_args, &hdr);
3010 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3011 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04003012
3013 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
3014 args->layout.pages, 0, args->layout.pglen);
3015
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003016 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003017}
Andy Adamson863a3c62011-03-23 13:27:54 +00003018
3019/*
3020 * Encode LAYOUTCOMMIT request
3021 */
Benny Halevycbe82602011-05-22 19:52:37 +03003022static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3023 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003024 const void *priv)
Andy Adamson863a3c62011-03-23 13:27:54 +00003025{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003026 const struct nfs4_layoutcommit_args *args = priv;
Benny Halevyac7db722011-05-22 19:53:48 +03003027 struct nfs4_layoutcommit_data *data =
3028 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00003029 struct compound_hdr hdr = {
3030 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3031 };
3032
3033 encode_compound_hdr(xdr, req, &hdr);
3034 encode_sequence(xdr, &args->seq_args, &hdr);
3035 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03003036 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003037 encode_getfattr(xdr, args->bitmask, &hdr);
3038 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03003039}
3040
3041/*
3042 * Encode LAYOUTRETURN request
3043 */
3044static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3045 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003046 const void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03003047{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003048 const struct nfs4_layoutreturn_args *args = data;
Benny Halevycbe82602011-05-22 19:52:37 +03003049 struct compound_hdr hdr = {
3050 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3051 };
3052
3053 encode_compound_hdr(xdr, req, &hdr);
3054 encode_sequence(xdr, &args->seq_args, &hdr);
3055 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3056 encode_layoutreturn(xdr, args, &hdr);
3057 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003058}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003059
3060/*
3061 * Encode SECINFO_NO_NAME request
3062 */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003063static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003064 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003065 const void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003066{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003067 const struct nfs41_secinfo_no_name_args *args = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003068 struct compound_hdr hdr = {
3069 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3070 };
3071
3072 encode_compound_hdr(xdr, req, &hdr);
3073 encode_sequence(xdr, &args->seq_args, &hdr);
3074 encode_putrootfh(xdr, &hdr);
3075 encode_secinfo_no_name(xdr, args, &hdr);
3076 encode_nops(&hdr);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003077}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003078
3079/*
3080 * Encode TEST_STATEID request
3081 */
3082static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3083 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003084 const void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04003085{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003086 const struct nfs41_test_stateid_args *args = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04003087 struct compound_hdr hdr = {
3088 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3089 };
3090
3091 encode_compound_hdr(xdr, req, &hdr);
3092 encode_sequence(xdr, &args->seq_args, &hdr);
3093 encode_test_stateid(xdr, args, &hdr);
3094 encode_nops(&hdr);
3095}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003096
3097/*
3098 * Encode FREE_STATEID request
3099 */
3100static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3101 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003102 const void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003103{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003104 const struct nfs41_free_stateid_args *args = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003105 struct compound_hdr hdr = {
3106 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3107 };
3108
3109 encode_compound_hdr(xdr, req, &hdr);
3110 encode_sequence(xdr, &args->seq_args, &hdr);
3111 encode_free_stateid(xdr, args, &hdr);
3112 encode_nops(&hdr);
3113}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003114#endif /* CONFIG_NFS_V4_1 */
3115
Benny Halevy686841b2009-08-14 17:19:48 +03003116static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3117{
3118 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3119 "Remaining buffer length is %tu words.\n",
3120 func, xdr->end - xdr->p);
3121}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122
Trond Myklebust683b57b2006-06-09 09:34:22 -04003123static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124{
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003125 ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3126 NFS4_OPAQUE_LIMIT);
3127 if (unlikely(ret < 0)) {
3128 if (ret == -EBADMSG)
3129 print_overflow_msg(__func__, xdr);
3130 return -EIO;
3131 }
3132 *len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 return 0;
3134}
3135
3136static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3137{
Al Viro8687b632006-10-19 23:28:48 -07003138 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139
Benny Halevyc0eae662009-08-14 17:20:14 +03003140 p = xdr_inline_decode(xdr, 8);
3141 if (unlikely(!p))
3142 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003143 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003144 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003145
Benny Halevyc0eae662009-08-14 17:20:14 +03003146 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3147 if (unlikely(!p))
3148 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 hdr->tag = (char *)p;
3150 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003151 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003152 if (unlikely(hdr->nops < 1))
3153 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003155out_overflow:
3156 print_overflow_msg(__func__, xdr);
3157 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158}
3159
Trond Myklebustc7848f62013-12-04 17:39:23 -05003160static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3161 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162{
Al Viro8687b632006-10-19 23:28:48 -07003163 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164 uint32_t opnum;
3165 int32_t nfserr;
3166
Benny Halevyc0eae662009-08-14 17:20:14 +03003167 p = xdr_inline_decode(xdr, 8);
3168 if (unlikely(!p))
3169 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003170 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003171 if (unlikely(opnum != expected))
3172 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003173 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003174 if (nfserr == NFS_OK)
3175 *nfs_retval = 0;
3176 else
3177 *nfs_retval = nfs4_stat_to_errno(nfserr);
3178 return true;
3179out_bad_operation:
3180 dprintk("nfs: Server returned operation"
3181 " %d but we issued a request for %d\n",
3182 opnum, expected);
3183 *nfs_retval = -EREMOTEIO;
3184 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003185out_overflow:
3186 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003187 *nfs_retval = -EIO;
3188 return false;
3189}
3190
3191static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3192{
3193 int retval;
3194
3195 __decode_op_hdr(xdr, expected, &retval);
3196 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197}
3198
3199/* Dummy routine */
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05003200static int decode_ace(struct xdr_stream *xdr, void *ace)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201{
Al Viro8687b632006-10-19 23:28:48 -07003202 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003203 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 char *str;
3205
Benny Halevyc0eae662009-08-14 17:20:14 +03003206 p = xdr_inline_decode(xdr, 12);
3207 if (likely(p))
3208 return decode_opaque_inline(xdr, &strlen, &str);
3209 print_overflow_msg(__func__, xdr);
3210 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211}
3212
Trond Myklebust37c88762018-03-20 17:03:08 -04003213static ssize_t
3214decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215{
Trond Myklebust37c88762018-03-20 17:03:08 -04003216 ssize_t ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217
Trond Myklebust37c88762018-03-20 17:03:08 -04003218 ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
3219 if (likely(ret >= 0))
3220 return ret;
3221 if (ret == -EMSGSIZE)
3222 return sz;
Benny Halevyc0eae662009-08-14 17:20:14 +03003223 print_overflow_msg(__func__, xdr);
3224 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225}
3226
Trond Myklebust37c88762018-03-20 17:03:08 -04003227static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3228{
3229 ssize_t ret;
3230 ret = decode_bitmap4(xdr, bitmap, 3);
3231 return ret < 0 ? ret : 0;
3232}
3233
Trond Myklebust256e48b2012-06-21 11:18:13 -04003234static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235{
Al Viro8687b632006-10-19 23:28:48 -07003236 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237
Benny Halevyc0eae662009-08-14 17:20:14 +03003238 p = xdr_inline_decode(xdr, 4);
3239 if (unlikely(!p))
3240 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003241 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003242 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003244out_overflow:
3245 print_overflow_msg(__func__, xdr);
3246 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247}
3248
3249static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3250{
3251 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003252 int ret;
3253 ret = decode_attr_bitmap(xdr, bitmask);
3254 if (unlikely(ret < 0))
3255 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3257 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003258 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3259 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3260 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 return 0;
3262}
3263
3264static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3265{
Al Viro8687b632006-10-19 23:28:48 -07003266 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003267 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268
3269 *type = 0;
3270 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3271 return -EIO;
3272 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003273 p = xdr_inline_decode(xdr, 4);
3274 if (unlikely(!p))
3275 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003276 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003278 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 return -EIO;
3280 }
3281 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003282 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003284 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003285 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003286out_overflow:
3287 print_overflow_msg(__func__, xdr);
3288 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289}
3290
Chuck Lever264e6352012-03-01 17:02:05 -05003291static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3292 uint32_t *bitmap, uint32_t *type)
3293{
3294 __be32 *p;
3295
3296 *type = 0;
3297 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3298 return -EIO;
3299 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3300 p = xdr_inline_decode(xdr, 4);
3301 if (unlikely(!p))
3302 goto out_overflow;
3303 *type = be32_to_cpup(p);
3304 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3305 }
3306 dprintk("%s: expire type=0x%x\n", __func__, *type);
3307 return 0;
3308out_overflow:
3309 print_overflow_msg(__func__, xdr);
3310 return -EIO;
3311}
3312
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3314{
Al Viro8687b632006-10-19 23:28:48 -07003315 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003316 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317
3318 *change = 0;
3319 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3320 return -EIO;
3321 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003322 p = xdr_inline_decode(xdr, 8);
3323 if (unlikely(!p))
3324 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003325 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003327 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003329 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003331 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003332out_overflow:
3333 print_overflow_msg(__func__, xdr);
3334 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335}
3336
3337static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3338{
Al Viro8687b632006-10-19 23:28:48 -07003339 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003340 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341
3342 *size = 0;
3343 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3344 return -EIO;
3345 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003346 p = xdr_inline_decode(xdr, 8);
3347 if (unlikely(!p))
3348 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003349 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003351 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003353 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003354 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003355out_overflow:
3356 print_overflow_msg(__func__, xdr);
3357 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358}
3359
3360static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3361{
Al Viro8687b632006-10-19 23:28:48 -07003362 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363
3364 *res = 0;
3365 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3366 return -EIO;
3367 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003368 p = xdr_inline_decode(xdr, 4);
3369 if (unlikely(!p))
3370 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003371 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3373 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003374 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003376out_overflow:
3377 print_overflow_msg(__func__, xdr);
3378 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379}
3380
3381static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3382{
Al Viro8687b632006-10-19 23:28:48 -07003383 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384
3385 *res = 0;
3386 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3387 return -EIO;
3388 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003389 p = xdr_inline_decode(xdr, 4);
3390 if (unlikely(!p))
3391 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003392 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3394 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003395 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003397out_overflow:
3398 print_overflow_msg(__func__, xdr);
3399 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400}
3401
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003402static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403{
Al Viro8687b632006-10-19 23:28:48 -07003404 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003405 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406
3407 fsid->major = 0;
3408 fsid->minor = 0;
3409 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3410 return -EIO;
3411 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003412 p = xdr_inline_decode(xdr, 16);
3413 if (unlikely(!p))
3414 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003415 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003416 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003418 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003420 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421 (unsigned long long)fsid->major,
3422 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003423 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003424out_overflow:
3425 print_overflow_msg(__func__, xdr);
3426 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427}
3428
3429static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3430{
Al Viro8687b632006-10-19 23:28:48 -07003431 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432
3433 *res = 60;
3434 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3435 return -EIO;
3436 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003437 p = xdr_inline_decode(xdr, 4);
3438 if (unlikely(!p))
3439 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003440 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3442 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003443 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003445out_overflow:
3446 print_overflow_msg(__func__, xdr);
3447 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448}
3449
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003450static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003451{
3452 __be32 *p;
3453
3454 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3455 return -EIO;
3456 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3457 p = xdr_inline_decode(xdr, 4);
3458 if (unlikely(!p))
3459 goto out_overflow;
3460 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003461 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003462 }
3463 return 0;
3464out_overflow:
3465 print_overflow_msg(__func__, xdr);
3466 return -EIO;
3467}
3468
Kinglong Mee8c612822015-08-26 21:12:58 +08003469static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3470 uint32_t *bitmap, uint32_t *bitmask)
3471{
3472 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3473 int ret;
3474 ret = decode_attr_bitmap(xdr, bitmask);
3475 if (unlikely(ret < 0))
3476 return ret;
3477 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3478 } else
3479 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3480 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3481 bitmask[0], bitmask[1], bitmask[2]);
3482 return 0;
3483}
3484
Bryan Schumakerae42c702010-10-21 16:33:17 -04003485static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3486{
3487 __be32 *p;
3488 int len;
3489
Trond Myklebust7ad07352010-10-23 15:34:20 -04003490 if (fh != NULL)
3491 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003492
3493 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3494 return -EIO;
3495 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3496 p = xdr_inline_decode(xdr, 4);
3497 if (unlikely(!p))
3498 goto out_overflow;
3499 len = be32_to_cpup(p);
3500 if (len > NFS4_FHSIZE)
3501 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003502 p = xdr_inline_decode(xdr, len);
3503 if (unlikely(!p))
3504 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003505 if (fh != NULL) {
3506 memcpy(fh->data, p, len);
3507 fh->size = len;
3508 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003509 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3510 }
3511 return 0;
3512out_overflow:
3513 print_overflow_msg(__func__, xdr);
3514 return -EIO;
3515}
3516
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3518{
Al Viro8687b632006-10-19 23:28:48 -07003519 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003521 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3523 return -EIO;
3524 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003525 p = xdr_inline_decode(xdr, 4);
3526 if (unlikely(!p))
3527 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003528 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3530 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003531 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003533out_overflow:
3534 print_overflow_msg(__func__, xdr);
3535 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536}
3537
3538static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3539{
Al Viro8687b632006-10-19 23:28:48 -07003540 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003541 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542
3543 *fileid = 0;
3544 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3545 return -EIO;
3546 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003547 p = xdr_inline_decode(xdr, 8);
3548 if (unlikely(!p))
3549 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003550 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003552 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003554 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003555 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003556out_overflow:
3557 print_overflow_msg(__func__, xdr);
3558 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559}
3560
Manoj Naik99baf622006-06-09 09:34:24 -04003561static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3562{
Al Viro8687b632006-10-19 23:28:48 -07003563 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003564 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003565
3566 *fileid = 0;
3567 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3568 return -EIO;
3569 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003570 p = xdr_inline_decode(xdr, 8);
3571 if (unlikely(!p))
3572 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003573 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003574 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003575 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003576 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003577 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003578 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003579out_overflow:
3580 print_overflow_msg(__func__, xdr);
3581 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003582}
3583
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3585{
Al Viro8687b632006-10-19 23:28:48 -07003586 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587 int status = 0;
3588
3589 *res = 0;
3590 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3591 return -EIO;
3592 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003593 p = xdr_inline_decode(xdr, 8);
3594 if (unlikely(!p))
3595 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003596 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3598 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003599 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003601out_overflow:
3602 print_overflow_msg(__func__, xdr);
3603 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604}
3605
3606static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3607{
Al Viro8687b632006-10-19 23:28:48 -07003608 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609 int status = 0;
3610
3611 *res = 0;
3612 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3613 return -EIO;
3614 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003615 p = xdr_inline_decode(xdr, 8);
3616 if (unlikely(!p))
3617 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003618 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3620 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003621 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003622 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003623out_overflow:
3624 print_overflow_msg(__func__, xdr);
3625 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626}
3627
3628static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3629{
Al Viro8687b632006-10-19 23:28:48 -07003630 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 int status = 0;
3632
3633 *res = 0;
3634 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3635 return -EIO;
3636 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003637 p = xdr_inline_decode(xdr, 8);
3638 if (unlikely(!p))
3639 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003640 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3642 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003643 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003645out_overflow:
3646 print_overflow_msg(__func__, xdr);
3647 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648}
3649
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003650static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3651{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003652 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003653 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003654 int status = 0;
3655
Benny Halevyc0eae662009-08-14 17:20:14 +03003656 p = xdr_inline_decode(xdr, 4);
3657 if (unlikely(!p))
3658 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003659 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003660 if (n == 0)
3661 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003662 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003663 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3664 dprintk("cannot parse %d components in path\n", n);
3665 goto out_eio;
3666 }
3667 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003668 struct nfs4_string *component = &path->components[path->ncomponents];
3669 status = decode_opaque_inline(xdr, &component->len, &component->data);
3670 if (unlikely(status != 0))
3671 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003672 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003673 pr_cont("%s%.*s ",
3674 (path->ncomponents != n ? "/ " : ""),
3675 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003676 }
3677out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003678 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003679root_path:
3680/* a root pathname is sent as a zero component4 */
3681 path->ncomponents = 1;
3682 path->components[0].len=0;
3683 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003684 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003685 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003686out_eio:
3687 dprintk(" status %d", status);
3688 status = -EIO;
3689 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003690out_overflow:
3691 print_overflow_msg(__func__, xdr);
3692 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003693}
3694
3695static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003696{
3697 int n;
Al Viro8687b632006-10-19 23:28:48 -07003698 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003699 int status = -EIO;
3700
3701 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3702 goto out;
3703 status = 0;
3704 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3705 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003706 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003707 status = -EIO;
3708 /* Ignore borken servers that return unrequested attrs */
3709 if (unlikely(res == NULL))
3710 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003711 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003712 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003713 if (unlikely(status != 0))
3714 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003715 p = xdr_inline_decode(xdr, 4);
3716 if (unlikely(!p))
3717 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003718 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003719 if (n <= 0)
3720 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003721 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003722 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003723 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003724
Trond Myklebust809b4262013-03-27 11:54:45 -04003725 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3726 break;
3727 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003728 p = xdr_inline_decode(xdr, 4);
3729 if (unlikely(!p))
3730 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003731 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003732
Chuck Lever02a29762012-03-01 17:00:31 -05003733 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003734 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3735 struct nfs4_string *server;
3736
3737 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003738 unsigned int i;
3739 dprintk("%s: using first %u of %u servers "
3740 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003741 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003742 NFS4_FS_LOCATION_MAXSERVERS,
3743 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003744 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003745 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003746 char *data;
3747 status = decode_opaque_inline(xdr, &len, &data);
3748 if (unlikely(status != 0))
3749 goto out_eio;
3750 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003751 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003752 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003753 server = &loc->servers[loc->nservers];
3754 status = decode_opaque_inline(xdr, &server->len, &server->data);
3755 if (unlikely(status != 0))
3756 goto out_eio;
3757 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003758 }
3759 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003760 if (unlikely(status != 0))
3761 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003762 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003763 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003764 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003765out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003766 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003767 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003768out_overflow:
3769 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003770out_eio:
3771 status = -EIO;
3772 goto out;
3773}
3774
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3776{
Al Viro8687b632006-10-19 23:28:48 -07003777 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778 int status = 0;
3779
3780 *res = 0;
3781 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3782 return -EIO;
3783 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003784 p = xdr_inline_decode(xdr, 8);
3785 if (unlikely(!p))
3786 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003787 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3789 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003790 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003792out_overflow:
3793 print_overflow_msg(__func__, xdr);
3794 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795}
3796
3797static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3798{
Al Viro8687b632006-10-19 23:28:48 -07003799 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 int status = 0;
3801
3802 *maxlink = 1;
3803 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3804 return -EIO;
3805 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003806 p = xdr_inline_decode(xdr, 4);
3807 if (unlikely(!p))
3808 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003809 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3811 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003812 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003814out_overflow:
3815 print_overflow_msg(__func__, xdr);
3816 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817}
3818
3819static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3820{
Al Viro8687b632006-10-19 23:28:48 -07003821 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 int status = 0;
3823
3824 *maxname = 1024;
3825 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3826 return -EIO;
3827 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003828 p = xdr_inline_decode(xdr, 4);
3829 if (unlikely(!p))
3830 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003831 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3833 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003834 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003836out_overflow:
3837 print_overflow_msg(__func__, xdr);
3838 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839}
3840
3841static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3842{
Al Viro8687b632006-10-19 23:28:48 -07003843 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 int status = 0;
3845
3846 *res = 1024;
3847 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3848 return -EIO;
3849 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3850 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003851 p = xdr_inline_decode(xdr, 8);
3852 if (unlikely(!p))
3853 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003854 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 if (maxread > 0x7FFFFFFF)
3856 maxread = 0x7FFFFFFF;
3857 *res = (uint32_t)maxread;
3858 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3859 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003860 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003862out_overflow:
3863 print_overflow_msg(__func__, xdr);
3864 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865}
3866
3867static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3868{
Al Viro8687b632006-10-19 23:28:48 -07003869 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 int status = 0;
3871
3872 *res = 1024;
3873 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3874 return -EIO;
3875 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3876 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003877 p = xdr_inline_decode(xdr, 8);
3878 if (unlikely(!p))
3879 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003880 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881 if (maxwrite > 0x7FFFFFFF)
3882 maxwrite = 0x7FFFFFFF;
3883 *res = (uint32_t)maxwrite;
3884 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3885 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003886 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003888out_overflow:
3889 print_overflow_msg(__func__, xdr);
3890 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891}
3892
Trond Myklebustbca79472009-03-11 14:10:26 -04003893static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894{
Trond Myklebustbca79472009-03-11 14:10:26 -04003895 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003896 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003897 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898
3899 *mode = 0;
3900 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3901 return -EIO;
3902 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003903 p = xdr_inline_decode(xdr, 4);
3904 if (unlikely(!p))
3905 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003906 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003907 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003909 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003911 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003912 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003913out_overflow:
3914 print_overflow_msg(__func__, xdr);
3915 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916}
3917
3918static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3919{
Al Viro8687b632006-10-19 23:28:48 -07003920 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003921 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922
3923 *nlink = 1;
3924 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3925 return -EIO;
3926 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003927 p = xdr_inline_decode(xdr, 4);
3928 if (unlikely(!p))
3929 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003930 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003932 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003934 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003935 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003936out_overflow:
3937 print_overflow_msg(__func__, xdr);
3938 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939}
3940
Trond Myklebust686a8162017-02-19 16:08:32 -05003941static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3942 struct nfs4_string *name, gfp_t gfp_flags)
3943{
3944 ssize_t ret;
3945
3946 ret = xdr_stream_decode_string_dup(xdr, &name->data,
3947 XDR_MAX_NETOBJ, gfp_flags);
3948 name->len = 0;
3949 if (ret > 0)
3950 name->len = ret;
3951 return ret;
3952}
3953
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003954static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003955 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003956 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957{
Trond Myklebust686a8162017-02-19 16:08:32 -05003958 ssize_t len;
3959 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960
Eric W. Biedermane5782072013-02-01 14:22:02 -08003961 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3963 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003964 if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3965 return 0;
3966 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3967
3968 if (owner_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04003969 len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05003970 if (len <= 0)
3971 goto out;
3972 dprintk("%s: name=%s\n", __func__, owner_name->data);
3973 return NFS_ATTR_FATTR_OWNER_NAME;
3974 } else {
3975 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3976 XDR_MAX_NETOBJ);
3977 if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3978 goto out;
3979 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3980 return NFS_ATTR_FATTR_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003982out:
3983 if (len != -EBADMSG)
3984 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003985 print_overflow_msg(__func__, xdr);
3986 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987}
3988
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003989static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003990 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003991 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992{
Trond Myklebust686a8162017-02-19 16:08:32 -05003993 ssize_t len;
3994 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995
Eric W. Biedermane5782072013-02-01 14:22:02 -08003996 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3998 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003999 if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
4000 return 0;
4001 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
4002
4003 if (group_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04004004 len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05004005 if (len <= 0)
4006 goto out;
4007 dprintk("%s: name=%s\n", __func__, group_name->data);
Kinglong Mee6f1f6222017-03-06 17:49:42 +08004008 return NFS_ATTR_FATTR_GROUP_NAME;
Trond Myklebust686a8162017-02-19 16:08:32 -05004009 } else {
4010 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
4011 XDR_MAX_NETOBJ);
4012 if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
4013 goto out;
4014 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
4015 return NFS_ATTR_FATTR_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 }
Trond Myklebust686a8162017-02-19 16:08:32 -05004017out:
4018 if (len != -EBADMSG)
4019 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004020 print_overflow_msg(__func__, xdr);
4021 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022}
4023
4024static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
4025{
Al Viro8687b632006-10-19 23:28:48 -07004026 uint32_t major = 0, minor = 0;
4027 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004028 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029
4030 *rdev = MKDEV(0,0);
4031 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
4032 return -EIO;
4033 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
4034 dev_t tmp;
4035
Benny Halevyc0eae662009-08-14 17:20:14 +03004036 p = xdr_inline_decode(xdr, 8);
4037 if (unlikely(!p))
4038 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004039 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004040 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041 tmp = MKDEV(major, minor);
4042 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
4043 *rdev = tmp;
4044 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04004045 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004047 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04004048 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004049out_overflow:
4050 print_overflow_msg(__func__, xdr);
4051 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052}
4053
4054static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4055{
Al Viro8687b632006-10-19 23:28:48 -07004056 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 int status = 0;
4058
4059 *res = 0;
4060 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
4061 return -EIO;
4062 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004063 p = xdr_inline_decode(xdr, 8);
4064 if (unlikely(!p))
4065 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004066 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4068 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004069 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004071out_overflow:
4072 print_overflow_msg(__func__, xdr);
4073 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074}
4075
4076static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4077{
Al Viro8687b632006-10-19 23:28:48 -07004078 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079 int status = 0;
4080
4081 *res = 0;
4082 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4083 return -EIO;
4084 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004085 p = xdr_inline_decode(xdr, 8);
4086 if (unlikely(!p))
4087 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004088 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4090 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004091 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004093out_overflow:
4094 print_overflow_msg(__func__, xdr);
4095 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096}
4097
4098static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4099{
Al Viro8687b632006-10-19 23:28:48 -07004100 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101 int status = 0;
4102
4103 *res = 0;
4104 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4105 return -EIO;
4106 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004107 p = xdr_inline_decode(xdr, 8);
4108 if (unlikely(!p))
4109 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004110 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4112 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004113 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004115out_overflow:
4116 print_overflow_msg(__func__, xdr);
4117 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118}
4119
4120static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4121{
Al Viro8687b632006-10-19 23:28:48 -07004122 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004123 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124
4125 *used = 0;
4126 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4127 return -EIO;
4128 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004129 p = xdr_inline_decode(xdr, 8);
4130 if (unlikely(!p))
4131 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004132 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004134 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004136 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004138 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004139out_overflow:
4140 print_overflow_msg(__func__, xdr);
4141 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142}
4143
Trond Myklebust36b37432018-03-20 17:03:10 -04004144static __be32 *
4145xdr_decode_nfstime4(__be32 *p, struct timespec *t)
4146{
4147 __u64 sec;
4148
4149 p = xdr_decode_hyper(p, &sec);
4150 t-> tv_sec = (time_t)sec;
4151 t->tv_nsec = be32_to_cpup(p++);
4152 return p;
4153}
4154
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4156{
Al Viro8687b632006-10-19 23:28:48 -07004157 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158
Trond Myklebust36b37432018-03-20 17:03:10 -04004159 p = xdr_inline_decode(xdr, nfstime4_maxsz << 2);
Benny Halevyc0eae662009-08-14 17:20:14 +03004160 if (unlikely(!p))
4161 goto out_overflow;
Trond Myklebust36b37432018-03-20 17:03:10 -04004162 xdr_decode_nfstime4(p, time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004164out_overflow:
4165 print_overflow_msg(__func__, xdr);
4166 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167}
4168
4169static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4170{
4171 int status = 0;
4172
4173 time->tv_sec = 0;
4174 time->tv_nsec = 0;
4175 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4176 return -EIO;
4177 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4178 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004179 if (status == 0)
4180 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4182 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004183 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 return status;
4185}
4186
4187static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4188{
4189 int status = 0;
4190
4191 time->tv_sec = 0;
4192 time->tv_nsec = 0;
4193 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4194 return -EIO;
4195 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4196 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004197 if (status == 0)
4198 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4200 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004201 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202 return status;
4203}
4204
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004205static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4206 struct timespec *time)
4207{
4208 int status = 0;
4209
4210 time->tv_sec = 0;
4211 time->tv_nsec = 0;
4212 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4213 return -EIO;
4214 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4215 status = decode_attr_time(xdr, time);
4216 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4217 }
4218 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4219 (long)time->tv_nsec);
4220 return status;
4221}
4222
David Quigleyaa9c2662013-05-22 12:50:44 -04004223static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4224 struct nfs4_label *label)
4225{
4226 uint32_t pi = 0;
4227 uint32_t lfs = 0;
4228 __u32 len;
4229 __be32 *p;
4230 int status = 0;
4231
4232 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4233 return -EIO;
4234 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4235 p = xdr_inline_decode(xdr, 4);
4236 if (unlikely(!p))
4237 goto out_overflow;
4238 lfs = be32_to_cpup(p++);
4239 p = xdr_inline_decode(xdr, 4);
4240 if (unlikely(!p))
4241 goto out_overflow;
4242 pi = be32_to_cpup(p++);
4243 p = xdr_inline_decode(xdr, 4);
4244 if (unlikely(!p))
4245 goto out_overflow;
4246 len = be32_to_cpup(p++);
4247 p = xdr_inline_decode(xdr, len);
4248 if (unlikely(!p))
4249 goto out_overflow;
4250 if (len < NFS4_MAXLABELLEN) {
4251 if (label) {
4252 memcpy(label->label, p, len);
4253 label->len = len;
4254 label->pi = pi;
4255 label->lfs = lfs;
4256 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4257 }
4258 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4259 } else
4260 printk(KERN_WARNING "%s: label too long (%u)!\n",
4261 __func__, len);
4262 }
4263 if (label && label->label)
4264 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4265 (char *)label->label, label->len, label->pi, label->lfs);
4266 return status;
4267
4268out_overflow:
4269 print_overflow_msg(__func__, xdr);
4270 return -EIO;
4271}
4272
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4274{
4275 int status = 0;
4276
4277 time->tv_sec = 0;
4278 time->tv_nsec = 0;
4279 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4280 return -EIO;
4281 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4282 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004283 if (status == 0)
4284 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4286 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004287 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288 return status;
4289}
4290
Trond Myklebust256e48b2012-06-21 11:18:13 -04004291static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292{
4293 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004294 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295
4296 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004297 dprintk("%s: server returned incorrect attribute length: "
4298 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004299 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300 attrwords << 2,
4301 (attrwords < nwords) ? '<' : '>',
4302 nwords << 2);
4303 return -EIO;
4304 }
4305 return 0;
4306}
4307
4308static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4309{
Al Viro8687b632006-10-19 23:28:48 -07004310 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311
Benny Halevyc0eae662009-08-14 17:20:14 +03004312 p = xdr_inline_decode(xdr, 20);
4313 if (unlikely(!p))
4314 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004315 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004316 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004317 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004319out_overflow:
4320 print_overflow_msg(__func__, xdr);
4321 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322}
4323
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004324static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325{
Al Viro8687b632006-10-19 23:28:48 -07004326 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327 uint32_t supp, acc;
4328 int status;
4329
4330 status = decode_op_hdr(xdr, OP_ACCESS);
4331 if (status)
4332 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004333 p = xdr_inline_decode(xdr, 8);
4334 if (unlikely(!p))
4335 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004336 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004337 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004338 *supported = supp;
4339 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004340 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004341out_overflow:
4342 print_overflow_msg(__func__, xdr);
4343 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004344}
4345
Benny Halevy07d30432009-08-14 17:19:52 +03004346static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004348 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4349 if (unlikely(ret < 0)) {
4350 print_overflow_msg(__func__, xdr);
4351 return -EIO;
Benny Halevy07d30432009-08-14 17:19:52 +03004352 }
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004353 return 0;
Benny Halevy07d30432009-08-14 17:19:52 +03004354}
4355
4356static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4357{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004358 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359}
4360
Trond Myklebust93b717f2016-05-16 17:42:43 -04004361static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4362{
4363 stateid->type = NFS4_OPEN_STATEID_TYPE;
4364 return decode_stateid(xdr, stateid);
4365}
4366
4367static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4368{
4369 stateid->type = NFS4_LOCK_STATEID_TYPE;
4370 return decode_stateid(xdr, stateid);
4371}
4372
4373static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4374{
4375 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4376 return decode_stateid(xdr, stateid);
4377}
4378
Trond Myklebustfcd88432017-11-07 12:39:44 -05004379static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4380{
4381 nfs4_stateid dummy;
4382
4383 nfs4_stateid_copy(stateid, &invalid_stateid);
4384 return decode_stateid(xdr, &dummy);
4385}
4386
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4388{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 int status;
4390
4391 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004392 if (status != -EIO)
4393 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004394 if (!status)
Trond Myklebustfcd88432017-11-07 12:39:44 -05004395 status = decode_invalid_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004396 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397}
4398
Benny Halevydb942bb2009-08-14 17:19:56 +03004399static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4400{
Chuck Levercd937102012-03-02 17:14:31 -05004401 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402}
4403
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004404static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4405{
4406 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4407}
4408
Fred Isaman0b7c0152012-04-20 14:47:39 -04004409static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411 int status;
4412
4413 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004414 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004415 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004416 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417}
4418
4419static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4420{
Al Viro8687b632006-10-19 23:28:48 -07004421 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422 uint32_t bmlen;
4423 int status;
4424
4425 status = decode_op_hdr(xdr, OP_CREATE);
4426 if (status)
4427 return status;
4428 if ((status = decode_change_info(xdr, cinfo)))
4429 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004430 p = xdr_inline_decode(xdr, 4);
4431 if (unlikely(!p))
4432 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004433 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004434 p = xdr_inline_decode(xdr, bmlen << 2);
4435 if (likely(p))
4436 return 0;
4437out_overflow:
4438 print_overflow_msg(__func__, xdr);
4439 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440}
4441
4442static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4443{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004444 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004445 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004446 int status;
4447
4448 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4449 goto xdr_error;
4450 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4451 goto xdr_error;
4452 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4453 goto xdr_error;
4454 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4455 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004456 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4457 &res->fh_expire_type)) != 0)
4458 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4460 goto xdr_error;
4461 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4462 goto xdr_error;
4463 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4464 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004465 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4466 res->exclcreat_bitmask)) != 0)
4467 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 status = verify_attr_len(xdr, savep, attrlen);
4469xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004470 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004471 return status;
4472}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004473
Linus Torvalds1da177e2005-04-16 15:20:36 -07004474static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4475{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004476 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004477 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004479
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4481 goto xdr_error;
4482 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4483 goto xdr_error;
4484 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4485 goto xdr_error;
4486
4487 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4488 goto xdr_error;
4489 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4490 goto xdr_error;
4491 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4492 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004493
4494 status = -EIO;
4495 if (unlikely(bitmap[0]))
4496 goto xdr_error;
4497
Linus Torvalds1da177e2005-04-16 15:20:36 -07004498 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4499 goto xdr_error;
4500 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4501 goto xdr_error;
4502 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4503 goto xdr_error;
4504
4505 status = verify_attr_len(xdr, savep, attrlen);
4506xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004507 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 return status;
4509}
4510
4511static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4512{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004513 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004514 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004516
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4518 goto xdr_error;
4519 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4520 goto xdr_error;
4521 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4522 goto xdr_error;
4523
4524 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4525 goto xdr_error;
4526 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4527 goto xdr_error;
4528
4529 status = verify_attr_len(xdr, savep, attrlen);
4530xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004531 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532 return status;
4533}
4534
Andy Adamson88034c32012-05-23 05:02:34 -04004535static int decode_threshold_hint(struct xdr_stream *xdr,
4536 uint32_t *bitmap,
4537 uint64_t *res,
4538 uint32_t hint_bit)
4539{
4540 __be32 *p;
4541
4542 *res = 0;
4543 if (likely(bitmap[0] & hint_bit)) {
4544 p = xdr_inline_decode(xdr, 8);
4545 if (unlikely(!p))
4546 goto out_overflow;
4547 xdr_decode_hyper(p, res);
4548 }
4549 return 0;
4550out_overflow:
4551 print_overflow_msg(__func__, xdr);
4552 return -EIO;
4553}
4554
4555static int decode_first_threshold_item4(struct xdr_stream *xdr,
4556 struct nfs4_threshold *res)
4557{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004558 __be32 *p;
4559 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004560 uint32_t bitmap[3] = {0,}, attrlen;
4561 int status;
4562
4563 /* layout type */
4564 p = xdr_inline_decode(xdr, 4);
4565 if (unlikely(!p)) {
4566 print_overflow_msg(__func__, xdr);
4567 return -EIO;
4568 }
4569 res->l_type = be32_to_cpup(p);
4570
4571 /* thi_hintset bitmap */
4572 status = decode_attr_bitmap(xdr, bitmap);
4573 if (status < 0)
4574 goto xdr_error;
4575
4576 /* thi_hintlist length */
4577 status = decode_attr_length(xdr, &attrlen, &savep);
4578 if (status < 0)
4579 goto xdr_error;
4580 /* thi_hintlist */
4581 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4582 if (status < 0)
4583 goto xdr_error;
4584 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4585 if (status < 0)
4586 goto xdr_error;
4587 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4588 THRESHOLD_RD_IO);
4589 if (status < 0)
4590 goto xdr_error;
4591 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4592 THRESHOLD_WR_IO);
4593 if (status < 0)
4594 goto xdr_error;
4595
4596 status = verify_attr_len(xdr, savep, attrlen);
4597 res->bm = bitmap[0];
4598
4599 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4600 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4601 res->wr_io_sz);
4602xdr_error:
4603 dprintk("%s ret=%d!\n", __func__, status);
4604 return status;
4605}
4606
4607/*
4608 * Thresholds on pNFS direct I/O vrs MDS I/O
4609 */
4610static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4611 uint32_t *bitmap,
4612 struct nfs4_threshold *res)
4613{
4614 __be32 *p;
4615 int status = 0;
4616 uint32_t num;
4617
4618 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4619 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004620 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004621 /* Did the server return an unrequested attribute? */
4622 if (unlikely(res == NULL))
4623 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004624 p = xdr_inline_decode(xdr, 4);
4625 if (unlikely(!p))
4626 goto out_overflow;
4627 num = be32_to_cpup(p);
4628 if (num == 0)
4629 return 0;
4630 if (num > 1)
4631 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4632 "drivers per filesystem not supported\n",
4633 __func__);
4634
4635 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004636 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004637 }
4638 return status;
4639out_overflow:
4640 print_overflow_msg(__func__, xdr);
4641 return -EIO;
4642}
4643
Bryan Schumakerae42c702010-10-21 16:33:17 -04004644static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4645 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004646 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004647 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648{
Trond Myklebustbca79472009-03-11 14:10:26 -04004649 int status;
4650 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004651 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004652 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004653
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004654 status = decode_attr_type(xdr, bitmap, &type);
4655 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004657 fattr->mode = 0;
4658 if (status != 0) {
4659 fattr->mode |= nfs_type2fmt[type];
4660 fattr->valid |= status;
4661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004663 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4664 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004666 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004667
4668 status = decode_attr_size(xdr, bitmap, &fattr->size);
4669 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004671 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004672
4673 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4674 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004675 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004676 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004677
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004678 err = 0;
4679 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004680 if (status < 0)
4681 goto xdr_error;
4682
4683 status = decode_attr_filehandle(xdr, bitmap, fh);
4684 if (status < 0)
4685 goto xdr_error;
4686
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004687 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4688 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004689 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004690 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004691
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004692 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004693 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004694 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004695 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004696
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004697 status = -EIO;
4698 if (unlikely(bitmap[0]))
4699 goto xdr_error;
4700
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004701 status = decode_attr_mode(xdr, bitmap, &fmode);
4702 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004704 if (status != 0) {
4705 fattr->mode |= fmode;
4706 fattr->valid |= status;
4707 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004708
4709 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4710 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004712 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004713
Trond Myklebust6926afd2012-01-07 13:22:46 -05004714 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004715 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004717 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004718
Trond Myklebust6926afd2012-01-07 13:22:46 -05004719 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004720 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004722 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004723
4724 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4725 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004727 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004728
4729 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4730 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004732 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004733
4734 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4735 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004737 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004738
4739 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4740 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004742 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004743
4744 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4745 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004747 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004748
Trond Myklebust28331a42011-04-27 13:47:52 -04004749 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004750 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004751 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004752 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004753
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004754 status = -EIO;
4755 if (unlikely(bitmap[1]))
4756 goto xdr_error;
4757
Andy Adamson88034c32012-05-23 05:02:34 -04004758 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4759 if (status < 0)
4760 goto xdr_error;
4761
David Quigleyaa9c2662013-05-22 12:50:44 -04004762 if (label) {
4763 status = decode_attr_security_label(xdr, bitmap, label);
4764 if (status < 0)
4765 goto xdr_error;
4766 fattr->valid |= status;
4767 }
4768
Bryan Schumakerae42c702010-10-21 16:33:17 -04004769xdr_error:
4770 dprintk("%s: xdr returned %d\n", __func__, -status);
4771 return status;
4772}
4773
4774static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004775 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004776 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004777{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004778 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004779 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004780 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004781 int status;
4782
4783 status = decode_op_hdr(xdr, OP_GETATTR);
4784 if (status < 0)
4785 goto xdr_error;
4786
4787 status = decode_attr_bitmap(xdr, bitmap);
4788 if (status < 0)
4789 goto xdr_error;
4790
4791 status = decode_attr_length(xdr, &attrlen, &savep);
4792 if (status < 0)
4793 goto xdr_error;
4794
David Quigleyaa9c2662013-05-22 12:50:44 -04004795 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4796 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004797 if (status < 0)
4798 goto xdr_error;
4799
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004800 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004802 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803 return status;
4804}
4805
David Quigleyaa9c2662013-05-22 12:50:44 -04004806static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4807 struct nfs4_label *label, const struct nfs_server *server)
4808{
4809 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4810}
4811
Bryan Schumakerae42c702010-10-21 16:33:17 -04004812static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004813 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004814{
David Quigleyaa9c2662013-05-22 12:50:44 -04004815 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004816}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817
Andy Adamson504913f2010-10-20 00:17:57 -04004818/*
Jeff Layton3132e492016-08-10 15:58:24 -04004819 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004820 */
Jeff Layton3132e492016-08-10 15:58:24 -04004821static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004822 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004823{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004824 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004825 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004826
4827 p = xdr_inline_decode(xdr, 4);
4828 if (unlikely(!p))
4829 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004830 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004831
4832 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004833 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004834 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004835
4836 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004837 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004838 if (unlikely(!p))
4839 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004840
4841 /* If we get too many, then just cap it at the max */
4842 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4843 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4844 __func__, fsinfo->nlayouttypes);
4845 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4846 }
4847
4848 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4849 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004850 return 0;
4851out_overflow:
4852 print_overflow_msg(__func__, xdr);
4853 return -EIO;
4854}
4855
4856/*
4857 * The type of file system exported.
4858 * Note we must ensure that layouttype is set in any non-error case.
4859 */
4860static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004861 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004862{
4863 int status = 0;
4864
4865 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4866 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4867 return -EIO;
4868 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004869 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004870 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004871 }
Andy Adamson504913f2010-10-20 00:17:57 -04004872 return status;
4873}
4874
Fred Isamandae100c2011-07-30 20:52:37 -04004875/*
4876 * The prefered block size for layout directed io
4877 */
4878static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4879 uint32_t *res)
4880{
4881 __be32 *p;
4882
4883 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4884 *res = 0;
4885 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4886 p = xdr_inline_decode(xdr, 4);
4887 if (unlikely(!p)) {
4888 print_overflow_msg(__func__, xdr);
4889 return -EIO;
4890 }
4891 *res = be32_to_cpup(p);
4892 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4893 }
4894 return 0;
4895}
4896
Peng Tao2a92ee92015-09-26 02:24:37 +08004897/*
4898 * The granularity of a CLONE operation.
4899 */
4900static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4901 uint32_t *res)
4902{
4903 __be32 *p;
4904
4905 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4906 *res = 0;
4907 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4908 p = xdr_inline_decode(xdr, 4);
4909 if (unlikely(!p)) {
4910 print_overflow_msg(__func__, xdr);
4911 return -EIO;
4912 }
4913 *res = be32_to_cpup(p);
4914 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4915 }
4916 return 0;
4917}
4918
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4920{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004921 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004922 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004923 int status;
4924
4925 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4926 goto xdr_error;
4927 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4928 goto xdr_error;
4929 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4930 goto xdr_error;
4931
4932 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4933
4934 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4935 goto xdr_error;
4936 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4937 goto xdr_error;
4938 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4939 goto xdr_error;
4940 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4941 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4942 goto xdr_error;
4943 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004944
4945 status = -EIO;
4946 if (unlikely(bitmap[0]))
4947 goto xdr_error;
4948
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004949 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4950 if (status != 0)
4951 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004952 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004953 if (status != 0)
4954 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004955
4956 status = -EIO;
4957 if (unlikely(bitmap[1]))
4958 goto xdr_error;
4959
Fred Isamandae100c2011-07-30 20:52:37 -04004960 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4961 if (status)
4962 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004963 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4964 if (status)
4965 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004966
4967 status = verify_attr_len(xdr, savep, attrlen);
4968xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004969 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970 return status;
4971}
4972
4973static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4974{
Al Viro8687b632006-10-19 23:28:48 -07004975 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976 uint32_t len;
4977 int status;
4978
Trond Myklebust99367812007-07-17 21:52:41 -04004979 /* Zero handle first to allow comparisons */
4980 memset(fh, 0, sizeof(*fh));
4981
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982 status = decode_op_hdr(xdr, OP_GETFH);
4983 if (status)
4984 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985
Benny Halevyc0eae662009-08-14 17:20:14 +03004986 p = xdr_inline_decode(xdr, 4);
4987 if (unlikely(!p))
4988 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004989 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990 if (len > NFS4_FHSIZE)
4991 return -EIO;
4992 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004993 p = xdr_inline_decode(xdr, len);
4994 if (unlikely(!p))
4995 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004996 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004997 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004998out_overflow:
4999 print_overflow_msg(__func__, xdr);
5000 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001}
5002
5003static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5004{
5005 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005006
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007 status = decode_op_hdr(xdr, OP_LINK);
5008 if (status)
5009 return status;
5010 return decode_change_info(xdr, cinfo);
5011}
5012
5013/*
5014 * We create the owner, so we know a proper owner.id length is 4.
5015 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005016static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005017{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005018 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07005019 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005020 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005021
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005022 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03005023 if (unlikely(!p))
5024 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005025 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03005026 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005027 type = be32_to_cpup(p++); /* 4 byte read */
5028 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005029 fl->fl_start = (loff_t)offset;
5030 fl->fl_end = fl->fl_start + (loff_t)length - 1;
5031 if (length == ~(uint64_t)0)
5032 fl->fl_end = OFFSET_MAX;
5033 fl->fl_type = F_WRLCK;
5034 if (type & 1)
5035 fl->fl_type = F_RDLCK;
5036 fl->fl_pid = 0;
5037 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005038 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
5039 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
5040 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03005041 if (likely(p))
5042 return -NFS4ERR_DENIED;
5043out_overflow:
5044 print_overflow_msg(__func__, xdr);
5045 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046}
5047
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005048static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050 int status;
5051
5052 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005053 if (status == -EIO)
5054 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005055 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04005056 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005057 if (unlikely(status))
5058 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005059 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04005060 status = decode_lock_denied(xdr, NULL);
5061 if (res->open_seqid != NULL)
5062 nfs_increment_open_seqid(status, res->open_seqid);
5063 nfs_increment_lock_seqid(status, res->lock_seqid);
5064out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005065 return status;
5066}
5067
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005068static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069{
5070 int status;
5071 status = decode_op_hdr(xdr, OP_LOCKT);
5072 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005073 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074 return status;
5075}
5076
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005077static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079 int status;
5080
5081 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005082 if (status != -EIO)
5083 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005084 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005085 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086 return status;
5087}
5088
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005089static int decode_release_lockowner(struct xdr_stream *xdr)
5090{
5091 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5092}
5093
Linus Torvalds1da177e2005-04-16 15:20:36 -07005094static int decode_lookup(struct xdr_stream *xdr)
5095{
5096 return decode_op_hdr(xdr, OP_LOOKUP);
5097}
5098
Jeff Layton5b5faaf2017-06-29 06:34:52 -07005099static int decode_lookupp(struct xdr_stream *xdr)
5100{
5101 return decode_op_hdr(xdr, OP_LOOKUPP);
5102}
5103
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005105static int decode_space_limit(struct xdr_stream *xdr,
5106 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107{
Andy Adamson05d564f2008-12-23 16:06:15 -05005108 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005110 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111
Benny Halevyc0eae662009-08-14 17:20:14 +03005112 p = xdr_inline_decode(xdr, 12);
5113 if (unlikely(!p))
5114 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005115 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005117 case NFS4_LIMIT_SIZE:
5118 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005119 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005120 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005121 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005122 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005123 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005124 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005125 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005126 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005128out_overflow:
5129 print_overflow_msg(__func__, xdr);
5130 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005131}
5132
Trond Myklebust6ae37332015-01-30 14:21:14 -05005133static int decode_rw_delegation(struct xdr_stream *xdr,
5134 uint32_t delegation_type,
5135 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136{
Andy Adamson05d564f2008-12-23 16:06:15 -05005137 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005138 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139
Trond Myklebust93b717f2016-05-16 17:42:43 -04005140 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005141 if (unlikely(status))
5142 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005143 p = xdr_inline_decode(xdr, 4);
5144 if (unlikely(!p))
5145 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005146 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005147
Linus Torvalds1da177e2005-04-16 15:20:36 -07005148 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005149 case NFS4_OPEN_DELEGATE_READ:
5150 res->delegation_type = FMODE_READ;
5151 break;
5152 case NFS4_OPEN_DELEGATE_WRITE:
5153 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005154 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155 return -EIO;
5156 }
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05005157 return decode_ace(xdr, NULL);
Benny Halevyc0eae662009-08-14 17:20:14 +03005158out_overflow:
5159 print_overflow_msg(__func__, xdr);
5160 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005161}
5162
Trond Myklebust6ae37332015-01-30 14:21:14 -05005163static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5164{
5165 __be32 *p;
5166 uint32_t why_no_delegation;
5167
5168 p = xdr_inline_decode(xdr, 4);
5169 if (unlikely(!p))
5170 goto out_overflow;
5171 why_no_delegation = be32_to_cpup(p);
5172 switch (why_no_delegation) {
5173 case WND4_CONTENTION:
5174 case WND4_RESOURCE:
5175 xdr_inline_decode(xdr, 4);
5176 /* Ignore for now */
5177 }
5178 return 0;
5179out_overflow:
5180 print_overflow_msg(__func__, xdr);
5181 return -EIO;
5182}
5183
5184static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5185{
5186 __be32 *p;
5187 uint32_t delegation_type;
5188
5189 p = xdr_inline_decode(xdr, 4);
5190 if (unlikely(!p))
5191 goto out_overflow;
5192 delegation_type = be32_to_cpup(p);
5193 res->delegation_type = 0;
5194 switch (delegation_type) {
5195 case NFS4_OPEN_DELEGATE_NONE:
5196 return 0;
5197 case NFS4_OPEN_DELEGATE_READ:
5198 case NFS4_OPEN_DELEGATE_WRITE:
5199 return decode_rw_delegation(xdr, delegation_type, res);
5200 case NFS4_OPEN_DELEGATE_NONE_EXT:
5201 return decode_no_delegation(xdr, res);
5202 }
5203 return -EIO;
5204out_overflow:
5205 print_overflow_msg(__func__, xdr);
5206 return -EIO;
5207}
5208
Linus Torvalds1da177e2005-04-16 15:20:36 -07005209static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5210{
Andy Adamson05d564f2008-12-23 16:06:15 -05005211 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005212 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005213 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214
Trond Myklebustc7848f62013-12-04 17:39:23 -05005215 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5216 return status;
5217 nfs_increment_open_seqid(status, res->seqid);
5218 if (status)
5219 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005220 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005221 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005222 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223
Andy Adamson05d564f2008-12-23 16:06:15 -05005224 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005225
Benny Halevyc0eae662009-08-14 17:20:14 +03005226 p = xdr_inline_decode(xdr, 8);
5227 if (unlikely(!p))
5228 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005229 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005230 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005231 if (bmlen > 10)
5232 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005233
Benny Halevyc0eae662009-08-14 17:20:14 +03005234 p = xdr_inline_decode(xdr, bmlen << 2);
5235 if (unlikely(!p))
5236 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005237 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5238 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005239 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005240 for (; i < NFS4_BITMAP_SIZE; i++)
5241 res->attrset[i] = 0;
5242
Linus Torvalds1da177e2005-04-16 15:20:36 -07005243 return decode_delegation(xdr, res);
5244xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005245 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005246 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005247out_overflow:
5248 print_overflow_msg(__func__, xdr);
5249 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250}
5251
5252static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5253{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254 int status;
5255
Andy Adamson05d564f2008-12-23 16:06:15 -05005256 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005257 if (status != -EIO)
5258 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005259 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005260 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005261 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262}
5263
5264static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5265{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266 int status;
5267
5268 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005269 if (status != -EIO)
5270 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005271 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005272 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005273 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274}
5275
5276static int decode_putfh(struct xdr_stream *xdr)
5277{
5278 return decode_op_hdr(xdr, OP_PUTFH);
5279}
5280
5281static int decode_putrootfh(struct xdr_stream *xdr)
5282{
5283 return decode_op_hdr(xdr, OP_PUTROOTFH);
5284}
5285
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005286static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5287 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005288{
Al Viro8687b632006-10-19 23:28:48 -07005289 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005290 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005291 int status;
5292
5293 status = decode_op_hdr(xdr, OP_READ);
5294 if (status)
5295 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005296 p = xdr_inline_decode(xdr, 8);
5297 if (unlikely(!p))
5298 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005299 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005300 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005301 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005303 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005304 "count %u > recvd %u\n", count, recvd);
5305 count = recvd;
5306 eof = 0;
5307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005308 res->eof = eof;
5309 res->count = count;
5310 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005311out_overflow:
5312 print_overflow_msg(__func__, xdr);
5313 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005314}
5315
5316static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5317{
Chuck Leverbcecff72007-10-26 13:32:03 -04005318 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005319 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005320
5321 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005322 if (!status)
5323 status = decode_verifier(xdr, readdir->verifier.data);
5324 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005326 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005327 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005328 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005329 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005330}
5331
5332static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5333{
5334 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005335 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005336 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005337 int status;
5338
5339 status = decode_op_hdr(xdr, OP_READLINK);
5340 if (status)
5341 return status;
5342
5343 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005344 p = xdr_inline_decode(xdr, 4);
5345 if (unlikely(!p))
5346 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005347 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005348 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005349 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005350 return -ENAMETOOLONG;
5351 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005352 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005353 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005354 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005355 "count %u > recvd %u\n", len, recvd);
5356 return -EIO;
5357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005358 /*
5359 * The XDR encode routine has set things up so that
5360 * the link text will be copied directly into the
5361 * buffer. We just have to do overflow-checking,
5362 * and and null-terminate the text (the VFS expects
5363 * null-termination).
5364 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005365 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005366 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005367out_overflow:
5368 print_overflow_msg(__func__, xdr);
5369 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005370}
5371
5372static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5373{
5374 int status;
5375
5376 status = decode_op_hdr(xdr, OP_REMOVE);
5377 if (status)
5378 goto out;
5379 status = decode_change_info(xdr, cinfo);
5380out:
5381 return status;
5382}
5383
5384static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5385 struct nfs4_change_info *new_cinfo)
5386{
5387 int status;
5388
5389 status = decode_op_hdr(xdr, OP_RENAME);
5390 if (status)
5391 goto out;
5392 if ((status = decode_change_info(xdr, old_cinfo)))
5393 goto out;
5394 status = decode_change_info(xdr, new_cinfo);
5395out:
5396 return status;
5397}
5398
5399static int decode_renew(struct xdr_stream *xdr)
5400{
5401 return decode_op_hdr(xdr, OP_RENEW);
5402}
5403
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005404static int
5405decode_restorefh(struct xdr_stream *xdr)
5406{
5407 return decode_op_hdr(xdr, OP_RESTOREFH);
5408}
5409
J. Bruce Fields029d1052005-06-22 17:16:22 +00005410static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005411 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005412{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005413 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005414 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005415 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005416 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005417 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005418
Andy Adamsonbf118a32011-12-07 11:55:27 -05005419 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005420 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5421 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005422
Trond Myklebust519d3952012-08-14 17:30:10 -04005423 xdr_enter_page(xdr, xdr->buf->page_len);
5424
Trond Myklebustcff298c2012-08-14 17:14:17 -04005425 /* Calculate the offset of the page data */
5426 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005427
J. Bruce Fields029d1052005-06-22 17:16:22 +00005428 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5429 goto out;
5430 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5431 goto out;
5432
5433 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5434 return -EIO;
5435 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005436
Andy Adamsonbf118a32011-12-07 11:55:27 -05005437 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5438 * are stored with the acl data to handle the problem of
5439 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005440 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005441 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005442
5443 /* Check for receive buffer overflow */
5444 if (res->acl_len > (xdr->nwords << 2) ||
5445 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5446 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005447 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005448 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005449 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005450 } else
5451 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005452
5453out:
5454 return status;
5455}
5456
Linus Torvalds1da177e2005-04-16 15:20:36 -07005457static int
5458decode_savefh(struct xdr_stream *xdr)
5459{
5460 return decode_op_hdr(xdr, OP_SAVEFH);
5461}
5462
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005463static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005464{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005465 int status;
5466
Linus Torvalds1da177e2005-04-16 15:20:36 -07005467 status = decode_op_hdr(xdr, OP_SETATTR);
5468 if (status)
5469 return status;
Trond Myklebust37c88762018-03-20 17:03:08 -04005470 if (decode_bitmap4(xdr, NULL, 0) >= 0)
Benny Halevyc0eae662009-08-14 17:20:14 +03005471 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005472 print_overflow_msg(__func__, xdr);
5473 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005474}
5475
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005476static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005477{
Al Viro8687b632006-10-19 23:28:48 -07005478 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005479 uint32_t opnum;
5480 int32_t nfserr;
5481
Benny Halevyc0eae662009-08-14 17:20:14 +03005482 p = xdr_inline_decode(xdr, 8);
5483 if (unlikely(!p))
5484 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005485 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005486 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005487 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005488 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005489 return -EIO;
5490 }
Benny Halevycccddf42009-08-14 17:20:19 +03005491 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005492 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005493 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5494 if (unlikely(!p))
5495 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005496 p = xdr_decode_hyper(p, &res->clientid);
5497 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005498 } else if (nfserr == NFSERR_CLID_INUSE) {
5499 uint32_t len;
5500
5501 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005502 p = xdr_inline_decode(xdr, 4);
5503 if (unlikely(!p))
5504 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005505 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005506 p = xdr_inline_decode(xdr, len);
5507 if (unlikely(!p))
5508 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005509
5510 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005511 p = xdr_inline_decode(xdr, 4);
5512 if (unlikely(!p))
5513 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005514 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005515 p = xdr_inline_decode(xdr, len);
5516 if (unlikely(!p))
5517 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005518 return -NFSERR_CLID_INUSE;
5519 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005520 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005521
5522 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005523out_overflow:
5524 print_overflow_msg(__func__, xdr);
5525 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005526}
5527
5528static int decode_setclientid_confirm(struct xdr_stream *xdr)
5529{
5530 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5531}
5532
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005533static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005534{
Al Viro8687b632006-10-19 23:28:48 -07005535 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005536 int status;
5537
5538 status = decode_op_hdr(xdr, OP_WRITE);
5539 if (status)
5540 return status;
5541
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005542 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005543 if (unlikely(!p))
5544 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005545 res->count = be32_to_cpup(p++);
5546 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005547 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005548out_overflow:
5549 print_overflow_msg(__func__, xdr);
5550 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005551}
5552
5553static int decode_delegreturn(struct xdr_stream *xdr)
5554{
5555 return decode_op_hdr(xdr, OP_DELEGRETURN);
5556}
5557
Chuck Leverfb15b262013-03-16 15:54:34 -04005558static int decode_secinfo_gss(struct xdr_stream *xdr,
5559 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005560{
Chuck Leverfb15b262013-03-16 15:54:34 -04005561 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005562 __be32 *p;
5563
5564 p = xdr_inline_decode(xdr, 4);
5565 if (unlikely(!p))
5566 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005567 oid_len = be32_to_cpup(p);
5568 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005569 goto out_err;
5570
Chuck Leverfb15b262013-03-16 15:54:34 -04005571 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005572 if (unlikely(!p))
5573 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005574 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5575 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005576
5577 p = xdr_inline_decode(xdr, 8);
5578 if (unlikely(!p))
5579 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005580 flavor->flavor_info.qop = be32_to_cpup(p++);
5581 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005582
5583 return 0;
5584
5585out_overflow:
5586 print_overflow_msg(__func__, xdr);
5587 return -EIO;
5588out_err:
5589 return -EINVAL;
5590}
5591
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005592static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005593{
Chuck Leverfb15b262013-03-16 15:54:34 -04005594 struct nfs4_secinfo4 *sec_flavor;
5595 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005596 int status;
5597 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005598
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005599 p = xdr_inline_decode(xdr, 4);
5600 if (unlikely(!p))
5601 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005602
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005603 res->flavors->num_flavors = 0;
5604 num_flavors = be32_to_cpup(p);
5605
5606 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005607 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005608 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005609 break;
5610
5611 p = xdr_inline_decode(xdr, 4);
5612 if (unlikely(!p))
5613 goto out_overflow;
5614 sec_flavor->flavor = be32_to_cpup(p);
5615
5616 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005617 status = decode_secinfo_gss(xdr, sec_flavor);
5618 if (status)
5619 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005620 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005621 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005622 }
5623
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005624 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005625out:
5626 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005627out_overflow:
5628 print_overflow_msg(__func__, xdr);
5629 return -EIO;
5630}
5631
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005632static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5633{
5634 int status = decode_op_hdr(xdr, OP_SECINFO);
5635 if (status)
5636 return status;
5637 return decode_secinfo_common(xdr, res);
5638}
5639
Benny Halevy99fe60d2009-04-01 09:22:29 -04005640#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005641static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5642{
5643 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5644 if (status)
5645 return status;
5646 return decode_secinfo_common(xdr, res);
5647}
5648
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005649static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5650{
5651 __be32 *p;
5652 uint32_t bitmap_words;
5653 unsigned int i;
5654
5655 p = xdr_inline_decode(xdr, 4);
Pan Bian4edabfd2017-04-23 14:49:41 +08005656 if (!p)
5657 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005658 bitmap_words = be32_to_cpup(p++);
5659 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5660 return -EIO;
5661 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5662 for (i = 0; i < bitmap_words; i++)
5663 op_map->u.words[i] = be32_to_cpup(p++);
5664
5665 return 0;
5666}
5667
Benny Halevy99fe60d2009-04-01 09:22:29 -04005668static int decode_exchange_id(struct xdr_stream *xdr,
5669 struct nfs41_exchange_id_res *res)
5670{
5671 __be32 *p;
5672 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005673 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005674 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005675 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005676
5677 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5678 if (status)
5679 return status;
5680
Benny Halevyc0eae662009-08-14 17:20:14 +03005681 p = xdr_inline_decode(xdr, 8);
5682 if (unlikely(!p))
5683 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005684 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005685 p = xdr_inline_decode(xdr, 12);
5686 if (unlikely(!p))
5687 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005688 res->seqid = be32_to_cpup(p++);
5689 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005690
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005691 res->state_protect.how = be32_to_cpup(p);
5692 switch (res->state_protect.how) {
5693 case SP4_NONE:
5694 break;
5695 case SP4_MACH_CRED:
5696 status = decode_op_map(xdr, &res->state_protect.enforce);
5697 if (status)
5698 return status;
5699 status = decode_op_map(xdr, &res->state_protect.allow);
5700 if (status)
5701 return status;
5702 break;
5703 default:
5704 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005705 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005706 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005707
Chuck Leveracdeb692012-05-21 22:46:16 -04005708 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005709 p = xdr_inline_decode(xdr, 8);
5710 if (unlikely(!p))
5711 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005712 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005713
Chuck Leveracdeb692012-05-21 22:46:16 -04005714 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005715 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5716 if (unlikely(status))
5717 return status;
Chuck Leveracdeb692012-05-21 22:46:16 -04005718 memcpy(res->server_owner->major_id, dummy_str, dummy);
5719 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005720
Chuck Leveracdeb692012-05-21 22:46:16 -04005721 /* server_scope4 */
5722 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5723 if (unlikely(status))
5724 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005725 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5726 res->server_scope->server_scope_sz = dummy;
5727
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005728 /* Implementation Id */
5729 p = xdr_inline_decode(xdr, 4);
5730 if (unlikely(!p))
5731 goto out_overflow;
5732 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005733
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005734 if (impl_id_count) {
5735 /* nii_domain */
5736 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5737 if (unlikely(status))
5738 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005739 memcpy(res->impl_id->domain, dummy_str, dummy);
5740
5741 /* nii_name */
5742 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5743 if (unlikely(status))
5744 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005745 memcpy(res->impl_id->name, dummy_str, dummy);
5746
5747 /* nii_date */
5748 p = xdr_inline_decode(xdr, 12);
5749 if (unlikely(!p))
5750 goto out_overflow;
5751 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5752 res->impl_id->date.nseconds = be32_to_cpup(p);
5753
5754 /* if there's more than one entry, ignore the rest */
5755 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005756 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005757out_overflow:
5758 print_overflow_msg(__func__, xdr);
5759 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005760}
Andy Adamsonfc931582009-04-01 09:22:31 -04005761
5762static int decode_chan_attrs(struct xdr_stream *xdr,
5763 struct nfs4_channel_attrs *attrs)
5764{
5765 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005766 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005767
Benny Halevyc0eae662009-08-14 17:20:14 +03005768 p = xdr_inline_decode(xdr, 28);
5769 if (unlikely(!p))
5770 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005771 val = be32_to_cpup(p++); /* headerpadsz */
5772 if (val)
5773 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005774 attrs->max_rqst_sz = be32_to_cpup(p++);
5775 attrs->max_resp_sz = be32_to_cpup(p++);
5776 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5777 attrs->max_ops = be32_to_cpup(p++);
5778 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005779 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005780 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005781 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5782 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005783 return -EINVAL;
5784 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005785 if (nr_attrs == 1) {
5786 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5787 if (unlikely(!p))
5788 goto out_overflow;
5789 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005790 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005791out_overflow:
5792 print_overflow_msg(__func__, xdr);
5793 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005794}
5795
Benny Halevye78291e2009-08-14 17:20:00 +03005796static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5797{
5798 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005799}
5800
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005801static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5802 struct nfs41_bind_conn_to_session_res *res)
5803{
5804 __be32 *p;
5805 int status;
5806
5807 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5808 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005809 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005810 if (unlikely(status))
5811 return status;
5812
5813 /* dir flags, rdma mode bool */
5814 p = xdr_inline_decode(xdr, 8);
5815 if (unlikely(!p))
5816 goto out_overflow;
5817
5818 res->dir = be32_to_cpup(p++);
5819 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5820 return -EIO;
5821 if (be32_to_cpup(p) == 0)
5822 res->use_conn_in_rdma_mode = false;
5823 else
5824 res->use_conn_in_rdma_mode = true;
5825
5826 return 0;
5827out_overflow:
5828 print_overflow_msg(__func__, xdr);
5829 return -EIO;
5830}
5831
Andy Adamsonfc931582009-04-01 09:22:31 -04005832static int decode_create_session(struct xdr_stream *xdr,
5833 struct nfs41_create_session_res *res)
5834{
5835 __be32 *p;
5836 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005837
5838 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005839 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005840 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005841 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005842 return status;
5843
Andy Adamsonfc931582009-04-01 09:22:31 -04005844 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005845 p = xdr_inline_decode(xdr, 8);
5846 if (unlikely(!p))
5847 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005848 res->seqid = be32_to_cpup(p++);
5849 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005850
5851 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005852 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005853 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005854 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005855 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005856out_overflow:
5857 print_overflow_msg(__func__, xdr);
5858 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005859}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005860
5861static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5862{
5863 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5864}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005865
Trond Myklebust66245532012-05-25 17:18:09 -04005866static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5867{
5868 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5869}
5870
Ricardo Labiaga180197532009-12-05 16:08:40 -05005871static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5872{
5873 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5874}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005875#endif /* CONFIG_NFS_V4_1 */
5876
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005877static int decode_sequence(struct xdr_stream *xdr,
5878 struct nfs4_sequence_res *res,
5879 struct rpc_rqst *rqstp)
5880{
5881#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005882 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005883 struct nfs4_sessionid id;
5884 u32 dummy;
5885 int status;
5886 __be32 *p;
5887
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005888 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005889 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005890 if (!res->sr_slot->table->session)
5891 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005892
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005893 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005894 if (!status)
5895 status = decode_sessionid(xdr, &id);
5896 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005897 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005898
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005899 /*
5900 * If the server returns different values for sessionID, slotID or
5901 * sequence number, the server is looney tunes.
5902 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005903 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005904 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005905
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005906 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005907 NFS4_MAX_SESSIONID_LEN)) {
5908 dprintk("%s Invalid session id\n", __func__);
5909 goto out_err;
5910 }
Benny Halevye78291e2009-08-14 17:20:00 +03005911
Benny Halevyc0eae662009-08-14 17:20:14 +03005912 p = xdr_inline_decode(xdr, 20);
5913 if (unlikely(!p))
5914 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005915
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005916 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005917 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005918 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005919 dprintk("%s Invalid sequence number\n", __func__);
5920 goto out_err;
5921 }
5922 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005923 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005924 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005925 dprintk("%s Invalid slot id\n", __func__);
5926 goto out_err;
5927 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005928 /* highest slot id */
5929 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005930 /* target highest slot id */
5931 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005932 /* result flags */
5933 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005934 status = 0;
5935out_err:
5936 res->sr_status = status;
5937 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005938out_overflow:
5939 print_overflow_msg(__func__, xdr);
5940 status = -EIO;
5941 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005942#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005943 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005944#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005945}
5946
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005947#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005948static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5949{
5950 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5951 return decode_stateid(xdr, stateid);
5952}
5953
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005954static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005955 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005956{
Trond Myklebust4e590802015-03-09 14:01:25 -04005957 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005958 __be32 *p;
5959 uint32_t len, type;
5960 int status;
5961
5962 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5963 if (status) {
5964 if (status == -ETOOSMALL) {
5965 p = xdr_inline_decode(xdr, 4);
5966 if (unlikely(!p))
5967 goto out_overflow;
5968 pdev->mincount = be32_to_cpup(p);
5969 dprintk("%s: Min count too small. mincnt = %u\n",
5970 __func__, pdev->mincount);
5971 }
5972 return status;
5973 }
5974
5975 p = xdr_inline_decode(xdr, 8);
5976 if (unlikely(!p))
5977 goto out_overflow;
5978 type = be32_to_cpup(p++);
5979 if (type != pdev->layout_type) {
5980 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5981 __func__, pdev->layout_type, type);
5982 return -EINVAL;
5983 }
5984 /*
5985 * Get the length of the opaque device_addr4. xdr_read_pages places
5986 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5987 * and places the remaining xdr data in xdr_buf->tail
5988 */
5989 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005990 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5991 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005992
5993 /* Parse notification bitmap, verifying that it is zero. */
5994 p = xdr_inline_decode(xdr, 4);
5995 if (unlikely(!p))
5996 goto out_overflow;
5997 len = be32_to_cpup(p);
5998 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005999 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006000
6001 p = xdr_inline_decode(xdr, 4 * len);
6002 if (unlikely(!p))
6003 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07006004
Trond Myklebust4e590802015-03-09 14:01:25 -04006005 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07006006 for (i = 1; i < len; i++) {
6007 if (be32_to_cpup(p++)) {
6008 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006009 __func__);
6010 return -EIO;
6011 }
6012 }
6013 }
6014 return 0;
6015out_overflow:
6016 print_overflow_msg(__func__, xdr);
6017 return -EIO;
6018}
6019
6020static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6021 struct nfs4_layoutget_res *res)
6022{
6023 __be32 *p;
6024 int status;
6025 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04006026 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006027
6028 status = decode_op_hdr(xdr, OP_LAYOUTGET);
6029 if (status)
6030 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006031 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006032 if (unlikely(!p))
6033 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006034 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04006035 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006036 p = xdr_inline_decode(xdr, 4);
6037 if (unlikely(!p))
6038 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006039 layout_count = be32_to_cpup(p);
6040 if (!layout_count) {
6041 dprintk("%s: server responded with empty layout array\n",
6042 __func__);
6043 return -EINVAL;
6044 }
6045
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006046 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006047 if (unlikely(!p))
6048 goto out_overflow;
6049 p = xdr_decode_hyper(p, &res->range.offset);
6050 p = xdr_decode_hyper(p, &res->range.length);
6051 res->range.iomode = be32_to_cpup(p++);
6052 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006053 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006054
6055 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
6056 __func__,
6057 (unsigned long)res->range.offset,
6058 (unsigned long)res->range.length,
6059 res->range.iomode,
6060 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006061 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006062
Trond Myklebust64bd5772012-06-20 22:35:05 -04006063 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006064 if (res->layoutp->len > recvd) {
6065 dprintk("NFS: server cheating in layoutget reply: "
6066 "layout len %u > recvd %u\n",
6067 res->layoutp->len, recvd);
6068 return -EINVAL;
6069 }
6070
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006071 if (layout_count > 1) {
6072 /* We only handle a length one array at the moment. Any
6073 * further entries are just ignored. Note that this means
6074 * the client may see a response that is less than the
6075 * minimum it requested.
6076 */
6077 dprintk("%s: server responded with %d layouts, dropping tail\n",
6078 __func__, layout_count);
6079 }
6080
6081 return 0;
6082out_overflow:
6083 print_overflow_msg(__func__, xdr);
6084 return -EIO;
6085}
Andy Adamson863a3c62011-03-23 13:27:54 +00006086
Benny Halevycbe82602011-05-22 19:52:37 +03006087static int decode_layoutreturn(struct xdr_stream *xdr,
6088 struct nfs4_layoutreturn_res *res)
6089{
6090 __be32 *p;
6091 int status;
6092
6093 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6094 if (status)
6095 return status;
6096 p = xdr_inline_decode(xdr, 4);
6097 if (unlikely(!p))
6098 goto out_overflow;
6099 res->lrs_present = be32_to_cpup(p);
6100 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04006101 status = decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustfcd88432017-11-07 12:39:44 -05006102 else
6103 nfs4_stateid_copy(&res->stateid, &invalid_stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03006104 return status;
6105out_overflow:
6106 print_overflow_msg(__func__, xdr);
6107 return -EIO;
6108}
6109
Andy Adamson863a3c62011-03-23 13:27:54 +00006110static int decode_layoutcommit(struct xdr_stream *xdr,
6111 struct rpc_rqst *req,
6112 struct nfs4_layoutcommit_res *res)
6113{
6114 __be32 *p;
6115 __u32 sizechanged;
6116 int status;
6117
6118 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04006119 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00006120 if (status)
6121 return status;
6122
6123 p = xdr_inline_decode(xdr, 4);
6124 if (unlikely(!p))
6125 goto out_overflow;
6126 sizechanged = be32_to_cpup(p);
6127
6128 if (sizechanged) {
6129 /* throw away new size */
6130 p = xdr_inline_decode(xdr, 8);
6131 if (unlikely(!p))
6132 goto out_overflow;
6133 }
6134 return 0;
6135out_overflow:
6136 print_overflow_msg(__func__, xdr);
6137 return -EIO;
6138}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006139
6140static int decode_test_stateid(struct xdr_stream *xdr,
6141 struct nfs41_test_stateid_res *res)
6142{
6143 __be32 *p;
6144 int status;
6145 int num_res;
6146
6147 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6148 if (status)
6149 return status;
6150
6151 p = xdr_inline_decode(xdr, 4);
6152 if (unlikely(!p))
6153 goto out_overflow;
6154 num_res = be32_to_cpup(p++);
6155 if (num_res != 1)
6156 goto out;
6157
6158 p = xdr_inline_decode(xdr, 4);
6159 if (unlikely(!p))
6160 goto out_overflow;
6161 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006162
6163 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006164out_overflow:
6165 print_overflow_msg(__func__, xdr);
6166out:
6167 return -EIO;
6168}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006169
6170static int decode_free_stateid(struct xdr_stream *xdr,
6171 struct nfs41_free_stateid_res *res)
6172{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006173 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006174 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006175}
Trond Myklebustcf805162016-11-15 14:56:07 -05006176#else
6177static inline
6178int decode_layoutreturn(struct xdr_stream *xdr,
6179 struct nfs4_layoutreturn_res *res)
6180{
6181 return 0;
6182}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006183#endif /* CONFIG_NFS_V4_1 */
6184
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185/*
Benny Halevy49c25592008-12-23 16:06:16 -05006186 * END OF "GENERIC" DECODE ROUTINES.
6187 */
6188
6189/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006190 * Decode OPEN_DOWNGRADE response
6191 */
Chuck Leverbf269552010-12-14 14:59:29 +00006192static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6193 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006194 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006196 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006197 struct compound_hdr hdr;
6198 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006199
Chuck Leverbf269552010-12-14 14:59:29 +00006200 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006201 if (status)
6202 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006203 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006204 if (status)
6205 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006206 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006207 if (status)
6208 goto out;
Trond Myklebustb6808142016-11-20 13:34:16 -05006209 if (res->lr_res) {
6210 status = decode_layoutreturn(xdr, res->lr_res);
6211 res->lr_ret = status;
6212 if (status)
6213 goto out;
6214 }
Chuck Leverbf269552010-12-14 14:59:29 +00006215 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006217 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218}
6219
6220/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221 * Decode ACCESS response
6222 */
Chuck Leverbf269552010-12-14 14:59:29 +00006223static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006224 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006226 struct nfs4_accessres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227 struct compound_hdr hdr;
6228 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006229
Chuck Leverbf269552010-12-14 14:59:29 +00006230 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006231 if (status)
6232 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006233 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006234 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006236 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006237 if (status != 0)
6238 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006239 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006240 if (status != 0)
6241 goto out;
Trond Myklebust8bcbe7d2018-03-20 17:03:11 -04006242 if (res->fattr)
6243 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006244out:
6245 return status;
6246}
6247
6248/*
6249 * Decode LOOKUP response
6250 */
Chuck Leverbf269552010-12-14 14:59:29 +00006251static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006252 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006253{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006254 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006255 struct compound_hdr hdr;
6256 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006257
Chuck Leverbf269552010-12-14 14:59:29 +00006258 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006259 if (status)
6260 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006261 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006262 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006263 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006264 status = decode_putfh(xdr);
6265 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006266 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006267 status = decode_lookup(xdr);
6268 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006269 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006270 status = decode_getfh(xdr, res->fh);
6271 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006272 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006273 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006274out:
6275 return status;
6276}
6277
6278/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07006279 * Decode LOOKUPP response
6280 */
6281static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6282 void *data)
6283{
6284 struct nfs4_lookupp_res *res = data;
6285 struct compound_hdr hdr;
6286 int status;
6287
6288 status = decode_compound_hdr(xdr, &hdr);
6289 if (status)
6290 goto out;
6291 status = decode_sequence(xdr, &res->seq_res, rqstp);
6292 if (status)
6293 goto out;
6294 status = decode_putfh(xdr);
6295 if (status)
6296 goto out;
6297 status = decode_lookupp(xdr);
6298 if (status)
6299 goto out;
6300 status = decode_getfh(xdr, res->fh);
6301 if (status)
6302 goto out;
6303 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6304out:
6305 return status;
6306}
6307
6308/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006309 * Decode LOOKUP_ROOT response
6310 */
Chuck Leverbf269552010-12-14 14:59:29 +00006311static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6312 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006313 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006314{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006315 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006316 struct compound_hdr hdr;
6317 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006318
Chuck Leverbf269552010-12-14 14:59:29 +00006319 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006320 if (status)
6321 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006322 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006323 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_putrootfh(xdr);
6326 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006327 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006328 status = decode_getfh(xdr, res->fh);
6329 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006330 status = decode_getfattr_label(xdr, res->fattr,
6331 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332out:
6333 return status;
6334}
6335
6336/*
6337 * Decode REMOVE response
6338 */
Chuck Leverbf269552010-12-14 14:59:29 +00006339static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006340 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006341{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006342 struct nfs_removeres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006343 struct compound_hdr hdr;
6344 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006345
Chuck Leverbf269552010-12-14 14:59:29 +00006346 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006347 if (status)
6348 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006349 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006350 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006352 status = decode_putfh(xdr);
6353 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006354 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006355 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006356out:
6357 return status;
6358}
6359
6360/*
6361 * Decode RENAME response
6362 */
Chuck Leverbf269552010-12-14 14:59:29 +00006363static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006364 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006365{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006366 struct nfs_renameres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006367 struct compound_hdr hdr;
6368 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006369
Chuck Leverbf269552010-12-14 14:59:29 +00006370 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006371 if (status)
6372 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006373 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006374 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006375 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006376 status = decode_putfh(xdr);
6377 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006379 status = decode_savefh(xdr);
6380 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006382 status = decode_putfh(xdr);
6383 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006384 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006385 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006386out:
6387 return status;
6388}
6389
6390/*
6391 * Decode LINK response
6392 */
Chuck Leverbf269552010-12-14 14:59:29 +00006393static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006394 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006395{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006396 struct nfs4_link_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006397 struct compound_hdr hdr;
6398 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006399
Chuck Leverbf269552010-12-14 14:59:29 +00006400 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006401 if (status)
6402 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006403 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006404 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006405 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006406 status = decode_putfh(xdr);
6407 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006408 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006409 status = decode_savefh(xdr);
6410 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006412 status = decode_putfh(xdr);
6413 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006414 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006415 status = decode_link(xdr, &res->cinfo);
6416 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006417 goto out;
6418 /*
6419 * Note order: OP_LINK leaves the directory as the current
6420 * filehandle.
6421 */
Chuck Leverbf269552010-12-14 14:59:29 +00006422 status = decode_restorefh(xdr);
6423 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006424 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006425 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426out:
6427 return status;
6428}
6429
6430/*
6431 * Decode CREATE response
6432 */
Chuck Leverbf269552010-12-14 14:59:29 +00006433static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006434 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006436 struct nfs4_create_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437 struct compound_hdr hdr;
6438 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006439
Chuck Leverbf269552010-12-14 14:59:29 +00006440 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006441 if (status)
6442 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006443 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006444 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006445 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006446 status = decode_putfh(xdr);
6447 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006449 status = decode_create(xdr, &res->dir_cinfo);
6450 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006451 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006452 status = decode_getfh(xdr, res->fh);
6453 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006455 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006456out:
6457 return status;
6458}
6459
6460/*
6461 * Decode SYMLINK response
6462 */
Chuck Leverbf269552010-12-14 14:59:29 +00006463static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006464 void *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465{
Chuck Leverbf269552010-12-14 14:59:29 +00006466 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467}
6468
6469/*
6470 * Decode GETATTR response
6471 */
Chuck Leverbf269552010-12-14 14:59:29 +00006472static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006473 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006474{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006475 struct nfs4_getattr_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006476 struct compound_hdr hdr;
6477 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006478
Chuck Leverbf269552010-12-14 14:59:29 +00006479 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480 if (status)
6481 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006482 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006483 if (status)
6484 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006485 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006486 if (status)
6487 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006488 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006489out:
6490 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491}
6492
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006493/*
6494 * Encode an SETACL request
6495 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006496static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006497 const void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006498{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006499 const struct nfs_setaclargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006500 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006501 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006502 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006503
Chuck Lever9f06c712010-12-14 14:59:18 +00006504 encode_compound_hdr(xdr, req, &hdr);
6505 encode_sequence(xdr, &args->seq_args, &hdr);
6506 encode_putfh(xdr, args->fh, &hdr);
6507 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006508 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006509}
Andy Adamson05d564f2008-12-23 16:06:15 -05006510
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006511/*
6512 * Decode SETACL response
6513 */
6514static int
Chuck Leverbf269552010-12-14 14:59:29 +00006515nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006516 void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006517{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006518 struct nfs_setaclres *res = data;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006519 struct compound_hdr hdr;
6520 int status;
6521
Chuck Leverbf269552010-12-14 14:59:29 +00006522 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006523 if (status)
6524 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006525 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006526 if (status)
6527 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006528 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006529 if (status)
6530 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006531 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006532out:
6533 return status;
6534}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535
6536/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006537 * Decode GETACL response
6538 */
6539static int
Chuck Leverbf269552010-12-14 14:59:29 +00006540nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006541 void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006542{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006543 struct nfs_getaclres *res = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00006544 struct compound_hdr hdr;
6545 int status;
6546
Trond Myklebust331818f2012-02-03 18:30:53 -05006547 if (res->acl_scratch != NULL) {
6548 void *p = page_address(res->acl_scratch);
6549 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6550 }
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006552 if (status)
6553 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006554 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006555 if (status)
6556 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006557 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006558 if (status)
6559 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006560 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006561
6562out:
6563 return status;
6564}
6565
6566/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006567 * Decode CLOSE response
6568 */
Chuck Leverbf269552010-12-14 14:59:29 +00006569static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006570 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006571{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006572 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006573 struct compound_hdr hdr;
6574 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006575
Chuck Leverbf269552010-12-14 14:59:29 +00006576 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006577 if (status)
6578 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006579 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006580 if (status)
6581 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006582 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006583 if (status)
6584 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006585 if (res->lr_res) {
6586 status = decode_layoutreturn(xdr, res->lr_res);
6587 res->lr_ret = status;
6588 if (status)
6589 goto out;
6590 }
Trond Myklebustd8d84982016-12-19 12:14:44 -05006591 if (res->fattr != NULL) {
6592 status = decode_getfattr(xdr, res->fattr, res->server);
6593 if (status != 0)
6594 goto out;
6595 }
Chuck Leverbf269552010-12-14 14:59:29 +00006596 status = decode_close(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006598 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006599}
6600
6601/*
6602 * Decode OPEN response
6603 */
Chuck Leverbf269552010-12-14 14:59:29 +00006604static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006605 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006607 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006608 struct compound_hdr hdr;
6609 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006610
Chuck Leverbf269552010-12-14 14:59:29 +00006611 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006612 if (status)
6613 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006614 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006615 if (status)
6616 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006617 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006618 if (status)
6619 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006620 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006621 if (status)
6622 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006623 status = decode_getfh(xdr, &res->fh);
6624 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006625 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006626 if (res->access_request)
6627 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006628 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006630 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631}
6632
6633/*
6634 * Decode OPEN_CONFIRM response
6635 */
Chuck Leverbf269552010-12-14 14:59:29 +00006636static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6637 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006638 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006639{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006640 struct nfs_open_confirmres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006641 struct compound_hdr hdr;
6642 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643
Chuck Leverbf269552010-12-14 14:59:29 +00006644 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006645 if (status)
6646 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006647 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006648 if (status)
6649 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006650 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006651out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006652 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653}
6654
6655/*
6656 * Decode OPEN response
6657 */
Chuck Leverbf269552010-12-14 14:59:29 +00006658static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6659 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006660 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006661{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006662 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006663 struct compound_hdr hdr;
6664 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006665
Chuck Leverbf269552010-12-14 14:59:29 +00006666 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006667 if (status)
6668 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006669 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006670 if (status)
6671 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006672 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006673 if (status)
6674 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006675 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006676 if (status)
6677 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006678 if (res->access_request)
6679 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006680 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006681out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006682 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006683}
6684
6685/*
6686 * Decode SETATTR response
6687 */
Chuck Leverbf269552010-12-14 14:59:29 +00006688static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6689 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006690 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006691{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006692 struct nfs_setattrres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006693 struct compound_hdr hdr;
6694 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006695
Chuck Leverbf269552010-12-14 14:59:29 +00006696 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006697 if (status)
6698 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006699 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006700 if (status)
6701 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006702 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006703 if (status)
6704 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006705 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006706 if (status)
6707 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006708 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006709out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006710 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006711}
6712
6713/*
6714 * Decode LOCK response
6715 */
Chuck Leverbf269552010-12-14 14:59:29 +00006716static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006717 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006718{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006719 struct nfs_lock_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006720 struct compound_hdr hdr;
6721 int status;
6722
Chuck Leverbf269552010-12-14 14:59:29 +00006723 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006724 if (status)
6725 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006726 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006727 if (status)
6728 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006729 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006730 if (status)
6731 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006732 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006733out:
6734 return status;
6735}
6736
6737/*
6738 * Decode LOCKT response
6739 */
Chuck Leverbf269552010-12-14 14:59:29 +00006740static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006741 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006742{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006743 struct nfs_lockt_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006744 struct compound_hdr hdr;
6745 int status;
6746
Chuck Leverbf269552010-12-14 14:59:29 +00006747 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006748 if (status)
6749 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006750 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006751 if (status)
6752 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006753 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006754 if (status)
6755 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006756 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757out:
6758 return status;
6759}
6760
6761/*
6762 * Decode LOCKU response
6763 */
Chuck Leverbf269552010-12-14 14:59:29 +00006764static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006765 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006767 struct nfs_locku_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768 struct compound_hdr hdr;
6769 int status;
6770
Chuck Leverbf269552010-12-14 14:59:29 +00006771 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006772 if (status)
6773 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006774 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006775 if (status)
6776 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006777 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006778 if (status)
6779 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006780 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006781out:
6782 return status;
6783}
6784
Chuck Leverbf269552010-12-14 14:59:29 +00006785static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6786 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006787{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006788 struct compound_hdr hdr;
6789 int status;
6790
Chuck Leverbf269552010-12-14 14:59:29 +00006791 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006792 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006793 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006794 return status;
6795}
6796
Linus Torvalds1da177e2005-04-16 15:20:36 -07006797/*
6798 * Decode READLINK response
6799 */
Chuck Leverbf269552010-12-14 14:59:29 +00006800static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6801 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006802 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006803{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006804 struct nfs4_readlink_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006805 struct compound_hdr hdr;
6806 int status;
6807
Chuck Leverbf269552010-12-14 14:59:29 +00006808 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006809 if (status)
6810 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006811 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006812 if (status)
6813 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006814 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006815 if (status)
6816 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006817 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006818out:
6819 return status;
6820}
6821
6822/*
6823 * Decode READDIR response
6824 */
Chuck Leverbf269552010-12-14 14:59:29 +00006825static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006826 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006827{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006828 struct nfs4_readdir_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006829 struct compound_hdr hdr;
6830 int status;
6831
Chuck Leverbf269552010-12-14 14:59:29 +00006832 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006833 if (status)
6834 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006835 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006836 if (status)
6837 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006838 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006839 if (status)
6840 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006841 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006842out:
6843 return status;
6844}
6845
6846/*
6847 * Decode Read response
6848 */
Chuck Leverbf269552010-12-14 14:59:29 +00006849static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006850 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006851{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006852 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006853 struct compound_hdr hdr;
6854 int status;
6855
Chuck Leverbf269552010-12-14 14:59:29 +00006856 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006857 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006858 if (status)
6859 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006860 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006861 if (status)
6862 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006863 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006864 if (status)
6865 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006866 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006867 if (!status)
6868 status = res->count;
6869out:
6870 return status;
6871}
6872
6873/*
6874 * Decode WRITE response
6875 */
Chuck Leverbf269552010-12-14 14:59:29 +00006876static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006877 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006878{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006879 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006880 struct compound_hdr hdr;
6881 int status;
6882
Chuck Leverbf269552010-12-14 14:59:29 +00006883 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006884 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006885 if (status)
6886 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006887 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006888 if (status)
6889 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006890 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006891 if (status)
6892 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006893 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006894 if (status)
6895 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006896 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006897 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006898 if (!status)
6899 status = res->count;
6900out:
6901 return status;
6902}
6903
6904/*
6905 * Decode COMMIT response
6906 */
Chuck Leverbf269552010-12-14 14:59:29 +00006907static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006908 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006909{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006910 struct nfs_commitres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006911 struct compound_hdr hdr;
6912 int status;
6913
Chuck Leverbf269552010-12-14 14:59:29 +00006914 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006915 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006916 if (status)
6917 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006918 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006919 if (status)
6920 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006921 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006922 if (status)
6923 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006924 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006925out:
6926 return status;
6927}
6928
6929/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006930 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006931 */
Chuck Leverbf269552010-12-14 14:59:29 +00006932static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006933 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006934{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006935 struct nfs4_fsinfo_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006936 struct compound_hdr hdr;
6937 int status;
6938
Chuck Leverbf269552010-12-14 14:59:29 +00006939 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006940 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006941 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006942 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006943 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006944 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006945 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006946 return status;
6947}
6948
6949/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006950 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006951 */
Chuck Leverbf269552010-12-14 14:59:29 +00006952static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006953 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006954{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006955 struct nfs4_pathconf_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006956 struct compound_hdr hdr;
6957 int status;
6958
Chuck Leverbf269552010-12-14 14:59:29 +00006959 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006960 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006961 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006962 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006963 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006964 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006965 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006966 return status;
6967}
6968
6969/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006970 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006971 */
Chuck Leverbf269552010-12-14 14:59:29 +00006972static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006973 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006974{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006975 struct nfs4_statfs_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006976 struct compound_hdr hdr;
6977 int status;
6978
Chuck Leverbf269552010-12-14 14:59:29 +00006979 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006980 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006981 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006982 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006983 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006984 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006985 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006986 return status;
6987}
6988
6989/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006990 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006991 */
Chuck Leverbf269552010-12-14 14:59:29 +00006992static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6993 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006994 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006995{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006996 struct nfs4_server_caps_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006997 struct compound_hdr hdr;
6998 int status;
6999
Chuck Leverbf269552010-12-14 14:59:29 +00007000 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007001 if (status)
7002 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007003 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007004 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007005 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007006 status = decode_putfh(xdr);
7007 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007008 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007009 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007010out:
7011 return status;
7012}
7013
7014/*
7015 * Decode RENEW response
7016 */
Chuck Leverbf269552010-12-14 14:59:29 +00007017static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
7018 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007019{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007020 struct compound_hdr hdr;
7021 int status;
7022
Chuck Leverbf269552010-12-14 14:59:29 +00007023 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007024 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007025 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007026 return status;
7027}
7028
7029/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007030 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007031 */
Chuck Leverbf269552010-12-14 14:59:29 +00007032static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
7033 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007034 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007035{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007036 struct nfs4_setclientid_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007037 struct compound_hdr hdr;
7038 int status;
7039
Chuck Leverbf269552010-12-14 14:59:29 +00007040 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007041 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007042 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007043 return status;
7044}
7045
7046/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007047 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007048 */
Chuck Leverbf269552010-12-14 14:59:29 +00007049static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007050 struct xdr_stream *xdr,
7051 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007052{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007053 struct compound_hdr hdr;
7054 int status;
7055
Chuck Leverbf269552010-12-14 14:59:29 +00007056 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007057 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007058 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007059 return status;
7060}
7061
7062/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007063 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007064 */
Chuck Leverbf269552010-12-14 14:59:29 +00007065static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
7066 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007067 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007068{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007069 struct nfs4_delegreturnres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007070 struct compound_hdr hdr;
7071 int status;
7072
Chuck Leverbf269552010-12-14 14:59:29 +00007073 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007074 if (status)
7075 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007076 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007077 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01007078 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007079 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01007080 if (status != 0)
7081 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05007082 if (res->lr_res) {
7083 status = decode_layoutreturn(xdr, res->lr_res);
7084 res->lr_ret = status;
7085 if (status)
7086 goto out;
7087 }
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05007088 if (res->fattr) {
7089 status = decode_getfattr(xdr, res->fattr, res->server);
7090 if (status != 0)
7091 goto out;
7092 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04007093 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01007094out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07007095 return status;
7096}
7097
Trond Myklebust683b57b2006-06-09 09:34:22 -04007098/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007099 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04007100 */
Chuck Leverbf269552010-12-14 14:59:29 +00007101static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
7102 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007103 void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007104{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007105 struct nfs4_fs_locations_res *res = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04007106 struct compound_hdr hdr;
7107 int status;
7108
Chuck Leverbf269552010-12-14 14:59:29 +00007109 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007110 if (status)
7111 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007112 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007113 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007114 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007115 status = decode_putfh(xdr);
7116 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007117 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04007118 if (res->migration) {
7119 xdr_enter_page(xdr, PAGE_SIZE);
7120 status = decode_getfattr_generic(xdr,
7121 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007122 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04007123 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04007124 if (status)
7125 goto out;
7126 if (res->renew)
7127 status = decode_renew(xdr);
7128 } else {
7129 status = decode_lookup(xdr);
7130 if (status)
7131 goto out;
7132 xdr_enter_page(xdr, PAGE_SIZE);
7133 status = decode_getfattr_generic(xdr,
7134 &res->fs_locations->fattr,
7135 NULL, res->fs_locations,
7136 NULL, res->fs_locations->server);
7137 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04007138out:
7139 return status;
7140}
7141
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007142/*
7143 * Decode SECINFO response
7144 */
7145static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7146 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007147 void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007148{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007149 struct nfs4_secinfo_res *res = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007150 struct compound_hdr hdr;
7151 int status;
7152
7153 status = decode_compound_hdr(xdr, &hdr);
7154 if (status)
7155 goto out;
7156 status = decode_sequence(xdr, &res->seq_res, rqstp);
7157 if (status)
7158 goto out;
7159 status = decode_putfh(xdr);
7160 if (status)
7161 goto out;
7162 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007163out:
7164 return status;
7165}
7166
Chuck Lever44c99932013-10-17 14:13:30 -04007167/*
7168 * Decode FSID_PRESENT response
7169 */
7170static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7171 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007172 void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04007173{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007174 struct nfs4_fsid_present_res *res = data;
Chuck Lever44c99932013-10-17 14:13:30 -04007175 struct compound_hdr hdr;
7176 int status;
7177
7178 status = decode_compound_hdr(xdr, &hdr);
7179 if (status)
7180 goto out;
7181 status = decode_sequence(xdr, &res->seq_res, rqstp);
7182 if (status)
7183 goto out;
7184 status = decode_putfh(xdr);
7185 if (status)
7186 goto out;
7187 status = decode_getfh(xdr, res->fh);
7188 if (status)
7189 goto out;
7190 if (res->renew)
7191 status = decode_renew(xdr);
7192out:
7193 return status;
7194}
7195
Benny Halevy99fe60d2009-04-01 09:22:29 -04007196#if defined(CONFIG_NFS_V4_1)
7197/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007198 * Decode BIND_CONN_TO_SESSION response
7199 */
7200static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7201 struct xdr_stream *xdr,
7202 void *res)
7203{
7204 struct compound_hdr hdr;
7205 int status;
7206
7207 status = decode_compound_hdr(xdr, &hdr);
7208 if (!status)
7209 status = decode_bind_conn_to_session(xdr, res);
7210 return status;
7211}
7212
7213/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007214 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007215 */
Chuck Leverbf269552010-12-14 14:59:29 +00007216static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7217 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007218 void *res)
7219{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007220 struct compound_hdr hdr;
7221 int status;
7222
Chuck Leverbf269552010-12-14 14:59:29 +00007223 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007224 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007225 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007226 return status;
7227}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007228
7229/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007230 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007231 */
Chuck Leverbf269552010-12-14 14:59:29 +00007232static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7233 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007234 void *res)
Andy Adamsonfc931582009-04-01 09:22:31 -04007235{
Andy Adamsonfc931582009-04-01 09:22:31 -04007236 struct compound_hdr hdr;
7237 int status;
7238
Chuck Leverbf269552010-12-14 14:59:29 +00007239 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007240 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007241 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007242 return status;
7243}
7244
7245/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007246 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007247 */
Chuck Leverbf269552010-12-14 14:59:29 +00007248static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7249 struct xdr_stream *xdr,
7250 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007251{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007252 struct compound_hdr hdr;
7253 int status;
7254
Chuck Leverbf269552010-12-14 14:59:29 +00007255 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007256 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007257 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007258 return status;
7259}
7260
7261/*
Trond Myklebust66245532012-05-25 17:18:09 -04007262 * Decode DESTROY_CLIENTID response
7263 */
7264static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7265 struct xdr_stream *xdr,
7266 void *res)
7267{
7268 struct compound_hdr hdr;
7269 int status;
7270
7271 status = decode_compound_hdr(xdr, &hdr);
7272 if (!status)
7273 status = decode_destroy_clientid(xdr, res);
7274 return status;
7275}
7276
7277/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007278 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007279 */
Chuck Leverbf269552010-12-14 14:59:29 +00007280static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7281 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007282 void *res)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007283{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007284 struct compound_hdr hdr;
7285 int status;
7286
Chuck Leverbf269552010-12-14 14:59:29 +00007287 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007288 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007289 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007290 return status;
7291}
7292
7293/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007294 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007295 */
Chuck Leverbf269552010-12-14 14:59:29 +00007296static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7297 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007298 void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04007299{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007300 struct nfs4_get_lease_time_res *res = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04007301 struct compound_hdr hdr;
7302 int status;
7303
Chuck Leverbf269552010-12-14 14:59:29 +00007304 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007305 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007306 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007307 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007308 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007309 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007310 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007311 return status;
7312}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007313
7314/*
7315 * Decode RECLAIM_COMPLETE response
7316 */
Chuck Leverbf269552010-12-14 14:59:29 +00007317static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7318 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007319 void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05007320{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007321 struct nfs41_reclaim_complete_res *res = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05007322 struct compound_hdr hdr;
7323 int status;
7324
Chuck Leverbf269552010-12-14 14:59:29 +00007325 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007326 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007327 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007328 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307329 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007330 return status;
7331}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007332
7333/*
7334 * Decode GETDEVINFO response
7335 */
Chuck Leverbf269552010-12-14 14:59:29 +00007336static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7337 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007338 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007339{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007340 struct nfs4_getdeviceinfo_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007341 struct compound_hdr hdr;
7342 int status;
7343
Chuck Leverbf269552010-12-14 14:59:29 +00007344 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007345 if (status != 0)
7346 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007347 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007348 if (status != 0)
7349 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007350 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007351out:
7352 return status;
7353}
7354
7355/*
7356 * Decode LAYOUTGET response
7357 */
Chuck Leverbf269552010-12-14 14:59:29 +00007358static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7359 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007360 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007361{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007362 struct nfs4_layoutget_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007363 struct compound_hdr hdr;
7364 int status;
7365
Chuck Leverbf269552010-12-14 14:59:29 +00007366 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007367 if (status)
7368 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007369 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007370 if (status)
7371 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007372 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007373 if (status)
7374 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007375 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007376out:
7377 return status;
7378}
Andy Adamson863a3c62011-03-23 13:27:54 +00007379
7380/*
Benny Halevycbe82602011-05-22 19:52:37 +03007381 * Decode LAYOUTRETURN response
7382 */
7383static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7384 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007385 void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03007386{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007387 struct nfs4_layoutreturn_res *res = data;
Benny Halevycbe82602011-05-22 19:52:37 +03007388 struct compound_hdr hdr;
7389 int status;
7390
7391 status = decode_compound_hdr(xdr, &hdr);
7392 if (status)
7393 goto out;
7394 status = decode_sequence(xdr, &res->seq_res, rqstp);
7395 if (status)
7396 goto out;
7397 status = decode_putfh(xdr);
7398 if (status)
7399 goto out;
7400 status = decode_layoutreturn(xdr, res);
7401out:
7402 return status;
7403}
7404
7405/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007406 * Decode LAYOUTCOMMIT response
7407 */
7408static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7409 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007410 void *data)
Andy Adamson863a3c62011-03-23 13:27:54 +00007411{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007412 struct nfs4_layoutcommit_res *res = data;
Andy Adamson863a3c62011-03-23 13:27:54 +00007413 struct compound_hdr hdr;
7414 int status;
7415
7416 status = decode_compound_hdr(xdr, &hdr);
7417 if (status)
7418 goto out;
7419 status = decode_sequence(xdr, &res->seq_res, rqstp);
7420 if (status)
7421 goto out;
7422 status = decode_putfh(xdr);
7423 if (status)
7424 goto out;
7425 status = decode_layoutcommit(xdr, rqstp, res);
7426 if (status)
7427 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007428 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007429out:
7430 return status;
7431}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007432
7433/*
7434 * Decode SECINFO_NO_NAME response
7435 */
7436static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7437 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007438 void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007439{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007440 struct nfs4_secinfo_res *res = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007441 struct compound_hdr hdr;
7442 int status;
7443
7444 status = decode_compound_hdr(xdr, &hdr);
7445 if (status)
7446 goto out;
7447 status = decode_sequence(xdr, &res->seq_res, rqstp);
7448 if (status)
7449 goto out;
7450 status = decode_putrootfh(xdr);
7451 if (status)
7452 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007453 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007454out:
7455 return status;
7456}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007457
7458/*
7459 * Decode TEST_STATEID response
7460 */
7461static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7462 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007463 void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04007464{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007465 struct nfs41_test_stateid_res *res = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04007466 struct compound_hdr hdr;
7467 int status;
7468
7469 status = decode_compound_hdr(xdr, &hdr);
7470 if (status)
7471 goto out;
7472 status = decode_sequence(xdr, &res->seq_res, rqstp);
7473 if (status)
7474 goto out;
7475 status = decode_test_stateid(xdr, res);
7476out:
7477 return status;
7478}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007479
7480/*
7481 * Decode FREE_STATEID response
7482 */
7483static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7484 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007485 void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007486{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007487 struct nfs41_free_stateid_res *res = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007488 struct compound_hdr hdr;
7489 int status;
7490
7491 status = decode_compound_hdr(xdr, &hdr);
7492 if (status)
7493 goto out;
7494 status = decode_sequence(xdr, &res->seq_res, rqstp);
7495 if (status)
7496 goto out;
7497 status = decode_free_stateid(xdr, res);
7498out:
7499 return status;
7500}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007501#endif /* CONFIG_NFS_V4_1 */
7502
Chuck Lever573c4e12010-12-14 14:58:11 +00007503/**
7504 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7505 * the local page cache.
7506 * @xdr: XDR stream where entry resides
7507 * @entry: buffer to fill in with entry data
7508 * @plus: boolean indicating whether this should be a readdirplus entry
7509 *
7510 * Returns zero if successful, otherwise a negative errno value is
7511 * returned.
7512 *
7513 * This function is not invoked during READDIR reply decoding, but
7514 * rather whenever an application invokes the getdents(2) system call
7515 * on a directory already in our cache.
7516 */
7517int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -04007518 bool plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007519{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007520 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007521 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007522 uint32_t len;
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007523 uint64_t new_cookie;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007524 __be32 *p = xdr_inline_decode(xdr, 4);
7525 if (unlikely(!p))
7526 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007527 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007528 p = xdr_inline_decode(xdr, 4);
7529 if (unlikely(!p))
7530 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007531 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007532 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007533 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007534 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007535 }
7536
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007537 p = xdr_inline_decode(xdr, 12);
7538 if (unlikely(!p))
7539 goto out_overflow;
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007540 p = xdr_decode_hyper(p, &new_cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007541 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007542
Trond Myklebust9af8c222010-10-24 11:52:55 -04007543 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007544 if (unlikely(!p))
7545 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007546 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007547
7548 /*
7549 * In case the server doesn't return an inode number,
7550 * we fake one here. (We don't use inode number 0,
7551 * since glibc seems to choke on it...)
7552 */
7553 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007554 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007555
Trond Myklebust9af8c222010-10-24 11:52:55 -04007556 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007557 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007558
Trond Myklebust256e48b2012-06-21 11:18:13 -04007559 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007560 goto out_overflow;
7561
Chuck Lever573c4e12010-12-14 14:58:11 +00007562 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007563 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007564 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007565 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7566 entry->ino = entry->fattr->mounted_on_fileid;
7567 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007568 entry->ino = entry->fattr->fileid;
7569
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007570 entry->d_type = DT_UNKNOWN;
7571 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7572 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7573
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007574 entry->prev_cookie = entry->cookie;
7575 entry->cookie = new_cookie;
7576
Chuck Lever573c4e12010-12-14 14:58:11 +00007577 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007578
7579out_overflow:
7580 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007581 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007582}
7583
7584/*
7585 * We need to translate between nfs status return values and
7586 * the local errno values which may not be the same.
7587 */
7588static struct {
7589 int stat;
7590 int errno;
7591} nfs_errtbl[] = {
7592 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007593 { NFS4ERR_PERM, -EPERM },
7594 { NFS4ERR_NOENT, -ENOENT },
7595 { NFS4ERR_IO, -errno_NFSERR_IO},
7596 { NFS4ERR_NXIO, -ENXIO },
7597 { NFS4ERR_ACCESS, -EACCES },
7598 { NFS4ERR_EXIST, -EEXIST },
7599 { NFS4ERR_XDEV, -EXDEV },
7600 { NFS4ERR_NOTDIR, -ENOTDIR },
7601 { NFS4ERR_ISDIR, -EISDIR },
7602 { NFS4ERR_INVAL, -EINVAL },
7603 { NFS4ERR_FBIG, -EFBIG },
7604 { NFS4ERR_NOSPC, -ENOSPC },
7605 { NFS4ERR_ROFS, -EROFS },
7606 { NFS4ERR_MLINK, -EMLINK },
7607 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7608 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7609 { NFS4ERR_DQUOT, -EDQUOT },
7610 { NFS4ERR_STALE, -ESTALE },
7611 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007612 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7613 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7614 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007615 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007616 { NFS4ERR_BADTYPE, -EBADTYPE },
7617 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007618 { NFS4ERR_SYMLINK, -ELOOP },
7619 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7620 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007621 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007622};
7623
7624/*
7625 * Convert an NFS error code to a local one.
7626 * This one is used jointly by NFSv2 and NFSv3.
7627 */
7628static int
David Howells0a8ea432006-08-22 20:06:08 -04007629nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007630{
7631 int i;
7632 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7633 if (nfs_errtbl[i].stat == stat)
7634 return nfs_errtbl[i].errno;
7635 }
7636 if (stat <= 10000 || stat > 10100) {
7637 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007638 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007639 }
7640 /* If we cannot translate the error, the recovery routines should
7641 * handle it.
7642 * Note: remaining NFSv4 error codes have values > 10000, so should
7643 * not conflict with native Linux error codes.
7644 */
Benny Halevy856dff32008-03-31 17:39:06 +03007645 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007646}
7647
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007648#ifdef CONFIG_NFS_V4_2
7649#include "nfs42xdr.c"
7650#endif /* CONFIG_NFS_V4_2 */
7651
Linus Torvalds1da177e2005-04-16 15:20:36 -07007652#define PROC(proc, argtype, restype) \
7653[NFSPROC4_CLNT_##proc] = { \
7654 .p_proc = NFSPROC4_COMPOUND, \
Christoph Hellwigfcc85812017-05-08 10:01:49 +02007655 .p_encode = nfs4_xdr_##argtype, \
Christoph Hellwigfc016482017-05-08 15:09:02 +02007656 .p_decode = nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007657 .p_arglen = NFS4_##argtype##_sz, \
7658 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007659 .p_statidx = NFSPROC4_CLNT_##proc, \
7660 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007661}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007662
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007663#define STUB(proc) \
7664[NFSPROC4_CLNT_##proc] = { \
7665 .p_name = #proc, \
7666}
7667
Trond Myklebust8634ef52018-01-06 09:53:49 -05007668#if defined(CONFIG_NFS_V4_1)
7669#define PROC41(proc, argtype, restype) \
7670 PROC(proc, argtype, restype)
7671#else
7672#define PROC41(proc, argtype, restype) \
7673 STUB(proc)
7674#endif
7675
7676#if defined(CONFIG_NFS_V4_2)
7677#define PROC42(proc, argtype, restype) \
7678 PROC(proc, argtype, restype)
7679#else
7680#define PROC42(proc, argtype, restype) \
7681 STUB(proc)
7682#endif
7683
Christoph Hellwig511e9362017-05-12 15:36:49 +02007684const struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007685 PROC(READ, enc_read, dec_read),
7686 PROC(WRITE, enc_write, dec_write),
7687 PROC(COMMIT, enc_commit, dec_commit),
7688 PROC(OPEN, enc_open, dec_open),
7689 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7690 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7691 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7692 PROC(CLOSE, enc_close, dec_close),
7693 PROC(SETATTR, enc_setattr, dec_setattr),
7694 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7695 PROC(RENEW, enc_renew, dec_renew),
7696 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7697 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7698 PROC(LOCK, enc_lock, dec_lock),
7699 PROC(LOCKT, enc_lockt, dec_lockt),
7700 PROC(LOCKU, enc_locku, dec_locku),
7701 PROC(ACCESS, enc_access, dec_access),
7702 PROC(GETATTR, enc_getattr, dec_getattr),
7703 PROC(LOOKUP, enc_lookup, dec_lookup),
7704 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7705 PROC(REMOVE, enc_remove, dec_remove),
7706 PROC(RENAME, enc_rename, dec_rename),
7707 PROC(LINK, enc_link, dec_link),
7708 PROC(SYMLINK, enc_symlink, dec_symlink),
7709 PROC(CREATE, enc_create, dec_create),
7710 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7711 PROC(STATFS, enc_statfs, dec_statfs),
7712 PROC(READLINK, enc_readlink, dec_readlink),
7713 PROC(READDIR, enc_readdir, dec_readdir),
7714 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7715 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7716 PROC(GETACL, enc_getacl, dec_getacl),
7717 PROC(SETACL, enc_setacl, dec_setacl),
7718 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7719 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007720 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007721 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007722 PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7723 PROC41(CREATE_SESSION, enc_create_session, dec_create_session),
7724 PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7725 PROC41(SEQUENCE, enc_sequence, dec_sequence),
7726 PROC41(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7727 PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete),
7728 PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7729 PROC41(LAYOUTGET, enc_layoutget, dec_layoutget),
7730 PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7731 PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7732 PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7733 PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7734 PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007735 STUB(GETDEVICELIST),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007736 PROC41(BIND_CONN_TO_SESSION,
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007737 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007738 PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid),
7739 PROC42(SEEK, enc_seek, dec_seek),
7740 PROC42(ALLOCATE, enc_allocate, dec_allocate),
7741 PROC42(DEALLOCATE, enc_deallocate, dec_deallocate),
7742 PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
7743 PROC42(CLONE, enc_clone, dec_clone),
7744 PROC42(COPY, enc_copy, dec_copy),
7745 PROC(LOOKUPP, enc_lookupp, dec_lookupp),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007746};
7747
Christoph Hellwigc5518582017-05-08 23:27:10 +02007748static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
Trond Myklebusta613fa12012-01-20 13:53:56 -05007749const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007750 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007751 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Christoph Hellwigc5518582017-05-08 23:27:10 +02007752 .procs = nfs4_procedures,
7753 .counts = nfs_version4_counts,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007754};
7755
7756/*
7757 * Local variables:
7758 * c-basic-offset: 8
7759 * End:
7760 */