blob: 936c57779ff4d08291463042b4b367701d9a2aba [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 Myklebust95b72eb2012-04-20 19:24:51 -040087#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050088#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040089#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
91#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
92#define op_encode_hdr_maxsz (1)
93#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040094#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
95#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
96#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
97#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
99 (NFS4_FHSIZE >> 2))
100#define decode_putfh_maxsz (op_decode_hdr_maxsz)
101#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
102#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
103#define encode_getfh_maxsz (op_encode_hdr_maxsz)
104#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
105 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -0400106#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +0000107#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Trond Myklebust36b37432018-03-20 17:03:10 -0400108#define nfstime4_maxsz (3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
110#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400111#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
112#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
David Quigleyaa9c2662013-05-22 12:50:44 -0400113#ifdef CONFIG_NFS_V4_SECURITY_LABEL
114/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
115#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
David Quigleyaa9c2662013-05-22 12:50:44 -0400116#else
117#define nfs4_label_maxsz 0
David Quigleyaa9c2662013-05-22 12:50:44 -0400118#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400119/* We support only one layout type per file system */
120#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000121/* This is based on getfattr, which uses the most attributes: */
122#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebust36b37432018-03-20 17:03:10 -0400123 3*nfstime4_maxsz + \
124 nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400125 nfs4_group_maxsz + nfs4_label_maxsz + \
126 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000127#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
128 nfs4_fattr_value_maxsz)
129#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400130#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
131 1 + 2 + 1 + \
132 nfs4_owner_maxsz + \
133 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400134 nfs4_label_maxsz + \
Trond Myklebust36b37432018-03-20 17:03:10 -0400135 1 + nfstime4_maxsz + \
136 1 + nfstime4_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#define encode_savefh_maxsz (op_encode_hdr_maxsz)
138#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400139#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
140#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200141#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400142/* The 5 accounts for the PNFS attributes, and assumes that at most three
143 * layout types will be returned.
144 */
145#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
146 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
148#define decode_renew_maxsz (op_decode_hdr_maxsz)
149#define encode_setclientid_maxsz \
150 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500151 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400152 /* client name */ \
153 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500154 1 /* sc_prog */ + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500155 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
156 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500157 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158#define decode_setclientid_maxsz \
159 (op_decode_hdr_maxsz + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500160 2 /* clientid */ + \
161 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
162 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
163 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164#define encode_setclientid_confirm_maxsz \
165 (op_encode_hdr_maxsz + \
166 3 + (NFS4_VERIFIER_SIZE >> 2))
167#define decode_setclientid_confirm_maxsz \
168 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400169#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
170#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700171#define encode_lookupp_maxsz (op_encode_hdr_maxsz)
172#define decode_lookupp_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400173#define encode_share_access_maxsz \
174 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500175#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400176#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
177#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
178#define encode_open_maxsz (op_encode_hdr_maxsz + \
179 2 + encode_share_access_maxsz + 2 + \
180 open_owner_id_maxsz + \
181 encode_opentype_maxsz + \
182 encode_claim_null_maxsz)
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500183#define decode_space_limit_maxsz (3)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400184#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400185#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500186 decode_space_limit_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400187 decode_ace_maxsz)
188#define decode_change_info_maxsz (5)
189#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400190 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400191 decode_change_info_maxsz + 1 + \
192 nfs4_fattr_bitmap_maxsz + \
193 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400194#define encode_open_confirm_maxsz \
195 (op_encode_hdr_maxsz + \
196 encode_stateid_maxsz + 1)
197#define decode_open_confirm_maxsz \
198 (op_decode_hdr_maxsz + \
199 decode_stateid_maxsz)
200#define encode_open_downgrade_maxsz \
201 (op_encode_hdr_maxsz + \
202 encode_stateid_maxsz + 1 + \
203 encode_share_access_maxsz)
204#define decode_open_downgrade_maxsz \
205 (op_decode_hdr_maxsz + \
206 decode_stateid_maxsz)
207#define encode_close_maxsz (op_encode_hdr_maxsz + \
208 1 + encode_stateid_maxsz)
209#define decode_close_maxsz (op_decode_hdr_maxsz + \
210 decode_stateid_maxsz)
211#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
212 encode_stateid_maxsz + \
213 encode_attrs_maxsz)
214#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
215 nfs4_fattr_bitmap_maxsz)
216#define encode_read_maxsz (op_encode_hdr_maxsz + \
217 encode_stateid_maxsz + 3)
Chuck Lever02ef04e2019-02-11 11:25:25 -0500218#define decode_read_maxsz (op_decode_hdr_maxsz + 2 + 1)
Trond Myklebust9104a552007-07-17 21:52:42 -0400219#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400220 2 + encode_verifier_maxsz + 5 + \
221 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400222#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Chuck Lever02ef04e2019-02-11 11:25:25 -0500223 decode_verifier_maxsz + 1)
Trond Myklebust9104a552007-07-17 21:52:42 -0400224#define encode_readlink_maxsz (op_encode_hdr_maxsz)
Chuck Lever02ef04e2019-02-11 11:25:25 -0500225#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1 + 1)
Trond Myklebust9104a552007-07-17 21:52:42 -0400226#define encode_write_maxsz (op_encode_hdr_maxsz + \
227 encode_stateid_maxsz + 4)
228#define decode_write_maxsz (op_decode_hdr_maxsz + \
229 2 + decode_verifier_maxsz)
230#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
231#define decode_commit_maxsz (op_decode_hdr_maxsz + \
232 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233#define encode_remove_maxsz (op_encode_hdr_maxsz + \
234 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400235#define decode_remove_maxsz (op_decode_hdr_maxsz + \
236 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237#define encode_rename_maxsz (op_encode_hdr_maxsz + \
238 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400239#define decode_rename_maxsz (op_decode_hdr_maxsz + \
240 decode_change_info_maxsz + \
241 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242#define encode_link_maxsz (op_encode_hdr_maxsz + \
243 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400244#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400245#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400246#define encode_lock_maxsz (op_encode_hdr_maxsz + \
247 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400248 1 + encode_stateid_maxsz + 1 + \
249 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400250#define decode_lock_denied_maxsz \
251 (8 + decode_lockowner_maxsz)
252#define decode_lock_maxsz (op_decode_hdr_maxsz + \
253 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400254#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
255 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400256#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
257 decode_lock_denied_maxsz)
258#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
259 encode_stateid_maxsz + \
260 4)
261#define decode_locku_maxsz (op_decode_hdr_maxsz + \
262 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400263#define encode_release_lockowner_maxsz \
264 (op_encode_hdr_maxsz + \
265 encode_lockowner_maxsz)
266#define decode_release_lockowner_maxsz \
267 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400268#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
269#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
271 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400272 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000273 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
275#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400276 1 + 2 + nfs4_name_maxsz + \
277 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400278#define decode_create_maxsz (op_decode_hdr_maxsz + \
279 decode_change_info_maxsz + \
280 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400281#define encode_statfs_maxsz (encode_getattr_maxsz)
282#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
284#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400285#define encode_getacl_maxsz (encode_getattr_maxsz)
286#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
Chuck Lever02ef04e2019-02-11 11:25:25 -0500287 nfs4_fattr_bitmap_maxsz + 1 + 1)
Trond Myklebust9104a552007-07-17 21:52:42 -0400288#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
289 encode_stateid_maxsz + 3)
290#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400291#define encode_fs_locations_maxsz \
292 (encode_getattr_maxsz)
293#define decode_fs_locations_maxsz \
Chuck Lever02ef04e2019-02-11 11:25:25 -0500294 (1)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000295#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400296#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 -0400297
298#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400299#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500300#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
301 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400302
Benny Halevy99fe60d2009-04-01 09:22:29 -0400303#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
304 encode_verifier_maxsz + \
305 1 /* co_ownerid.len */ + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400306 /* eia_clientowner */ \
307 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400308 1 /* flags */ + \
309 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400310 /* max is SP4_MACH_CRED (for now) */ + \
311 1 + NFS4_OP_MAP_NUM_WORDS + \
312 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500313 1 /* implementation id array of size 1 */ + \
314 1 /* nii_domain */ + \
315 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
316 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500317 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500318 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400319#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
320 2 /* eir_clientid */ + \
321 1 /* eir_sequenceid */ + \
322 1 /* eir_flags */ + \
323 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400324 /* max is SP4_MACH_CRED (for now) */ + \
325 1 + NFS4_OP_MAP_NUM_WORDS + \
326 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400327 2 /* eir_server_owner.so_minor_id */ + \
328 /* eir_server_owner.so_major_id<> */ \
329 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
330 /* eir_server_scope<> */ \
331 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
332 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500333 1 /* nii_domain */ + \
334 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
335 1 /* nii_name */ + \
336 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
337 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400338#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
339#define decode_channel_attrs_maxsz (6 + \
340 1 /* ca_rdma_ird.len */ + \
341 1 /* ca_rdma_ird */)
342#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
343 2 /* csa_clientid */ + \
344 1 /* csa_sequence */ + \
345 1 /* csa_flags */ + \
346 encode_channel_attrs_maxsz + \
347 encode_channel_attrs_maxsz + \
348 1 /* csa_cb_program */ + \
349 1 /* csa_sec_parms.len (1) */ + \
350 1 /* cb_secflavor (AUTH_SYS) */ + \
351 1 /* stamp */ + \
352 1 /* machinename.len */ + \
353 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
354 1 /* uid */ + \
355 1 /* gid */ + \
356 1 /* gids.len (0) */)
357#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
358 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
359 1 /* csr_sequence */ + \
360 1 /* csr_flags */ + \
361 decode_channel_attrs_maxsz + \
362 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400363#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
364 /* bctsa_sessid */ \
365 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
366 1 /* bctsa_dir */ + \
367 1 /* bctsa_use_conn_in_rdma_mode */)
368#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
369 /* bctsr_sessid */ \
370 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
371 1 /* bctsr_dir */ + \
372 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400373#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
374#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400375#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
376#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400377#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
378 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
379#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
380 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500381#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
382#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700383#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
384 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
385 1 /* layout type */ + \
386 1 /* maxcount */ + \
387 1 /* bitmap size */ + \
388 1 /* notification bitmap length */ + \
389 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400390#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
391 1 /* layout type */ + \
392 1 /* opaque devaddr4 length */ + \
393 /* devaddr4 payload is read into page */ \
394 1 /* notification bitmap length */ + \
Chuck Lever02ef04e2019-02-11 11:25:25 -0500395 1 /* notification bitmap, word 0 */ + \
396 1 /* possible XDR padding */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400397#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
398 encode_stateid_maxsz)
399#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
400 decode_stateid_maxsz + \
Chuck Lever02ef04e2019-02-11 11:25:25 -0500401 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
Andy Adamson863a3c62011-03-23 13:27:54 +0000402#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
403 2 /* offset */ + \
404 2 /* length */ + \
405 1 /* reclaim */ + \
406 encode_stateid_maxsz + \
407 1 /* new offset (true) */ + \
408 2 /* last byte written */ + \
409 1 /* nt_timechanged (false) */ + \
410 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500411 1 /* layoutupdate4 opaqueue len */)
412 /* the actual content of layoutupdate4 should
413 be allocated by drivers and spliced in
414 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000415#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300416#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
417 encode_stateid_maxsz + \
Trond Myklebust6669cb82015-08-27 20:43:20 -0400418 1 + \
419 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
Benny Halevycbe82602011-05-22 19:52:37 +0300420#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
421 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400422#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
423#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400424#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
425 XDR_QUADLEN(NFS4_STATEID_SIZE))
426#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400427#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
428 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400429#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430#else /* CONFIG_NFS_V4_1 */
431#define encode_sequence_maxsz 0
432#define decode_sequence_maxsz 0
Trond Myklebustcf805162016-11-15 14:56:07 -0500433#define encode_layoutreturn_maxsz 0
434#define decode_layoutreturn_maxsz 0
Fred Isaman56f487f2016-09-21 11:43:41 -0400435#define encode_layoutget_maxsz 0
436#define decode_layoutget_maxsz 0
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437#endif /* CONFIG_NFS_V4_1 */
438
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
440#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
441#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400444 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400446 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400448 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400450 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400452 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400454 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400456 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400460 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400462 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400464 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400466 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400468 encode_write_maxsz + \
Trond Myklebust4f9838c72005-10-27 22:12:44 -0400469 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400471 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400473 decode_write_maxsz + \
Trond Myklebust4f9838c72005-10-27 22:12:44 -0400474 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400476 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400478 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400480 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400482 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400484 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400485 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400486 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400487 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400488 encode_getfh_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400489 encode_getattr_maxsz + \
490 encode_layoutget_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400493 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400494 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400495 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400496 decode_getfh_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400497 decode_getattr_maxsz + \
498 decode_layoutget_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400499#define NFS4_enc_open_confirm_sz \
500 (compound_encode_hdr_maxsz + \
501 encode_putfh_maxsz + \
502 encode_open_confirm_maxsz)
503#define NFS4_dec_open_confirm_sz \
504 (compound_decode_hdr_maxsz + \
505 decode_putfh_maxsz + \
506 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400508 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400510 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400511 encode_access_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400512 encode_getattr_maxsz + \
513 encode_layoutget_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400515 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400517 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400518 decode_access_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400519 decode_getattr_maxsz + \
520 decode_layoutget_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521#define NFS4_enc_open_downgrade_sz \
522 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400523 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400524 encode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500525 encode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400526 encode_open_downgrade_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527#define NFS4_dec_open_downgrade_sz \
528 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400529 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400530 decode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500531 decode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400532 decode_open_downgrade_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400533#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400535 encode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500536 encode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400537 encode_close_maxsz + \
538 encode_getattr_maxsz)
539#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400540 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400541 decode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500542 decode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400543 decode_close_maxsz + \
544 decode_getattr_maxsz)
545#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400547 encode_putfh_maxsz + \
548 encode_setattr_maxsz + \
549 encode_getattr_maxsz)
550#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400551 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400552 decode_putfh_maxsz + \
553 decode_setattr_maxsz + \
554 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 encode_putfh_maxsz + \
558 encode_fsinfo_maxsz)
559#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400560 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 decode_putfh_maxsz + \
562 decode_fsinfo_maxsz)
563#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
564 encode_renew_maxsz)
565#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
566 decode_renew_maxsz)
567#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
568 encode_setclientid_maxsz)
569#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
570 decode_setclientid_maxsz)
571#define NFS4_enc_setclientid_confirm_sz \
572 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400573 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574#define NFS4_dec_setclientid_confirm_sz \
575 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400576 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400578 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400580 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400584 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400588 encode_lockt_maxsz)
589#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400591 decode_putfh_maxsz + \
592 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400594 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400596 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400598 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400600 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400601#define NFS4_enc_release_lockowner_sz \
602 (compound_encode_hdr_maxsz + \
603 encode_lockowner_maxsz)
604#define NFS4_dec_release_lockowner_sz \
605 (compound_decode_hdr_maxsz + \
606 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400608 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400610 encode_access_maxsz + \
611 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400613 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400615 decode_access_maxsz + \
616 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400618 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400620 encode_getattr_maxsz + \
621 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400623 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400625 decode_getattr_maxsz + \
626 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400628 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 encode_putfh_maxsz + \
630 encode_lookup_maxsz + \
631 encode_getattr_maxsz + \
632 encode_getfh_maxsz)
633#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400634 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400636 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 decode_getattr_maxsz + \
638 decode_getfh_maxsz)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700639#define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \
640 encode_sequence_maxsz + \
641 encode_putfh_maxsz + \
642 encode_lookupp_maxsz + \
643 encode_getattr_maxsz + \
644 encode_getfh_maxsz)
645#define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \
646 decode_sequence_maxsz + \
647 decode_putfh_maxsz + \
648 decode_lookupp_maxsz + \
649 decode_getattr_maxsz + \
650 decode_getfh_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400652 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 encode_putrootfh_maxsz + \
654 encode_getattr_maxsz + \
655 encode_getfh_maxsz)
656#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400657 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 decode_putrootfh_maxsz + \
659 decode_getattr_maxsz + \
660 decode_getfh_maxsz)
661#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400662 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 encode_putfh_maxsz + \
Trond Myklebust778d28172012-04-27 13:48:19 -0400664 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400666 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 decode_putfh_maxsz + \
Trond Myklebust778d28172012-04-27 13:48:19 -0400668 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400670 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 encode_putfh_maxsz + \
672 encode_savefh_maxsz + \
673 encode_putfh_maxsz + \
Trond Myklebust778d28172012-04-27 13:48:19 -0400674 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 decode_putfh_maxsz + \
678 decode_savefh_maxsz + \
679 decode_putfh_maxsz + \
Trond Myklebust778d28172012-04-27 13:48:19 -0400680 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400682 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 encode_putfh_maxsz + \
684 encode_savefh_maxsz + \
685 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400686 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400687 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400688 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400690 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 decode_putfh_maxsz + \
692 decode_savefh_maxsz + \
693 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400694 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400695 decode_restorefh_maxsz + \
696 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400698 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 encode_putfh_maxsz + \
700 encode_symlink_maxsz + \
701 encode_getattr_maxsz + \
702 encode_getfh_maxsz)
703#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400704 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 decode_putfh_maxsz + \
706 decode_symlink_maxsz + \
707 decode_getattr_maxsz + \
708 decode_getfh_maxsz)
709#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400710 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 encode_putfh_maxsz + \
712 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400713 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400714 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400716 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 decode_putfh_maxsz + \
718 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400719 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400720 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400722 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 encode_putfh_maxsz + \
724 encode_getattr_maxsz)
725#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400726 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 decode_putfh_maxsz + \
728 decode_getattr_maxsz)
729#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400730 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400732 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400734 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400736 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400738 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800739 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 encode_getattr_maxsz)
741#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400742 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800743 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 decode_getattr_maxsz)
745#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400746 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 encode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500748 encode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100749 encode_delegreturn_maxsz + \
750 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400752 decode_sequence_maxsz + \
Trond Myklebustd8434d4c2016-11-16 13:54:00 -0500753 decode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500754 decode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100755 decode_delegreturn_maxsz + \
756 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000757#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400758 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000759 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400760 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000761#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400762 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000763 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400764 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000765#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400766 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000767 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400768 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000769#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400770 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000771 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400772 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400773#define NFS4_enc_fs_locations_sz \
774 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400775 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400776 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400777 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400778 encode_fs_locations_maxsz + \
779 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400780#define NFS4_dec_fs_locations_sz \
781 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400782 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400783 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400784 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400785 decode_fs_locations_maxsz + \
786 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000787#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
788 encode_sequence_maxsz + \
789 encode_putfh_maxsz + \
790 encode_secinfo_maxsz)
791#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
792 decode_sequence_maxsz + \
793 decode_putfh_maxsz + \
794 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400795#define NFS4_enc_fsid_present_sz \
796 (compound_encode_hdr_maxsz + \
797 encode_sequence_maxsz + \
798 encode_putfh_maxsz + \
799 encode_getfh_maxsz + \
800 encode_renew_maxsz)
801#define NFS4_dec_fsid_present_sz \
802 (compound_decode_hdr_maxsz + \
803 decode_sequence_maxsz + \
804 decode_putfh_maxsz + \
805 decode_getfh_maxsz + \
806 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400807#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400808#define NFS4_enc_bind_conn_to_session_sz \
809 (compound_encode_hdr_maxsz + \
810 encode_bind_conn_to_session_maxsz)
811#define NFS4_dec_bind_conn_to_session_sz \
812 (compound_decode_hdr_maxsz + \
813 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400814#define NFS4_enc_exchange_id_sz \
815 (compound_encode_hdr_maxsz + \
816 encode_exchange_id_maxsz)
817#define NFS4_dec_exchange_id_sz \
818 (compound_decode_hdr_maxsz + \
819 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400820#define NFS4_enc_create_session_sz \
821 (compound_encode_hdr_maxsz + \
822 encode_create_session_maxsz)
823#define NFS4_dec_create_session_sz \
824 (compound_decode_hdr_maxsz + \
825 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400826#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
827 encode_destroy_session_maxsz)
828#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
829 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400830#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
831 encode_destroy_clientid_maxsz)
832#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
833 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400834#define NFS4_enc_sequence_sz \
835 (compound_decode_hdr_maxsz + \
836 encode_sequence_maxsz)
837#define NFS4_dec_sequence_sz \
838 (compound_decode_hdr_maxsz + \
839 decode_sequence_maxsz)
Donald Buczek0efb01b2019-07-07 21:26:08 +0200840#endif
Andy Adamson2050f0c2009-04-01 09:22:30 -0400841#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
842 encode_sequence_maxsz + \
843 encode_putrootfh_maxsz + \
844 encode_fsinfo_maxsz)
845#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
846 decode_sequence_maxsz + \
847 decode_putrootfh_maxsz + \
848 decode_fsinfo_maxsz)
Donald Buczek0efb01b2019-07-07 21:26:08 +0200849#if defined(CONFIG_NFS_V4_1)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500850#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
851 encode_sequence_maxsz + \
852 encode_reclaim_complete_maxsz)
853#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
854 decode_sequence_maxsz + \
855 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400856#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
857 encode_sequence_maxsz +\
858 encode_getdeviceinfo_maxsz)
859#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
860 decode_sequence_maxsz + \
861 decode_getdeviceinfo_maxsz)
862#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
863 encode_sequence_maxsz + \
864 encode_putfh_maxsz + \
865 encode_layoutget_maxsz)
866#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
867 decode_sequence_maxsz + \
868 decode_putfh_maxsz + \
869 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000870#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
871 encode_sequence_maxsz +\
872 encode_putfh_maxsz + \
873 encode_layoutcommit_maxsz + \
874 encode_getattr_maxsz)
875#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
876 decode_sequence_maxsz + \
877 decode_putfh_maxsz + \
878 decode_layoutcommit_maxsz + \
879 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300880#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
881 encode_sequence_maxsz + \
882 encode_putfh_maxsz + \
883 encode_layoutreturn_maxsz)
884#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
885 decode_sequence_maxsz + \
886 decode_putfh_maxsz + \
887 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400888#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
889 encode_sequence_maxsz + \
890 encode_putrootfh_maxsz +\
891 encode_secinfo_no_name_maxsz)
892#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
893 decode_sequence_maxsz + \
894 decode_putrootfh_maxsz + \
895 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400896#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
897 encode_sequence_maxsz + \
898 encode_test_stateid_maxsz)
899#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
900 decode_sequence_maxsz + \
901 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400902#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
903 encode_sequence_maxsz + \
904 encode_free_stateid_maxsz)
905#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
906 decode_sequence_maxsz + \
907 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500908
909const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
910 compound_encode_hdr_maxsz +
911 encode_sequence_maxsz +
912 encode_putfh_maxsz +
913 encode_getattr_maxsz) *
914 XDR_UNIT);
915
916const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
917 compound_decode_hdr_maxsz +
918 decode_sequence_maxsz +
919 decode_putfh_maxsz) *
920 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400921
922const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
923 compound_decode_hdr_maxsz +
924 decode_sequence_maxsz) *
925 XDR_UNIT);
926EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400927#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Trond Myklebustbca79472009-03-11 14:10:26 -0400929static const umode_t nfs_type2fmt[] = {
930 [NF4BAD] = 0,
931 [NF4REG] = S_IFREG,
932 [NF4DIR] = S_IFDIR,
933 [NF4BLK] = S_IFBLK,
934 [NF4CHR] = S_IFCHR,
935 [NF4LNK] = S_IFLNK,
936 [NF4SOCK] = S_IFSOCK,
937 [NF4FIFO] = S_IFIFO,
938 [NF4ATTRDIR] = 0,
939 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940};
941
942struct compound_hdr {
943 int32_t status;
944 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500945 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 uint32_t taglen;
947 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400948 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400949 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950};
951
Benny Halevy13c65ce2009-08-14 17:19:25 +0300952static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
953{
954 __be32 *p = xdr_reserve_space(xdr, nbytes);
955 BUG_ON(!p);
956 return p;
957}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Trond Myklebustcb17e552012-03-04 18:13:56 -0500959static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
960{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500961 WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
Trond Myklebustcb17e552012-03-04 18:13:56 -0500962}
963
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
965{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500966 WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967}
968
Trond Myklebust4ade9822012-03-04 18:13:57 -0500969static void encode_uint32(struct xdr_stream *xdr, u32 n)
970{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500971 WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500972}
973
Trond Myklebustff2eb682012-03-05 11:40:12 -0500974static void encode_uint64(struct xdr_stream *xdr, u64 n)
975{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500976 WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
Trond Myklebustff2eb682012-03-05 11:40:12 -0500977}
978
Trond Myklebust37c88762018-03-20 17:03:08 -0400979static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
980 const __u32 *bitmap, size_t len)
981{
982 ssize_t ret;
983
984 /* Trim empty words */
985 while (len > 0 && bitmap[len-1] == 0)
986 len--;
987 ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
988 if (WARN_ON_ONCE(ret < 0))
989 return ret;
990 return len;
991}
992
993static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
994 __u32 *res, size_t len)
995{
996 size_t i;
997 __u32 tmp;
998
999 while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
1000 len--;
1001 for (i = len; i-- > 0;) {
1002 tmp = bitmap[i] & mask[i];
1003 res[i] = tmp;
1004 }
1005 return len;
1006}
1007
Trond Myklebust4ade9822012-03-04 18:13:57 -05001008static void encode_nfs4_seqid(struct xdr_stream *xdr,
1009 const struct nfs_seqid *seqid)
1010{
Trond Myklebusta6796412015-01-23 19:04:44 -05001011 if (seqid != NULL)
1012 encode_uint32(xdr, seqid->sequence->counter);
1013 else
1014 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001015}
1016
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001017static void encode_compound_hdr(struct xdr_stream *xdr,
1018 struct rpc_rqst *req,
1019 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020{
Al Viro8687b632006-10-19 23:28:48 -07001021 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001022
1023 /* initialize running count of expected bytes in reply.
1024 * NOTE: the replied tag SHOULD be the same is the one sent,
1025 * but this is not required as a MUST for the server to do so. */
Chuck Levercf500ba2019-02-11 11:25:20 -05001026 hdr->replen = 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Trond Myklebust7fc38842012-10-15 11:51:21 -04001028 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001029 encode_string(xdr, hdr->taglen, hdr->tag);
1030 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001031 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -05001032 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +03001033 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -05001034}
1035
Trond Myklebustab19b482012-03-04 18:13:57 -05001036static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
1037 uint32_t replen,
1038 struct compound_hdr *hdr)
1039{
1040 encode_uint32(xdr, op);
1041 hdr->nops++;
1042 hdr->replen += replen;
1043}
1044
Andy Adamsond0179312008-12-23 16:06:17 -05001045static void encode_nops(struct compound_hdr *hdr)
1046{
Trond Myklebust7fc38842012-10-15 11:51:21 -04001047 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -05001048 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049}
1050
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001051static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1052{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001053 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001054}
1055
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1057{
Trond Myklebustcb17e552012-03-04 18:13:56 -05001058 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059}
1060
Trond Myklebust36b37432018-03-20 17:03:10 -04001061static __be32 *
Trond Myklebuste7d4b052019-10-04 16:43:09 -04001062xdr_encode_nfstime4(__be32 *p, const struct timespec64 *t)
Trond Myklebust36b37432018-03-20 17:03:10 -04001063{
1064 p = xdr_encode_hyper(p, (__s64)t->tv_sec);
1065 *p++ = cpu_to_be32(t->tv_nsec);
1066 return p;
1067}
1068
David Quigleyaa9c2662013-05-22 12:50:44 -04001069static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1070 const struct nfs4_label *label,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001071 const umode_t *umask,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001072 const struct nfs_server *server,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001073 const uint32_t attrmask[])
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074{
1075 char owner_name[IDMAP_NAMESZ];
1076 char owner_group[IDMAP_NAMESZ];
1077 int owner_namelen = 0;
1078 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001079 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001080 uint32_t len = 0;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001081 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
1083 /*
1084 * We reserve enough space to write the entire attribute buffer at once.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 */
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001086 if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001087 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001089 }
1090 if (iap->ia_valid & ATTR_MODE) {
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001091 if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001092 bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1093 len += 8;
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001094 } else if (attrmask[1] & FATTR4_WORD1_MODE) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001095 bmval[1] |= FATTR4_WORD1_MODE;
1096 len += 4;
1097 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001098 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001099 if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001100 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001102 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001103 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 /* XXX */
1105 strcpy(owner_name, "nobody");
1106 owner_namelen = sizeof("nobody") - 1;
1107 /* goto out; */
1108 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001109 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1111 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001112 if ((iap->ia_valid & ATTR_GID) &&
1113 (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001114 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001116 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001117 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 strcpy(owner_group, "nobody");
1119 owner_grouplen = sizeof("nobody") - 1;
1120 /* goto out; */
1121 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001122 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1124 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001125 if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1126 if (iap->ia_valid & ATTR_ATIME_SET) {
1127 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
Trond Myklebust36b37432018-03-20 17:03:10 -04001128 len += 4 + (nfstime4_maxsz << 2);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001129 } else if (iap->ia_valid & ATTR_ATIME) {
1130 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1131 len += 4;
1132 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001134 if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1135 if (iap->ia_valid & ATTR_MTIME_SET) {
1136 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
Trond Myklebust36b37432018-03-20 17:03:10 -04001137 len += 4 + (nfstime4_maxsz << 2);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001138 } else if (iap->ia_valid & ATTR_MTIME) {
1139 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1140 len += 4;
1141 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001143
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001144 if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001145 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1146 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1147 }
1148
Trond Myklebust40a3426c2018-03-20 17:03:09 -04001149 xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
1150 xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001151
1152 if (bmval[0] & FATTR4_WORD0_SIZE)
1153 p = xdr_encode_hyper(p, iap->ia_size);
1154 if (bmval[1] & FATTR4_WORD1_MODE)
1155 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1156 if (bmval[1] & FATTR4_WORD1_OWNER)
1157 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1158 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1159 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1160 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1161 if (iap->ia_valid & ATTR_ATIME_SET) {
1162 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Trond Myklebuste7d4b052019-10-04 16:43:09 -04001163 p = xdr_encode_nfstime4(p, &iap->ia_atime);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001164 } else
1165 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1166 }
1167 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1168 if (iap->ia_valid & ATTR_MTIME_SET) {
1169 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Trond Myklebuste7d4b052019-10-04 16:43:09 -04001170 p = xdr_encode_nfstime4(p, &iap->ia_mtime);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001171 } else
1172 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1173 }
Jia-Ju Baie2751462019-07-26 15:48:53 +08001174 if (label && (bmval[2] & FATTR4_WORD2_SECURITY_LABEL)) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001175 *p++ = cpu_to_be32(label->lfs);
1176 *p++ = cpu_to_be32(label->pi);
1177 *p++ = cpu_to_be32(label->len);
1178 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1179 }
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001180 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1181 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1182 *p++ = cpu_to_be32(*umask);
1183 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001184
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186}
1187
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001188static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001190 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1191 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192}
1193
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001194static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195{
Trond Myklebustab19b482012-03-04 18:13:57 -05001196 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001197 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001198 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199}
1200
Fred Isaman0b7c0152012-04-20 14:47:39 -04001201static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202{
Al Viro8687b632006-10-19 23:28:48 -07001203 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001204
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001205 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1206 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001207 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001208 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209}
1210
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001211static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212{
Al Viro8687b632006-10-19 23:28:48 -07001213 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001214
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001215 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1216 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
1218 switch (create->ftype) {
1219 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001220 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001221 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001222 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1223 create->u.symlink.len);
1224 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 break;
1226
1227 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001228 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001229 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001230 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 break;
1232
1233 default:
1234 break;
1235 }
1236
Benny Halevy811652b2009-08-14 17:19:34 +03001237 encode_string(xdr, create->name->len, create->name->name);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001238 encode_attrs(xdr, create->attrs, create->label, &create->umask,
1239 create->server, create->server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240}
1241
Trond Myklebust37c88762018-03-20 17:03:08 -04001242static void encode_getattr(struct xdr_stream *xdr,
1243 const __u32 *bitmap, const __u32 *mask, size_t len,
1244 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245{
Trond Myklebust37c88762018-03-20 17:03:08 -04001246 __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001248 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04001249 if (mask) {
1250 if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
1251 len = ARRAY_SIZE(masked_bitmap);
1252 len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
1253 bitmap = masked_bitmap;
Fred Isamandae100c2011-07-30 20:52:37 -04001254 }
Trond Myklebust37c88762018-03-20 17:03:08 -04001255 xdr_encode_bitmap4(xdr, bitmap, len);
Fred Isamandae100c2011-07-30 20:52:37 -04001256}
1257
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001258static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259{
Trond Myklebust37c88762018-03-20 17:03:08 -04001260 encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
1261 ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262}
1263
Andy Adamson88034c32012-05-23 05:02:34 -04001264static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001265 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001266 struct compound_hdr *hdr)
1267{
Trond Myklebust37c88762018-03-20 17:03:08 -04001268 encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
Andy Adamson88034c32012-05-23 05:02:34 -04001269}
1270
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001271static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272{
Trond Myklebust37c88762018-03-20 17:03:08 -04001273 encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
1274 ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275}
1276
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001277static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001278{
Trond Myklebust37c88762018-03-20 17:03:08 -04001279 encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
1280 ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001281}
1282
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001283static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284{
Trond Myklebustab19b482012-03-04 18:13:57 -05001285 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286}
1287
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001288static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
Trond Myklebustab19b482012-03-04 18:13:57 -05001290 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001291 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292}
1293
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001294static inline int nfs4_lock_type(struct file_lock *fl, int block)
1295{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001296 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001297 return block ? NFS4_READW_LT : NFS4_READ_LT;
1298 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1299}
1300
1301static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1302{
1303 if (fl->fl_end == OFFSET_MAX)
1304 return ~(uint64_t)0;
1305 return fl->fl_end - fl->fl_start + 1;
1306}
1307
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001308static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1309{
1310 __be32 *p;
1311
Trond Myklebustd035c362010-12-21 10:45:27 -05001312 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001313 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001314 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001315 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001316 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001317 xdr_encode_hyper(p, lowner->id);
1318}
1319
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320/*
1321 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1322 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1323 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001324static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325{
Al Viro8687b632006-10-19 23:28:48 -07001326 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001328 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1329 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001330 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1331 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001332 p = xdr_encode_hyper(p, args->fl->fl_start);
1333 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001334 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001335 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001336 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001337 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001338 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001339 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 }
1341 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001342 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001343 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345}
1346
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001347static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348{
Al Viro8687b632006-10-19 23:28:48 -07001349 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001351 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1352 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001353 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001354 p = xdr_encode_hyper(p, args->fl->fl_start);
1355 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001356 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357}
1358
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001359static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360{
Al Viro8687b632006-10-19 23:28:48 -07001361 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001363 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1364 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001365 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001366 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001367 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001368 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001369 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370}
1371
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001372static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1373{
Trond Myklebustab19b482012-03-04 18:13:57 -05001374 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001375 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001376}
1377
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001378static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379{
Trond Myklebustab19b482012-03-04 18:13:57 -05001380 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001381 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382}
1383
Jeff Layton5b5faaf2017-06-29 06:34:52 -07001384static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
1385{
1386 encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
1387}
1388
Trond Myklebust6ae37332015-01-30 14:21:14 -05001389static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390{
Al Viro8687b632006-10-19 23:28:48 -07001391 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
Benny Halevy13c65ce2009-08-14 17:19:25 +03001393 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001394 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001395 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396}
1397
1398static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1399{
Al Viro8687b632006-10-19 23:28:48 -07001400 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 /*
1402 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1403 * owner 4 = 32
1404 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001405 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001406 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001407 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001408 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001409 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001410 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001411 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001412 *p++ = cpu_to_be32(arg->id.uniquifier);
1413 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414}
1415
1416static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1417{
Al Viro8687b632006-10-19 23:28:48 -07001418 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
Benny Halevy13c65ce2009-08-14 17:19:25 +03001420 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001421 switch(arg->createmode) {
1422 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001423 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001424 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1425 arg->server, arg->server->attr_bitmask);
Andy Adamson05d564f2008-12-23 16:06:15 -05001426 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001427 case NFS4_CREATE_GUARDED:
1428 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001429 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1430 arg->server, arg->server->attr_bitmask);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001431 break;
1432 case NFS4_CREATE_EXCLUSIVE:
1433 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1434 encode_nfs4_verifier(xdr, &arg->u.verifier);
1435 break;
1436 case NFS4_CREATE_EXCLUSIVE4_1:
1437 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1438 encode_nfs4_verifier(xdr, &arg->u.verifier);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001439 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1440 arg->server, arg->server->exclcreat_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 }
1442}
1443
1444static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1445{
Al Viro8687b632006-10-19 23:28:48 -07001446 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
Benny Halevy13c65ce2009-08-14 17:19:25 +03001448 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001450 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001451 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001452 break;
1453 default:
Benny Halevy34558512009-08-14 17:19:30 +03001454 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001455 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 }
1457}
1458
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001459static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460{
Al Viro8687b632006-10-19 23:28:48 -07001461 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Benny Halevy13c65ce2009-08-14 17:19:25 +03001463 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001465 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001466 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001467 break;
1468 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001469 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001470 break;
1471 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001472 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001473 break;
1474 default:
1475 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 }
1477}
1478
1479static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1480{
Al Viro8687b632006-10-19 23:28:48 -07001481 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Benny Halevy13c65ce2009-08-14 17:19:25 +03001483 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001484 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 encode_string(xdr, name->len, name->name);
1486}
1487
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001488static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489{
Al Viro8687b632006-10-19 23:28:48 -07001490 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Benny Halevy13c65ce2009-08-14 17:19:25 +03001492 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001493 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 encode_delegation_type(xdr, type);
1495}
1496
1497static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1498{
Al Viro8687b632006-10-19 23:28:48 -07001499 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001501 p = reserve_space(xdr, 4);
1502 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1503 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 encode_string(xdr, name->len, name->name);
1505}
1506
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001507static inline void encode_claim_fh(struct xdr_stream *xdr)
1508{
1509 __be32 *p;
1510
1511 p = reserve_space(xdr, 4);
1512 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1513}
1514
1515static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1516{
1517 __be32 *p;
1518
1519 p = reserve_space(xdr, 4);
1520 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1521 encode_nfs4_stateid(xdr, stateid);
1522}
1523
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001524static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525{
Trond Myklebustab19b482012-03-04 18:13:57 -05001526 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 encode_openhdr(xdr, arg);
1528 encode_opentype(xdr, arg);
1529 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001530 case NFS4_OPEN_CLAIM_NULL:
1531 encode_claim_null(xdr, arg->name);
1532 break;
1533 case NFS4_OPEN_CLAIM_PREVIOUS:
1534 encode_claim_previous(xdr, arg->u.delegation_type);
1535 break;
1536 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1537 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1538 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001539 case NFS4_OPEN_CLAIM_FH:
1540 encode_claim_fh(xdr);
1541 break;
1542 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1543 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1544 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001545 default:
1546 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548}
1549
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001550static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
Trond Myklebustab19b482012-03-04 18:13:57 -05001552 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001553 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001554 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555}
1556
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001557static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558{
Trond Myklebustab19b482012-03-04 18:13:57 -05001559 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001560 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001561 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001562 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563}
1564
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001565static void
Andy Adamsond0179312008-12-23 16:06:17 -05001566encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567{
Trond Myklebustab19b482012-03-04 18:13:57 -05001568 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001569 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570}
1571
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001572static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573{
Trond Myklebustab19b482012-03-04 18:13:57 -05001574 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575}
1576
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001577static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1578 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579{
Al Viro8687b632006-10-19 23:28:48 -07001580 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
Trond Myklebustab19b482012-03-04 18:13:57 -05001582 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001583 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Benny Halevy13c65ce2009-08-14 17:19:25 +03001585 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001586 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001587 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588}
1589
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001590static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591{
David Quigleyaa9c2662013-05-22 12:50:44 -04001592 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001593 FATTR4_WORD0_RDATTR_ERROR,
1594 FATTR4_WORD1_MOUNTED_ON_FILEID,
1595 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001596 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001597 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001598 uint32_t attrlen = 0;
1599 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001601 if (readdir->plus) {
1602 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001603 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001604 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1605 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1606 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1607 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001608 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001609 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001610 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001611 /* Use mounted_on_fileid only if the server supports it */
1612 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1613 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001614 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1615 attrs[i] &= readdir->bitmask[i];
1616 if (attrs[i] != 0)
1617 attrlen = i+1;
1618 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001619
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001620 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001621 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001622 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001623 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001624 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001625 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001626 *p++ = cpu_to_be32(attrlen);
1627 for (i = 0; i < attrlen; i++)
1628 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001629 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001630
1631 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001632 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001633 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001634 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001635 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001636 attrs[1] & readdir->bitmask[1],
1637 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638}
1639
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001640static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641{
Trond Myklebustab19b482012-03-04 18:13:57 -05001642 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643}
1644
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001645static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646{
Trond Myklebustab19b482012-03-04 18:13:57 -05001647 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001648 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
1650
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001651static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652{
Trond Myklebustab19b482012-03-04 18:13:57 -05001653 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001654 encode_string(xdr, oldname->len, oldname->name);
1655 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656}
1657
Chuck Leverbb4dae52012-03-01 17:01:48 -05001658static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1659 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001661 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001662 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663}
1664
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001665static void
Andy Adamsond0179312008-12-23 16:06:17 -05001666encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001667{
Trond Myklebustab19b482012-03-04 18:13:57 -05001668 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001669}
1670
Chuck Lever9f06c712010-12-14 14:59:18 +00001671static void
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001672encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1673 struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001674{
Al Viro8687b632006-10-19 23:28:48 -07001675 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001676
Trond Myklebustab19b482012-03-04 18:13:57 -05001677 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001678 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001679 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001680 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001681 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001682 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001683 *p = cpu_to_be32(arg->acl_len);
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01001684 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001685}
1686
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001687static void
Andy Adamsond0179312008-12-23 16:06:17 -05001688encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689{
Trond Myklebustab19b482012-03-04 18:13:57 -05001690 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691}
1692
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001693static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694{
Trond Myklebustab19b482012-03-04 18:13:57 -05001695 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001696 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001697 encode_attrs(xdr, arg->iap, arg->label, NULL, server,
1698 server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699}
1700
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001701static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702{
Al Viro8687b632006-10-19 23:28:48 -07001703 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
Trond Myklebust70019512012-03-04 20:49:32 -05001705 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001706 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
Jeff Layton3a6bb732015-06-09 19:43:57 -04001708 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1709 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001710 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001711 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1713 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001714 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001715 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716}
1717
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001718static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001720 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1721 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001722 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001723 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724}
1725
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001726static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1727 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728{
Al Viro8687b632006-10-19 23:28:48 -07001729 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
Trond Myklebustab19b482012-03-04 18:13:57 -05001731 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001732 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
Benny Halevy13c65ce2009-08-14 17:19:25 +03001734 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001735 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001736 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001737 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
1739 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740}
1741
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001742static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743{
Trond Myklebustab19b482012-03-04 18:13:57 -05001744 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001745 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001747
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001748static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1749{
Trond Myklebustab19b482012-03-04 18:13:57 -05001750 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001751 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001752}
1753
Benny Halevy99fe60d2009-04-01 09:22:29 -04001754#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001755/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001756static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001757 const struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001758 struct compound_hdr *hdr)
1759{
1760 __be32 *p;
1761
1762 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1763 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001764 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001765 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001766 *p++ = cpu_to_be32(args->dir);
1767 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001768}
1769
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001770static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001771{
1772 unsigned int i;
1773 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1774 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1775 encode_uint32(xdr, op_map->u.words[i]);
1776}
1777
Benny Halevy99fe60d2009-04-01 09:22:29 -04001778static void encode_exchange_id(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001779 const struct nfs41_exchange_id_args *args,
Benny Halevy99fe60d2009-04-01 09:22:29 -04001780 struct compound_hdr *hdr)
1781{
1782 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001783 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001784 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001785
Trond Myklebust70019512012-03-04 20:49:32 -05001786 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Trond Myklebustfd405592017-08-01 16:02:47 -04001787 encode_nfs4_verifier(xdr, &args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001788
Jeff Layton3a6bb732015-06-09 19:43:57 -04001789 encode_string(xdr, strlen(args->client->cl_owner_id),
1790 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001791
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001792 encode_uint32(xdr, args->flags);
1793 encode_uint32(xdr, args->state_protect.how);
1794
1795 switch (args->state_protect.how) {
1796 case SP4_NONE:
1797 break;
1798 case SP4_MACH_CRED:
1799 encode_op_map(xdr, &args->state_protect.enforce);
1800 encode_op_map(xdr, &args->state_protect.allow);
1801 break;
1802 default:
1803 WARN_ON_ONCE(1);
1804 break;
1805 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001806
1807 if (send_implementation_id &&
1808 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1809 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001810 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001811 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1812 utsname()->sysname, utsname()->release,
1813 utsname()->version, utsname()->machine);
1814
1815 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001816 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001817
1818 encode_string(xdr,
1819 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1820 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1821 encode_string(xdr, len, impl_name);
1822 /* just send zeros for nii_date - the date is in nii_name */
1823 p = reserve_space(xdr, 12);
1824 p = xdr_encode_hyper(p, 0);
1825 *p = cpu_to_be32(0);
1826 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001827 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001828}
Andy Adamsonfc931582009-04-01 09:22:31 -04001829
1830static void encode_create_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001831 const struct nfs41_create_session_args *args,
Andy Adamsonfc931582009-04-01 09:22:31 -04001832 struct compound_hdr *hdr)
1833{
1834 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001835 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001836 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001837 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001838 u32 max_resp_sz_cached;
1839
1840 /*
1841 * Assumes OPEN is the biggest non-idempotent compound.
1842 * 2 is the verifier.
1843 */
J. Bruce Fields35c036e2017-09-20 12:42:13 -04001844 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
1845 * XDR_UNIT + RPC_MAX_AUTH_SIZE;
Andy Adamsonfc931582009-04-01 09:22:31 -04001846
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001847 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001848 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd12015-02-18 11:30:18 -08001849 p = xdr_encode_hyper(p, args->clientid);
1850 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001851 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001852
Andy Adamsonfc931582009-04-01 09:22:31 -04001853 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001854 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001855 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1856 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001857 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001858 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1859 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1860 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001861
1862 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001863 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001864 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1865 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1866 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1867 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1868 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1869 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001870
Benny Halevye75bc1c2009-08-14 17:18:54 +03001871 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001872 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001873 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001874
1875 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001876 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001877 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001878 *p++ = cpu_to_be32(0); /* UID */
1879 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001880 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001881}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001882
1883static void encode_destroy_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001884 const struct nfs4_session *session,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001885 struct compound_hdr *hdr)
1886{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001887 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1888 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001889}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001890
Trond Myklebust66245532012-05-25 17:18:09 -04001891static void encode_destroy_clientid(struct xdr_stream *xdr,
1892 uint64_t clientid,
1893 struct compound_hdr *hdr)
1894{
1895 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1896 encode_uint64(xdr, clientid);
1897}
1898
Ricardo Labiaga180197532009-12-05 16:08:40 -05001899static void encode_reclaim_complete(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001900 const struct nfs41_reclaim_complete_args *args,
Ricardo Labiaga180197532009-12-05 16:08:40 -05001901 struct compound_hdr *hdr)
1902{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001903 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1904 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001905}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001906#endif /* CONFIG_NFS_V4_1 */
1907
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001908static void encode_sequence(struct xdr_stream *xdr,
1909 const struct nfs4_sequence_args *args,
1910 struct compound_hdr *hdr)
1911{
1912#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001913 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001914 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001915 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001916 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001917
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001918 tp = slot->table;
1919 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001920 if (!session)
1921 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001922
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001923 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001924
1925 /*
1926 * Sessionid + seqid + slotid + max slotid + cache_this
1927 */
1928 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1929 "max_slotid=%d cache_this=%d\n",
1930 __func__,
1931 ((u32 *)session->sess_id.data)[0],
1932 ((u32 *)session->sess_id.data)[1],
1933 ((u32 *)session->sess_id.data)[2],
1934 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001935 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001936 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001937 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001938 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001939 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001940 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001941 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001942 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001943#endif /* CONFIG_NFS_V4_1 */
1944}
1945
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001946#ifdef CONFIG_NFS_V4_1
1947static void
1948encode_getdeviceinfo(struct xdr_stream *xdr,
1949 const struct nfs4_getdeviceinfo_args *args,
1950 struct compound_hdr *hdr)
1951{
1952 __be32 *p;
1953
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001954 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001955 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001956 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1957 NFS4_DEVICEID4_SIZE);
1958 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001959 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001960
1961 p = reserve_space(xdr, 4 + 4);
1962 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001963 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001964}
1965
1966static void
1967encode_layoutget(struct xdr_stream *xdr,
1968 const struct nfs4_layoutget_args *args,
1969 struct compound_hdr *hdr)
1970{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001971 __be32 *p;
1972
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001973 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1974 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001975 *p++ = cpu_to_be32(0); /* Signal layout available */
1976 *p++ = cpu_to_be32(args->type);
1977 *p++ = cpu_to_be32(args->range.iomode);
1978 p = xdr_encode_hyper(p, args->range.offset);
1979 p = xdr_encode_hyper(p, args->range.length);
1980 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001981 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001982 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001983
1984 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1985 __func__,
1986 args->type,
1987 args->range.iomode,
1988 (unsigned long)args->range.offset,
1989 (unsigned long)args->range.length,
1990 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001991}
Andy Adamson863a3c62011-03-23 13:27:54 +00001992
1993static int
1994encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001995 struct inode *inode,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001996 const struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001997 struct compound_hdr *hdr)
1998{
1999 __be32 *p;
2000
2001 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2002 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2003
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002004 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2005 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00002006 /* Only whole file layouts */
2007 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002008 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002009 *p = cpu_to_be32(0); /* reclaim */
2010 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04002011 if (args->lastbytewritten != U64_MAX) {
2012 p = reserve_space(xdr, 20);
2013 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2014 p = xdr_encode_hyper(p, args->lastbytewritten);
2015 } else {
2016 p = reserve_space(xdr, 12);
2017 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2018 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002019 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2020 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002021
Trond Myklebust73504742017-04-20 16:48:14 -04002022 encode_uint32(xdr, args->layoutupdate_len);
2023 if (args->layoutupdate_pages)
2024 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2025 args->layoutupdate_len);
Andy Adamson863a3c62011-03-23 13:27:54 +00002026
Andy Adamson863a3c62011-03-23 13:27:54 +00002027 return 0;
2028}
Benny Halevycbe82602011-05-22 19:52:37 +03002029
2030static void
2031encode_layoutreturn(struct xdr_stream *xdr,
2032 const struct nfs4_layoutreturn_args *args,
2033 struct compound_hdr *hdr)
2034{
2035 __be32 *p;
2036
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002037 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2038 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002039 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2040 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002041 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002042 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002043 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002044 p = xdr_encode_hyper(p, args->range.offset);
2045 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002046 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002047 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002048 spin_unlock(&args->inode->i_lock);
Trond Myklebust4d796d72016-09-23 11:38:08 -04002049 if (args->ld_private->ops && args->ld_private->ops->encode)
2050 args->ld_private->ops->encode(xdr, args, args->ld_private);
Trond Myklebust94e5c572016-09-15 18:49:52 -04002051 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002052 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002053}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002054
2055static int
2056encode_secinfo_no_name(struct xdr_stream *xdr,
2057 const struct nfs41_secinfo_no_name_args *args,
2058 struct compound_hdr *hdr)
2059{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002060 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2061 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002062 return 0;
2063}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002064
2065static void encode_test_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002066 const struct nfs41_test_stateid_args *args,
Bryan Schumaker7d974792011-06-02 14:59:08 -04002067 struct compound_hdr *hdr)
2068{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002069 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2070 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002071 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002072}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002073
2074static void encode_free_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002075 const struct nfs41_free_stateid_args *args,
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002076 struct compound_hdr *hdr)
2077{
Trond Myklebustab19b482012-03-04 18:13:57 -05002078 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002079 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002080}
Trond Myklebustcf805162016-11-15 14:56:07 -05002081#else
2082static inline void
2083encode_layoutreturn(struct xdr_stream *xdr,
2084 const struct nfs4_layoutreturn_args *args,
2085 struct compound_hdr *hdr)
2086{
2087}
Fred Isaman56f487f2016-09-21 11:43:41 -04002088
2089static void
2090encode_layoutget(struct xdr_stream *xdr,
2091 const struct nfs4_layoutget_args *args,
2092 struct compound_hdr *hdr)
2093{
2094}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002095#endif /* CONFIG_NFS_V4_1 */
2096
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097/*
2098 * END OF "GENERIC" ENCODE ROUTINES.
2099 */
2100
Benny Halevy66cc0422009-04-01 09:22:10 -04002101static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2102{
2103#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002104 struct nfs4_session *session = args->sa_slot->table->session;
2105 if (session)
2106 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002107#endif /* CONFIG_NFS_V4_1 */
2108 return 0;
2109}
2110
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111/*
2112 * Encode an ACCESS request
2113 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002114static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002115 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002117 const struct nfs4_accessargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002119 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121
Chuck Lever9f06c712010-12-14 14:59:18 +00002122 encode_compound_hdr(xdr, req, &hdr);
2123 encode_sequence(xdr, &args->seq_args, &hdr);
2124 encode_putfh(xdr, args->fh, &hdr);
2125 encode_access(xdr, args->access, &hdr);
Trond Myklebust8bcbe7d2018-03-20 17:03:11 -04002126 if (args->bitmask)
2127 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002128 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129}
2130
2131/*
2132 * Encode LOOKUP request
2133 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002134static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002135 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002137 const struct nfs4_lookup_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002139 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
Chuck Lever9f06c712010-12-14 14:59:18 +00002142 encode_compound_hdr(xdr, req, &hdr);
2143 encode_sequence(xdr, &args->seq_args, &hdr);
2144 encode_putfh(xdr, args->dir_fh, &hdr);
2145 encode_lookup(xdr, args->name, &hdr);
2146 encode_getfh(xdr, &hdr);
2147 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002148 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149}
2150
2151/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07002152 * Encode LOOKUPP request
2153 */
2154static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
2155 const void *data)
2156{
2157 const struct nfs4_lookupp_arg *args = data;
2158 struct compound_hdr hdr = {
2159 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2160 };
2161
2162 encode_compound_hdr(xdr, req, &hdr);
2163 encode_sequence(xdr, &args->seq_args, &hdr);
2164 encode_putfh(xdr, args->fh, &hdr);
2165 encode_lookupp(xdr, &hdr);
2166 encode_getfh(xdr, &hdr);
2167 encode_getfattr(xdr, args->bitmask, &hdr);
2168 encode_nops(&hdr);
2169}
2170
2171/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 * Encode LOOKUP_ROOT request
2173 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002174static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2175 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002176 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002178 const struct nfs4_lookup_root_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002180 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
Chuck Lever9f06c712010-12-14 14:59:18 +00002183 encode_compound_hdr(xdr, req, &hdr);
2184 encode_sequence(xdr, &args->seq_args, &hdr);
2185 encode_putrootfh(xdr, &hdr);
2186 encode_getfh(xdr, &hdr);
2187 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002188 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189}
2190
2191/*
2192 * Encode REMOVE request
2193 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002194static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002195 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002197 const struct nfs_removeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002199 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
Chuck Lever9f06c712010-12-14 14:59:18 +00002202 encode_compound_hdr(xdr, req, &hdr);
2203 encode_sequence(xdr, &args->seq_args, &hdr);
2204 encode_putfh(xdr, args->fh, &hdr);
2205 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002206 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207}
2208
2209/*
2210 * Encode RENAME request
2211 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002212static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002213 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002215 const struct nfs_renameargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002217 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219
Chuck Lever9f06c712010-12-14 14:59:18 +00002220 encode_compound_hdr(xdr, req, &hdr);
2221 encode_sequence(xdr, &args->seq_args, &hdr);
2222 encode_putfh(xdr, args->old_dir, &hdr);
2223 encode_savefh(xdr, &hdr);
2224 encode_putfh(xdr, args->new_dir, &hdr);
2225 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002226 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227}
2228
2229/*
2230 * Encode LINK request
2231 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002232static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002233 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002235 const struct nfs4_link_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002237 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239
Chuck Lever9f06c712010-12-14 14:59:18 +00002240 encode_compound_hdr(xdr, req, &hdr);
2241 encode_sequence(xdr, &args->seq_args, &hdr);
2242 encode_putfh(xdr, args->fh, &hdr);
2243 encode_savefh(xdr, &hdr);
2244 encode_putfh(xdr, args->dir_fh, &hdr);
2245 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002246 encode_restorefh(xdr, &hdr);
2247 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002248 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249}
2250
2251/*
2252 * Encode CREATE request
2253 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002254static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002255 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002257 const struct nfs4_create_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002259 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
Chuck Lever9f06c712010-12-14 14:59:18 +00002262 encode_compound_hdr(xdr, req, &hdr);
2263 encode_sequence(xdr, &args->seq_args, &hdr);
2264 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002265 encode_create(xdr, args, &hdr);
2266 encode_getfh(xdr, &hdr);
2267 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002268 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269}
2270
2271/*
2272 * Encode SYMLINK request
2273 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002274static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002275 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002277 const struct nfs4_create_arg *args = data;
2278
Chuck Lever9f06c712010-12-14 14:59:18 +00002279 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280}
2281
2282/*
2283 * Encode GETATTR request
2284 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002285static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002286 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002288 const struct nfs4_getattr_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002290 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
Chuck Lever9f06c712010-12-14 14:59:18 +00002293 encode_compound_hdr(xdr, req, &hdr);
2294 encode_sequence(xdr, &args->seq_args, &hdr);
2295 encode_putfh(xdr, args->fh, &hdr);
2296 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002297 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298}
2299
2300/*
2301 * Encode a CLOSE request
2302 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002303static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002304 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002306 const struct nfs_closeargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002307 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002308 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002309 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
Chuck Lever9f06c712010-12-14 14:59:18 +00002311 encode_compound_hdr(xdr, req, &hdr);
2312 encode_sequence(xdr, &args->seq_args, &hdr);
2313 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002314 if (args->lr_args)
2315 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002316 if (args->bitmask != NULL)
2317 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebustd8d84982016-12-19 12:14:44 -05002318 encode_close(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002319 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320}
2321
2322/*
2323 * Encode an OPEN request
2324 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002325static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002326 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002328 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002330 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332
Chuck Lever9f06c712010-12-14 14:59:18 +00002333 encode_compound_hdr(xdr, req, &hdr);
2334 encode_sequence(xdr, &args->seq_args, &hdr);
2335 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002336 encode_open(xdr, args, &hdr);
2337 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002338 if (args->access)
2339 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002340 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Fred Isaman56f487f2016-09-21 11:43:41 -04002341 if (args->lg_args) {
2342 encode_layoutget(xdr, args->lg_args, &hdr);
Chuck Levercf500ba2019-02-11 11:25:20 -05002343 rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2344 args->lg_args->layout.pglen,
2345 hdr.replen);
Fred Isaman56f487f2016-09-21 11:43:41 -04002346 }
Andy Adamsond0179312008-12-23 16:06:17 -05002347 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348}
2349
2350/*
2351 * Encode an OPEN_CONFIRM request
2352 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002353static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2354 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002355 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002357 const struct nfs_open_confirmargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002359 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
Chuck Lever9f06c712010-12-14 14:59:18 +00002362 encode_compound_hdr(xdr, req, &hdr);
2363 encode_putfh(xdr, args->fh, &hdr);
2364 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002365 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366}
2367
2368/*
2369 * Encode an OPEN request with no attributes.
2370 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002371static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2372 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002373 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002375 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002377 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379
Chuck Lever9f06c712010-12-14 14:59:18 +00002380 encode_compound_hdr(xdr, req, &hdr);
2381 encode_sequence(xdr, &args->seq_args, &hdr);
2382 encode_putfh(xdr, args->fh, &hdr);
2383 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002384 if (args->access)
2385 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002386 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Fred Isaman56f487f2016-09-21 11:43:41 -04002387 if (args->lg_args) {
2388 encode_layoutget(xdr, args->lg_args, &hdr);
Chuck Levercf500ba2019-02-11 11:25:20 -05002389 rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2390 args->lg_args->layout.pglen,
2391 hdr.replen);
Fred Isaman56f487f2016-09-21 11:43:41 -04002392 }
Andy Adamsond0179312008-12-23 16:06:17 -05002393 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394}
2395
2396/*
2397 * Encode an OPEN_DOWNGRADE request
2398 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002399static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2400 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002401 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002403 const struct nfs_closeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002405 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407
Chuck Lever9f06c712010-12-14 14:59:18 +00002408 encode_compound_hdr(xdr, req, &hdr);
2409 encode_sequence(xdr, &args->seq_args, &hdr);
2410 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustb6808142016-11-20 13:34:16 -05002411 if (args->lr_args)
2412 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002413 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002414 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415}
2416
2417/*
2418 * Encode a LOCK request
2419 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002420static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002421 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002423 const struct nfs_lock_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002425 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
Chuck Lever9f06c712010-12-14 14:59:18 +00002428 encode_compound_hdr(xdr, req, &hdr);
2429 encode_sequence(xdr, &args->seq_args, &hdr);
2430 encode_putfh(xdr, args->fh, &hdr);
2431 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002432 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433}
2434
2435/*
2436 * Encode a LOCKT request
2437 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002438static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002439 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002441 const struct nfs_lockt_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002443 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
Chuck Lever9f06c712010-12-14 14:59:18 +00002446 encode_compound_hdr(xdr, req, &hdr);
2447 encode_sequence(xdr, &args->seq_args, &hdr);
2448 encode_putfh(xdr, args->fh, &hdr);
2449 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002450 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451}
2452
2453/*
2454 * Encode a LOCKU request
2455 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002456static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002457 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002459 const struct nfs_locku_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002461 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463
Chuck Lever9f06c712010-12-14 14:59:18 +00002464 encode_compound_hdr(xdr, req, &hdr);
2465 encode_sequence(xdr, &args->seq_args, &hdr);
2466 encode_putfh(xdr, args->fh, &hdr);
2467 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002468 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469}
2470
Chuck Lever9f06c712010-12-14 14:59:18 +00002471static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2472 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002473 const void *data)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002474{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002475 const struct nfs_release_lockowner_args *args = data;
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002476 struct compound_hdr hdr = {
2477 .minorversion = 0,
2478 };
2479
Chuck Lever9f06c712010-12-14 14:59:18 +00002480 encode_compound_hdr(xdr, req, &hdr);
2481 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002482 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002483}
2484
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485/*
2486 * Encode a READLINK request
2487 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002488static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002489 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002491 const struct nfs4_readlink *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002493 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495
Chuck Lever9f06c712010-12-14 14:59:18 +00002496 encode_compound_hdr(xdr, req, &hdr);
2497 encode_sequence(xdr, &args->seq_args, &hdr);
2498 encode_putfh(xdr, args->fh, &hdr);
2499 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002500
Chuck Levercf500ba2019-02-11 11:25:20 -05002501 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2502 args->pglen, hdr.replen);
Andy Adamsond0179312008-12-23 16:06:17 -05002503 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504}
2505
2506/*
2507 * Encode a READDIR request
2508 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002509static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002510 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002512 const struct nfs4_readdir_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002514 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516
Chuck Lever9f06c712010-12-14 14:59:18 +00002517 encode_compound_hdr(xdr, req, &hdr);
2518 encode_sequence(xdr, &args->seq_args, &hdr);
2519 encode_putfh(xdr, args->fh, &hdr);
2520 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002521
Chuck Levercf500ba2019-02-11 11:25:20 -05002522 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2523 args->count, hdr.replen);
Andy Adamsond0179312008-12-23 16:06:17 -05002524 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525}
2526
2527/*
2528 * Encode a READ request
2529 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002530static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002531 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002533 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002535 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537
Chuck Lever9f06c712010-12-14 14:59:18 +00002538 encode_compound_hdr(xdr, req, &hdr);
2539 encode_sequence(xdr, &args->seq_args, &hdr);
2540 encode_putfh(xdr, args->fh, &hdr);
2541 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542
Chuck Levercf500ba2019-02-11 11:25:20 -05002543 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2544 args->count, hdr.replen);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002545 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002546 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547}
2548
2549/*
2550 * Encode an SETATTR request
2551 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002552static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002553 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002555 const struct nfs_setattrargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002556 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002557 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002558 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559
Chuck Lever9f06c712010-12-14 14:59:18 +00002560 encode_compound_hdr(xdr, req, &hdr);
2561 encode_sequence(xdr, &args->seq_args, &hdr);
2562 encode_putfh(xdr, args->fh, &hdr);
2563 encode_setattr(xdr, args, args->server, &hdr);
2564 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002565 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566}
2567
2568/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002569 * Encode a GETACL request
2570 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002571static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002572 const void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002573{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002574 const struct nfs_getaclargs *args = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002575 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002576 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002577 };
Trond Myklebust37c88762018-03-20 17:03:08 -04002578 const __u32 nfs4_acl_bitmap[1] = {
2579 [0] = FATTR4_WORD0_ACL,
2580 };
Benny Halevy28f56692009-04-01 09:22:09 -04002581 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002582
Chuck Lever9f06c712010-12-14 14:59:18 +00002583 encode_compound_hdr(xdr, req, &hdr);
2584 encode_sequence(xdr, &args->seq_args, &hdr);
2585 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fields6682c142017-02-23 14:53:39 -05002586 replen = hdr.replen + op_decode_hdr_maxsz;
Trond Myklebust37c88762018-03-20 17:03:08 -04002587 encode_getattr(xdr, nfs4_acl_bitmap, NULL,
2588 ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002589
Chuck Levercf500ba2019-02-11 11:25:20 -05002590 rpc_prepare_reply_pages(req, args->acl_pages, 0,
Chuck Lever29e7ca72019-04-09 10:44:16 -04002591 args->acl_len, replen + 1);
Andy Adamsond0179312008-12-23 16:06:17 -05002592 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002593}
2594
2595/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 * Encode a WRITE request
2597 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002598static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002599 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002601 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002603 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605
Chuck Lever9f06c712010-12-14 14:59:18 +00002606 encode_compound_hdr(xdr, req, &hdr);
2607 encode_sequence(xdr, &args->seq_args, &hdr);
2608 encode_putfh(xdr, args->fh, &hdr);
2609 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002610 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002611 if (args->bitmask)
2612 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002613 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614}
2615
2616/*
2617 * a COMMIT request
2618 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002619static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002620 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002622 const struct nfs_commitargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002624 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
Chuck Lever9f06c712010-12-14 14:59:18 +00002627 encode_compound_hdr(xdr, req, &hdr);
2628 encode_sequence(xdr, &args->seq_args, &hdr);
2629 encode_putfh(xdr, args->fh, &hdr);
2630 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002631 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632}
2633
2634/*
2635 * FSINFO request
2636 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002637static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002638 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002640 const struct nfs4_fsinfo_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002642 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
Chuck Lever9f06c712010-12-14 14:59:18 +00002645 encode_compound_hdr(xdr, req, &hdr);
2646 encode_sequence(xdr, &args->seq_args, &hdr);
2647 encode_putfh(xdr, args->fh, &hdr);
2648 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002649 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650}
2651
2652/*
2653 * a PATHCONF request
2654 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002655static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002656 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002658 const struct nfs4_pathconf_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002660 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662
Chuck Lever9f06c712010-12-14 14:59:18 +00002663 encode_compound_hdr(xdr, req, &hdr);
2664 encode_sequence(xdr, &args->seq_args, &hdr);
2665 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002666 encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
2667 ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002668 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669}
2670
2671/*
2672 * a STATFS request
2673 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002674static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002675 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002677 const struct nfs4_statfs_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002679 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681
Chuck Lever9f06c712010-12-14 14:59:18 +00002682 encode_compound_hdr(xdr, req, &hdr);
2683 encode_sequence(xdr, &args->seq_args, &hdr);
2684 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002685 encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
2686 ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002687 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688}
2689
2690/*
2691 * GETATTR_BITMAP request
2692 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002693static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2694 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002695 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002697 const struct nfs4_server_caps_arg *args = data;
Kinglong Mee8c612822015-08-26 21:12:58 +08002698 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002700 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702
Chuck Lever9f06c712010-12-14 14:59:18 +00002703 encode_compound_hdr(xdr, req, &hdr);
2704 encode_sequence(xdr, &args->seq_args, &hdr);
2705 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002706 encode_getattr(xdr, bitmask, NULL, 3, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002707 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708}
2709
2710/*
2711 * a RENEW request
2712 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002713static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002714 const void *data)
2715
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002717 const struct nfs_client *clp = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002719 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 };
2721
Chuck Lever9f06c712010-12-14 14:59:18 +00002722 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002723 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002724 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725}
2726
2727/*
2728 * a SETCLIENTID request
2729 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002730static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2731 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002732 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002734 const struct nfs4_setclientid *sc = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002736 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 };
2738
Chuck Lever9f06c712010-12-14 14:59:18 +00002739 encode_compound_hdr(xdr, req, &hdr);
2740 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002741 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742}
2743
2744/*
2745 * a SETCLIENTID_CONFIRM request
2746 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002747static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2748 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002749 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002751 const struct nfs4_setclientid_res *arg = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002753 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755
Chuck Lever9f06c712010-12-14 14:59:18 +00002756 encode_compound_hdr(xdr, req, &hdr);
2757 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002758 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759}
2760
2761/*
2762 * DELEGRETURN request
2763 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002764static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2765 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002766 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002768 const struct nfs4_delegreturnargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002770 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772
Chuck Lever9f06c712010-12-14 14:59:18 +00002773 encode_compound_hdr(xdr, req, &hdr);
2774 encode_sequence(xdr, &args->seq_args, &hdr);
2775 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust586f1c32016-11-15 15:03:33 -05002776 if (args->lr_args)
2777 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05002778 if (args->bitmask)
2779 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002780 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002781 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782}
2783
2784/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002785 * Encode FS_LOCATIONS request
2786 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002787static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2788 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002789 const void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002790{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002791 const struct nfs4_fs_locations_arg *args = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002792 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002793 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002794 };
Benny Halevy28f56692009-04-01 09:22:09 -04002795 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002796
Chuck Lever9f06c712010-12-14 14:59:18 +00002797 encode_compound_hdr(xdr, req, &hdr);
2798 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002799 if (args->migration) {
2800 encode_putfh(xdr, args->fh, &hdr);
2801 replen = hdr.replen;
2802 encode_fs_locations(xdr, args->bitmask, &hdr);
2803 if (args->renew)
2804 encode_renew(xdr, args->clientid, &hdr);
2805 } else {
2806 encode_putfh(xdr, args->dir_fh, &hdr);
2807 encode_lookup(xdr, args->name, &hdr);
2808 replen = hdr.replen;
2809 encode_fs_locations(xdr, args->bitmask, &hdr);
2810 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002811
Chuck Levercf500ba2019-02-11 11:25:20 -05002812 rpc_prepare_reply_pages(req, (struct page **)&args->page, 0,
Chuck Lever29e7ca72019-04-09 10:44:16 -04002813 PAGE_SIZE, replen + 1);
Andy Adamsond0179312008-12-23 16:06:17 -05002814 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002815}
2816
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002817/*
2818 * Encode SECINFO request
2819 */
2820static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2821 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002822 const void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002823{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002824 const struct nfs4_secinfo_arg *args = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002825 struct compound_hdr hdr = {
2826 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2827 };
2828
2829 encode_compound_hdr(xdr, req, &hdr);
2830 encode_sequence(xdr, &args->seq_args, &hdr);
2831 encode_putfh(xdr, args->dir_fh, &hdr);
2832 encode_secinfo(xdr, args->name, &hdr);
2833 encode_nops(&hdr);
2834}
2835
Chuck Lever44c99932013-10-17 14:13:30 -04002836/*
2837 * Encode FSID_PRESENT request
2838 */
2839static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2840 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002841 const void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04002842{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002843 const struct nfs4_fsid_present_arg *args = data;
Chuck Lever44c99932013-10-17 14:13:30 -04002844 struct compound_hdr hdr = {
2845 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2846 };
2847
2848 encode_compound_hdr(xdr, req, &hdr);
2849 encode_sequence(xdr, &args->seq_args, &hdr);
2850 encode_putfh(xdr, args->fh, &hdr);
2851 encode_getfh(xdr, &hdr);
2852 if (args->renew)
2853 encode_renew(xdr, args->clientid, &hdr);
2854 encode_nops(&hdr);
2855}
2856
Benny Halevy99fe60d2009-04-01 09:22:29 -04002857#if defined(CONFIG_NFS_V4_1)
2858/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002859 * BIND_CONN_TO_SESSION request
2860 */
2861static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2862 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002863 const void *data)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002864{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002865 const struct nfs41_bind_conn_to_session_args *args = data;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002866 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002867 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002868 };
2869
2870 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002871 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002872 encode_nops(&hdr);
2873}
2874
2875/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002876 * EXCHANGE_ID request
2877 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002878static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2879 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002880 const void *data)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002881{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002882 const struct nfs41_exchange_id_args *args = data;
Benny Halevy99fe60d2009-04-01 09:22:29 -04002883 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002884 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002885 };
2886
Chuck Lever9f06c712010-12-14 14:59:18 +00002887 encode_compound_hdr(xdr, req, &hdr);
2888 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002889 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002890}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002891
2892/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002893 * a CREATE_SESSION request
2894 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002895static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2896 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002897 const void *data)
Andy Adamsonfc931582009-04-01 09:22:31 -04002898{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002899 const struct nfs41_create_session_args *args = data;
Andy Adamsonfc931582009-04-01 09:22:31 -04002900 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002901 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002902 };
2903
Chuck Lever9f06c712010-12-14 14:59:18 +00002904 encode_compound_hdr(xdr, req, &hdr);
2905 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002906 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002907}
2908
2909/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002910 * a DESTROY_SESSION request
2911 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002912static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2913 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002914 const void *data)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002915{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002916 const struct nfs4_session *session = data;
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002917 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002918 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002919 };
2920
Chuck Lever9f06c712010-12-14 14:59:18 +00002921 encode_compound_hdr(xdr, req, &hdr);
2922 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002923 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002924}
2925
2926/*
Trond Myklebust66245532012-05-25 17:18:09 -04002927 * a DESTROY_CLIENTID request
2928 */
2929static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2930 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002931 const void *data)
Trond Myklebust66245532012-05-25 17:18:09 -04002932{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002933 const struct nfs_client *clp = data;
Trond Myklebust66245532012-05-25 17:18:09 -04002934 struct compound_hdr hdr = {
2935 .minorversion = clp->cl_mvops->minor_version,
2936 };
2937
2938 encode_compound_hdr(xdr, req, &hdr);
2939 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2940 encode_nops(&hdr);
2941}
2942
2943/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002944 * a SEQUENCE request
2945 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002946static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002947 const void *data)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002948{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002949 const struct nfs4_sequence_args *args = data;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002950 struct compound_hdr hdr = {
2951 .minorversion = nfs4_xdr_minorversion(args),
2952 };
2953
Chuck Lever9f06c712010-12-14 14:59:18 +00002954 encode_compound_hdr(xdr, req, &hdr);
2955 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002956 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002957}
2958
Donald Buczek0efb01b2019-07-07 21:26:08 +02002959#endif
2960
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002961/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002962 * a GET_LEASE_TIME request
2963 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002964static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2965 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002966 const void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002967{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002968 const struct nfs4_get_lease_time_args *args = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04002969 struct compound_hdr hdr = {
2970 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2971 };
Fred Isamandae100c2011-07-30 20:52:37 -04002972 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002973
Chuck Lever9f06c712010-12-14 14:59:18 +00002974 encode_compound_hdr(xdr, req, &hdr);
2975 encode_sequence(xdr, &args->la_seq_args, &hdr);
2976 encode_putrootfh(xdr, &hdr);
2977 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002978 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002979}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002980
Donald Buczek0efb01b2019-07-07 21:26:08 +02002981#ifdef CONFIG_NFS_V4_1
2982
Ricardo Labiaga180197532009-12-05 16:08:40 -05002983/*
2984 * a RECLAIM_COMPLETE request
2985 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002986static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2987 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002988 const void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002989{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002990 const struct nfs41_reclaim_complete_args *args = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05002991 struct compound_hdr hdr = {
2992 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2993 };
2994
Chuck Lever9f06c712010-12-14 14:59:18 +00002995 encode_compound_hdr(xdr, req, &hdr);
2996 encode_sequence(xdr, &args->seq_args, &hdr);
2997 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002998 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002999}
3000
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003001/*
3002 * Encode GETDEVICEINFO request
3003 */
Chuck Lever9f06c712010-12-14 14:59:18 +00003004static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
3005 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003006 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003007{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003008 const struct nfs4_getdeviceinfo_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003009 struct compound_hdr hdr = {
3010 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3011 };
3012
Chuck Lever9f06c712010-12-14 14:59:18 +00003013 encode_compound_hdr(xdr, req, &hdr);
3014 encode_sequence(xdr, &args->seq_args, &hdr);
3015 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003016
3017 /* set up reply kvec. Subtract notification bitmap max size (2)
3018 * so that notification bitmap is put in xdr_buf tail */
Chuck Levercf500ba2019-02-11 11:25:20 -05003019 rpc_prepare_reply_pages(req, args->pdev->pages, args->pdev->pgbase,
3020 args->pdev->pglen, hdr.replen - 2);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003021 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003022}
3023
3024/*
3025 * Encode LAYOUTGET request
3026 */
Chuck Lever9f06c712010-12-14 14:59:18 +00003027static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
3028 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003029 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003030{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003031 const struct nfs4_layoutget_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003032 struct compound_hdr hdr = {
3033 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3034 };
3035
Chuck Lever9f06c712010-12-14 14:59:18 +00003036 encode_compound_hdr(xdr, req, &hdr);
3037 encode_sequence(xdr, &args->seq_args, &hdr);
3038 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3039 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04003040
Chuck Levercf500ba2019-02-11 11:25:20 -05003041 rpc_prepare_reply_pages(req, args->layout.pages, 0,
3042 args->layout.pglen, hdr.replen);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003043 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003044}
Andy Adamson863a3c62011-03-23 13:27:54 +00003045
3046/*
3047 * Encode LAYOUTCOMMIT request
3048 */
Benny Halevycbe82602011-05-22 19:52:37 +03003049static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3050 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003051 const void *priv)
Andy Adamson863a3c62011-03-23 13:27:54 +00003052{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003053 const struct nfs4_layoutcommit_args *args = priv;
Benny Halevyac7db722011-05-22 19:53:48 +03003054 struct nfs4_layoutcommit_data *data =
3055 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00003056 struct compound_hdr hdr = {
3057 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3058 };
3059
3060 encode_compound_hdr(xdr, req, &hdr);
3061 encode_sequence(xdr, &args->seq_args, &hdr);
3062 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03003063 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003064 encode_getfattr(xdr, args->bitmask, &hdr);
3065 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03003066}
3067
3068/*
3069 * Encode LAYOUTRETURN request
3070 */
3071static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3072 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003073 const void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03003074{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003075 const struct nfs4_layoutreturn_args *args = data;
Benny Halevycbe82602011-05-22 19:52:37 +03003076 struct compound_hdr hdr = {
3077 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3078 };
3079
3080 encode_compound_hdr(xdr, req, &hdr);
3081 encode_sequence(xdr, &args->seq_args, &hdr);
3082 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3083 encode_layoutreturn(xdr, args, &hdr);
3084 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003085}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003086
3087/*
3088 * Encode SECINFO_NO_NAME request
3089 */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003090static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003091 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003092 const void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003093{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003094 const struct nfs41_secinfo_no_name_args *args = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003095 struct compound_hdr hdr = {
3096 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3097 };
3098
3099 encode_compound_hdr(xdr, req, &hdr);
3100 encode_sequence(xdr, &args->seq_args, &hdr);
3101 encode_putrootfh(xdr, &hdr);
3102 encode_secinfo_no_name(xdr, args, &hdr);
3103 encode_nops(&hdr);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003104}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003105
3106/*
3107 * Encode TEST_STATEID request
3108 */
3109static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3110 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003111 const void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04003112{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003113 const struct nfs41_test_stateid_args *args = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04003114 struct compound_hdr hdr = {
3115 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3116 };
3117
3118 encode_compound_hdr(xdr, req, &hdr);
3119 encode_sequence(xdr, &args->seq_args, &hdr);
3120 encode_test_stateid(xdr, args, &hdr);
3121 encode_nops(&hdr);
3122}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003123
3124/*
3125 * Encode FREE_STATEID request
3126 */
3127static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3128 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003129 const void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003130{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003131 const struct nfs41_free_stateid_args *args = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003132 struct compound_hdr hdr = {
3133 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3134 };
3135
3136 encode_compound_hdr(xdr, req, &hdr);
3137 encode_sequence(xdr, &args->seq_args, &hdr);
3138 encode_free_stateid(xdr, args, &hdr);
3139 encode_nops(&hdr);
3140}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003141#endif /* CONFIG_NFS_V4_1 */
3142
Trond Myklebust683b57b2006-06-09 09:34:22 -04003143static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144{
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003145 ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3146 NFS4_OPAQUE_LIMIT);
Chuck Levereb72f482019-02-11 11:24:21 -05003147 if (unlikely(ret < 0))
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003148 return -EIO;
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003149 *len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 return 0;
3151}
3152
3153static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3154{
Al Viro8687b632006-10-19 23:28:48 -07003155 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156
Benny Halevyc0eae662009-08-14 17:20:14 +03003157 p = xdr_inline_decode(xdr, 8);
3158 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003159 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03003160 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003161 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003162
Benny Halevyc0eae662009-08-14 17:20:14 +03003163 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3164 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003165 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 hdr->tag = (char *)p;
3167 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003168 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003169 if (unlikely(hdr->nops < 1))
3170 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 return 0;
3172}
3173
Trond Myklebustc7848f62013-12-04 17:39:23 -05003174static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3175 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176{
Al Viro8687b632006-10-19 23:28:48 -07003177 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 uint32_t opnum;
3179 int32_t nfserr;
3180
Benny Halevyc0eae662009-08-14 17:20:14 +03003181 p = xdr_inline_decode(xdr, 8);
3182 if (unlikely(!p))
3183 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003184 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003185 if (unlikely(opnum != expected))
3186 goto out_bad_operation;
Chuck Leverf23f6582019-02-11 11:24:26 -05003187 if (unlikely(*p != cpu_to_be32(NFS_OK)))
3188 goto out_status;
3189 *nfs_retval = 0;
3190 return true;
3191out_status:
Benny Halevycccddf42009-08-14 17:20:19 +03003192 nfserr = be32_to_cpup(p);
Chuck Lever62a92ba2019-06-19 10:34:09 -04003193 trace_nfs4_xdr_status(xdr, opnum, nfserr);
Chuck Leverf23f6582019-02-11 11:24:26 -05003194 *nfs_retval = nfs4_stat_to_errno(nfserr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003195 return true;
3196out_bad_operation:
3197 dprintk("nfs: Server returned operation"
3198 " %d but we issued a request for %d\n",
3199 opnum, expected);
3200 *nfs_retval = -EREMOTEIO;
3201 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003202out_overflow:
Trond Myklebustc7848f62013-12-04 17:39:23 -05003203 *nfs_retval = -EIO;
3204 return false;
3205}
3206
3207static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3208{
3209 int retval;
3210
3211 __decode_op_hdr(xdr, expected, &retval);
3212 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213}
3214
3215/* Dummy routine */
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05003216static int decode_ace(struct xdr_stream *xdr, void *ace)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217{
Al Viro8687b632006-10-19 23:28:48 -07003218 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003219 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220 char *str;
3221
Benny Halevyc0eae662009-08-14 17:20:14 +03003222 p = xdr_inline_decode(xdr, 12);
Chuck Levereb72f482019-02-11 11:24:21 -05003223 if (unlikely(!p))
3224 return -EIO;
3225 return decode_opaque_inline(xdr, &strlen, &str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226}
3227
Trond Myklebust37c88762018-03-20 17:03:08 -04003228static ssize_t
3229decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230{
Trond Myklebust37c88762018-03-20 17:03:08 -04003231 ssize_t ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232
Trond Myklebust37c88762018-03-20 17:03:08 -04003233 ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
3234 if (likely(ret >= 0))
3235 return ret;
Chuck Levereb72f482019-02-11 11:24:21 -05003236 if (ret != -EMSGSIZE)
3237 return -EIO;
3238 return sz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239}
3240
Trond Myklebust37c88762018-03-20 17:03:08 -04003241static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3242{
3243 ssize_t ret;
3244 ret = decode_bitmap4(xdr, bitmap, 3);
3245 return ret < 0 ? ret : 0;
3246}
3247
Trond Myklebust256e48b2012-06-21 11:18:13 -04003248static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249{
Al Viro8687b632006-10-19 23:28:48 -07003250 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251
Benny Halevyc0eae662009-08-14 17:20:14 +03003252 p = xdr_inline_decode(xdr, 4);
3253 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003254 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003255 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003256 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 return 0;
3258}
3259
3260static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3261{
3262 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003263 int ret;
3264 ret = decode_attr_bitmap(xdr, bitmask);
3265 if (unlikely(ret < 0))
3266 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3268 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003269 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3270 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3271 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 return 0;
3273}
3274
3275static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3276{
Al Viro8687b632006-10-19 23:28:48 -07003277 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003278 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279
3280 *type = 0;
3281 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3282 return -EIO;
3283 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003284 p = xdr_inline_decode(xdr, 4);
3285 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003286 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003287 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003289 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 return -EIO;
3291 }
3292 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003293 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003295 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003296 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297}
3298
Chuck Lever264e6352012-03-01 17:02:05 -05003299static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3300 uint32_t *bitmap, uint32_t *type)
3301{
3302 __be32 *p;
3303
3304 *type = 0;
3305 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3306 return -EIO;
3307 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3308 p = xdr_inline_decode(xdr, 4);
3309 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003310 return -EIO;
Chuck Lever264e6352012-03-01 17:02:05 -05003311 *type = be32_to_cpup(p);
3312 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3313 }
3314 dprintk("%s: expire type=0x%x\n", __func__, *type);
3315 return 0;
Chuck Lever264e6352012-03-01 17:02:05 -05003316}
3317
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3319{
Al Viro8687b632006-10-19 23:28:48 -07003320 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003321 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322
3323 *change = 0;
3324 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3325 return -EIO;
3326 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003327 p = xdr_inline_decode(xdr, 8);
3328 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003329 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003330 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003332 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003334 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003336 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337}
3338
3339static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3340{
Al Viro8687b632006-10-19 23:28:48 -07003341 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003342 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343
3344 *size = 0;
3345 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3346 return -EIO;
3347 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003348 p = xdr_inline_decode(xdr, 8);
3349 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003350 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003351 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003353 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003355 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003356 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357}
3358
3359static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3360{
Al Viro8687b632006-10-19 23:28:48 -07003361 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362
3363 *res = 0;
3364 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3365 return -EIO;
3366 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003367 p = xdr_inline_decode(xdr, 4);
3368 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003369 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003370 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3372 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003373 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 return 0;
3375}
3376
3377static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3378{
Al Viro8687b632006-10-19 23:28:48 -07003379 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380
3381 *res = 0;
3382 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3383 return -EIO;
3384 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003385 p = xdr_inline_decode(xdr, 4);
3386 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003387 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003388 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3390 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003391 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 return 0;
3393}
3394
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003395static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396{
Al Viro8687b632006-10-19 23:28:48 -07003397 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003398 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399
3400 fsid->major = 0;
3401 fsid->minor = 0;
3402 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3403 return -EIO;
3404 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003405 p = xdr_inline_decode(xdr, 16);
3406 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003407 return -EIO;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003408 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003409 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003411 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003413 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 (unsigned long long)fsid->major,
3415 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003416 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417}
3418
3419static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3420{
Al Viro8687b632006-10-19 23:28:48 -07003421 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422
3423 *res = 60;
3424 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3425 return -EIO;
3426 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003427 p = xdr_inline_decode(xdr, 4);
3428 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003429 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003430 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3432 }
Donald Buczek2eaf4262019-07-07 21:26:07 +02003433 dprintk("%s: lease time=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 return 0;
3435}
3436
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003437static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003438{
3439 __be32 *p;
3440
3441 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3442 return -EIO;
3443 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3444 p = xdr_inline_decode(xdr, 4);
3445 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003446 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003447 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003448 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003449 }
3450 return 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003451}
3452
Kinglong Mee8c612822015-08-26 21:12:58 +08003453static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3454 uint32_t *bitmap, uint32_t *bitmask)
3455{
3456 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3457 int ret;
3458 ret = decode_attr_bitmap(xdr, bitmask);
3459 if (unlikely(ret < 0))
3460 return ret;
3461 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3462 } else
3463 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3464 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3465 bitmask[0], bitmask[1], bitmask[2]);
3466 return 0;
3467}
3468
Bryan Schumakerae42c702010-10-21 16:33:17 -04003469static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3470{
3471 __be32 *p;
Frank Sorenson86bbd742018-10-23 10:34:57 -05003472 u32 len;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003473
Trond Myklebust7ad07352010-10-23 15:34:20 -04003474 if (fh != NULL)
3475 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003476
3477 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3478 return -EIO;
3479 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3480 p = xdr_inline_decode(xdr, 4);
3481 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003482 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003483 len = be32_to_cpup(p);
3484 if (len > NFS4_FHSIZE)
3485 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003486 p = xdr_inline_decode(xdr, len);
3487 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003488 return -EIO;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003489 if (fh != NULL) {
3490 memcpy(fh->data, p, len);
3491 fh->size = len;
3492 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003493 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3494 }
3495 return 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003496}
3497
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3499{
Al Viro8687b632006-10-19 23:28:48 -07003500 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003502 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3504 return -EIO;
3505 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003506 p = xdr_inline_decode(xdr, 4);
3507 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003508 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003509 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3511 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003512 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513 return 0;
3514}
3515
3516static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3517{
Al Viro8687b632006-10-19 23:28:48 -07003518 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003519 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520
3521 *fileid = 0;
3522 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3523 return -EIO;
3524 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003525 p = xdr_inline_decode(xdr, 8);
3526 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003527 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003528 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003530 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003532 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003533 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534}
3535
Manoj Naik99baf622006-06-09 09:34:24 -04003536static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3537{
Al Viro8687b632006-10-19 23:28:48 -07003538 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003539 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003540
3541 *fileid = 0;
3542 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3543 return -EIO;
3544 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003545 p = xdr_inline_decode(xdr, 8);
3546 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003547 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003548 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003549 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003550 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003551 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003552 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003553 return ret;
Manoj Naik99baf622006-06-09 09:34:24 -04003554}
3555
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3557{
Al Viro8687b632006-10-19 23:28:48 -07003558 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 int status = 0;
3560
3561 *res = 0;
3562 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3563 return -EIO;
3564 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003565 p = xdr_inline_decode(xdr, 8);
3566 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003567 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003568 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3570 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003571 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 return status;
3573}
3574
3575static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3576{
Al Viro8687b632006-10-19 23:28:48 -07003577 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 int status = 0;
3579
3580 *res = 0;
3581 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3582 return -EIO;
3583 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003584 p = xdr_inline_decode(xdr, 8);
3585 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003586 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003587 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3589 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003590 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591 return status;
3592}
3593
3594static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3595{
Al Viro8687b632006-10-19 23:28:48 -07003596 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597 int status = 0;
3598
3599 *res = 0;
3600 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3601 return -EIO;
3602 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003603 p = xdr_inline_decode(xdr, 8);
3604 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003605 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003606 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3608 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003609 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 return status;
3611}
3612
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003613static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3614{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003615 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003616 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003617 int status = 0;
3618
Benny Halevyc0eae662009-08-14 17:20:14 +03003619 p = xdr_inline_decode(xdr, 4);
3620 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003621 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003622 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003623 if (n == 0)
3624 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003625 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003626 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3627 dprintk("cannot parse %d components in path\n", n);
3628 goto out_eio;
3629 }
3630 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003631 struct nfs4_string *component = &path->components[path->ncomponents];
3632 status = decode_opaque_inline(xdr, &component->len, &component->data);
3633 if (unlikely(status != 0))
3634 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003635 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003636 pr_cont("%s%.*s ",
3637 (path->ncomponents != n ? "/ " : ""),
3638 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003639 }
3640out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003641 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003642root_path:
3643/* a root pathname is sent as a zero component4 */
3644 path->ncomponents = 1;
3645 path->components[0].len=0;
3646 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003647 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003648 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003649out_eio:
3650 dprintk(" status %d", status);
3651 status = -EIO;
3652 goto out;
3653}
3654
3655static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003656{
3657 int n;
Al Viro8687b632006-10-19 23:28:48 -07003658 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003659 int status = -EIO;
3660
3661 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3662 goto out;
3663 status = 0;
3664 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3665 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003666 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003667 status = -EIO;
3668 /* Ignore borken servers that return unrequested attrs */
3669 if (unlikely(res == NULL))
3670 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003671 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003672 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003673 if (unlikely(status != 0))
3674 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003675 p = xdr_inline_decode(xdr, 4);
3676 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003677 goto out_eio;
Benny Halevycccddf42009-08-14 17:20:19 +03003678 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003679 if (n <= 0)
3680 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003681 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003682 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003683 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003684
Trond Myklebust809b4262013-03-27 11:54:45 -04003685 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3686 break;
3687 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003688 p = xdr_inline_decode(xdr, 4);
3689 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003690 goto out_eio;
Benny Halevycccddf42009-08-14 17:20:19 +03003691 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003692
Chuck Lever02a29762012-03-01 17:00:31 -05003693 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003694 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3695 struct nfs4_string *server;
3696
3697 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003698 unsigned int i;
3699 dprintk("%s: using first %u of %u servers "
3700 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003701 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003702 NFS4_FS_LOCATION_MAXSERVERS,
3703 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003704 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003705 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003706 char *data;
3707 status = decode_opaque_inline(xdr, &len, &data);
3708 if (unlikely(status != 0))
3709 goto out_eio;
3710 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003711 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003712 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003713 server = &loc->servers[loc->nservers];
3714 status = decode_opaque_inline(xdr, &server->len, &server->data);
3715 if (unlikely(status != 0))
3716 goto out_eio;
3717 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003718 }
3719 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003720 if (unlikely(status != 0))
3721 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003722 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003723 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003724 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003725out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003726 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003727 return status;
3728out_eio:
3729 status = -EIO;
3730 goto out;
3731}
3732
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3734{
Al Viro8687b632006-10-19 23:28:48 -07003735 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 int status = 0;
3737
3738 *res = 0;
3739 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3740 return -EIO;
3741 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003742 p = xdr_inline_decode(xdr, 8);
3743 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003744 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003745 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3747 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003748 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 return status;
3750}
3751
3752static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3753{
Al Viro8687b632006-10-19 23:28:48 -07003754 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 int status = 0;
3756
3757 *maxlink = 1;
3758 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3759 return -EIO;
3760 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003761 p = xdr_inline_decode(xdr, 4);
3762 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003763 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003764 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3766 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003767 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 return status;
3769}
3770
3771static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3772{
Al Viro8687b632006-10-19 23:28:48 -07003773 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774 int status = 0;
3775
3776 *maxname = 1024;
3777 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3778 return -EIO;
3779 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003780 p = xdr_inline_decode(xdr, 4);
3781 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003782 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003783 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3785 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003786 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787 return status;
3788}
3789
3790static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3791{
Al Viro8687b632006-10-19 23:28:48 -07003792 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 int status = 0;
3794
3795 *res = 1024;
3796 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3797 return -EIO;
3798 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3799 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003800 p = xdr_inline_decode(xdr, 8);
3801 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003802 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003803 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 if (maxread > 0x7FFFFFFF)
3805 maxread = 0x7FFFFFFF;
3806 *res = (uint32_t)maxread;
3807 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3808 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003809 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 return status;
3811}
3812
3813static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3814{
Al Viro8687b632006-10-19 23:28:48 -07003815 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 int status = 0;
3817
3818 *res = 1024;
3819 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3820 return -EIO;
3821 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3822 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003823 p = xdr_inline_decode(xdr, 8);
3824 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003825 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003826 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827 if (maxwrite > 0x7FFFFFFF)
3828 maxwrite = 0x7FFFFFFF;
3829 *res = (uint32_t)maxwrite;
3830 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3831 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003832 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 return status;
3834}
3835
Trond Myklebustbca79472009-03-11 14:10:26 -04003836static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837{
Trond Myklebustbca79472009-03-11 14:10:26 -04003838 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003839 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003840 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841
3842 *mode = 0;
3843 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3844 return -EIO;
3845 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003846 p = xdr_inline_decode(xdr, 4);
3847 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003848 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003849 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003850 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003852 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003854 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003855 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856}
3857
3858static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3859{
Al Viro8687b632006-10-19 23:28:48 -07003860 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003861 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862
3863 *nlink = 1;
3864 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3865 return -EIO;
3866 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003867 p = xdr_inline_decode(xdr, 4);
3868 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003869 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003870 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003872 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003874 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003875 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876}
3877
Trond Myklebust686a8162017-02-19 16:08:32 -05003878static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3879 struct nfs4_string *name, gfp_t gfp_flags)
3880{
3881 ssize_t ret;
3882
3883 ret = xdr_stream_decode_string_dup(xdr, &name->data,
3884 XDR_MAX_NETOBJ, gfp_flags);
3885 name->len = 0;
3886 if (ret > 0)
3887 name->len = ret;
3888 return ret;
3889}
3890
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003891static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003892 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003893 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894{
Trond Myklebust686a8162017-02-19 16:08:32 -05003895 ssize_t len;
3896 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897
Eric W. Biedermane5782072013-02-01 14:22:02 -08003898 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3900 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003901 if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3902 return 0;
3903 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3904
3905 if (owner_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04003906 len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05003907 if (len <= 0)
3908 goto out;
3909 dprintk("%s: name=%s\n", __func__, owner_name->data);
3910 return NFS_ATTR_FATTR_OWNER_NAME;
3911 } else {
3912 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3913 XDR_MAX_NETOBJ);
3914 if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3915 goto out;
3916 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3917 return NFS_ATTR_FATTR_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003919out:
Chuck Levereb72f482019-02-11 11:24:21 -05003920 if (len == -EBADMSG)
3921 return -EIO;
3922 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923}
3924
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003925static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003926 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003927 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928{
Trond Myklebust686a8162017-02-19 16:08:32 -05003929 ssize_t len;
3930 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931
Eric W. Biedermane5782072013-02-01 14:22:02 -08003932 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3934 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003935 if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
3936 return 0;
3937 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3938
3939 if (group_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04003940 len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05003941 if (len <= 0)
3942 goto out;
3943 dprintk("%s: name=%s\n", __func__, group_name->data);
Kinglong Mee6f1f6222017-03-06 17:49:42 +08003944 return NFS_ATTR_FATTR_GROUP_NAME;
Trond Myklebust686a8162017-02-19 16:08:32 -05003945 } else {
3946 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3947 XDR_MAX_NETOBJ);
3948 if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
3949 goto out;
3950 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3951 return NFS_ATTR_FATTR_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003953out:
Chuck Levereb72f482019-02-11 11:24:21 -05003954 if (len == -EBADMSG)
3955 return -EIO;
3956 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957}
3958
3959static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3960{
Al Viro8687b632006-10-19 23:28:48 -07003961 uint32_t major = 0, minor = 0;
3962 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003963 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964
3965 *rdev = MKDEV(0,0);
3966 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3967 return -EIO;
3968 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3969 dev_t tmp;
3970
Benny Halevyc0eae662009-08-14 17:20:14 +03003971 p = xdr_inline_decode(xdr, 8);
3972 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003973 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03003974 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003975 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 tmp = MKDEV(major, minor);
3977 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3978 *rdev = tmp;
3979 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003980 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003982 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003983 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984}
3985
3986static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3987{
Al Viro8687b632006-10-19 23:28:48 -07003988 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 int status = 0;
3990
3991 *res = 0;
3992 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3993 return -EIO;
3994 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003995 p = xdr_inline_decode(xdr, 8);
3996 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003997 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003998 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4000 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004001 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 return status;
4003}
4004
4005static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4006{
Al Viro8687b632006-10-19 23:28:48 -07004007 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 int status = 0;
4009
4010 *res = 0;
4011 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4012 return -EIO;
4013 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004014 p = xdr_inline_decode(xdr, 8);
4015 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004016 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004017 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4019 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004020 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021 return status;
4022}
4023
4024static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4025{
Al Viro8687b632006-10-19 23:28:48 -07004026 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027 int status = 0;
4028
4029 *res = 0;
4030 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4031 return -EIO;
4032 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004033 p = xdr_inline_decode(xdr, 8);
4034 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004035 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004036 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4038 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004039 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 return status;
4041}
4042
4043static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4044{
Al Viro8687b632006-10-19 23:28:48 -07004045 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004046 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047
4048 *used = 0;
4049 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4050 return -EIO;
4051 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004052 p = xdr_inline_decode(xdr, 8);
4053 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004054 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004055 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004057 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004059 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004061 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062}
4063
Trond Myklebust36b37432018-03-20 17:03:10 -04004064static __be32 *
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004065xdr_decode_nfstime4(__be32 *p, struct timespec64 *t)
Trond Myklebust36b37432018-03-20 17:03:10 -04004066{
4067 __u64 sec;
4068
4069 p = xdr_decode_hyper(p, &sec);
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004070 t-> tv_sec = sec;
Trond Myklebust36b37432018-03-20 17:03:10 -04004071 t->tv_nsec = be32_to_cpup(p++);
4072 return p;
4073}
4074
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004075static int decode_attr_time(struct xdr_stream *xdr, struct timespec64 *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076{
Al Viro8687b632006-10-19 23:28:48 -07004077 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078
Trond Myklebust36b37432018-03-20 17:03:10 -04004079 p = xdr_inline_decode(xdr, nfstime4_maxsz << 2);
Benny Halevyc0eae662009-08-14 17:20:14 +03004080 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004081 return -EIO;
Trond Myklebust36b37432018-03-20 17:03:10 -04004082 xdr_decode_nfstime4(p, time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083 return 0;
4084}
4085
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004086static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087{
4088 int status = 0;
4089
4090 time->tv_sec = 0;
4091 time->tv_nsec = 0;
4092 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4093 return -EIO;
4094 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4095 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004096 if (status == 0)
4097 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4099 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004100 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101 return status;
4102}
4103
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004104static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105{
4106 int status = 0;
4107
4108 time->tv_sec = 0;
4109 time->tv_nsec = 0;
4110 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4111 return -EIO;
4112 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4113 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004114 if (status == 0)
4115 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4117 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004118 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119 return status;
4120}
4121
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004122static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004123 struct timespec64 *time)
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004124{
4125 int status = 0;
4126
4127 time->tv_sec = 0;
4128 time->tv_nsec = 0;
4129 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4130 return -EIO;
4131 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4132 status = decode_attr_time(xdr, time);
4133 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4134 }
4135 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4136 (long)time->tv_nsec);
4137 return status;
4138}
4139
David Quigleyaa9c2662013-05-22 12:50:44 -04004140static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4141 struct nfs4_label *label)
4142{
4143 uint32_t pi = 0;
4144 uint32_t lfs = 0;
4145 __u32 len;
4146 __be32 *p;
4147 int status = 0;
4148
4149 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4150 return -EIO;
4151 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4152 p = xdr_inline_decode(xdr, 4);
4153 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004154 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004155 lfs = be32_to_cpup(p++);
4156 p = xdr_inline_decode(xdr, 4);
4157 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004158 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004159 pi = be32_to_cpup(p++);
4160 p = xdr_inline_decode(xdr, 4);
4161 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004162 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004163 len = be32_to_cpup(p++);
4164 p = xdr_inline_decode(xdr, len);
4165 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004166 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004167 if (len < NFS4_MAXLABELLEN) {
4168 if (label) {
4169 memcpy(label->label, p, len);
4170 label->len = len;
4171 label->pi = pi;
4172 label->lfs = lfs;
4173 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4174 }
4175 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4176 } else
4177 printk(KERN_WARNING "%s: label too long (%u)!\n",
4178 __func__, len);
4179 }
4180 if (label && label->label)
4181 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4182 (char *)label->label, label->len, label->pi, label->lfs);
4183 return status;
David Quigleyaa9c2662013-05-22 12:50:44 -04004184}
4185
Trond Myklebuste86d5a02019-10-04 16:38:56 -04004186static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187{
4188 int status = 0;
4189
4190 time->tv_sec = 0;
4191 time->tv_nsec = 0;
4192 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4193 return -EIO;
4194 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4195 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004196 if (status == 0)
4197 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4199 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004200 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201 return status;
4202}
4203
Trond Myklebust256e48b2012-06-21 11:18:13 -04004204static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205{
4206 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004207 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208
4209 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004210 dprintk("%s: server returned incorrect attribute length: "
4211 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004212 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 attrwords << 2,
4214 (attrwords < nwords) ? '<' : '>',
4215 nwords << 2);
4216 return -EIO;
4217 }
4218 return 0;
4219}
4220
4221static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4222{
Al Viro8687b632006-10-19 23:28:48 -07004223 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224
Benny Halevyc0eae662009-08-14 17:20:14 +03004225 p = xdr_inline_decode(xdr, 20);
4226 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004227 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03004228 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004229 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004230 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231 return 0;
4232}
4233
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004234static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235{
Al Viro8687b632006-10-19 23:28:48 -07004236 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004237 uint32_t supp, acc;
4238 int status;
4239
4240 status = decode_op_hdr(xdr, OP_ACCESS);
4241 if (status)
4242 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004243 p = xdr_inline_decode(xdr, 8);
4244 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004245 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03004246 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004247 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004248 *supported = supp;
4249 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250 return 0;
4251}
4252
Benny Halevy07d30432009-08-14 17:19:52 +03004253static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004255 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
Chuck Levereb72f482019-02-11 11:24:21 -05004256 if (unlikely(ret < 0))
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004257 return -EIO;
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004258 return 0;
Benny Halevy07d30432009-08-14 17:19:52 +03004259}
4260
4261static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4262{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004263 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264}
4265
Trond Myklebust93b717f2016-05-16 17:42:43 -04004266static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4267{
4268 stateid->type = NFS4_OPEN_STATEID_TYPE;
4269 return decode_stateid(xdr, stateid);
4270}
4271
4272static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4273{
4274 stateid->type = NFS4_LOCK_STATEID_TYPE;
4275 return decode_stateid(xdr, stateid);
4276}
4277
4278static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4279{
4280 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4281 return decode_stateid(xdr, stateid);
4282}
4283
Trond Myklebustfcd88432017-11-07 12:39:44 -05004284static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4285{
4286 nfs4_stateid dummy;
4287
4288 nfs4_stateid_copy(stateid, &invalid_stateid);
4289 return decode_stateid(xdr, &dummy);
4290}
4291
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4293{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294 int status;
4295
4296 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004297 if (status != -EIO)
4298 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004299 if (!status)
Trond Myklebustfcd88432017-11-07 12:39:44 -05004300 status = decode_invalid_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004301 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302}
4303
Benny Halevydb942bb2009-08-14 17:19:56 +03004304static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4305{
Chuck Levercd937102012-03-02 17:14:31 -05004306 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307}
4308
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004309static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4310{
4311 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4312}
4313
Fred Isaman0b7c0152012-04-20 14:47:39 -04004314static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 int status;
4317
4318 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004319 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004320 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004321 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322}
4323
4324static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4325{
Al Viro8687b632006-10-19 23:28:48 -07004326 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327 uint32_t bmlen;
4328 int status;
4329
4330 status = decode_op_hdr(xdr, OP_CREATE);
4331 if (status)
4332 return status;
4333 if ((status = decode_change_info(xdr, cinfo)))
4334 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004335 p = xdr_inline_decode(xdr, 4);
4336 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004337 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004338 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004339 p = xdr_inline_decode(xdr, bmlen << 2);
4340 if (likely(p))
4341 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004342 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343}
4344
4345static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4346{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004347 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004348 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349 int status;
4350
4351 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4352 goto xdr_error;
4353 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4354 goto xdr_error;
4355 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4356 goto xdr_error;
4357 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4358 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004359 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4360 &res->fh_expire_type)) != 0)
4361 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004362 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4363 goto xdr_error;
4364 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4365 goto xdr_error;
4366 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4367 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004368 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4369 res->exclcreat_bitmask)) != 0)
4370 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371 status = verify_attr_len(xdr, savep, attrlen);
4372xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004373 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374 return status;
4375}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004376
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4378{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004379 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004380 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004381 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004382
Linus Torvalds1da177e2005-04-16 15:20:36 -07004383 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4384 goto xdr_error;
4385 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4386 goto xdr_error;
4387 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4388 goto xdr_error;
4389
4390 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4391 goto xdr_error;
4392 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4393 goto xdr_error;
4394 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4395 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004396
4397 status = -EIO;
4398 if (unlikely(bitmap[0]))
4399 goto xdr_error;
4400
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4402 goto xdr_error;
4403 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4404 goto xdr_error;
4405 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4406 goto xdr_error;
4407
4408 status = verify_attr_len(xdr, savep, attrlen);
4409xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004410 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411 return status;
4412}
4413
4414static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4415{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004416 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004417 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004418 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004419
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4421 goto xdr_error;
4422 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4423 goto xdr_error;
4424 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4425 goto xdr_error;
4426
4427 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4428 goto xdr_error;
4429 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4430 goto xdr_error;
4431
4432 status = verify_attr_len(xdr, savep, attrlen);
4433xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004434 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435 return status;
4436}
4437
Andy Adamson88034c32012-05-23 05:02:34 -04004438static int decode_threshold_hint(struct xdr_stream *xdr,
4439 uint32_t *bitmap,
4440 uint64_t *res,
4441 uint32_t hint_bit)
4442{
4443 __be32 *p;
4444
4445 *res = 0;
4446 if (likely(bitmap[0] & hint_bit)) {
4447 p = xdr_inline_decode(xdr, 8);
4448 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004449 return -EIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004450 xdr_decode_hyper(p, res);
4451 }
4452 return 0;
Andy Adamson88034c32012-05-23 05:02:34 -04004453}
4454
4455static int decode_first_threshold_item4(struct xdr_stream *xdr,
4456 struct nfs4_threshold *res)
4457{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004458 __be32 *p;
4459 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004460 uint32_t bitmap[3] = {0,}, attrlen;
4461 int status;
4462
4463 /* layout type */
4464 p = xdr_inline_decode(xdr, 4);
Chuck Levereb72f482019-02-11 11:24:21 -05004465 if (unlikely(!p))
Andy Adamson88034c32012-05-23 05:02:34 -04004466 return -EIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004467 res->l_type = be32_to_cpup(p);
4468
4469 /* thi_hintset bitmap */
4470 status = decode_attr_bitmap(xdr, bitmap);
4471 if (status < 0)
4472 goto xdr_error;
4473
4474 /* thi_hintlist length */
4475 status = decode_attr_length(xdr, &attrlen, &savep);
4476 if (status < 0)
4477 goto xdr_error;
4478 /* thi_hintlist */
4479 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4480 if (status < 0)
4481 goto xdr_error;
4482 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4483 if (status < 0)
4484 goto xdr_error;
4485 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4486 THRESHOLD_RD_IO);
4487 if (status < 0)
4488 goto xdr_error;
4489 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4490 THRESHOLD_WR_IO);
4491 if (status < 0)
4492 goto xdr_error;
4493
4494 status = verify_attr_len(xdr, savep, attrlen);
4495 res->bm = bitmap[0];
4496
4497 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4498 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4499 res->wr_io_sz);
4500xdr_error:
4501 dprintk("%s ret=%d!\n", __func__, status);
4502 return status;
4503}
4504
4505/*
4506 * Thresholds on pNFS direct I/O vrs MDS I/O
4507 */
4508static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4509 uint32_t *bitmap,
4510 struct nfs4_threshold *res)
4511{
4512 __be32 *p;
4513 int status = 0;
4514 uint32_t num;
4515
4516 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4517 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004518 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004519 /* Did the server return an unrequested attribute? */
4520 if (unlikely(res == NULL))
4521 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004522 p = xdr_inline_decode(xdr, 4);
4523 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004524 return -EIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004525 num = be32_to_cpup(p);
4526 if (num == 0)
4527 return 0;
4528 if (num > 1)
4529 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4530 "drivers per filesystem not supported\n",
4531 __func__);
4532
4533 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004534 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004535 }
4536 return status;
Andy Adamson88034c32012-05-23 05:02:34 -04004537}
4538
Bryan Schumakerae42c702010-10-21 16:33:17 -04004539static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4540 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004541 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004542 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543{
Trond Myklebustbca79472009-03-11 14:10:26 -04004544 int status;
4545 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004546 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004547 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004549 status = decode_attr_type(xdr, bitmap, &type);
4550 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004552 fattr->mode = 0;
4553 if (status != 0) {
4554 fattr->mode |= nfs_type2fmt[type];
4555 fattr->valid |= status;
4556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004558 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4559 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004561 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004562
4563 status = decode_attr_size(xdr, bitmap, &fattr->size);
4564 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004565 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004566 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004567
4568 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4569 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004571 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004572
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004573 err = 0;
4574 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004575 if (status < 0)
4576 goto xdr_error;
4577
4578 status = decode_attr_filehandle(xdr, bitmap, fh);
4579 if (status < 0)
4580 goto xdr_error;
4581
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004582 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4583 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004584 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004585 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004586
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004587 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004588 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004589 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004590 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004591
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004592 status = -EIO;
4593 if (unlikely(bitmap[0]))
4594 goto xdr_error;
4595
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004596 status = decode_attr_mode(xdr, bitmap, &fmode);
4597 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004599 if (status != 0) {
4600 fattr->mode |= fmode;
4601 fattr->valid |= status;
4602 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004603
4604 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4605 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004607 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004608
Trond Myklebust6926afd12012-01-07 13:22:46 -05004609 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004610 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004612 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004613
Trond Myklebust6926afd12012-01-07 13:22:46 -05004614 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004615 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004617 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004618
4619 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4620 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004622 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004623
4624 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4625 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004626 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004627 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004628
4629 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4630 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004632 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004633
4634 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4635 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004636 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004637 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004638
4639 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4640 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004642 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004643
Trond Myklebust28331a42011-04-27 13:47:52 -04004644 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004645 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004646 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004647 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004648
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004649 status = -EIO;
4650 if (unlikely(bitmap[1]))
4651 goto xdr_error;
4652
Andy Adamson88034c32012-05-23 05:02:34 -04004653 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4654 if (status < 0)
4655 goto xdr_error;
4656
David Quigleyaa9c2662013-05-22 12:50:44 -04004657 if (label) {
4658 status = decode_attr_security_label(xdr, bitmap, label);
4659 if (status < 0)
4660 goto xdr_error;
4661 fattr->valid |= status;
4662 }
4663
Bryan Schumakerae42c702010-10-21 16:33:17 -04004664xdr_error:
4665 dprintk("%s: xdr returned %d\n", __func__, -status);
4666 return status;
4667}
4668
4669static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004670 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004671 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004672{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004673 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004674 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004675 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004676 int status;
4677
4678 status = decode_op_hdr(xdr, OP_GETATTR);
4679 if (status < 0)
4680 goto xdr_error;
4681
4682 status = decode_attr_bitmap(xdr, bitmap);
4683 if (status < 0)
4684 goto xdr_error;
4685
4686 status = decode_attr_length(xdr, &attrlen, &savep);
4687 if (status < 0)
4688 goto xdr_error;
4689
David Quigleyaa9c2662013-05-22 12:50:44 -04004690 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4691 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004692 if (status < 0)
4693 goto xdr_error;
4694
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004695 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004697 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698 return status;
4699}
4700
David Quigleyaa9c2662013-05-22 12:50:44 -04004701static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4702 struct nfs4_label *label, const struct nfs_server *server)
4703{
4704 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4705}
4706
Bryan Schumakerae42c702010-10-21 16:33:17 -04004707static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004708 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004709{
David Quigleyaa9c2662013-05-22 12:50:44 -04004710 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004711}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712
Andy Adamson504913f2010-10-20 00:17:57 -04004713/*
Jeff Layton3132e492016-08-10 15:58:24 -04004714 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004715 */
Jeff Layton3132e492016-08-10 15:58:24 -04004716static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004717 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004718{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004719 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004720 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004721
4722 p = xdr_inline_decode(xdr, 4);
4723 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004724 return -EIO;
Jeff Laytonca440c32016-09-15 14:40:49 -04004725 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004726
4727 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004728 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004729 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004730
4731 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004732 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004733 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004734 return -EIO;
Jeff Laytonca440c32016-09-15 14:40:49 -04004735
4736 /* If we get too many, then just cap it at the max */
4737 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4738 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4739 __func__, fsinfo->nlayouttypes);
4740 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4741 }
4742
4743 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4744 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004745 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004746}
4747
4748/*
4749 * The type of file system exported.
4750 * Note we must ensure that layouttype is set in any non-error case.
4751 */
4752static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004753 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004754{
4755 int status = 0;
4756
4757 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4758 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4759 return -EIO;
4760 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004761 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004762 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004763 }
Andy Adamson504913f2010-10-20 00:17:57 -04004764 return status;
4765}
4766
Fred Isamandae100c2011-07-30 20:52:37 -04004767/*
4768 * The prefered block size for layout directed io
4769 */
4770static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4771 uint32_t *res)
4772{
4773 __be32 *p;
4774
4775 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4776 *res = 0;
4777 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4778 p = xdr_inline_decode(xdr, 4);
Chuck Levereb72f482019-02-11 11:24:21 -05004779 if (unlikely(!p))
Fred Isamandae100c2011-07-30 20:52:37 -04004780 return -EIO;
Fred Isamandae100c2011-07-30 20:52:37 -04004781 *res = be32_to_cpup(p);
4782 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4783 }
4784 return 0;
4785}
4786
Peng Tao2a92ee92015-09-26 02:24:37 +08004787/*
4788 * The granularity of a CLONE operation.
4789 */
4790static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4791 uint32_t *res)
4792{
4793 __be32 *p;
4794
4795 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4796 *res = 0;
4797 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4798 p = xdr_inline_decode(xdr, 4);
Chuck Levereb72f482019-02-11 11:24:21 -05004799 if (unlikely(!p))
Peng Tao2a92ee92015-09-26 02:24:37 +08004800 return -EIO;
Peng Tao2a92ee92015-09-26 02:24:37 +08004801 *res = be32_to_cpup(p);
4802 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4803 }
4804 return 0;
4805}
4806
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4808{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004809 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004810 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811 int status;
4812
4813 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4814 goto xdr_error;
4815 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4816 goto xdr_error;
4817 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4818 goto xdr_error;
4819
4820 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4821
4822 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4823 goto xdr_error;
4824 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4825 goto xdr_error;
4826 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4827 goto xdr_error;
4828 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4829 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4830 goto xdr_error;
4831 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004832
4833 status = -EIO;
4834 if (unlikely(bitmap[0]))
4835 goto xdr_error;
4836
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004837 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4838 if (status != 0)
4839 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004840 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004841 if (status != 0)
4842 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004843
4844 status = -EIO;
4845 if (unlikely(bitmap[1]))
4846 goto xdr_error;
4847
Fred Isamandae100c2011-07-30 20:52:37 -04004848 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4849 if (status)
4850 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004851 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4852 if (status)
4853 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854
4855 status = verify_attr_len(xdr, savep, attrlen);
4856xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004857 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858 return status;
4859}
4860
4861static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4862{
Al Viro8687b632006-10-19 23:28:48 -07004863 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864 uint32_t len;
4865 int status;
4866
Trond Myklebust9936781d2007-07-17 21:52:41 -04004867 /* Zero handle first to allow comparisons */
4868 memset(fh, 0, sizeof(*fh));
4869
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870 status = decode_op_hdr(xdr, OP_GETFH);
4871 if (status)
4872 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873
Benny Halevyc0eae662009-08-14 17:20:14 +03004874 p = xdr_inline_decode(xdr, 4);
4875 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004876 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004877 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 if (len > NFS4_FHSIZE)
4879 return -EIO;
4880 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004881 p = xdr_inline_decode(xdr, len);
4882 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004883 return -EIO;
Benny Halevy99398d02009-08-14 17:20:05 +03004884 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885 return 0;
4886}
4887
4888static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4889{
4890 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004891
Linus Torvalds1da177e2005-04-16 15:20:36 -07004892 status = decode_op_hdr(xdr, OP_LINK);
4893 if (status)
4894 return status;
4895 return decode_change_info(xdr, cinfo);
4896}
4897
4898/*
4899 * We create the owner, so we know a proper owner.id length is 4.
4900 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004901static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004903 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004904 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004905 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004907 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004908 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004909 return -EIO;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004910 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004911 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004912 type = be32_to_cpup(p++); /* 4 byte read */
4913 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004914 fl->fl_start = (loff_t)offset;
4915 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4916 if (length == ~(uint64_t)0)
4917 fl->fl_end = OFFSET_MAX;
4918 fl->fl_type = F_WRLCK;
4919 if (type & 1)
4920 fl->fl_type = F_RDLCK;
4921 fl->fl_pid = 0;
4922 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004923 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4924 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4925 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Chuck Levereb72f482019-02-11 11:24:21 -05004926 if (likely(!p))
4927 return -EIO;
4928 return -NFS4ERR_DENIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004929}
4930
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004931static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004932{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004933 int status;
4934
4935 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004936 if (status == -EIO)
4937 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004938 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04004939 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004940 if (unlikely(status))
4941 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004943 status = decode_lock_denied(xdr, NULL);
4944 if (res->open_seqid != NULL)
4945 nfs_increment_open_seqid(status, res->open_seqid);
4946 nfs_increment_lock_seqid(status, res->lock_seqid);
4947out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948 return status;
4949}
4950
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004951static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952{
4953 int status;
4954 status = decode_op_hdr(xdr, OP_LOCKT);
4955 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004956 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957 return status;
4958}
4959
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004960static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962 int status;
4963
4964 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004965 if (status != -EIO)
4966 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004967 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04004968 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004969 return status;
4970}
4971
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004972static int decode_release_lockowner(struct xdr_stream *xdr)
4973{
4974 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4975}
4976
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977static int decode_lookup(struct xdr_stream *xdr)
4978{
4979 return decode_op_hdr(xdr, OP_LOOKUP);
4980}
4981
Jeff Layton5b5faaf2017-06-29 06:34:52 -07004982static int decode_lookupp(struct xdr_stream *xdr)
4983{
4984 return decode_op_hdr(xdr, OP_LOOKUPP);
4985}
4986
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04004988static int decode_space_limit(struct xdr_stream *xdr,
4989 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990{
Andy Adamson05d564f2008-12-23 16:06:15 -05004991 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04004993 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994
Benny Halevyc0eae662009-08-14 17:20:14 +03004995 p = xdr_inline_decode(xdr, 12);
4996 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004997 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03004998 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005000 case NFS4_LIMIT_SIZE:
5001 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005002 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005003 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005004 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005005 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005006 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005008 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005009 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010 return 0;
5011}
5012
Trond Myklebust6ae37332015-01-30 14:21:14 -05005013static int decode_rw_delegation(struct xdr_stream *xdr,
5014 uint32_t delegation_type,
5015 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016{
Andy Adamson05d564f2008-12-23 16:06:15 -05005017 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005018 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019
Trond Myklebust93b717f2016-05-16 17:42:43 -04005020 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005021 if (unlikely(status))
5022 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005023 p = xdr_inline_decode(xdr, 4);
5024 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005025 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005026 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005027
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005029 case NFS4_OPEN_DELEGATE_READ:
5030 res->delegation_type = FMODE_READ;
5031 break;
5032 case NFS4_OPEN_DELEGATE_WRITE:
5033 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005034 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035 return -EIO;
5036 }
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05005037 return decode_ace(xdr, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038}
5039
Trond Myklebust6ae37332015-01-30 14:21:14 -05005040static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5041{
5042 __be32 *p;
5043 uint32_t why_no_delegation;
5044
5045 p = xdr_inline_decode(xdr, 4);
5046 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005047 return -EIO;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005048 why_no_delegation = be32_to_cpup(p);
5049 switch (why_no_delegation) {
5050 case WND4_CONTENTION:
5051 case WND4_RESOURCE:
5052 xdr_inline_decode(xdr, 4);
5053 /* Ignore for now */
5054 }
5055 return 0;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005056}
5057
5058static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5059{
5060 __be32 *p;
5061 uint32_t delegation_type;
5062
5063 p = xdr_inline_decode(xdr, 4);
5064 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005065 return -EIO;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005066 delegation_type = be32_to_cpup(p);
5067 res->delegation_type = 0;
5068 switch (delegation_type) {
5069 case NFS4_OPEN_DELEGATE_NONE:
5070 return 0;
5071 case NFS4_OPEN_DELEGATE_READ:
5072 case NFS4_OPEN_DELEGATE_WRITE:
5073 return decode_rw_delegation(xdr, delegation_type, res);
5074 case NFS4_OPEN_DELEGATE_NONE_EXT:
5075 return decode_no_delegation(xdr, res);
5076 }
5077 return -EIO;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005078}
5079
Linus Torvalds1da177e2005-04-16 15:20:36 -07005080static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5081{
Andy Adamson05d564f2008-12-23 16:06:15 -05005082 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005083 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005084 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085
Trond Myklebustc7848f62013-12-04 17:39:23 -05005086 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5087 return status;
5088 nfs_increment_open_seqid(status, res->seqid);
5089 if (status)
5090 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005091 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005092 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005093 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005094
Andy Adamson05d564f2008-12-23 16:06:15 -05005095 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005096
Benny Halevyc0eae662009-08-14 17:20:14 +03005097 p = xdr_inline_decode(xdr, 8);
5098 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005099 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005100 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005101 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005102 if (bmlen > 10)
5103 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104
Benny Halevyc0eae662009-08-14 17:20:14 +03005105 p = xdr_inline_decode(xdr, bmlen << 2);
5106 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005107 return -EIO;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005108 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5109 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005110 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005111 for (; i < NFS4_BITMAP_SIZE; i++)
5112 res->attrset[i] = 0;
5113
Linus Torvalds1da177e2005-04-16 15:20:36 -07005114 return decode_delegation(xdr, res);
5115xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005116 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117 return -EIO;
5118}
5119
5120static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5121{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005122 int status;
5123
Andy Adamson05d564f2008-12-23 16:06:15 -05005124 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005125 if (status != -EIO)
5126 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005127 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005128 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005129 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130}
5131
5132static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5133{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005134 int status;
5135
5136 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005137 if (status != -EIO)
5138 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005139 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005140 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005141 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005142}
5143
5144static int decode_putfh(struct xdr_stream *xdr)
5145{
5146 return decode_op_hdr(xdr, OP_PUTFH);
5147}
5148
5149static int decode_putrootfh(struct xdr_stream *xdr)
5150{
5151 return decode_op_hdr(xdr, OP_PUTROOTFH);
5152}
5153
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005154static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5155 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156{
Al Viro8687b632006-10-19 23:28:48 -07005157 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005158 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005159 int status;
5160
5161 status = decode_op_hdr(xdr, OP_READ);
5162 if (status)
5163 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005164 p = xdr_inline_decode(xdr, 8);
5165 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005166 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005167 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005168 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005169 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005171 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005172 "count %u > recvd %u\n", count, recvd);
5173 count = recvd;
5174 eof = 0;
5175 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005176 res->eof = eof;
5177 res->count = count;
5178 return 0;
5179}
5180
5181static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5182{
Chuck Leverbcecff72007-10-26 13:32:03 -04005183 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005184 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185
5186 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005187 if (!status)
5188 status = decode_verifier(xdr, readdir->verifier.data);
5189 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005191 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005192 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005193 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005194 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005195}
5196
5197static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5198{
5199 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005200 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005201 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005202 int status;
5203
5204 status = decode_op_hdr(xdr, OP_READLINK);
5205 if (status)
5206 return status;
5207
5208 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005209 p = xdr_inline_decode(xdr, 4);
5210 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005211 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005212 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005213 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005214 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215 return -ENAMETOOLONG;
5216 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005217 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005219 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220 "count %u > recvd %u\n", len, recvd);
5221 return -EIO;
5222 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223 /*
5224 * The XDR encode routine has set things up so that
5225 * the link text will be copied directly into the
5226 * buffer. We just have to do overflow-checking,
5227 * and and null-terminate the text (the VFS expects
5228 * null-termination).
5229 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005230 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005231 return 0;
5232}
5233
5234static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5235{
5236 int status;
5237
5238 status = decode_op_hdr(xdr, OP_REMOVE);
5239 if (status)
5240 goto out;
5241 status = decode_change_info(xdr, cinfo);
5242out:
5243 return status;
5244}
5245
5246static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5247 struct nfs4_change_info *new_cinfo)
5248{
5249 int status;
5250
5251 status = decode_op_hdr(xdr, OP_RENAME);
5252 if (status)
5253 goto out;
5254 if ((status = decode_change_info(xdr, old_cinfo)))
5255 goto out;
5256 status = decode_change_info(xdr, new_cinfo);
5257out:
5258 return status;
5259}
5260
5261static int decode_renew(struct xdr_stream *xdr)
5262{
5263 return decode_op_hdr(xdr, OP_RENEW);
5264}
5265
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005266static int
5267decode_restorefh(struct xdr_stream *xdr)
5268{
5269 return decode_op_hdr(xdr, OP_RESTOREFH);
5270}
5271
J. Bruce Fields029d1052005-06-22 17:16:22 +00005272static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005273 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005274{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005275 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005276 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005277 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005278 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005279 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005280
Andy Adamsonbf118a32011-12-07 11:55:27 -05005281 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005282 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5283 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005284
Trond Myklebust519d3952012-08-14 17:30:10 -04005285 xdr_enter_page(xdr, xdr->buf->page_len);
5286
Trond Myklebustcff298c2012-08-14 17:14:17 -04005287 /* Calculate the offset of the page data */
5288 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005289
J. Bruce Fields029d1052005-06-22 17:16:22 +00005290 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5291 goto out;
5292 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5293 goto out;
5294
5295 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5296 return -EIO;
5297 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005298
Andy Adamsonbf118a32011-12-07 11:55:27 -05005299 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5300 * are stored with the acl data to handle the problem of
5301 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005302 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005303 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005304
5305 /* Check for receive buffer overflow */
5306 if (res->acl_len > (xdr->nwords << 2) ||
5307 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5308 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005309 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005310 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005311 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005312 } else
5313 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005314
5315out:
5316 return status;
5317}
5318
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319static int
5320decode_savefh(struct xdr_stream *xdr)
5321{
5322 return decode_op_hdr(xdr, OP_SAVEFH);
5323}
5324
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005325static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005326{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005327 int status;
5328
Linus Torvalds1da177e2005-04-16 15:20:36 -07005329 status = decode_op_hdr(xdr, OP_SETATTR);
5330 if (status)
5331 return status;
Trond Myklebust37c88762018-03-20 17:03:08 -04005332 if (decode_bitmap4(xdr, NULL, 0) >= 0)
Benny Halevyc0eae662009-08-14 17:20:14 +03005333 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005334 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005335}
5336
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005337static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005338{
Al Viro8687b632006-10-19 23:28:48 -07005339 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005340 uint32_t opnum;
5341 int32_t nfserr;
5342
Benny Halevyc0eae662009-08-14 17:20:14 +03005343 p = xdr_inline_decode(xdr, 8);
5344 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005345 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005346 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005347 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005348 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005349 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005350 return -EIO;
5351 }
Benny Halevycccddf42009-08-14 17:20:19 +03005352 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005353 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005354 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5355 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005356 return -EIO;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005357 p = xdr_decode_hyper(p, &res->clientid);
5358 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005359 } else if (nfserr == NFSERR_CLID_INUSE) {
5360 uint32_t len;
5361
5362 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005363 p = xdr_inline_decode(xdr, 4);
5364 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005365 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005366 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005367 p = xdr_inline_decode(xdr, len);
5368 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005369 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005370
5371 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005372 p = xdr_inline_decode(xdr, 4);
5373 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005374 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005375 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005376 p = xdr_inline_decode(xdr, len);
5377 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005378 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005379 return -NFSERR_CLID_INUSE;
5380 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005381 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005382
5383 return 0;
5384}
5385
5386static int decode_setclientid_confirm(struct xdr_stream *xdr)
5387{
5388 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5389}
5390
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005391static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005392{
Al Viro8687b632006-10-19 23:28:48 -07005393 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394 int status;
5395
5396 status = decode_op_hdr(xdr, OP_WRITE);
5397 if (status)
5398 return status;
5399
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005400 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005401 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005402 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005403 res->count = be32_to_cpup(p++);
5404 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005405 return decode_write_verifier(xdr, &res->verf->verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406}
5407
5408static int decode_delegreturn(struct xdr_stream *xdr)
5409{
5410 return decode_op_hdr(xdr, OP_DELEGRETURN);
5411}
5412
Chuck Leverfb15b262013-03-16 15:54:34 -04005413static int decode_secinfo_gss(struct xdr_stream *xdr,
5414 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005415{
Chuck Leverfb15b262013-03-16 15:54:34 -04005416 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005417 __be32 *p;
5418
5419 p = xdr_inline_decode(xdr, 4);
5420 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005421 return -EIO;
Chuck Leverfb15b262013-03-16 15:54:34 -04005422 oid_len = be32_to_cpup(p);
5423 if (oid_len > GSS_OID_MAX_LEN)
Chuck Levereb72f482019-02-11 11:24:21 -05005424 return -EINVAL;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005425
Chuck Leverfb15b262013-03-16 15:54:34 -04005426 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005427 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005428 return -EIO;
Chuck Leverfb15b262013-03-16 15:54:34 -04005429 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5430 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005431
5432 p = xdr_inline_decode(xdr, 8);
5433 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005434 return -EIO;
Chuck Leverfb15b262013-03-16 15:54:34 -04005435 flavor->flavor_info.qop = be32_to_cpup(p++);
5436 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005437
5438 return 0;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005439}
5440
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005441static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005442{
Chuck Leverfb15b262013-03-16 15:54:34 -04005443 struct nfs4_secinfo4 *sec_flavor;
5444 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005445 int status;
5446 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005447
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005448 p = xdr_inline_decode(xdr, 4);
5449 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005450 return -EIO;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005451
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005452 res->flavors->num_flavors = 0;
5453 num_flavors = be32_to_cpup(p);
5454
5455 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005456 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005457 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005458 break;
5459
5460 p = xdr_inline_decode(xdr, 4);
5461 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005462 return -EIO;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005463 sec_flavor->flavor = be32_to_cpup(p);
5464
5465 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005466 status = decode_secinfo_gss(xdr, sec_flavor);
5467 if (status)
5468 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005469 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005470 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005471 }
5472
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005473 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005474out:
5475 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005476}
5477
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005478static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5479{
5480 int status = decode_op_hdr(xdr, OP_SECINFO);
5481 if (status)
5482 return status;
5483 return decode_secinfo_common(xdr, res);
5484}
5485
Benny Halevy99fe60d2009-04-01 09:22:29 -04005486#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005487static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5488{
5489 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5490 if (status)
5491 return status;
5492 return decode_secinfo_common(xdr, res);
5493}
5494
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005495static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5496{
5497 __be32 *p;
5498 uint32_t bitmap_words;
5499 unsigned int i;
5500
5501 p = xdr_inline_decode(xdr, 4);
Pan Bian4edabfd2017-04-23 14:49:41 +08005502 if (!p)
5503 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005504 bitmap_words = be32_to_cpup(p++);
5505 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5506 return -EIO;
5507 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5508 for (i = 0; i < bitmap_words; i++)
5509 op_map->u.words[i] = be32_to_cpup(p++);
5510
5511 return 0;
5512}
5513
Benny Halevy99fe60d2009-04-01 09:22:29 -04005514static int decode_exchange_id(struct xdr_stream *xdr,
5515 struct nfs41_exchange_id_res *res)
5516{
5517 __be32 *p;
5518 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005519 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005520 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005521 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005522
5523 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5524 if (status)
5525 return status;
5526
Benny Halevyc0eae662009-08-14 17:20:14 +03005527 p = xdr_inline_decode(xdr, 8);
5528 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005529 return -EIO;
Trond Myklebust32b01312012-05-26 13:41:04 -04005530 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005531 p = xdr_inline_decode(xdr, 12);
5532 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005533 return -EIO;
Trond Myklebust32b01312012-05-26 13:41:04 -04005534 res->seqid = be32_to_cpup(p++);
5535 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005536
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005537 res->state_protect.how = be32_to_cpup(p);
5538 switch (res->state_protect.how) {
5539 case SP4_NONE:
5540 break;
5541 case SP4_MACH_CRED:
5542 status = decode_op_map(xdr, &res->state_protect.enforce);
5543 if (status)
5544 return status;
5545 status = decode_op_map(xdr, &res->state_protect.allow);
5546 if (status)
5547 return status;
5548 break;
5549 default:
5550 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005551 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005552 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005553
Chuck Leveracdeb692012-05-21 22:46:16 -04005554 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005555 p = xdr_inline_decode(xdr, 8);
5556 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005557 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005558 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005559
Chuck Leveracdeb692012-05-21 22:46:16 -04005560 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005561 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5562 if (unlikely(status))
5563 return status;
Chuck Leveracdeb692012-05-21 22:46:16 -04005564 memcpy(res->server_owner->major_id, dummy_str, dummy);
5565 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005566
Chuck Leveracdeb692012-05-21 22:46:16 -04005567 /* server_scope4 */
5568 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5569 if (unlikely(status))
5570 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005571 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5572 res->server_scope->server_scope_sz = dummy;
5573
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005574 /* Implementation Id */
5575 p = xdr_inline_decode(xdr, 4);
5576 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005577 return -EIO;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005578 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005579
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005580 if (impl_id_count) {
5581 /* nii_domain */
5582 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5583 if (unlikely(status))
5584 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005585 memcpy(res->impl_id->domain, dummy_str, dummy);
5586
5587 /* nii_name */
5588 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5589 if (unlikely(status))
5590 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005591 memcpy(res->impl_id->name, dummy_str, dummy);
5592
5593 /* nii_date */
5594 p = xdr_inline_decode(xdr, 12);
5595 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005596 return -EIO;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005597 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5598 res->impl_id->date.nseconds = be32_to_cpup(p);
5599
5600 /* if there's more than one entry, ignore the rest */
5601 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005602 return 0;
5603}
Andy Adamsonfc931582009-04-01 09:22:31 -04005604
5605static int decode_chan_attrs(struct xdr_stream *xdr,
5606 struct nfs4_channel_attrs *attrs)
5607{
5608 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005609 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005610
Benny Halevyc0eae662009-08-14 17:20:14 +03005611 p = xdr_inline_decode(xdr, 28);
5612 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005613 return -EIO;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005614 val = be32_to_cpup(p++); /* headerpadsz */
5615 if (val)
5616 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005617 attrs->max_rqst_sz = be32_to_cpup(p++);
5618 attrs->max_resp_sz = be32_to_cpup(p++);
5619 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5620 attrs->max_ops = be32_to_cpup(p++);
5621 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005622 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005623 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005624 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5625 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005626 return -EINVAL;
5627 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005628 if (nr_attrs == 1) {
5629 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5630 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005631 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005632 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005633 return 0;
5634}
5635
Benny Halevye78291e2009-08-14 17:20:00 +03005636static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5637{
5638 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005639}
5640
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005641static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5642 struct nfs41_bind_conn_to_session_res *res)
5643{
5644 __be32 *p;
5645 int status;
5646
5647 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5648 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005649 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005650 if (unlikely(status))
5651 return status;
5652
5653 /* dir flags, rdma mode bool */
5654 p = xdr_inline_decode(xdr, 8);
5655 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005656 return -EIO;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005657
5658 res->dir = be32_to_cpup(p++);
5659 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5660 return -EIO;
5661 if (be32_to_cpup(p) == 0)
5662 res->use_conn_in_rdma_mode = false;
5663 else
5664 res->use_conn_in_rdma_mode = true;
5665
5666 return 0;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005667}
5668
Andy Adamsonfc931582009-04-01 09:22:31 -04005669static int decode_create_session(struct xdr_stream *xdr,
5670 struct nfs41_create_session_res *res)
5671{
5672 __be32 *p;
5673 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005674
5675 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005676 if (!status)
Trond Myklebust79969dd12015-02-18 11:30:18 -08005677 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005678 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005679 return status;
5680
Andy Adamsonfc931582009-04-01 09:22:31 -04005681 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005682 p = xdr_inline_decode(xdr, 8);
5683 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005684 return -EIO;
Trond Myklebust79969dd12015-02-18 11:30:18 -08005685 res->seqid = be32_to_cpup(p++);
5686 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005687
5688 /* Channel attributes */
Trond Myklebust79969dd12015-02-18 11:30:18 -08005689 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005690 if (!status)
Trond Myklebust79969dd12015-02-18 11:30:18 -08005691 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005692 return status;
5693}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005694
5695static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5696{
5697 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5698}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005699
Trond Myklebust66245532012-05-25 17:18:09 -04005700static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5701{
5702 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5703}
5704
Ricardo Labiaga180197532009-12-05 16:08:40 -05005705static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5706{
5707 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5708}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005709#endif /* CONFIG_NFS_V4_1 */
5710
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005711static int decode_sequence(struct xdr_stream *xdr,
5712 struct nfs4_sequence_res *res,
5713 struct rpc_rqst *rqstp)
5714{
5715#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005716 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005717 struct nfs4_sessionid id;
5718 u32 dummy;
5719 int status;
5720 __be32 *p;
5721
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005722 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005723 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005724 if (!res->sr_slot->table->session)
5725 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005726
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005727 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005728 if (!status)
5729 status = decode_sessionid(xdr, &id);
5730 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005731 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005732
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005733 /*
5734 * If the server returns different values for sessionID, slotID or
5735 * sequence number, the server is looney tunes.
5736 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005737 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005738 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005739
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005740 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005741 NFS4_MAX_SESSIONID_LEN)) {
5742 dprintk("%s Invalid session id\n", __func__);
5743 goto out_err;
5744 }
Benny Halevye78291e2009-08-14 17:20:00 +03005745
Benny Halevyc0eae662009-08-14 17:20:14 +03005746 p = xdr_inline_decode(xdr, 20);
5747 if (unlikely(!p))
5748 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005749
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005750 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005751 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005752 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005753 dprintk("%s Invalid sequence number\n", __func__);
5754 goto out_err;
5755 }
5756 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005757 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005758 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005759 dprintk("%s Invalid slot id\n", __func__);
5760 goto out_err;
5761 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005762 /* highest slot id */
5763 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005764 /* target highest slot id */
5765 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005766 /* result flags */
5767 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005768 status = 0;
5769out_err:
5770 res->sr_status = status;
5771 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005772out_overflow:
Benny Halevyc0eae662009-08-14 17:20:14 +03005773 status = -EIO;
5774 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005775#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005776 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005777#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005778}
5779
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005780#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005781static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5782{
5783 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5784 return decode_stateid(xdr, stateid);
5785}
5786
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005787static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005788 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005789{
Trond Myklebust4e590802015-03-09 14:01:25 -04005790 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005791 __be32 *p;
5792 uint32_t len, type;
5793 int status;
5794
5795 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5796 if (status) {
5797 if (status == -ETOOSMALL) {
5798 p = xdr_inline_decode(xdr, 4);
5799 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005800 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005801 pdev->mincount = be32_to_cpup(p);
5802 dprintk("%s: Min count too small. mincnt = %u\n",
5803 __func__, pdev->mincount);
5804 }
5805 return status;
5806 }
5807
5808 p = xdr_inline_decode(xdr, 8);
5809 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005810 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005811 type = be32_to_cpup(p++);
5812 if (type != pdev->layout_type) {
5813 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5814 __func__, pdev->layout_type, type);
5815 return -EINVAL;
5816 }
5817 /*
5818 * Get the length of the opaque device_addr4. xdr_read_pages places
5819 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5820 * and places the remaining xdr data in xdr_buf->tail
5821 */
5822 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005823 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
Chuck Levereb72f482019-02-11 11:24:21 -05005824 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005825
5826 /* Parse notification bitmap, verifying that it is zero. */
5827 p = xdr_inline_decode(xdr, 4);
5828 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005829 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005830 len = be32_to_cpup(p);
5831 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005832 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005833
5834 p = xdr_inline_decode(xdr, 4 * len);
5835 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005836 return -EIO;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005837
Trond Myklebust4e590802015-03-09 14:01:25 -04005838 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005839 for (i = 1; i < len; i++) {
5840 if (be32_to_cpup(p++)) {
5841 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005842 __func__);
5843 return -EIO;
5844 }
5845 }
5846 }
5847 return 0;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005848}
5849
5850static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5851 struct nfs4_layoutget_res *res)
5852{
5853 __be32 *p;
5854 int status;
5855 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005856 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005857
5858 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5859 if (status)
Fred Isaman808ba322016-10-04 15:02:21 -04005860 goto out;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005861 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005862 if (unlikely(!p))
5863 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005864 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04005865 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005866 p = xdr_inline_decode(xdr, 4);
5867 if (unlikely(!p))
5868 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005869 layout_count = be32_to_cpup(p);
5870 if (!layout_count) {
5871 dprintk("%s: server responded with empty layout array\n",
5872 __func__);
Fred Isaman808ba322016-10-04 15:02:21 -04005873 status = -EINVAL;
5874 goto out;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005875 }
5876
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005877 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005878 if (unlikely(!p))
5879 goto out_overflow;
5880 p = xdr_decode_hyper(p, &res->range.offset);
5881 p = xdr_decode_hyper(p, &res->range.length);
5882 res->range.iomode = be32_to_cpup(p++);
5883 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005884 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005885
5886 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5887 __func__,
5888 (unsigned long)res->range.offset,
5889 (unsigned long)res->range.length,
5890 res->range.iomode,
5891 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005892 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005893
Trond Myklebust64bd5772012-06-20 22:35:05 -04005894 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005895 if (res->layoutp->len > recvd) {
5896 dprintk("NFS: server cheating in layoutget reply: "
5897 "layout len %u > recvd %u\n",
5898 res->layoutp->len, recvd);
Fred Isaman808ba322016-10-04 15:02:21 -04005899 status = -EINVAL;
5900 goto out;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005901 }
5902
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005903 if (layout_count > 1) {
5904 /* We only handle a length one array at the moment. Any
5905 * further entries are just ignored. Note that this means
5906 * the client may see a response that is less than the
5907 * minimum it requested.
5908 */
5909 dprintk("%s: server responded with %d layouts, dropping tail\n",
5910 __func__, layout_count);
5911 }
5912
Fred Isaman808ba322016-10-04 15:02:21 -04005913out:
5914 res->status = status;
5915 return status;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005916out_overflow:
Fred Isaman808ba322016-10-04 15:02:21 -04005917 status = -EIO;
5918 goto out;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005919}
Andy Adamson863a3c62011-03-23 13:27:54 +00005920
Benny Halevycbe82602011-05-22 19:52:37 +03005921static int decode_layoutreturn(struct xdr_stream *xdr,
5922 struct nfs4_layoutreturn_res *res)
5923{
5924 __be32 *p;
5925 int status;
5926
5927 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5928 if (status)
5929 return status;
5930 p = xdr_inline_decode(xdr, 4);
5931 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005932 return -EIO;
Benny Halevycbe82602011-05-22 19:52:37 +03005933 res->lrs_present = be32_to_cpup(p);
5934 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005935 status = decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustfcd88432017-11-07 12:39:44 -05005936 else
5937 nfs4_stateid_copy(&res->stateid, &invalid_stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03005938 return status;
Benny Halevycbe82602011-05-22 19:52:37 +03005939}
5940
Andy Adamson863a3c62011-03-23 13:27:54 +00005941static int decode_layoutcommit(struct xdr_stream *xdr,
5942 struct rpc_rqst *req,
5943 struct nfs4_layoutcommit_res *res)
5944{
5945 __be32 *p;
5946 __u32 sizechanged;
5947 int status;
5948
5949 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005950 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005951 if (status)
5952 return status;
5953
5954 p = xdr_inline_decode(xdr, 4);
5955 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005956 return -EIO;
Andy Adamson863a3c62011-03-23 13:27:54 +00005957 sizechanged = be32_to_cpup(p);
5958
5959 if (sizechanged) {
5960 /* throw away new size */
5961 p = xdr_inline_decode(xdr, 8);
5962 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005963 return -EIO;
Andy Adamson863a3c62011-03-23 13:27:54 +00005964 }
5965 return 0;
Andy Adamson863a3c62011-03-23 13:27:54 +00005966}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005967
5968static int decode_test_stateid(struct xdr_stream *xdr,
5969 struct nfs41_test_stateid_res *res)
5970{
5971 __be32 *p;
5972 int status;
5973 int num_res;
5974
5975 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5976 if (status)
5977 return status;
5978
5979 p = xdr_inline_decode(xdr, 4);
5980 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005981 return -EIO;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005982 num_res = be32_to_cpup(p++);
5983 if (num_res != 1)
Chuck Levereb72f482019-02-11 11:24:21 -05005984 return -EIO;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005985
5986 p = xdr_inline_decode(xdr, 4);
5987 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005988 return -EIO;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005989 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005990
5991 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005992}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005993
5994static int decode_free_stateid(struct xdr_stream *xdr,
5995 struct nfs41_free_stateid_res *res)
5996{
Andy Adamson9f79fb42013-09-10 12:56:29 -04005997 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005998 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005999}
Trond Myklebustcf805162016-11-15 14:56:07 -05006000#else
6001static inline
6002int decode_layoutreturn(struct xdr_stream *xdr,
6003 struct nfs4_layoutreturn_res *res)
6004{
6005 return 0;
6006}
Fred Isaman56f487f2016-09-21 11:43:41 -04006007
6008static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6009 struct nfs4_layoutget_res *res)
6010{
6011 return 0;
6012}
6013
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006014#endif /* CONFIG_NFS_V4_1 */
6015
Linus Torvalds1da177e2005-04-16 15:20:36 -07006016/*
Benny Halevy49c25592008-12-23 16:06:16 -05006017 * END OF "GENERIC" DECODE ROUTINES.
6018 */
6019
6020/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006021 * Decode OPEN_DOWNGRADE response
6022 */
Chuck Leverbf269552010-12-14 14:59:29 +00006023static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6024 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006025 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006026{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006027 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006028 struct compound_hdr hdr;
6029 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030
Chuck Leverbf269552010-12-14 14:59:29 +00006031 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006032 if (status)
6033 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006034 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006035 if (status)
6036 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006037 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006038 if (status)
6039 goto out;
Trond Myklebustb6808142016-11-20 13:34:16 -05006040 if (res->lr_res) {
6041 status = decode_layoutreturn(xdr, res->lr_res);
6042 res->lr_ret = status;
6043 if (status)
6044 goto out;
6045 }
Chuck Leverbf269552010-12-14 14:59:29 +00006046 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006047out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006048 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006049}
6050
6051/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006052 * Decode ACCESS response
6053 */
Chuck Leverbf269552010-12-14 14:59:29 +00006054static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006055 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006057 struct nfs4_accessres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006058 struct compound_hdr hdr;
6059 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006060
Chuck Leverbf269552010-12-14 14:59:29 +00006061 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006062 if (status)
6063 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006064 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006065 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006066 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006067 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006068 if (status != 0)
6069 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006070 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006071 if (status != 0)
6072 goto out;
Trond Myklebust8bcbe7d2018-03-20 17:03:11 -04006073 if (res->fattr)
6074 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006075out:
6076 return status;
6077}
6078
6079/*
6080 * Decode LOOKUP response
6081 */
Chuck Leverbf269552010-12-14 14:59:29 +00006082static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006083 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006084{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006085 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006086 struct compound_hdr hdr;
6087 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006088
Chuck Leverbf269552010-12-14 14:59:29 +00006089 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006090 if (status)
6091 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006092 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006093 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006094 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006095 status = decode_putfh(xdr);
6096 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006098 status = decode_lookup(xdr);
6099 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006100 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006101 status = decode_getfh(xdr, res->fh);
6102 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006104 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006105out:
6106 return status;
6107}
6108
6109/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07006110 * Decode LOOKUPP response
6111 */
6112static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6113 void *data)
6114{
6115 struct nfs4_lookupp_res *res = data;
6116 struct compound_hdr hdr;
6117 int status;
6118
6119 status = decode_compound_hdr(xdr, &hdr);
6120 if (status)
6121 goto out;
6122 status = decode_sequence(xdr, &res->seq_res, rqstp);
6123 if (status)
6124 goto out;
6125 status = decode_putfh(xdr);
6126 if (status)
6127 goto out;
6128 status = decode_lookupp(xdr);
6129 if (status)
6130 goto out;
6131 status = decode_getfh(xdr, res->fh);
6132 if (status)
6133 goto out;
6134 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6135out:
6136 return status;
6137}
6138
6139/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006140 * Decode LOOKUP_ROOT response
6141 */
Chuck Leverbf269552010-12-14 14:59:29 +00006142static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6143 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006144 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006145{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006146 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006147 struct compound_hdr hdr;
6148 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006149
Chuck Leverbf269552010-12-14 14:59:29 +00006150 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006151 if (status)
6152 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006154 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_putrootfh(xdr);
6157 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006158 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_getfh(xdr, res->fh);
6160 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006161 status = decode_getfattr_label(xdr, res->fattr,
6162 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006163out:
6164 return status;
6165}
6166
6167/*
6168 * Decode REMOVE response
6169 */
Chuck Leverbf269552010-12-14 14:59:29 +00006170static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006171 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006173 struct nfs_removeres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006174 struct compound_hdr hdr;
6175 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006176
Chuck Leverbf269552010-12-14 14:59:29 +00006177 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006178 if (status)
6179 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006180 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006181 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006183 status = decode_putfh(xdr);
6184 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006185 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006186 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187out:
6188 return status;
6189}
6190
6191/*
6192 * Decode RENAME response
6193 */
Chuck Leverbf269552010-12-14 14:59:29 +00006194static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006195 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006197 struct nfs_renameres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198 struct compound_hdr hdr;
6199 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006200
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006202 if (status)
6203 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006204 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006205 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006207 status = decode_putfh(xdr);
6208 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006210 status = decode_savefh(xdr);
6211 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006212 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006213 status = decode_putfh(xdr);
6214 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006215 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006216 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006217out:
6218 return status;
6219}
6220
6221/*
6222 * Decode LINK response
6223 */
Chuck Leverbf269552010-12-14 14:59:29 +00006224static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006225 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006227 struct nfs4_link_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228 struct compound_hdr hdr;
6229 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006230
Chuck Leverbf269552010-12-14 14:59:29 +00006231 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006232 if (status)
6233 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006234 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006235 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006236 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006237 status = decode_putfh(xdr);
6238 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006240 status = decode_savefh(xdr);
6241 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006243 status = decode_putfh(xdr);
6244 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006245 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006246 status = decode_link(xdr, &res->cinfo);
6247 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006248 goto out;
6249 /*
6250 * Note order: OP_LINK leaves the directory as the current
6251 * filehandle.
6252 */
Chuck Leverbf269552010-12-14 14:59:29 +00006253 status = decode_restorefh(xdr);
6254 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006255 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006256 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006257out:
6258 return status;
6259}
6260
6261/*
6262 * Decode CREATE response
6263 */
Chuck Leverbf269552010-12-14 14:59:29 +00006264static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006265 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006266{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006267 struct nfs4_create_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006268 struct compound_hdr hdr;
6269 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006270
Chuck Leverbf269552010-12-14 14:59:29 +00006271 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006272 if (status)
6273 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006274 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006275 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_create(xdr, &res->dir_cinfo);
6281 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006282 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006283 status = decode_getfh(xdr, res->fh);
6284 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006286 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006287out:
6288 return status;
6289}
6290
6291/*
6292 * Decode SYMLINK response
6293 */
Chuck Leverbf269552010-12-14 14:59:29 +00006294static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006295 void *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006296{
Chuck Leverbf269552010-12-14 14:59:29 +00006297 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298}
6299
6300/*
6301 * Decode GETATTR response
6302 */
Chuck Leverbf269552010-12-14 14:59:29 +00006303static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006304 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006305{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006306 struct nfs4_getattr_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006307 struct compound_hdr hdr;
6308 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006309
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311 if (status)
6312 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006313 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006314 if (status)
6315 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006316 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006317 if (status)
6318 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006319 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006320out:
6321 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006322}
6323
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006324/*
6325 * Encode an SETACL request
6326 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006327static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006328 const void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006329{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006330 const struct nfs_setaclargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006331 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006332 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006333 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006334
Chuck Lever9f06c712010-12-14 14:59:18 +00006335 encode_compound_hdr(xdr, req, &hdr);
6336 encode_sequence(xdr, &args->seq_args, &hdr);
6337 encode_putfh(xdr, args->fh, &hdr);
6338 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006339 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006340}
Andy Adamson05d564f2008-12-23 16:06:15 -05006341
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006342/*
6343 * Decode SETACL response
6344 */
6345static int
Chuck Leverbf269552010-12-14 14:59:29 +00006346nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006347 void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006348{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006349 struct nfs_setaclres *res = data;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006350 struct compound_hdr hdr;
6351 int status;
6352
Chuck Leverbf269552010-12-14 14:59:29 +00006353 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006354 if (status)
6355 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006356 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006357 if (status)
6358 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006359 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006360 if (status)
6361 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006362 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006363out:
6364 return status;
6365}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006366
6367/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006368 * Decode GETACL response
6369 */
6370static int
Chuck Leverbf269552010-12-14 14:59:29 +00006371nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006372 void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006373{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006374 struct nfs_getaclres *res = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00006375 struct compound_hdr hdr;
6376 int status;
6377
Trond Myklebust331818f2012-02-03 18:30:53 -05006378 if (res->acl_scratch != NULL) {
6379 void *p = page_address(res->acl_scratch);
6380 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6381 }
Chuck Leverbf269552010-12-14 14:59:29 +00006382 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006383 if (status)
6384 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006385 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006386 if (status)
6387 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006388 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006389 if (status)
6390 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006391 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006392
6393out:
6394 return status;
6395}
6396
6397/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006398 * Decode CLOSE response
6399 */
Chuck Leverbf269552010-12-14 14:59:29 +00006400static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006401 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006402{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006403 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006404 struct compound_hdr hdr;
6405 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006406
Chuck Leverbf269552010-12-14 14:59:29 +00006407 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006408 if (status)
6409 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006411 if (status)
6412 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006413 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006414 if (status)
6415 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006416 if (res->lr_res) {
6417 status = decode_layoutreturn(xdr, res->lr_res);
6418 res->lr_ret = status;
6419 if (status)
6420 goto out;
6421 }
Trond Myklebustd8d84982016-12-19 12:14:44 -05006422 if (res->fattr != NULL) {
6423 status = decode_getfattr(xdr, res->fattr, res->server);
6424 if (status != 0)
6425 goto out;
6426 }
Chuck Leverbf269552010-12-14 14:59:29 +00006427 status = decode_close(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006428out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006429 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006430}
6431
6432/*
6433 * Decode OPEN response
6434 */
Chuck Leverbf269552010-12-14 14:59:29 +00006435static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006436 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006438 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006439 struct compound_hdr hdr;
6440 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006441
Chuck Leverbf269552010-12-14 14:59:29 +00006442 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006443 if (status)
6444 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006445 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006446 if (status)
6447 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006448 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006449 if (status)
6450 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006451 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006452 if (status)
6453 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006454 status = decode_getfh(xdr, &res->fh);
6455 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006456 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006457 if (res->access_request)
6458 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006459 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Fred Isaman56f487f2016-09-21 11:43:41 -04006460 if (res->lg_res)
6461 decode_layoutget(xdr, rqstp, res->lg_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_CONFIRM response
6468 */
Chuck Leverbf269552010-12-14 14:59:29 +00006469static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6470 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006471 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006473 struct nfs_open_confirmres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006474 struct compound_hdr hdr;
6475 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006476
Chuck Leverbf269552010-12-14 14:59:29 +00006477 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006478 if (status)
6479 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006480 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006481 if (status)
6482 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006483 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006485 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006486}
6487
6488/*
6489 * Decode OPEN response
6490 */
Chuck Leverbf269552010-12-14 14:59:29 +00006491static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6492 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006493 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006494{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006495 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006496 struct compound_hdr hdr;
6497 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006498
Chuck Leverbf269552010-12-14 14:59:29 +00006499 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006500 if (status)
6501 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006502 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006503 if (status)
6504 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006505 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006506 if (status)
6507 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006508 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006509 if (status)
6510 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006511 if (res->access_request)
6512 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd12012-01-07 13:22:46 -05006513 decode_getfattr(xdr, res->f_attr, res->server);
Fred Isaman56f487f2016-09-21 11:43:41 -04006514 if (res->lg_res)
6515 decode_layoutget(xdr, rqstp, res->lg_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006517 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518}
6519
6520/*
6521 * Decode SETATTR response
6522 */
Chuck Leverbf269552010-12-14 14:59:29 +00006523static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6524 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006525 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006526{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006527 struct nfs_setattrres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006528 struct compound_hdr hdr;
6529 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530
Chuck Leverbf269552010-12-14 14:59:29 +00006531 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006532 if (status)
6533 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006534 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006535 if (status)
6536 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006537 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006538 if (status)
6539 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006540 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006541 if (status)
6542 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006543 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006545 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006546}
6547
6548/*
6549 * Decode LOCK response
6550 */
Chuck Leverbf269552010-12-14 14:59:29 +00006551static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006552 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006553{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006554 struct nfs_lock_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006555 struct compound_hdr hdr;
6556 int status;
6557
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559 if (status)
6560 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006561 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006562 if (status)
6563 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006564 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006565 if (status)
6566 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006567 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006568out:
6569 return status;
6570}
6571
6572/*
6573 * Decode LOCKT response
6574 */
Chuck Leverbf269552010-12-14 14:59:29 +00006575static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006576 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006577{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006578 struct nfs_lockt_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006579 struct compound_hdr hdr;
6580 int status;
6581
Chuck Leverbf269552010-12-14 14:59:29 +00006582 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583 if (status)
6584 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006585 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006586 if (status)
6587 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006588 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006589 if (status)
6590 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006591 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006592out:
6593 return status;
6594}
6595
6596/*
6597 * Decode LOCKU response
6598 */
Chuck Leverbf269552010-12-14 14:59:29 +00006599static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006600 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006601{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006602 struct nfs_locku_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006603 struct compound_hdr hdr;
6604 int status;
6605
Chuck Leverbf269552010-12-14 14:59:29 +00006606 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006607 if (status)
6608 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006609 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006610 if (status)
6611 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006612 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613 if (status)
6614 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006615 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006616out:
6617 return status;
6618}
6619
Chuck Leverbf269552010-12-14 14:59:29 +00006620static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6621 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006622{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006623 struct compound_hdr hdr;
6624 int status;
6625
Chuck Leverbf269552010-12-14 14:59:29 +00006626 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006627 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006628 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006629 return status;
6630}
6631
Linus Torvalds1da177e2005-04-16 15:20:36 -07006632/*
6633 * Decode READLINK response
6634 */
Chuck Leverbf269552010-12-14 14:59:29 +00006635static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6636 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006637 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006639 struct nfs4_readlink_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640 struct compound_hdr hdr;
6641 int status;
6642
Chuck Leverbf269552010-12-14 14:59:29 +00006643 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644 if (status)
6645 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006646 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006647 if (status)
6648 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006649 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650 if (status)
6651 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006652 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653out:
6654 return status;
6655}
6656
6657/*
6658 * Decode READDIR response
6659 */
Chuck Leverbf269552010-12-14 14:59:29 +00006660static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006661 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006662{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006663 struct nfs4_readdir_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006664 struct compound_hdr hdr;
6665 int status;
6666
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006668 if (status)
6669 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006670 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006671 if (status)
6672 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006673 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006674 if (status)
6675 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006676 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006677out:
6678 return status;
6679}
6680
6681/*
6682 * Decode Read response
6683 */
Chuck Leverbf269552010-12-14 14:59:29 +00006684static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006685 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006686{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006687 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006688 struct compound_hdr hdr;
6689 int status;
6690
Chuck Leverbf269552010-12-14 14:59:29 +00006691 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006692 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006693 if (status)
6694 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006695 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006696 if (status)
6697 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006698 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699 if (status)
6700 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006701 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006702 if (!status)
6703 status = res->count;
6704out:
6705 return status;
6706}
6707
6708/*
6709 * Decode WRITE response
6710 */
Chuck Leverbf269552010-12-14 14:59:29 +00006711static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006712 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006713{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006714 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006715 struct compound_hdr hdr;
6716 int status;
6717
Chuck Leverbf269552010-12-14 14:59:29 +00006718 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006719 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006720 if (status)
6721 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006722 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006723 if (status)
6724 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006725 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006726 if (status)
6727 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006728 status = decode_write(xdr, res);
Trond Myklebust4f9838c72005-10-27 22:12:44 -04006729 if (status)
6730 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006731 if (res->fattr)
Trond Myklebust6926afd12012-01-07 13:22:46 -05006732 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006733 if (!status)
6734 status = res->count;
6735out:
6736 return status;
6737}
6738
6739/*
6740 * Decode COMMIT response
6741 */
Chuck Leverbf269552010-12-14 14:59:29 +00006742static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006743 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006744{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006745 struct nfs_commitres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006746 struct compound_hdr hdr;
6747 int status;
6748
Chuck Leverbf269552010-12-14 14:59:29 +00006749 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006750 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006751 if (status)
6752 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006753 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006754 if (status)
6755 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006756 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757 if (status)
6758 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006759 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006760out:
6761 return status;
6762}
6763
6764/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006765 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766 */
Chuck Leverbf269552010-12-14 14:59:29 +00006767static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006768 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006769{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006770 struct nfs4_fsinfo_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006771 struct compound_hdr hdr;
6772 int status;
6773
Chuck Leverbf269552010-12-14 14:59:29 +00006774 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006775 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006776 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006777 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006778 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006779 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006780 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006781 return status;
6782}
6783
6784/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006785 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006786 */
Chuck Leverbf269552010-12-14 14:59:29 +00006787static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006788 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006789{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006790 struct nfs4_pathconf_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006791 struct compound_hdr hdr;
6792 int status;
6793
Chuck Leverbf269552010-12-14 14:59:29 +00006794 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006795 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006796 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006797 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006798 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006799 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006800 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006801 return status;
6802}
6803
6804/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006805 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006806 */
Chuck Leverbf269552010-12-14 14:59:29 +00006807static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006808 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006809{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006810 struct nfs4_statfs_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006811 struct compound_hdr hdr;
6812 int status;
6813
Chuck Leverbf269552010-12-14 14:59:29 +00006814 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006815 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006816 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006817 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006818 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006819 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006820 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006821 return status;
6822}
6823
6824/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006825 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006826 */
Chuck Leverbf269552010-12-14 14:59:29 +00006827static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6828 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006829 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006830{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006831 struct nfs4_server_caps_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006832 struct compound_hdr hdr;
6833 int status;
6834
Chuck Leverbf269552010-12-14 14:59:29 +00006835 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006836 if (status)
6837 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006838 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006839 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006840 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006841 status = decode_putfh(xdr);
6842 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006843 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006844 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006845out:
6846 return status;
6847}
6848
6849/*
6850 * Decode RENEW response
6851 */
Chuck Leverbf269552010-12-14 14:59:29 +00006852static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6853 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006854{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006855 struct compound_hdr hdr;
6856 int status;
6857
Chuck Leverbf269552010-12-14 14:59:29 +00006858 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006859 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006860 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006861 return status;
6862}
6863
6864/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006865 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006866 */
Chuck Leverbf269552010-12-14 14:59:29 +00006867static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6868 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006869 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006870{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006871 struct nfs4_setclientid_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006872 struct compound_hdr hdr;
6873 int status;
6874
Chuck Leverbf269552010-12-14 14:59:29 +00006875 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006876 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006877 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006878 return status;
6879}
6880
6881/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006882 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006883 */
Chuck Leverbf269552010-12-14 14:59:29 +00006884static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006885 struct xdr_stream *xdr,
6886 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006887{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006888 struct compound_hdr hdr;
6889 int status;
6890
Chuck Leverbf269552010-12-14 14:59:29 +00006891 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006892 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006893 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006894 return status;
6895}
6896
6897/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006898 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006899 */
Chuck Leverbf269552010-12-14 14:59:29 +00006900static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6901 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006902 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006903{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006904 struct nfs4_delegreturnres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006905 struct compound_hdr hdr;
6906 int status;
6907
Chuck Leverbf269552010-12-14 14:59:29 +00006908 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006909 if (status)
6910 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006911 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006912 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006913 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006914 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006915 if (status != 0)
6916 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05006917 if (res->lr_res) {
6918 status = decode_layoutreturn(xdr, res->lr_res);
6919 res->lr_ret = status;
6920 if (status)
6921 goto out;
6922 }
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05006923 if (res->fattr) {
6924 status = decode_getfattr(xdr, res->fattr, res->server);
6925 if (status != 0)
6926 goto out;
6927 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006928 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006929out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006930 return status;
6931}
6932
Trond Myklebust683b57b2006-06-09 09:34:22 -04006933/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006934 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006935 */
Chuck Leverbf269552010-12-14 14:59:29 +00006936static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6937 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006938 void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006939{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006940 struct nfs4_fs_locations_res *res = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04006941 struct compound_hdr hdr;
6942 int status;
6943
Chuck Leverbf269552010-12-14 14:59:29 +00006944 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006945 if (status)
6946 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006947 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006948 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006949 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006950 status = decode_putfh(xdr);
6951 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006952 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006953 if (res->migration) {
6954 xdr_enter_page(xdr, PAGE_SIZE);
6955 status = decode_getfattr_generic(xdr,
6956 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006957 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006958 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006959 if (status)
6960 goto out;
6961 if (res->renew)
6962 status = decode_renew(xdr);
6963 } else {
6964 status = decode_lookup(xdr);
6965 if (status)
6966 goto out;
6967 xdr_enter_page(xdr, PAGE_SIZE);
6968 status = decode_getfattr_generic(xdr,
6969 &res->fs_locations->fattr,
6970 NULL, res->fs_locations,
6971 NULL, res->fs_locations->server);
6972 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006973out:
6974 return status;
6975}
6976
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006977/*
6978 * Decode SECINFO response
6979 */
6980static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6981 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006982 void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006983{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006984 struct nfs4_secinfo_res *res = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006985 struct compound_hdr hdr;
6986 int status;
6987
6988 status = decode_compound_hdr(xdr, &hdr);
6989 if (status)
6990 goto out;
6991 status = decode_sequence(xdr, &res->seq_res, rqstp);
6992 if (status)
6993 goto out;
6994 status = decode_putfh(xdr);
6995 if (status)
6996 goto out;
6997 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006998out:
6999 return status;
7000}
7001
Chuck Lever44c99932013-10-17 14:13:30 -04007002/*
7003 * Decode FSID_PRESENT response
7004 */
7005static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7006 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007007 void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04007008{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007009 struct nfs4_fsid_present_res *res = data;
Chuck Lever44c99932013-10-17 14:13:30 -04007010 struct compound_hdr hdr;
7011 int status;
7012
7013 status = decode_compound_hdr(xdr, &hdr);
7014 if (status)
7015 goto out;
7016 status = decode_sequence(xdr, &res->seq_res, rqstp);
7017 if (status)
7018 goto out;
7019 status = decode_putfh(xdr);
7020 if (status)
7021 goto out;
7022 status = decode_getfh(xdr, res->fh);
7023 if (status)
7024 goto out;
7025 if (res->renew)
7026 status = decode_renew(xdr);
7027out:
7028 return status;
7029}
7030
Benny Halevy99fe60d2009-04-01 09:22:29 -04007031#if defined(CONFIG_NFS_V4_1)
7032/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007033 * Decode BIND_CONN_TO_SESSION response
7034 */
7035static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7036 struct xdr_stream *xdr,
7037 void *res)
7038{
7039 struct compound_hdr hdr;
7040 int status;
7041
7042 status = decode_compound_hdr(xdr, &hdr);
7043 if (!status)
7044 status = decode_bind_conn_to_session(xdr, res);
7045 return status;
7046}
7047
7048/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007049 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007050 */
Chuck Leverbf269552010-12-14 14:59:29 +00007051static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7052 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007053 void *res)
7054{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007055 struct compound_hdr hdr;
7056 int status;
7057
Chuck Leverbf269552010-12-14 14:59:29 +00007058 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007059 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007060 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007061 return status;
7062}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007063
7064/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007065 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007066 */
Chuck Leverbf269552010-12-14 14:59:29 +00007067static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7068 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007069 void *res)
Andy Adamsonfc931582009-04-01 09:22:31 -04007070{
Andy Adamsonfc931582009-04-01 09:22:31 -04007071 struct compound_hdr hdr;
7072 int status;
7073
Chuck Leverbf269552010-12-14 14:59:29 +00007074 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007075 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007076 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007077 return status;
7078}
7079
7080/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007081 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007082 */
Chuck Leverbf269552010-12-14 14:59:29 +00007083static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7084 struct xdr_stream *xdr,
7085 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007086{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007087 struct compound_hdr hdr;
7088 int status;
7089
Chuck Leverbf269552010-12-14 14:59:29 +00007090 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007091 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007092 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007093 return status;
7094}
7095
7096/*
Trond Myklebust66245532012-05-25 17:18:09 -04007097 * Decode DESTROY_CLIENTID response
7098 */
7099static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7100 struct xdr_stream *xdr,
7101 void *res)
7102{
7103 struct compound_hdr hdr;
7104 int status;
7105
7106 status = decode_compound_hdr(xdr, &hdr);
7107 if (!status)
7108 status = decode_destroy_clientid(xdr, res);
7109 return status;
7110}
7111
7112/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007113 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007114 */
Chuck Leverbf269552010-12-14 14:59:29 +00007115static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7116 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007117 void *res)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007118{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007119 struct compound_hdr hdr;
7120 int status;
7121
Chuck Leverbf269552010-12-14 14:59:29 +00007122 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007123 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007124 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007125 return status;
7126}
7127
Donald Buczek0efb01b2019-07-07 21:26:08 +02007128#endif
7129
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007130/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007131 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007132 */
Chuck Leverbf269552010-12-14 14:59:29 +00007133static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7134 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007135 void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04007136{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007137 struct nfs4_get_lease_time_res *res = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04007138 struct compound_hdr hdr;
7139 int status;
7140
Chuck Leverbf269552010-12-14 14:59:29 +00007141 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007142 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007143 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007144 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007145 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007146 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007147 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007148 return status;
7149}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007150
Donald Buczek0efb01b2019-07-07 21:26:08 +02007151#ifdef CONFIG_NFS_V4_1
7152
Ricardo Labiaga180197532009-12-05 16:08:40 -05007153/*
7154 * Decode RECLAIM_COMPLETE response
7155 */
Chuck Leverbf269552010-12-14 14:59:29 +00007156static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7157 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007158 void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05007159{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007160 struct nfs41_reclaim_complete_res *res = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05007161 struct compound_hdr hdr;
7162 int status;
7163
Chuck Leverbf269552010-12-14 14:59:29 +00007164 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007165 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007166 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007167 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307168 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007169 return status;
7170}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007171
7172/*
7173 * Decode GETDEVINFO response
7174 */
Chuck Leverbf269552010-12-14 14:59:29 +00007175static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7176 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007177 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007178{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007179 struct nfs4_getdeviceinfo_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007180 struct compound_hdr hdr;
7181 int status;
7182
Chuck Leverbf269552010-12-14 14:59:29 +00007183 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007184 if (status != 0)
7185 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007186 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007187 if (status != 0)
7188 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007189 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007190out:
7191 return status;
7192}
7193
7194/*
7195 * Decode LAYOUTGET response
7196 */
Chuck Leverbf269552010-12-14 14:59:29 +00007197static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7198 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007199 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007200{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007201 struct nfs4_layoutget_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007202 struct compound_hdr hdr;
7203 int status;
7204
Chuck Leverbf269552010-12-14 14:59:29 +00007205 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007206 if (status)
7207 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007208 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007209 if (status)
7210 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007211 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007212 if (status)
7213 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007214 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007215out:
7216 return status;
7217}
Andy Adamson863a3c62011-03-23 13:27:54 +00007218
7219/*
Benny Halevycbe82602011-05-22 19:52:37 +03007220 * Decode LAYOUTRETURN response
7221 */
7222static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7223 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007224 void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03007225{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007226 struct nfs4_layoutreturn_res *res = data;
Benny Halevycbe82602011-05-22 19:52:37 +03007227 struct compound_hdr hdr;
7228 int status;
7229
7230 status = decode_compound_hdr(xdr, &hdr);
7231 if (status)
7232 goto out;
7233 status = decode_sequence(xdr, &res->seq_res, rqstp);
7234 if (status)
7235 goto out;
7236 status = decode_putfh(xdr);
7237 if (status)
7238 goto out;
7239 status = decode_layoutreturn(xdr, res);
7240out:
7241 return status;
7242}
7243
7244/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007245 * Decode LAYOUTCOMMIT response
7246 */
7247static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7248 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007249 void *data)
Andy Adamson863a3c62011-03-23 13:27:54 +00007250{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007251 struct nfs4_layoutcommit_res *res = data;
Andy Adamson863a3c62011-03-23 13:27:54 +00007252 struct compound_hdr hdr;
7253 int status;
7254
7255 status = decode_compound_hdr(xdr, &hdr);
7256 if (status)
7257 goto out;
7258 status = decode_sequence(xdr, &res->seq_res, rqstp);
7259 if (status)
7260 goto out;
7261 status = decode_putfh(xdr);
7262 if (status)
7263 goto out;
7264 status = decode_layoutcommit(xdr, rqstp, res);
7265 if (status)
7266 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05007267 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007268out:
7269 return status;
7270}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007271
7272/*
7273 * Decode SECINFO_NO_NAME response
7274 */
7275static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7276 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007277 void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007278{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007279 struct nfs4_secinfo_res *res = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007280 struct compound_hdr hdr;
7281 int status;
7282
7283 status = decode_compound_hdr(xdr, &hdr);
7284 if (status)
7285 goto out;
7286 status = decode_sequence(xdr, &res->seq_res, rqstp);
7287 if (status)
7288 goto out;
7289 status = decode_putrootfh(xdr);
7290 if (status)
7291 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007292 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007293out:
7294 return status;
7295}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007296
7297/*
7298 * Decode TEST_STATEID response
7299 */
7300static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7301 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007302 void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04007303{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007304 struct nfs41_test_stateid_res *res = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04007305 struct compound_hdr hdr;
7306 int status;
7307
7308 status = decode_compound_hdr(xdr, &hdr);
7309 if (status)
7310 goto out;
7311 status = decode_sequence(xdr, &res->seq_res, rqstp);
7312 if (status)
7313 goto out;
7314 status = decode_test_stateid(xdr, res);
7315out:
7316 return status;
7317}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007318
7319/*
7320 * Decode FREE_STATEID response
7321 */
7322static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7323 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007324 void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007325{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007326 struct nfs41_free_stateid_res *res = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007327 struct compound_hdr hdr;
7328 int status;
7329
7330 status = decode_compound_hdr(xdr, &hdr);
7331 if (status)
7332 goto out;
7333 status = decode_sequence(xdr, &res->seq_res, rqstp);
7334 if (status)
7335 goto out;
7336 status = decode_free_stateid(xdr, res);
7337out:
7338 return status;
7339}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007340#endif /* CONFIG_NFS_V4_1 */
7341
Chuck Lever573c4e12010-12-14 14:58:11 +00007342/**
7343 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7344 * the local page cache.
7345 * @xdr: XDR stream where entry resides
7346 * @entry: buffer to fill in with entry data
7347 * @plus: boolean indicating whether this should be a readdirplus entry
7348 *
7349 * Returns zero if successful, otherwise a negative errno value is
7350 * returned.
7351 *
7352 * This function is not invoked during READDIR reply decoding, but
7353 * rather whenever an application invokes the getdents(2) system call
7354 * on a directory already in our cache.
7355 */
7356int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -04007357 bool plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007358{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007359 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007360 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007361 uint32_t len;
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007362 uint64_t new_cookie;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007363 __be32 *p = xdr_inline_decode(xdr, 4);
7364 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007365 return -EAGAIN;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007366 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007367 p = xdr_inline_decode(xdr, 4);
7368 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007369 return -EAGAIN;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007370 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007371 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007372 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007373 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007374 }
7375
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007376 p = xdr_inline_decode(xdr, 12);
7377 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007378 return -EAGAIN;
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007379 p = xdr_decode_hyper(p, &new_cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007380 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007381
Trond Myklebust9af8c222010-10-24 11:52:55 -04007382 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007383 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007384 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007385 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007386
7387 /*
7388 * In case the server doesn't return an inode number,
7389 * we fake one here. (We don't use inode number 0,
7390 * since glibc seems to choke on it...)
7391 */
7392 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007393 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007394
Trond Myklebust9af8c222010-10-24 11:52:55 -04007395 if (decode_attr_bitmap(xdr, bitmap) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05007396 return -EAGAIN;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007397
Trond Myklebust256e48b2012-06-21 11:18:13 -04007398 if (decode_attr_length(xdr, &len, &savep) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05007399 return -EAGAIN;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007400
Chuck Lever573c4e12010-12-14 14:58:11 +00007401 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007402 NULL, entry->label, entry->server) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05007403 return -EAGAIN;
Trond Myklebust28331a42011-04-27 13:47:52 -04007404 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7405 entry->ino = entry->fattr->mounted_on_fileid;
7406 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007407 entry->ino = entry->fattr->fileid;
7408
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007409 entry->d_type = DT_UNKNOWN;
7410 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7411 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7412
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007413 entry->prev_cookie = entry->cookie;
7414 entry->cookie = new_cookie;
7415
Chuck Lever573c4e12010-12-14 14:58:11 +00007416 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007417}
7418
7419/*
7420 * We need to translate between nfs status return values and
7421 * the local errno values which may not be the same.
7422 */
7423static struct {
7424 int stat;
7425 int errno;
7426} nfs_errtbl[] = {
7427 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007428 { NFS4ERR_PERM, -EPERM },
7429 { NFS4ERR_NOENT, -ENOENT },
7430 { NFS4ERR_IO, -errno_NFSERR_IO},
7431 { NFS4ERR_NXIO, -ENXIO },
7432 { NFS4ERR_ACCESS, -EACCES },
7433 { NFS4ERR_EXIST, -EEXIST },
7434 { NFS4ERR_XDEV, -EXDEV },
7435 { NFS4ERR_NOTDIR, -ENOTDIR },
7436 { NFS4ERR_ISDIR, -EISDIR },
7437 { NFS4ERR_INVAL, -EINVAL },
7438 { NFS4ERR_FBIG, -EFBIG },
7439 { NFS4ERR_NOSPC, -ENOSPC },
7440 { NFS4ERR_ROFS, -EROFS },
7441 { NFS4ERR_MLINK, -EMLINK },
7442 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7443 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7444 { NFS4ERR_DQUOT, -EDQUOT },
7445 { NFS4ERR_STALE, -ESTALE },
7446 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007447 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7448 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7449 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007450 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007451 { NFS4ERR_BADTYPE, -EBADTYPE },
7452 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007453 { NFS4ERR_SYMLINK, -ELOOP },
7454 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7455 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007456 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007457};
7458
7459/*
7460 * Convert an NFS error code to a local one.
7461 * This one is used jointly by NFSv2 and NFSv3.
7462 */
7463static int
David Howells0a8ea432006-08-22 20:06:08 -04007464nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007465{
7466 int i;
7467 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7468 if (nfs_errtbl[i].stat == stat)
7469 return nfs_errtbl[i].errno;
7470 }
7471 if (stat <= 10000 || stat > 10100) {
7472 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007473 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007474 }
7475 /* If we cannot translate the error, the recovery routines should
7476 * handle it.
7477 * Note: remaining NFSv4 error codes have values > 10000, so should
7478 * not conflict with native Linux error codes.
7479 */
Benny Halevy856dff32008-03-31 17:39:06 +03007480 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007481}
7482
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007483#ifdef CONFIG_NFS_V4_2
7484#include "nfs42xdr.c"
7485#endif /* CONFIG_NFS_V4_2 */
7486
Linus Torvalds1da177e2005-04-16 15:20:36 -07007487#define PROC(proc, argtype, restype) \
7488[NFSPROC4_CLNT_##proc] = { \
7489 .p_proc = NFSPROC4_COMPOUND, \
Christoph Hellwigfcc85812017-05-08 10:01:49 +02007490 .p_encode = nfs4_xdr_##argtype, \
Christoph Hellwigfc016482017-05-08 15:09:02 +02007491 .p_decode = nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007492 .p_arglen = NFS4_##argtype##_sz, \
7493 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007494 .p_statidx = NFSPROC4_CLNT_##proc, \
7495 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007496}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007497
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007498#define STUB(proc) \
7499[NFSPROC4_CLNT_##proc] = { \
7500 .p_name = #proc, \
7501}
7502
Trond Myklebust8634ef52018-01-06 09:53:49 -05007503#if defined(CONFIG_NFS_V4_1)
7504#define PROC41(proc, argtype, restype) \
7505 PROC(proc, argtype, restype)
7506#else
7507#define PROC41(proc, argtype, restype) \
7508 STUB(proc)
7509#endif
7510
7511#if defined(CONFIG_NFS_V4_2)
7512#define PROC42(proc, argtype, restype) \
7513 PROC(proc, argtype, restype)
7514#else
7515#define PROC42(proc, argtype, restype) \
7516 STUB(proc)
7517#endif
7518
Christoph Hellwig511e9362017-05-12 15:36:49 +02007519const struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007520 PROC(READ, enc_read, dec_read),
7521 PROC(WRITE, enc_write, dec_write),
7522 PROC(COMMIT, enc_commit, dec_commit),
7523 PROC(OPEN, enc_open, dec_open),
7524 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7525 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7526 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7527 PROC(CLOSE, enc_close, dec_close),
7528 PROC(SETATTR, enc_setattr, dec_setattr),
7529 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7530 PROC(RENEW, enc_renew, dec_renew),
7531 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7532 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7533 PROC(LOCK, enc_lock, dec_lock),
7534 PROC(LOCKT, enc_lockt, dec_lockt),
7535 PROC(LOCKU, enc_locku, dec_locku),
7536 PROC(ACCESS, enc_access, dec_access),
7537 PROC(GETATTR, enc_getattr, dec_getattr),
7538 PROC(LOOKUP, enc_lookup, dec_lookup),
7539 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7540 PROC(REMOVE, enc_remove, dec_remove),
7541 PROC(RENAME, enc_rename, dec_rename),
7542 PROC(LINK, enc_link, dec_link),
7543 PROC(SYMLINK, enc_symlink, dec_symlink),
7544 PROC(CREATE, enc_create, dec_create),
7545 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7546 PROC(STATFS, enc_statfs, dec_statfs),
7547 PROC(READLINK, enc_readlink, dec_readlink),
7548 PROC(READDIR, enc_readdir, dec_readdir),
7549 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7550 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7551 PROC(GETACL, enc_getacl, dec_getacl),
7552 PROC(SETACL, enc_setacl, dec_setacl),
7553 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7554 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007555 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007556 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007557 PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7558 PROC41(CREATE_SESSION, enc_create_session, dec_create_session),
7559 PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7560 PROC41(SEQUENCE, enc_sequence, dec_sequence),
Donald Buczek0efb01b2019-07-07 21:26:08 +02007561 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007562 PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete),
7563 PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7564 PROC41(LAYOUTGET, enc_layoutget, dec_layoutget),
7565 PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7566 PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7567 PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7568 PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7569 PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007570 STUB(GETDEVICELIST),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007571 PROC41(BIND_CONN_TO_SESSION,
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007572 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007573 PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid),
7574 PROC42(SEEK, enc_seek, dec_seek),
7575 PROC42(ALLOCATE, enc_allocate, dec_allocate),
7576 PROC42(DEALLOCATE, enc_deallocate, dec_deallocate),
7577 PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
7578 PROC42(CLONE, enc_clone, dec_clone),
7579 PROC42(COPY, enc_copy, dec_copy),
Olga Kornievskaiacb95dee2018-07-09 15:13:29 -04007580 PROC42(OFFLOAD_CANCEL, enc_offload_cancel, dec_offload_cancel),
Olga Kornievskaia04915672019-06-04 16:14:30 -04007581 PROC42(COPY_NOTIFY, enc_copy_notify, dec_copy_notify),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007582 PROC(LOOKUPP, enc_lookupp, dec_lookupp),
Trond Myklebust3eb86092019-02-08 10:31:05 -05007583 PROC42(LAYOUTERROR, enc_layouterror, dec_layouterror),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007584};
7585
Christoph Hellwigc5518582017-05-08 23:27:10 +02007586static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
Trond Myklebusta613fa12012-01-20 13:53:56 -05007587const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007588 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007589 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Christoph Hellwigc5518582017-05-08 23:27:10 +02007590 .procs = nfs4_procedures,
7591 .counts = nfs_version4_counts,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007592};
7593
7594/*
7595 * Local variables:
7596 * c-basic-offset: 8
7597 * End:
7598 */