blob: 69862bf6db0015cee29e0a7907ce9e728f157432 [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"
Chuck Leverf23f6582019-02-11 11:24:26 -050057#include "nfs4trace.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050058#include "internal.h"
Anna Schumaker40c64c22015-04-15 13:00:05 -040059#include "nfs4idmap.h"
Trond Myklebust76e697b2012-11-26 14:20:49 -050060#include "nfs4session.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040061#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040062#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64#define NFSDBG_FACILITY NFSDBG_XDR
65
66/* Mapping from NFS error code to "errno" error code. */
67#define errno_NFSERR_IO EIO
68
Fred Isaman56f487f2016-09-21 11:43:41 -040069struct compound_hdr;
David Howells0a8ea432006-08-22 20:06:08 -040070static int nfs4_stat_to_errno(int);
Fred Isaman56f487f2016-09-21 11:43:41 -040071static void encode_layoutget(struct xdr_stream *xdr,
72 const struct nfs4_layoutget_args *args,
73 struct compound_hdr *hdr);
74static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
75 struct nfs4_layoutget_res *res);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
78#ifdef DEBUG
79#define NFS4_MAXTAGLEN 20
80#else
81#define NFS4_MAXTAGLEN 0
82#endif
83
Andy Adamson6c0195a2008-12-23 16:06:15 -050084/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040085 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 */
Trond Myklebust9ed5af262020-11-21 20:46:18 -050087#define pagepad_maxsz (1)
Trond Myklebust95b72eb2012-04-20 19:24:51 -040088#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050089#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040090#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
92#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
93#define op_encode_hdr_maxsz (1)
94#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040095#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
96#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
97#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
98#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
100 (NFS4_FHSIZE >> 2))
101#define decode_putfh_maxsz (op_decode_hdr_maxsz)
102#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
103#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
104#define encode_getfh_maxsz (op_encode_hdr_maxsz)
105#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
106 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -0400107#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +0000108#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Trond Myklebust36b37432018-03-20 17:03:10 -0400109#define nfstime4_maxsz (3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
111#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400112#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
113#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
David Quigleyaa9c2662013-05-22 12:50:44 -0400114#ifdef CONFIG_NFS_V4_SECURITY_LABEL
115/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
116#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
David Quigleyaa9c2662013-05-22 12:50:44 -0400117#else
118#define nfs4_label_maxsz 0
David Quigleyaa9c2662013-05-22 12:50:44 -0400119#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400120/* We support only one layout type per file system */
121#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000122/* This is based on getfattr, which uses the most attributes: */
123#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebust36b37432018-03-20 17:03:10 -0400124 3*nfstime4_maxsz + \
125 nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400126 nfs4_group_maxsz + nfs4_label_maxsz + \
127 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000128#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
129 nfs4_fattr_value_maxsz)
130#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400131#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
132 1 + 2 + 1 + \
133 nfs4_owner_maxsz + \
134 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400135 nfs4_label_maxsz + \
Trond Myklebust36b37432018-03-20 17:03:10 -0400136 1 + nfstime4_maxsz + \
137 1 + nfstime4_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#define encode_savefh_maxsz (op_encode_hdr_maxsz)
139#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400140#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
141#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200142#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400143/* The 5 accounts for the PNFS attributes, and assumes that at most three
144 * layout types will be returned.
145 */
146#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust57a789a2021-03-26 10:17:25 -0400147 nfs4_fattr_bitmap_maxsz + 1 + \
148 1 /* lease time */ + \
149 2 /* max filesize */ + \
150 2 /* max read */ + \
151 2 /* max write */ + \
152 nfstime4_maxsz /* time delta */ + \
153 5 /* fs layout types */ + \
154 1 /* layout blksize */ + \
155 1 /* clone blksize */ + \
Trond Myklebust7f08a332021-03-26 09:50:19 -0400156 1 /* change attr type */ + \
Trond Myklebust57a789a2021-03-26 10:17:25 -0400157 1 /* xattr support */)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
159#define decode_renew_maxsz (op_decode_hdr_maxsz)
160#define encode_setclientid_maxsz \
161 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500162 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400163 /* client name */ \
164 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500165 1 /* sc_prog */ + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500166 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
167 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500168 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169#define decode_setclientid_maxsz \
170 (op_decode_hdr_maxsz + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500171 2 /* clientid */ + \
172 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
173 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
174 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175#define encode_setclientid_confirm_maxsz \
176 (op_encode_hdr_maxsz + \
177 3 + (NFS4_VERIFIER_SIZE >> 2))
178#define decode_setclientid_confirm_maxsz \
179 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400180#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
181#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700182#define encode_lookupp_maxsz (op_encode_hdr_maxsz)
183#define decode_lookupp_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400184#define encode_share_access_maxsz \
185 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500186#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400187#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
188#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
189#define encode_open_maxsz (op_encode_hdr_maxsz + \
190 2 + encode_share_access_maxsz + 2 + \
191 open_owner_id_maxsz + \
192 encode_opentype_maxsz + \
193 encode_claim_null_maxsz)
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500194#define decode_space_limit_maxsz (3)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400195#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400196#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500197 decode_space_limit_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400198 decode_ace_maxsz)
199#define decode_change_info_maxsz (5)
200#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400201 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400202 decode_change_info_maxsz + 1 + \
203 nfs4_fattr_bitmap_maxsz + \
204 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400205#define encode_open_confirm_maxsz \
206 (op_encode_hdr_maxsz + \
207 encode_stateid_maxsz + 1)
208#define decode_open_confirm_maxsz \
209 (op_decode_hdr_maxsz + \
210 decode_stateid_maxsz)
211#define encode_open_downgrade_maxsz \
212 (op_encode_hdr_maxsz + \
213 encode_stateid_maxsz + 1 + \
214 encode_share_access_maxsz)
215#define decode_open_downgrade_maxsz \
216 (op_decode_hdr_maxsz + \
217 decode_stateid_maxsz)
218#define encode_close_maxsz (op_encode_hdr_maxsz + \
219 1 + encode_stateid_maxsz)
220#define decode_close_maxsz (op_decode_hdr_maxsz + \
221 decode_stateid_maxsz)
222#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
223 encode_stateid_maxsz + \
224 encode_attrs_maxsz)
225#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
226 nfs4_fattr_bitmap_maxsz)
227#define encode_read_maxsz (op_encode_hdr_maxsz + \
228 encode_stateid_maxsz + 3)
Trond Myklebust9ed5af262020-11-21 20:46:18 -0500229#define decode_read_maxsz (op_decode_hdr_maxsz + 2 + pagepad_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400230#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400231 2 + encode_verifier_maxsz + 5 + \
232 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400233#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9ed5af262020-11-21 20:46:18 -0500234 decode_verifier_maxsz + pagepad_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400235#define encode_readlink_maxsz (op_encode_hdr_maxsz)
Trond Myklebust9ed5af262020-11-21 20:46:18 -0500236#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1 + pagepad_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400237#define encode_write_maxsz (op_encode_hdr_maxsz + \
238 encode_stateid_maxsz + 4)
239#define decode_write_maxsz (op_decode_hdr_maxsz + \
240 2 + decode_verifier_maxsz)
241#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
242#define decode_commit_maxsz (op_decode_hdr_maxsz + \
243 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244#define encode_remove_maxsz (op_encode_hdr_maxsz + \
245 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400246#define decode_remove_maxsz (op_decode_hdr_maxsz + \
247 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248#define encode_rename_maxsz (op_encode_hdr_maxsz + \
249 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400250#define decode_rename_maxsz (op_decode_hdr_maxsz + \
251 decode_change_info_maxsz + \
252 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253#define encode_link_maxsz (op_encode_hdr_maxsz + \
254 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400255#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400256#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400257#define encode_lock_maxsz (op_encode_hdr_maxsz + \
258 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400259 1 + encode_stateid_maxsz + 1 + \
260 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400261#define decode_lock_denied_maxsz \
262 (8 + decode_lockowner_maxsz)
263#define decode_lock_maxsz (op_decode_hdr_maxsz + \
264 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400265#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
266 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400267#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
268 decode_lock_denied_maxsz)
269#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
270 encode_stateid_maxsz + \
271 4)
272#define decode_locku_maxsz (op_decode_hdr_maxsz + \
273 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400274#define encode_release_lockowner_maxsz \
275 (op_encode_hdr_maxsz + \
276 encode_lockowner_maxsz)
277#define decode_release_lockowner_maxsz \
278 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400279#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
280#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
282 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400283 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000284 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
286#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400287 1 + 2 + nfs4_name_maxsz + \
288 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400289#define decode_create_maxsz (op_decode_hdr_maxsz + \
290 decode_change_info_maxsz + \
291 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400292#define encode_statfs_maxsz (encode_getattr_maxsz)
293#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
295#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400296#define encode_getacl_maxsz (encode_getattr_maxsz)
297#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9ed5af262020-11-21 20:46:18 -0500298 nfs4_fattr_bitmap_maxsz + 1 + pagepad_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400299#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
300 encode_stateid_maxsz + 3)
301#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400302#define encode_fs_locations_maxsz \
303 (encode_getattr_maxsz)
304#define decode_fs_locations_maxsz \
Trond Myklebust9ed5af262020-11-21 20:46:18 -0500305 (pagepad_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000306#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400307#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 -0400308
309#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400310#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500311#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
312 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400313
Benny Halevy99fe60d2009-04-01 09:22:29 -0400314#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
315 encode_verifier_maxsz + \
316 1 /* co_ownerid.len */ + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400317 /* eia_clientowner */ \
318 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400319 1 /* flags */ + \
320 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400321 /* max is SP4_MACH_CRED (for now) */ + \
322 1 + NFS4_OP_MAP_NUM_WORDS + \
323 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500324 1 /* implementation id array of size 1 */ + \
325 1 /* nii_domain */ + \
326 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
327 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500328 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500329 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400330#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
331 2 /* eir_clientid */ + \
332 1 /* eir_sequenceid */ + \
333 1 /* eir_flags */ + \
334 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400335 /* max is SP4_MACH_CRED (for now) */ + \
336 1 + NFS4_OP_MAP_NUM_WORDS + \
337 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400338 2 /* eir_server_owner.so_minor_id */ + \
339 /* eir_server_owner.so_major_id<> */ \
340 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
341 /* eir_server_scope<> */ \
342 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
343 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500344 1 /* nii_domain */ + \
345 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
346 1 /* nii_name */ + \
347 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
348 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400349#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
350#define decode_channel_attrs_maxsz (6 + \
351 1 /* ca_rdma_ird.len */ + \
352 1 /* ca_rdma_ird */)
353#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
354 2 /* csa_clientid */ + \
355 1 /* csa_sequence */ + \
356 1 /* csa_flags */ + \
357 encode_channel_attrs_maxsz + \
358 encode_channel_attrs_maxsz + \
359 1 /* csa_cb_program */ + \
360 1 /* csa_sec_parms.len (1) */ + \
361 1 /* cb_secflavor (AUTH_SYS) */ + \
362 1 /* stamp */ + \
363 1 /* machinename.len */ + \
364 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
365 1 /* uid */ + \
366 1 /* gid */ + \
367 1 /* gids.len (0) */)
368#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
369 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
370 1 /* csr_sequence */ + \
371 1 /* csr_flags */ + \
372 decode_channel_attrs_maxsz + \
373 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400374#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
375 /* bctsa_sessid */ \
376 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
377 1 /* bctsa_dir */ + \
378 1 /* bctsa_use_conn_in_rdma_mode */)
379#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
380 /* bctsr_sessid */ \
381 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
382 1 /* bctsr_dir */ + \
383 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400384#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
385#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400386#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
387#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400388#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
389 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
390#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
391 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500392#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
393#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700394#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
395 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
396 1 /* layout type */ + \
397 1 /* maxcount */ + \
398 1 /* bitmap size */ + \
399 1 /* notification bitmap length */ + \
400 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400401#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
402 1 /* layout type */ + \
403 1 /* opaque devaddr4 length */ + \
404 /* devaddr4 payload is read into page */ \
405 1 /* notification bitmap length */ + \
Chuck Lever02ef04e2019-02-11 11:25:25 -0500406 1 /* notification bitmap, word 0 */ + \
Trond Myklebust9ed5af262020-11-21 20:46:18 -0500407 pagepad_maxsz /* possible XDR padding */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400408#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
409 encode_stateid_maxsz)
410#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
411 decode_stateid_maxsz + \
Trond Myklebust9ed5af262020-11-21 20:46:18 -0500412 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + \
413 pagepad_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000414#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
415 2 /* offset */ + \
416 2 /* length */ + \
417 1 /* reclaim */ + \
418 encode_stateid_maxsz + \
419 1 /* new offset (true) */ + \
420 2 /* last byte written */ + \
421 1 /* nt_timechanged (false) */ + \
422 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500423 1 /* layoutupdate4 opaqueue len */)
424 /* the actual content of layoutupdate4 should
425 be allocated by drivers and spliced in
426 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000427#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300428#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
429 encode_stateid_maxsz + \
Trond Myklebust6669cb82015-08-27 20:43:20 -0400430 1 + \
431 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
Benny Halevycbe82602011-05-22 19:52:37 +0300432#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
433 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400434#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
435#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400436#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
437 XDR_QUADLEN(NFS4_STATEID_SIZE))
438#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400439#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
440 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400441#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442#else /* CONFIG_NFS_V4_1 */
443#define encode_sequence_maxsz 0
444#define decode_sequence_maxsz 0
Trond Myklebustcf805162016-11-15 14:56:07 -0500445#define encode_layoutreturn_maxsz 0
446#define decode_layoutreturn_maxsz 0
Fred Isaman56f487f2016-09-21 11:43:41 -0400447#define encode_layoutget_maxsz 0
448#define decode_layoutget_maxsz 0
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400449#endif /* CONFIG_NFS_V4_1 */
450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
452#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
453#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400454 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400456 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400460 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400462 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400464 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400466 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400468 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400470 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400472 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400474 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400476 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400478 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400480 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400481 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400483 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400485 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400486 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400488 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400490 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400494 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400497 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_getfh_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400501 encode_getattr_maxsz + \
502 encode_layoutget_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400504 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400505 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400506 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400507 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400508 decode_getfh_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400509 decode_getattr_maxsz + \
510 decode_layoutget_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400511#define NFS4_enc_open_confirm_sz \
512 (compound_encode_hdr_maxsz + \
513 encode_putfh_maxsz + \
514 encode_open_confirm_maxsz)
515#define NFS4_dec_open_confirm_sz \
516 (compound_decode_hdr_maxsz + \
517 decode_putfh_maxsz + \
518 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400522 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400523 encode_access_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400524 encode_getattr_maxsz + \
525 encode_layoutget_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400527 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400529 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400530 decode_access_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400531 decode_getattr_maxsz + \
532 decode_layoutget_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#define NFS4_enc_open_downgrade_sz \
534 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400535 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400536 encode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500537 encode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400538 encode_open_downgrade_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539#define NFS4_dec_open_downgrade_sz \
540 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400541 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400542 decode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500543 decode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400544 decode_open_downgrade_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400545#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400547 encode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500548 encode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400549 encode_close_maxsz + \
550 encode_getattr_maxsz)
551#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400552 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400553 decode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500554 decode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400555 decode_close_maxsz + \
556 decode_getattr_maxsz)
557#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400558 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400559 encode_putfh_maxsz + \
560 encode_setattr_maxsz + \
561 encode_getattr_maxsz)
562#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400563 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400564 decode_putfh_maxsz + \
565 decode_setattr_maxsz + \
566 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 encode_putfh_maxsz + \
570 encode_fsinfo_maxsz)
571#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 decode_putfh_maxsz + \
574 decode_fsinfo_maxsz)
575#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
576 encode_renew_maxsz)
577#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
578 decode_renew_maxsz)
579#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
580 encode_setclientid_maxsz)
581#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
582 decode_setclientid_maxsz)
583#define NFS4_enc_setclientid_confirm_sz \
584 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400585 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586#define NFS4_dec_setclientid_confirm_sz \
587 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400588 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400592 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400594 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400596 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400598 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400600 encode_lockt_maxsz)
601#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400602 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400603 decode_putfh_maxsz + \
604 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400608 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400610 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400612 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400613#define NFS4_enc_release_lockowner_sz \
614 (compound_encode_hdr_maxsz + \
615 encode_lockowner_maxsz)
616#define NFS4_dec_release_lockowner_sz \
617 (compound_decode_hdr_maxsz + \
618 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400620 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400622 encode_access_maxsz + \
623 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400625 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400627 decode_access_maxsz + \
628 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400630 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400632 encode_getattr_maxsz + \
633 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400635 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400637 decode_getattr_maxsz + \
638 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400640 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 encode_putfh_maxsz + \
642 encode_lookup_maxsz + \
643 encode_getattr_maxsz + \
644 encode_getfh_maxsz)
645#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400646 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400648 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 decode_getattr_maxsz + \
650 decode_getfh_maxsz)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700651#define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \
652 encode_sequence_maxsz + \
653 encode_putfh_maxsz + \
654 encode_lookupp_maxsz + \
655 encode_getattr_maxsz + \
656 encode_getfh_maxsz)
657#define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \
658 decode_sequence_maxsz + \
659 decode_putfh_maxsz + \
660 decode_lookupp_maxsz + \
661 decode_getattr_maxsz + \
662 decode_getfh_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400664 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 encode_putrootfh_maxsz + \
666 encode_getattr_maxsz + \
667 encode_getfh_maxsz)
668#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400669 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 decode_putrootfh_maxsz + \
671 decode_getattr_maxsz + \
672 decode_getfh_maxsz)
673#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400674 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400676 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400678 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400680 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400682 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 encode_putfh_maxsz + \
684 encode_savefh_maxsz + \
685 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400686 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 decode_putfh_maxsz + \
690 decode_savefh_maxsz + \
691 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400692 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400694 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 encode_putfh_maxsz + \
696 encode_savefh_maxsz + \
697 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400698 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400699 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400700 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701#define NFS4_dec_link_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_savefh_maxsz + \
705 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400706 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400707 decode_restorefh_maxsz + \
708 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400710 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 encode_putfh_maxsz + \
712 encode_symlink_maxsz + \
713 encode_getattr_maxsz + \
714 encode_getfh_maxsz)
715#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400716 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 decode_putfh_maxsz + \
718 decode_symlink_maxsz + \
719 decode_getattr_maxsz + \
720 decode_getfh_maxsz)
721#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400722 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 encode_putfh_maxsz + \
724 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400725 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400726 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400728 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 decode_putfh_maxsz + \
730 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400731 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400732 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400734 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 encode_putfh_maxsz + \
736 encode_getattr_maxsz)
737#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400738 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 decode_putfh_maxsz + \
740 decode_getattr_maxsz)
741#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400742 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400744 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400746 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400748 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400750 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800751 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 encode_getattr_maxsz)
753#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400754 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800755 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 decode_getattr_maxsz)
757#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400758 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 encode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500760 encode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100761 encode_delegreturn_maxsz + \
762 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400764 decode_sequence_maxsz + \
Trond Myklebustd8434d4c2016-11-16 13:54:00 -0500765 decode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500766 decode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100767 decode_delegreturn_maxsz + \
768 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000769#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400770 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000771 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400772 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000773#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400774 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000775 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400776 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000777#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400778 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000779 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400780 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000781#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400782 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000783 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400784 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400785#define NFS4_enc_fs_locations_sz \
786 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400787 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400788 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400789 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400790 encode_fs_locations_maxsz + \
791 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400792#define NFS4_dec_fs_locations_sz \
793 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400794 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400795 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400796 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400797 decode_fs_locations_maxsz + \
798 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000799#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
800 encode_sequence_maxsz + \
801 encode_putfh_maxsz + \
802 encode_secinfo_maxsz)
803#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
804 decode_sequence_maxsz + \
805 decode_putfh_maxsz + \
806 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400807#define NFS4_enc_fsid_present_sz \
808 (compound_encode_hdr_maxsz + \
809 encode_sequence_maxsz + \
810 encode_putfh_maxsz + \
811 encode_getfh_maxsz + \
812 encode_renew_maxsz)
813#define NFS4_dec_fsid_present_sz \
814 (compound_decode_hdr_maxsz + \
815 decode_sequence_maxsz + \
816 decode_putfh_maxsz + \
817 decode_getfh_maxsz + \
818 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400819#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400820#define NFS4_enc_bind_conn_to_session_sz \
821 (compound_encode_hdr_maxsz + \
822 encode_bind_conn_to_session_maxsz)
823#define NFS4_dec_bind_conn_to_session_sz \
824 (compound_decode_hdr_maxsz + \
825 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400826#define NFS4_enc_exchange_id_sz \
827 (compound_encode_hdr_maxsz + \
828 encode_exchange_id_maxsz)
829#define NFS4_dec_exchange_id_sz \
830 (compound_decode_hdr_maxsz + \
831 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400832#define NFS4_enc_create_session_sz \
833 (compound_encode_hdr_maxsz + \
834 encode_create_session_maxsz)
835#define NFS4_dec_create_session_sz \
836 (compound_decode_hdr_maxsz + \
837 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400838#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
839 encode_destroy_session_maxsz)
840#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
841 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400842#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
843 encode_destroy_clientid_maxsz)
844#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
845 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400846#define NFS4_enc_sequence_sz \
847 (compound_decode_hdr_maxsz + \
848 encode_sequence_maxsz)
849#define NFS4_dec_sequence_sz \
850 (compound_decode_hdr_maxsz + \
851 decode_sequence_maxsz)
Donald Buczek0efb01b2019-07-07 21:26:08 +0200852#endif
Andy Adamson2050f0c2009-04-01 09:22:30 -0400853#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
854 encode_sequence_maxsz + \
855 encode_putrootfh_maxsz + \
856 encode_fsinfo_maxsz)
857#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
858 decode_sequence_maxsz + \
859 decode_putrootfh_maxsz + \
860 decode_fsinfo_maxsz)
Donald Buczek0efb01b2019-07-07 21:26:08 +0200861#if defined(CONFIG_NFS_V4_1)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500862#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
863 encode_sequence_maxsz + \
864 encode_reclaim_complete_maxsz)
865#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
866 decode_sequence_maxsz + \
867 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400868#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
869 encode_sequence_maxsz +\
870 encode_getdeviceinfo_maxsz)
871#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
872 decode_sequence_maxsz + \
873 decode_getdeviceinfo_maxsz)
874#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
875 encode_sequence_maxsz + \
876 encode_putfh_maxsz + \
877 encode_layoutget_maxsz)
878#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
879 decode_sequence_maxsz + \
880 decode_putfh_maxsz + \
881 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000882#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
883 encode_sequence_maxsz +\
884 encode_putfh_maxsz + \
885 encode_layoutcommit_maxsz + \
886 encode_getattr_maxsz)
887#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
888 decode_sequence_maxsz + \
889 decode_putfh_maxsz + \
890 decode_layoutcommit_maxsz + \
891 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300892#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
893 encode_sequence_maxsz + \
894 encode_putfh_maxsz + \
895 encode_layoutreturn_maxsz)
896#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
897 decode_sequence_maxsz + \
898 decode_putfh_maxsz + \
899 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400900#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
901 encode_sequence_maxsz + \
902 encode_putrootfh_maxsz +\
903 encode_secinfo_no_name_maxsz)
904#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
905 decode_sequence_maxsz + \
906 decode_putrootfh_maxsz + \
907 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400908#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
909 encode_sequence_maxsz + \
910 encode_test_stateid_maxsz)
911#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
912 decode_sequence_maxsz + \
913 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400914#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
915 encode_sequence_maxsz + \
916 encode_free_stateid_maxsz)
917#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
918 decode_sequence_maxsz + \
919 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500920
921const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
922 compound_encode_hdr_maxsz +
923 encode_sequence_maxsz +
924 encode_putfh_maxsz +
925 encode_getattr_maxsz) *
926 XDR_UNIT);
927
928const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
929 compound_decode_hdr_maxsz +
930 decode_sequence_maxsz +
931 decode_putfh_maxsz) *
932 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400933
934const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
935 compound_decode_hdr_maxsz +
936 decode_sequence_maxsz) *
937 XDR_UNIT);
938EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400939#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
Trond Myklebustbca79472009-03-11 14:10:26 -0400941static const umode_t nfs_type2fmt[] = {
942 [NF4BAD] = 0,
943 [NF4REG] = S_IFREG,
944 [NF4DIR] = S_IFDIR,
945 [NF4BLK] = S_IFBLK,
946 [NF4CHR] = S_IFCHR,
947 [NF4LNK] = S_IFLNK,
948 [NF4SOCK] = S_IFSOCK,
949 [NF4FIFO] = S_IFIFO,
950 [NF4ATTRDIR] = 0,
951 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952};
953
954struct compound_hdr {
955 int32_t status;
956 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500957 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 uint32_t taglen;
959 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400960 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400961 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962};
963
Benny Halevy13c65ce2009-08-14 17:19:25 +0300964static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
965{
966 __be32 *p = xdr_reserve_space(xdr, nbytes);
967 BUG_ON(!p);
968 return p;
969}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
Trond Myklebustcb17e552012-03-04 18:13:56 -0500971static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
972{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500973 WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
Trond Myklebustcb17e552012-03-04 18:13:56 -0500974}
975
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
977{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500978 WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979}
980
Trond Myklebust4ade9822012-03-04 18:13:57 -0500981static void encode_uint32(struct xdr_stream *xdr, u32 n)
982{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500983 WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500984}
985
Trond Myklebustff2eb682012-03-05 11:40:12 -0500986static void encode_uint64(struct xdr_stream *xdr, u64 n)
987{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500988 WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
Trond Myklebustff2eb682012-03-05 11:40:12 -0500989}
990
Trond Myklebust37c88762018-03-20 17:03:08 -0400991static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
992 const __u32 *bitmap, size_t len)
993{
994 ssize_t ret;
995
996 /* Trim empty words */
997 while (len > 0 && bitmap[len-1] == 0)
998 len--;
999 ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
1000 if (WARN_ON_ONCE(ret < 0))
1001 return ret;
1002 return len;
1003}
1004
1005static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
1006 __u32 *res, size_t len)
1007{
1008 size_t i;
1009 __u32 tmp;
1010
1011 while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
1012 len--;
1013 for (i = len; i-- > 0;) {
1014 tmp = bitmap[i] & mask[i];
1015 res[i] = tmp;
1016 }
1017 return len;
1018}
1019
Trond Myklebust4ade9822012-03-04 18:13:57 -05001020static void encode_nfs4_seqid(struct xdr_stream *xdr,
1021 const struct nfs_seqid *seqid)
1022{
Trond Myklebusta6796412015-01-23 19:04:44 -05001023 if (seqid != NULL)
1024 encode_uint32(xdr, seqid->sequence->counter);
1025 else
1026 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001027}
1028
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001029static void encode_compound_hdr(struct xdr_stream *xdr,
1030 struct rpc_rqst *req,
1031 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032{
Al Viro8687b632006-10-19 23:28:48 -07001033 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001034
1035 /* initialize running count of expected bytes in reply.
1036 * NOTE: the replied tag SHOULD be the same is the one sent,
1037 * but this is not required as a MUST for the server to do so. */
Chuck Levercf500ba2019-02-11 11:25:20 -05001038 hdr->replen = 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Trond Myklebust7fc38842012-10-15 11:51:21 -04001040 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001041 encode_string(xdr, hdr->taglen, hdr->tag);
1042 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001043 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -05001044 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +03001045 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -05001046}
1047
Trond Myklebustab19b482012-03-04 18:13:57 -05001048static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
1049 uint32_t replen,
1050 struct compound_hdr *hdr)
1051{
1052 encode_uint32(xdr, op);
1053 hdr->nops++;
1054 hdr->replen += replen;
1055}
1056
Andy Adamsond0179312008-12-23 16:06:17 -05001057static void encode_nops(struct compound_hdr *hdr)
1058{
Trond Myklebust7fc38842012-10-15 11:51:21 -04001059 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -05001060 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061}
1062
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001063static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1064{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001065 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001066}
1067
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1069{
Trond Myklebustcb17e552012-03-04 18:13:56 -05001070 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
Trond Myklebust36b37432018-03-20 17:03:10 -04001073static __be32 *
Trond Myklebuste7d4b052019-10-04 16:43:09 -04001074xdr_encode_nfstime4(__be32 *p, const struct timespec64 *t)
Trond Myklebust36b37432018-03-20 17:03:10 -04001075{
Arnd Bergmanna3167da2019-11-11 21:16:27 +01001076 p = xdr_encode_hyper(p, t->tv_sec);
Trond Myklebust36b37432018-03-20 17:03:10 -04001077 *p++ = cpu_to_be32(t->tv_nsec);
1078 return p;
1079}
1080
David Quigleyaa9c2662013-05-22 12:50:44 -04001081static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1082 const struct nfs4_label *label,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001083 const umode_t *umask,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001084 const struct nfs_server *server,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001085 const uint32_t attrmask[])
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086{
1087 char owner_name[IDMAP_NAMESZ];
1088 char owner_group[IDMAP_NAMESZ];
1089 int owner_namelen = 0;
1090 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001091 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001092 uint32_t len = 0;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001093 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
1095 /*
1096 * We reserve enough space to write the entire attribute buffer at once.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 */
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001098 if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001099 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001101 }
1102 if (iap->ia_valid & ATTR_MODE) {
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001103 if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001104 bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1105 len += 8;
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001106 } else if (attrmask[1] & FATTR4_WORD1_MODE) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001107 bmval[1] |= FATTR4_WORD1_MODE;
1108 len += 4;
1109 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001110 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001111 if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001112 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001114 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001115 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 /* XXX */
1117 strcpy(owner_name, "nobody");
1118 owner_namelen = sizeof("nobody") - 1;
1119 /* goto out; */
1120 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001121 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1123 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001124 if ((iap->ia_valid & ATTR_GID) &&
1125 (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001126 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001128 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001129 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 strcpy(owner_group, "nobody");
1131 owner_grouplen = sizeof("nobody") - 1;
1132 /* goto out; */
1133 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001134 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1136 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001137 if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1138 if (iap->ia_valid & ATTR_ATIME_SET) {
1139 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
Trond Myklebust36b37432018-03-20 17:03:10 -04001140 len += 4 + (nfstime4_maxsz << 2);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001141 } else if (iap->ia_valid & ATTR_ATIME) {
1142 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1143 len += 4;
1144 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001146 if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1147 if (iap->ia_valid & ATTR_MTIME_SET) {
1148 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
Trond Myklebust36b37432018-03-20 17:03:10 -04001149 len += 4 + (nfstime4_maxsz << 2);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001150 } else if (iap->ia_valid & ATTR_MTIME) {
1151 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1152 len += 4;
1153 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001155
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001156 if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001157 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1158 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1159 }
1160
Trond Myklebust40a3426c2018-03-20 17:03:09 -04001161 xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
1162 xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001163
1164 if (bmval[0] & FATTR4_WORD0_SIZE)
1165 p = xdr_encode_hyper(p, iap->ia_size);
1166 if (bmval[1] & FATTR4_WORD1_MODE)
1167 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1168 if (bmval[1] & FATTR4_WORD1_OWNER)
1169 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1170 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1171 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1172 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1173 if (iap->ia_valid & ATTR_ATIME_SET) {
1174 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Trond Myklebuste7d4b052019-10-04 16:43:09 -04001175 p = xdr_encode_nfstime4(p, &iap->ia_atime);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001176 } else
1177 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1178 }
1179 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1180 if (iap->ia_valid & ATTR_MTIME_SET) {
1181 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Trond Myklebuste7d4b052019-10-04 16:43:09 -04001182 p = xdr_encode_nfstime4(p, &iap->ia_mtime);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001183 } else
1184 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1185 }
Jia-Ju Baie2751462019-07-26 15:48:53 +08001186 if (label && (bmval[2] & FATTR4_WORD2_SECURITY_LABEL)) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001187 *p++ = cpu_to_be32(label->lfs);
1188 *p++ = cpu_to_be32(label->pi);
1189 *p++ = cpu_to_be32(label->len);
1190 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1191 }
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001192 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1193 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1194 *p++ = cpu_to_be32(*umask);
1195 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001196
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198}
1199
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001200static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001202 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1203 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204}
1205
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001206static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207{
Trond Myklebustab19b482012-03-04 18:13:57 -05001208 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001209 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001210 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211}
1212
Fred Isaman0b7c0152012-04-20 14:47:39 -04001213static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214{
Al Viro8687b632006-10-19 23:28:48 -07001215 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001216
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001217 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1218 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001219 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001220 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221}
1222
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001223static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224{
Al Viro8687b632006-10-19 23:28:48 -07001225 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001226
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001227 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1228 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230 switch (create->ftype) {
1231 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001232 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001233 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001234 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1235 create->u.symlink.len);
1236 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 break;
1238
1239 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001240 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001241 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001242 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 break;
1244
1245 default:
1246 break;
1247 }
1248
Benny Halevy811652b2009-08-14 17:19:34 +03001249 encode_string(xdr, create->name->len, create->name->name);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001250 encode_attrs(xdr, create->attrs, create->label, &create->umask,
1251 create->server, create->server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252}
1253
Trond Myklebust37c88762018-03-20 17:03:08 -04001254static void encode_getattr(struct xdr_stream *xdr,
1255 const __u32 *bitmap, const __u32 *mask, size_t len,
1256 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257{
Trond Myklebust37c88762018-03-20 17:03:08 -04001258 __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001260 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04001261 if (mask) {
1262 if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
1263 len = ARRAY_SIZE(masked_bitmap);
1264 len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
1265 bitmap = masked_bitmap;
Fred Isamandae100c2011-07-30 20:52:37 -04001266 }
Trond Myklebust37c88762018-03-20 17:03:08 -04001267 xdr_encode_bitmap4(xdr, bitmap, len);
Fred Isamandae100c2011-07-30 20:52:37 -04001268}
1269
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001270static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271{
Trond Myklebust37c88762018-03-20 17:03:08 -04001272 encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
1273 ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274}
1275
Andy Adamson88034c32012-05-23 05:02:34 -04001276static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001277 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001278 struct compound_hdr *hdr)
1279{
Trond Myklebust37c88762018-03-20 17:03:08 -04001280 encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
Andy Adamson88034c32012-05-23 05:02:34 -04001281}
1282
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001283static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284{
Trond Myklebust37c88762018-03-20 17:03:08 -04001285 encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
1286 ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287}
1288
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001289static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001290{
Trond Myklebust37c88762018-03-20 17:03:08 -04001291 encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
1292 ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001293}
1294
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001295static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296{
Trond Myklebustab19b482012-03-04 18:13:57 -05001297 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298}
1299
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001300static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301{
Trond Myklebustab19b482012-03-04 18:13:57 -05001302 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001303 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304}
1305
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001306static inline int nfs4_lock_type(struct file_lock *fl, int block)
1307{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001308 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001309 return block ? NFS4_READW_LT : NFS4_READ_LT;
1310 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1311}
1312
1313static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1314{
1315 if (fl->fl_end == OFFSET_MAX)
1316 return ~(uint64_t)0;
1317 return fl->fl_end - fl->fl_start + 1;
1318}
1319
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001320static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1321{
1322 __be32 *p;
1323
Trond Myklebustd035c362010-12-21 10:45:27 -05001324 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001325 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001326 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001327 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001328 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001329 xdr_encode_hyper(p, lowner->id);
1330}
1331
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332/*
1333 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1334 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1335 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001336static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337{
Al Viro8687b632006-10-19 23:28:48 -07001338 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001340 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1341 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001342 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1343 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001344 p = xdr_encode_hyper(p, args->fl->fl_start);
1345 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001346 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001347 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001348 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001349 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001350 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001351 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 }
1353 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001354 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001355 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357}
1358
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001359static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360{
Al Viro8687b632006-10-19 23:28:48 -07001361 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001363 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1364 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001365 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001366 p = xdr_encode_hyper(p, args->fl->fl_start);
1367 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001368 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369}
1370
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001371static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372{
Al Viro8687b632006-10-19 23:28:48 -07001373 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001375 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1376 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001377 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001378 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001379 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001380 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001381 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382}
1383
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001384static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1385{
Trond Myklebustab19b482012-03-04 18:13:57 -05001386 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001387 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001388}
1389
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001390static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391{
Trond Myklebustab19b482012-03-04 18:13:57 -05001392 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001393 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394}
1395
Jeff Layton5b5faaf2017-06-29 06:34:52 -07001396static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
1397{
1398 encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
1399}
1400
Trond Myklebust6ae37332015-01-30 14:21:14 -05001401static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402{
Al Viro8687b632006-10-19 23:28:48 -07001403 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
Benny Halevy13c65ce2009-08-14 17:19:25 +03001405 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001406 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001407 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408}
1409
1410static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1411{
Al Viro8687b632006-10-19 23:28:48 -07001412 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 /*
1414 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1415 * owner 4 = 32
1416 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001417 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001418 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001419 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001420 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001421 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001422 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001423 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001424 *p++ = cpu_to_be32(arg->id.uniquifier);
1425 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426}
1427
1428static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1429{
Al Viro8687b632006-10-19 23:28:48 -07001430 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
Benny Halevy13c65ce2009-08-14 17:19:25 +03001432 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001433 switch(arg->createmode) {
1434 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001435 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001436 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1437 arg->server, arg->server->attr_bitmask);
Andy Adamson05d564f2008-12-23 16:06:15 -05001438 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001439 case NFS4_CREATE_GUARDED:
1440 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001441 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1442 arg->server, arg->server->attr_bitmask);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001443 break;
1444 case NFS4_CREATE_EXCLUSIVE:
1445 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1446 encode_nfs4_verifier(xdr, &arg->u.verifier);
1447 break;
1448 case NFS4_CREATE_EXCLUSIVE4_1:
1449 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1450 encode_nfs4_verifier(xdr, &arg->u.verifier);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001451 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1452 arg->server, arg->server->exclcreat_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 }
1454}
1455
1456static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1457{
Al Viro8687b632006-10-19 23:28:48 -07001458 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Benny Halevy13c65ce2009-08-14 17:19:25 +03001460 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001462 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001463 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001464 break;
1465 default:
Benny Halevy34558512009-08-14 17:19:30 +03001466 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001467 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 }
1469}
1470
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001471static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472{
Al Viro8687b632006-10-19 23:28:48 -07001473 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Benny Halevy13c65ce2009-08-14 17:19:25 +03001475 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001477 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001478 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001479 break;
1480 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001481 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001482 break;
1483 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001484 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001485 break;
1486 default:
1487 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 }
1489}
1490
1491static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1492{
Al Viro8687b632006-10-19 23:28:48 -07001493 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
Benny Halevy13c65ce2009-08-14 17:19:25 +03001495 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001496 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 encode_string(xdr, name->len, name->name);
1498}
1499
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001500static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501{
Al Viro8687b632006-10-19 23:28:48 -07001502 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503
Benny Halevy13c65ce2009-08-14 17:19:25 +03001504 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001505 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 encode_delegation_type(xdr, type);
1507}
1508
1509static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1510{
Al Viro8687b632006-10-19 23:28:48 -07001511 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001513 p = reserve_space(xdr, 4);
1514 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1515 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 encode_string(xdr, name->len, name->name);
1517}
1518
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001519static inline void encode_claim_fh(struct xdr_stream *xdr)
1520{
1521 __be32 *p;
1522
1523 p = reserve_space(xdr, 4);
1524 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1525}
1526
1527static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1528{
1529 __be32 *p;
1530
1531 p = reserve_space(xdr, 4);
1532 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1533 encode_nfs4_stateid(xdr, stateid);
1534}
1535
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001536static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537{
Trond Myklebustab19b482012-03-04 18:13:57 -05001538 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 encode_openhdr(xdr, arg);
1540 encode_opentype(xdr, arg);
1541 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001542 case NFS4_OPEN_CLAIM_NULL:
1543 encode_claim_null(xdr, arg->name);
1544 break;
1545 case NFS4_OPEN_CLAIM_PREVIOUS:
1546 encode_claim_previous(xdr, arg->u.delegation_type);
1547 break;
1548 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1549 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1550 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001551 case NFS4_OPEN_CLAIM_FH:
1552 encode_claim_fh(xdr);
1553 break;
1554 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1555 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1556 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001557 default:
1558 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560}
1561
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001562static 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 -07001563{
Trond Myklebustab19b482012-03-04 18:13:57 -05001564 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001565 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001566 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567}
1568
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001569static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570{
Trond Myklebustab19b482012-03-04 18:13:57 -05001571 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001572 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001573 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001574 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575}
1576
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001577static void
Andy Adamsond0179312008-12-23 16:06:17 -05001578encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579{
Trond Myklebustab19b482012-03-04 18:13:57 -05001580 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001581 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582}
1583
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001584static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585{
Trond Myklebustab19b482012-03-04 18:13:57 -05001586 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587}
1588
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001589static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1590 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591{
Al Viro8687b632006-10-19 23:28:48 -07001592 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
Trond Myklebustab19b482012-03-04 18:13:57 -05001594 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001595 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
Benny Halevy13c65ce2009-08-14 17:19:25 +03001597 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001598 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001599 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600}
1601
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001602static 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 -07001603{
David Quigleyaa9c2662013-05-22 12:50:44 -04001604 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001605 FATTR4_WORD0_RDATTR_ERROR,
1606 FATTR4_WORD1_MOUNTED_ON_FILEID,
1607 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001608 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001609 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001610 uint32_t attrlen = 0;
1611 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001613 if (readdir->plus) {
1614 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001615 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001616 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1617 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1618 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1619 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001620 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001621 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001622 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001623 /* Use mounted_on_fileid only if the server supports it */
1624 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1625 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001626 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1627 attrs[i] &= readdir->bitmask[i];
1628 if (attrs[i] != 0)
1629 attrlen = i+1;
1630 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001631
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001632 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001633 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001634 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001635 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001636 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001637 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001638 *p++ = cpu_to_be32(attrlen);
1639 for (i = 0; i < attrlen; i++)
1640 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001641 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001642
1643 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001644 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001645 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001646 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001647 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001648 attrs[1] & readdir->bitmask[1],
1649 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650}
1651
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001652static 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 -07001653{
Trond Myklebustab19b482012-03-04 18:13:57 -05001654 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655}
1656
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001657static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658{
Trond Myklebustab19b482012-03-04 18:13:57 -05001659 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001660 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661}
1662
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001663static 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 -07001664{
Trond Myklebustab19b482012-03-04 18:13:57 -05001665 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001666 encode_string(xdr, oldname->len, oldname->name);
1667 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668}
1669
Chuck Leverbb4dae52012-03-01 17:01:48 -05001670static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1671 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001673 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001674 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675}
1676
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001677static void
Andy Adamsond0179312008-12-23 16:06:17 -05001678encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001679{
Trond Myklebustab19b482012-03-04 18:13:57 -05001680 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001681}
1682
Chuck Lever9f06c712010-12-14 14:59:18 +00001683static void
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001684encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1685 struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001686{
Al Viro8687b632006-10-19 23:28:48 -07001687 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001688
Trond Myklebustab19b482012-03-04 18:13:57 -05001689 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001690 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001691 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001692 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001693 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001694 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001695 *p = cpu_to_be32(arg->acl_len);
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01001696 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001697}
1698
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001699static void
Andy Adamsond0179312008-12-23 16:06:17 -05001700encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701{
Trond Myklebustab19b482012-03-04 18:13:57 -05001702 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703}
1704
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001705static 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 -07001706{
Trond Myklebustab19b482012-03-04 18:13:57 -05001707 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001708 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001709 encode_attrs(xdr, arg->iap, arg->label, NULL, server,
1710 server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711}
1712
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001713static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714{
Al Viro8687b632006-10-19 23:28:48 -07001715 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Trond Myklebust70019512012-03-04 20:49:32 -05001717 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001718 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
Jeff Layton3a6bb732015-06-09 19:43:57 -04001720 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1721 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001722 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001723 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1725 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001726 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001727 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728}
1729
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001730static 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 -07001731{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001732 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1733 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001734 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001735 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736}
1737
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001738static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1739 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740{
Al Viro8687b632006-10-19 23:28:48 -07001741 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
Trond Myklebustab19b482012-03-04 18:13:57 -05001743 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001744 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
Benny Halevy13c65ce2009-08-14 17:19:25 +03001746 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001747 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001748 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001749 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
1751 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752}
1753
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001754static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755{
Trond Myklebustab19b482012-03-04 18:13:57 -05001756 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001757 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001759
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001760static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1761{
Trond Myklebustab19b482012-03-04 18:13:57 -05001762 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001763 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001764}
1765
Benny Halevy99fe60d2009-04-01 09:22:29 -04001766#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001767/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001768static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001769 const struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001770 struct compound_hdr *hdr)
1771{
1772 __be32 *p;
1773
1774 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1775 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001776 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001777 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001778 *p++ = cpu_to_be32(args->dir);
1779 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001780}
1781
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001782static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001783{
1784 unsigned int i;
1785 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1786 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1787 encode_uint32(xdr, op_map->u.words[i]);
1788}
1789
Benny Halevy99fe60d2009-04-01 09:22:29 -04001790static void encode_exchange_id(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001791 const struct nfs41_exchange_id_args *args,
Benny Halevy99fe60d2009-04-01 09:22:29 -04001792 struct compound_hdr *hdr)
1793{
1794 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001795 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001796 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001797
Trond Myklebust70019512012-03-04 20:49:32 -05001798 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Trond Myklebustfd405592017-08-01 16:02:47 -04001799 encode_nfs4_verifier(xdr, &args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001800
Jeff Layton3a6bb732015-06-09 19:43:57 -04001801 encode_string(xdr, strlen(args->client->cl_owner_id),
1802 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001803
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001804 encode_uint32(xdr, args->flags);
1805 encode_uint32(xdr, args->state_protect.how);
1806
1807 switch (args->state_protect.how) {
1808 case SP4_NONE:
1809 break;
1810 case SP4_MACH_CRED:
1811 encode_op_map(xdr, &args->state_protect.enforce);
1812 encode_op_map(xdr, &args->state_protect.allow);
1813 break;
1814 default:
1815 WARN_ON_ONCE(1);
1816 break;
1817 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001818
1819 if (send_implementation_id &&
1820 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1821 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001822 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001823 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1824 utsname()->sysname, utsname()->release,
1825 utsname()->version, utsname()->machine);
1826
1827 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001828 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001829
1830 encode_string(xdr,
1831 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1832 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1833 encode_string(xdr, len, impl_name);
1834 /* just send zeros for nii_date - the date is in nii_name */
1835 p = reserve_space(xdr, 12);
1836 p = xdr_encode_hyper(p, 0);
1837 *p = cpu_to_be32(0);
1838 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001839 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001840}
Andy Adamsonfc931582009-04-01 09:22:31 -04001841
1842static void encode_create_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001843 const struct nfs41_create_session_args *args,
Andy Adamsonfc931582009-04-01 09:22:31 -04001844 struct compound_hdr *hdr)
1845{
1846 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001847 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001848 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001849 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001850 u32 max_resp_sz_cached;
1851
1852 /*
1853 * Assumes OPEN is the biggest non-idempotent compound.
1854 * 2 is the verifier.
1855 */
J. Bruce Fields35c036e2017-09-20 12:42:13 -04001856 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
1857 * XDR_UNIT + RPC_MAX_AUTH_SIZE;
Andy Adamsonfc931582009-04-01 09:22:31 -04001858
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001859 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001860 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001861 p = xdr_encode_hyper(p, args->clientid);
1862 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001863 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001864
Andy Adamsonfc931582009-04-01 09:22:31 -04001865 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001866 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001867 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1868 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001869 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001870 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1871 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1872 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001873
1874 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001875 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001876 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1877 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1878 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1879 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1880 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1881 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001882
Benny Halevye75bc1c2009-08-14 17:18:54 +03001883 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001884 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001885 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001886
1887 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001888 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001889 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001890 *p++ = cpu_to_be32(0); /* UID */
1891 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001892 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001893}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001894
1895static void encode_destroy_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001896 const struct nfs4_session *session,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001897 struct compound_hdr *hdr)
1898{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001899 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1900 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001901}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001902
Trond Myklebust66245532012-05-25 17:18:09 -04001903static void encode_destroy_clientid(struct xdr_stream *xdr,
1904 uint64_t clientid,
1905 struct compound_hdr *hdr)
1906{
1907 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1908 encode_uint64(xdr, clientid);
1909}
1910
Ricardo Labiaga180197532009-12-05 16:08:40 -05001911static void encode_reclaim_complete(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001912 const struct nfs41_reclaim_complete_args *args,
Ricardo Labiaga180197532009-12-05 16:08:40 -05001913 struct compound_hdr *hdr)
1914{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001915 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1916 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001917}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001918#endif /* CONFIG_NFS_V4_1 */
1919
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001920static void encode_sequence(struct xdr_stream *xdr,
1921 const struct nfs4_sequence_args *args,
1922 struct compound_hdr *hdr)
1923{
1924#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001925 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001926 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001927 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001928 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001929
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001930 tp = slot->table;
1931 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001932 if (!session)
1933 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001934
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001935 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001936
1937 /*
1938 * Sessionid + seqid + slotid + max slotid + cache_this
1939 */
1940 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1941 "max_slotid=%d cache_this=%d\n",
1942 __func__,
1943 ((u32 *)session->sess_id.data)[0],
1944 ((u32 *)session->sess_id.data)[1],
1945 ((u32 *)session->sess_id.data)[2],
1946 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001947 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001948 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001949 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001950 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001951 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001952 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001953 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001954 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001955#endif /* CONFIG_NFS_V4_1 */
1956}
1957
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001958#ifdef CONFIG_NFS_V4_1
1959static void
1960encode_getdeviceinfo(struct xdr_stream *xdr,
1961 const struct nfs4_getdeviceinfo_args *args,
1962 struct compound_hdr *hdr)
1963{
1964 __be32 *p;
1965
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001966 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001967 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001968 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1969 NFS4_DEVICEID4_SIZE);
1970 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001971 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001972
1973 p = reserve_space(xdr, 4 + 4);
1974 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001975 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001976}
1977
1978static void
1979encode_layoutget(struct xdr_stream *xdr,
1980 const struct nfs4_layoutget_args *args,
1981 struct compound_hdr *hdr)
1982{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001983 __be32 *p;
1984
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001985 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1986 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001987 *p++ = cpu_to_be32(0); /* Signal layout available */
1988 *p++ = cpu_to_be32(args->type);
1989 *p++ = cpu_to_be32(args->range.iomode);
1990 p = xdr_encode_hyper(p, args->range.offset);
1991 p = xdr_encode_hyper(p, args->range.length);
1992 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001993 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001994 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001995
1996 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1997 __func__,
1998 args->type,
1999 args->range.iomode,
2000 (unsigned long)args->range.offset,
2001 (unsigned long)args->range.length,
2002 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002003}
Andy Adamson863a3c62011-03-23 13:27:54 +00002004
2005static int
2006encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03002007 struct inode *inode,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002008 const struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00002009 struct compound_hdr *hdr)
2010{
2011 __be32 *p;
2012
2013 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2014 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2015
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002016 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2017 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00002018 /* Only whole file layouts */
2019 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002020 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002021 *p = cpu_to_be32(0); /* reclaim */
2022 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04002023 if (args->lastbytewritten != U64_MAX) {
2024 p = reserve_space(xdr, 20);
2025 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2026 p = xdr_encode_hyper(p, args->lastbytewritten);
2027 } else {
2028 p = reserve_space(xdr, 12);
2029 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2030 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002031 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2032 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002033
Trond Myklebust73504742017-04-20 16:48:14 -04002034 encode_uint32(xdr, args->layoutupdate_len);
2035 if (args->layoutupdate_pages)
2036 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2037 args->layoutupdate_len);
Andy Adamson863a3c62011-03-23 13:27:54 +00002038
Andy Adamson863a3c62011-03-23 13:27:54 +00002039 return 0;
2040}
Benny Halevycbe82602011-05-22 19:52:37 +03002041
2042static void
2043encode_layoutreturn(struct xdr_stream *xdr,
2044 const struct nfs4_layoutreturn_args *args,
2045 struct compound_hdr *hdr)
2046{
2047 __be32 *p;
2048
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002049 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2050 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002051 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2052 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002053 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002054 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002055 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002056 p = xdr_encode_hyper(p, args->range.offset);
2057 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002058 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002059 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002060 spin_unlock(&args->inode->i_lock);
Trond Myklebust4d796d72016-09-23 11:38:08 -04002061 if (args->ld_private->ops && args->ld_private->ops->encode)
2062 args->ld_private->ops->encode(xdr, args, args->ld_private);
Trond Myklebust94e5c572016-09-15 18:49:52 -04002063 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002064 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002065}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002066
2067static int
2068encode_secinfo_no_name(struct xdr_stream *xdr,
2069 const struct nfs41_secinfo_no_name_args *args,
2070 struct compound_hdr *hdr)
2071{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002072 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2073 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002074 return 0;
2075}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002076
2077static void encode_test_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002078 const struct nfs41_test_stateid_args *args,
Bryan Schumaker7d974792011-06-02 14:59:08 -04002079 struct compound_hdr *hdr)
2080{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002081 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2082 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002083 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002084}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002085
2086static void encode_free_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002087 const struct nfs41_free_stateid_args *args,
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002088 struct compound_hdr *hdr)
2089{
Trond Myklebustab19b482012-03-04 18:13:57 -05002090 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002091 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002092}
Trond Myklebustcf805162016-11-15 14:56:07 -05002093#else
2094static inline void
2095encode_layoutreturn(struct xdr_stream *xdr,
2096 const struct nfs4_layoutreturn_args *args,
2097 struct compound_hdr *hdr)
2098{
2099}
Fred Isaman56f487f2016-09-21 11:43:41 -04002100
2101static void
2102encode_layoutget(struct xdr_stream *xdr,
2103 const struct nfs4_layoutget_args *args,
2104 struct compound_hdr *hdr)
2105{
2106}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002107#endif /* CONFIG_NFS_V4_1 */
2108
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109/*
2110 * END OF "GENERIC" ENCODE ROUTINES.
2111 */
2112
Benny Halevy66cc0422009-04-01 09:22:10 -04002113static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2114{
2115#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002116 struct nfs4_session *session = args->sa_slot->table->session;
2117 if (session)
2118 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002119#endif /* CONFIG_NFS_V4_1 */
2120 return 0;
2121}
2122
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123/*
2124 * Encode an ACCESS request
2125 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002126static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002127 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002129 const struct nfs4_accessargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002131 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133
Chuck Lever9f06c712010-12-14 14:59:18 +00002134 encode_compound_hdr(xdr, req, &hdr);
2135 encode_sequence(xdr, &args->seq_args, &hdr);
2136 encode_putfh(xdr, args->fh, &hdr);
2137 encode_access(xdr, args->access, &hdr);
Trond Myklebust8bcbe7d2018-03-20 17:03:11 -04002138 if (args->bitmask)
2139 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002140 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141}
2142
2143/*
2144 * Encode LOOKUP request
2145 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002146static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002147 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002149 const struct nfs4_lookup_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002151 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153
Chuck Lever9f06c712010-12-14 14:59:18 +00002154 encode_compound_hdr(xdr, req, &hdr);
2155 encode_sequence(xdr, &args->seq_args, &hdr);
2156 encode_putfh(xdr, args->dir_fh, &hdr);
2157 encode_lookup(xdr, args->name, &hdr);
2158 encode_getfh(xdr, &hdr);
2159 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002160 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161}
2162
2163/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07002164 * Encode LOOKUPP request
2165 */
2166static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
2167 const void *data)
2168{
2169 const struct nfs4_lookupp_arg *args = data;
2170 struct compound_hdr hdr = {
2171 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2172 };
2173
2174 encode_compound_hdr(xdr, req, &hdr);
2175 encode_sequence(xdr, &args->seq_args, &hdr);
2176 encode_putfh(xdr, args->fh, &hdr);
2177 encode_lookupp(xdr, &hdr);
2178 encode_getfh(xdr, &hdr);
2179 encode_getfattr(xdr, args->bitmask, &hdr);
2180 encode_nops(&hdr);
2181}
2182
2183/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 * Encode LOOKUP_ROOT request
2185 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002186static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2187 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002188 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002190 const struct nfs4_lookup_root_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002192 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
Chuck Lever9f06c712010-12-14 14:59:18 +00002195 encode_compound_hdr(xdr, req, &hdr);
2196 encode_sequence(xdr, &args->seq_args, &hdr);
2197 encode_putrootfh(xdr, &hdr);
2198 encode_getfh(xdr, &hdr);
2199 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002200 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201}
2202
2203/*
2204 * Encode REMOVE request
2205 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002206static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002207 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002209 const struct nfs_removeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002211 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
Chuck Lever9f06c712010-12-14 14:59:18 +00002214 encode_compound_hdr(xdr, req, &hdr);
2215 encode_sequence(xdr, &args->seq_args, &hdr);
2216 encode_putfh(xdr, args->fh, &hdr);
2217 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002218 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219}
2220
2221/*
2222 * Encode RENAME request
2223 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002224static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002225 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002227 const struct nfs_renameargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002229 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
Chuck Lever9f06c712010-12-14 14:59:18 +00002232 encode_compound_hdr(xdr, req, &hdr);
2233 encode_sequence(xdr, &args->seq_args, &hdr);
2234 encode_putfh(xdr, args->old_dir, &hdr);
2235 encode_savefh(xdr, &hdr);
2236 encode_putfh(xdr, args->new_dir, &hdr);
2237 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002238 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239}
2240
2241/*
2242 * Encode LINK request
2243 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002244static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002245 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002247 const struct nfs4_link_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002249 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251
Chuck Lever9f06c712010-12-14 14:59:18 +00002252 encode_compound_hdr(xdr, req, &hdr);
2253 encode_sequence(xdr, &args->seq_args, &hdr);
2254 encode_putfh(xdr, args->fh, &hdr);
2255 encode_savefh(xdr, &hdr);
2256 encode_putfh(xdr, args->dir_fh, &hdr);
2257 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002258 encode_restorefh(xdr, &hdr);
2259 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002260 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261}
2262
2263/*
2264 * Encode CREATE request
2265 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002266static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002267 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002269 const struct nfs4_create_arg *args = data;
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->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002277 encode_create(xdr, args, &hdr);
2278 encode_getfh(xdr, &hdr);
2279 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002280 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281}
2282
2283/*
2284 * Encode SYMLINK request
2285 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002286static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002287 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002289 const struct nfs4_create_arg *args = data;
2290
Chuck Lever9f06c712010-12-14 14:59:18 +00002291 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292}
2293
2294/*
2295 * Encode GETATTR request
2296 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002297static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002298 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002300 const struct nfs4_getattr_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002302 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
Chuck Lever9f06c712010-12-14 14:59:18 +00002305 encode_compound_hdr(xdr, req, &hdr);
2306 encode_sequence(xdr, &args->seq_args, &hdr);
2307 encode_putfh(xdr, args->fh, &hdr);
2308 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002309 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310}
2311
2312/*
2313 * Encode a CLOSE request
2314 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002315static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002316 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002318 const struct nfs_closeargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002319 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002320 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002321 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322
Chuck Lever9f06c712010-12-14 14:59:18 +00002323 encode_compound_hdr(xdr, req, &hdr);
2324 encode_sequence(xdr, &args->seq_args, &hdr);
2325 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002326 if (args->lr_args)
2327 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002328 if (args->bitmask != NULL)
2329 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebustd8d84982016-12-19 12:14:44 -05002330 encode_close(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002331 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332}
2333
2334/*
2335 * Encode an OPEN request
2336 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002337static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002338 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002340 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002342 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344
Chuck Lever9f06c712010-12-14 14:59:18 +00002345 encode_compound_hdr(xdr, req, &hdr);
2346 encode_sequence(xdr, &args->seq_args, &hdr);
2347 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002348 encode_open(xdr, args, &hdr);
2349 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002350 if (args->access)
2351 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002352 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Fred Isaman56f487f2016-09-21 11:43:41 -04002353 if (args->lg_args) {
2354 encode_layoutget(xdr, args->lg_args, &hdr);
Chuck Levercf500ba2019-02-11 11:25:20 -05002355 rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2356 args->lg_args->layout.pglen,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05002357 hdr.replen - pagepad_maxsz);
Fred Isaman56f487f2016-09-21 11:43:41 -04002358 }
Andy Adamsond0179312008-12-23 16:06:17 -05002359 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360}
2361
2362/*
2363 * Encode an OPEN_CONFIRM request
2364 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002365static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2366 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002367 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002369 const struct nfs_open_confirmargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002371 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373
Chuck Lever9f06c712010-12-14 14:59:18 +00002374 encode_compound_hdr(xdr, req, &hdr);
2375 encode_putfh(xdr, args->fh, &hdr);
2376 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002377 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378}
2379
2380/*
2381 * Encode an OPEN request with no attributes.
2382 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002383static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2384 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002385 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002387 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002389 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391
Chuck Lever9f06c712010-12-14 14:59:18 +00002392 encode_compound_hdr(xdr, req, &hdr);
2393 encode_sequence(xdr, &args->seq_args, &hdr);
2394 encode_putfh(xdr, args->fh, &hdr);
2395 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002396 if (args->access)
2397 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002398 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Fred Isaman56f487f2016-09-21 11:43:41 -04002399 if (args->lg_args) {
2400 encode_layoutget(xdr, args->lg_args, &hdr);
Chuck Levercf500ba2019-02-11 11:25:20 -05002401 rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2402 args->lg_args->layout.pglen,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05002403 hdr.replen - pagepad_maxsz);
Fred Isaman56f487f2016-09-21 11:43:41 -04002404 }
Andy Adamsond0179312008-12-23 16:06:17 -05002405 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406}
2407
2408/*
2409 * Encode an OPEN_DOWNGRADE request
2410 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002411static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2412 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002413 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002415 const struct nfs_closeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002417 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
Chuck Lever9f06c712010-12-14 14:59:18 +00002420 encode_compound_hdr(xdr, req, &hdr);
2421 encode_sequence(xdr, &args->seq_args, &hdr);
2422 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustb6808142016-11-20 13:34:16 -05002423 if (args->lr_args)
2424 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002425 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002426 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427}
2428
2429/*
2430 * Encode a LOCK request
2431 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002432static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002433 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002435 const struct nfs_lock_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002437 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439
Chuck Lever9f06c712010-12-14 14:59:18 +00002440 encode_compound_hdr(xdr, req, &hdr);
2441 encode_sequence(xdr, &args->seq_args, &hdr);
2442 encode_putfh(xdr, args->fh, &hdr);
2443 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002444 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445}
2446
2447/*
2448 * Encode a LOCKT request
2449 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002450static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002451 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002453 const struct nfs_lockt_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002455 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457
Chuck Lever9f06c712010-12-14 14:59:18 +00002458 encode_compound_hdr(xdr, req, &hdr);
2459 encode_sequence(xdr, &args->seq_args, &hdr);
2460 encode_putfh(xdr, args->fh, &hdr);
2461 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002462 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463}
2464
2465/*
2466 * Encode a LOCKU request
2467 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002468static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002469 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002471 const struct nfs_locku_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002473 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
Chuck Lever9f06c712010-12-14 14:59:18 +00002476 encode_compound_hdr(xdr, req, &hdr);
2477 encode_sequence(xdr, &args->seq_args, &hdr);
2478 encode_putfh(xdr, args->fh, &hdr);
2479 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002480 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481}
2482
Chuck Lever9f06c712010-12-14 14:59:18 +00002483static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2484 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002485 const void *data)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002486{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002487 const struct nfs_release_lockowner_args *args = data;
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002488 struct compound_hdr hdr = {
2489 .minorversion = 0,
2490 };
2491
Chuck Lever9f06c712010-12-14 14:59:18 +00002492 encode_compound_hdr(xdr, req, &hdr);
2493 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002494 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002495}
2496
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497/*
2498 * Encode a READLINK request
2499 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002500static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002501 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002503 const struct nfs4_readlink *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002505 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507
Chuck Lever9f06c712010-12-14 14:59:18 +00002508 encode_compound_hdr(xdr, req, &hdr);
2509 encode_sequence(xdr, &args->seq_args, &hdr);
2510 encode_putfh(xdr, args->fh, &hdr);
2511 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002512
Chuck Levercf500ba2019-02-11 11:25:20 -05002513 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05002514 args->pglen, hdr.replen - pagepad_maxsz);
Andy Adamsond0179312008-12-23 16:06:17 -05002515 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516}
2517
2518/*
2519 * Encode a READDIR request
2520 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002521static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002522 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002524 const struct nfs4_readdir_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002526 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528
Chuck Lever9f06c712010-12-14 14:59:18 +00002529 encode_compound_hdr(xdr, req, &hdr);
2530 encode_sequence(xdr, &args->seq_args, &hdr);
2531 encode_putfh(xdr, args->fh, &hdr);
2532 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002533
Chuck Levercf500ba2019-02-11 11:25:20 -05002534 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05002535 args->count, hdr.replen - pagepad_maxsz);
Andy Adamsond0179312008-12-23 16:06:17 -05002536 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537}
2538
2539/*
2540 * Encode a READ request
2541 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002542static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002543 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002545 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002547 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549
Chuck Lever9f06c712010-12-14 14:59:18 +00002550 encode_compound_hdr(xdr, req, &hdr);
2551 encode_sequence(xdr, &args->seq_args, &hdr);
2552 encode_putfh(xdr, args->fh, &hdr);
2553 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554
Chuck Levercf500ba2019-02-11 11:25:20 -05002555 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05002556 args->count, hdr.replen - pagepad_maxsz);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002557 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002558 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559}
2560
2561/*
2562 * Encode an SETATTR request
2563 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002564static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002565 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002567 const struct nfs_setattrargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002568 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002569 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002570 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571
Chuck Lever9f06c712010-12-14 14:59:18 +00002572 encode_compound_hdr(xdr, req, &hdr);
2573 encode_sequence(xdr, &args->seq_args, &hdr);
2574 encode_putfh(xdr, args->fh, &hdr);
2575 encode_setattr(xdr, args, args->server, &hdr);
2576 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002577 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578}
2579
2580/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002581 * Encode a GETACL request
2582 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002583static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002584 const void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002585{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002586 const struct nfs_getaclargs *args = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002587 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002588 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002589 };
Trond Myklebust37c88762018-03-20 17:03:08 -04002590 const __u32 nfs4_acl_bitmap[1] = {
2591 [0] = FATTR4_WORD0_ACL,
2592 };
Benny Halevy28f56692009-04-01 09:22:09 -04002593 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002594
Chuck Lever9f06c712010-12-14 14:59:18 +00002595 encode_compound_hdr(xdr, req, &hdr);
2596 encode_sequence(xdr, &args->seq_args, &hdr);
2597 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fields6682c142017-02-23 14:53:39 -05002598 replen = hdr.replen + op_decode_hdr_maxsz;
Trond Myklebust37c88762018-03-20 17:03:08 -04002599 encode_getattr(xdr, nfs4_acl_bitmap, NULL,
2600 ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002601
Chuck Levercf500ba2019-02-11 11:25:20 -05002602 rpc_prepare_reply_pages(req, args->acl_pages, 0,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05002603 args->acl_len, replen);
Andy Adamsond0179312008-12-23 16:06:17 -05002604 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002605}
2606
2607/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 * Encode a WRITE request
2609 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002610static void nfs4_xdr_enc_write(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 nfs_pgio_args *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_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002622 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002623 if (args->bitmask)
2624 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002625 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626}
2627
2628/*
2629 * a COMMIT request
2630 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002631static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002632 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002634 const struct nfs_commitargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002636 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638
Chuck Lever9f06c712010-12-14 14:59:18 +00002639 encode_compound_hdr(xdr, req, &hdr);
2640 encode_sequence(xdr, &args->seq_args, &hdr);
2641 encode_putfh(xdr, args->fh, &hdr);
2642 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002643 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644}
2645
2646/*
2647 * FSINFO request
2648 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002649static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002650 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002652 const struct nfs4_fsinfo_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002654 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656
Chuck Lever9f06c712010-12-14 14:59:18 +00002657 encode_compound_hdr(xdr, req, &hdr);
2658 encode_sequence(xdr, &args->seq_args, &hdr);
2659 encode_putfh(xdr, args->fh, &hdr);
2660 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002661 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662}
2663
2664/*
2665 * a PATHCONF request
2666 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002667static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, 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_pathconf_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002672 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674
Chuck Lever9f06c712010-12-14 14:59:18 +00002675 encode_compound_hdr(xdr, req, &hdr);
2676 encode_sequence(xdr, &args->seq_args, &hdr);
2677 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002678 encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
2679 ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002680 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681}
2682
2683/*
2684 * a STATFS request
2685 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002686static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002687 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002689 const struct nfs4_statfs_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002691 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693
Chuck Lever9f06c712010-12-14 14:59:18 +00002694 encode_compound_hdr(xdr, req, &hdr);
2695 encode_sequence(xdr, &args->seq_args, &hdr);
2696 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002697 encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
2698 ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002699 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700}
2701
2702/*
2703 * GETATTR_BITMAP request
2704 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002705static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2706 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002707 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002709 const struct nfs4_server_caps_arg *args = data;
Kinglong Mee8c612822015-08-26 21:12:58 +08002710 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002712 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714
Chuck Lever9f06c712010-12-14 14:59:18 +00002715 encode_compound_hdr(xdr, req, &hdr);
2716 encode_sequence(xdr, &args->seq_args, &hdr);
2717 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002718 encode_getattr(xdr, bitmask, NULL, 3, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002719 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720}
2721
2722/*
2723 * a RENEW request
2724 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002725static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002726 const void *data)
2727
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002729 const struct nfs_client *clp = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002731 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 };
2733
Chuck Lever9f06c712010-12-14 14:59:18 +00002734 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002735 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002736 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737}
2738
2739/*
2740 * a SETCLIENTID request
2741 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002742static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2743 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002744 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002746 const struct nfs4_setclientid *sc = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002748 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 };
2750
Chuck Lever9f06c712010-12-14 14:59:18 +00002751 encode_compound_hdr(xdr, req, &hdr);
2752 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002753 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754}
2755
2756/*
2757 * a SETCLIENTID_CONFIRM request
2758 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002759static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2760 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002761 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002763 const struct nfs4_setclientid_res *arg = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002765 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767
Chuck Lever9f06c712010-12-14 14:59:18 +00002768 encode_compound_hdr(xdr, req, &hdr);
2769 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002770 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771}
2772
2773/*
2774 * DELEGRETURN request
2775 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002776static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2777 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002778 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002780 const struct nfs4_delegreturnargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002782 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784
Chuck Lever9f06c712010-12-14 14:59:18 +00002785 encode_compound_hdr(xdr, req, &hdr);
2786 encode_sequence(xdr, &args->seq_args, &hdr);
2787 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust586f1c32016-11-15 15:03:33 -05002788 if (args->lr_args)
2789 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05002790 if (args->bitmask)
2791 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002792 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002793 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794}
2795
2796/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002797 * Encode FS_LOCATIONS request
2798 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002799static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2800 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002801 const void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002802{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002803 const struct nfs4_fs_locations_arg *args = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002804 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002805 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002806 };
Benny Halevy28f56692009-04-01 09:22:09 -04002807 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002808
Chuck Lever9f06c712010-12-14 14:59:18 +00002809 encode_compound_hdr(xdr, req, &hdr);
2810 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002811 if (args->migration) {
2812 encode_putfh(xdr, args->fh, &hdr);
2813 replen = hdr.replen;
2814 encode_fs_locations(xdr, args->bitmask, &hdr);
2815 if (args->renew)
2816 encode_renew(xdr, args->clientid, &hdr);
2817 } else {
2818 encode_putfh(xdr, args->dir_fh, &hdr);
2819 encode_lookup(xdr, args->name, &hdr);
2820 replen = hdr.replen;
2821 encode_fs_locations(xdr, args->bitmask, &hdr);
2822 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002823
Chuck Levercf500ba2019-02-11 11:25:20 -05002824 rpc_prepare_reply_pages(req, (struct page **)&args->page, 0,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05002825 PAGE_SIZE, replen);
Andy Adamsond0179312008-12-23 16:06:17 -05002826 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002827}
2828
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002829/*
2830 * Encode SECINFO request
2831 */
2832static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2833 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002834 const void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002835{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002836 const struct nfs4_secinfo_arg *args = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002837 struct compound_hdr hdr = {
2838 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2839 };
2840
2841 encode_compound_hdr(xdr, req, &hdr);
2842 encode_sequence(xdr, &args->seq_args, &hdr);
2843 encode_putfh(xdr, args->dir_fh, &hdr);
2844 encode_secinfo(xdr, args->name, &hdr);
2845 encode_nops(&hdr);
2846}
2847
Chuck Lever44c99932013-10-17 14:13:30 -04002848/*
2849 * Encode FSID_PRESENT request
2850 */
2851static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2852 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002853 const void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04002854{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002855 const struct nfs4_fsid_present_arg *args = data;
Chuck Lever44c99932013-10-17 14:13:30 -04002856 struct compound_hdr hdr = {
2857 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2858 };
2859
2860 encode_compound_hdr(xdr, req, &hdr);
2861 encode_sequence(xdr, &args->seq_args, &hdr);
2862 encode_putfh(xdr, args->fh, &hdr);
2863 encode_getfh(xdr, &hdr);
2864 if (args->renew)
2865 encode_renew(xdr, args->clientid, &hdr);
2866 encode_nops(&hdr);
2867}
2868
Benny Halevy99fe60d2009-04-01 09:22:29 -04002869#if defined(CONFIG_NFS_V4_1)
2870/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002871 * BIND_CONN_TO_SESSION request
2872 */
2873static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2874 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002875 const void *data)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002876{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002877 const struct nfs41_bind_conn_to_session_args *args = data;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002878 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002879 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002880 };
2881
2882 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002883 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002884 encode_nops(&hdr);
2885}
2886
2887/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002888 * EXCHANGE_ID request
2889 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002890static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2891 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002892 const void *data)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002893{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002894 const struct nfs41_exchange_id_args *args = data;
Benny Halevy99fe60d2009-04-01 09:22:29 -04002895 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002896 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002897 };
2898
Chuck Lever9f06c712010-12-14 14:59:18 +00002899 encode_compound_hdr(xdr, req, &hdr);
2900 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002901 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002902}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002903
2904/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002905 * a CREATE_SESSION request
2906 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002907static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2908 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002909 const void *data)
Andy Adamsonfc931582009-04-01 09:22:31 -04002910{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002911 const struct nfs41_create_session_args *args = data;
Andy Adamsonfc931582009-04-01 09:22:31 -04002912 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002913 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002914 };
2915
Chuck Lever9f06c712010-12-14 14:59:18 +00002916 encode_compound_hdr(xdr, req, &hdr);
2917 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002918 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002919}
2920
2921/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002922 * a DESTROY_SESSION request
2923 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002924static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2925 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002926 const void *data)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002927{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002928 const struct nfs4_session *session = data;
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002929 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002930 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002931 };
2932
Chuck Lever9f06c712010-12-14 14:59:18 +00002933 encode_compound_hdr(xdr, req, &hdr);
2934 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002935 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002936}
2937
2938/*
Trond Myklebust66245532012-05-25 17:18:09 -04002939 * a DESTROY_CLIENTID request
2940 */
2941static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2942 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002943 const void *data)
Trond Myklebust66245532012-05-25 17:18:09 -04002944{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002945 const struct nfs_client *clp = data;
Trond Myklebust66245532012-05-25 17:18:09 -04002946 struct compound_hdr hdr = {
2947 .minorversion = clp->cl_mvops->minor_version,
2948 };
2949
2950 encode_compound_hdr(xdr, req, &hdr);
2951 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2952 encode_nops(&hdr);
2953}
2954
2955/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002956 * a SEQUENCE request
2957 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002958static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002959 const void *data)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002960{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002961 const struct nfs4_sequence_args *args = data;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002962 struct compound_hdr hdr = {
2963 .minorversion = nfs4_xdr_minorversion(args),
2964 };
2965
Chuck Lever9f06c712010-12-14 14:59:18 +00002966 encode_compound_hdr(xdr, req, &hdr);
2967 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002968 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002969}
2970
Donald Buczek0efb01b2019-07-07 21:26:08 +02002971#endif
2972
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002973/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002974 * a GET_LEASE_TIME request
2975 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002976static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2977 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002978 const void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002979{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002980 const struct nfs4_get_lease_time_args *args = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04002981 struct compound_hdr hdr = {
2982 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2983 };
Fred Isamandae100c2011-07-30 20:52:37 -04002984 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002985
Chuck Lever9f06c712010-12-14 14:59:18 +00002986 encode_compound_hdr(xdr, req, &hdr);
2987 encode_sequence(xdr, &args->la_seq_args, &hdr);
2988 encode_putrootfh(xdr, &hdr);
2989 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002990 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002991}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002992
Donald Buczek0efb01b2019-07-07 21:26:08 +02002993#ifdef CONFIG_NFS_V4_1
2994
Ricardo Labiaga180197532009-12-05 16:08:40 -05002995/*
2996 * a RECLAIM_COMPLETE request
2997 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002998static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2999 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003000 const void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05003001{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003002 const struct nfs41_reclaim_complete_args *args = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05003003 struct compound_hdr hdr = {
3004 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
3005 };
3006
Chuck Lever9f06c712010-12-14 14:59:18 +00003007 encode_compound_hdr(xdr, req, &hdr);
3008 encode_sequence(xdr, &args->seq_args, &hdr);
3009 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05003010 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05003011}
3012
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003013/*
3014 * Encode GETDEVICEINFO request
3015 */
Chuck Lever9f06c712010-12-14 14:59:18 +00003016static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
3017 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003018 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003019{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003020 const struct nfs4_getdeviceinfo_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003021 struct compound_hdr hdr = {
3022 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3023 };
Trond Myklebust046e5cc2020-11-13 21:42:16 -05003024 uint32_t replen;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003025
Chuck Lever9f06c712010-12-14 14:59:18 +00003026 encode_compound_hdr(xdr, req, &hdr);
3027 encode_sequence(xdr, &args->seq_args, &hdr);
Trond Myklebust046e5cc2020-11-13 21:42:16 -05003028
Trond Myklebust9ed5af262020-11-21 20:46:18 -05003029 replen = hdr.replen + op_decode_hdr_maxsz + 2;
Trond Myklebust046e5cc2020-11-13 21:42:16 -05003030
Chuck Lever9f06c712010-12-14 14:59:18 +00003031 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003032
Trond Myklebust046e5cc2020-11-13 21:42:16 -05003033 /* set up reply kvec. device_addr4 opaque data is read into the
3034 * pages */
Chuck Levercf500ba2019-02-11 11:25:20 -05003035 rpc_prepare_reply_pages(req, args->pdev->pages, args->pdev->pgbase,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05003036 args->pdev->pglen, replen);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003037 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003038}
3039
3040/*
3041 * Encode LAYOUTGET request
3042 */
Chuck Lever9f06c712010-12-14 14:59:18 +00003043static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
3044 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003045 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003046{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003047 const struct nfs4_layoutget_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003048 struct compound_hdr hdr = {
3049 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3050 };
3051
Chuck Lever9f06c712010-12-14 14:59:18 +00003052 encode_compound_hdr(xdr, req, &hdr);
3053 encode_sequence(xdr, &args->seq_args, &hdr);
3054 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3055 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04003056
Chuck Levercf500ba2019-02-11 11:25:20 -05003057 rpc_prepare_reply_pages(req, args->layout.pages, 0,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05003058 args->layout.pglen, hdr.replen - pagepad_maxsz);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003059 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003060}
Andy Adamson863a3c62011-03-23 13:27:54 +00003061
3062/*
3063 * Encode LAYOUTCOMMIT request
3064 */
Benny Halevycbe82602011-05-22 19:52:37 +03003065static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3066 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003067 const void *priv)
Andy Adamson863a3c62011-03-23 13:27:54 +00003068{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003069 const struct nfs4_layoutcommit_args *args = priv;
Benny Halevyac7db722011-05-22 19:53:48 +03003070 struct nfs4_layoutcommit_data *data =
3071 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00003072 struct compound_hdr hdr = {
3073 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3074 };
3075
3076 encode_compound_hdr(xdr, req, &hdr);
3077 encode_sequence(xdr, &args->seq_args, &hdr);
3078 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03003079 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003080 encode_getfattr(xdr, args->bitmask, &hdr);
3081 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03003082}
3083
3084/*
3085 * Encode LAYOUTRETURN request
3086 */
3087static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3088 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003089 const void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03003090{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003091 const struct nfs4_layoutreturn_args *args = data;
Benny Halevycbe82602011-05-22 19:52:37 +03003092 struct compound_hdr hdr = {
3093 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3094 };
3095
3096 encode_compound_hdr(xdr, req, &hdr);
3097 encode_sequence(xdr, &args->seq_args, &hdr);
3098 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3099 encode_layoutreturn(xdr, args, &hdr);
3100 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003101}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003102
3103/*
3104 * Encode SECINFO_NO_NAME request
3105 */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003106static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003107 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003108 const void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003109{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003110 const struct nfs41_secinfo_no_name_args *args = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003111 struct compound_hdr hdr = {
3112 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3113 };
3114
3115 encode_compound_hdr(xdr, req, &hdr);
3116 encode_sequence(xdr, &args->seq_args, &hdr);
3117 encode_putrootfh(xdr, &hdr);
3118 encode_secinfo_no_name(xdr, args, &hdr);
3119 encode_nops(&hdr);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003120}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003121
3122/*
3123 * Encode TEST_STATEID request
3124 */
3125static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3126 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003127 const void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04003128{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003129 const struct nfs41_test_stateid_args *args = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04003130 struct compound_hdr hdr = {
3131 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3132 };
3133
3134 encode_compound_hdr(xdr, req, &hdr);
3135 encode_sequence(xdr, &args->seq_args, &hdr);
3136 encode_test_stateid(xdr, args, &hdr);
3137 encode_nops(&hdr);
3138}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003139
3140/*
3141 * Encode FREE_STATEID request
3142 */
3143static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3144 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003145 const void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003146{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003147 const struct nfs41_free_stateid_args *args = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003148 struct compound_hdr hdr = {
3149 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3150 };
3151
3152 encode_compound_hdr(xdr, req, &hdr);
3153 encode_sequence(xdr, &args->seq_args, &hdr);
3154 encode_free_stateid(xdr, args, &hdr);
3155 encode_nops(&hdr);
3156}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003157#endif /* CONFIG_NFS_V4_1 */
3158
Trond Myklebust683b57b2006-06-09 09:34:22 -04003159static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160{
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003161 ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3162 NFS4_OPAQUE_LIMIT);
Chuck Levereb72f482019-02-11 11:24:21 -05003163 if (unlikely(ret < 0))
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003164 return -EIO;
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003165 *len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 return 0;
3167}
3168
3169static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3170{
Trond Myklebust6659db42021-11-04 17:18:01 -04003171 ssize_t ret;
3172 void *ptr;
3173 u32 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174
Trond Myklebust6659db42021-11-04 17:18:01 -04003175 if (xdr_stream_decode_u32(xdr, &tmp) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05003176 return -EIO;
Trond Myklebust6659db42021-11-04 17:18:01 -04003177 hdr->status = tmp;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003178
Trond Myklebust6659db42021-11-04 17:18:01 -04003179 ret = xdr_stream_decode_opaque_inline(xdr, &ptr, NFS4_OPAQUE_LIMIT);
3180 if (ret < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05003181 return -EIO;
Trond Myklebust6659db42021-11-04 17:18:01 -04003182 hdr->taglen = ret;
3183 hdr->tag = ptr;
3184
3185 if (xdr_stream_decode_u32(xdr, &tmp) < 0)
3186 return -EIO;
3187 hdr->nops = tmp;
Benny Halevyaadf6152008-12-23 16:06:13 -05003188 if (unlikely(hdr->nops < 1))
3189 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 return 0;
3191}
3192
Trond Myklebustc7848f62013-12-04 17:39:23 -05003193static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3194 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195{
Al Viro8687b632006-10-19 23:28:48 -07003196 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 uint32_t opnum;
3198 int32_t nfserr;
3199
Benny Halevyc0eae662009-08-14 17:20:14 +03003200 p = xdr_inline_decode(xdr, 8);
3201 if (unlikely(!p))
3202 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003203 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003204 if (unlikely(opnum != expected))
3205 goto out_bad_operation;
Chuck Leverf23f6582019-02-11 11:24:26 -05003206 if (unlikely(*p != cpu_to_be32(NFS_OK)))
3207 goto out_status;
3208 *nfs_retval = 0;
3209 return true;
3210out_status:
Benny Halevycccddf42009-08-14 17:20:19 +03003211 nfserr = be32_to_cpup(p);
Chuck Lever62a92ba2019-06-19 10:34:09 -04003212 trace_nfs4_xdr_status(xdr, opnum, nfserr);
Chuck Leverf23f6582019-02-11 11:24:26 -05003213 *nfs_retval = nfs4_stat_to_errno(nfserr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003214 return true;
3215out_bad_operation:
Trond Myklebustda934ae2021-04-01 14:38:13 -04003216 trace_nfs4_xdr_bad_operation(xdr, opnum, expected);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003217 *nfs_retval = -EREMOTEIO;
3218 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003219out_overflow:
Trond Myklebustc7848f62013-12-04 17:39:23 -05003220 *nfs_retval = -EIO;
3221 return false;
3222}
3223
3224static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3225{
3226 int retval;
3227
3228 __decode_op_hdr(xdr, expected, &retval);
3229 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230}
3231
3232/* Dummy routine */
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05003233static int decode_ace(struct xdr_stream *xdr, void *ace)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234{
Al Viro8687b632006-10-19 23:28:48 -07003235 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003236 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 char *str;
3238
Benny Halevyc0eae662009-08-14 17:20:14 +03003239 p = xdr_inline_decode(xdr, 12);
Chuck Levereb72f482019-02-11 11:24:21 -05003240 if (unlikely(!p))
3241 return -EIO;
3242 return decode_opaque_inline(xdr, &strlen, &str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243}
3244
Trond Myklebust37c88762018-03-20 17:03:08 -04003245static ssize_t
3246decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247{
Trond Myklebust37c88762018-03-20 17:03:08 -04003248 ssize_t ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249
Trond Myklebust37c88762018-03-20 17:03:08 -04003250 ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
3251 if (likely(ret >= 0))
3252 return ret;
Chuck Levereb72f482019-02-11 11:24:21 -05003253 if (ret != -EMSGSIZE)
3254 return -EIO;
3255 return sz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256}
3257
Trond Myklebust37c88762018-03-20 17:03:08 -04003258static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3259{
3260 ssize_t ret;
3261 ret = decode_bitmap4(xdr, bitmap, 3);
3262 return ret < 0 ? ret : 0;
3263}
3264
Trond Myklebust256e48b2012-06-21 11:18:13 -04003265static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266{
Al Viro8687b632006-10-19 23:28:48 -07003267 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268
Benny Halevyc0eae662009-08-14 17:20:14 +03003269 p = xdr_inline_decode(xdr, 4);
3270 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003271 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003272 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003273 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 return 0;
3275}
3276
3277static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3278{
3279 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003280 int ret;
3281 ret = decode_attr_bitmap(xdr, bitmask);
3282 if (unlikely(ret < 0))
3283 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3285 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003286 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3287 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3288 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 return 0;
3290}
3291
3292static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3293{
Al Viro8687b632006-10-19 23:28:48 -07003294 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003295 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296
3297 *type = 0;
3298 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3299 return -EIO;
3300 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003301 p = xdr_inline_decode(xdr, 4);
3302 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003303 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003304 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003306 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 return -EIO;
3308 }
3309 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003310 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003312 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003313 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314}
3315
Chuck Lever264e6352012-03-01 17:02:05 -05003316static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3317 uint32_t *bitmap, uint32_t *type)
3318{
3319 __be32 *p;
3320
3321 *type = 0;
3322 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3323 return -EIO;
3324 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3325 p = xdr_inline_decode(xdr, 4);
3326 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003327 return -EIO;
Chuck Lever264e6352012-03-01 17:02:05 -05003328 *type = be32_to_cpup(p);
3329 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3330 }
3331 dprintk("%s: expire type=0x%x\n", __func__, *type);
3332 return 0;
Chuck Lever264e6352012-03-01 17:02:05 -05003333}
3334
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3336{
Al Viro8687b632006-10-19 23:28:48 -07003337 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003338 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339
3340 *change = 0;
3341 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3342 return -EIO;
3343 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003344 p = xdr_inline_decode(xdr, 8);
3345 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003346 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003347 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003349 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003351 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003353 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354}
3355
3356static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3357{
Al Viro8687b632006-10-19 23:28:48 -07003358 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003359 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360
3361 *size = 0;
3362 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3363 return -EIO;
3364 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003365 p = xdr_inline_decode(xdr, 8);
3366 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003367 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003368 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003370 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003372 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003373 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374}
3375
3376static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3377{
Al Viro8687b632006-10-19 23:28:48 -07003378 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379
3380 *res = 0;
3381 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3382 return -EIO;
3383 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003384 p = xdr_inline_decode(xdr, 4);
3385 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003386 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003387 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3389 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003390 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 return 0;
3392}
3393
3394static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3395{
Al Viro8687b632006-10-19 23:28:48 -07003396 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397
3398 *res = 0;
3399 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3400 return -EIO;
3401 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003402 p = xdr_inline_decode(xdr, 4);
3403 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003404 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003405 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3407 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003408 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 return 0;
3410}
3411
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003412static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413{
Al Viro8687b632006-10-19 23:28:48 -07003414 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003415 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416
3417 fsid->major = 0;
3418 fsid->minor = 0;
3419 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3420 return -EIO;
3421 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003422 p = xdr_inline_decode(xdr, 16);
3423 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003424 return -EIO;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003425 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003426 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003428 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003430 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 (unsigned long long)fsid->major,
3432 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003433 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434}
3435
3436static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3437{
Al Viro8687b632006-10-19 23:28:48 -07003438 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439
3440 *res = 60;
3441 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3442 return -EIO;
3443 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003444 p = xdr_inline_decode(xdr, 4);
3445 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003446 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003447 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3449 }
Donald Buczek2eaf4262019-07-07 21:26:07 +02003450 dprintk("%s: lease time=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 return 0;
3452}
3453
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003454static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003455{
3456 __be32 *p;
3457
3458 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3459 return -EIO;
3460 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3461 p = xdr_inline_decode(xdr, 4);
3462 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003463 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003464 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003465 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003466 }
3467 return 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003468}
3469
Kinglong Mee8c612822015-08-26 21:12:58 +08003470static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3471 uint32_t *bitmap, uint32_t *bitmask)
3472{
3473 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3474 int ret;
3475 ret = decode_attr_bitmap(xdr, bitmask);
3476 if (unlikely(ret < 0))
3477 return ret;
3478 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3479 } else
3480 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3481 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3482 bitmask[0], bitmask[1], bitmask[2]);
3483 return 0;
3484}
3485
Bryan Schumakerae42c702010-10-21 16:33:17 -04003486static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3487{
3488 __be32 *p;
Frank Sorenson86bbd742018-10-23 10:34:57 -05003489 u32 len;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003490
Trond Myklebust7ad07352010-10-23 15:34:20 -04003491 if (fh != NULL)
3492 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003493
3494 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3495 return -EIO;
3496 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3497 p = xdr_inline_decode(xdr, 4);
3498 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003499 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003500 len = be32_to_cpup(p);
Trond Myklebusteb3d58c2021-04-01 14:03:26 -04003501 if (len > NFS4_FHSIZE || len == 0) {
3502 trace_nfs4_xdr_bad_filehandle(xdr, OP_READDIR,
3503 NFS4ERR_BADHANDLE);
3504 return -EREMOTEIO;
3505 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003506 p = xdr_inline_decode(xdr, len);
3507 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003508 return -EIO;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003509 if (fh != NULL) {
3510 memcpy(fh->data, p, len);
3511 fh->size = len;
3512 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003513 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3514 }
3515 return 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003516}
3517
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3519{
Al Viro8687b632006-10-19 23:28:48 -07003520 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003522 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3524 return -EIO;
3525 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003526 p = xdr_inline_decode(xdr, 4);
3527 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003528 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003529 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3531 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003532 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 return 0;
3534}
3535
3536static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3537{
Al Viro8687b632006-10-19 23:28:48 -07003538 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003539 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540
3541 *fileid = 0;
3542 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3543 return -EIO;
3544 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003545 p = xdr_inline_decode(xdr, 8);
3546 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003547 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003548 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003550 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003552 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003553 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554}
3555
Manoj Naik99baf622006-06-09 09:34:24 -04003556static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3557{
Al Viro8687b632006-10-19 23:28:48 -07003558 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003559 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003560
3561 *fileid = 0;
3562 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3563 return -EIO;
3564 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003565 p = xdr_inline_decode(xdr, 8);
3566 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003567 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003568 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003569 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003570 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003571 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003572 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003573 return ret;
Manoj Naik99baf622006-06-09 09:34:24 -04003574}
3575
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3577{
Al Viro8687b632006-10-19 23:28:48 -07003578 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579 int status = 0;
3580
3581 *res = 0;
3582 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3583 return -EIO;
3584 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003585 p = xdr_inline_decode(xdr, 8);
3586 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003587 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003588 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3590 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003591 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592 return status;
3593}
3594
3595static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3596{
Al Viro8687b632006-10-19 23:28:48 -07003597 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598 int status = 0;
3599
3600 *res = 0;
3601 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3602 return -EIO;
3603 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003604 p = xdr_inline_decode(xdr, 8);
3605 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003606 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003607 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3609 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003610 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611 return status;
3612}
3613
3614static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3615{
Al Viro8687b632006-10-19 23:28:48 -07003616 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 int status = 0;
3618
3619 *res = 0;
3620 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3621 return -EIO;
3622 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003623 p = xdr_inline_decode(xdr, 8);
3624 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003625 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003626 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3628 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003629 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 return status;
3631}
3632
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003633static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3634{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003635 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003636 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003637 int status = 0;
3638
Benny Halevyc0eae662009-08-14 17:20:14 +03003639 p = xdr_inline_decode(xdr, 4);
3640 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003641 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003642 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003643 if (n == 0)
3644 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003645 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003646 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3647 dprintk("cannot parse %d components in path\n", n);
3648 goto out_eio;
3649 }
3650 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003651 struct nfs4_string *component = &path->components[path->ncomponents];
3652 status = decode_opaque_inline(xdr, &component->len, &component->data);
3653 if (unlikely(status != 0))
3654 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003655 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003656 pr_cont("%s%.*s ",
3657 (path->ncomponents != n ? "/ " : ""),
3658 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003659 }
3660out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003661 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003662root_path:
3663/* a root pathname is sent as a zero component4 */
3664 path->ncomponents = 1;
3665 path->components[0].len=0;
3666 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003667 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003668 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003669out_eio:
3670 dprintk(" status %d", status);
3671 status = -EIO;
3672 goto out;
3673}
3674
3675static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003676{
3677 int n;
Al Viro8687b632006-10-19 23:28:48 -07003678 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003679 int status = -EIO;
3680
3681 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3682 goto out;
3683 status = 0;
3684 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3685 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003686 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003687 status = -EIO;
3688 /* Ignore borken servers that return unrequested attrs */
3689 if (unlikely(res == NULL))
3690 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003691 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003692 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003693 if (unlikely(status != 0))
3694 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003695 p = xdr_inline_decode(xdr, 4);
3696 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003697 goto out_eio;
Benny Halevycccddf42009-08-14 17:20:19 +03003698 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003699 if (n <= 0)
3700 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003701 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003702 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003703 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003704
Trond Myklebust809b4262013-03-27 11:54:45 -04003705 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3706 break;
3707 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003708 p = xdr_inline_decode(xdr, 4);
3709 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003710 goto out_eio;
Benny Halevycccddf42009-08-14 17:20:19 +03003711 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003712
Chuck Lever02a29762012-03-01 17:00:31 -05003713 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003714 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3715 struct nfs4_string *server;
3716
3717 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003718 unsigned int i;
3719 dprintk("%s: using first %u of %u servers "
3720 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003721 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003722 NFS4_FS_LOCATION_MAXSERVERS,
3723 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003724 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003725 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003726 char *data;
3727 status = decode_opaque_inline(xdr, &len, &data);
3728 if (unlikely(status != 0))
3729 goto out_eio;
3730 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003731 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003732 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003733 server = &loc->servers[loc->nservers];
3734 status = decode_opaque_inline(xdr, &server->len, &server->data);
3735 if (unlikely(status != 0))
3736 goto out_eio;
3737 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003738 }
3739 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003740 if (unlikely(status != 0))
3741 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003742 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003743 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003744 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003745out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003746 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003747 return status;
3748out_eio:
3749 status = -EIO;
3750 goto out;
3751}
3752
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3754{
Al Viro8687b632006-10-19 23:28:48 -07003755 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 int status = 0;
3757
3758 *res = 0;
3759 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3760 return -EIO;
3761 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003762 p = xdr_inline_decode(xdr, 8);
3763 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003764 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003765 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3767 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003768 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769 return status;
3770}
3771
3772static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3773{
Al Viro8687b632006-10-19 23:28:48 -07003774 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 int status = 0;
3776
3777 *maxlink = 1;
3778 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3779 return -EIO;
3780 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003781 p = xdr_inline_decode(xdr, 4);
3782 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003783 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003784 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3786 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003787 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 return status;
3789}
3790
3791static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3792{
Al Viro8687b632006-10-19 23:28:48 -07003793 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794 int status = 0;
3795
3796 *maxname = 1024;
3797 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3798 return -EIO;
3799 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003800 p = xdr_inline_decode(xdr, 4);
3801 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003802 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003803 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3805 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003806 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 return status;
3808}
3809
3810static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3811{
Al Viro8687b632006-10-19 23:28:48 -07003812 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 int status = 0;
3814
3815 *res = 1024;
3816 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3817 return -EIO;
3818 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3819 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003820 p = xdr_inline_decode(xdr, 8);
3821 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003822 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003823 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 if (maxread > 0x7FFFFFFF)
3825 maxread = 0x7FFFFFFF;
3826 *res = (uint32_t)maxread;
3827 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3828 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003829 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 return status;
3831}
3832
3833static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3834{
Al Viro8687b632006-10-19 23:28:48 -07003835 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836 int status = 0;
3837
3838 *res = 1024;
3839 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3840 return -EIO;
3841 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3842 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003843 p = xdr_inline_decode(xdr, 8);
3844 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003845 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003846 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847 if (maxwrite > 0x7FFFFFFF)
3848 maxwrite = 0x7FFFFFFF;
3849 *res = (uint32_t)maxwrite;
3850 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3851 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003852 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 return status;
3854}
3855
Trond Myklebustbca79472009-03-11 14:10:26 -04003856static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857{
Trond Myklebustbca79472009-03-11 14:10:26 -04003858 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003859 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003860 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861
3862 *mode = 0;
3863 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3864 return -EIO;
3865 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003866 p = xdr_inline_decode(xdr, 4);
3867 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003868 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003869 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003870 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003872 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003874 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003875 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876}
3877
3878static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3879{
Al Viro8687b632006-10-19 23:28:48 -07003880 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003881 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882
3883 *nlink = 1;
3884 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3885 return -EIO;
3886 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003887 p = xdr_inline_decode(xdr, 4);
3888 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003889 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003890 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003892 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003894 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003895 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896}
3897
Trond Myklebust686a8162017-02-19 16:08:32 -05003898static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3899 struct nfs4_string *name, gfp_t gfp_flags)
3900{
3901 ssize_t ret;
3902
3903 ret = xdr_stream_decode_string_dup(xdr, &name->data,
3904 XDR_MAX_NETOBJ, gfp_flags);
3905 name->len = 0;
3906 if (ret > 0)
3907 name->len = ret;
3908 return ret;
3909}
3910
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003911static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003912 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003913 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914{
Trond Myklebust686a8162017-02-19 16:08:32 -05003915 ssize_t len;
3916 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917
Eric W. Biedermane5782072013-02-01 14:22:02 -08003918 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3920 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003921 if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3922 return 0;
3923 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3924
3925 if (owner_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04003926 len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05003927 if (len <= 0)
3928 goto out;
3929 dprintk("%s: name=%s\n", __func__, owner_name->data);
3930 return NFS_ATTR_FATTR_OWNER_NAME;
3931 } else {
3932 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3933 XDR_MAX_NETOBJ);
3934 if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3935 goto out;
3936 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3937 return NFS_ATTR_FATTR_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003939out:
Chuck Levereb72f482019-02-11 11:24:21 -05003940 if (len == -EBADMSG)
3941 return -EIO;
3942 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943}
3944
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003945static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003946 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003947 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948{
Trond Myklebust686a8162017-02-19 16:08:32 -05003949 ssize_t len;
3950 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951
Eric W. Biedermane5782072013-02-01 14:22:02 -08003952 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3954 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003955 if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
3956 return 0;
3957 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3958
3959 if (group_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04003960 len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05003961 if (len <= 0)
3962 goto out;
3963 dprintk("%s: name=%s\n", __func__, group_name->data);
Kinglong Mee6f1f6222017-03-06 17:49:42 +08003964 return NFS_ATTR_FATTR_GROUP_NAME;
Trond Myklebust686a8162017-02-19 16:08:32 -05003965 } else {
3966 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3967 XDR_MAX_NETOBJ);
3968 if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
3969 goto out;
3970 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3971 return NFS_ATTR_FATTR_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003973out:
Chuck Levereb72f482019-02-11 11:24:21 -05003974 if (len == -EBADMSG)
3975 return -EIO;
3976 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977}
3978
3979static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3980{
Al Viro8687b632006-10-19 23:28:48 -07003981 uint32_t major = 0, minor = 0;
3982 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003983 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984
3985 *rdev = MKDEV(0,0);
3986 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3987 return -EIO;
3988 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3989 dev_t tmp;
3990
Benny Halevyc0eae662009-08-14 17:20:14 +03003991 p = xdr_inline_decode(xdr, 8);
3992 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003993 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03003994 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003995 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 tmp = MKDEV(major, minor);
3997 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3998 *rdev = tmp;
3999 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04004000 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004002 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04004003 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004}
4005
4006static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4007{
Al Viro8687b632006-10-19 23:28:48 -07004008 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009 int status = 0;
4010
4011 *res = 0;
4012 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
4013 return -EIO;
4014 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004015 p = xdr_inline_decode(xdr, 8);
4016 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004017 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004018 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4020 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004021 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 return status;
4023}
4024
4025static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4026{
Al Viro8687b632006-10-19 23:28:48 -07004027 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028 int status = 0;
4029
4030 *res = 0;
4031 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4032 return -EIO;
4033 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004034 p = xdr_inline_decode(xdr, 8);
4035 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004036 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004037 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4039 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004040 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041 return status;
4042}
4043
4044static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4045{
Al Viro8687b632006-10-19 23:28:48 -07004046 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 int status = 0;
4048
4049 *res = 0;
4050 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4051 return -EIO;
4052 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004053 p = xdr_inline_decode(xdr, 8);
4054 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004055 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004056 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4058 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004059 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 return status;
4061}
4062
4063static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4064{
Al Viro8687b632006-10-19 23:28:48 -07004065 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004066 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067
4068 *used = 0;
4069 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4070 return -EIO;
4071 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004072 p = xdr_inline_decode(xdr, 8);
4073 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004074 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004075 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004077 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004079 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004081 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082}
4083
Trond Myklebust36b37432018-03-20 17:03:10 -04004084static __be32 *
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004085xdr_decode_nfstime4(__be32 *p, struct timespec64 *t)
Trond Myklebust36b37432018-03-20 17:03:10 -04004086{
4087 __u64 sec;
4088
4089 p = xdr_decode_hyper(p, &sec);
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004090 t-> tv_sec = sec;
Trond Myklebust36b37432018-03-20 17:03:10 -04004091 t->tv_nsec = be32_to_cpup(p++);
4092 return p;
4093}
4094
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004095static int decode_attr_time(struct xdr_stream *xdr, struct timespec64 *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096{
Al Viro8687b632006-10-19 23:28:48 -07004097 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098
Trond Myklebust36b37432018-03-20 17:03:10 -04004099 p = xdr_inline_decode(xdr, nfstime4_maxsz << 2);
Benny Halevyc0eae662009-08-14 17:20:14 +03004100 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004101 return -EIO;
Trond Myklebust36b37432018-03-20 17:03:10 -04004102 xdr_decode_nfstime4(p, time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 return 0;
4104}
4105
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004106static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107{
4108 int status = 0;
4109
4110 time->tv_sec = 0;
4111 time->tv_nsec = 0;
4112 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4113 return -EIO;
4114 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4115 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004116 if (status == 0)
4117 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4119 }
Arnd Bergmannae084832019-11-11 21:16:23 +01004120 dprintk("%s: atime=%lld\n", __func__, time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 return status;
4122}
4123
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004124static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125{
4126 int status = 0;
4127
4128 time->tv_sec = 0;
4129 time->tv_nsec = 0;
4130 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4131 return -EIO;
4132 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4133 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004134 if (status == 0)
4135 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4137 }
Arnd Bergmannae084832019-11-11 21:16:23 +01004138 dprintk("%s: ctime=%lld\n", __func__, time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139 return status;
4140}
4141
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004142static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004143 struct timespec64 *time)
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004144{
4145 int status = 0;
4146
4147 time->tv_sec = 0;
4148 time->tv_nsec = 0;
4149 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4150 return -EIO;
4151 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4152 status = decode_attr_time(xdr, time);
4153 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4154 }
Arnd Bergmannae084832019-11-11 21:16:23 +01004155 dprintk("%s: time_delta=%lld %ld\n", __func__, time->tv_sec,
4156 time->tv_nsec);
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004157 return status;
4158}
4159
David Quigleyaa9c2662013-05-22 12:50:44 -04004160static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4161 struct nfs4_label *label)
4162{
4163 uint32_t pi = 0;
4164 uint32_t lfs = 0;
4165 __u32 len;
4166 __be32 *p;
4167 int status = 0;
4168
4169 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4170 return -EIO;
4171 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4172 p = xdr_inline_decode(xdr, 4);
4173 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004174 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004175 lfs = be32_to_cpup(p++);
4176 p = xdr_inline_decode(xdr, 4);
4177 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004178 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004179 pi = be32_to_cpup(p++);
4180 p = xdr_inline_decode(xdr, 4);
4181 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004182 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004183 len = be32_to_cpup(p++);
4184 p = xdr_inline_decode(xdr, len);
4185 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004186 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004187 if (len < NFS4_MAXLABELLEN) {
4188 if (label) {
Jeffrey Mitchellb4487b92020-08-05 12:23:19 -05004189 if (label->len) {
4190 if (label->len < len)
4191 return -ERANGE;
4192 memcpy(label->label, p, len);
4193 }
David Quigleyaa9c2662013-05-22 12:50:44 -04004194 label->len = len;
4195 label->pi = pi;
4196 label->lfs = lfs;
4197 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4198 }
4199 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4200 } else
4201 printk(KERN_WARNING "%s: label too long (%u)!\n",
4202 __func__, len);
4203 }
4204 if (label && label->label)
4205 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4206 (char *)label->label, label->len, label->pi, label->lfs);
4207 return status;
David Quigleyaa9c2662013-05-22 12:50:44 -04004208}
4209
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004210static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211{
4212 int status = 0;
4213
4214 time->tv_sec = 0;
4215 time->tv_nsec = 0;
4216 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4217 return -EIO;
4218 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4219 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004220 if (status == 0)
4221 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4223 }
Arnd Bergmannae084832019-11-11 21:16:23 +01004224 dprintk("%s: mtime=%lld\n", __func__, time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225 return status;
4226}
4227
Frank van der Lindenb78ef842020-06-23 22:38:55 +00004228static int decode_attr_xattrsupport(struct xdr_stream *xdr, uint32_t *bitmap,
4229 uint32_t *res)
4230{
4231 __be32 *p;
4232
4233 *res = 0;
4234 if (unlikely(bitmap[2] & (FATTR4_WORD2_XATTR_SUPPORT - 1U)))
4235 return -EIO;
4236 if (likely(bitmap[2] & FATTR4_WORD2_XATTR_SUPPORT)) {
4237 p = xdr_inline_decode(xdr, 4);
4238 if (unlikely(!p))
4239 return -EIO;
4240 *res = be32_to_cpup(p);
4241 bitmap[2] &= ~FATTR4_WORD2_XATTR_SUPPORT;
4242 }
4243 dprintk("%s: XATTR support=%s\n", __func__,
4244 *res == 0 ? "false" : "true");
4245 return 0;
4246}
4247
Trond Myklebust256e48b2012-06-21 11:18:13 -04004248static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249{
4250 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004251 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252
4253 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004254 dprintk("%s: server returned incorrect attribute length: "
4255 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004256 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 attrwords << 2,
4258 (attrwords < nwords) ? '<' : '>',
4259 nwords << 2);
4260 return -EIO;
4261 }
4262 return 0;
4263}
4264
4265static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4266{
Al Viro8687b632006-10-19 23:28:48 -07004267 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268
Benny Halevyc0eae662009-08-14 17:20:14 +03004269 p = xdr_inline_decode(xdr, 20);
4270 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004271 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03004272 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004273 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004274 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275 return 0;
4276}
4277
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004278static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279{
Al Viro8687b632006-10-19 23:28:48 -07004280 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281 uint32_t supp, acc;
4282 int status;
4283
4284 status = decode_op_hdr(xdr, OP_ACCESS);
4285 if (status)
4286 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004287 p = xdr_inline_decode(xdr, 8);
4288 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004289 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03004290 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004291 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004292 *supported = supp;
4293 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294 return 0;
4295}
4296
Benny Halevy07d30432009-08-14 17:19:52 +03004297static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004299 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
Chuck Levereb72f482019-02-11 11:24:21 -05004300 if (unlikely(ret < 0))
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004301 return -EIO;
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004302 return 0;
Benny Halevy07d30432009-08-14 17:19:52 +03004303}
4304
4305static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4306{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004307 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308}
4309
Trond Myklebust93b717f2016-05-16 17:42:43 -04004310static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4311{
4312 stateid->type = NFS4_OPEN_STATEID_TYPE;
4313 return decode_stateid(xdr, stateid);
4314}
4315
4316static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4317{
4318 stateid->type = NFS4_LOCK_STATEID_TYPE;
4319 return decode_stateid(xdr, stateid);
4320}
4321
4322static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4323{
4324 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4325 return decode_stateid(xdr, stateid);
4326}
4327
Trond Myklebustfcd88432017-11-07 12:39:44 -05004328static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4329{
4330 nfs4_stateid dummy;
4331
4332 nfs4_stateid_copy(stateid, &invalid_stateid);
4333 return decode_stateid(xdr, &dummy);
4334}
4335
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4337{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338 int status;
4339
4340 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004341 if (status != -EIO)
4342 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004343 if (!status)
Trond Myklebustfcd88432017-11-07 12:39:44 -05004344 status = decode_invalid_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004345 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346}
4347
Benny Halevydb942bb2009-08-14 17:19:56 +03004348static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4349{
Chuck Levercd937102012-03-02 17:14:31 -05004350 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351}
4352
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004353static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4354{
4355 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4356}
4357
Fred Isaman0b7c0152012-04-20 14:47:39 -04004358static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359{
Trond Myklebust221203c2020-01-06 15:25:04 -05004360 struct nfs_writeverf *verf = res->verf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361 int status;
4362
4363 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004364 if (!status)
Trond Myklebust221203c2020-01-06 15:25:04 -05004365 status = decode_write_verifier(xdr, &verf->verifier);
4366 if (!status)
4367 verf->committed = NFS_FILE_SYNC;
Benny Halevydb942bb2009-08-14 17:19:56 +03004368 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004369}
4370
4371static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4372{
Al Viro8687b632006-10-19 23:28:48 -07004373 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374 uint32_t bmlen;
4375 int status;
4376
4377 status = decode_op_hdr(xdr, OP_CREATE);
4378 if (status)
4379 return status;
4380 if ((status = decode_change_info(xdr, cinfo)))
4381 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004382 p = xdr_inline_decode(xdr, 4);
4383 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004384 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004385 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004386 p = xdr_inline_decode(xdr, bmlen << 2);
4387 if (likely(p))
4388 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004389 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390}
4391
4392static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4393{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004394 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004395 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396 int status;
4397
4398 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4399 goto xdr_error;
4400 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4401 goto xdr_error;
4402 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4403 goto xdr_error;
4404 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4405 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004406 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4407 &res->fh_expire_type)) != 0)
4408 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4410 goto xdr_error;
4411 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4412 goto xdr_error;
4413 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4414 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004415 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4416 res->exclcreat_bitmask)) != 0)
4417 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004418 status = verify_attr_len(xdr, savep, attrlen);
4419xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004420 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 return status;
4422}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004423
Linus Torvalds1da177e2005-04-16 15:20:36 -07004424static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4425{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004426 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004427 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004429
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4431 goto xdr_error;
4432 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4433 goto xdr_error;
4434 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4435 goto xdr_error;
4436
4437 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4438 goto xdr_error;
4439 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4440 goto xdr_error;
4441 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4442 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004443
4444 status = -EIO;
4445 if (unlikely(bitmap[0]))
4446 goto xdr_error;
4447
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4449 goto xdr_error;
4450 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4451 goto xdr_error;
4452 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4453 goto xdr_error;
4454
4455 status = verify_attr_len(xdr, savep, attrlen);
4456xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004457 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458 return status;
4459}
4460
4461static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4462{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004463 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004464 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004466
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4468 goto xdr_error;
4469 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4470 goto xdr_error;
4471 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4472 goto xdr_error;
4473
4474 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4475 goto xdr_error;
4476 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4477 goto xdr_error;
4478
4479 status = verify_attr_len(xdr, savep, attrlen);
4480xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004481 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482 return status;
4483}
4484
Andy Adamson88034c32012-05-23 05:02:34 -04004485static int decode_threshold_hint(struct xdr_stream *xdr,
4486 uint32_t *bitmap,
4487 uint64_t *res,
4488 uint32_t hint_bit)
4489{
4490 __be32 *p;
4491
4492 *res = 0;
4493 if (likely(bitmap[0] & hint_bit)) {
4494 p = xdr_inline_decode(xdr, 8);
4495 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004496 return -EIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004497 xdr_decode_hyper(p, res);
4498 }
4499 return 0;
Andy Adamson88034c32012-05-23 05:02:34 -04004500}
4501
4502static int decode_first_threshold_item4(struct xdr_stream *xdr,
4503 struct nfs4_threshold *res)
4504{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004505 __be32 *p;
4506 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004507 uint32_t bitmap[3] = {0,}, attrlen;
4508 int status;
4509
4510 /* layout type */
4511 p = xdr_inline_decode(xdr, 4);
Chuck Levereb72f482019-02-11 11:24:21 -05004512 if (unlikely(!p))
Andy Adamson88034c32012-05-23 05:02:34 -04004513 return -EIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004514 res->l_type = be32_to_cpup(p);
4515
4516 /* thi_hintset bitmap */
4517 status = decode_attr_bitmap(xdr, bitmap);
4518 if (status < 0)
4519 goto xdr_error;
4520
4521 /* thi_hintlist length */
4522 status = decode_attr_length(xdr, &attrlen, &savep);
4523 if (status < 0)
4524 goto xdr_error;
4525 /* thi_hintlist */
4526 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4527 if (status < 0)
4528 goto xdr_error;
4529 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4530 if (status < 0)
4531 goto xdr_error;
4532 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4533 THRESHOLD_RD_IO);
4534 if (status < 0)
4535 goto xdr_error;
4536 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4537 THRESHOLD_WR_IO);
4538 if (status < 0)
4539 goto xdr_error;
4540
4541 status = verify_attr_len(xdr, savep, attrlen);
4542 res->bm = bitmap[0];
4543
4544 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4545 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4546 res->wr_io_sz);
4547xdr_error:
4548 dprintk("%s ret=%d!\n", __func__, status);
4549 return status;
4550}
4551
4552/*
4553 * Thresholds on pNFS direct I/O vrs MDS I/O
4554 */
4555static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4556 uint32_t *bitmap,
4557 struct nfs4_threshold *res)
4558{
4559 __be32 *p;
4560 int status = 0;
4561 uint32_t num;
4562
4563 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4564 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004565 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004566 /* Did the server return an unrequested attribute? */
4567 if (unlikely(res == NULL))
4568 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004569 p = xdr_inline_decode(xdr, 4);
4570 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004571 return -EIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004572 num = be32_to_cpup(p);
4573 if (num == 0)
4574 return 0;
4575 if (num > 1)
4576 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4577 "drivers per filesystem not supported\n",
4578 __func__);
4579
4580 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004581 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004582 }
4583 return status;
Andy Adamson88034c32012-05-23 05:02:34 -04004584}
4585
Bryan Schumakerae42c702010-10-21 16:33:17 -04004586static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4587 struct nfs_fattr *fattr, struct nfs_fh *fh,
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04004588 struct nfs4_fs_locations *fs_loc, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004589{
Trond Myklebustbca79472009-03-11 14:10:26 -04004590 int status;
4591 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004592 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004593 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004594
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004595 status = decode_attr_type(xdr, bitmap, &type);
4596 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004597 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004598 fattr->mode = 0;
4599 if (status != 0) {
4600 fattr->mode |= nfs_type2fmt[type];
4601 fattr->valid |= status;
4602 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004604 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4605 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004607 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004608
4609 status = decode_attr_size(xdr, bitmap, &fattr->size);
4610 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004612 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004613
4614 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4615 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004617 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004618
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004619 err = 0;
4620 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004621 if (status < 0)
4622 goto xdr_error;
4623
4624 status = decode_attr_filehandle(xdr, bitmap, fh);
4625 if (status < 0)
4626 goto xdr_error;
4627
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004628 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4629 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004631 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004632
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004633 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004634 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004635 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004636 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004637
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004638 status = -EIO;
4639 if (unlikely(bitmap[0]))
4640 goto xdr_error;
4641
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004642 status = decode_attr_mode(xdr, bitmap, &fmode);
4643 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004645 if (status != 0) {
4646 fattr->mode |= fmode;
4647 fattr->valid |= status;
4648 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004649
4650 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4651 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004653 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004654
Trond Myklebust6926afd12012-01-07 13:22:46 -05004655 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004656 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004658 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004659
Trond Myklebust6926afd12012-01-07 13:22:46 -05004660 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004661 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004663 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004664
4665 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4666 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004667 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004668 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004669
4670 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4671 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004672 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004673 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004674
4675 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4676 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004677 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004678 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004679
4680 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4681 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004683 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004684
4685 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4686 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004687 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004688 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004689
Trond Myklebust28331a42011-04-27 13:47:52 -04004690 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004691 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004692 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004693 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004694
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004695 status = -EIO;
4696 if (unlikely(bitmap[1]))
4697 goto xdr_error;
4698
Andy Adamson88034c32012-05-23 05:02:34 -04004699 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4700 if (status < 0)
4701 goto xdr_error;
4702
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04004703 if (fattr->label) {
4704 status = decode_attr_security_label(xdr, bitmap, fattr->label);
David Quigleyaa9c2662013-05-22 12:50:44 -04004705 if (status < 0)
4706 goto xdr_error;
4707 fattr->valid |= status;
4708 }
4709
Bryan Schumakerae42c702010-10-21 16:33:17 -04004710xdr_error:
4711 dprintk("%s: xdr returned %d\n", __func__, -status);
4712 return status;
4713}
4714
4715static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004716 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04004717 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004718{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004719 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004720 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004721 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004722 int status;
4723
4724 status = decode_op_hdr(xdr, OP_GETATTR);
4725 if (status < 0)
4726 goto xdr_error;
4727
4728 status = decode_attr_bitmap(xdr, bitmap);
4729 if (status < 0)
4730 goto xdr_error;
4731
4732 status = decode_attr_length(xdr, &attrlen, &savep);
4733 if (status < 0)
4734 goto xdr_error;
4735
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04004736 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004737 if (status < 0)
4738 goto xdr_error;
4739
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004740 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004742 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004743 return status;
4744}
4745
Bryan Schumakerae42c702010-10-21 16:33:17 -04004746static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004747 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004748{
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04004749 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004750}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751
Andy Adamson504913f2010-10-20 00:17:57 -04004752/*
Jeff Layton3132e492016-08-10 15:58:24 -04004753 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004754 */
Jeff Layton3132e492016-08-10 15:58:24 -04004755static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004756 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004757{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004758 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004759 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004760
4761 p = xdr_inline_decode(xdr, 4);
4762 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004763 return -EIO;
Jeff Laytonca440c32016-09-15 14:40:49 -04004764 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004765
4766 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004767 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004768 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004769
4770 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004771 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004772 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004773 return -EIO;
Jeff Laytonca440c32016-09-15 14:40:49 -04004774
4775 /* If we get too many, then just cap it at the max */
4776 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4777 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4778 __func__, fsinfo->nlayouttypes);
4779 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4780 }
4781
4782 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4783 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004784 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004785}
4786
4787/*
4788 * The type of file system exported.
4789 * Note we must ensure that layouttype is set in any non-error case.
4790 */
4791static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004792 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004793{
4794 int status = 0;
4795
4796 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4797 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4798 return -EIO;
4799 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004800 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004801 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004802 }
Andy Adamson504913f2010-10-20 00:17:57 -04004803 return status;
4804}
4805
Fred Isamandae100c2011-07-30 20:52:37 -04004806/*
4807 * The prefered block size for layout directed io
4808 */
4809static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4810 uint32_t *res)
4811{
4812 __be32 *p;
4813
4814 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4815 *res = 0;
4816 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4817 p = xdr_inline_decode(xdr, 4);
Chuck Levereb72f482019-02-11 11:24:21 -05004818 if (unlikely(!p))
Fred Isamandae100c2011-07-30 20:52:37 -04004819 return -EIO;
Fred Isamandae100c2011-07-30 20:52:37 -04004820 *res = be32_to_cpup(p);
4821 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4822 }
4823 return 0;
4824}
4825
Peng Tao2a92ee92015-09-26 02:24:37 +08004826/*
4827 * The granularity of a CLONE operation.
4828 */
4829static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4830 uint32_t *res)
4831{
4832 __be32 *p;
4833
4834 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4835 *res = 0;
4836 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4837 p = xdr_inline_decode(xdr, 4);
Chuck Levereb72f482019-02-11 11:24:21 -05004838 if (unlikely(!p))
Peng Tao2a92ee92015-09-26 02:24:37 +08004839 return -EIO;
Peng Tao2a92ee92015-09-26 02:24:37 +08004840 *res = be32_to_cpup(p);
4841 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4842 }
4843 return 0;
4844}
4845
Trond Myklebust7f08a332021-03-26 09:50:19 -04004846static int decode_attr_change_attr_type(struct xdr_stream *xdr,
4847 uint32_t *bitmap,
4848 enum nfs4_change_attr_type *res)
4849{
4850 u32 tmp = NFS4_CHANGE_TYPE_IS_UNDEFINED;
4851
4852 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4853 if (bitmap[2] & FATTR4_WORD2_CHANGE_ATTR_TYPE) {
4854 if (xdr_stream_decode_u32(xdr, &tmp))
4855 return -EIO;
4856 bitmap[2] &= ~FATTR4_WORD2_CHANGE_ATTR_TYPE;
4857 }
4858
4859 switch(tmp) {
4860 case NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR:
4861 case NFS4_CHANGE_TYPE_IS_VERSION_COUNTER:
4862 case NFS4_CHANGE_TYPE_IS_VERSION_COUNTER_NOPNFS:
4863 case NFS4_CHANGE_TYPE_IS_TIME_METADATA:
4864 *res = tmp;
4865 break;
4866 default:
4867 *res = NFS4_CHANGE_TYPE_IS_UNDEFINED;
4868 }
4869 return 0;
4870}
4871
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4873{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004874 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004875 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876 int status;
4877
4878 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4879 goto xdr_error;
4880 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4881 goto xdr_error;
4882 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4883 goto xdr_error;
4884
4885 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4886
4887 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4888 goto xdr_error;
4889 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4890 goto xdr_error;
4891 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4892 goto xdr_error;
4893 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4894 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4895 goto xdr_error;
4896 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004897
4898 status = -EIO;
4899 if (unlikely(bitmap[0]))
4900 goto xdr_error;
4901
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004902 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4903 if (status != 0)
4904 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004905 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004906 if (status != 0)
4907 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004908
4909 status = -EIO;
4910 if (unlikely(bitmap[1]))
4911 goto xdr_error;
4912
Fred Isamandae100c2011-07-30 20:52:37 -04004913 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4914 if (status)
4915 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004916 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4917 if (status)
4918 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919
Trond Myklebust7f08a332021-03-26 09:50:19 -04004920 status = decode_attr_change_attr_type(xdr, bitmap,
4921 &fsinfo->change_attr_type);
4922 if (status)
4923 goto xdr_error;
4924
Frank van der Lindenb78ef842020-06-23 22:38:55 +00004925 status = decode_attr_xattrsupport(xdr, bitmap,
4926 &fsinfo->xattr_support);
4927 if (status)
4928 goto xdr_error;
4929
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930 status = verify_attr_len(xdr, savep, attrlen);
4931xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004932 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004933 return status;
4934}
4935
4936static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4937{
Al Viro8687b632006-10-19 23:28:48 -07004938 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004939 uint32_t len;
4940 int status;
4941
Trond Myklebust99367812007-07-17 21:52:41 -04004942 /* Zero handle first to allow comparisons */
4943 memset(fh, 0, sizeof(*fh));
4944
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945 status = decode_op_hdr(xdr, OP_GETFH);
4946 if (status)
4947 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948
Benny Halevyc0eae662009-08-14 17:20:14 +03004949 p = xdr_inline_decode(xdr, 4);
4950 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004951 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004952 len = be32_to_cpup(p);
Trond Myklebusteb3d58c2021-04-01 14:03:26 -04004953 if (len > NFS4_FHSIZE || len == 0) {
4954 trace_nfs4_xdr_bad_filehandle(xdr, OP_GETFH, NFS4ERR_BADHANDLE);
4955 return -EREMOTEIO;
4956 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004958 p = xdr_inline_decode(xdr, len);
4959 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004960 return -EIO;
Benny Halevy99398d02009-08-14 17:20:05 +03004961 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962 return 0;
4963}
4964
4965static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4966{
4967 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004968
Linus Torvalds1da177e2005-04-16 15:20:36 -07004969 status = decode_op_hdr(xdr, OP_LINK);
4970 if (status)
4971 return status;
4972 return decode_change_info(xdr, cinfo);
4973}
4974
4975/*
4976 * We create the owner, so we know a proper owner.id length is 4.
4977 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004978static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004980 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004981 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004982 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004983
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004984 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004985 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004986 return -EIO;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004987 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004988 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004989 type = be32_to_cpup(p++); /* 4 byte read */
4990 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004991 fl->fl_start = (loff_t)offset;
4992 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4993 if (length == ~(uint64_t)0)
4994 fl->fl_end = OFFSET_MAX;
4995 fl->fl_type = F_WRLCK;
4996 if (type & 1)
4997 fl->fl_type = F_RDLCK;
4998 fl->fl_pid = 0;
4999 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005000 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
5001 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
5002 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Chuck Levereb72f482019-02-11 11:24:21 -05005003 if (likely(!p))
5004 return -EIO;
5005 return -NFS4ERR_DENIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006}
5007
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005008static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010 int status;
5011
5012 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005013 if (status == -EIO)
5014 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04005016 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005017 if (unlikely(status))
5018 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04005020 status = decode_lock_denied(xdr, NULL);
5021 if (res->open_seqid != NULL)
5022 nfs_increment_open_seqid(status, res->open_seqid);
5023 nfs_increment_lock_seqid(status, res->lock_seqid);
5024out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 return status;
5026}
5027
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005028static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029{
5030 int status;
5031 status = decode_op_hdr(xdr, OP_LOCKT);
5032 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005033 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034 return status;
5035}
5036
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005037static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005039 int status;
5040
5041 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005042 if (status != -EIO)
5043 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005044 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005045 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046 return status;
5047}
5048
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005049static int decode_release_lockowner(struct xdr_stream *xdr)
5050{
5051 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5052}
5053
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054static int decode_lookup(struct xdr_stream *xdr)
5055{
5056 return decode_op_hdr(xdr, OP_LOOKUP);
5057}
5058
Jeff Layton5b5faaf2017-06-29 06:34:52 -07005059static int decode_lookupp(struct xdr_stream *xdr)
5060{
5061 return decode_op_hdr(xdr, OP_LOOKUPP);
5062}
5063
Linus Torvalds1da177e2005-04-16 15:20:36 -07005064/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005065static int decode_space_limit(struct xdr_stream *xdr,
5066 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005067{
Andy Adamson05d564f2008-12-23 16:06:15 -05005068 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005070 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071
Benny Halevyc0eae662009-08-14 17:20:14 +03005072 p = xdr_inline_decode(xdr, 12);
5073 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005074 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005075 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005076 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005077 case NFS4_LIMIT_SIZE:
5078 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005079 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005080 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005081 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005082 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005083 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005085 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005086 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087 return 0;
5088}
5089
Trond Myklebust6ae37332015-01-30 14:21:14 -05005090static int decode_rw_delegation(struct xdr_stream *xdr,
5091 uint32_t delegation_type,
5092 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093{
Andy Adamson05d564f2008-12-23 16:06:15 -05005094 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005095 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005096
Trond Myklebust93b717f2016-05-16 17:42:43 -04005097 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005098 if (unlikely(status))
5099 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005100 p = xdr_inline_decode(xdr, 4);
5101 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005102 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005103 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005104
Linus Torvalds1da177e2005-04-16 15:20:36 -07005105 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005106 case NFS4_OPEN_DELEGATE_READ:
5107 res->delegation_type = FMODE_READ;
5108 break;
5109 case NFS4_OPEN_DELEGATE_WRITE:
5110 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005111 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112 return -EIO;
5113 }
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05005114 return decode_ace(xdr, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115}
5116
Trond Myklebust6ae37332015-01-30 14:21:14 -05005117static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5118{
5119 __be32 *p;
5120 uint32_t why_no_delegation;
5121
5122 p = xdr_inline_decode(xdr, 4);
5123 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005124 return -EIO;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005125 why_no_delegation = be32_to_cpup(p);
5126 switch (why_no_delegation) {
5127 case WND4_CONTENTION:
5128 case WND4_RESOURCE:
5129 xdr_inline_decode(xdr, 4);
5130 /* Ignore for now */
5131 }
5132 return 0;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005133}
5134
5135static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5136{
5137 __be32 *p;
5138 uint32_t delegation_type;
5139
5140 p = xdr_inline_decode(xdr, 4);
5141 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005142 return -EIO;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005143 delegation_type = be32_to_cpup(p);
5144 res->delegation_type = 0;
5145 switch (delegation_type) {
5146 case NFS4_OPEN_DELEGATE_NONE:
5147 return 0;
5148 case NFS4_OPEN_DELEGATE_READ:
5149 case NFS4_OPEN_DELEGATE_WRITE:
5150 return decode_rw_delegation(xdr, delegation_type, res);
5151 case NFS4_OPEN_DELEGATE_NONE_EXT:
5152 return decode_no_delegation(xdr, res);
5153 }
5154 return -EIO;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005155}
5156
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5158{
Andy Adamson05d564f2008-12-23 16:06:15 -05005159 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005160 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005161 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162
Trond Myklebustc7848f62013-12-04 17:39:23 -05005163 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5164 return status;
5165 nfs_increment_open_seqid(status, res->seqid);
5166 if (status)
5167 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005168 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005169 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005170 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005171
Andy Adamson05d564f2008-12-23 16:06:15 -05005172 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173
Benny Halevyc0eae662009-08-14 17:20:14 +03005174 p = xdr_inline_decode(xdr, 8);
5175 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005176 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005177 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005178 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005179 if (bmlen > 10)
5180 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181
Benny Halevyc0eae662009-08-14 17:20:14 +03005182 p = xdr_inline_decode(xdr, bmlen << 2);
5183 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005184 return -EIO;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005185 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5186 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005187 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005188 for (; i < NFS4_BITMAP_SIZE; i++)
5189 res->attrset[i] = 0;
5190
Linus Torvalds1da177e2005-04-16 15:20:36 -07005191 return decode_delegation(xdr, res);
5192xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005193 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194 return -EIO;
5195}
5196
5197static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5198{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005199 int status;
5200
Andy Adamson05d564f2008-12-23 16:06:15 -05005201 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005202 if (status != -EIO)
5203 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005204 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005205 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005206 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207}
5208
5209static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5210{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005211 int status;
5212
5213 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005214 if (status != -EIO)
5215 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005216 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005217 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005218 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005219}
5220
5221static int decode_putfh(struct xdr_stream *xdr)
5222{
5223 return decode_op_hdr(xdr, OP_PUTFH);
5224}
5225
5226static int decode_putrootfh(struct xdr_stream *xdr)
5227{
5228 return decode_op_hdr(xdr, OP_PUTROOTFH);
5229}
5230
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005231static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5232 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005233{
Al Viro8687b632006-10-19 23:28:48 -07005234 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005235 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005236 int status;
5237
5238 status = decode_op_hdr(xdr, OP_READ);
5239 if (status)
5240 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005241 p = xdr_inline_decode(xdr, 8);
5242 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005243 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005244 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005245 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005246 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005247 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005248 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249 "count %u > recvd %u\n", count, recvd);
5250 count = recvd;
5251 eof = 0;
5252 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005253 res->eof = eof;
5254 res->count = count;
5255 return 0;
5256}
5257
5258static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5259{
Chuck Leverbcecff72007-10-26 13:32:03 -04005260 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005261 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262
5263 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005264 if (!status)
5265 status = decode_verifier(xdr, readdir->verifier.data);
5266 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005267 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005268 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005269 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005270 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005271 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005272}
5273
5274static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5275{
5276 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005277 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005278 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005279 int status;
5280
5281 status = decode_op_hdr(xdr, OP_READLINK);
5282 if (status)
5283 return status;
5284
5285 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005286 p = xdr_inline_decode(xdr, 4);
5287 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005288 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005289 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005291 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005292 return -ENAMETOOLONG;
5293 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005294 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005295 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005296 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005297 "count %u > recvd %u\n", len, recvd);
5298 return -EIO;
5299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005300 /*
5301 * The XDR encode routine has set things up so that
5302 * the link text will be copied directly into the
5303 * buffer. We just have to do overflow-checking,
Randy Dunlapa5032912020-08-10 19:18:35 -07005304 * and null-terminate the text (the VFS expects
Linus Torvalds1da177e2005-04-16 15:20:36 -07005305 * null-termination).
5306 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005307 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005308 return 0;
5309}
5310
5311static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5312{
5313 int status;
5314
5315 status = decode_op_hdr(xdr, OP_REMOVE);
5316 if (status)
5317 goto out;
5318 status = decode_change_info(xdr, cinfo);
5319out:
5320 return status;
5321}
5322
5323static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5324 struct nfs4_change_info *new_cinfo)
5325{
5326 int status;
5327
5328 status = decode_op_hdr(xdr, OP_RENAME);
5329 if (status)
5330 goto out;
5331 if ((status = decode_change_info(xdr, old_cinfo)))
5332 goto out;
5333 status = decode_change_info(xdr, new_cinfo);
5334out:
5335 return status;
5336}
5337
5338static int decode_renew(struct xdr_stream *xdr)
5339{
5340 return decode_op_hdr(xdr, OP_RENEW);
5341}
5342
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005343static int
5344decode_restorefh(struct xdr_stream *xdr)
5345{
5346 return decode_op_hdr(xdr, OP_RESTOREFH);
5347}
5348
J. Bruce Fields029d1052005-06-22 17:16:22 +00005349static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005350 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005351{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005352 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005353 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005354 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005355 int status;
5356
Andy Adamsonbf118a32011-12-07 11:55:27 -05005357 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005358 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5359 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005360
Trond Myklebust519d3952012-08-14 17:30:10 -04005361 xdr_enter_page(xdr, xdr->buf->page_len);
5362
J. Bruce Fields029d1052005-06-22 17:16:22 +00005363 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5364 goto out;
5365 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5366 goto out;
5367
5368 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5369 return -EIO;
5370 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005371
Andy Adamsonbf118a32011-12-07 11:55:27 -05005372 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5373 * are stored with the acl data to handle the problem of
5374 * variable length bitmaps.*/
Anna Schumakera14a6352020-04-17 11:01:50 -04005375 res->acl_data_offset = xdr_page_pos(xdr);
Trond Myklebust519d3952012-08-14 17:30:10 -04005376 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005377
5378 /* Check for receive buffer overflow */
Trond Myklebust17068462020-11-21 21:41:08 -05005379 if (res->acl_len > xdr_stream_remaining(xdr) ||
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005380 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5381 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust17068462020-11-21 21:41:08 -05005382 dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
5383 attrlen, xdr_stream_remaining(xdr));
J. Bruce Fields029d1052005-06-22 17:16:22 +00005384 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005385 } else
5386 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005387
5388out:
5389 return status;
5390}
5391
Linus Torvalds1da177e2005-04-16 15:20:36 -07005392static int
5393decode_savefh(struct xdr_stream *xdr)
5394{
5395 return decode_op_hdr(xdr, OP_SAVEFH);
5396}
5397
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005398static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005399{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005400 int status;
5401
Linus Torvalds1da177e2005-04-16 15:20:36 -07005402 status = decode_op_hdr(xdr, OP_SETATTR);
5403 if (status)
5404 return status;
Trond Myklebust37c88762018-03-20 17:03:08 -04005405 if (decode_bitmap4(xdr, NULL, 0) >= 0)
Benny Halevyc0eae662009-08-14 17:20:14 +03005406 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005407 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408}
5409
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005410static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005411{
Al Viro8687b632006-10-19 23:28:48 -07005412 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005413 uint32_t opnum;
5414 int32_t nfserr;
5415
Benny Halevyc0eae662009-08-14 17:20:14 +03005416 p = xdr_inline_decode(xdr, 8);
5417 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005418 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005419 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005420 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005421 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005422 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005423 return -EIO;
5424 }
Benny Halevycccddf42009-08-14 17:20:19 +03005425 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005426 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005427 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5428 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005429 return -EIO;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005430 p = xdr_decode_hyper(p, &res->clientid);
5431 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005432 } else if (nfserr == NFSERR_CLID_INUSE) {
5433 uint32_t len;
5434
5435 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005436 p = xdr_inline_decode(xdr, 4);
5437 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005438 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005439 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005440 p = xdr_inline_decode(xdr, len);
5441 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005442 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005443
5444 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005445 p = xdr_inline_decode(xdr, 4);
5446 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005447 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005448 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005449 p = xdr_inline_decode(xdr, len);
5450 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005451 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005452 return -NFSERR_CLID_INUSE;
5453 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005454 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005455
5456 return 0;
5457}
5458
5459static int decode_setclientid_confirm(struct xdr_stream *xdr)
5460{
5461 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5462}
5463
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005464static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005465{
Al Viro8687b632006-10-19 23:28:48 -07005466 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005467 int status;
5468
5469 status = decode_op_hdr(xdr, OP_WRITE);
5470 if (status)
5471 return status;
5472
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005473 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005474 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005475 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005476 res->count = be32_to_cpup(p++);
5477 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005478 return decode_write_verifier(xdr, &res->verf->verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005479}
5480
5481static int decode_delegreturn(struct xdr_stream *xdr)
5482{
5483 return decode_op_hdr(xdr, OP_DELEGRETURN);
5484}
5485
Chuck Leverfb15b262013-03-16 15:54:34 -04005486static int decode_secinfo_gss(struct xdr_stream *xdr,
5487 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005488{
Chuck Leverfb15b262013-03-16 15:54:34 -04005489 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005490 __be32 *p;
5491
5492 p = xdr_inline_decode(xdr, 4);
5493 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005494 return -EIO;
Chuck Leverfb15b262013-03-16 15:54:34 -04005495 oid_len = be32_to_cpup(p);
5496 if (oid_len > GSS_OID_MAX_LEN)
Chuck Levereb72f482019-02-11 11:24:21 -05005497 return -EINVAL;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005498
Chuck Leverfb15b262013-03-16 15:54:34 -04005499 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005500 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005501 return -EIO;
Chuck Leverfb15b262013-03-16 15:54:34 -04005502 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5503 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005504
5505 p = xdr_inline_decode(xdr, 8);
5506 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005507 return -EIO;
Chuck Leverfb15b262013-03-16 15:54:34 -04005508 flavor->flavor_info.qop = be32_to_cpup(p++);
5509 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005510
5511 return 0;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005512}
5513
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005514static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005515{
Chuck Leverfb15b262013-03-16 15:54:34 -04005516 struct nfs4_secinfo4 *sec_flavor;
5517 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005518 int status;
5519 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005520
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005521 p = xdr_inline_decode(xdr, 4);
5522 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005523 return -EIO;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005524
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005525 res->flavors->num_flavors = 0;
5526 num_flavors = be32_to_cpup(p);
5527
5528 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005529 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005530 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005531 break;
5532
5533 p = xdr_inline_decode(xdr, 4);
5534 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005535 return -EIO;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005536 sec_flavor->flavor = be32_to_cpup(p);
5537
5538 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005539 status = decode_secinfo_gss(xdr, sec_flavor);
5540 if (status)
5541 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005542 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005543 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005544 }
5545
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005546 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005547out:
5548 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005549}
5550
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005551static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5552{
5553 int status = decode_op_hdr(xdr, OP_SECINFO);
5554 if (status)
5555 return status;
5556 return decode_secinfo_common(xdr, res);
5557}
5558
Benny Halevy99fe60d2009-04-01 09:22:29 -04005559#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005560static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5561{
5562 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5563 if (status)
5564 return status;
5565 return decode_secinfo_common(xdr, res);
5566}
5567
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005568static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5569{
Trond Myklebustf1147592021-11-04 17:33:36 -04005570 if (xdr_stream_decode_uint32_array(xdr, op_map->u.words,
5571 ARRAY_SIZE(op_map->u.words)) < 0)
Pan Bian4edabfd2017-04-23 14:49:41 +08005572 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005573 return 0;
5574}
5575
Benny Halevy99fe60d2009-04-01 09:22:29 -04005576static int decode_exchange_id(struct xdr_stream *xdr,
5577 struct nfs41_exchange_id_res *res)
5578{
5579 __be32 *p;
5580 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005581 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005582 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005583 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005584
5585 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5586 if (status)
5587 return status;
5588
Benny Halevyc0eae662009-08-14 17:20:14 +03005589 p = xdr_inline_decode(xdr, 8);
5590 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005591 return -EIO;
Trond Myklebust32b01312012-05-26 13:41:04 -04005592 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005593 p = xdr_inline_decode(xdr, 12);
5594 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005595 return -EIO;
Trond Myklebust32b01312012-05-26 13:41:04 -04005596 res->seqid = be32_to_cpup(p++);
5597 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005598
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005599 res->state_protect.how = be32_to_cpup(p);
5600 switch (res->state_protect.how) {
5601 case SP4_NONE:
5602 break;
5603 case SP4_MACH_CRED:
5604 status = decode_op_map(xdr, &res->state_protect.enforce);
5605 if (status)
5606 return status;
5607 status = decode_op_map(xdr, &res->state_protect.allow);
5608 if (status)
5609 return status;
5610 break;
5611 default:
5612 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005613 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005614 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005615
Chuck Leveracdeb692012-05-21 22:46:16 -04005616 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005617 p = xdr_inline_decode(xdr, 8);
5618 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005619 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005620 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005621
Chuck Leveracdeb692012-05-21 22:46:16 -04005622 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005623 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5624 if (unlikely(status))
5625 return status;
Chuck Leveracdeb692012-05-21 22:46:16 -04005626 memcpy(res->server_owner->major_id, dummy_str, dummy);
5627 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005628
Chuck Leveracdeb692012-05-21 22:46:16 -04005629 /* server_scope4 */
5630 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5631 if (unlikely(status))
5632 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005633 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5634 res->server_scope->server_scope_sz = dummy;
5635
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005636 /* Implementation Id */
5637 p = xdr_inline_decode(xdr, 4);
5638 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005639 return -EIO;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005640 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005641
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005642 if (impl_id_count) {
5643 /* nii_domain */
5644 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5645 if (unlikely(status))
5646 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005647 memcpy(res->impl_id->domain, dummy_str, dummy);
5648
5649 /* nii_name */
5650 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5651 if (unlikely(status))
5652 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005653 memcpy(res->impl_id->name, dummy_str, dummy);
5654
5655 /* nii_date */
5656 p = xdr_inline_decode(xdr, 12);
5657 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005658 return -EIO;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005659 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5660 res->impl_id->date.nseconds = be32_to_cpup(p);
5661
5662 /* if there's more than one entry, ignore the rest */
5663 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005664 return 0;
5665}
Andy Adamsonfc931582009-04-01 09:22:31 -04005666
5667static int decode_chan_attrs(struct xdr_stream *xdr,
5668 struct nfs4_channel_attrs *attrs)
5669{
5670 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005671 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005672
Benny Halevyc0eae662009-08-14 17:20:14 +03005673 p = xdr_inline_decode(xdr, 28);
5674 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005675 return -EIO;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005676 val = be32_to_cpup(p++); /* headerpadsz */
5677 if (val)
5678 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005679 attrs->max_rqst_sz = be32_to_cpup(p++);
5680 attrs->max_resp_sz = be32_to_cpup(p++);
5681 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5682 attrs->max_ops = be32_to_cpup(p++);
5683 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005684 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005685 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005686 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5687 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005688 return -EINVAL;
5689 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005690 if (nr_attrs == 1) {
5691 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5692 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005693 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005694 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005695 return 0;
5696}
5697
Benny Halevye78291e2009-08-14 17:20:00 +03005698static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5699{
5700 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005701}
5702
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005703static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5704 struct nfs41_bind_conn_to_session_res *res)
5705{
5706 __be32 *p;
5707 int status;
5708
5709 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5710 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005711 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005712 if (unlikely(status))
5713 return status;
5714
5715 /* dir flags, rdma mode bool */
5716 p = xdr_inline_decode(xdr, 8);
5717 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005718 return -EIO;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005719
5720 res->dir = be32_to_cpup(p++);
5721 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5722 return -EIO;
5723 if (be32_to_cpup(p) == 0)
5724 res->use_conn_in_rdma_mode = false;
5725 else
5726 res->use_conn_in_rdma_mode = true;
5727
5728 return 0;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005729}
5730
Andy Adamsonfc931582009-04-01 09:22:31 -04005731static int decode_create_session(struct xdr_stream *xdr,
5732 struct nfs41_create_session_res *res)
5733{
5734 __be32 *p;
5735 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005736
5737 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005738 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005739 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005740 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005741 return status;
5742
Andy Adamsonfc931582009-04-01 09:22:31 -04005743 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005744 p = xdr_inline_decode(xdr, 8);
5745 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005746 return -EIO;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005747 res->seqid = be32_to_cpup(p++);
5748 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005749
5750 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005751 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005752 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005753 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005754 return status;
5755}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005756
5757static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5758{
5759 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5760}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005761
Trond Myklebust66245532012-05-25 17:18:09 -04005762static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5763{
5764 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5765}
5766
Ricardo Labiaga180197532009-12-05 16:08:40 -05005767static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5768{
5769 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5770}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005771#endif /* CONFIG_NFS_V4_1 */
5772
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005773static int decode_sequence(struct xdr_stream *xdr,
5774 struct nfs4_sequence_res *res,
5775 struct rpc_rqst *rqstp)
5776{
5777#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005778 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005779 struct nfs4_sessionid id;
5780 u32 dummy;
5781 int status;
5782 __be32 *p;
5783
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005784 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005785 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005786 if (!res->sr_slot->table->session)
5787 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005788
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005789 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005790 if (!status)
5791 status = decode_sessionid(xdr, &id);
5792 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005793 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005794
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005795 /*
5796 * If the server returns different values for sessionID, slotID or
5797 * sequence number, the server is looney tunes.
5798 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005799 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005800 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005801
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005802 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005803 NFS4_MAX_SESSIONID_LEN)) {
5804 dprintk("%s Invalid session id\n", __func__);
5805 goto out_err;
5806 }
Benny Halevye78291e2009-08-14 17:20:00 +03005807
Benny Halevyc0eae662009-08-14 17:20:14 +03005808 p = xdr_inline_decode(xdr, 20);
5809 if (unlikely(!p))
5810 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005811
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005812 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005813 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005814 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005815 dprintk("%s Invalid sequence number\n", __func__);
5816 goto out_err;
5817 }
5818 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005819 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005820 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005821 dprintk("%s Invalid slot id\n", __func__);
5822 goto out_err;
5823 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005824 /* highest slot id */
5825 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005826 /* target highest slot id */
5827 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005828 /* result flags */
5829 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005830 status = 0;
5831out_err:
5832 res->sr_status = status;
5833 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005834out_overflow:
Benny Halevyc0eae662009-08-14 17:20:14 +03005835 status = -EIO;
5836 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005837#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005838 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005839#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005840}
5841
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005842#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005843static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5844{
5845 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5846 return decode_stateid(xdr, stateid);
5847}
5848
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005849static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005850 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005851{
Trond Myklebust4e590802015-03-09 14:01:25 -04005852 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005853 __be32 *p;
5854 uint32_t len, type;
5855 int status;
5856
5857 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5858 if (status) {
5859 if (status == -ETOOSMALL) {
5860 p = xdr_inline_decode(xdr, 4);
5861 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005862 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005863 pdev->mincount = be32_to_cpup(p);
5864 dprintk("%s: Min count too small. mincnt = %u\n",
5865 __func__, pdev->mincount);
5866 }
5867 return status;
5868 }
5869
5870 p = xdr_inline_decode(xdr, 8);
5871 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005872 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005873 type = be32_to_cpup(p++);
5874 if (type != pdev->layout_type) {
5875 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5876 __func__, pdev->layout_type, type);
5877 return -EINVAL;
5878 }
5879 /*
5880 * Get the length of the opaque device_addr4. xdr_read_pages places
5881 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5882 * and places the remaining xdr data in xdr_buf->tail
5883 */
5884 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005885 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
Chuck Levereb72f482019-02-11 11:24:21 -05005886 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005887
5888 /* Parse notification bitmap, verifying that it is zero. */
5889 p = xdr_inline_decode(xdr, 4);
5890 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005891 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005892 len = be32_to_cpup(p);
5893 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005894 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005895
5896 p = xdr_inline_decode(xdr, 4 * len);
5897 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005898 return -EIO;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005899
Trond Myklebust4e590802015-03-09 14:01:25 -04005900 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005901 for (i = 1; i < len; i++) {
5902 if (be32_to_cpup(p++)) {
5903 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005904 __func__);
5905 return -EIO;
5906 }
5907 }
5908 }
5909 return 0;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005910}
5911
5912static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5913 struct nfs4_layoutget_res *res)
5914{
5915 __be32 *p;
5916 int status;
5917 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005918 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005919
5920 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5921 if (status)
Fred Isaman808ba322016-10-04 15:02:21 -04005922 goto out;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005923 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005924 if (unlikely(!p))
5925 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005926 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04005927 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005928 p = xdr_inline_decode(xdr, 4);
5929 if (unlikely(!p))
5930 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005931 layout_count = be32_to_cpup(p);
5932 if (!layout_count) {
5933 dprintk("%s: server responded with empty layout array\n",
5934 __func__);
Fred Isaman808ba322016-10-04 15:02:21 -04005935 status = -EINVAL;
5936 goto out;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005937 }
5938
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005939 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005940 if (unlikely(!p))
5941 goto out_overflow;
5942 p = xdr_decode_hyper(p, &res->range.offset);
5943 p = xdr_decode_hyper(p, &res->range.length);
5944 res->range.iomode = be32_to_cpup(p++);
5945 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005946 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005947
5948 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5949 __func__,
5950 (unsigned long)res->range.offset,
5951 (unsigned long)res->range.length,
5952 res->range.iomode,
5953 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005954 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005955
Trond Myklebust64bd5772012-06-20 22:35:05 -04005956 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005957 if (res->layoutp->len > recvd) {
5958 dprintk("NFS: server cheating in layoutget reply: "
5959 "layout len %u > recvd %u\n",
5960 res->layoutp->len, recvd);
Fred Isaman808ba322016-10-04 15:02:21 -04005961 status = -EINVAL;
5962 goto out;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005963 }
5964
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005965 if (layout_count > 1) {
5966 /* We only handle a length one array at the moment. Any
5967 * further entries are just ignored. Note that this means
5968 * the client may see a response that is less than the
5969 * minimum it requested.
5970 */
5971 dprintk("%s: server responded with %d layouts, dropping tail\n",
5972 __func__, layout_count);
5973 }
5974
Fred Isaman808ba322016-10-04 15:02:21 -04005975out:
5976 res->status = status;
5977 return status;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005978out_overflow:
Fred Isaman808ba322016-10-04 15:02:21 -04005979 status = -EIO;
5980 goto out;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005981}
Andy Adamson863a3c62011-03-23 13:27:54 +00005982
Benny Halevycbe82602011-05-22 19:52:37 +03005983static int decode_layoutreturn(struct xdr_stream *xdr,
5984 struct nfs4_layoutreturn_res *res)
5985{
5986 __be32 *p;
5987 int status;
5988
5989 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5990 if (status)
5991 return status;
5992 p = xdr_inline_decode(xdr, 4);
5993 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005994 return -EIO;
Benny Halevycbe82602011-05-22 19:52:37 +03005995 res->lrs_present = be32_to_cpup(p);
5996 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005997 status = decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustfcd88432017-11-07 12:39:44 -05005998 else
5999 nfs4_stateid_copy(&res->stateid, &invalid_stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03006000 return status;
Benny Halevycbe82602011-05-22 19:52:37 +03006001}
6002
Andy Adamson863a3c62011-03-23 13:27:54 +00006003static int decode_layoutcommit(struct xdr_stream *xdr,
6004 struct rpc_rqst *req,
6005 struct nfs4_layoutcommit_res *res)
6006{
6007 __be32 *p;
6008 __u32 sizechanged;
6009 int status;
6010
6011 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04006012 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00006013 if (status)
6014 return status;
6015
6016 p = xdr_inline_decode(xdr, 4);
6017 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05006018 return -EIO;
Andy Adamson863a3c62011-03-23 13:27:54 +00006019 sizechanged = be32_to_cpup(p);
6020
6021 if (sizechanged) {
6022 /* throw away new size */
6023 p = xdr_inline_decode(xdr, 8);
6024 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05006025 return -EIO;
Andy Adamson863a3c62011-03-23 13:27:54 +00006026 }
6027 return 0;
Andy Adamson863a3c62011-03-23 13:27:54 +00006028}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006029
6030static int decode_test_stateid(struct xdr_stream *xdr,
6031 struct nfs41_test_stateid_res *res)
6032{
6033 __be32 *p;
6034 int status;
6035 int num_res;
6036
6037 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6038 if (status)
6039 return status;
6040
6041 p = xdr_inline_decode(xdr, 4);
6042 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05006043 return -EIO;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006044 num_res = be32_to_cpup(p++);
6045 if (num_res != 1)
Chuck Levereb72f482019-02-11 11:24:21 -05006046 return -EIO;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006047
6048 p = xdr_inline_decode(xdr, 4);
6049 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05006050 return -EIO;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006051 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006052
6053 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006054}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006055
6056static int decode_free_stateid(struct xdr_stream *xdr,
6057 struct nfs41_free_stateid_res *res)
6058{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006059 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006060 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006061}
Trond Myklebustcf805162016-11-15 14:56:07 -05006062#else
6063static inline
6064int decode_layoutreturn(struct xdr_stream *xdr,
6065 struct nfs4_layoutreturn_res *res)
6066{
6067 return 0;
6068}
Fred Isaman56f487f2016-09-21 11:43:41 -04006069
6070static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6071 struct nfs4_layoutget_res *res)
6072{
6073 return 0;
6074}
6075
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006076#endif /* CONFIG_NFS_V4_1 */
6077
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078/*
Benny Halevy49c25592008-12-23 16:06:16 -05006079 * END OF "GENERIC" DECODE ROUTINES.
6080 */
6081
6082/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083 * Decode OPEN_DOWNGRADE response
6084 */
Chuck Leverbf269552010-12-14 14:59:29 +00006085static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6086 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006087 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006088{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006089 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006090 struct compound_hdr hdr;
6091 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092
Chuck Leverbf269552010-12-14 14:59:29 +00006093 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006094 if (status)
6095 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006096 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006097 if (status)
6098 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006099 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006100 if (status)
6101 goto out;
Trond Myklebustb6808142016-11-20 13:34:16 -05006102 if (res->lr_res) {
6103 status = decode_layoutreturn(xdr, res->lr_res);
6104 res->lr_ret = status;
6105 if (status)
6106 goto out;
6107 }
Chuck Leverbf269552010-12-14 14:59:29 +00006108 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006110 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006111}
6112
6113/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114 * Decode ACCESS response
6115 */
Chuck Leverbf269552010-12-14 14:59:29 +00006116static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006117 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006119 struct nfs4_accessres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006120 struct compound_hdr hdr;
6121 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006122
Chuck Leverbf269552010-12-14 14:59:29 +00006123 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006124 if (status)
6125 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006126 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006127 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006128 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006129 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006130 if (status != 0)
6131 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006132 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006133 if (status != 0)
6134 goto out;
Trond Myklebust8bcbe7d2018-03-20 17:03:11 -04006135 if (res->fattr)
6136 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137out:
6138 return status;
6139}
6140
6141/*
6142 * Decode LOOKUP response
6143 */
Chuck Leverbf269552010-12-14 14:59:29 +00006144static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006145 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006147 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006148 struct compound_hdr hdr;
6149 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006150
Chuck Leverbf269552010-12-14 14:59:29 +00006151 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006152 if (status)
6153 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006154 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006155 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006156 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006157 status = decode_putfh(xdr);
6158 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006159 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006160 status = decode_lookup(xdr);
6161 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006162 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006163 status = decode_getfh(xdr, res->fh);
6164 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006165 goto out;
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04006166 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006167out:
6168 return status;
6169}
6170
6171/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07006172 * Decode LOOKUPP response
6173 */
6174static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6175 void *data)
6176{
6177 struct nfs4_lookupp_res *res = data;
6178 struct compound_hdr hdr;
6179 int status;
6180
6181 status = decode_compound_hdr(xdr, &hdr);
6182 if (status)
6183 goto out;
6184 status = decode_sequence(xdr, &res->seq_res, rqstp);
6185 if (status)
6186 goto out;
6187 status = decode_putfh(xdr);
6188 if (status)
6189 goto out;
6190 status = decode_lookupp(xdr);
6191 if (status)
6192 goto out;
6193 status = decode_getfh(xdr, res->fh);
6194 if (status)
6195 goto out;
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04006196 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton5b5faaf2017-06-29 06:34:52 -07006197out:
6198 return status;
6199}
6200
6201/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202 * Decode LOOKUP_ROOT response
6203 */
Chuck Leverbf269552010-12-14 14:59:29 +00006204static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6205 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006206 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006208 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209 struct compound_hdr hdr;
6210 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006211
Chuck Leverbf269552010-12-14 14:59:29 +00006212 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006213 if (status)
6214 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006215 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006216 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006217 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006218 status = decode_putrootfh(xdr);
6219 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006220 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006221 status = decode_getfh(xdr, res->fh);
6222 if (status == 0)
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04006223 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006224out:
6225 return status;
6226}
6227
6228/*
6229 * Decode REMOVE response
6230 */
Chuck Leverbf269552010-12-14 14:59:29 +00006231static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006232 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006234 struct nfs_removeres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235 struct compound_hdr hdr;
6236 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006237
Chuck Leverbf269552010-12-14 14:59:29 +00006238 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006239 if (status)
6240 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006241 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006242 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006244 status = decode_putfh(xdr);
6245 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006246 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006247 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248out:
6249 return status;
6250}
6251
6252/*
6253 * Decode RENAME response
6254 */
Chuck Leverbf269552010-12-14 14:59:29 +00006255static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006256 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006257{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006258 struct nfs_renameres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006259 struct compound_hdr hdr;
6260 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006261
Chuck Leverbf269552010-12-14 14:59:29 +00006262 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006263 if (status)
6264 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006265 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006266 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006267 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006268 status = decode_putfh(xdr);
6269 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006271 status = decode_savefh(xdr);
6272 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006274 status = decode_putfh(xdr);
6275 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006277 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006278out:
6279 return status;
6280}
6281
6282/*
6283 * Decode LINK response
6284 */
Chuck Leverbf269552010-12-14 14:59:29 +00006285static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006286 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006287{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006288 struct nfs4_link_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006289 struct compound_hdr hdr;
6290 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006291
Chuck Leverbf269552010-12-14 14:59:29 +00006292 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006293 if (status)
6294 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006295 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006296 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006297 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006298 status = decode_putfh(xdr);
6299 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006300 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006301 status = decode_savefh(xdr);
6302 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006303 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006304 status = decode_putfh(xdr);
6305 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006307 status = decode_link(xdr, &res->cinfo);
6308 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006309 goto out;
6310 /*
6311 * Note order: OP_LINK leaves the directory as the current
6312 * filehandle.
6313 */
Chuck Leverbf269552010-12-14 14:59:29 +00006314 status = decode_restorefh(xdr);
6315 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006316 goto out;
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04006317 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006318out:
6319 return status;
6320}
6321
6322/*
6323 * Decode CREATE response
6324 */
Chuck Leverbf269552010-12-14 14:59:29 +00006325static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006326 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006327{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006328 struct nfs4_create_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006329 struct compound_hdr hdr;
6330 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006331
Chuck Leverbf269552010-12-14 14:59:29 +00006332 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006333 if (status)
6334 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006335 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006336 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006337 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006338 status = decode_putfh(xdr);
6339 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006340 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006341 status = decode_create(xdr, &res->dir_cinfo);
6342 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006343 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006344 status = decode_getfh(xdr, res->fh);
6345 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006346 goto out;
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04006347 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348out:
6349 return status;
6350}
6351
6352/*
6353 * Decode SYMLINK response
6354 */
Chuck Leverbf269552010-12-14 14:59:29 +00006355static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006356 void *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357{
Chuck Leverbf269552010-12-14 14:59:29 +00006358 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359}
6360
6361/*
6362 * Decode GETATTR response
6363 */
Chuck Leverbf269552010-12-14 14:59:29 +00006364static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006365 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006366{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006367 struct nfs4_getattr_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368 struct compound_hdr hdr;
6369 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006370
Chuck Leverbf269552010-12-14 14:59:29 +00006371 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372 if (status)
6373 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006374 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006375 if (status)
6376 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006377 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378 if (status)
6379 goto out;
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04006380 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381out:
6382 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006383}
6384
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006385/*
6386 * Encode an SETACL request
6387 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006388static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006389 const void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006390{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006391 const struct nfs_setaclargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006392 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006393 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006394 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006395
Chuck Lever9f06c712010-12-14 14:59:18 +00006396 encode_compound_hdr(xdr, req, &hdr);
6397 encode_sequence(xdr, &args->seq_args, &hdr);
6398 encode_putfh(xdr, args->fh, &hdr);
6399 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006400 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006401}
Andy Adamson05d564f2008-12-23 16:06:15 -05006402
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006403/*
6404 * Decode SETACL response
6405 */
6406static int
Chuck Leverbf269552010-12-14 14:59:29 +00006407nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006408 void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006409{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006410 struct nfs_setaclres *res = data;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006411 struct compound_hdr hdr;
6412 int status;
6413
Chuck Leverbf269552010-12-14 14:59:29 +00006414 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006415 if (status)
6416 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006417 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006418 if (status)
6419 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006420 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006421 if (status)
6422 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006423 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006424out:
6425 return status;
6426}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427
6428/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006429 * Decode GETACL response
6430 */
6431static int
Chuck Leverbf269552010-12-14 14:59:29 +00006432nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006433 void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006434{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006435 struct nfs_getaclres *res = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00006436 struct compound_hdr hdr;
6437 int status;
6438
Chuck Lever0ae4c3e2020-11-11 15:52:47 -05006439 if (res->acl_scratch != NULL)
6440 xdr_set_scratch_page(xdr, res->acl_scratch);
Chuck Leverbf269552010-12-14 14:59:29 +00006441 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006442 if (status)
6443 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006444 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006445 if (status)
6446 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006447 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006448 if (status)
6449 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006450 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006451
6452out:
6453 return status;
6454}
6455
6456/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006457 * Decode CLOSE response
6458 */
Chuck Leverbf269552010-12-14 14:59:29 +00006459static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006460 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006462 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006463 struct compound_hdr hdr;
6464 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465
Chuck Leverbf269552010-12-14 14:59:29 +00006466 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006467 if (status)
6468 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006469 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006470 if (status)
6471 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006472 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006473 if (status)
6474 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006475 if (res->lr_res) {
6476 status = decode_layoutreturn(xdr, res->lr_res);
6477 res->lr_ret = status;
6478 if (status)
6479 goto out;
6480 }
Trond Myklebustd8d84982016-12-19 12:14:44 -05006481 if (res->fattr != NULL) {
6482 status = decode_getfattr(xdr, res->fattr, res->server);
6483 if (status != 0)
6484 goto out;
6485 }
Chuck Leverbf269552010-12-14 14:59:29 +00006486 status = decode_close(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006487out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006488 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006489}
6490
6491/*
6492 * Decode OPEN response
6493 */
Chuck Leverbf269552010-12-14 14:59:29 +00006494static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006495 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006496{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006497 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006498 struct compound_hdr hdr;
6499 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006500
Chuck Leverbf269552010-12-14 14:59:29 +00006501 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006502 if (status)
6503 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006504 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006505 if (status)
6506 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006507 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006508 if (status)
6509 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006510 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006511 if (status)
6512 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006513 status = decode_getfh(xdr, &res->fh);
6514 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006515 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006516 if (res->access_request)
6517 decode_access(xdr, &res->access_supported, &res->access_result);
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04006518 decode_getfattr(xdr, res->f_attr, res->server);
Fred Isaman56f487f2016-09-21 11:43:41 -04006519 if (res->lg_res)
6520 decode_layoutget(xdr, rqstp, res->lg_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006521out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006522 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006523}
6524
6525/*
6526 * Decode OPEN_CONFIRM response
6527 */
Chuck Leverbf269552010-12-14 14:59:29 +00006528static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6529 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006530 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006531{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006532 struct nfs_open_confirmres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006533 struct compound_hdr hdr;
6534 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535
Chuck Leverbf269552010-12-14 14:59:29 +00006536 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006537 if (status)
6538 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006539 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006540 if (status)
6541 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006542 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006544 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545}
6546
6547/*
6548 * Decode OPEN response
6549 */
Chuck Leverbf269552010-12-14 14:59:29 +00006550static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6551 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006552 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006553{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006554 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006555 struct compound_hdr hdr;
6556 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006557
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006559 if (status)
6560 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006561 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006562 if (status)
6563 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006564 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006565 if (status)
6566 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006567 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006568 if (status)
6569 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006570 if (res->access_request)
6571 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd12012-01-07 13:22:46 -05006572 decode_getfattr(xdr, res->f_attr, res->server);
Fred Isaman56f487f2016-09-21 11:43:41 -04006573 if (res->lg_res)
6574 decode_layoutget(xdr, rqstp, res->lg_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006575out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006576 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006577}
6578
6579/*
6580 * Decode SETATTR response
6581 */
Chuck Leverbf269552010-12-14 14:59:29 +00006582static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6583 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006584 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006585{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006586 struct nfs_setattrres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006587 struct compound_hdr hdr;
6588 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006589
Chuck Leverbf269552010-12-14 14:59:29 +00006590 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006591 if (status)
6592 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006593 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006594 if (status)
6595 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006596 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006597 if (status)
6598 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006599 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006600 if (status)
6601 goto out;
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04006602 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006603out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006604 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006605}
6606
6607/*
6608 * Decode LOCK response
6609 */
Chuck Leverbf269552010-12-14 14:59:29 +00006610static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006611 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006612{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006613 struct nfs_lock_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006614 struct compound_hdr hdr;
6615 int status;
6616
Chuck Leverbf269552010-12-14 14:59:29 +00006617 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006618 if (status)
6619 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006620 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006621 if (status)
6622 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006623 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006624 if (status)
6625 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006626 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006627out:
6628 return status;
6629}
6630
6631/*
6632 * Decode LOCKT response
6633 */
Chuck Leverbf269552010-12-14 14:59:29 +00006634static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006635 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006637 struct nfs_lockt_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638 struct compound_hdr hdr;
6639 int status;
6640
Chuck Leverbf269552010-12-14 14:59:29 +00006641 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006642 if (status)
6643 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006644 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006645 if (status)
6646 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006647 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006648 if (status)
6649 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006650 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006651out:
6652 return status;
6653}
6654
6655/*
6656 * Decode LOCKU response
6657 */
Chuck Leverbf269552010-12-14 14:59:29 +00006658static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006659 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006660{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006661 struct nfs_locku_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006662 struct compound_hdr hdr;
6663 int status;
6664
Chuck Leverbf269552010-12-14 14:59:29 +00006665 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666 if (status)
6667 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006668 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006669 if (status)
6670 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006671 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672 if (status)
6673 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006674 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006675out:
6676 return status;
6677}
6678
Chuck Leverbf269552010-12-14 14:59:29 +00006679static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6680 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006681{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006682 struct compound_hdr hdr;
6683 int status;
6684
Chuck Leverbf269552010-12-14 14:59:29 +00006685 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006686 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006687 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006688 return status;
6689}
6690
Linus Torvalds1da177e2005-04-16 15:20:36 -07006691/*
6692 * Decode READLINK response
6693 */
Chuck Leverbf269552010-12-14 14:59:29 +00006694static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6695 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006696 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006697{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006698 struct nfs4_readlink_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699 struct compound_hdr hdr;
6700 int status;
6701
Chuck Leverbf269552010-12-14 14:59:29 +00006702 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006703 if (status)
6704 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006705 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006706 if (status)
6707 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006708 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006709 if (status)
6710 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006711 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712out:
6713 return status;
6714}
6715
6716/*
6717 * Decode READDIR response
6718 */
Chuck Leverbf269552010-12-14 14:59:29 +00006719static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006720 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006721{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006722 struct nfs4_readdir_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006723 struct compound_hdr hdr;
6724 int status;
6725
Chuck Leverbf269552010-12-14 14:59:29 +00006726 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006727 if (status)
6728 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006729 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006730 if (status)
6731 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006732 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006733 if (status)
6734 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006735 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736out:
6737 return status;
6738}
6739
6740/*
6741 * Decode Read response
6742 */
Chuck Leverbf269552010-12-14 14:59:29 +00006743static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006744 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006745{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006746 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006747 struct compound_hdr hdr;
6748 int status;
6749
Chuck Leverbf269552010-12-14 14:59:29 +00006750 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006751 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006752 if (status)
6753 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006754 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006755 if (status)
6756 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006757 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006758 if (status)
6759 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006760 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006761 if (!status)
6762 status = res->count;
6763out:
6764 return status;
6765}
6766
6767/*
6768 * Decode WRITE response
6769 */
Chuck Leverbf269552010-12-14 14:59:29 +00006770static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006771 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006772{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006773 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006774 struct compound_hdr hdr;
6775 int status;
6776
Chuck Leverbf269552010-12-14 14:59:29 +00006777 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006778 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006779 if (status)
6780 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006781 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006782 if (status)
6783 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006784 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006785 if (status)
6786 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006787 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006788 if (status)
6789 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006790 if (res->fattr)
Trond Myklebust6926afd12012-01-07 13:22:46 -05006791 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006792 if (!status)
6793 status = res->count;
6794out:
6795 return status;
6796}
6797
6798/*
6799 * Decode COMMIT response
6800 */
Chuck Leverbf269552010-12-14 14:59:29 +00006801static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, 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 nfs_commitres *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);
Peng Taoaabff4d2014-08-27 10:47:14 +08006809 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006810 if (status)
6811 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006812 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006813 if (status)
6814 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006815 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006816 if (status)
6817 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006818 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006819out:
6820 return status;
6821}
6822
6823/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006824 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006825 */
Chuck Leverbf269552010-12-14 14:59:29 +00006826static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006827 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006828{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006829 struct nfs4_fsinfo_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006830 struct compound_hdr hdr;
6831 int status;
6832
Chuck Leverbf269552010-12-14 14:59:29 +00006833 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006834 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006835 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006836 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006837 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006838 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006839 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006840 return status;
6841}
6842
6843/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006844 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006845 */
Chuck Leverbf269552010-12-14 14:59:29 +00006846static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006847 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006848{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006849 struct nfs4_pathconf_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006850 struct compound_hdr hdr;
6851 int status;
6852
Chuck Leverbf269552010-12-14 14:59:29 +00006853 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006854 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006855 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006856 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006857 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006858 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006859 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006860 return status;
6861}
6862
6863/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006864 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006865 */
Chuck Leverbf269552010-12-14 14:59:29 +00006866static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006867 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006868{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006869 struct nfs4_statfs_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006870 struct compound_hdr hdr;
6871 int status;
6872
Chuck Leverbf269552010-12-14 14:59:29 +00006873 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006874 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006875 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006876 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006877 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006878 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006879 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006880 return status;
6881}
6882
6883/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006884 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006885 */
Chuck Leverbf269552010-12-14 14:59:29 +00006886static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6887 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006888 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006889{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006890 struct nfs4_server_caps_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006891 struct compound_hdr hdr;
6892 int status;
6893
Chuck Leverbf269552010-12-14 14:59:29 +00006894 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006895 if (status)
6896 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006897 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006898 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006899 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006900 status = decode_putfh(xdr);
6901 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006902 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006903 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006904out:
6905 return status;
6906}
6907
6908/*
6909 * Decode RENEW response
6910 */
Chuck Leverbf269552010-12-14 14:59:29 +00006911static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6912 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006913{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006914 struct compound_hdr hdr;
6915 int status;
6916
Chuck Leverbf269552010-12-14 14:59:29 +00006917 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006918 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006919 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006920 return status;
6921}
6922
6923/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006924 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006925 */
Chuck Leverbf269552010-12-14 14:59:29 +00006926static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6927 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006928 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006929{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006930 struct nfs4_setclientid_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006931 struct compound_hdr hdr;
6932 int status;
6933
Chuck Leverbf269552010-12-14 14:59:29 +00006934 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006935 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006936 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006937 return status;
6938}
6939
6940/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006941 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006942 */
Chuck Leverbf269552010-12-14 14:59:29 +00006943static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006944 struct xdr_stream *xdr,
6945 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006946{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006947 struct compound_hdr hdr;
6948 int status;
6949
Chuck Leverbf269552010-12-14 14:59:29 +00006950 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006951 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006952 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006953 return status;
6954}
6955
6956/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006957 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006958 */
Chuck Leverbf269552010-12-14 14:59:29 +00006959static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6960 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006961 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006962{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006963 struct nfs4_delegreturnres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006964 struct compound_hdr hdr;
6965 int status;
6966
Chuck Leverbf269552010-12-14 14:59:29 +00006967 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006968 if (status)
6969 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006970 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006971 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006972 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006973 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006974 if (status != 0)
6975 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05006976 if (res->lr_res) {
6977 status = decode_layoutreturn(xdr, res->lr_res);
6978 res->lr_ret = status;
6979 if (status)
6980 goto out;
6981 }
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05006982 if (res->fattr) {
6983 status = decode_getfattr(xdr, res->fattr, res->server);
6984 if (status != 0)
6985 goto out;
6986 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006987 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006988out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006989 return status;
6990}
6991
Trond Myklebust683b57b2006-06-09 09:34:22 -04006992/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006993 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006994 */
Chuck Leverbf269552010-12-14 14:59:29 +00006995static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6996 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006997 void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006998{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006999 struct nfs4_fs_locations_res *res = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04007000 struct compound_hdr hdr;
7001 int status;
7002
Chuck Leverbf269552010-12-14 14:59:29 +00007003 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007004 if (status)
7005 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007006 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007007 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007008 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007009 status = decode_putfh(xdr);
7010 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007011 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04007012 if (res->migration) {
7013 xdr_enter_page(xdr, PAGE_SIZE);
7014 status = decode_getfattr_generic(xdr,
7015 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007016 NULL, res->fs_locations,
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04007017 res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04007018 if (status)
7019 goto out;
7020 if (res->renew)
7021 status = decode_renew(xdr);
7022 } else {
7023 status = decode_lookup(xdr);
7024 if (status)
7025 goto out;
7026 xdr_enter_page(xdr, PAGE_SIZE);
7027 status = decode_getfattr_generic(xdr,
7028 &res->fs_locations->fattr,
7029 NULL, res->fs_locations,
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04007030 res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04007031 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04007032out:
7033 return status;
7034}
7035
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007036/*
7037 * Decode SECINFO response
7038 */
7039static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7040 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007041 void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007042{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007043 struct nfs4_secinfo_res *res = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007044 struct compound_hdr hdr;
7045 int status;
7046
7047 status = decode_compound_hdr(xdr, &hdr);
7048 if (status)
7049 goto out;
7050 status = decode_sequence(xdr, &res->seq_res, rqstp);
7051 if (status)
7052 goto out;
7053 status = decode_putfh(xdr);
7054 if (status)
7055 goto out;
7056 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007057out:
7058 return status;
7059}
7060
Chuck Lever44c99932013-10-17 14:13:30 -04007061/*
7062 * Decode FSID_PRESENT response
7063 */
7064static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7065 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007066 void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04007067{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007068 struct nfs4_fsid_present_res *res = data;
Chuck Lever44c99932013-10-17 14:13:30 -04007069 struct compound_hdr hdr;
7070 int status;
7071
7072 status = decode_compound_hdr(xdr, &hdr);
7073 if (status)
7074 goto out;
7075 status = decode_sequence(xdr, &res->seq_res, rqstp);
7076 if (status)
7077 goto out;
7078 status = decode_putfh(xdr);
7079 if (status)
7080 goto out;
7081 status = decode_getfh(xdr, res->fh);
7082 if (status)
7083 goto out;
7084 if (res->renew)
7085 status = decode_renew(xdr);
7086out:
7087 return status;
7088}
7089
Benny Halevy99fe60d2009-04-01 09:22:29 -04007090#if defined(CONFIG_NFS_V4_1)
7091/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007092 * Decode BIND_CONN_TO_SESSION response
7093 */
7094static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7095 struct xdr_stream *xdr,
7096 void *res)
7097{
7098 struct compound_hdr hdr;
7099 int status;
7100
7101 status = decode_compound_hdr(xdr, &hdr);
7102 if (!status)
7103 status = decode_bind_conn_to_session(xdr, res);
7104 return status;
7105}
7106
7107/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007108 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007109 */
Chuck Leverbf269552010-12-14 14:59:29 +00007110static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7111 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007112 void *res)
7113{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007114 struct compound_hdr hdr;
7115 int status;
7116
Chuck Leverbf269552010-12-14 14:59:29 +00007117 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007118 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007119 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007120 return status;
7121}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007122
7123/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007124 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007125 */
Chuck Leverbf269552010-12-14 14:59:29 +00007126static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7127 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007128 void *res)
Andy Adamsonfc931582009-04-01 09:22:31 -04007129{
Andy Adamsonfc931582009-04-01 09:22:31 -04007130 struct compound_hdr hdr;
7131 int status;
7132
Chuck Leverbf269552010-12-14 14:59:29 +00007133 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007134 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007135 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007136 return status;
7137}
7138
7139/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007140 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007141 */
Chuck Leverbf269552010-12-14 14:59:29 +00007142static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7143 struct xdr_stream *xdr,
7144 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007145{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007146 struct compound_hdr hdr;
7147 int status;
7148
Chuck Leverbf269552010-12-14 14:59:29 +00007149 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007150 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007151 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007152 return status;
7153}
7154
7155/*
Trond Myklebust66245532012-05-25 17:18:09 -04007156 * Decode DESTROY_CLIENTID response
7157 */
7158static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7159 struct xdr_stream *xdr,
7160 void *res)
7161{
7162 struct compound_hdr hdr;
7163 int status;
7164
7165 status = decode_compound_hdr(xdr, &hdr);
7166 if (!status)
7167 status = decode_destroy_clientid(xdr, res);
7168 return status;
7169}
7170
7171/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007172 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007173 */
Chuck Leverbf269552010-12-14 14:59:29 +00007174static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7175 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007176 void *res)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007177{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007178 struct compound_hdr hdr;
7179 int status;
7180
Chuck Leverbf269552010-12-14 14:59:29 +00007181 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007182 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007183 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007184 return status;
7185}
7186
Donald Buczek0efb01b2019-07-07 21:26:08 +02007187#endif
7188
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007189/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007190 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007191 */
Chuck Leverbf269552010-12-14 14:59:29 +00007192static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7193 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007194 void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04007195{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007196 struct nfs4_get_lease_time_res *res = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04007197 struct compound_hdr hdr;
7198 int status;
7199
Chuck Leverbf269552010-12-14 14:59:29 +00007200 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007201 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007202 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007203 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007204 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007205 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007206 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007207 return status;
7208}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007209
Donald Buczek0efb01b2019-07-07 21:26:08 +02007210#ifdef CONFIG_NFS_V4_1
7211
Ricardo Labiaga180197532009-12-05 16:08:40 -05007212/*
7213 * Decode RECLAIM_COMPLETE response
7214 */
Chuck Leverbf269552010-12-14 14:59:29 +00007215static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7216 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007217 void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05007218{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007219 struct nfs41_reclaim_complete_res *res = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05007220 struct compound_hdr hdr;
7221 int status;
7222
Chuck Leverbf269552010-12-14 14:59:29 +00007223 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007224 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007225 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007226 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307227 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007228 return status;
7229}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007230
7231/*
7232 * Decode GETDEVINFO response
7233 */
Chuck Leverbf269552010-12-14 14:59:29 +00007234static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7235 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007236 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007237{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007238 struct nfs4_getdeviceinfo_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007239 struct compound_hdr hdr;
7240 int status;
7241
Chuck Leverbf269552010-12-14 14:59:29 +00007242 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007243 if (status != 0)
7244 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007245 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007246 if (status != 0)
7247 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007248 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007249out:
7250 return status;
7251}
7252
7253/*
7254 * Decode LAYOUTGET response
7255 */
Chuck Leverbf269552010-12-14 14:59:29 +00007256static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7257 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007258 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007259{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007260 struct nfs4_layoutget_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007261 struct compound_hdr hdr;
7262 int status;
7263
Chuck Leverbf269552010-12-14 14:59:29 +00007264 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007265 if (status)
7266 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007267 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007268 if (status)
7269 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007270 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007271 if (status)
7272 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007273 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007274out:
7275 return status;
7276}
Andy Adamson863a3c62011-03-23 13:27:54 +00007277
7278/*
Benny Halevycbe82602011-05-22 19:52:37 +03007279 * Decode LAYOUTRETURN response
7280 */
7281static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7282 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007283 void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03007284{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007285 struct nfs4_layoutreturn_res *res = data;
Benny Halevycbe82602011-05-22 19:52:37 +03007286 struct compound_hdr hdr;
7287 int status;
7288
7289 status = decode_compound_hdr(xdr, &hdr);
7290 if (status)
7291 goto out;
7292 status = decode_sequence(xdr, &res->seq_res, rqstp);
7293 if (status)
7294 goto out;
7295 status = decode_putfh(xdr);
7296 if (status)
7297 goto out;
7298 status = decode_layoutreturn(xdr, res);
7299out:
7300 return status;
7301}
7302
7303/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007304 * Decode LAYOUTCOMMIT response
7305 */
7306static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7307 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007308 void *data)
Andy Adamson863a3c62011-03-23 13:27:54 +00007309{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007310 struct nfs4_layoutcommit_res *res = data;
Andy Adamson863a3c62011-03-23 13:27:54 +00007311 struct compound_hdr hdr;
7312 int status;
7313
7314 status = decode_compound_hdr(xdr, &hdr);
7315 if (status)
7316 goto out;
7317 status = decode_sequence(xdr, &res->seq_res, rqstp);
7318 if (status)
7319 goto out;
7320 status = decode_putfh(xdr);
7321 if (status)
7322 goto out;
7323 status = decode_layoutcommit(xdr, rqstp, res);
7324 if (status)
7325 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05007326 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007327out:
7328 return status;
7329}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007330
7331/*
7332 * Decode SECINFO_NO_NAME response
7333 */
7334static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7335 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007336 void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007337{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007338 struct nfs4_secinfo_res *res = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007339 struct compound_hdr hdr;
7340 int status;
7341
7342 status = decode_compound_hdr(xdr, &hdr);
7343 if (status)
7344 goto out;
7345 status = decode_sequence(xdr, &res->seq_res, rqstp);
7346 if (status)
7347 goto out;
7348 status = decode_putrootfh(xdr);
7349 if (status)
7350 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007351 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007352out:
7353 return status;
7354}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007355
7356/*
7357 * Decode TEST_STATEID response
7358 */
7359static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7360 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007361 void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04007362{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007363 struct nfs41_test_stateid_res *res = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04007364 struct compound_hdr hdr;
7365 int status;
7366
7367 status = decode_compound_hdr(xdr, &hdr);
7368 if (status)
7369 goto out;
7370 status = decode_sequence(xdr, &res->seq_res, rqstp);
7371 if (status)
7372 goto out;
7373 status = decode_test_stateid(xdr, res);
7374out:
7375 return status;
7376}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007377
7378/*
7379 * Decode FREE_STATEID response
7380 */
7381static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7382 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007383 void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007384{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007385 struct nfs41_free_stateid_res *res = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007386 struct compound_hdr hdr;
7387 int status;
7388
7389 status = decode_compound_hdr(xdr, &hdr);
7390 if (status)
7391 goto out;
7392 status = decode_sequence(xdr, &res->seq_res, rqstp);
7393 if (status)
7394 goto out;
7395 status = decode_free_stateid(xdr, res);
7396out:
7397 return status;
7398}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007399#endif /* CONFIG_NFS_V4_1 */
7400
Chuck Lever573c4e12010-12-14 14:58:11 +00007401/**
7402 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7403 * the local page cache.
7404 * @xdr: XDR stream where entry resides
7405 * @entry: buffer to fill in with entry data
7406 * @plus: boolean indicating whether this should be a readdirplus entry
7407 *
7408 * Returns zero if successful, otherwise a negative errno value is
7409 * returned.
7410 *
7411 * This function is not invoked during READDIR reply decoding, but
7412 * rather whenever an application invokes the getdents(2) system call
7413 * on a directory already in our cache.
7414 */
7415int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -04007416 bool plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007417{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007418 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007419 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007420 uint32_t len;
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007421 uint64_t new_cookie;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007422 __be32 *p = xdr_inline_decode(xdr, 4);
7423 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007424 return -EAGAIN;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007425 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007426 p = xdr_inline_decode(xdr, 4);
7427 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007428 return -EAGAIN;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007429 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007430 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007431 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007432 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007433 }
7434
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007435 p = xdr_inline_decode(xdr, 12);
7436 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007437 return -EAGAIN;
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007438 p = xdr_decode_hyper(p, &new_cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007439 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007440
Trond Myklebust9af8c222010-10-24 11:52:55 -04007441 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007442 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007443 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007444 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007445
7446 /*
7447 * In case the server doesn't return an inode number,
7448 * we fake one here. (We don't use inode number 0,
7449 * since glibc seems to choke on it...)
7450 */
7451 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007452 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007453
Trond Myklebust9af8c222010-10-24 11:52:55 -04007454 if (decode_attr_bitmap(xdr, bitmap) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05007455 return -EAGAIN;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007456
Trond Myklebust256e48b2012-06-21 11:18:13 -04007457 if (decode_attr_length(xdr, &len, &savep) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05007458 return -EAGAIN;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007459
Chuck Lever573c4e12010-12-14 14:58:11 +00007460 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Anna Schumaker1e2f67d2021-10-22 13:11:13 -04007461 NULL, entry->server) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05007462 return -EAGAIN;
Trond Myklebust28331a42011-04-27 13:47:52 -04007463 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7464 entry->ino = entry->fattr->mounted_on_fileid;
7465 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007466 entry->ino = entry->fattr->fileid;
7467
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007468 entry->d_type = DT_UNKNOWN;
7469 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7470 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7471
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007472 entry->prev_cookie = entry->cookie;
7473 entry->cookie = new_cookie;
7474
Chuck Lever573c4e12010-12-14 14:58:11 +00007475 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007476}
7477
7478/*
7479 * We need to translate between nfs status return values and
7480 * the local errno values which may not be the same.
7481 */
7482static struct {
7483 int stat;
7484 int errno;
7485} nfs_errtbl[] = {
7486 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007487 { NFS4ERR_PERM, -EPERM },
7488 { NFS4ERR_NOENT, -ENOENT },
7489 { NFS4ERR_IO, -errno_NFSERR_IO},
7490 { NFS4ERR_NXIO, -ENXIO },
7491 { NFS4ERR_ACCESS, -EACCES },
7492 { NFS4ERR_EXIST, -EEXIST },
7493 { NFS4ERR_XDEV, -EXDEV },
7494 { NFS4ERR_NOTDIR, -ENOTDIR },
7495 { NFS4ERR_ISDIR, -EISDIR },
7496 { NFS4ERR_INVAL, -EINVAL },
7497 { NFS4ERR_FBIG, -EFBIG },
7498 { NFS4ERR_NOSPC, -ENOSPC },
7499 { NFS4ERR_ROFS, -EROFS },
7500 { NFS4ERR_MLINK, -EMLINK },
7501 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7502 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7503 { NFS4ERR_DQUOT, -EDQUOT },
7504 { NFS4ERR_STALE, -ESTALE },
7505 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007506 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7507 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7508 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007509 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007510 { NFS4ERR_BADTYPE, -EBADTYPE },
7511 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007512 { NFS4ERR_SYMLINK, -ELOOP },
7513 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7514 { NFS4ERR_DEADLOCK, -EDEADLK },
Frank van der Linden3e1f0212020-06-23 22:38:56 +00007515 { NFS4ERR_NOXATTR, -ENODATA },
7516 { NFS4ERR_XATTR2BIG, -E2BIG },
Benny Halevy856dff32008-03-31 17:39:06 +03007517 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007518};
7519
7520/*
7521 * Convert an NFS error code to a local one.
7522 * This one is used jointly by NFSv2 and NFSv3.
7523 */
7524static int
David Howells0a8ea432006-08-22 20:06:08 -04007525nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007526{
7527 int i;
7528 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7529 if (nfs_errtbl[i].stat == stat)
7530 return nfs_errtbl[i].errno;
7531 }
7532 if (stat <= 10000 || stat > 10100) {
7533 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007534 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007535 }
7536 /* If we cannot translate the error, the recovery routines should
7537 * handle it.
7538 * Note: remaining NFSv4 error codes have values > 10000, so should
7539 * not conflict with native Linux error codes.
7540 */
Benny Halevy856dff32008-03-31 17:39:06 +03007541 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007542}
7543
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007544#ifdef CONFIG_NFS_V4_2
7545#include "nfs42xdr.c"
7546#endif /* CONFIG_NFS_V4_2 */
7547
Linus Torvalds1da177e2005-04-16 15:20:36 -07007548#define PROC(proc, argtype, restype) \
7549[NFSPROC4_CLNT_##proc] = { \
7550 .p_proc = NFSPROC4_COMPOUND, \
Christoph Hellwigfcc85812017-05-08 10:01:49 +02007551 .p_encode = nfs4_xdr_##argtype, \
Christoph Hellwigfc016482017-05-08 15:09:02 +02007552 .p_decode = nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007553 .p_arglen = NFS4_##argtype##_sz, \
7554 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007555 .p_statidx = NFSPROC4_CLNT_##proc, \
7556 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007557}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007558
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007559#define STUB(proc) \
7560[NFSPROC4_CLNT_##proc] = { \
7561 .p_name = #proc, \
7562}
7563
Trond Myklebust8634ef52018-01-06 09:53:49 -05007564#if defined(CONFIG_NFS_V4_1)
7565#define PROC41(proc, argtype, restype) \
7566 PROC(proc, argtype, restype)
7567#else
7568#define PROC41(proc, argtype, restype) \
7569 STUB(proc)
7570#endif
7571
7572#if defined(CONFIG_NFS_V4_2)
7573#define PROC42(proc, argtype, restype) \
7574 PROC(proc, argtype, restype)
7575#else
7576#define PROC42(proc, argtype, restype) \
7577 STUB(proc)
7578#endif
7579
Christoph Hellwig511e9362017-05-12 15:36:49 +02007580const struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007581 PROC(READ, enc_read, dec_read),
7582 PROC(WRITE, enc_write, dec_write),
7583 PROC(COMMIT, enc_commit, dec_commit),
7584 PROC(OPEN, enc_open, dec_open),
7585 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7586 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7587 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7588 PROC(CLOSE, enc_close, dec_close),
7589 PROC(SETATTR, enc_setattr, dec_setattr),
7590 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7591 PROC(RENEW, enc_renew, dec_renew),
7592 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7593 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7594 PROC(LOCK, enc_lock, dec_lock),
7595 PROC(LOCKT, enc_lockt, dec_lockt),
7596 PROC(LOCKU, enc_locku, dec_locku),
7597 PROC(ACCESS, enc_access, dec_access),
7598 PROC(GETATTR, enc_getattr, dec_getattr),
7599 PROC(LOOKUP, enc_lookup, dec_lookup),
7600 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7601 PROC(REMOVE, enc_remove, dec_remove),
7602 PROC(RENAME, enc_rename, dec_rename),
7603 PROC(LINK, enc_link, dec_link),
7604 PROC(SYMLINK, enc_symlink, dec_symlink),
7605 PROC(CREATE, enc_create, dec_create),
7606 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7607 PROC(STATFS, enc_statfs, dec_statfs),
7608 PROC(READLINK, enc_readlink, dec_readlink),
7609 PROC(READDIR, enc_readdir, dec_readdir),
7610 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7611 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7612 PROC(GETACL, enc_getacl, dec_getacl),
7613 PROC(SETACL, enc_setacl, dec_setacl),
7614 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7615 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007616 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007617 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007618 PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7619 PROC41(CREATE_SESSION, enc_create_session, dec_create_session),
7620 PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7621 PROC41(SEQUENCE, enc_sequence, dec_sequence),
Donald Buczek0efb01b2019-07-07 21:26:08 +02007622 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007623 PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete),
7624 PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7625 PROC41(LAYOUTGET, enc_layoutget, dec_layoutget),
7626 PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7627 PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7628 PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7629 PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7630 PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007631 STUB(GETDEVICELIST),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007632 PROC41(BIND_CONN_TO_SESSION,
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007633 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007634 PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid),
7635 PROC42(SEEK, enc_seek, dec_seek),
7636 PROC42(ALLOCATE, enc_allocate, dec_allocate),
7637 PROC42(DEALLOCATE, enc_deallocate, dec_deallocate),
7638 PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
7639 PROC42(CLONE, enc_clone, dec_clone),
7640 PROC42(COPY, enc_copy, dec_copy),
Olga Kornievskaiacb95dee2018-07-09 15:13:29 -04007641 PROC42(OFFLOAD_CANCEL, enc_offload_cancel, dec_offload_cancel),
Olga Kornievskaia04915672019-06-04 16:14:30 -04007642 PROC42(COPY_NOTIFY, enc_copy_notify, dec_copy_notify),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007643 PROC(LOOKUPP, enc_lookupp, dec_lookupp),
Trond Myklebust3eb86092019-02-08 10:31:05 -05007644 PROC42(LAYOUTERROR, enc_layouterror, dec_layouterror),
Frank van der Linden3e1f0212020-06-23 22:38:56 +00007645 PROC42(GETXATTR, enc_getxattr, dec_getxattr),
7646 PROC42(SETXATTR, enc_setxattr, dec_setxattr),
7647 PROC42(LISTXATTRS, enc_listxattrs, dec_listxattrs),
7648 PROC42(REMOVEXATTR, enc_removexattr, dec_removexattr),
Anna Schumakerc5675522014-05-28 13:41:22 -04007649 PROC42(READ_PLUS, enc_read_plus, dec_read_plus),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007650};
7651
Christoph Hellwigc5518582017-05-08 23:27:10 +02007652static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
Trond Myklebusta613fa12012-01-20 13:53:56 -05007653const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007654 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007655 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Christoph Hellwigc5518582017-05-08 23:27:10 +02007656 .procs = nfs4_procedures,
7657 .counts = nfs_version4_counts,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007658};