blob: 3899ef3047f47a6164cc8d1e7ee9ff3597061cec [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 + \
147 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
149#define decode_renew_maxsz (op_decode_hdr_maxsz)
150#define encode_setclientid_maxsz \
151 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500152 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400153 /* client name */ \
154 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500155 1 /* sc_prog */ + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500156 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
157 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500158 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159#define decode_setclientid_maxsz \
160 (op_decode_hdr_maxsz + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500161 2 /* clientid */ + \
162 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
163 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
164 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165#define encode_setclientid_confirm_maxsz \
166 (op_encode_hdr_maxsz + \
167 3 + (NFS4_VERIFIER_SIZE >> 2))
168#define decode_setclientid_confirm_maxsz \
169 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400170#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
171#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700172#define encode_lookupp_maxsz (op_encode_hdr_maxsz)
173#define decode_lookupp_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400174#define encode_share_access_maxsz \
175 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500176#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400177#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
178#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
179#define encode_open_maxsz (op_encode_hdr_maxsz + \
180 2 + encode_share_access_maxsz + 2 + \
181 open_owner_id_maxsz + \
182 encode_opentype_maxsz + \
183 encode_claim_null_maxsz)
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500184#define decode_space_limit_maxsz (3)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400185#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400186#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500187 decode_space_limit_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400188 decode_ace_maxsz)
189#define decode_change_info_maxsz (5)
190#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400191 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400192 decode_change_info_maxsz + 1 + \
193 nfs4_fattr_bitmap_maxsz + \
194 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400195#define encode_open_confirm_maxsz \
196 (op_encode_hdr_maxsz + \
197 encode_stateid_maxsz + 1)
198#define decode_open_confirm_maxsz \
199 (op_decode_hdr_maxsz + \
200 decode_stateid_maxsz)
201#define encode_open_downgrade_maxsz \
202 (op_encode_hdr_maxsz + \
203 encode_stateid_maxsz + 1 + \
204 encode_share_access_maxsz)
205#define decode_open_downgrade_maxsz \
206 (op_decode_hdr_maxsz + \
207 decode_stateid_maxsz)
208#define encode_close_maxsz (op_encode_hdr_maxsz + \
209 1 + encode_stateid_maxsz)
210#define decode_close_maxsz (op_decode_hdr_maxsz + \
211 decode_stateid_maxsz)
212#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
213 encode_stateid_maxsz + \
214 encode_attrs_maxsz)
215#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
216 nfs4_fattr_bitmap_maxsz)
217#define encode_read_maxsz (op_encode_hdr_maxsz + \
218 encode_stateid_maxsz + 3)
Trond Myklebust9ed5af262020-11-21 20:46:18 -0500219#define decode_read_maxsz (op_decode_hdr_maxsz + 2 + pagepad_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400220#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400221 2 + encode_verifier_maxsz + 5 + \
222 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400223#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9ed5af262020-11-21 20:46:18 -0500224 decode_verifier_maxsz + pagepad_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400225#define encode_readlink_maxsz (op_encode_hdr_maxsz)
Trond Myklebust9ed5af262020-11-21 20:46:18 -0500226#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1 + pagepad_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400227#define encode_write_maxsz (op_encode_hdr_maxsz + \
228 encode_stateid_maxsz + 4)
229#define decode_write_maxsz (op_decode_hdr_maxsz + \
230 2 + decode_verifier_maxsz)
231#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
232#define decode_commit_maxsz (op_decode_hdr_maxsz + \
233 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234#define encode_remove_maxsz (op_encode_hdr_maxsz + \
235 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400236#define decode_remove_maxsz (op_decode_hdr_maxsz + \
237 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#define encode_rename_maxsz (op_encode_hdr_maxsz + \
239 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400240#define decode_rename_maxsz (op_decode_hdr_maxsz + \
241 decode_change_info_maxsz + \
242 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243#define encode_link_maxsz (op_encode_hdr_maxsz + \
244 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400245#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400246#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400247#define encode_lock_maxsz (op_encode_hdr_maxsz + \
248 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400249 1 + encode_stateid_maxsz + 1 + \
250 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400251#define decode_lock_denied_maxsz \
252 (8 + decode_lockowner_maxsz)
253#define decode_lock_maxsz (op_decode_hdr_maxsz + \
254 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400255#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
256 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400257#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
258 decode_lock_denied_maxsz)
259#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
260 encode_stateid_maxsz + \
261 4)
262#define decode_locku_maxsz (op_decode_hdr_maxsz + \
263 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400264#define encode_release_lockowner_maxsz \
265 (op_encode_hdr_maxsz + \
266 encode_lockowner_maxsz)
267#define decode_release_lockowner_maxsz \
268 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400269#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
270#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
272 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400273 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000274 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
276#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400277 1 + 2 + nfs4_name_maxsz + \
278 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400279#define decode_create_maxsz (op_decode_hdr_maxsz + \
280 decode_change_info_maxsz + \
281 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400282#define encode_statfs_maxsz (encode_getattr_maxsz)
283#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
285#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400286#define encode_getacl_maxsz (encode_getattr_maxsz)
287#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9ed5af262020-11-21 20:46:18 -0500288 nfs4_fattr_bitmap_maxsz + 1 + pagepad_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400289#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
290 encode_stateid_maxsz + 3)
291#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400292#define encode_fs_locations_maxsz \
293 (encode_getattr_maxsz)
294#define decode_fs_locations_maxsz \
Trond Myklebust9ed5af262020-11-21 20:46:18 -0500295 (pagepad_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000296#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400297#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 -0400298
299#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400300#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500301#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
302 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400303
Benny Halevy99fe60d2009-04-01 09:22:29 -0400304#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
305 encode_verifier_maxsz + \
306 1 /* co_ownerid.len */ + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400307 /* eia_clientowner */ \
308 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400309 1 /* flags */ + \
310 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400311 /* max is SP4_MACH_CRED (for now) */ + \
312 1 + NFS4_OP_MAP_NUM_WORDS + \
313 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500314 1 /* implementation id array of size 1 */ + \
315 1 /* nii_domain */ + \
316 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
317 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500318 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500319 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400320#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
321 2 /* eir_clientid */ + \
322 1 /* eir_sequenceid */ + \
323 1 /* eir_flags */ + \
324 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400325 /* max is SP4_MACH_CRED (for now) */ + \
326 1 + NFS4_OP_MAP_NUM_WORDS + \
327 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400328 2 /* eir_server_owner.so_minor_id */ + \
329 /* eir_server_owner.so_major_id<> */ \
330 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
331 /* eir_server_scope<> */ \
332 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
333 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500334 1 /* nii_domain */ + \
335 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
336 1 /* nii_name */ + \
337 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
338 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400339#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
340#define decode_channel_attrs_maxsz (6 + \
341 1 /* ca_rdma_ird.len */ + \
342 1 /* ca_rdma_ird */)
343#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
344 2 /* csa_clientid */ + \
345 1 /* csa_sequence */ + \
346 1 /* csa_flags */ + \
347 encode_channel_attrs_maxsz + \
348 encode_channel_attrs_maxsz + \
349 1 /* csa_cb_program */ + \
350 1 /* csa_sec_parms.len (1) */ + \
351 1 /* cb_secflavor (AUTH_SYS) */ + \
352 1 /* stamp */ + \
353 1 /* machinename.len */ + \
354 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
355 1 /* uid */ + \
356 1 /* gid */ + \
357 1 /* gids.len (0) */)
358#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
359 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
360 1 /* csr_sequence */ + \
361 1 /* csr_flags */ + \
362 decode_channel_attrs_maxsz + \
363 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400364#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
365 /* bctsa_sessid */ \
366 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
367 1 /* bctsa_dir */ + \
368 1 /* bctsa_use_conn_in_rdma_mode */)
369#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
370 /* bctsr_sessid */ \
371 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
372 1 /* bctsr_dir */ + \
373 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400374#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
375#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400376#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
377#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400378#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
379 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
380#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
381 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500382#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
383#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700384#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
385 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
386 1 /* layout type */ + \
387 1 /* maxcount */ + \
388 1 /* bitmap size */ + \
389 1 /* notification bitmap length */ + \
390 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400391#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
392 1 /* layout type */ + \
393 1 /* opaque devaddr4 length */ + \
394 /* devaddr4 payload is read into page */ \
395 1 /* notification bitmap length */ + \
Chuck Lever02ef04e2019-02-11 11:25:25 -0500396 1 /* notification bitmap, word 0 */ + \
Trond Myklebust9ed5af262020-11-21 20:46:18 -0500397 pagepad_maxsz /* possible XDR padding */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400398#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
399 encode_stateid_maxsz)
400#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
401 decode_stateid_maxsz + \
Trond Myklebust9ed5af262020-11-21 20:46:18 -0500402 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + \
403 pagepad_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000404#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
405 2 /* offset */ + \
406 2 /* length */ + \
407 1 /* reclaim */ + \
408 encode_stateid_maxsz + \
409 1 /* new offset (true) */ + \
410 2 /* last byte written */ + \
411 1 /* nt_timechanged (false) */ + \
412 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500413 1 /* layoutupdate4 opaqueue len */)
414 /* the actual content of layoutupdate4 should
415 be allocated by drivers and spliced in
416 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000417#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300418#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
419 encode_stateid_maxsz + \
Trond Myklebust6669cb82015-08-27 20:43:20 -0400420 1 + \
421 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
Benny Halevycbe82602011-05-22 19:52:37 +0300422#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
423 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400424#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
425#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400426#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
427 XDR_QUADLEN(NFS4_STATEID_SIZE))
428#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400429#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
430 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400431#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432#else /* CONFIG_NFS_V4_1 */
433#define encode_sequence_maxsz 0
434#define decode_sequence_maxsz 0
Trond Myklebustcf805162016-11-15 14:56:07 -0500435#define encode_layoutreturn_maxsz 0
436#define decode_layoutreturn_maxsz 0
Fred Isaman56f487f2016-09-21 11:43:41 -0400437#define encode_layoutget_maxsz 0
438#define decode_layoutget_maxsz 0
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400439#endif /* CONFIG_NFS_V4_1 */
440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
442#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
443#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400444 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400446 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400448 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400450 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400452 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400454 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400456 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400458 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400460 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400462 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400464 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400466 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400468 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400470 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400471 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400473 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400475 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400476 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#define NFS4_enc_commit_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 Myklebust85827152012-04-29 10:44:42 -0400480 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400482 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400484 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400486 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400487 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400488 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400489 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400490 encode_getfh_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400491 encode_getattr_maxsz + \
492 encode_layoutget_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400494 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400495 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400496 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400497 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400498 decode_getfh_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400499 decode_getattr_maxsz + \
500 decode_layoutget_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400501#define NFS4_enc_open_confirm_sz \
502 (compound_encode_hdr_maxsz + \
503 encode_putfh_maxsz + \
504 encode_open_confirm_maxsz)
505#define NFS4_dec_open_confirm_sz \
506 (compound_decode_hdr_maxsz + \
507 decode_putfh_maxsz + \
508 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400510 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400512 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400513 encode_access_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400514 encode_getattr_maxsz + \
515 encode_layoutget_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400517 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400519 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400520 decode_access_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400521 decode_getattr_maxsz + \
522 decode_layoutget_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523#define NFS4_enc_open_downgrade_sz \
524 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400525 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400526 encode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500527 encode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400528 encode_open_downgrade_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_dec_open_downgrade_sz \
530 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400531 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400532 decode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500533 decode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400534 decode_open_downgrade_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400535#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400536 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400537 encode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500538 encode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400539 encode_close_maxsz + \
540 encode_getattr_maxsz)
541#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400543 decode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500544 decode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400545 decode_close_maxsz + \
546 decode_getattr_maxsz)
547#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400548 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400549 encode_putfh_maxsz + \
550 encode_setattr_maxsz + \
551 encode_getattr_maxsz)
552#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400553 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400554 decode_putfh_maxsz + \
555 decode_setattr_maxsz + \
556 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400558 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 encode_putfh_maxsz + \
560 encode_fsinfo_maxsz)
561#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 decode_putfh_maxsz + \
564 decode_fsinfo_maxsz)
565#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
566 encode_renew_maxsz)
567#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
568 decode_renew_maxsz)
569#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
570 encode_setclientid_maxsz)
571#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
572 decode_setclientid_maxsz)
573#define NFS4_enc_setclientid_confirm_sz \
574 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400575 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576#define NFS4_dec_setclientid_confirm_sz \
577 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400578 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400582 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400584 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400586 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400588 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400590 encode_lockt_maxsz)
591#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400592 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400593 decode_putfh_maxsz + \
594 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400598 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400600 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400602 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400603#define NFS4_enc_release_lockowner_sz \
604 (compound_encode_hdr_maxsz + \
605 encode_lockowner_maxsz)
606#define NFS4_dec_release_lockowner_sz \
607 (compound_decode_hdr_maxsz + \
608 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400610 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400612 encode_access_maxsz + \
613 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400615 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400617 decode_access_maxsz + \
618 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619#define NFS4_enc_getattr_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 + \
Chuck Lever44c99932013-10-17 14:13:30 -0400622 encode_getattr_maxsz + \
623 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624#define NFS4_dec_getattr_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 + \
Chuck Lever44c99932013-10-17 14:13:30 -0400627 decode_getattr_maxsz + \
628 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#define NFS4_enc_lookup_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 + \
632 encode_lookup_maxsz + \
633 encode_getattr_maxsz + \
634 encode_getfh_maxsz)
635#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400636 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400638 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 decode_getattr_maxsz + \
640 decode_getfh_maxsz)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700641#define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \
642 encode_sequence_maxsz + \
643 encode_putfh_maxsz + \
644 encode_lookupp_maxsz + \
645 encode_getattr_maxsz + \
646 encode_getfh_maxsz)
647#define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \
648 decode_sequence_maxsz + \
649 decode_putfh_maxsz + \
650 decode_lookupp_maxsz + \
651 decode_getattr_maxsz + \
652 decode_getfh_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 encode_putrootfh_maxsz + \
656 encode_getattr_maxsz + \
657 encode_getfh_maxsz)
658#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400659 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 decode_putrootfh_maxsz + \
661 decode_getattr_maxsz + \
662 decode_getfh_maxsz)
663#define NFS4_enc_remove_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_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400666 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400668 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400670 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 encode_putfh_maxsz + \
674 encode_savefh_maxsz + \
675 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400676 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677#define NFS4_dec_rename_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 + \
680 decode_savefh_maxsz + \
681 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400682 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 encode_putfh_maxsz + \
686 encode_savefh_maxsz + \
687 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400688 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400689 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400690 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 decode_putfh_maxsz + \
694 decode_savefh_maxsz + \
695 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400696 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400697 decode_restorefh_maxsz + \
698 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400700 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 encode_putfh_maxsz + \
702 encode_symlink_maxsz + \
703 encode_getattr_maxsz + \
704 encode_getfh_maxsz)
705#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400706 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 decode_putfh_maxsz + \
708 decode_symlink_maxsz + \
709 decode_getattr_maxsz + \
710 decode_getfh_maxsz)
711#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400712 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 encode_putfh_maxsz + \
714 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400715 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400716 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400718 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 decode_putfh_maxsz + \
720 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400721 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400722 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400724 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 encode_putfh_maxsz + \
726 encode_getattr_maxsz)
727#define NFS4_dec_pathconf_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_getattr_maxsz)
731#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400732 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400734 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400736 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400738 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400740 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800741 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 encode_getattr_maxsz)
743#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400744 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800745 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 decode_getattr_maxsz)
747#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400748 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 encode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500750 encode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100751 encode_delegreturn_maxsz + \
752 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400754 decode_sequence_maxsz + \
Trond Myklebustd8434d4c2016-11-16 13:54:00 -0500755 decode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500756 decode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100757 decode_delegreturn_maxsz + \
758 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000759#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400760 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000761 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400762 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000763#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400764 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000765 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400766 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000767#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400768 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000769 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400770 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000771#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400772 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000773 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400774 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400775#define NFS4_enc_fs_locations_sz \
776 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400777 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400778 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400779 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400780 encode_fs_locations_maxsz + \
781 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400782#define NFS4_dec_fs_locations_sz \
783 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400784 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400785 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400786 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400787 decode_fs_locations_maxsz + \
788 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000789#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
790 encode_sequence_maxsz + \
791 encode_putfh_maxsz + \
792 encode_secinfo_maxsz)
793#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
794 decode_sequence_maxsz + \
795 decode_putfh_maxsz + \
796 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400797#define NFS4_enc_fsid_present_sz \
798 (compound_encode_hdr_maxsz + \
799 encode_sequence_maxsz + \
800 encode_putfh_maxsz + \
801 encode_getfh_maxsz + \
802 encode_renew_maxsz)
803#define NFS4_dec_fsid_present_sz \
804 (compound_decode_hdr_maxsz + \
805 decode_sequence_maxsz + \
806 decode_putfh_maxsz + \
807 decode_getfh_maxsz + \
808 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400809#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400810#define NFS4_enc_bind_conn_to_session_sz \
811 (compound_encode_hdr_maxsz + \
812 encode_bind_conn_to_session_maxsz)
813#define NFS4_dec_bind_conn_to_session_sz \
814 (compound_decode_hdr_maxsz + \
815 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400816#define NFS4_enc_exchange_id_sz \
817 (compound_encode_hdr_maxsz + \
818 encode_exchange_id_maxsz)
819#define NFS4_dec_exchange_id_sz \
820 (compound_decode_hdr_maxsz + \
821 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400822#define NFS4_enc_create_session_sz \
823 (compound_encode_hdr_maxsz + \
824 encode_create_session_maxsz)
825#define NFS4_dec_create_session_sz \
826 (compound_decode_hdr_maxsz + \
827 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400828#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
829 encode_destroy_session_maxsz)
830#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
831 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400832#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
833 encode_destroy_clientid_maxsz)
834#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
835 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400836#define NFS4_enc_sequence_sz \
837 (compound_decode_hdr_maxsz + \
838 encode_sequence_maxsz)
839#define NFS4_dec_sequence_sz \
840 (compound_decode_hdr_maxsz + \
841 decode_sequence_maxsz)
Donald Buczek0efb01b2019-07-07 21:26:08 +0200842#endif
Andy Adamson2050f0c2009-04-01 09:22:30 -0400843#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
844 encode_sequence_maxsz + \
845 encode_putrootfh_maxsz + \
846 encode_fsinfo_maxsz)
847#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
848 decode_sequence_maxsz + \
849 decode_putrootfh_maxsz + \
850 decode_fsinfo_maxsz)
Donald Buczek0efb01b2019-07-07 21:26:08 +0200851#if defined(CONFIG_NFS_V4_1)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500852#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
853 encode_sequence_maxsz + \
854 encode_reclaim_complete_maxsz)
855#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
856 decode_sequence_maxsz + \
857 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400858#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
859 encode_sequence_maxsz +\
860 encode_getdeviceinfo_maxsz)
861#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
862 decode_sequence_maxsz + \
863 decode_getdeviceinfo_maxsz)
864#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
865 encode_sequence_maxsz + \
866 encode_putfh_maxsz + \
867 encode_layoutget_maxsz)
868#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
869 decode_sequence_maxsz + \
870 decode_putfh_maxsz + \
871 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000872#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
873 encode_sequence_maxsz +\
874 encode_putfh_maxsz + \
875 encode_layoutcommit_maxsz + \
876 encode_getattr_maxsz)
877#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
878 decode_sequence_maxsz + \
879 decode_putfh_maxsz + \
880 decode_layoutcommit_maxsz + \
881 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300882#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
883 encode_sequence_maxsz + \
884 encode_putfh_maxsz + \
885 encode_layoutreturn_maxsz)
886#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
887 decode_sequence_maxsz + \
888 decode_putfh_maxsz + \
889 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400890#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
891 encode_sequence_maxsz + \
892 encode_putrootfh_maxsz +\
893 encode_secinfo_no_name_maxsz)
894#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
895 decode_sequence_maxsz + \
896 decode_putrootfh_maxsz + \
897 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400898#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
899 encode_sequence_maxsz + \
900 encode_test_stateid_maxsz)
901#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
902 decode_sequence_maxsz + \
903 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400904#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
905 encode_sequence_maxsz + \
906 encode_free_stateid_maxsz)
907#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
908 decode_sequence_maxsz + \
909 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500910
911const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
912 compound_encode_hdr_maxsz +
913 encode_sequence_maxsz +
914 encode_putfh_maxsz +
915 encode_getattr_maxsz) *
916 XDR_UNIT);
917
918const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
919 compound_decode_hdr_maxsz +
920 decode_sequence_maxsz +
921 decode_putfh_maxsz) *
922 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400923
924const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
925 compound_decode_hdr_maxsz +
926 decode_sequence_maxsz) *
927 XDR_UNIT);
928EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400929#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Trond Myklebustbca79472009-03-11 14:10:26 -0400931static const umode_t nfs_type2fmt[] = {
932 [NF4BAD] = 0,
933 [NF4REG] = S_IFREG,
934 [NF4DIR] = S_IFDIR,
935 [NF4BLK] = S_IFBLK,
936 [NF4CHR] = S_IFCHR,
937 [NF4LNK] = S_IFLNK,
938 [NF4SOCK] = S_IFSOCK,
939 [NF4FIFO] = S_IFIFO,
940 [NF4ATTRDIR] = 0,
941 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942};
943
944struct compound_hdr {
945 int32_t status;
946 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500947 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 uint32_t taglen;
949 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400950 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400951 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952};
953
Benny Halevy13c65ce2009-08-14 17:19:25 +0300954static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
955{
956 __be32 *p = xdr_reserve_space(xdr, nbytes);
957 BUG_ON(!p);
958 return p;
959}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
Trond Myklebustcb17e552012-03-04 18:13:56 -0500961static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
962{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500963 WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
Trond Myklebustcb17e552012-03-04 18:13:56 -0500964}
965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
967{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500968 WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969}
970
Trond Myklebust4ade9822012-03-04 18:13:57 -0500971static void encode_uint32(struct xdr_stream *xdr, u32 n)
972{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500973 WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500974}
975
Trond Myklebustff2eb682012-03-05 11:40:12 -0500976static void encode_uint64(struct xdr_stream *xdr, u64 n)
977{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500978 WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
Trond Myklebustff2eb682012-03-05 11:40:12 -0500979}
980
Trond Myklebust37c88762018-03-20 17:03:08 -0400981static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
982 const __u32 *bitmap, size_t len)
983{
984 ssize_t ret;
985
986 /* Trim empty words */
987 while (len > 0 && bitmap[len-1] == 0)
988 len--;
989 ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
990 if (WARN_ON_ONCE(ret < 0))
991 return ret;
992 return len;
993}
994
995static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
996 __u32 *res, size_t len)
997{
998 size_t i;
999 __u32 tmp;
1000
1001 while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
1002 len--;
1003 for (i = len; i-- > 0;) {
1004 tmp = bitmap[i] & mask[i];
1005 res[i] = tmp;
1006 }
1007 return len;
1008}
1009
Trond Myklebust4ade9822012-03-04 18:13:57 -05001010static void encode_nfs4_seqid(struct xdr_stream *xdr,
1011 const struct nfs_seqid *seqid)
1012{
Trond Myklebusta6796412015-01-23 19:04:44 -05001013 if (seqid != NULL)
1014 encode_uint32(xdr, seqid->sequence->counter);
1015 else
1016 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001017}
1018
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001019static void encode_compound_hdr(struct xdr_stream *xdr,
1020 struct rpc_rqst *req,
1021 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022{
Al Viro8687b632006-10-19 23:28:48 -07001023 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001024
1025 /* initialize running count of expected bytes in reply.
1026 * NOTE: the replied tag SHOULD be the same is the one sent,
1027 * but this is not required as a MUST for the server to do so. */
Chuck Levercf500ba2019-02-11 11:25:20 -05001028 hdr->replen = 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
Trond Myklebust7fc38842012-10-15 11:51:21 -04001030 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001031 encode_string(xdr, hdr->taglen, hdr->tag);
1032 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001033 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -05001034 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +03001035 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -05001036}
1037
Trond Myklebustab19b482012-03-04 18:13:57 -05001038static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
1039 uint32_t replen,
1040 struct compound_hdr *hdr)
1041{
1042 encode_uint32(xdr, op);
1043 hdr->nops++;
1044 hdr->replen += replen;
1045}
1046
Andy Adamsond0179312008-12-23 16:06:17 -05001047static void encode_nops(struct compound_hdr *hdr)
1048{
Trond Myklebust7fc38842012-10-15 11:51:21 -04001049 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -05001050 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051}
1052
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001053static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1054{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001055 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001056}
1057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1059{
Trond Myklebustcb17e552012-03-04 18:13:56 -05001060 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061}
1062
Trond Myklebust36b37432018-03-20 17:03:10 -04001063static __be32 *
Trond Myklebuste7d4b052019-10-04 16:43:09 -04001064xdr_encode_nfstime4(__be32 *p, const struct timespec64 *t)
Trond Myklebust36b37432018-03-20 17:03:10 -04001065{
Arnd Bergmanna3167da2019-11-11 21:16:27 +01001066 p = xdr_encode_hyper(p, t->tv_sec);
Trond Myklebust36b37432018-03-20 17:03:10 -04001067 *p++ = cpu_to_be32(t->tv_nsec);
1068 return p;
1069}
1070
David Quigleyaa9c2662013-05-22 12:50:44 -04001071static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1072 const struct nfs4_label *label,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001073 const umode_t *umask,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001074 const struct nfs_server *server,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001075 const uint32_t attrmask[])
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076{
1077 char owner_name[IDMAP_NAMESZ];
1078 char owner_group[IDMAP_NAMESZ];
1079 int owner_namelen = 0;
1080 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001081 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001082 uint32_t len = 0;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001083 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
1085 /*
1086 * We reserve enough space to write the entire attribute buffer at once.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 */
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001088 if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001089 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001091 }
1092 if (iap->ia_valid & ATTR_MODE) {
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001093 if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001094 bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1095 len += 8;
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001096 } else if (attrmask[1] & FATTR4_WORD1_MODE) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001097 bmval[1] |= FATTR4_WORD1_MODE;
1098 len += 4;
1099 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001100 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001101 if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001102 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001104 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001105 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 /* XXX */
1107 strcpy(owner_name, "nobody");
1108 owner_namelen = sizeof("nobody") - 1;
1109 /* goto out; */
1110 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001111 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1113 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001114 if ((iap->ia_valid & ATTR_GID) &&
1115 (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001116 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001118 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001119 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 strcpy(owner_group, "nobody");
1121 owner_grouplen = sizeof("nobody") - 1;
1122 /* goto out; */
1123 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001124 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1126 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001127 if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1128 if (iap->ia_valid & ATTR_ATIME_SET) {
1129 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
Trond Myklebust36b37432018-03-20 17:03:10 -04001130 len += 4 + (nfstime4_maxsz << 2);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001131 } else if (iap->ia_valid & ATTR_ATIME) {
1132 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1133 len += 4;
1134 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001136 if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1137 if (iap->ia_valid & ATTR_MTIME_SET) {
1138 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
Trond Myklebust36b37432018-03-20 17:03:10 -04001139 len += 4 + (nfstime4_maxsz << 2);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001140 } else if (iap->ia_valid & ATTR_MTIME) {
1141 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1142 len += 4;
1143 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001145
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001146 if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001147 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1148 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1149 }
1150
Trond Myklebust40a3426c2018-03-20 17:03:09 -04001151 xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
1152 xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001153
1154 if (bmval[0] & FATTR4_WORD0_SIZE)
1155 p = xdr_encode_hyper(p, iap->ia_size);
1156 if (bmval[1] & FATTR4_WORD1_MODE)
1157 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1158 if (bmval[1] & FATTR4_WORD1_OWNER)
1159 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1160 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1161 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1162 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1163 if (iap->ia_valid & ATTR_ATIME_SET) {
1164 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Trond Myklebuste7d4b052019-10-04 16:43:09 -04001165 p = xdr_encode_nfstime4(p, &iap->ia_atime);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001166 } else
1167 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1168 }
1169 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1170 if (iap->ia_valid & ATTR_MTIME_SET) {
1171 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Trond Myklebuste7d4b052019-10-04 16:43:09 -04001172 p = xdr_encode_nfstime4(p, &iap->ia_mtime);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001173 } else
1174 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1175 }
Jia-Ju Baie2751462019-07-26 15:48:53 +08001176 if (label && (bmval[2] & FATTR4_WORD2_SECURITY_LABEL)) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001177 *p++ = cpu_to_be32(label->lfs);
1178 *p++ = cpu_to_be32(label->pi);
1179 *p++ = cpu_to_be32(label->len);
1180 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1181 }
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001182 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1183 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1184 *p++ = cpu_to_be32(*umask);
1185 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001186
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188}
1189
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001190static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001192 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1193 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194}
1195
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001196static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197{
Trond Myklebustab19b482012-03-04 18:13:57 -05001198 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001199 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001200 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201}
1202
Fred Isaman0b7c0152012-04-20 14:47:39 -04001203static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204{
Al Viro8687b632006-10-19 23:28:48 -07001205 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001206
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001207 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1208 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001209 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001210 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211}
1212
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001213static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, 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_CREATE, decode_create_maxsz, hdr);
1218 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
1220 switch (create->ftype) {
1221 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001222 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001223 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001224 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1225 create->u.symlink.len);
1226 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 break;
1228
1229 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001230 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001231 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001232 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 break;
1234
1235 default:
1236 break;
1237 }
1238
Benny Halevy811652b2009-08-14 17:19:34 +03001239 encode_string(xdr, create->name->len, create->name->name);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001240 encode_attrs(xdr, create->attrs, create->label, &create->umask,
1241 create->server, create->server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242}
1243
Trond Myklebust37c88762018-03-20 17:03:08 -04001244static void encode_getattr(struct xdr_stream *xdr,
1245 const __u32 *bitmap, const __u32 *mask, size_t len,
1246 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247{
Trond Myklebust37c88762018-03-20 17:03:08 -04001248 __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001250 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04001251 if (mask) {
1252 if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
1253 len = ARRAY_SIZE(masked_bitmap);
1254 len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
1255 bitmap = masked_bitmap;
Fred Isamandae100c2011-07-30 20:52:37 -04001256 }
Trond Myklebust37c88762018-03-20 17:03:08 -04001257 xdr_encode_bitmap4(xdr, bitmap, len);
Fred Isamandae100c2011-07-30 20:52:37 -04001258}
1259
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001260static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261{
Trond Myklebust37c88762018-03-20 17:03:08 -04001262 encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
1263 ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264}
1265
Andy Adamson88034c32012-05-23 05:02:34 -04001266static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001267 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001268 struct compound_hdr *hdr)
1269{
Trond Myklebust37c88762018-03-20 17:03:08 -04001270 encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
Andy Adamson88034c32012-05-23 05:02:34 -04001271}
1272
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001273static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274{
Trond Myklebust37c88762018-03-20 17:03:08 -04001275 encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
1276 ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277}
1278
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001279static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001280{
Trond Myklebust37c88762018-03-20 17:03:08 -04001281 encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
1282 ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001283}
1284
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001285static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286{
Trond Myklebustab19b482012-03-04 18:13:57 -05001287 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288}
1289
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001290static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291{
Trond Myklebustab19b482012-03-04 18:13:57 -05001292 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001293 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294}
1295
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001296static inline int nfs4_lock_type(struct file_lock *fl, int block)
1297{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001298 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001299 return block ? NFS4_READW_LT : NFS4_READ_LT;
1300 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1301}
1302
1303static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1304{
1305 if (fl->fl_end == OFFSET_MAX)
1306 return ~(uint64_t)0;
1307 return fl->fl_end - fl->fl_start + 1;
1308}
1309
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001310static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1311{
1312 __be32 *p;
1313
Trond Myklebustd035c362010-12-21 10:45:27 -05001314 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001315 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001316 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001317 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001318 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001319 xdr_encode_hyper(p, lowner->id);
1320}
1321
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322/*
1323 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1324 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1325 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001326static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327{
Al Viro8687b632006-10-19 23:28:48 -07001328 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001330 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1331 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001332 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1333 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001334 p = xdr_encode_hyper(p, args->fl->fl_start);
1335 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001336 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001337 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001338 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001339 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001340 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001341 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 }
1343 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001344 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001345 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001349static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350{
Al Viro8687b632006-10-19 23:28:48 -07001351 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001353 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1354 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001355 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001356 p = xdr_encode_hyper(p, args->fl->fl_start);
1357 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001358 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359}
1360
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001361static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362{
Al Viro8687b632006-10-19 23:28:48 -07001363 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001365 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1366 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001367 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001368 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001369 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001370 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001371 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372}
1373
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001374static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1375{
Trond Myklebustab19b482012-03-04 18:13:57 -05001376 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001377 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001378}
1379
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001380static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381{
Trond Myklebustab19b482012-03-04 18:13:57 -05001382 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001383 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384}
1385
Jeff Layton5b5faaf2017-06-29 06:34:52 -07001386static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
1387{
1388 encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
1389}
1390
Trond Myklebust6ae37332015-01-30 14:21:14 -05001391static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392{
Al Viro8687b632006-10-19 23:28:48 -07001393 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Benny Halevy13c65ce2009-08-14 17:19:25 +03001395 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001396 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001397 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398}
1399
1400static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1401{
Al Viro8687b632006-10-19 23:28:48 -07001402 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 /*
1404 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1405 * owner 4 = 32
1406 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001407 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001408 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001409 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001410 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001411 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001412 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001413 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001414 *p++ = cpu_to_be32(arg->id.uniquifier);
1415 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416}
1417
1418static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1419{
Al Viro8687b632006-10-19 23:28:48 -07001420 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
Benny Halevy13c65ce2009-08-14 17:19:25 +03001422 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001423 switch(arg->createmode) {
1424 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001425 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001426 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1427 arg->server, arg->server->attr_bitmask);
Andy Adamson05d564f2008-12-23 16:06:15 -05001428 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001429 case NFS4_CREATE_GUARDED:
1430 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001431 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1432 arg->server, arg->server->attr_bitmask);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001433 break;
1434 case NFS4_CREATE_EXCLUSIVE:
1435 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1436 encode_nfs4_verifier(xdr, &arg->u.verifier);
1437 break;
1438 case NFS4_CREATE_EXCLUSIVE4_1:
1439 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1440 encode_nfs4_verifier(xdr, &arg->u.verifier);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001441 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1442 arg->server, arg->server->exclcreat_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 }
1444}
1445
1446static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1447{
Al Viro8687b632006-10-19 23:28:48 -07001448 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
Benny Halevy13c65ce2009-08-14 17:19:25 +03001450 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001452 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001453 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001454 break;
1455 default:
Benny Halevy34558512009-08-14 17:19:30 +03001456 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001457 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 }
1459}
1460
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001461static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462{
Al Viro8687b632006-10-19 23:28:48 -07001463 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Benny Halevy13c65ce2009-08-14 17:19:25 +03001465 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001467 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001468 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001469 break;
1470 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001471 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001472 break;
1473 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001474 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001475 break;
1476 default:
1477 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 }
1479}
1480
1481static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1482{
Al Viro8687b632006-10-19 23:28:48 -07001483 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
Benny Halevy13c65ce2009-08-14 17:19:25 +03001485 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001486 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 encode_string(xdr, name->len, name->name);
1488}
1489
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001490static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491{
Al Viro8687b632006-10-19 23:28:48 -07001492 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
Benny Halevy13c65ce2009-08-14 17:19:25 +03001494 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001495 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 encode_delegation_type(xdr, type);
1497}
1498
1499static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1500{
Al Viro8687b632006-10-19 23:28:48 -07001501 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001503 p = reserve_space(xdr, 4);
1504 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1505 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 encode_string(xdr, name->len, name->name);
1507}
1508
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001509static inline void encode_claim_fh(struct xdr_stream *xdr)
1510{
1511 __be32 *p;
1512
1513 p = reserve_space(xdr, 4);
1514 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1515}
1516
1517static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1518{
1519 __be32 *p;
1520
1521 p = reserve_space(xdr, 4);
1522 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1523 encode_nfs4_stateid(xdr, stateid);
1524}
1525
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001526static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527{
Trond Myklebustab19b482012-03-04 18:13:57 -05001528 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 encode_openhdr(xdr, arg);
1530 encode_opentype(xdr, arg);
1531 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001532 case NFS4_OPEN_CLAIM_NULL:
1533 encode_claim_null(xdr, arg->name);
1534 break;
1535 case NFS4_OPEN_CLAIM_PREVIOUS:
1536 encode_claim_previous(xdr, arg->u.delegation_type);
1537 break;
1538 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1539 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1540 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001541 case NFS4_OPEN_CLAIM_FH:
1542 encode_claim_fh(xdr);
1543 break;
1544 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1545 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1546 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001547 default:
1548 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550}
1551
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001552static 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 -07001553{
Trond Myklebustab19b482012-03-04 18:13:57 -05001554 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001555 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001556 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557}
1558
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001559static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560{
Trond Myklebustab19b482012-03-04 18:13:57 -05001561 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001562 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001563 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001564 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565}
1566
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001567static void
Andy Adamsond0179312008-12-23 16:06:17 -05001568encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569{
Trond Myklebustab19b482012-03-04 18:13:57 -05001570 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001571 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572}
1573
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001574static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575{
Trond Myklebustab19b482012-03-04 18:13:57 -05001576 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577}
1578
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001579static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1580 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581{
Al Viro8687b632006-10-19 23:28:48 -07001582 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
Trond Myklebustab19b482012-03-04 18:13:57 -05001584 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001585 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586
Benny Halevy13c65ce2009-08-14 17:19:25 +03001587 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001588 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001589 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590}
1591
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001592static 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 -07001593{
David Quigleyaa9c2662013-05-22 12:50:44 -04001594 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001595 FATTR4_WORD0_RDATTR_ERROR,
1596 FATTR4_WORD1_MOUNTED_ON_FILEID,
1597 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001598 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001599 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001600 uint32_t attrlen = 0;
1601 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001603 if (readdir->plus) {
1604 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001605 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001606 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1607 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1608 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1609 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001610 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001611 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001612 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001613 /* Use mounted_on_fileid only if the server supports it */
1614 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1615 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001616 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1617 attrs[i] &= readdir->bitmask[i];
1618 if (attrs[i] != 0)
1619 attrlen = i+1;
1620 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001621
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001622 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001623 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001624 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001625 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001626 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001627 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001628 *p++ = cpu_to_be32(attrlen);
1629 for (i = 0; i < attrlen; i++)
1630 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001631 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001632
1633 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001634 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001635 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001636 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001637 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001638 attrs[1] & readdir->bitmask[1],
1639 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640}
1641
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001642static 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 -07001643{
Trond Myklebustab19b482012-03-04 18:13:57 -05001644 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645}
1646
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001647static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648{
Trond Myklebustab19b482012-03-04 18:13:57 -05001649 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001650 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651}
1652
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001653static 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 -07001654{
Trond Myklebustab19b482012-03-04 18:13:57 -05001655 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001656 encode_string(xdr, oldname->len, oldname->name);
1657 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658}
1659
Chuck Leverbb4dae52012-03-01 17:01:48 -05001660static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1661 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001663 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001664 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665}
1666
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001667static void
Andy Adamsond0179312008-12-23 16:06:17 -05001668encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001669{
Trond Myklebustab19b482012-03-04 18:13:57 -05001670 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001671}
1672
Chuck Lever9f06c712010-12-14 14:59:18 +00001673static void
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001674encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1675 struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001676{
Al Viro8687b632006-10-19 23:28:48 -07001677 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001678
Trond Myklebustab19b482012-03-04 18:13:57 -05001679 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001680 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001681 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001682 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001683 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001684 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001685 *p = cpu_to_be32(arg->acl_len);
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01001686 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001687}
1688
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001689static void
Andy Adamsond0179312008-12-23 16:06:17 -05001690encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691{
Trond Myklebustab19b482012-03-04 18:13:57 -05001692 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693}
1694
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001695static 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 -07001696{
Trond Myklebustab19b482012-03-04 18:13:57 -05001697 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001698 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001699 encode_attrs(xdr, arg->iap, arg->label, NULL, server,
1700 server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701}
1702
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001703static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704{
Al Viro8687b632006-10-19 23:28:48 -07001705 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Trond Myklebust70019512012-03-04 20:49:32 -05001707 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001708 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
Jeff Layton3a6bb732015-06-09 19:43:57 -04001710 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1711 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001712 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001713 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1715 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001716 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001717 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718}
1719
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001720static 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 -07001721{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001722 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1723 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001724 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001725 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726}
1727
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001728static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1729 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730{
Al Viro8687b632006-10-19 23:28:48 -07001731 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
Trond Myklebustab19b482012-03-04 18:13:57 -05001733 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001734 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
Benny Halevy13c65ce2009-08-14 17:19:25 +03001736 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001737 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001738 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001739 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
1741 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742}
1743
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001744static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745{
Trond Myklebustab19b482012-03-04 18:13:57 -05001746 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001747 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001749
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001750static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1751{
Trond Myklebustab19b482012-03-04 18:13:57 -05001752 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001753 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001754}
1755
Benny Halevy99fe60d2009-04-01 09:22:29 -04001756#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001757/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001758static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001759 const struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001760 struct compound_hdr *hdr)
1761{
1762 __be32 *p;
1763
1764 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1765 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001766 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001767 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001768 *p++ = cpu_to_be32(args->dir);
1769 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001770}
1771
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001772static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001773{
1774 unsigned int i;
1775 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1776 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1777 encode_uint32(xdr, op_map->u.words[i]);
1778}
1779
Benny Halevy99fe60d2009-04-01 09:22:29 -04001780static void encode_exchange_id(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001781 const struct nfs41_exchange_id_args *args,
Benny Halevy99fe60d2009-04-01 09:22:29 -04001782 struct compound_hdr *hdr)
1783{
1784 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001785 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001786 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001787
Trond Myklebust70019512012-03-04 20:49:32 -05001788 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Trond Myklebustfd405592017-08-01 16:02:47 -04001789 encode_nfs4_verifier(xdr, &args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001790
Jeff Layton3a6bb732015-06-09 19:43:57 -04001791 encode_string(xdr, strlen(args->client->cl_owner_id),
1792 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001793
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001794 encode_uint32(xdr, args->flags);
1795 encode_uint32(xdr, args->state_protect.how);
1796
1797 switch (args->state_protect.how) {
1798 case SP4_NONE:
1799 break;
1800 case SP4_MACH_CRED:
1801 encode_op_map(xdr, &args->state_protect.enforce);
1802 encode_op_map(xdr, &args->state_protect.allow);
1803 break;
1804 default:
1805 WARN_ON_ONCE(1);
1806 break;
1807 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001808
1809 if (send_implementation_id &&
1810 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1811 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001812 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001813 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1814 utsname()->sysname, utsname()->release,
1815 utsname()->version, utsname()->machine);
1816
1817 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001818 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001819
1820 encode_string(xdr,
1821 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1822 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1823 encode_string(xdr, len, impl_name);
1824 /* just send zeros for nii_date - the date is in nii_name */
1825 p = reserve_space(xdr, 12);
1826 p = xdr_encode_hyper(p, 0);
1827 *p = cpu_to_be32(0);
1828 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001829 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001830}
Andy Adamsonfc931582009-04-01 09:22:31 -04001831
1832static void encode_create_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001833 const struct nfs41_create_session_args *args,
Andy Adamsonfc931582009-04-01 09:22:31 -04001834 struct compound_hdr *hdr)
1835{
1836 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001837 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001838 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001839 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001840 u32 max_resp_sz_cached;
1841
1842 /*
1843 * Assumes OPEN is the biggest non-idempotent compound.
1844 * 2 is the verifier.
1845 */
J. Bruce Fields35c036e2017-09-20 12:42:13 -04001846 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
1847 * XDR_UNIT + RPC_MAX_AUTH_SIZE;
Andy Adamsonfc931582009-04-01 09:22:31 -04001848
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001849 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001850 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001851 p = xdr_encode_hyper(p, args->clientid);
1852 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001853 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001854
Andy Adamsonfc931582009-04-01 09:22:31 -04001855 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001856 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001857 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1858 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001859 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001860 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1861 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1862 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001863
1864 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001865 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001866 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1867 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1868 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1869 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1870 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1871 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001872
Benny Halevye75bc1c2009-08-14 17:18:54 +03001873 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001874 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001875 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001876
1877 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001878 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001879 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001880 *p++ = cpu_to_be32(0); /* UID */
1881 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001882 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001883}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001884
1885static void encode_destroy_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001886 const struct nfs4_session *session,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001887 struct compound_hdr *hdr)
1888{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001889 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1890 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001891}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001892
Trond Myklebust66245532012-05-25 17:18:09 -04001893static void encode_destroy_clientid(struct xdr_stream *xdr,
1894 uint64_t clientid,
1895 struct compound_hdr *hdr)
1896{
1897 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1898 encode_uint64(xdr, clientid);
1899}
1900
Ricardo Labiaga180197532009-12-05 16:08:40 -05001901static void encode_reclaim_complete(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001902 const struct nfs41_reclaim_complete_args *args,
Ricardo Labiaga180197532009-12-05 16:08:40 -05001903 struct compound_hdr *hdr)
1904{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001905 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1906 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001907}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001908#endif /* CONFIG_NFS_V4_1 */
1909
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001910static void encode_sequence(struct xdr_stream *xdr,
1911 const struct nfs4_sequence_args *args,
1912 struct compound_hdr *hdr)
1913{
1914#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001915 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001916 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001917 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001918 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001919
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001920 tp = slot->table;
1921 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001922 if (!session)
1923 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001924
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001925 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001926
1927 /*
1928 * Sessionid + seqid + slotid + max slotid + cache_this
1929 */
1930 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1931 "max_slotid=%d cache_this=%d\n",
1932 __func__,
1933 ((u32 *)session->sess_id.data)[0],
1934 ((u32 *)session->sess_id.data)[1],
1935 ((u32 *)session->sess_id.data)[2],
1936 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001937 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001938 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001939 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001940 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001941 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001942 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001943 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001944 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001945#endif /* CONFIG_NFS_V4_1 */
1946}
1947
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001948#ifdef CONFIG_NFS_V4_1
1949static void
1950encode_getdeviceinfo(struct xdr_stream *xdr,
1951 const struct nfs4_getdeviceinfo_args *args,
1952 struct compound_hdr *hdr)
1953{
1954 __be32 *p;
1955
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001956 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001957 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001958 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1959 NFS4_DEVICEID4_SIZE);
1960 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001961 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001962
1963 p = reserve_space(xdr, 4 + 4);
1964 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001965 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001966}
1967
1968static void
1969encode_layoutget(struct xdr_stream *xdr,
1970 const struct nfs4_layoutget_args *args,
1971 struct compound_hdr *hdr)
1972{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001973 __be32 *p;
1974
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001975 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1976 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001977 *p++ = cpu_to_be32(0); /* Signal layout available */
1978 *p++ = cpu_to_be32(args->type);
1979 *p++ = cpu_to_be32(args->range.iomode);
1980 p = xdr_encode_hyper(p, args->range.offset);
1981 p = xdr_encode_hyper(p, args->range.length);
1982 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001983 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001984 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001985
1986 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1987 __func__,
1988 args->type,
1989 args->range.iomode,
1990 (unsigned long)args->range.offset,
1991 (unsigned long)args->range.length,
1992 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001993}
Andy Adamson863a3c62011-03-23 13:27:54 +00001994
1995static int
1996encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001997 struct inode *inode,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001998 const struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001999 struct compound_hdr *hdr)
2000{
2001 __be32 *p;
2002
2003 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2004 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2005
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002006 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2007 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00002008 /* Only whole file layouts */
2009 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002010 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002011 *p = cpu_to_be32(0); /* reclaim */
2012 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04002013 if (args->lastbytewritten != U64_MAX) {
2014 p = reserve_space(xdr, 20);
2015 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2016 p = xdr_encode_hyper(p, args->lastbytewritten);
2017 } else {
2018 p = reserve_space(xdr, 12);
2019 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2020 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002021 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2022 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002023
Trond Myklebust73504742017-04-20 16:48:14 -04002024 encode_uint32(xdr, args->layoutupdate_len);
2025 if (args->layoutupdate_pages)
2026 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2027 args->layoutupdate_len);
Andy Adamson863a3c62011-03-23 13:27:54 +00002028
Andy Adamson863a3c62011-03-23 13:27:54 +00002029 return 0;
2030}
Benny Halevycbe82602011-05-22 19:52:37 +03002031
2032static void
2033encode_layoutreturn(struct xdr_stream *xdr,
2034 const struct nfs4_layoutreturn_args *args,
2035 struct compound_hdr *hdr)
2036{
2037 __be32 *p;
2038
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002039 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2040 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002041 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2042 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002043 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002044 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002045 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002046 p = xdr_encode_hyper(p, args->range.offset);
2047 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002048 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002049 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002050 spin_unlock(&args->inode->i_lock);
Trond Myklebust4d796d72016-09-23 11:38:08 -04002051 if (args->ld_private->ops && args->ld_private->ops->encode)
2052 args->ld_private->ops->encode(xdr, args, args->ld_private);
Trond Myklebust94e5c572016-09-15 18:49:52 -04002053 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002054 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002055}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002056
2057static int
2058encode_secinfo_no_name(struct xdr_stream *xdr,
2059 const struct nfs41_secinfo_no_name_args *args,
2060 struct compound_hdr *hdr)
2061{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002062 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2063 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002064 return 0;
2065}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002066
2067static void encode_test_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002068 const struct nfs41_test_stateid_args *args,
Bryan Schumaker7d974792011-06-02 14:59:08 -04002069 struct compound_hdr *hdr)
2070{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002071 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2072 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002073 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002074}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002075
2076static void encode_free_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002077 const struct nfs41_free_stateid_args *args,
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002078 struct compound_hdr *hdr)
2079{
Trond Myklebustab19b482012-03-04 18:13:57 -05002080 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002081 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002082}
Trond Myklebustcf805162016-11-15 14:56:07 -05002083#else
2084static inline void
2085encode_layoutreturn(struct xdr_stream *xdr,
2086 const struct nfs4_layoutreturn_args *args,
2087 struct compound_hdr *hdr)
2088{
2089}
Fred Isaman56f487f2016-09-21 11:43:41 -04002090
2091static void
2092encode_layoutget(struct xdr_stream *xdr,
2093 const struct nfs4_layoutget_args *args,
2094 struct compound_hdr *hdr)
2095{
2096}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002097#endif /* CONFIG_NFS_V4_1 */
2098
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099/*
2100 * END OF "GENERIC" ENCODE ROUTINES.
2101 */
2102
Benny Halevy66cc0422009-04-01 09:22:10 -04002103static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2104{
2105#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002106 struct nfs4_session *session = args->sa_slot->table->session;
2107 if (session)
2108 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002109#endif /* CONFIG_NFS_V4_1 */
2110 return 0;
2111}
2112
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113/*
2114 * Encode an ACCESS request
2115 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002116static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002117 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002119 const struct nfs4_accessargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002121 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Chuck Lever9f06c712010-12-14 14:59:18 +00002124 encode_compound_hdr(xdr, req, &hdr);
2125 encode_sequence(xdr, &args->seq_args, &hdr);
2126 encode_putfh(xdr, args->fh, &hdr);
2127 encode_access(xdr, args->access, &hdr);
Trond Myklebust8bcbe7d2018-03-20 17:03:11 -04002128 if (args->bitmask)
2129 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002130 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131}
2132
2133/*
2134 * Encode LOOKUP request
2135 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002136static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002137 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002139 const struct nfs4_lookup_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002141 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
Chuck Lever9f06c712010-12-14 14:59:18 +00002144 encode_compound_hdr(xdr, req, &hdr);
2145 encode_sequence(xdr, &args->seq_args, &hdr);
2146 encode_putfh(xdr, args->dir_fh, &hdr);
2147 encode_lookup(xdr, args->name, &hdr);
2148 encode_getfh(xdr, &hdr);
2149 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002150 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151}
2152
2153/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07002154 * Encode LOOKUPP request
2155 */
2156static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
2157 const void *data)
2158{
2159 const struct nfs4_lookupp_arg *args = data;
2160 struct compound_hdr hdr = {
2161 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2162 };
2163
2164 encode_compound_hdr(xdr, req, &hdr);
2165 encode_sequence(xdr, &args->seq_args, &hdr);
2166 encode_putfh(xdr, args->fh, &hdr);
2167 encode_lookupp(xdr, &hdr);
2168 encode_getfh(xdr, &hdr);
2169 encode_getfattr(xdr, args->bitmask, &hdr);
2170 encode_nops(&hdr);
2171}
2172
2173/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 * Encode LOOKUP_ROOT request
2175 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002176static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2177 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002178 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002180 const struct nfs4_lookup_root_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002182 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184
Chuck Lever9f06c712010-12-14 14:59:18 +00002185 encode_compound_hdr(xdr, req, &hdr);
2186 encode_sequence(xdr, &args->seq_args, &hdr);
2187 encode_putrootfh(xdr, &hdr);
2188 encode_getfh(xdr, &hdr);
2189 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002190 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191}
2192
2193/*
2194 * Encode REMOVE request
2195 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002196static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002197 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002199 const struct nfs_removeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002201 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203
Chuck Lever9f06c712010-12-14 14:59:18 +00002204 encode_compound_hdr(xdr, req, &hdr);
2205 encode_sequence(xdr, &args->seq_args, &hdr);
2206 encode_putfh(xdr, args->fh, &hdr);
2207 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002208 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209}
2210
2211/*
2212 * Encode RENAME request
2213 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002214static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002215 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002217 const struct nfs_renameargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002219 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
Chuck Lever9f06c712010-12-14 14:59:18 +00002222 encode_compound_hdr(xdr, req, &hdr);
2223 encode_sequence(xdr, &args->seq_args, &hdr);
2224 encode_putfh(xdr, args->old_dir, &hdr);
2225 encode_savefh(xdr, &hdr);
2226 encode_putfh(xdr, args->new_dir, &hdr);
2227 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002228 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229}
2230
2231/*
2232 * Encode LINK request
2233 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002234static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002235 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002237 const struct nfs4_link_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002239 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
Chuck Lever9f06c712010-12-14 14:59:18 +00002242 encode_compound_hdr(xdr, req, &hdr);
2243 encode_sequence(xdr, &args->seq_args, &hdr);
2244 encode_putfh(xdr, args->fh, &hdr);
2245 encode_savefh(xdr, &hdr);
2246 encode_putfh(xdr, args->dir_fh, &hdr);
2247 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002248 encode_restorefh(xdr, &hdr);
2249 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002250 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251}
2252
2253/*
2254 * Encode CREATE request
2255 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002256static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002257 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002259 const struct nfs4_create_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002261 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263
Chuck Lever9f06c712010-12-14 14:59:18 +00002264 encode_compound_hdr(xdr, req, &hdr);
2265 encode_sequence(xdr, &args->seq_args, &hdr);
2266 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002267 encode_create(xdr, args, &hdr);
2268 encode_getfh(xdr, &hdr);
2269 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002270 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271}
2272
2273/*
2274 * Encode SYMLINK request
2275 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002276static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002277 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002279 const struct nfs4_create_arg *args = data;
2280
Chuck Lever9f06c712010-12-14 14:59:18 +00002281 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282}
2283
2284/*
2285 * Encode GETATTR request
2286 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002287static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002288 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002290 const struct nfs4_getattr_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002292 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
Chuck Lever9f06c712010-12-14 14:59:18 +00002295 encode_compound_hdr(xdr, req, &hdr);
2296 encode_sequence(xdr, &args->seq_args, &hdr);
2297 encode_putfh(xdr, args->fh, &hdr);
2298 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002299 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300}
2301
2302/*
2303 * Encode a CLOSE request
2304 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002305static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002306 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002308 const struct nfs_closeargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002309 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002310 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002311 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
Chuck Lever9f06c712010-12-14 14:59:18 +00002313 encode_compound_hdr(xdr, req, &hdr);
2314 encode_sequence(xdr, &args->seq_args, &hdr);
2315 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002316 if (args->lr_args)
2317 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002318 if (args->bitmask != NULL)
2319 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebustd8d84982016-12-19 12:14:44 -05002320 encode_close(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002321 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322}
2323
2324/*
2325 * Encode an OPEN request
2326 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002327static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002328 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002330 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002332 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334
Chuck Lever9f06c712010-12-14 14:59:18 +00002335 encode_compound_hdr(xdr, req, &hdr);
2336 encode_sequence(xdr, &args->seq_args, &hdr);
2337 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002338 encode_open(xdr, args, &hdr);
2339 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002340 if (args->access)
2341 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002342 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Fred Isaman56f487f2016-09-21 11:43:41 -04002343 if (args->lg_args) {
2344 encode_layoutget(xdr, args->lg_args, &hdr);
Chuck Levercf500ba2019-02-11 11:25:20 -05002345 rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2346 args->lg_args->layout.pglen,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05002347 hdr.replen - pagepad_maxsz);
Fred Isaman56f487f2016-09-21 11:43:41 -04002348 }
Andy Adamsond0179312008-12-23 16:06:17 -05002349 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350}
2351
2352/*
2353 * Encode an OPEN_CONFIRM request
2354 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002355static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2356 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002357 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002359 const struct nfs_open_confirmargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002361 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363
Chuck Lever9f06c712010-12-14 14:59:18 +00002364 encode_compound_hdr(xdr, req, &hdr);
2365 encode_putfh(xdr, args->fh, &hdr);
2366 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002367 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368}
2369
2370/*
2371 * Encode an OPEN request with no attributes.
2372 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002373static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2374 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002375 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002377 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002379 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
Chuck Lever9f06c712010-12-14 14:59:18 +00002382 encode_compound_hdr(xdr, req, &hdr);
2383 encode_sequence(xdr, &args->seq_args, &hdr);
2384 encode_putfh(xdr, args->fh, &hdr);
2385 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002386 if (args->access)
2387 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002388 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Fred Isaman56f487f2016-09-21 11:43:41 -04002389 if (args->lg_args) {
2390 encode_layoutget(xdr, args->lg_args, &hdr);
Chuck Levercf500ba2019-02-11 11:25:20 -05002391 rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2392 args->lg_args->layout.pglen,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05002393 hdr.replen - pagepad_maxsz);
Fred Isaman56f487f2016-09-21 11:43:41 -04002394 }
Andy Adamsond0179312008-12-23 16:06:17 -05002395 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396}
2397
2398/*
2399 * Encode an OPEN_DOWNGRADE request
2400 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002401static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2402 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002403 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002405 const struct nfs_closeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002407 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409
Chuck Lever9f06c712010-12-14 14:59:18 +00002410 encode_compound_hdr(xdr, req, &hdr);
2411 encode_sequence(xdr, &args->seq_args, &hdr);
2412 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustb6808142016-11-20 13:34:16 -05002413 if (args->lr_args)
2414 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002415 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002416 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417}
2418
2419/*
2420 * Encode a LOCK request
2421 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002422static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002423 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002425 const struct nfs_lock_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002427 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
Chuck Lever9f06c712010-12-14 14:59:18 +00002430 encode_compound_hdr(xdr, req, &hdr);
2431 encode_sequence(xdr, &args->seq_args, &hdr);
2432 encode_putfh(xdr, args->fh, &hdr);
2433 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002434 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435}
2436
2437/*
2438 * Encode a LOCKT request
2439 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002440static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002441 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002443 const struct nfs_lockt_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002445 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447
Chuck Lever9f06c712010-12-14 14:59:18 +00002448 encode_compound_hdr(xdr, req, &hdr);
2449 encode_sequence(xdr, &args->seq_args, &hdr);
2450 encode_putfh(xdr, args->fh, &hdr);
2451 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002452 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453}
2454
2455/*
2456 * Encode a LOCKU request
2457 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002458static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002459 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002461 const struct nfs_locku_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002463 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465
Chuck Lever9f06c712010-12-14 14:59:18 +00002466 encode_compound_hdr(xdr, req, &hdr);
2467 encode_sequence(xdr, &args->seq_args, &hdr);
2468 encode_putfh(xdr, args->fh, &hdr);
2469 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002470 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471}
2472
Chuck Lever9f06c712010-12-14 14:59:18 +00002473static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2474 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002475 const void *data)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002476{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002477 const struct nfs_release_lockowner_args *args = data;
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002478 struct compound_hdr hdr = {
2479 .minorversion = 0,
2480 };
2481
Chuck Lever9f06c712010-12-14 14:59:18 +00002482 encode_compound_hdr(xdr, req, &hdr);
2483 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002484 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002485}
2486
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487/*
2488 * Encode a READLINK request
2489 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002490static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002491 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002493 const struct nfs4_readlink *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002495 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
Chuck Lever9f06c712010-12-14 14:59:18 +00002498 encode_compound_hdr(xdr, req, &hdr);
2499 encode_sequence(xdr, &args->seq_args, &hdr);
2500 encode_putfh(xdr, args->fh, &hdr);
2501 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002502
Chuck Levercf500ba2019-02-11 11:25:20 -05002503 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05002504 args->pglen, hdr.replen - pagepad_maxsz);
Andy Adamsond0179312008-12-23 16:06:17 -05002505 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506}
2507
2508/*
2509 * Encode a READDIR request
2510 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002511static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002512 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002514 const struct nfs4_readdir_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002516 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
Chuck Lever9f06c712010-12-14 14:59:18 +00002519 encode_compound_hdr(xdr, req, &hdr);
2520 encode_sequence(xdr, &args->seq_args, &hdr);
2521 encode_putfh(xdr, args->fh, &hdr);
2522 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002523
Chuck Levercf500ba2019-02-11 11:25:20 -05002524 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05002525 args->count, hdr.replen - pagepad_maxsz);
Andy Adamsond0179312008-12-23 16:06:17 -05002526 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527}
2528
2529/*
2530 * Encode a READ request
2531 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002532static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002533 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002535 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002537 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539
Chuck Lever9f06c712010-12-14 14:59:18 +00002540 encode_compound_hdr(xdr, req, &hdr);
2541 encode_sequence(xdr, &args->seq_args, &hdr);
2542 encode_putfh(xdr, args->fh, &hdr);
2543 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544
Chuck Levercf500ba2019-02-11 11:25:20 -05002545 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05002546 args->count, hdr.replen - pagepad_maxsz);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002547 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002548 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549}
2550
2551/*
2552 * Encode an SETATTR request
2553 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002554static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002555 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002557 const struct nfs_setattrargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002558 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002559 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002560 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561
Chuck Lever9f06c712010-12-14 14:59:18 +00002562 encode_compound_hdr(xdr, req, &hdr);
2563 encode_sequence(xdr, &args->seq_args, &hdr);
2564 encode_putfh(xdr, args->fh, &hdr);
2565 encode_setattr(xdr, args, args->server, &hdr);
2566 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002567 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568}
2569
2570/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002571 * Encode a GETACL request
2572 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002573static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002574 const void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002575{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002576 const struct nfs_getaclargs *args = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002577 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002578 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002579 };
Trond Myklebust37c88762018-03-20 17:03:08 -04002580 const __u32 nfs4_acl_bitmap[1] = {
2581 [0] = FATTR4_WORD0_ACL,
2582 };
Benny Halevy28f56692009-04-01 09:22:09 -04002583 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002584
Chuck Lever9f06c712010-12-14 14:59:18 +00002585 encode_compound_hdr(xdr, req, &hdr);
2586 encode_sequence(xdr, &args->seq_args, &hdr);
2587 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fields6682c142017-02-23 14:53:39 -05002588 replen = hdr.replen + op_decode_hdr_maxsz;
Trond Myklebust37c88762018-03-20 17:03:08 -04002589 encode_getattr(xdr, nfs4_acl_bitmap, NULL,
2590 ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002591
Chuck Levercf500ba2019-02-11 11:25:20 -05002592 rpc_prepare_reply_pages(req, args->acl_pages, 0,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05002593 args->acl_len, replen);
Andy Adamsond0179312008-12-23 16:06:17 -05002594 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002595}
2596
2597/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 * Encode a WRITE request
2599 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002600static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002601 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002603 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002605 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607
Chuck Lever9f06c712010-12-14 14:59:18 +00002608 encode_compound_hdr(xdr, req, &hdr);
2609 encode_sequence(xdr, &args->seq_args, &hdr);
2610 encode_putfh(xdr, args->fh, &hdr);
2611 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002612 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002613 if (args->bitmask)
2614 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002615 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616}
2617
2618/*
2619 * a COMMIT request
2620 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002621static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002622 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002624 const struct nfs_commitargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002626 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628
Chuck Lever9f06c712010-12-14 14:59:18 +00002629 encode_compound_hdr(xdr, req, &hdr);
2630 encode_sequence(xdr, &args->seq_args, &hdr);
2631 encode_putfh(xdr, args->fh, &hdr);
2632 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002633 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634}
2635
2636/*
2637 * FSINFO request
2638 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002639static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002640 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002642 const struct nfs4_fsinfo_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002644 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646
Chuck Lever9f06c712010-12-14 14:59:18 +00002647 encode_compound_hdr(xdr, req, &hdr);
2648 encode_sequence(xdr, &args->seq_args, &hdr);
2649 encode_putfh(xdr, args->fh, &hdr);
2650 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002651 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652}
2653
2654/*
2655 * a PATHCONF request
2656 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002657static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002658 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002660 const struct nfs4_pathconf_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002662 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
Chuck Lever9f06c712010-12-14 14:59:18 +00002665 encode_compound_hdr(xdr, req, &hdr);
2666 encode_sequence(xdr, &args->seq_args, &hdr);
2667 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002668 encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
2669 ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002670 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671}
2672
2673/*
2674 * a STATFS request
2675 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002676static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002677 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002679 const struct nfs4_statfs_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002681 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683
Chuck Lever9f06c712010-12-14 14:59:18 +00002684 encode_compound_hdr(xdr, req, &hdr);
2685 encode_sequence(xdr, &args->seq_args, &hdr);
2686 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002687 encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
2688 ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002689 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690}
2691
2692/*
2693 * GETATTR_BITMAP request
2694 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002695static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2696 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002697 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002699 const struct nfs4_server_caps_arg *args = data;
Kinglong Mee8c612822015-08-26 21:12:58 +08002700 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002702 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704
Chuck Lever9f06c712010-12-14 14:59:18 +00002705 encode_compound_hdr(xdr, req, &hdr);
2706 encode_sequence(xdr, &args->seq_args, &hdr);
2707 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002708 encode_getattr(xdr, bitmask, NULL, 3, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002709 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710}
2711
2712/*
2713 * a RENEW request
2714 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002715static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002716 const void *data)
2717
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002719 const struct nfs_client *clp = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002721 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 };
2723
Chuck Lever9f06c712010-12-14 14:59:18 +00002724 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002725 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002726 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727}
2728
2729/*
2730 * a SETCLIENTID request
2731 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002732static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2733 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002734 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002736 const struct nfs4_setclientid *sc = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002738 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 };
2740
Chuck Lever9f06c712010-12-14 14:59:18 +00002741 encode_compound_hdr(xdr, req, &hdr);
2742 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002743 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744}
2745
2746/*
2747 * a SETCLIENTID_CONFIRM request
2748 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002749static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2750 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002751 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002753 const struct nfs4_setclientid_res *arg = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002755 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757
Chuck Lever9f06c712010-12-14 14:59:18 +00002758 encode_compound_hdr(xdr, req, &hdr);
2759 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002760 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761}
2762
2763/*
2764 * DELEGRETURN request
2765 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002766static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2767 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002768 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002770 const struct nfs4_delegreturnargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002772 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774
Chuck Lever9f06c712010-12-14 14:59:18 +00002775 encode_compound_hdr(xdr, req, &hdr);
2776 encode_sequence(xdr, &args->seq_args, &hdr);
2777 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust586f1c32016-11-15 15:03:33 -05002778 if (args->lr_args)
2779 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05002780 if (args->bitmask)
2781 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002782 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002783 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784}
2785
2786/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002787 * Encode FS_LOCATIONS request
2788 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002789static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2790 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002791 const void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002792{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002793 const struct nfs4_fs_locations_arg *args = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002794 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002795 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002796 };
Benny Halevy28f56692009-04-01 09:22:09 -04002797 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002798
Chuck Lever9f06c712010-12-14 14:59:18 +00002799 encode_compound_hdr(xdr, req, &hdr);
2800 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002801 if (args->migration) {
2802 encode_putfh(xdr, args->fh, &hdr);
2803 replen = hdr.replen;
2804 encode_fs_locations(xdr, args->bitmask, &hdr);
2805 if (args->renew)
2806 encode_renew(xdr, args->clientid, &hdr);
2807 } else {
2808 encode_putfh(xdr, args->dir_fh, &hdr);
2809 encode_lookup(xdr, args->name, &hdr);
2810 replen = hdr.replen;
2811 encode_fs_locations(xdr, args->bitmask, &hdr);
2812 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002813
Chuck Levercf500ba2019-02-11 11:25:20 -05002814 rpc_prepare_reply_pages(req, (struct page **)&args->page, 0,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05002815 PAGE_SIZE, replen);
Andy Adamsond0179312008-12-23 16:06:17 -05002816 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002817}
2818
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002819/*
2820 * Encode SECINFO request
2821 */
2822static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2823 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002824 const void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002825{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002826 const struct nfs4_secinfo_arg *args = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002827 struct compound_hdr hdr = {
2828 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2829 };
2830
2831 encode_compound_hdr(xdr, req, &hdr);
2832 encode_sequence(xdr, &args->seq_args, &hdr);
2833 encode_putfh(xdr, args->dir_fh, &hdr);
2834 encode_secinfo(xdr, args->name, &hdr);
2835 encode_nops(&hdr);
2836}
2837
Chuck Lever44c99932013-10-17 14:13:30 -04002838/*
2839 * Encode FSID_PRESENT request
2840 */
2841static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2842 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002843 const void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04002844{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002845 const struct nfs4_fsid_present_arg *args = data;
Chuck Lever44c99932013-10-17 14:13:30 -04002846 struct compound_hdr hdr = {
2847 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2848 };
2849
2850 encode_compound_hdr(xdr, req, &hdr);
2851 encode_sequence(xdr, &args->seq_args, &hdr);
2852 encode_putfh(xdr, args->fh, &hdr);
2853 encode_getfh(xdr, &hdr);
2854 if (args->renew)
2855 encode_renew(xdr, args->clientid, &hdr);
2856 encode_nops(&hdr);
2857}
2858
Benny Halevy99fe60d2009-04-01 09:22:29 -04002859#if defined(CONFIG_NFS_V4_1)
2860/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002861 * BIND_CONN_TO_SESSION request
2862 */
2863static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2864 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002865 const void *data)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002866{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002867 const struct nfs41_bind_conn_to_session_args *args = data;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002868 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002869 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002870 };
2871
2872 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002873 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002874 encode_nops(&hdr);
2875}
2876
2877/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002878 * EXCHANGE_ID request
2879 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002880static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2881 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002882 const void *data)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002883{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002884 const struct nfs41_exchange_id_args *args = data;
Benny Halevy99fe60d2009-04-01 09:22:29 -04002885 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002886 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002887 };
2888
Chuck Lever9f06c712010-12-14 14:59:18 +00002889 encode_compound_hdr(xdr, req, &hdr);
2890 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002891 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002892}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002893
2894/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002895 * a CREATE_SESSION request
2896 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002897static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2898 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002899 const void *data)
Andy Adamsonfc931582009-04-01 09:22:31 -04002900{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002901 const struct nfs41_create_session_args *args = data;
Andy Adamsonfc931582009-04-01 09:22:31 -04002902 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002903 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002904 };
2905
Chuck Lever9f06c712010-12-14 14:59:18 +00002906 encode_compound_hdr(xdr, req, &hdr);
2907 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002908 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002909}
2910
2911/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002912 * a DESTROY_SESSION request
2913 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002914static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2915 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002916 const void *data)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002917{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002918 const struct nfs4_session *session = data;
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002919 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002920 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002921 };
2922
Chuck Lever9f06c712010-12-14 14:59:18 +00002923 encode_compound_hdr(xdr, req, &hdr);
2924 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002925 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002926}
2927
2928/*
Trond Myklebust66245532012-05-25 17:18:09 -04002929 * a DESTROY_CLIENTID request
2930 */
2931static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2932 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002933 const void *data)
Trond Myklebust66245532012-05-25 17:18:09 -04002934{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002935 const struct nfs_client *clp = data;
Trond Myklebust66245532012-05-25 17:18:09 -04002936 struct compound_hdr hdr = {
2937 .minorversion = clp->cl_mvops->minor_version,
2938 };
2939
2940 encode_compound_hdr(xdr, req, &hdr);
2941 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2942 encode_nops(&hdr);
2943}
2944
2945/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002946 * a SEQUENCE request
2947 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002948static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002949 const void *data)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002950{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002951 const struct nfs4_sequence_args *args = data;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002952 struct compound_hdr hdr = {
2953 .minorversion = nfs4_xdr_minorversion(args),
2954 };
2955
Chuck Lever9f06c712010-12-14 14:59:18 +00002956 encode_compound_hdr(xdr, req, &hdr);
2957 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002958 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002959}
2960
Donald Buczek0efb01b2019-07-07 21:26:08 +02002961#endif
2962
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002963/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002964 * a GET_LEASE_TIME request
2965 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002966static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2967 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002968 const void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002969{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002970 const struct nfs4_get_lease_time_args *args = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04002971 struct compound_hdr hdr = {
2972 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2973 };
Fred Isamandae100c2011-07-30 20:52:37 -04002974 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002975
Chuck Lever9f06c712010-12-14 14:59:18 +00002976 encode_compound_hdr(xdr, req, &hdr);
2977 encode_sequence(xdr, &args->la_seq_args, &hdr);
2978 encode_putrootfh(xdr, &hdr);
2979 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002980 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002981}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002982
Donald Buczek0efb01b2019-07-07 21:26:08 +02002983#ifdef CONFIG_NFS_V4_1
2984
Ricardo Labiaga180197532009-12-05 16:08:40 -05002985/*
2986 * a RECLAIM_COMPLETE request
2987 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002988static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2989 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002990 const void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002991{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002992 const struct nfs41_reclaim_complete_args *args = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05002993 struct compound_hdr hdr = {
2994 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2995 };
2996
Chuck Lever9f06c712010-12-14 14:59:18 +00002997 encode_compound_hdr(xdr, req, &hdr);
2998 encode_sequence(xdr, &args->seq_args, &hdr);
2999 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05003000 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05003001}
3002
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003003/*
3004 * Encode GETDEVICEINFO request
3005 */
Chuck Lever9f06c712010-12-14 14:59:18 +00003006static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
3007 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003008 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003009{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003010 const struct nfs4_getdeviceinfo_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003011 struct compound_hdr hdr = {
3012 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3013 };
Trond Myklebust046e5cc2020-11-13 21:42:16 -05003014 uint32_t replen;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003015
Chuck Lever9f06c712010-12-14 14:59:18 +00003016 encode_compound_hdr(xdr, req, &hdr);
3017 encode_sequence(xdr, &args->seq_args, &hdr);
Trond Myklebust046e5cc2020-11-13 21:42:16 -05003018
Trond Myklebust9ed5af262020-11-21 20:46:18 -05003019 replen = hdr.replen + op_decode_hdr_maxsz + 2;
Trond Myklebust046e5cc2020-11-13 21:42:16 -05003020
Chuck Lever9f06c712010-12-14 14:59:18 +00003021 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003022
Trond Myklebust046e5cc2020-11-13 21:42:16 -05003023 /* set up reply kvec. device_addr4 opaque data is read into the
3024 * pages */
Chuck Levercf500ba2019-02-11 11:25:20 -05003025 rpc_prepare_reply_pages(req, args->pdev->pages, args->pdev->pgbase,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05003026 args->pdev->pglen, replen);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003027 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003028}
3029
3030/*
3031 * Encode LAYOUTGET request
3032 */
Chuck Lever9f06c712010-12-14 14:59:18 +00003033static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
3034 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003035 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003036{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003037 const struct nfs4_layoutget_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003038 struct compound_hdr hdr = {
3039 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3040 };
3041
Chuck Lever9f06c712010-12-14 14:59:18 +00003042 encode_compound_hdr(xdr, req, &hdr);
3043 encode_sequence(xdr, &args->seq_args, &hdr);
3044 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3045 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04003046
Chuck Levercf500ba2019-02-11 11:25:20 -05003047 rpc_prepare_reply_pages(req, args->layout.pages, 0,
Trond Myklebust9ed5af262020-11-21 20:46:18 -05003048 args->layout.pglen, hdr.replen - pagepad_maxsz);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003049 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003050}
Andy Adamson863a3c62011-03-23 13:27:54 +00003051
3052/*
3053 * Encode LAYOUTCOMMIT request
3054 */
Benny Halevycbe82602011-05-22 19:52:37 +03003055static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3056 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003057 const void *priv)
Andy Adamson863a3c62011-03-23 13:27:54 +00003058{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003059 const struct nfs4_layoutcommit_args *args = priv;
Benny Halevyac7db722011-05-22 19:53:48 +03003060 struct nfs4_layoutcommit_data *data =
3061 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00003062 struct compound_hdr hdr = {
3063 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3064 };
3065
3066 encode_compound_hdr(xdr, req, &hdr);
3067 encode_sequence(xdr, &args->seq_args, &hdr);
3068 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03003069 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003070 encode_getfattr(xdr, args->bitmask, &hdr);
3071 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03003072}
3073
3074/*
3075 * Encode LAYOUTRETURN request
3076 */
3077static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3078 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003079 const void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03003080{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003081 const struct nfs4_layoutreturn_args *args = data;
Benny Halevycbe82602011-05-22 19:52:37 +03003082 struct compound_hdr hdr = {
3083 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3084 };
3085
3086 encode_compound_hdr(xdr, req, &hdr);
3087 encode_sequence(xdr, &args->seq_args, &hdr);
3088 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3089 encode_layoutreturn(xdr, args, &hdr);
3090 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003091}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003092
3093/*
3094 * Encode SECINFO_NO_NAME request
3095 */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003096static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003097 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003098 const void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003099{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003100 const struct nfs41_secinfo_no_name_args *args = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003101 struct compound_hdr hdr = {
3102 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3103 };
3104
3105 encode_compound_hdr(xdr, req, &hdr);
3106 encode_sequence(xdr, &args->seq_args, &hdr);
3107 encode_putrootfh(xdr, &hdr);
3108 encode_secinfo_no_name(xdr, args, &hdr);
3109 encode_nops(&hdr);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003110}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003111
3112/*
3113 * Encode TEST_STATEID request
3114 */
3115static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3116 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003117 const void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04003118{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003119 const struct nfs41_test_stateid_args *args = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04003120 struct compound_hdr hdr = {
3121 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3122 };
3123
3124 encode_compound_hdr(xdr, req, &hdr);
3125 encode_sequence(xdr, &args->seq_args, &hdr);
3126 encode_test_stateid(xdr, args, &hdr);
3127 encode_nops(&hdr);
3128}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003129
3130/*
3131 * Encode FREE_STATEID request
3132 */
3133static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3134 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003135 const void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003136{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003137 const struct nfs41_free_stateid_args *args = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003138 struct compound_hdr hdr = {
3139 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3140 };
3141
3142 encode_compound_hdr(xdr, req, &hdr);
3143 encode_sequence(xdr, &args->seq_args, &hdr);
3144 encode_free_stateid(xdr, args, &hdr);
3145 encode_nops(&hdr);
3146}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003147#endif /* CONFIG_NFS_V4_1 */
3148
Trond Myklebust683b57b2006-06-09 09:34:22 -04003149static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150{
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003151 ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3152 NFS4_OPAQUE_LIMIT);
Chuck Levereb72f482019-02-11 11:24:21 -05003153 if (unlikely(ret < 0))
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003154 return -EIO;
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003155 *len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 return 0;
3157}
3158
3159static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3160{
Al Viro8687b632006-10-19 23:28:48 -07003161 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162
Benny Halevyc0eae662009-08-14 17:20:14 +03003163 p = xdr_inline_decode(xdr, 8);
3164 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003165 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03003166 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003167 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003168
Benny Halevyc0eae662009-08-14 17:20:14 +03003169 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3170 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003171 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 hdr->tag = (char *)p;
3173 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003174 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003175 if (unlikely(hdr->nops < 1))
3176 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 return 0;
3178}
3179
Trond Myklebustc7848f62013-12-04 17:39:23 -05003180static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3181 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182{
Al Viro8687b632006-10-19 23:28:48 -07003183 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 uint32_t opnum;
3185 int32_t nfserr;
3186
Benny Halevyc0eae662009-08-14 17:20:14 +03003187 p = xdr_inline_decode(xdr, 8);
3188 if (unlikely(!p))
3189 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003190 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003191 if (unlikely(opnum != expected))
3192 goto out_bad_operation;
Chuck Leverf23f6582019-02-11 11:24:26 -05003193 if (unlikely(*p != cpu_to_be32(NFS_OK)))
3194 goto out_status;
3195 *nfs_retval = 0;
3196 return true;
3197out_status:
Benny Halevycccddf42009-08-14 17:20:19 +03003198 nfserr = be32_to_cpup(p);
Chuck Lever62a92ba2019-06-19 10:34:09 -04003199 trace_nfs4_xdr_status(xdr, opnum, nfserr);
Chuck Leverf23f6582019-02-11 11:24:26 -05003200 *nfs_retval = nfs4_stat_to_errno(nfserr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003201 return true;
3202out_bad_operation:
3203 dprintk("nfs: Server returned operation"
3204 " %d but we issued a request for %d\n",
3205 opnum, expected);
3206 *nfs_retval = -EREMOTEIO;
3207 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003208out_overflow:
Trond Myklebustc7848f62013-12-04 17:39:23 -05003209 *nfs_retval = -EIO;
3210 return false;
3211}
3212
3213static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3214{
3215 int retval;
3216
3217 __decode_op_hdr(xdr, expected, &retval);
3218 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219}
3220
3221/* Dummy routine */
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05003222static int decode_ace(struct xdr_stream *xdr, void *ace)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223{
Al Viro8687b632006-10-19 23:28:48 -07003224 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003225 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 char *str;
3227
Benny Halevyc0eae662009-08-14 17:20:14 +03003228 p = xdr_inline_decode(xdr, 12);
Chuck Levereb72f482019-02-11 11:24:21 -05003229 if (unlikely(!p))
3230 return -EIO;
3231 return decode_opaque_inline(xdr, &strlen, &str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232}
3233
Trond Myklebust37c88762018-03-20 17:03:08 -04003234static ssize_t
3235decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236{
Trond Myklebust37c88762018-03-20 17:03:08 -04003237 ssize_t ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238
Trond Myklebust37c88762018-03-20 17:03:08 -04003239 ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
3240 if (likely(ret >= 0))
3241 return ret;
Chuck Levereb72f482019-02-11 11:24:21 -05003242 if (ret != -EMSGSIZE)
3243 return -EIO;
3244 return sz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245}
3246
Trond Myklebust37c88762018-03-20 17:03:08 -04003247static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3248{
3249 ssize_t ret;
3250 ret = decode_bitmap4(xdr, bitmap, 3);
3251 return ret < 0 ? ret : 0;
3252}
3253
Trond Myklebust256e48b2012-06-21 11:18:13 -04003254static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255{
Al Viro8687b632006-10-19 23:28:48 -07003256 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257
Benny Halevyc0eae662009-08-14 17:20:14 +03003258 p = xdr_inline_decode(xdr, 4);
3259 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003260 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003261 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003262 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 return 0;
3264}
3265
3266static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3267{
3268 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003269 int ret;
3270 ret = decode_attr_bitmap(xdr, bitmask);
3271 if (unlikely(ret < 0))
3272 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3274 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003275 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3276 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3277 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 return 0;
3279}
3280
3281static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3282{
Al Viro8687b632006-10-19 23:28:48 -07003283 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003284 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285
3286 *type = 0;
3287 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3288 return -EIO;
3289 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003290 p = xdr_inline_decode(xdr, 4);
3291 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003292 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003293 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003295 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 return -EIO;
3297 }
3298 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003299 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003301 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003302 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303}
3304
Chuck Lever264e6352012-03-01 17:02:05 -05003305static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3306 uint32_t *bitmap, uint32_t *type)
3307{
3308 __be32 *p;
3309
3310 *type = 0;
3311 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3312 return -EIO;
3313 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3314 p = xdr_inline_decode(xdr, 4);
3315 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003316 return -EIO;
Chuck Lever264e6352012-03-01 17:02:05 -05003317 *type = be32_to_cpup(p);
3318 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3319 }
3320 dprintk("%s: expire type=0x%x\n", __func__, *type);
3321 return 0;
Chuck Lever264e6352012-03-01 17:02:05 -05003322}
3323
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3325{
Al Viro8687b632006-10-19 23:28:48 -07003326 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003327 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328
3329 *change = 0;
3330 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3331 return -EIO;
3332 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003333 p = xdr_inline_decode(xdr, 8);
3334 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003335 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003336 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003338 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003340 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003342 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343}
3344
3345static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3346{
Al Viro8687b632006-10-19 23:28:48 -07003347 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003348 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349
3350 *size = 0;
3351 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3352 return -EIO;
3353 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003354 p = xdr_inline_decode(xdr, 8);
3355 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003356 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003357 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003359 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003361 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003362 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363}
3364
3365static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3366{
Al Viro8687b632006-10-19 23:28:48 -07003367 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368
3369 *res = 0;
3370 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3371 return -EIO;
3372 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003373 p = xdr_inline_decode(xdr, 4);
3374 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003375 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003376 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3378 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003379 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 return 0;
3381}
3382
3383static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3384{
Al Viro8687b632006-10-19 23:28:48 -07003385 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386
3387 *res = 0;
3388 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3389 return -EIO;
3390 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003391 p = xdr_inline_decode(xdr, 4);
3392 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003393 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003394 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3396 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003397 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 return 0;
3399}
3400
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003401static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402{
Al Viro8687b632006-10-19 23:28:48 -07003403 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003404 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405
3406 fsid->major = 0;
3407 fsid->minor = 0;
3408 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3409 return -EIO;
3410 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003411 p = xdr_inline_decode(xdr, 16);
3412 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003413 return -EIO;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003414 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003415 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003417 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003419 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 (unsigned long long)fsid->major,
3421 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003422 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423}
3424
3425static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3426{
Al Viro8687b632006-10-19 23:28:48 -07003427 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428
3429 *res = 60;
3430 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3431 return -EIO;
3432 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003433 p = xdr_inline_decode(xdr, 4);
3434 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003435 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003436 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3438 }
Donald Buczek2eaf4262019-07-07 21:26:07 +02003439 dprintk("%s: lease time=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440 return 0;
3441}
3442
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003443static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003444{
3445 __be32 *p;
3446
3447 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3448 return -EIO;
3449 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3450 p = xdr_inline_decode(xdr, 4);
3451 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003452 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003453 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003454 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003455 }
3456 return 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003457}
3458
Kinglong Mee8c612822015-08-26 21:12:58 +08003459static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3460 uint32_t *bitmap, uint32_t *bitmask)
3461{
3462 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3463 int ret;
3464 ret = decode_attr_bitmap(xdr, bitmask);
3465 if (unlikely(ret < 0))
3466 return ret;
3467 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3468 } else
3469 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3470 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3471 bitmask[0], bitmask[1], bitmask[2]);
3472 return 0;
3473}
3474
Bryan Schumakerae42c702010-10-21 16:33:17 -04003475static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3476{
3477 __be32 *p;
Frank Sorenson86bbd742018-10-23 10:34:57 -05003478 u32 len;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003479
Trond Myklebust7ad07352010-10-23 15:34:20 -04003480 if (fh != NULL)
3481 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003482
3483 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3484 return -EIO;
3485 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3486 p = xdr_inline_decode(xdr, 4);
3487 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003488 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003489 len = be32_to_cpup(p);
3490 if (len > NFS4_FHSIZE)
3491 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003492 p = xdr_inline_decode(xdr, len);
3493 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003494 return -EIO;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003495 if (fh != NULL) {
3496 memcpy(fh->data, p, len);
3497 fh->size = len;
3498 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003499 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3500 }
3501 return 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003502}
3503
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3505{
Al Viro8687b632006-10-19 23:28:48 -07003506 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003508 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3510 return -EIO;
3511 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003512 p = xdr_inline_decode(xdr, 4);
3513 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003514 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003515 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3517 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003518 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 return 0;
3520}
3521
3522static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3523{
Al Viro8687b632006-10-19 23:28:48 -07003524 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003525 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526
3527 *fileid = 0;
3528 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3529 return -EIO;
3530 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003531 p = xdr_inline_decode(xdr, 8);
3532 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003533 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003534 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003536 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003538 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003539 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540}
3541
Manoj Naik99baf622006-06-09 09:34:24 -04003542static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3543{
Al Viro8687b632006-10-19 23:28:48 -07003544 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003545 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003546
3547 *fileid = 0;
3548 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3549 return -EIO;
3550 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003551 p = xdr_inline_decode(xdr, 8);
3552 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003553 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003554 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003555 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003556 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003557 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003558 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003559 return ret;
Manoj Naik99baf622006-06-09 09:34:24 -04003560}
3561
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3563{
Al Viro8687b632006-10-19 23:28:48 -07003564 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565 int status = 0;
3566
3567 *res = 0;
3568 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3569 return -EIO;
3570 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003571 p = xdr_inline_decode(xdr, 8);
3572 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003573 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003574 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3576 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003577 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 return status;
3579}
3580
3581static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3582{
Al Viro8687b632006-10-19 23:28:48 -07003583 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584 int status = 0;
3585
3586 *res = 0;
3587 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3588 return -EIO;
3589 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003590 p = xdr_inline_decode(xdr, 8);
3591 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003592 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003593 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3595 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003596 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597 return status;
3598}
3599
3600static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3601{
Al Viro8687b632006-10-19 23:28:48 -07003602 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 int status = 0;
3604
3605 *res = 0;
3606 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3607 return -EIO;
3608 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003609 p = xdr_inline_decode(xdr, 8);
3610 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003611 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003612 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3614 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003615 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003616 return status;
3617}
3618
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003619static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3620{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003621 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003622 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003623 int status = 0;
3624
Benny Halevyc0eae662009-08-14 17:20:14 +03003625 p = xdr_inline_decode(xdr, 4);
3626 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003627 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003628 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003629 if (n == 0)
3630 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003631 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003632 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3633 dprintk("cannot parse %d components in path\n", n);
3634 goto out_eio;
3635 }
3636 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003637 struct nfs4_string *component = &path->components[path->ncomponents];
3638 status = decode_opaque_inline(xdr, &component->len, &component->data);
3639 if (unlikely(status != 0))
3640 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003641 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003642 pr_cont("%s%.*s ",
3643 (path->ncomponents != n ? "/ " : ""),
3644 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003645 }
3646out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003647 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003648root_path:
3649/* a root pathname is sent as a zero component4 */
3650 path->ncomponents = 1;
3651 path->components[0].len=0;
3652 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003653 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003654 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003655out_eio:
3656 dprintk(" status %d", status);
3657 status = -EIO;
3658 goto out;
3659}
3660
3661static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003662{
3663 int n;
Al Viro8687b632006-10-19 23:28:48 -07003664 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003665 int status = -EIO;
3666
3667 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3668 goto out;
3669 status = 0;
3670 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3671 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003672 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003673 status = -EIO;
3674 /* Ignore borken servers that return unrequested attrs */
3675 if (unlikely(res == NULL))
3676 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003677 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003678 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003679 if (unlikely(status != 0))
3680 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003681 p = xdr_inline_decode(xdr, 4);
3682 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003683 goto out_eio;
Benny Halevycccddf42009-08-14 17:20:19 +03003684 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003685 if (n <= 0)
3686 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003687 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003688 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003689 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003690
Trond Myklebust809b4262013-03-27 11:54:45 -04003691 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3692 break;
3693 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003694 p = xdr_inline_decode(xdr, 4);
3695 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003696 goto out_eio;
Benny Halevycccddf42009-08-14 17:20:19 +03003697 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003698
Chuck Lever02a29762012-03-01 17:00:31 -05003699 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003700 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3701 struct nfs4_string *server;
3702
3703 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003704 unsigned int i;
3705 dprintk("%s: using first %u of %u servers "
3706 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003707 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003708 NFS4_FS_LOCATION_MAXSERVERS,
3709 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003710 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003711 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003712 char *data;
3713 status = decode_opaque_inline(xdr, &len, &data);
3714 if (unlikely(status != 0))
3715 goto out_eio;
3716 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003717 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003718 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003719 server = &loc->servers[loc->nservers];
3720 status = decode_opaque_inline(xdr, &server->len, &server->data);
3721 if (unlikely(status != 0))
3722 goto out_eio;
3723 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003724 }
3725 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003726 if (unlikely(status != 0))
3727 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003728 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003729 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003730 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003731out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003732 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003733 return status;
3734out_eio:
3735 status = -EIO;
3736 goto out;
3737}
3738
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3740{
Al Viro8687b632006-10-19 23:28:48 -07003741 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 int status = 0;
3743
3744 *res = 0;
3745 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3746 return -EIO;
3747 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003748 p = xdr_inline_decode(xdr, 8);
3749 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003750 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003751 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3753 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003754 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 return status;
3756}
3757
3758static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3759{
Al Viro8687b632006-10-19 23:28:48 -07003760 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 int status = 0;
3762
3763 *maxlink = 1;
3764 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3765 return -EIO;
3766 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003767 p = xdr_inline_decode(xdr, 4);
3768 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003769 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003770 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3772 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003773 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774 return status;
3775}
3776
3777static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3778{
Al Viro8687b632006-10-19 23:28:48 -07003779 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780 int status = 0;
3781
3782 *maxname = 1024;
3783 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3784 return -EIO;
3785 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003786 p = xdr_inline_decode(xdr, 4);
3787 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003788 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003789 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3791 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003792 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 return status;
3794}
3795
3796static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3797{
Al Viro8687b632006-10-19 23:28:48 -07003798 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799 int status = 0;
3800
3801 *res = 1024;
3802 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3803 return -EIO;
3804 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3805 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003806 p = xdr_inline_decode(xdr, 8);
3807 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003808 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003809 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 if (maxread > 0x7FFFFFFF)
3811 maxread = 0x7FFFFFFF;
3812 *res = (uint32_t)maxread;
3813 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3814 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003815 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 return status;
3817}
3818
3819static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3820{
Al Viro8687b632006-10-19 23:28:48 -07003821 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 int status = 0;
3823
3824 *res = 1024;
3825 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3826 return -EIO;
3827 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3828 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003829 p = xdr_inline_decode(xdr, 8);
3830 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003831 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003832 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 if (maxwrite > 0x7FFFFFFF)
3834 maxwrite = 0x7FFFFFFF;
3835 *res = (uint32_t)maxwrite;
3836 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3837 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003838 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 return status;
3840}
3841
Trond Myklebustbca79472009-03-11 14:10:26 -04003842static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843{
Trond Myklebustbca79472009-03-11 14:10:26 -04003844 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003845 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003846 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847
3848 *mode = 0;
3849 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3850 return -EIO;
3851 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003852 p = xdr_inline_decode(xdr, 4);
3853 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003854 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003855 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003856 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003858 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003860 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003861 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862}
3863
3864static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3865{
Al Viro8687b632006-10-19 23:28:48 -07003866 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003867 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868
3869 *nlink = 1;
3870 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3871 return -EIO;
3872 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003873 p = xdr_inline_decode(xdr, 4);
3874 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003875 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003876 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003878 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003880 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003881 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882}
3883
Trond Myklebust686a8162017-02-19 16:08:32 -05003884static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3885 struct nfs4_string *name, gfp_t gfp_flags)
3886{
3887 ssize_t ret;
3888
3889 ret = xdr_stream_decode_string_dup(xdr, &name->data,
3890 XDR_MAX_NETOBJ, gfp_flags);
3891 name->len = 0;
3892 if (ret > 0)
3893 name->len = ret;
3894 return ret;
3895}
3896
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003897static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003898 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003899 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900{
Trond Myklebust686a8162017-02-19 16:08:32 -05003901 ssize_t len;
3902 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903
Eric W. Biedermane5782072013-02-01 14:22:02 -08003904 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3906 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003907 if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3908 return 0;
3909 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3910
3911 if (owner_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04003912 len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05003913 if (len <= 0)
3914 goto out;
3915 dprintk("%s: name=%s\n", __func__, owner_name->data);
3916 return NFS_ATTR_FATTR_OWNER_NAME;
3917 } else {
3918 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3919 XDR_MAX_NETOBJ);
3920 if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3921 goto out;
3922 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3923 return NFS_ATTR_FATTR_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003925out:
Chuck Levereb72f482019-02-11 11:24:21 -05003926 if (len == -EBADMSG)
3927 return -EIO;
3928 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929}
3930
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003931static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003932 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003933 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934{
Trond Myklebust686a8162017-02-19 16:08:32 -05003935 ssize_t len;
3936 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937
Eric W. Biedermane5782072013-02-01 14:22:02 -08003938 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3940 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003941 if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
3942 return 0;
3943 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3944
3945 if (group_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04003946 len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05003947 if (len <= 0)
3948 goto out;
3949 dprintk("%s: name=%s\n", __func__, group_name->data);
Kinglong Mee6f1f6222017-03-06 17:49:42 +08003950 return NFS_ATTR_FATTR_GROUP_NAME;
Trond Myklebust686a8162017-02-19 16:08:32 -05003951 } else {
3952 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3953 XDR_MAX_NETOBJ);
3954 if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
3955 goto out;
3956 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3957 return NFS_ATTR_FATTR_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003959out:
Chuck Levereb72f482019-02-11 11:24:21 -05003960 if (len == -EBADMSG)
3961 return -EIO;
3962 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963}
3964
3965static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3966{
Al Viro8687b632006-10-19 23:28:48 -07003967 uint32_t major = 0, minor = 0;
3968 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003969 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970
3971 *rdev = MKDEV(0,0);
3972 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3973 return -EIO;
3974 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3975 dev_t tmp;
3976
Benny Halevyc0eae662009-08-14 17:20:14 +03003977 p = xdr_inline_decode(xdr, 8);
3978 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003979 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03003980 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003981 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 tmp = MKDEV(major, minor);
3983 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3984 *rdev = tmp;
3985 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003986 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003988 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003989 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990}
3991
3992static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3993{
Al Viro8687b632006-10-19 23:28:48 -07003994 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 int status = 0;
3996
3997 *res = 0;
3998 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3999 return -EIO;
4000 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004001 p = xdr_inline_decode(xdr, 8);
4002 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004003 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004004 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4006 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004007 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 return status;
4009}
4010
4011static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4012{
Al Viro8687b632006-10-19 23:28:48 -07004013 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 int status = 0;
4015
4016 *res = 0;
4017 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4018 return -EIO;
4019 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004020 p = xdr_inline_decode(xdr, 8);
4021 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004022 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004023 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4025 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004026 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027 return status;
4028}
4029
4030static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4031{
Al Viro8687b632006-10-19 23:28:48 -07004032 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 int status = 0;
4034
4035 *res = 0;
4036 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4037 return -EIO;
4038 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004039 p = xdr_inline_decode(xdr, 8);
4040 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004041 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004042 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4044 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004045 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 return status;
4047}
4048
4049static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4050{
Al Viro8687b632006-10-19 23:28:48 -07004051 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004052 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053
4054 *used = 0;
4055 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4056 return -EIO;
4057 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004058 p = xdr_inline_decode(xdr, 8);
4059 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004060 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004061 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004063 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004065 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004067 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068}
4069
Trond Myklebust36b37432018-03-20 17:03:10 -04004070static __be32 *
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004071xdr_decode_nfstime4(__be32 *p, struct timespec64 *t)
Trond Myklebust36b37432018-03-20 17:03:10 -04004072{
4073 __u64 sec;
4074
4075 p = xdr_decode_hyper(p, &sec);
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004076 t-> tv_sec = sec;
Trond Myklebust36b37432018-03-20 17:03:10 -04004077 t->tv_nsec = be32_to_cpup(p++);
4078 return p;
4079}
4080
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004081static int decode_attr_time(struct xdr_stream *xdr, struct timespec64 *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082{
Al Viro8687b632006-10-19 23:28:48 -07004083 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084
Trond Myklebust36b37432018-03-20 17:03:10 -04004085 p = xdr_inline_decode(xdr, nfstime4_maxsz << 2);
Benny Halevyc0eae662009-08-14 17:20:14 +03004086 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004087 return -EIO;
Trond Myklebust36b37432018-03-20 17:03:10 -04004088 xdr_decode_nfstime4(p, time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 return 0;
4090}
4091
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004092static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093{
4094 int status = 0;
4095
4096 time->tv_sec = 0;
4097 time->tv_nsec = 0;
4098 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4099 return -EIO;
4100 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4101 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004102 if (status == 0)
4103 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4105 }
Arnd Bergmannae084832019-11-11 21:16:23 +01004106 dprintk("%s: atime=%lld\n", __func__, time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107 return status;
4108}
4109
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004110static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111{
4112 int status = 0;
4113
4114 time->tv_sec = 0;
4115 time->tv_nsec = 0;
4116 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4117 return -EIO;
4118 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4119 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004120 if (status == 0)
4121 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4123 }
Arnd Bergmannae084832019-11-11 21:16:23 +01004124 dprintk("%s: ctime=%lld\n", __func__, time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 return status;
4126}
4127
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004128static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004129 struct timespec64 *time)
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004130{
4131 int status = 0;
4132
4133 time->tv_sec = 0;
4134 time->tv_nsec = 0;
4135 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4136 return -EIO;
4137 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4138 status = decode_attr_time(xdr, time);
4139 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4140 }
Arnd Bergmannae084832019-11-11 21:16:23 +01004141 dprintk("%s: time_delta=%lld %ld\n", __func__, time->tv_sec,
4142 time->tv_nsec);
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004143 return status;
4144}
4145
David Quigleyaa9c2662013-05-22 12:50:44 -04004146static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4147 struct nfs4_label *label)
4148{
4149 uint32_t pi = 0;
4150 uint32_t lfs = 0;
4151 __u32 len;
4152 __be32 *p;
4153 int status = 0;
4154
4155 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4156 return -EIO;
4157 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4158 p = xdr_inline_decode(xdr, 4);
4159 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004160 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004161 lfs = be32_to_cpup(p++);
4162 p = xdr_inline_decode(xdr, 4);
4163 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004164 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004165 pi = be32_to_cpup(p++);
4166 p = xdr_inline_decode(xdr, 4);
4167 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004168 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004169 len = be32_to_cpup(p++);
4170 p = xdr_inline_decode(xdr, len);
4171 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004172 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004173 if (len < NFS4_MAXLABELLEN) {
4174 if (label) {
Jeffrey Mitchellb4487b92020-08-05 12:23:19 -05004175 if (label->len) {
4176 if (label->len < len)
4177 return -ERANGE;
4178 memcpy(label->label, p, len);
4179 }
David Quigleyaa9c2662013-05-22 12:50:44 -04004180 label->len = len;
4181 label->pi = pi;
4182 label->lfs = lfs;
4183 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4184 }
4185 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4186 } else
4187 printk(KERN_WARNING "%s: label too long (%u)!\n",
4188 __func__, len);
4189 }
4190 if (label && label->label)
4191 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4192 (char *)label->label, label->len, label->pi, label->lfs);
4193 return status;
David Quigleyaa9c2662013-05-22 12:50:44 -04004194}
4195
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004196static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197{
4198 int status = 0;
4199
4200 time->tv_sec = 0;
4201 time->tv_nsec = 0;
4202 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4203 return -EIO;
4204 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4205 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004206 if (status == 0)
4207 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4209 }
Arnd Bergmannae084832019-11-11 21:16:23 +01004210 dprintk("%s: mtime=%lld\n", __func__, time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211 return status;
4212}
4213
Frank van der Lindenb78ef842020-06-23 22:38:55 +00004214static int decode_attr_xattrsupport(struct xdr_stream *xdr, uint32_t *bitmap,
4215 uint32_t *res)
4216{
4217 __be32 *p;
4218
4219 *res = 0;
4220 if (unlikely(bitmap[2] & (FATTR4_WORD2_XATTR_SUPPORT - 1U)))
4221 return -EIO;
4222 if (likely(bitmap[2] & FATTR4_WORD2_XATTR_SUPPORT)) {
4223 p = xdr_inline_decode(xdr, 4);
4224 if (unlikely(!p))
4225 return -EIO;
4226 *res = be32_to_cpup(p);
4227 bitmap[2] &= ~FATTR4_WORD2_XATTR_SUPPORT;
4228 }
4229 dprintk("%s: XATTR support=%s\n", __func__,
4230 *res == 0 ? "false" : "true");
4231 return 0;
4232}
4233
Trond Myklebust256e48b2012-06-21 11:18:13 -04004234static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235{
4236 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004237 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238
4239 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004240 dprintk("%s: server returned incorrect attribute length: "
4241 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004242 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243 attrwords << 2,
4244 (attrwords < nwords) ? '<' : '>',
4245 nwords << 2);
4246 return -EIO;
4247 }
4248 return 0;
4249}
4250
4251static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4252{
Al Viro8687b632006-10-19 23:28:48 -07004253 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254
Benny Halevyc0eae662009-08-14 17:20:14 +03004255 p = xdr_inline_decode(xdr, 20);
4256 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004257 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03004258 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004259 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004260 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261 return 0;
4262}
4263
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004264static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265{
Al Viro8687b632006-10-19 23:28:48 -07004266 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267 uint32_t supp, acc;
4268 int status;
4269
4270 status = decode_op_hdr(xdr, OP_ACCESS);
4271 if (status)
4272 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004273 p = xdr_inline_decode(xdr, 8);
4274 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004275 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03004276 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004277 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004278 *supported = supp;
4279 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004280 return 0;
4281}
4282
Benny Halevy07d30432009-08-14 17:19:52 +03004283static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004284{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004285 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
Chuck Levereb72f482019-02-11 11:24:21 -05004286 if (unlikely(ret < 0))
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004287 return -EIO;
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004288 return 0;
Benny Halevy07d30432009-08-14 17:19:52 +03004289}
4290
4291static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4292{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004293 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294}
4295
Trond Myklebust93b717f2016-05-16 17:42:43 -04004296static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4297{
4298 stateid->type = NFS4_OPEN_STATEID_TYPE;
4299 return decode_stateid(xdr, stateid);
4300}
4301
4302static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4303{
4304 stateid->type = NFS4_LOCK_STATEID_TYPE;
4305 return decode_stateid(xdr, stateid);
4306}
4307
4308static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4309{
4310 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4311 return decode_stateid(xdr, stateid);
4312}
4313
Trond Myklebustfcd88432017-11-07 12:39:44 -05004314static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4315{
4316 nfs4_stateid dummy;
4317
4318 nfs4_stateid_copy(stateid, &invalid_stateid);
4319 return decode_stateid(xdr, &dummy);
4320}
4321
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4323{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324 int status;
4325
4326 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004327 if (status != -EIO)
4328 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004329 if (!status)
Trond Myklebustfcd88432017-11-07 12:39:44 -05004330 status = decode_invalid_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004331 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332}
4333
Benny Halevydb942bb2009-08-14 17:19:56 +03004334static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4335{
Chuck Levercd937102012-03-02 17:14:31 -05004336 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337}
4338
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004339static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4340{
4341 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4342}
4343
Fred Isaman0b7c0152012-04-20 14:47:39 -04004344static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345{
Trond Myklebust221203c2020-01-06 15:25:04 -05004346 struct nfs_writeverf *verf = res->verf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347 int status;
4348
4349 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004350 if (!status)
Trond Myklebust221203c2020-01-06 15:25:04 -05004351 status = decode_write_verifier(xdr, &verf->verifier);
4352 if (!status)
4353 verf->committed = NFS_FILE_SYNC;
Benny Halevydb942bb2009-08-14 17:19:56 +03004354 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355}
4356
4357static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4358{
Al Viro8687b632006-10-19 23:28:48 -07004359 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360 uint32_t bmlen;
4361 int status;
4362
4363 status = decode_op_hdr(xdr, OP_CREATE);
4364 if (status)
4365 return status;
4366 if ((status = decode_change_info(xdr, cinfo)))
4367 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004368 p = xdr_inline_decode(xdr, 4);
4369 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004370 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004371 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004372 p = xdr_inline_decode(xdr, bmlen << 2);
4373 if (likely(p))
4374 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004375 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376}
4377
4378static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4379{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004380 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004381 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382 int status;
4383
4384 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4385 goto xdr_error;
4386 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4387 goto xdr_error;
4388 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4389 goto xdr_error;
4390 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4391 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004392 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4393 &res->fh_expire_type)) != 0)
4394 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4396 goto xdr_error;
4397 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4398 goto xdr_error;
4399 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4400 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004401 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4402 res->exclcreat_bitmask)) != 0)
4403 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 status = verify_attr_len(xdr, savep, attrlen);
4405xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004406 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 return status;
4408}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004409
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4411{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004412 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004413 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004415
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4417 goto xdr_error;
4418 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4419 goto xdr_error;
4420 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4421 goto xdr_error;
4422
4423 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4424 goto xdr_error;
4425 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4426 goto xdr_error;
4427 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4428 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004429
4430 status = -EIO;
4431 if (unlikely(bitmap[0]))
4432 goto xdr_error;
4433
Linus Torvalds1da177e2005-04-16 15:20:36 -07004434 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4435 goto xdr_error;
4436 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4437 goto xdr_error;
4438 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4439 goto xdr_error;
4440
4441 status = verify_attr_len(xdr, savep, attrlen);
4442xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004443 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444 return status;
4445}
4446
4447static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4448{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004449 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004450 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004451 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004452
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4454 goto xdr_error;
4455 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4456 goto xdr_error;
4457 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4458 goto xdr_error;
4459
4460 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4461 goto xdr_error;
4462 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4463 goto xdr_error;
4464
4465 status = verify_attr_len(xdr, savep, attrlen);
4466xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004467 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 return status;
4469}
4470
Andy Adamson88034c32012-05-23 05:02:34 -04004471static int decode_threshold_hint(struct xdr_stream *xdr,
4472 uint32_t *bitmap,
4473 uint64_t *res,
4474 uint32_t hint_bit)
4475{
4476 __be32 *p;
4477
4478 *res = 0;
4479 if (likely(bitmap[0] & hint_bit)) {
4480 p = xdr_inline_decode(xdr, 8);
4481 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004482 return -EIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004483 xdr_decode_hyper(p, res);
4484 }
4485 return 0;
Andy Adamson88034c32012-05-23 05:02:34 -04004486}
4487
4488static int decode_first_threshold_item4(struct xdr_stream *xdr,
4489 struct nfs4_threshold *res)
4490{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004491 __be32 *p;
4492 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004493 uint32_t bitmap[3] = {0,}, attrlen;
4494 int status;
4495
4496 /* layout type */
4497 p = xdr_inline_decode(xdr, 4);
Chuck Levereb72f482019-02-11 11:24:21 -05004498 if (unlikely(!p))
Andy Adamson88034c32012-05-23 05:02:34 -04004499 return -EIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004500 res->l_type = be32_to_cpup(p);
4501
4502 /* thi_hintset bitmap */
4503 status = decode_attr_bitmap(xdr, bitmap);
4504 if (status < 0)
4505 goto xdr_error;
4506
4507 /* thi_hintlist length */
4508 status = decode_attr_length(xdr, &attrlen, &savep);
4509 if (status < 0)
4510 goto xdr_error;
4511 /* thi_hintlist */
4512 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4513 if (status < 0)
4514 goto xdr_error;
4515 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4516 if (status < 0)
4517 goto xdr_error;
4518 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4519 THRESHOLD_RD_IO);
4520 if (status < 0)
4521 goto xdr_error;
4522 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4523 THRESHOLD_WR_IO);
4524 if (status < 0)
4525 goto xdr_error;
4526
4527 status = verify_attr_len(xdr, savep, attrlen);
4528 res->bm = bitmap[0];
4529
4530 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4531 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4532 res->wr_io_sz);
4533xdr_error:
4534 dprintk("%s ret=%d!\n", __func__, status);
4535 return status;
4536}
4537
4538/*
4539 * Thresholds on pNFS direct I/O vrs MDS I/O
4540 */
4541static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4542 uint32_t *bitmap,
4543 struct nfs4_threshold *res)
4544{
4545 __be32 *p;
4546 int status = 0;
4547 uint32_t num;
4548
4549 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4550 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004551 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004552 /* Did the server return an unrequested attribute? */
4553 if (unlikely(res == NULL))
4554 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004555 p = xdr_inline_decode(xdr, 4);
4556 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004557 return -EIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004558 num = be32_to_cpup(p);
4559 if (num == 0)
4560 return 0;
4561 if (num > 1)
4562 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4563 "drivers per filesystem not supported\n",
4564 __func__);
4565
4566 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004567 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004568 }
4569 return status;
Andy Adamson88034c32012-05-23 05:02:34 -04004570}
4571
Bryan Schumakerae42c702010-10-21 16:33:17 -04004572static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4573 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004574 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004575 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576{
Trond Myklebustbca79472009-03-11 14:10:26 -04004577 int status;
4578 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004579 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004580 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004582 status = decode_attr_type(xdr, bitmap, &type);
4583 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004584 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004585 fattr->mode = 0;
4586 if (status != 0) {
4587 fattr->mode |= nfs_type2fmt[type];
4588 fattr->valid |= status;
4589 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004591 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4592 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004594 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004595
4596 status = decode_attr_size(xdr, bitmap, &fattr->size);
4597 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004599 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004600
4601 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4602 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004604 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004605
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004606 err = 0;
4607 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004608 if (status < 0)
4609 goto xdr_error;
4610
4611 status = decode_attr_filehandle(xdr, bitmap, fh);
4612 if (status < 0)
4613 goto xdr_error;
4614
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004615 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4616 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004618 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004619
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004620 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004621 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004622 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004623 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004624
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004625 status = -EIO;
4626 if (unlikely(bitmap[0]))
4627 goto xdr_error;
4628
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004629 status = decode_attr_mode(xdr, bitmap, &fmode);
4630 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004632 if (status != 0) {
4633 fattr->mode |= fmode;
4634 fattr->valid |= status;
4635 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004636
4637 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4638 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004640 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004641
Trond Myklebust6926afd12012-01-07 13:22:46 -05004642 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004643 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004645 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004646
Trond Myklebust6926afd12012-01-07 13:22:46 -05004647 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004648 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004650 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004651
4652 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4653 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004655 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004656
4657 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4658 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004660 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004661
4662 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4663 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004664 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004665 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004666
4667 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4668 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004670 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004671
4672 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4673 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004675 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004676
Trond Myklebust28331a42011-04-27 13:47:52 -04004677 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004678 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004679 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004680 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004681
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004682 status = -EIO;
4683 if (unlikely(bitmap[1]))
4684 goto xdr_error;
4685
Andy Adamson88034c32012-05-23 05:02:34 -04004686 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4687 if (status < 0)
4688 goto xdr_error;
4689
David Quigleyaa9c2662013-05-22 12:50:44 -04004690 if (label) {
4691 status = decode_attr_security_label(xdr, bitmap, label);
4692 if (status < 0)
4693 goto xdr_error;
4694 fattr->valid |= status;
4695 }
4696
Bryan Schumakerae42c702010-10-21 16:33:17 -04004697xdr_error:
4698 dprintk("%s: xdr returned %d\n", __func__, -status);
4699 return status;
4700}
4701
4702static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004703 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004704 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004705{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004706 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004707 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004708 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004709 int status;
4710
4711 status = decode_op_hdr(xdr, OP_GETATTR);
4712 if (status < 0)
4713 goto xdr_error;
4714
4715 status = decode_attr_bitmap(xdr, bitmap);
4716 if (status < 0)
4717 goto xdr_error;
4718
4719 status = decode_attr_length(xdr, &attrlen, &savep);
4720 if (status < 0)
4721 goto xdr_error;
4722
David Quigleyaa9c2662013-05-22 12:50:44 -04004723 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4724 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004725 if (status < 0)
4726 goto xdr_error;
4727
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004728 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004729xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004730 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731 return status;
4732}
4733
David Quigleyaa9c2662013-05-22 12:50:44 -04004734static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4735 struct nfs4_label *label, const struct nfs_server *server)
4736{
4737 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4738}
4739
Bryan Schumakerae42c702010-10-21 16:33:17 -04004740static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004741 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004742{
David Quigleyaa9c2662013-05-22 12:50:44 -04004743 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004744}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745
Andy Adamson504913f2010-10-20 00:17:57 -04004746/*
Jeff Layton3132e492016-08-10 15:58:24 -04004747 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004748 */
Jeff Layton3132e492016-08-10 15:58:24 -04004749static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004750 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004751{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004752 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004753 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004754
4755 p = xdr_inline_decode(xdr, 4);
4756 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004757 return -EIO;
Jeff Laytonca440c32016-09-15 14:40:49 -04004758 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004759
4760 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004761 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004762 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004763
4764 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004765 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004766 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004767 return -EIO;
Jeff Laytonca440c32016-09-15 14:40:49 -04004768
4769 /* If we get too many, then just cap it at the max */
4770 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4771 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4772 __func__, fsinfo->nlayouttypes);
4773 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4774 }
4775
4776 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4777 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004778 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004779}
4780
4781/*
4782 * The type of file system exported.
4783 * Note we must ensure that layouttype is set in any non-error case.
4784 */
4785static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004786 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004787{
4788 int status = 0;
4789
4790 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4791 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4792 return -EIO;
4793 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004794 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004795 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004796 }
Andy Adamson504913f2010-10-20 00:17:57 -04004797 return status;
4798}
4799
Fred Isamandae100c2011-07-30 20:52:37 -04004800/*
4801 * The prefered block size for layout directed io
4802 */
4803static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4804 uint32_t *res)
4805{
4806 __be32 *p;
4807
4808 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4809 *res = 0;
4810 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4811 p = xdr_inline_decode(xdr, 4);
Chuck Levereb72f482019-02-11 11:24:21 -05004812 if (unlikely(!p))
Fred Isamandae100c2011-07-30 20:52:37 -04004813 return -EIO;
Fred Isamandae100c2011-07-30 20:52:37 -04004814 *res = be32_to_cpup(p);
4815 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4816 }
4817 return 0;
4818}
4819
Peng Tao2a92ee92015-09-26 02:24:37 +08004820/*
4821 * The granularity of a CLONE operation.
4822 */
4823static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4824 uint32_t *res)
4825{
4826 __be32 *p;
4827
4828 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4829 *res = 0;
4830 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4831 p = xdr_inline_decode(xdr, 4);
Chuck Levereb72f482019-02-11 11:24:21 -05004832 if (unlikely(!p))
Peng Tao2a92ee92015-09-26 02:24:37 +08004833 return -EIO;
Peng Tao2a92ee92015-09-26 02:24:37 +08004834 *res = be32_to_cpup(p);
4835 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4836 }
4837 return 0;
4838}
4839
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4841{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004842 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004843 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 int status;
4845
4846 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4847 goto xdr_error;
4848 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4849 goto xdr_error;
4850 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4851 goto xdr_error;
4852
4853 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4854
4855 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4856 goto xdr_error;
4857 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4858 goto xdr_error;
4859 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4860 goto xdr_error;
4861 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4862 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4863 goto xdr_error;
4864 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004865
4866 status = -EIO;
4867 if (unlikely(bitmap[0]))
4868 goto xdr_error;
4869
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004870 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4871 if (status != 0)
4872 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004873 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004874 if (status != 0)
4875 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004876
4877 status = -EIO;
4878 if (unlikely(bitmap[1]))
4879 goto xdr_error;
4880
Fred Isamandae100c2011-07-30 20:52:37 -04004881 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4882 if (status)
4883 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004884 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4885 if (status)
4886 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887
Frank van der Lindenb78ef842020-06-23 22:38:55 +00004888 status = decode_attr_xattrsupport(xdr, bitmap,
4889 &fsinfo->xattr_support);
4890 if (status)
4891 goto xdr_error;
4892
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893 status = verify_attr_len(xdr, savep, attrlen);
4894xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004895 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004896 return status;
4897}
4898
4899static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4900{
Al Viro8687b632006-10-19 23:28:48 -07004901 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902 uint32_t len;
4903 int status;
4904
Trond Myklebust99367812007-07-17 21:52:41 -04004905 /* Zero handle first to allow comparisons */
4906 memset(fh, 0, sizeof(*fh));
4907
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908 status = decode_op_hdr(xdr, OP_GETFH);
4909 if (status)
4910 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004911
Benny Halevyc0eae662009-08-14 17:20:14 +03004912 p = xdr_inline_decode(xdr, 4);
4913 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004914 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004915 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916 if (len > NFS4_FHSIZE)
4917 return -EIO;
4918 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004919 p = xdr_inline_decode(xdr, len);
4920 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004921 return -EIO;
Benny Halevy99398d02009-08-14 17:20:05 +03004922 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004923 return 0;
4924}
4925
4926static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4927{
4928 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004929
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930 status = decode_op_hdr(xdr, OP_LINK);
4931 if (status)
4932 return status;
4933 return decode_change_info(xdr, cinfo);
4934}
4935
4936/*
4937 * We create the owner, so we know a proper owner.id length is 4.
4938 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004939static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004940{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004941 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004942 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004943 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004945 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004946 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004947 return -EIO;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004948 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004949 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004950 type = be32_to_cpup(p++); /* 4 byte read */
4951 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004952 fl->fl_start = (loff_t)offset;
4953 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4954 if (length == ~(uint64_t)0)
4955 fl->fl_end = OFFSET_MAX;
4956 fl->fl_type = F_WRLCK;
4957 if (type & 1)
4958 fl->fl_type = F_RDLCK;
4959 fl->fl_pid = 0;
4960 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004961 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4962 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4963 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Chuck Levereb72f482019-02-11 11:24:21 -05004964 if (likely(!p))
4965 return -EIO;
4966 return -NFS4ERR_DENIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967}
4968
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004969static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971 int status;
4972
4973 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004974 if (status == -EIO)
4975 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04004977 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004978 if (unlikely(status))
4979 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004981 status = decode_lock_denied(xdr, NULL);
4982 if (res->open_seqid != NULL)
4983 nfs_increment_open_seqid(status, res->open_seqid);
4984 nfs_increment_lock_seqid(status, res->lock_seqid);
4985out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986 return status;
4987}
4988
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004989static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990{
4991 int status;
4992 status = decode_op_hdr(xdr, OP_LOCKT);
4993 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004994 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995 return status;
4996}
4997
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004998static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005000 int status;
5001
5002 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005003 if (status != -EIO)
5004 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005005 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005006 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007 return status;
5008}
5009
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005010static int decode_release_lockowner(struct xdr_stream *xdr)
5011{
5012 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5013}
5014
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015static int decode_lookup(struct xdr_stream *xdr)
5016{
5017 return decode_op_hdr(xdr, OP_LOOKUP);
5018}
5019
Jeff Layton5b5faaf2017-06-29 06:34:52 -07005020static int decode_lookupp(struct xdr_stream *xdr)
5021{
5022 return decode_op_hdr(xdr, OP_LOOKUPP);
5023}
5024
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005026static int decode_space_limit(struct xdr_stream *xdr,
5027 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028{
Andy Adamson05d564f2008-12-23 16:06:15 -05005029 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005030 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005031 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032
Benny Halevyc0eae662009-08-14 17:20:14 +03005033 p = xdr_inline_decode(xdr, 12);
5034 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005035 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005036 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005037 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005038 case NFS4_LIMIT_SIZE:
5039 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005040 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005041 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005042 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005043 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005044 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005046 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005047 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048 return 0;
5049}
5050
Trond Myklebust6ae37332015-01-30 14:21:14 -05005051static int decode_rw_delegation(struct xdr_stream *xdr,
5052 uint32_t delegation_type,
5053 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054{
Andy Adamson05d564f2008-12-23 16:06:15 -05005055 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005056 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057
Trond Myklebust93b717f2016-05-16 17:42:43 -04005058 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005059 if (unlikely(status))
5060 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005061 p = xdr_inline_decode(xdr, 4);
5062 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005063 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005064 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005065
Linus Torvalds1da177e2005-04-16 15:20:36 -07005066 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005067 case NFS4_OPEN_DELEGATE_READ:
5068 res->delegation_type = FMODE_READ;
5069 break;
5070 case NFS4_OPEN_DELEGATE_WRITE:
5071 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005072 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073 return -EIO;
5074 }
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05005075 return decode_ace(xdr, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005076}
5077
Trond Myklebust6ae37332015-01-30 14:21:14 -05005078static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5079{
5080 __be32 *p;
5081 uint32_t why_no_delegation;
5082
5083 p = xdr_inline_decode(xdr, 4);
5084 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005085 return -EIO;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005086 why_no_delegation = be32_to_cpup(p);
5087 switch (why_no_delegation) {
5088 case WND4_CONTENTION:
5089 case WND4_RESOURCE:
5090 xdr_inline_decode(xdr, 4);
5091 /* Ignore for now */
5092 }
5093 return 0;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005094}
5095
5096static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5097{
5098 __be32 *p;
5099 uint32_t delegation_type;
5100
5101 p = xdr_inline_decode(xdr, 4);
5102 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005103 return -EIO;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005104 delegation_type = be32_to_cpup(p);
5105 res->delegation_type = 0;
5106 switch (delegation_type) {
5107 case NFS4_OPEN_DELEGATE_NONE:
5108 return 0;
5109 case NFS4_OPEN_DELEGATE_READ:
5110 case NFS4_OPEN_DELEGATE_WRITE:
5111 return decode_rw_delegation(xdr, delegation_type, res);
5112 case NFS4_OPEN_DELEGATE_NONE_EXT:
5113 return decode_no_delegation(xdr, res);
5114 }
5115 return -EIO;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005116}
5117
Linus Torvalds1da177e2005-04-16 15:20:36 -07005118static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5119{
Andy Adamson05d564f2008-12-23 16:06:15 -05005120 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005121 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005122 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123
Trond Myklebustc7848f62013-12-04 17:39:23 -05005124 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5125 return status;
5126 nfs_increment_open_seqid(status, res->seqid);
5127 if (status)
5128 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005129 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005130 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005131 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132
Andy Adamson05d564f2008-12-23 16:06:15 -05005133 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005134
Benny Halevyc0eae662009-08-14 17:20:14 +03005135 p = xdr_inline_decode(xdr, 8);
5136 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005137 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005138 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005139 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005140 if (bmlen > 10)
5141 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005142
Benny Halevyc0eae662009-08-14 17:20:14 +03005143 p = xdr_inline_decode(xdr, bmlen << 2);
5144 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005145 return -EIO;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005146 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5147 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005148 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005149 for (; i < NFS4_BITMAP_SIZE; i++)
5150 res->attrset[i] = 0;
5151
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152 return decode_delegation(xdr, res);
5153xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005154 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155 return -EIO;
5156}
5157
5158static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5159{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005160 int status;
5161
Andy Adamson05d564f2008-12-23 16:06:15 -05005162 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005163 if (status != -EIO)
5164 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005165 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005166 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005167 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168}
5169
5170static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5171{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005172 int status;
5173
5174 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005175 if (status != -EIO)
5176 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005177 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005178 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005179 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005180}
5181
5182static int decode_putfh(struct xdr_stream *xdr)
5183{
5184 return decode_op_hdr(xdr, OP_PUTFH);
5185}
5186
5187static int decode_putrootfh(struct xdr_stream *xdr)
5188{
5189 return decode_op_hdr(xdr, OP_PUTROOTFH);
5190}
5191
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005192static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5193 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194{
Al Viro8687b632006-10-19 23:28:48 -07005195 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005196 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005197 int status;
5198
5199 status = decode_op_hdr(xdr, OP_READ);
5200 if (status)
5201 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005202 p = xdr_inline_decode(xdr, 8);
5203 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005204 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005205 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005206 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005207 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005208 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005209 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005210 "count %u > recvd %u\n", count, recvd);
5211 count = recvd;
5212 eof = 0;
5213 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214 res->eof = eof;
5215 res->count = count;
5216 return 0;
5217}
5218
5219static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5220{
Chuck Leverbcecff72007-10-26 13:32:03 -04005221 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005222 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223
5224 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005225 if (!status)
5226 status = decode_verifier(xdr, readdir->verifier.data);
5227 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005229 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005230 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005231 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005232 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005233}
5234
5235static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5236{
5237 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005238 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005239 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240 int status;
5241
5242 status = decode_op_hdr(xdr, OP_READLINK);
5243 if (status)
5244 return status;
5245
5246 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005247 p = xdr_inline_decode(xdr, 4);
5248 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005249 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005250 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005251 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005252 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005253 return -ENAMETOOLONG;
5254 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005255 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005256 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005257 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005258 "count %u > recvd %u\n", len, recvd);
5259 return -EIO;
5260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005261 /*
5262 * The XDR encode routine has set things up so that
5263 * the link text will be copied directly into the
5264 * buffer. We just have to do overflow-checking,
Randy Dunlapa5032912020-08-10 19:18:35 -07005265 * and null-terminate the text (the VFS expects
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266 * null-termination).
5267 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005268 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269 return 0;
5270}
5271
5272static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5273{
5274 int status;
5275
5276 status = decode_op_hdr(xdr, OP_REMOVE);
5277 if (status)
5278 goto out;
5279 status = decode_change_info(xdr, cinfo);
5280out:
5281 return status;
5282}
5283
5284static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5285 struct nfs4_change_info *new_cinfo)
5286{
5287 int status;
5288
5289 status = decode_op_hdr(xdr, OP_RENAME);
5290 if (status)
5291 goto out;
5292 if ((status = decode_change_info(xdr, old_cinfo)))
5293 goto out;
5294 status = decode_change_info(xdr, new_cinfo);
5295out:
5296 return status;
5297}
5298
5299static int decode_renew(struct xdr_stream *xdr)
5300{
5301 return decode_op_hdr(xdr, OP_RENEW);
5302}
5303
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005304static int
5305decode_restorefh(struct xdr_stream *xdr)
5306{
5307 return decode_op_hdr(xdr, OP_RESTOREFH);
5308}
5309
J. Bruce Fields029d1052005-06-22 17:16:22 +00005310static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005311 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005312{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005313 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005314 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005315 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005316 int status;
5317
Andy Adamsonbf118a32011-12-07 11:55:27 -05005318 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005319 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5320 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005321
Trond Myklebust519d3952012-08-14 17:30:10 -04005322 xdr_enter_page(xdr, xdr->buf->page_len);
5323
J. Bruce Fields029d1052005-06-22 17:16:22 +00005324 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5325 goto out;
5326 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5327 goto out;
5328
5329 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5330 return -EIO;
5331 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005332
Andy Adamsonbf118a32011-12-07 11:55:27 -05005333 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5334 * are stored with the acl data to handle the problem of
5335 * variable length bitmaps.*/
Anna Schumakera14a6352020-04-17 11:01:50 -04005336 res->acl_data_offset = xdr_page_pos(xdr);
Trond Myklebust519d3952012-08-14 17:30:10 -04005337 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005338
5339 /* Check for receive buffer overflow */
5340 if (res->acl_len > (xdr->nwords << 2) ||
5341 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5342 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005343 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005344 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005345 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005346 } else
5347 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005348
5349out:
5350 return status;
5351}
5352
Linus Torvalds1da177e2005-04-16 15:20:36 -07005353static int
5354decode_savefh(struct xdr_stream *xdr)
5355{
5356 return decode_op_hdr(xdr, OP_SAVEFH);
5357}
5358
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005359static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005360{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005361 int status;
5362
Linus Torvalds1da177e2005-04-16 15:20:36 -07005363 status = decode_op_hdr(xdr, OP_SETATTR);
5364 if (status)
5365 return status;
Trond Myklebust37c88762018-03-20 17:03:08 -04005366 if (decode_bitmap4(xdr, NULL, 0) >= 0)
Benny Halevyc0eae662009-08-14 17:20:14 +03005367 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005368 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005369}
5370
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005371static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005372{
Al Viro8687b632006-10-19 23:28:48 -07005373 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005374 uint32_t opnum;
5375 int32_t nfserr;
5376
Benny Halevyc0eae662009-08-14 17:20:14 +03005377 p = xdr_inline_decode(xdr, 8);
5378 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005379 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005380 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005381 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005382 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005383 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005384 return -EIO;
5385 }
Benny Halevycccddf42009-08-14 17:20:19 +03005386 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005387 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005388 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5389 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005390 return -EIO;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005391 p = xdr_decode_hyper(p, &res->clientid);
5392 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005393 } else if (nfserr == NFSERR_CLID_INUSE) {
5394 uint32_t len;
5395
5396 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005397 p = xdr_inline_decode(xdr, 4);
5398 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005399 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005400 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005401 p = xdr_inline_decode(xdr, len);
5402 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005403 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005404
5405 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005406 p = xdr_inline_decode(xdr, 4);
5407 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005408 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005409 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005410 p = xdr_inline_decode(xdr, len);
5411 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005412 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005413 return -NFSERR_CLID_INUSE;
5414 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005415 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005416
5417 return 0;
5418}
5419
5420static int decode_setclientid_confirm(struct xdr_stream *xdr)
5421{
5422 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5423}
5424
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005425static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005426{
Al Viro8687b632006-10-19 23:28:48 -07005427 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005428 int status;
5429
5430 status = decode_op_hdr(xdr, OP_WRITE);
5431 if (status)
5432 return status;
5433
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005434 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005435 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005436 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005437 res->count = be32_to_cpup(p++);
5438 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005439 return decode_write_verifier(xdr, &res->verf->verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005440}
5441
5442static int decode_delegreturn(struct xdr_stream *xdr)
5443{
5444 return decode_op_hdr(xdr, OP_DELEGRETURN);
5445}
5446
Chuck Leverfb15b262013-03-16 15:54:34 -04005447static int decode_secinfo_gss(struct xdr_stream *xdr,
5448 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005449{
Chuck Leverfb15b262013-03-16 15:54:34 -04005450 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005451 __be32 *p;
5452
5453 p = xdr_inline_decode(xdr, 4);
5454 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005455 return -EIO;
Chuck Leverfb15b262013-03-16 15:54:34 -04005456 oid_len = be32_to_cpup(p);
5457 if (oid_len > GSS_OID_MAX_LEN)
Chuck Levereb72f482019-02-11 11:24:21 -05005458 return -EINVAL;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005459
Chuck Leverfb15b262013-03-16 15:54:34 -04005460 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005461 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005462 return -EIO;
Chuck Leverfb15b262013-03-16 15:54:34 -04005463 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5464 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005465
5466 p = xdr_inline_decode(xdr, 8);
5467 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005468 return -EIO;
Chuck Leverfb15b262013-03-16 15:54:34 -04005469 flavor->flavor_info.qop = be32_to_cpup(p++);
5470 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005471
5472 return 0;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005473}
5474
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005475static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005476{
Chuck Leverfb15b262013-03-16 15:54:34 -04005477 struct nfs4_secinfo4 *sec_flavor;
5478 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005479 int status;
5480 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005481
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005482 p = xdr_inline_decode(xdr, 4);
5483 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005484 return -EIO;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005485
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005486 res->flavors->num_flavors = 0;
5487 num_flavors = be32_to_cpup(p);
5488
5489 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005490 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005491 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005492 break;
5493
5494 p = xdr_inline_decode(xdr, 4);
5495 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005496 return -EIO;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005497 sec_flavor->flavor = be32_to_cpup(p);
5498
5499 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005500 status = decode_secinfo_gss(xdr, sec_flavor);
5501 if (status)
5502 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005503 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005504 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005505 }
5506
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005507 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005508out:
5509 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005510}
5511
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005512static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5513{
5514 int status = decode_op_hdr(xdr, OP_SECINFO);
5515 if (status)
5516 return status;
5517 return decode_secinfo_common(xdr, res);
5518}
5519
Benny Halevy99fe60d2009-04-01 09:22:29 -04005520#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005521static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5522{
5523 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5524 if (status)
5525 return status;
5526 return decode_secinfo_common(xdr, res);
5527}
5528
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005529static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5530{
5531 __be32 *p;
5532 uint32_t bitmap_words;
5533 unsigned int i;
5534
5535 p = xdr_inline_decode(xdr, 4);
Pan Bian4edabfd2017-04-23 14:49:41 +08005536 if (!p)
5537 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005538 bitmap_words = be32_to_cpup(p++);
5539 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5540 return -EIO;
5541 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5542 for (i = 0; i < bitmap_words; i++)
5543 op_map->u.words[i] = be32_to_cpup(p++);
5544
5545 return 0;
5546}
5547
Benny Halevy99fe60d2009-04-01 09:22:29 -04005548static int decode_exchange_id(struct xdr_stream *xdr,
5549 struct nfs41_exchange_id_res *res)
5550{
5551 __be32 *p;
5552 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005553 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005554 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005555 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005556
5557 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5558 if (status)
5559 return status;
5560
Benny Halevyc0eae662009-08-14 17:20:14 +03005561 p = xdr_inline_decode(xdr, 8);
5562 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005563 return -EIO;
Trond Myklebust32b01312012-05-26 13:41:04 -04005564 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005565 p = xdr_inline_decode(xdr, 12);
5566 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005567 return -EIO;
Trond Myklebust32b01312012-05-26 13:41:04 -04005568 res->seqid = be32_to_cpup(p++);
5569 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005570
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005571 res->state_protect.how = be32_to_cpup(p);
5572 switch (res->state_protect.how) {
5573 case SP4_NONE:
5574 break;
5575 case SP4_MACH_CRED:
5576 status = decode_op_map(xdr, &res->state_protect.enforce);
5577 if (status)
5578 return status;
5579 status = decode_op_map(xdr, &res->state_protect.allow);
5580 if (status)
5581 return status;
5582 break;
5583 default:
5584 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005585 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005586 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005587
Chuck Leveracdeb692012-05-21 22:46:16 -04005588 /* server_owner4.so_minor_id */
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;
Chuck Leveracdeb692012-05-21 22:46:16 -04005592 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005593
Chuck Leveracdeb692012-05-21 22:46:16 -04005594 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005595 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5596 if (unlikely(status))
5597 return status;
Chuck Leveracdeb692012-05-21 22:46:16 -04005598 memcpy(res->server_owner->major_id, dummy_str, dummy);
5599 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005600
Chuck Leveracdeb692012-05-21 22:46:16 -04005601 /* server_scope4 */
5602 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5603 if (unlikely(status))
5604 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005605 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5606 res->server_scope->server_scope_sz = dummy;
5607
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005608 /* Implementation Id */
5609 p = xdr_inline_decode(xdr, 4);
5610 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005611 return -EIO;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005612 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005613
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005614 if (impl_id_count) {
5615 /* nii_domain */
5616 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5617 if (unlikely(status))
5618 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005619 memcpy(res->impl_id->domain, dummy_str, dummy);
5620
5621 /* nii_name */
5622 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5623 if (unlikely(status))
5624 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005625 memcpy(res->impl_id->name, dummy_str, dummy);
5626
5627 /* nii_date */
5628 p = xdr_inline_decode(xdr, 12);
5629 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005630 return -EIO;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005631 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5632 res->impl_id->date.nseconds = be32_to_cpup(p);
5633
5634 /* if there's more than one entry, ignore the rest */
5635 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005636 return 0;
5637}
Andy Adamsonfc931582009-04-01 09:22:31 -04005638
5639static int decode_chan_attrs(struct xdr_stream *xdr,
5640 struct nfs4_channel_attrs *attrs)
5641{
5642 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005643 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005644
Benny Halevyc0eae662009-08-14 17:20:14 +03005645 p = xdr_inline_decode(xdr, 28);
5646 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005647 return -EIO;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005648 val = be32_to_cpup(p++); /* headerpadsz */
5649 if (val)
5650 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005651 attrs->max_rqst_sz = be32_to_cpup(p++);
5652 attrs->max_resp_sz = be32_to_cpup(p++);
5653 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5654 attrs->max_ops = be32_to_cpup(p++);
5655 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005656 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005657 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005658 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5659 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005660 return -EINVAL;
5661 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005662 if (nr_attrs == 1) {
5663 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5664 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005665 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005666 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005667 return 0;
5668}
5669
Benny Halevye78291e2009-08-14 17:20:00 +03005670static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5671{
5672 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005673}
5674
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005675static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5676 struct nfs41_bind_conn_to_session_res *res)
5677{
5678 __be32 *p;
5679 int status;
5680
5681 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5682 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005683 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005684 if (unlikely(status))
5685 return status;
5686
5687 /* dir flags, rdma mode bool */
5688 p = xdr_inline_decode(xdr, 8);
5689 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005690 return -EIO;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005691
5692 res->dir = be32_to_cpup(p++);
5693 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5694 return -EIO;
5695 if (be32_to_cpup(p) == 0)
5696 res->use_conn_in_rdma_mode = false;
5697 else
5698 res->use_conn_in_rdma_mode = true;
5699
5700 return 0;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005701}
5702
Andy Adamsonfc931582009-04-01 09:22:31 -04005703static int decode_create_session(struct xdr_stream *xdr,
5704 struct nfs41_create_session_res *res)
5705{
5706 __be32 *p;
5707 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005708
5709 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005710 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005711 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005712 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005713 return status;
5714
Andy Adamsonfc931582009-04-01 09:22:31 -04005715 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005716 p = xdr_inline_decode(xdr, 8);
5717 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005718 return -EIO;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005719 res->seqid = be32_to_cpup(p++);
5720 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005721
5722 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005723 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005724 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005725 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005726 return status;
5727}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005728
5729static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5730{
5731 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5732}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005733
Trond Myklebust66245532012-05-25 17:18:09 -04005734static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5735{
5736 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5737}
5738
Ricardo Labiaga180197532009-12-05 16:08:40 -05005739static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5740{
5741 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5742}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005743#endif /* CONFIG_NFS_V4_1 */
5744
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005745static int decode_sequence(struct xdr_stream *xdr,
5746 struct nfs4_sequence_res *res,
5747 struct rpc_rqst *rqstp)
5748{
5749#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005750 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005751 struct nfs4_sessionid id;
5752 u32 dummy;
5753 int status;
5754 __be32 *p;
5755
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005756 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005757 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005758 if (!res->sr_slot->table->session)
5759 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005760
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005761 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005762 if (!status)
5763 status = decode_sessionid(xdr, &id);
5764 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005765 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005766
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005767 /*
5768 * If the server returns different values for sessionID, slotID or
5769 * sequence number, the server is looney tunes.
5770 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005771 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005772 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005773
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005774 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005775 NFS4_MAX_SESSIONID_LEN)) {
5776 dprintk("%s Invalid session id\n", __func__);
5777 goto out_err;
5778 }
Benny Halevye78291e2009-08-14 17:20:00 +03005779
Benny Halevyc0eae662009-08-14 17:20:14 +03005780 p = xdr_inline_decode(xdr, 20);
5781 if (unlikely(!p))
5782 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005783
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005784 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005785 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005786 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005787 dprintk("%s Invalid sequence number\n", __func__);
5788 goto out_err;
5789 }
5790 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005791 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005792 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005793 dprintk("%s Invalid slot id\n", __func__);
5794 goto out_err;
5795 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005796 /* highest slot id */
5797 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005798 /* target highest slot id */
5799 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005800 /* result flags */
5801 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005802 status = 0;
5803out_err:
5804 res->sr_status = status;
5805 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005806out_overflow:
Benny Halevyc0eae662009-08-14 17:20:14 +03005807 status = -EIO;
5808 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005809#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005810 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005811#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005812}
5813
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005814#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005815static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5816{
5817 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5818 return decode_stateid(xdr, stateid);
5819}
5820
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005821static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005822 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005823{
Trond Myklebust4e590802015-03-09 14:01:25 -04005824 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005825 __be32 *p;
5826 uint32_t len, type;
5827 int status;
5828
5829 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5830 if (status) {
5831 if (status == -ETOOSMALL) {
5832 p = xdr_inline_decode(xdr, 4);
5833 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005834 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005835 pdev->mincount = be32_to_cpup(p);
5836 dprintk("%s: Min count too small. mincnt = %u\n",
5837 __func__, pdev->mincount);
5838 }
5839 return status;
5840 }
5841
5842 p = xdr_inline_decode(xdr, 8);
5843 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005844 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005845 type = be32_to_cpup(p++);
5846 if (type != pdev->layout_type) {
5847 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5848 __func__, pdev->layout_type, type);
5849 return -EINVAL;
5850 }
5851 /*
5852 * Get the length of the opaque device_addr4. xdr_read_pages places
5853 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5854 * and places the remaining xdr data in xdr_buf->tail
5855 */
5856 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005857 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
Chuck Levereb72f482019-02-11 11:24:21 -05005858 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005859
5860 /* Parse notification bitmap, verifying that it is zero. */
5861 p = xdr_inline_decode(xdr, 4);
5862 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005863 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005864 len = be32_to_cpup(p);
5865 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005866 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005867
5868 p = xdr_inline_decode(xdr, 4 * len);
5869 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005870 return -EIO;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005871
Trond Myklebust4e590802015-03-09 14:01:25 -04005872 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005873 for (i = 1; i < len; i++) {
5874 if (be32_to_cpup(p++)) {
5875 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005876 __func__);
5877 return -EIO;
5878 }
5879 }
5880 }
5881 return 0;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005882}
5883
5884static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5885 struct nfs4_layoutget_res *res)
5886{
5887 __be32 *p;
5888 int status;
5889 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005890 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005891
5892 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5893 if (status)
Fred Isaman808ba322016-10-04 15:02:21 -04005894 goto out;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005895 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005896 if (unlikely(!p))
5897 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005898 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04005899 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005900 p = xdr_inline_decode(xdr, 4);
5901 if (unlikely(!p))
5902 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005903 layout_count = be32_to_cpup(p);
5904 if (!layout_count) {
5905 dprintk("%s: server responded with empty layout array\n",
5906 __func__);
Fred Isaman808ba322016-10-04 15:02:21 -04005907 status = -EINVAL;
5908 goto out;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005909 }
5910
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005911 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005912 if (unlikely(!p))
5913 goto out_overflow;
5914 p = xdr_decode_hyper(p, &res->range.offset);
5915 p = xdr_decode_hyper(p, &res->range.length);
5916 res->range.iomode = be32_to_cpup(p++);
5917 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005918 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005919
5920 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5921 __func__,
5922 (unsigned long)res->range.offset,
5923 (unsigned long)res->range.length,
5924 res->range.iomode,
5925 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005926 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005927
Trond Myklebust64bd5772012-06-20 22:35:05 -04005928 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005929 if (res->layoutp->len > recvd) {
5930 dprintk("NFS: server cheating in layoutget reply: "
5931 "layout len %u > recvd %u\n",
5932 res->layoutp->len, recvd);
Fred Isaman808ba322016-10-04 15:02:21 -04005933 status = -EINVAL;
5934 goto out;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005935 }
5936
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005937 if (layout_count > 1) {
5938 /* We only handle a length one array at the moment. Any
5939 * further entries are just ignored. Note that this means
5940 * the client may see a response that is less than the
5941 * minimum it requested.
5942 */
5943 dprintk("%s: server responded with %d layouts, dropping tail\n",
5944 __func__, layout_count);
5945 }
5946
Fred Isaman808ba322016-10-04 15:02:21 -04005947out:
5948 res->status = status;
5949 return status;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005950out_overflow:
Fred Isaman808ba322016-10-04 15:02:21 -04005951 status = -EIO;
5952 goto out;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005953}
Andy Adamson863a3c62011-03-23 13:27:54 +00005954
Benny Halevycbe82602011-05-22 19:52:37 +03005955static int decode_layoutreturn(struct xdr_stream *xdr,
5956 struct nfs4_layoutreturn_res *res)
5957{
5958 __be32 *p;
5959 int status;
5960
5961 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5962 if (status)
5963 return status;
5964 p = xdr_inline_decode(xdr, 4);
5965 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005966 return -EIO;
Benny Halevycbe82602011-05-22 19:52:37 +03005967 res->lrs_present = be32_to_cpup(p);
5968 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005969 status = decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustfcd88432017-11-07 12:39:44 -05005970 else
5971 nfs4_stateid_copy(&res->stateid, &invalid_stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03005972 return status;
Benny Halevycbe82602011-05-22 19:52:37 +03005973}
5974
Andy Adamson863a3c62011-03-23 13:27:54 +00005975static int decode_layoutcommit(struct xdr_stream *xdr,
5976 struct rpc_rqst *req,
5977 struct nfs4_layoutcommit_res *res)
5978{
5979 __be32 *p;
5980 __u32 sizechanged;
5981 int status;
5982
5983 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005984 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005985 if (status)
5986 return status;
5987
5988 p = xdr_inline_decode(xdr, 4);
5989 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005990 return -EIO;
Andy Adamson863a3c62011-03-23 13:27:54 +00005991 sizechanged = be32_to_cpup(p);
5992
5993 if (sizechanged) {
5994 /* throw away new size */
5995 p = xdr_inline_decode(xdr, 8);
5996 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005997 return -EIO;
Andy Adamson863a3c62011-03-23 13:27:54 +00005998 }
5999 return 0;
Andy Adamson863a3c62011-03-23 13:27:54 +00006000}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006001
6002static int decode_test_stateid(struct xdr_stream *xdr,
6003 struct nfs41_test_stateid_res *res)
6004{
6005 __be32 *p;
6006 int status;
6007 int num_res;
6008
6009 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6010 if (status)
6011 return status;
6012
6013 p = xdr_inline_decode(xdr, 4);
6014 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05006015 return -EIO;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006016 num_res = be32_to_cpup(p++);
6017 if (num_res != 1)
Chuck Levereb72f482019-02-11 11:24:21 -05006018 return -EIO;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006019
6020 p = xdr_inline_decode(xdr, 4);
6021 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05006022 return -EIO;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006023 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006024
6025 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006026}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006027
6028static int decode_free_stateid(struct xdr_stream *xdr,
6029 struct nfs41_free_stateid_res *res)
6030{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006031 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006032 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006033}
Trond Myklebustcf805162016-11-15 14:56:07 -05006034#else
6035static inline
6036int decode_layoutreturn(struct xdr_stream *xdr,
6037 struct nfs4_layoutreturn_res *res)
6038{
6039 return 0;
6040}
Fred Isaman56f487f2016-09-21 11:43:41 -04006041
6042static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6043 struct nfs4_layoutget_res *res)
6044{
6045 return 0;
6046}
6047
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006048#endif /* CONFIG_NFS_V4_1 */
6049
Linus Torvalds1da177e2005-04-16 15:20:36 -07006050/*
Benny Halevy49c25592008-12-23 16:06:16 -05006051 * END OF "GENERIC" DECODE ROUTINES.
6052 */
6053
6054/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006055 * Decode OPEN_DOWNGRADE response
6056 */
Chuck Leverbf269552010-12-14 14:59:29 +00006057static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6058 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006059 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006060{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006061 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006062 struct compound_hdr hdr;
6063 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006064
Chuck Leverbf269552010-12-14 14:59:29 +00006065 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006066 if (status)
6067 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006068 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006069 if (status)
6070 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006071 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006072 if (status)
6073 goto out;
Trond Myklebustb6808142016-11-20 13:34:16 -05006074 if (res->lr_res) {
6075 status = decode_layoutreturn(xdr, res->lr_res);
6076 res->lr_ret = status;
6077 if (status)
6078 goto out;
6079 }
Chuck Leverbf269552010-12-14 14:59:29 +00006080 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006082 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083}
6084
6085/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006086 * Decode ACCESS response
6087 */
Chuck Leverbf269552010-12-14 14:59:29 +00006088static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006089 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006090{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006091 struct nfs4_accessres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092 struct compound_hdr hdr;
6093 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006094
Chuck Leverbf269552010-12-14 14:59:29 +00006095 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006096 if (status)
6097 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006098 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006099 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006100 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006101 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006102 if (status != 0)
6103 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006104 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006105 if (status != 0)
6106 goto out;
Trond Myklebust8bcbe7d2018-03-20 17:03:11 -04006107 if (res->fattr)
6108 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109out:
6110 return status;
6111}
6112
6113/*
6114 * Decode LOOKUP response
6115 */
Chuck Leverbf269552010-12-14 14:59:29 +00006116static int nfs4_xdr_dec_lookup(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_lookup_res *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);
6130 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006131 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006132 status = decode_lookup(xdr);
6133 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006134 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006135 status = decode_getfh(xdr, res->fh);
6136 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006138 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006139out:
6140 return status;
6141}
6142
6143/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07006144 * Decode LOOKUPP response
6145 */
6146static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6147 void *data)
6148{
6149 struct nfs4_lookupp_res *res = data;
6150 struct compound_hdr hdr;
6151 int status;
6152
6153 status = decode_compound_hdr(xdr, &hdr);
6154 if (status)
6155 goto out;
6156 status = decode_sequence(xdr, &res->seq_res, rqstp);
6157 if (status)
6158 goto out;
6159 status = decode_putfh(xdr);
6160 if (status)
6161 goto out;
6162 status = decode_lookupp(xdr);
6163 if (status)
6164 goto out;
6165 status = decode_getfh(xdr, res->fh);
6166 if (status)
6167 goto out;
6168 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6169out:
6170 return status;
6171}
6172
6173/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006174 * Decode LOOKUP_ROOT response
6175 */
Chuck Leverbf269552010-12-14 14:59:29 +00006176static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6177 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006178 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006179{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006180 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181 struct compound_hdr hdr;
6182 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006183
Chuck Leverbf269552010-12-14 14:59:29 +00006184 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006185 if (status)
6186 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006187 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006188 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006190 status = decode_putrootfh(xdr);
6191 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006193 status = decode_getfh(xdr, res->fh);
6194 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006195 status = decode_getfattr_label(xdr, res->fattr,
6196 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197out:
6198 return status;
6199}
6200
6201/*
6202 * Decode REMOVE response
6203 */
Chuck Leverbf269552010-12-14 14:59:29 +00006204static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006205 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006207 struct nfs_removeres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208 struct compound_hdr hdr;
6209 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006210
Chuck Leverbf269552010-12-14 14:59:29 +00006211 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006212 if (status)
6213 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006214 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006215 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006217 status = decode_putfh(xdr);
6218 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006219 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006220 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221out:
6222 return status;
6223}
6224
6225/*
6226 * Decode RENAME response
6227 */
Chuck Leverbf269552010-12-14 14:59:29 +00006228static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006229 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006230{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006231 struct nfs_renameres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006232 struct compound_hdr hdr;
6233 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006234
Chuck Leverbf269552010-12-14 14:59:29 +00006235 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006236 if (status)
6237 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006238 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006239 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006240 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006241 status = decode_putfh(xdr);
6242 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006244 status = decode_savefh(xdr);
6245 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006247 status = decode_putfh(xdr);
6248 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006249 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006250 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251out:
6252 return status;
6253}
6254
6255/*
6256 * Decode LINK response
6257 */
Chuck Leverbf269552010-12-14 14:59:29 +00006258static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006259 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006261 struct nfs4_link_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262 struct compound_hdr hdr;
6263 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006264
Chuck Leverbf269552010-12-14 14:59:29 +00006265 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006266 if (status)
6267 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006268 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006269 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006271 status = decode_putfh(xdr);
6272 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006274 status = decode_savefh(xdr);
6275 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006277 status = decode_putfh(xdr);
6278 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006279 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006280 status = decode_link(xdr, &res->cinfo);
6281 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006282 goto out;
6283 /*
6284 * Note order: OP_LINK leaves the directory as the current
6285 * filehandle.
6286 */
Chuck Leverbf269552010-12-14 14:59:29 +00006287 status = decode_restorefh(xdr);
6288 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006289 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006290 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006291out:
6292 return status;
6293}
6294
6295/*
6296 * Decode CREATE response
6297 */
Chuck Leverbf269552010-12-14 14:59:29 +00006298static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006299 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006300{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006301 struct nfs4_create_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006302 struct compound_hdr hdr;
6303 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006304
Chuck Leverbf269552010-12-14 14:59:29 +00006305 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006306 if (status)
6307 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006308 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006309 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006310 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006311 status = decode_putfh(xdr);
6312 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006313 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006314 status = decode_create(xdr, &res->dir_cinfo);
6315 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006316 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006317 status = decode_getfh(xdr, res->fh);
6318 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006319 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006320 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006321out:
6322 return status;
6323}
6324
6325/*
6326 * Decode SYMLINK response
6327 */
Chuck Leverbf269552010-12-14 14:59:29 +00006328static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006329 void *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006330{
Chuck Leverbf269552010-12-14 14:59:29 +00006331 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332}
6333
6334/*
6335 * Decode GETATTR response
6336 */
Chuck Leverbf269552010-12-14 14:59:29 +00006337static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006338 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006340 struct nfs4_getattr_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006341 struct compound_hdr hdr;
6342 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006343
Chuck Leverbf269552010-12-14 14:59:29 +00006344 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 if (status)
6346 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006347 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006348 if (status)
6349 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006350 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351 if (status)
6352 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006353 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354out:
6355 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006356}
6357
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006358/*
6359 * Encode an SETACL request
6360 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006361static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006362 const void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006363{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006364 const struct nfs_setaclargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006365 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006366 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006367 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006368
Chuck Lever9f06c712010-12-14 14:59:18 +00006369 encode_compound_hdr(xdr, req, &hdr);
6370 encode_sequence(xdr, &args->seq_args, &hdr);
6371 encode_putfh(xdr, args->fh, &hdr);
6372 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006373 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006374}
Andy Adamson05d564f2008-12-23 16:06:15 -05006375
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006376/*
6377 * Decode SETACL response
6378 */
6379static int
Chuck Leverbf269552010-12-14 14:59:29 +00006380nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006381 void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006382{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006383 struct nfs_setaclres *res = data;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006384 struct compound_hdr hdr;
6385 int status;
6386
Chuck Leverbf269552010-12-14 14:59:29 +00006387 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006388 if (status)
6389 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006390 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006391 if (status)
6392 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006393 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006394 if (status)
6395 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006396 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006397out:
6398 return status;
6399}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400
6401/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006402 * Decode GETACL response
6403 */
6404static int
Chuck Leverbf269552010-12-14 14:59:29 +00006405nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006406 void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006407{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006408 struct nfs_getaclres *res = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00006409 struct compound_hdr hdr;
6410 int status;
6411
Trond Myklebust331818f2012-02-03 18:30:53 -05006412 if (res->acl_scratch != NULL) {
6413 void *p = page_address(res->acl_scratch);
6414 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6415 }
Chuck Leverbf269552010-12-14 14:59:29 +00006416 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006417 if (status)
6418 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006419 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006420 if (status)
6421 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006422 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006423 if (status)
6424 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006425 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006426
6427out:
6428 return status;
6429}
6430
6431/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006432 * Decode CLOSE response
6433 */
Chuck Leverbf269552010-12-14 14:59:29 +00006434static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006435 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006436{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006437 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006438 struct compound_hdr hdr;
6439 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440
Chuck Leverbf269552010-12-14 14:59:29 +00006441 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006442 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);
Andy Adamson05d564f2008-12-23 16:06:15 -05006448 if (status)
6449 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006450 if (res->lr_res) {
6451 status = decode_layoutreturn(xdr, res->lr_res);
6452 res->lr_ret = status;
6453 if (status)
6454 goto out;
6455 }
Trond Myklebustd8d84982016-12-19 12:14:44 -05006456 if (res->fattr != NULL) {
6457 status = decode_getfattr(xdr, res->fattr, res->server);
6458 if (status != 0)
6459 goto out;
6460 }
Chuck Leverbf269552010-12-14 14:59:29 +00006461 status = decode_close(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006462out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006463 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464}
6465
6466/*
6467 * Decode OPEN response
6468 */
Chuck Leverbf269552010-12-14 14:59:29 +00006469static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006470 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006472 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006473 struct compound_hdr hdr;
6474 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475
Chuck Leverbf269552010-12-14 14:59:29 +00006476 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006477 if (status)
6478 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006479 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006480 if (status)
6481 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006482 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006483 if (status)
6484 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006485 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006486 if (status)
6487 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006488 status = decode_getfh(xdr, &res->fh);
6489 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006491 if (res->access_request)
6492 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006493 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Fred Isaman56f487f2016-09-21 11:43:41 -04006494 if (res->lg_res)
6495 decode_layoutget(xdr, rqstp, res->lg_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006496out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006497 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006498}
6499
6500/*
6501 * Decode OPEN_CONFIRM response
6502 */
Chuck Leverbf269552010-12-14 14:59:29 +00006503static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6504 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006505 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006506{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006507 struct nfs_open_confirmres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006508 struct compound_hdr hdr;
6509 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006510
Chuck Leverbf269552010-12-14 14:59:29 +00006511 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006512 if (status)
6513 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006514 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006515 if (status)
6516 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006517 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006519 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520}
6521
6522/*
6523 * Decode OPEN response
6524 */
Chuck Leverbf269552010-12-14 14:59:29 +00006525static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6526 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006527 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006528{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006529 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006530 struct compound_hdr hdr;
6531 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006532
Chuck Leverbf269552010-12-14 14:59:29 +00006533 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006534 if (status)
6535 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006536 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006537 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(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006543 if (status)
6544 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006545 if (res->access_request)
6546 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd12012-01-07 13:22:46 -05006547 decode_getfattr(xdr, res->f_attr, res->server);
Fred Isaman56f487f2016-09-21 11:43:41 -04006548 if (res->lg_res)
6549 decode_layoutget(xdr, rqstp, res->lg_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006551 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006552}
6553
6554/*
6555 * Decode SETATTR response
6556 */
Chuck Leverbf269552010-12-14 14:59:29 +00006557static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6558 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006559 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006560{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006561 struct nfs_setattrres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006562 struct compound_hdr hdr;
6563 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006564
Chuck Leverbf269552010-12-14 14:59:29 +00006565 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006566 if (status)
6567 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006568 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006569 if (status)
6570 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006571 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006572 if (status)
6573 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006574 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006575 if (status)
6576 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006577 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006578out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006579 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006580}
6581
6582/*
6583 * Decode LOCK response
6584 */
Chuck Leverbf269552010-12-14 14:59:29 +00006585static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006586 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006587{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006588 struct nfs_lock_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006589 struct compound_hdr hdr;
6590 int status;
6591
Chuck Leverbf269552010-12-14 14:59:29 +00006592 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593 if (status)
6594 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006595 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006596 if (status)
6597 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006598 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006599 if (status)
6600 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006601 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006602out:
6603 return status;
6604}
6605
6606/*
6607 * Decode LOCKT response
6608 */
Chuck Leverbf269552010-12-14 14:59:29 +00006609static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006610 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006611{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006612 struct nfs_lockt_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613 struct compound_hdr hdr;
6614 int status;
6615
Chuck Leverbf269552010-12-14 14:59:29 +00006616 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617 if (status)
6618 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006619 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006620 if (status)
6621 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006622 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006623 if (status)
6624 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006625 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006626out:
6627 return status;
6628}
6629
6630/*
6631 * Decode LOCKU response
6632 */
Chuck Leverbf269552010-12-14 14:59:29 +00006633static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006634 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006635{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006636 struct nfs_locku_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006637 struct compound_hdr hdr;
6638 int status;
6639
Chuck Leverbf269552010-12-14 14:59:29 +00006640 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006641 if (status)
6642 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006643 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006644 if (status)
6645 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006646 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647 if (status)
6648 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006649 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650out:
6651 return status;
6652}
6653
Chuck Leverbf269552010-12-14 14:59:29 +00006654static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6655 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006656{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006657 struct compound_hdr hdr;
6658 int status;
6659
Chuck Leverbf269552010-12-14 14:59:29 +00006660 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006661 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006662 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006663 return status;
6664}
6665
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666/*
6667 * Decode READLINK response
6668 */
Chuck Leverbf269552010-12-14 14:59:29 +00006669static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6670 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006671 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006673 struct nfs4_readlink_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006674 struct compound_hdr hdr;
6675 int status;
6676
Chuck Leverbf269552010-12-14 14:59:29 +00006677 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006678 if (status)
6679 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006680 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006681 if (status)
6682 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006683 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006684 if (status)
6685 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006686 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006687out:
6688 return status;
6689}
6690
6691/*
6692 * Decode READDIR response
6693 */
Chuck Leverbf269552010-12-14 14:59:29 +00006694static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006695 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006696{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006697 struct nfs4_readdir_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006698 struct compound_hdr hdr;
6699 int status;
6700
Chuck Leverbf269552010-12-14 14:59:29 +00006701 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006702 if (status)
6703 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006704 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006705 if (status)
6706 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006707 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006708 if (status)
6709 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006710 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006711out:
6712 return status;
6713}
6714
6715/*
6716 * Decode Read response
6717 */
Chuck Leverbf269552010-12-14 14:59:29 +00006718static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006719 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006720{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006721 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006722 struct compound_hdr hdr;
6723 int status;
6724
Chuck Leverbf269552010-12-14 14:59:29 +00006725 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006726 res->op_status = hdr.status;
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_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736 if (!status)
6737 status = res->count;
6738out:
6739 return status;
6740}
6741
6742/*
6743 * Decode WRITE response
6744 */
Chuck Leverbf269552010-12-14 14:59:29 +00006745static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006746 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006747{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006748 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749 struct compound_hdr hdr;
6750 int status;
6751
Chuck Leverbf269552010-12-14 14:59:29 +00006752 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006753 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006754 if (status)
6755 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006756 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006757 if (status)
6758 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006759 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006760 if (status)
6761 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006762 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006763 if (status)
6764 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006765 if (res->fattr)
Trond Myklebust6926afd12012-01-07 13:22:46 -05006766 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006767 if (!status)
6768 status = res->count;
6769out:
6770 return status;
6771}
6772
6773/*
6774 * Decode COMMIT response
6775 */
Chuck Leverbf269552010-12-14 14:59:29 +00006776static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006777 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006778{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006779 struct nfs_commitres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006780 struct compound_hdr hdr;
6781 int status;
6782
Chuck Leverbf269552010-12-14 14:59:29 +00006783 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006784 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006785 if (status)
6786 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006787 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006788 if (status)
6789 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006790 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006791 if (status)
6792 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006793 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006794out:
6795 return status;
6796}
6797
6798/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006799 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006800 */
Chuck Leverbf269552010-12-14 14:59:29 +00006801static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006802 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006803{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006804 struct nfs4_fsinfo_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006805 struct compound_hdr hdr;
6806 int status;
6807
Chuck Leverbf269552010-12-14 14:59:29 +00006808 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006809 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006810 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006811 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006812 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006813 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006814 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006815 return status;
6816}
6817
6818/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006819 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006820 */
Chuck Leverbf269552010-12-14 14:59:29 +00006821static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006822 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006823{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006824 struct nfs4_pathconf_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006825 struct compound_hdr hdr;
6826 int status;
6827
Chuck Leverbf269552010-12-14 14:59:29 +00006828 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006829 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006830 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006831 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006832 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006833 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006834 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006835 return status;
6836}
6837
6838/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006839 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006840 */
Chuck Leverbf269552010-12-14 14:59:29 +00006841static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006842 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006843{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006844 struct nfs4_statfs_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006845 struct compound_hdr hdr;
6846 int status;
6847
Chuck Leverbf269552010-12-14 14:59:29 +00006848 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006849 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006850 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006851 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006852 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006853 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006854 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006855 return status;
6856}
6857
6858/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006859 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006860 */
Chuck Leverbf269552010-12-14 14:59:29 +00006861static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6862 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006863 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006864{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006865 struct nfs4_server_caps_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006866 struct compound_hdr hdr;
6867 int status;
6868
Chuck Leverbf269552010-12-14 14:59:29 +00006869 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006870 if (status)
6871 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006872 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006873 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006874 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006875 status = decode_putfh(xdr);
6876 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006877 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006878 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006879out:
6880 return status;
6881}
6882
6883/*
6884 * Decode RENEW response
6885 */
Chuck Leverbf269552010-12-14 14:59:29 +00006886static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6887 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006888{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006889 struct compound_hdr hdr;
6890 int status;
6891
Chuck Leverbf269552010-12-14 14:59:29 +00006892 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006893 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006894 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006895 return status;
6896}
6897
6898/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006899 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006900 */
Chuck Leverbf269552010-12-14 14:59:29 +00006901static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6902 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006903 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006904{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006905 struct nfs4_setclientid_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006906 struct compound_hdr hdr;
6907 int status;
6908
Chuck Leverbf269552010-12-14 14:59:29 +00006909 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006910 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006911 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006912 return status;
6913}
6914
6915/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006916 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006917 */
Chuck Leverbf269552010-12-14 14:59:29 +00006918static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006919 struct xdr_stream *xdr,
6920 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006921{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006922 struct compound_hdr hdr;
6923 int status;
6924
Chuck Leverbf269552010-12-14 14:59:29 +00006925 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006926 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006927 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006928 return status;
6929}
6930
6931/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006932 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006933 */
Chuck Leverbf269552010-12-14 14:59:29 +00006934static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6935 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006936 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006937{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006938 struct nfs4_delegreturnres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006939 struct compound_hdr hdr;
6940 int status;
6941
Chuck Leverbf269552010-12-14 14:59:29 +00006942 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006943 if (status)
6944 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006945 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006946 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006947 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006948 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006949 if (status != 0)
6950 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05006951 if (res->lr_res) {
6952 status = decode_layoutreturn(xdr, res->lr_res);
6953 res->lr_ret = status;
6954 if (status)
6955 goto out;
6956 }
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05006957 if (res->fattr) {
6958 status = decode_getfattr(xdr, res->fattr, res->server);
6959 if (status != 0)
6960 goto out;
6961 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006962 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006963out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006964 return status;
6965}
6966
Trond Myklebust683b57b2006-06-09 09:34:22 -04006967/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006968 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006969 */
Chuck Leverbf269552010-12-14 14:59:29 +00006970static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6971 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006972 void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006973{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006974 struct nfs4_fs_locations_res *res = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04006975 struct compound_hdr hdr;
6976 int status;
6977
Chuck Leverbf269552010-12-14 14:59:29 +00006978 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006979 if (status)
6980 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006981 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006982 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006983 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006984 status = decode_putfh(xdr);
6985 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006986 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006987 if (res->migration) {
6988 xdr_enter_page(xdr, PAGE_SIZE);
6989 status = decode_getfattr_generic(xdr,
6990 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006991 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006992 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006993 if (status)
6994 goto out;
6995 if (res->renew)
6996 status = decode_renew(xdr);
6997 } else {
6998 status = decode_lookup(xdr);
6999 if (status)
7000 goto out;
7001 xdr_enter_page(xdr, PAGE_SIZE);
7002 status = decode_getfattr_generic(xdr,
7003 &res->fs_locations->fattr,
7004 NULL, res->fs_locations,
7005 NULL, res->fs_locations->server);
7006 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04007007out:
7008 return status;
7009}
7010
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007011/*
7012 * Decode SECINFO response
7013 */
7014static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7015 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007016 void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007017{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007018 struct nfs4_secinfo_res *res = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007019 struct compound_hdr hdr;
7020 int status;
7021
7022 status = decode_compound_hdr(xdr, &hdr);
7023 if (status)
7024 goto out;
7025 status = decode_sequence(xdr, &res->seq_res, rqstp);
7026 if (status)
7027 goto out;
7028 status = decode_putfh(xdr);
7029 if (status)
7030 goto out;
7031 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007032out:
7033 return status;
7034}
7035
Chuck Lever44c99932013-10-17 14:13:30 -04007036/*
7037 * Decode FSID_PRESENT response
7038 */
7039static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7040 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007041 void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04007042{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007043 struct nfs4_fsid_present_res *res = data;
Chuck Lever44c99932013-10-17 14:13:30 -04007044 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_getfh(xdr, res->fh);
7057 if (status)
7058 goto out;
7059 if (res->renew)
7060 status = decode_renew(xdr);
7061out:
7062 return status;
7063}
7064
Benny Halevy99fe60d2009-04-01 09:22:29 -04007065#if defined(CONFIG_NFS_V4_1)
7066/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007067 * Decode BIND_CONN_TO_SESSION response
7068 */
7069static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7070 struct xdr_stream *xdr,
7071 void *res)
7072{
7073 struct compound_hdr hdr;
7074 int status;
7075
7076 status = decode_compound_hdr(xdr, &hdr);
7077 if (!status)
7078 status = decode_bind_conn_to_session(xdr, res);
7079 return status;
7080}
7081
7082/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007083 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007084 */
Chuck Leverbf269552010-12-14 14:59:29 +00007085static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7086 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007087 void *res)
7088{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007089 struct compound_hdr hdr;
7090 int status;
7091
Chuck Leverbf269552010-12-14 14:59:29 +00007092 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007093 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007094 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007095 return status;
7096}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007097
7098/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007099 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007100 */
Chuck Leverbf269552010-12-14 14:59:29 +00007101static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7102 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007103 void *res)
Andy Adamsonfc931582009-04-01 09:22:31 -04007104{
Andy Adamsonfc931582009-04-01 09:22:31 -04007105 struct compound_hdr hdr;
7106 int status;
7107
Chuck Leverbf269552010-12-14 14:59:29 +00007108 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007109 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007110 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007111 return status;
7112}
7113
7114/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007115 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007116 */
Chuck Leverbf269552010-12-14 14:59:29 +00007117static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7118 struct xdr_stream *xdr,
7119 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007120{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007121 struct compound_hdr hdr;
7122 int status;
7123
Chuck Leverbf269552010-12-14 14:59:29 +00007124 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007125 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007126 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007127 return status;
7128}
7129
7130/*
Trond Myklebust66245532012-05-25 17:18:09 -04007131 * Decode DESTROY_CLIENTID response
7132 */
7133static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7134 struct xdr_stream *xdr,
7135 void *res)
7136{
7137 struct compound_hdr hdr;
7138 int status;
7139
7140 status = decode_compound_hdr(xdr, &hdr);
7141 if (!status)
7142 status = decode_destroy_clientid(xdr, res);
7143 return status;
7144}
7145
7146/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007147 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007148 */
Chuck Leverbf269552010-12-14 14:59:29 +00007149static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7150 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007151 void *res)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007152{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007153 struct compound_hdr hdr;
7154 int status;
7155
Chuck Leverbf269552010-12-14 14:59:29 +00007156 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007157 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007158 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007159 return status;
7160}
7161
Donald Buczek0efb01b2019-07-07 21:26:08 +02007162#endif
7163
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007164/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007165 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007166 */
Chuck Leverbf269552010-12-14 14:59:29 +00007167static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7168 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007169 void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04007170{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007171 struct nfs4_get_lease_time_res *res = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04007172 struct compound_hdr hdr;
7173 int status;
7174
Chuck Leverbf269552010-12-14 14:59:29 +00007175 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007176 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007177 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007178 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007179 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007180 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007181 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007182 return status;
7183}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007184
Donald Buczek0efb01b2019-07-07 21:26:08 +02007185#ifdef CONFIG_NFS_V4_1
7186
Ricardo Labiaga180197532009-12-05 16:08:40 -05007187/*
7188 * Decode RECLAIM_COMPLETE response
7189 */
Chuck Leverbf269552010-12-14 14:59:29 +00007190static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7191 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007192 void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05007193{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007194 struct nfs41_reclaim_complete_res *res = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05007195 struct compound_hdr hdr;
7196 int status;
7197
Chuck Leverbf269552010-12-14 14:59:29 +00007198 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007199 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007200 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007201 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307202 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007203 return status;
7204}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007205
7206/*
7207 * Decode GETDEVINFO response
7208 */
Chuck Leverbf269552010-12-14 14:59:29 +00007209static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7210 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007211 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007212{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007213 struct nfs4_getdeviceinfo_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007214 struct compound_hdr hdr;
7215 int status;
7216
Chuck Leverbf269552010-12-14 14:59:29 +00007217 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007218 if (status != 0)
7219 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007220 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007221 if (status != 0)
7222 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007223 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007224out:
7225 return status;
7226}
7227
7228/*
7229 * Decode LAYOUTGET response
7230 */
Chuck Leverbf269552010-12-14 14:59:29 +00007231static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7232 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007233 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007234{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007235 struct nfs4_layoutget_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007236 struct compound_hdr hdr;
7237 int status;
7238
Chuck Leverbf269552010-12-14 14:59:29 +00007239 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007240 if (status)
7241 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007242 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007243 if (status)
7244 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007245 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007246 if (status)
7247 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007248 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007249out:
7250 return status;
7251}
Andy Adamson863a3c62011-03-23 13:27:54 +00007252
7253/*
Benny Halevycbe82602011-05-22 19:52:37 +03007254 * Decode LAYOUTRETURN response
7255 */
7256static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7257 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007258 void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03007259{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007260 struct nfs4_layoutreturn_res *res = data;
Benny Halevycbe82602011-05-22 19:52:37 +03007261 struct compound_hdr hdr;
7262 int status;
7263
7264 status = decode_compound_hdr(xdr, &hdr);
7265 if (status)
7266 goto out;
7267 status = decode_sequence(xdr, &res->seq_res, rqstp);
7268 if (status)
7269 goto out;
7270 status = decode_putfh(xdr);
7271 if (status)
7272 goto out;
7273 status = decode_layoutreturn(xdr, res);
7274out:
7275 return status;
7276}
7277
7278/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007279 * Decode LAYOUTCOMMIT response
7280 */
7281static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7282 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007283 void *data)
Andy Adamson863a3c62011-03-23 13:27:54 +00007284{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007285 struct nfs4_layoutcommit_res *res = data;
Andy Adamson863a3c62011-03-23 13:27:54 +00007286 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_layoutcommit(xdr, rqstp, res);
7299 if (status)
7300 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05007301 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007302out:
7303 return status;
7304}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007305
7306/*
7307 * Decode SECINFO_NO_NAME response
7308 */
7309static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7310 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007311 void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007312{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007313 struct nfs4_secinfo_res *res = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007314 struct compound_hdr hdr;
7315 int status;
7316
7317 status = decode_compound_hdr(xdr, &hdr);
7318 if (status)
7319 goto out;
7320 status = decode_sequence(xdr, &res->seq_res, rqstp);
7321 if (status)
7322 goto out;
7323 status = decode_putrootfh(xdr);
7324 if (status)
7325 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007326 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007327out:
7328 return status;
7329}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007330
7331/*
7332 * Decode TEST_STATEID response
7333 */
7334static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7335 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007336 void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04007337{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007338 struct nfs41_test_stateid_res *res = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -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_test_stateid(xdr, res);
7349out:
7350 return status;
7351}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007352
7353/*
7354 * Decode FREE_STATEID response
7355 */
7356static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7357 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007358 void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007359{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007360 struct nfs41_free_stateid_res *res = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007361 struct compound_hdr hdr;
7362 int status;
7363
7364 status = decode_compound_hdr(xdr, &hdr);
7365 if (status)
7366 goto out;
7367 status = decode_sequence(xdr, &res->seq_res, rqstp);
7368 if (status)
7369 goto out;
7370 status = decode_free_stateid(xdr, res);
7371out:
7372 return status;
7373}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007374#endif /* CONFIG_NFS_V4_1 */
7375
Chuck Lever573c4e12010-12-14 14:58:11 +00007376/**
7377 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7378 * the local page cache.
7379 * @xdr: XDR stream where entry resides
7380 * @entry: buffer to fill in with entry data
7381 * @plus: boolean indicating whether this should be a readdirplus entry
7382 *
7383 * Returns zero if successful, otherwise a negative errno value is
7384 * returned.
7385 *
7386 * This function is not invoked during READDIR reply decoding, but
7387 * rather whenever an application invokes the getdents(2) system call
7388 * on a directory already in our cache.
7389 */
7390int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -04007391 bool plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007392{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007393 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007394 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007395 uint32_t len;
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007396 uint64_t new_cookie;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007397 __be32 *p = xdr_inline_decode(xdr, 4);
7398 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007399 return -EAGAIN;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007400 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007401 p = xdr_inline_decode(xdr, 4);
7402 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007403 return -EAGAIN;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007404 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007405 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007406 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007407 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007408 }
7409
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007410 p = xdr_inline_decode(xdr, 12);
7411 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007412 return -EAGAIN;
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007413 p = xdr_decode_hyper(p, &new_cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007414 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007415
Trond Myklebust9af8c222010-10-24 11:52:55 -04007416 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007417 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007418 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007419 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007420
7421 /*
7422 * In case the server doesn't return an inode number,
7423 * we fake one here. (We don't use inode number 0,
7424 * since glibc seems to choke on it...)
7425 */
7426 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007427 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007428
Trond Myklebust9af8c222010-10-24 11:52:55 -04007429 if (decode_attr_bitmap(xdr, bitmap) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05007430 return -EAGAIN;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007431
Trond Myklebust256e48b2012-06-21 11:18:13 -04007432 if (decode_attr_length(xdr, &len, &savep) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05007433 return -EAGAIN;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007434
Chuck Lever573c4e12010-12-14 14:58:11 +00007435 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007436 NULL, entry->label, entry->server) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05007437 return -EAGAIN;
Trond Myklebust28331a42011-04-27 13:47:52 -04007438 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7439 entry->ino = entry->fattr->mounted_on_fileid;
7440 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007441 entry->ino = entry->fattr->fileid;
7442
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007443 entry->d_type = DT_UNKNOWN;
7444 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7445 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7446
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007447 entry->prev_cookie = entry->cookie;
7448 entry->cookie = new_cookie;
7449
Chuck Lever573c4e12010-12-14 14:58:11 +00007450 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007451}
7452
7453/*
7454 * We need to translate between nfs status return values and
7455 * the local errno values which may not be the same.
7456 */
7457static struct {
7458 int stat;
7459 int errno;
7460} nfs_errtbl[] = {
7461 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007462 { NFS4ERR_PERM, -EPERM },
7463 { NFS4ERR_NOENT, -ENOENT },
7464 { NFS4ERR_IO, -errno_NFSERR_IO},
7465 { NFS4ERR_NXIO, -ENXIO },
7466 { NFS4ERR_ACCESS, -EACCES },
7467 { NFS4ERR_EXIST, -EEXIST },
7468 { NFS4ERR_XDEV, -EXDEV },
7469 { NFS4ERR_NOTDIR, -ENOTDIR },
7470 { NFS4ERR_ISDIR, -EISDIR },
7471 { NFS4ERR_INVAL, -EINVAL },
7472 { NFS4ERR_FBIG, -EFBIG },
7473 { NFS4ERR_NOSPC, -ENOSPC },
7474 { NFS4ERR_ROFS, -EROFS },
7475 { NFS4ERR_MLINK, -EMLINK },
7476 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7477 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7478 { NFS4ERR_DQUOT, -EDQUOT },
7479 { NFS4ERR_STALE, -ESTALE },
7480 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007481 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7482 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7483 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007484 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007485 { NFS4ERR_BADTYPE, -EBADTYPE },
7486 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007487 { NFS4ERR_SYMLINK, -ELOOP },
7488 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7489 { NFS4ERR_DEADLOCK, -EDEADLK },
Frank van der Linden3e1f0212020-06-23 22:38:56 +00007490 { NFS4ERR_NOXATTR, -ENODATA },
7491 { NFS4ERR_XATTR2BIG, -E2BIG },
Benny Halevy856dff32008-03-31 17:39:06 +03007492 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007493};
7494
7495/*
7496 * Convert an NFS error code to a local one.
7497 * This one is used jointly by NFSv2 and NFSv3.
7498 */
7499static int
David Howells0a8ea432006-08-22 20:06:08 -04007500nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007501{
7502 int i;
7503 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7504 if (nfs_errtbl[i].stat == stat)
7505 return nfs_errtbl[i].errno;
7506 }
7507 if (stat <= 10000 || stat > 10100) {
7508 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007509 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007510 }
7511 /* If we cannot translate the error, the recovery routines should
7512 * handle it.
7513 * Note: remaining NFSv4 error codes have values > 10000, so should
7514 * not conflict with native Linux error codes.
7515 */
Benny Halevy856dff32008-03-31 17:39:06 +03007516 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007517}
7518
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007519#ifdef CONFIG_NFS_V4_2
7520#include "nfs42xdr.c"
7521#endif /* CONFIG_NFS_V4_2 */
7522
Linus Torvalds1da177e2005-04-16 15:20:36 -07007523#define PROC(proc, argtype, restype) \
7524[NFSPROC4_CLNT_##proc] = { \
7525 .p_proc = NFSPROC4_COMPOUND, \
Christoph Hellwigfcc85812017-05-08 10:01:49 +02007526 .p_encode = nfs4_xdr_##argtype, \
Christoph Hellwigfc016482017-05-08 15:09:02 +02007527 .p_decode = nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007528 .p_arglen = NFS4_##argtype##_sz, \
7529 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007530 .p_statidx = NFSPROC4_CLNT_##proc, \
7531 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007532}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007533
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007534#define STUB(proc) \
7535[NFSPROC4_CLNT_##proc] = { \
7536 .p_name = #proc, \
7537}
7538
Trond Myklebust8634ef52018-01-06 09:53:49 -05007539#if defined(CONFIG_NFS_V4_1)
7540#define PROC41(proc, argtype, restype) \
7541 PROC(proc, argtype, restype)
7542#else
7543#define PROC41(proc, argtype, restype) \
7544 STUB(proc)
7545#endif
7546
7547#if defined(CONFIG_NFS_V4_2)
7548#define PROC42(proc, argtype, restype) \
7549 PROC(proc, argtype, restype)
7550#else
7551#define PROC42(proc, argtype, restype) \
7552 STUB(proc)
7553#endif
7554
Christoph Hellwig511e9362017-05-12 15:36:49 +02007555const struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007556 PROC(READ, enc_read, dec_read),
7557 PROC(WRITE, enc_write, dec_write),
7558 PROC(COMMIT, enc_commit, dec_commit),
7559 PROC(OPEN, enc_open, dec_open),
7560 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7561 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7562 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7563 PROC(CLOSE, enc_close, dec_close),
7564 PROC(SETATTR, enc_setattr, dec_setattr),
7565 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7566 PROC(RENEW, enc_renew, dec_renew),
7567 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7568 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7569 PROC(LOCK, enc_lock, dec_lock),
7570 PROC(LOCKT, enc_lockt, dec_lockt),
7571 PROC(LOCKU, enc_locku, dec_locku),
7572 PROC(ACCESS, enc_access, dec_access),
7573 PROC(GETATTR, enc_getattr, dec_getattr),
7574 PROC(LOOKUP, enc_lookup, dec_lookup),
7575 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7576 PROC(REMOVE, enc_remove, dec_remove),
7577 PROC(RENAME, enc_rename, dec_rename),
7578 PROC(LINK, enc_link, dec_link),
7579 PROC(SYMLINK, enc_symlink, dec_symlink),
7580 PROC(CREATE, enc_create, dec_create),
7581 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7582 PROC(STATFS, enc_statfs, dec_statfs),
7583 PROC(READLINK, enc_readlink, dec_readlink),
7584 PROC(READDIR, enc_readdir, dec_readdir),
7585 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7586 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7587 PROC(GETACL, enc_getacl, dec_getacl),
7588 PROC(SETACL, enc_setacl, dec_setacl),
7589 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7590 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007591 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007592 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007593 PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7594 PROC41(CREATE_SESSION, enc_create_session, dec_create_session),
7595 PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7596 PROC41(SEQUENCE, enc_sequence, dec_sequence),
Donald Buczek0efb01b2019-07-07 21:26:08 +02007597 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007598 PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete),
7599 PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7600 PROC41(LAYOUTGET, enc_layoutget, dec_layoutget),
7601 PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7602 PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7603 PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7604 PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7605 PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007606 STUB(GETDEVICELIST),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007607 PROC41(BIND_CONN_TO_SESSION,
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007608 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007609 PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid),
7610 PROC42(SEEK, enc_seek, dec_seek),
7611 PROC42(ALLOCATE, enc_allocate, dec_allocate),
7612 PROC42(DEALLOCATE, enc_deallocate, dec_deallocate),
7613 PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
7614 PROC42(CLONE, enc_clone, dec_clone),
7615 PROC42(COPY, enc_copy, dec_copy),
Olga Kornievskaiacb95dee2018-07-09 15:13:29 -04007616 PROC42(OFFLOAD_CANCEL, enc_offload_cancel, dec_offload_cancel),
Olga Kornievskaia04915672019-06-04 16:14:30 -04007617 PROC42(COPY_NOTIFY, enc_copy_notify, dec_copy_notify),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007618 PROC(LOOKUPP, enc_lookupp, dec_lookupp),
Trond Myklebust3eb86092019-02-08 10:31:05 -05007619 PROC42(LAYOUTERROR, enc_layouterror, dec_layouterror),
Frank van der Linden3e1f0212020-06-23 22:38:56 +00007620 PROC42(GETXATTR, enc_getxattr, dec_getxattr),
7621 PROC42(SETXATTR, enc_setxattr, dec_setxattr),
7622 PROC42(LISTXATTRS, enc_listxattrs, dec_listxattrs),
7623 PROC42(REMOVEXATTR, enc_removexattr, dec_removexattr),
Anna Schumakerc5675522014-05-28 13:41:22 -04007624 PROC42(READ_PLUS, enc_read_plus, dec_read_plus),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007625};
7626
Christoph Hellwigc5518582017-05-08 23:27:10 +02007627static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
Trond Myklebusta613fa12012-01-20 13:53:56 -05007628const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007629 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007630 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Christoph Hellwigc5518582017-05-08 23:27:10 +02007631 .procs = nfs4_procedures,
7632 .counts = nfs_version4_counts,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007633};
7634
7635/*
7636 * Local variables:
7637 * c-basic-offset: 8
7638 * End:
7639 */