blob: 47817ef0aadb1558d5c92b48d4e2ee7479f5abd9 [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 Myklebust4f9838c2005-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 Myklebust4f9838c2005-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 Myklebust778d2812012-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 Myklebust778d2812012-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 Myklebust778d2812012-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 Myklebust778d2812012-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{
Arnd Bergmanna3167da2019-11-11 21:16:27 +01001064 p = xdr_encode_hyper(p, t->tv_sec);
Trond Myklebust36b37432018-03-20 17:03:10 -04001065 *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 Myklebust79969dd2015-02-18 11:30:18 -08001849 p = xdr_encode_hyper(p, args->clientid);
1850 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001851 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001852
Andy Adamsonfc931582009-04-01 09:22:31 -04001853 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001854 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001855 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1856 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001857 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001858 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1859 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1860 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001861
1862 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001863 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001864 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1865 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1866 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1867 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1868 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1869 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001870
Benny Halevye75bc1c2009-08-14 17:18:54 +03001871 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001872 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001873 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001874
1875 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001876 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001877 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001878 *p++ = cpu_to_be32(0); /* UID */
1879 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001880 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001881}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001882
1883static void encode_destroy_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001884 const struct nfs4_session *session,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001885 struct compound_hdr *hdr)
1886{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001887 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1888 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001889}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001890
Trond Myklebust66245532012-05-25 17:18:09 -04001891static void encode_destroy_clientid(struct xdr_stream *xdr,
1892 uint64_t clientid,
1893 struct compound_hdr *hdr)
1894{
1895 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1896 encode_uint64(xdr, clientid);
1897}
1898
Ricardo Labiaga180197532009-12-05 16:08:40 -05001899static void encode_reclaim_complete(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001900 const struct nfs41_reclaim_complete_args *args,
Ricardo Labiaga180197532009-12-05 16:08:40 -05001901 struct compound_hdr *hdr)
1902{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001903 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1904 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001905}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001906#endif /* CONFIG_NFS_V4_1 */
1907
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001908static void encode_sequence(struct xdr_stream *xdr,
1909 const struct nfs4_sequence_args *args,
1910 struct compound_hdr *hdr)
1911{
1912#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001913 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001914 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001915 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001916 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001917
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001918 tp = slot->table;
1919 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001920 if (!session)
1921 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001922
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001923 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001924
1925 /*
1926 * Sessionid + seqid + slotid + max slotid + cache_this
1927 */
1928 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1929 "max_slotid=%d cache_this=%d\n",
1930 __func__,
1931 ((u32 *)session->sess_id.data)[0],
1932 ((u32 *)session->sess_id.data)[1],
1933 ((u32 *)session->sess_id.data)[2],
1934 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001935 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001936 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001937 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001938 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001939 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001940 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001941 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001942 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001943#endif /* CONFIG_NFS_V4_1 */
1944}
1945
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001946#ifdef CONFIG_NFS_V4_1
1947static void
1948encode_getdeviceinfo(struct xdr_stream *xdr,
1949 const struct nfs4_getdeviceinfo_args *args,
1950 struct compound_hdr *hdr)
1951{
1952 __be32 *p;
1953
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001954 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001955 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001956 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1957 NFS4_DEVICEID4_SIZE);
1958 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001959 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001960
1961 p = reserve_space(xdr, 4 + 4);
1962 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001963 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001964}
1965
1966static void
1967encode_layoutget(struct xdr_stream *xdr,
1968 const struct nfs4_layoutget_args *args,
1969 struct compound_hdr *hdr)
1970{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001971 __be32 *p;
1972
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001973 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1974 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001975 *p++ = cpu_to_be32(0); /* Signal layout available */
1976 *p++ = cpu_to_be32(args->type);
1977 *p++ = cpu_to_be32(args->range.iomode);
1978 p = xdr_encode_hyper(p, args->range.offset);
1979 p = xdr_encode_hyper(p, args->range.length);
1980 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001981 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001982 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001983
1984 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1985 __func__,
1986 args->type,
1987 args->range.iomode,
1988 (unsigned long)args->range.offset,
1989 (unsigned long)args->range.length,
1990 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001991}
Andy Adamson863a3c62011-03-23 13:27:54 +00001992
1993static int
1994encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001995 struct inode *inode,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001996 const struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001997 struct compound_hdr *hdr)
1998{
1999 __be32 *p;
2000
2001 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2002 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2003
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002004 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2005 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00002006 /* Only whole file layouts */
2007 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002008 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002009 *p = cpu_to_be32(0); /* reclaim */
2010 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04002011 if (args->lastbytewritten != U64_MAX) {
2012 p = reserve_space(xdr, 20);
2013 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2014 p = xdr_encode_hyper(p, args->lastbytewritten);
2015 } else {
2016 p = reserve_space(xdr, 12);
2017 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2018 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002019 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2020 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002021
Trond Myklebust73504742017-04-20 16:48:14 -04002022 encode_uint32(xdr, args->layoutupdate_len);
2023 if (args->layoutupdate_pages)
2024 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2025 args->layoutupdate_len);
Andy Adamson863a3c62011-03-23 13:27:54 +00002026
Andy Adamson863a3c62011-03-23 13:27:54 +00002027 return 0;
2028}
Benny Halevycbe82602011-05-22 19:52:37 +03002029
2030static void
2031encode_layoutreturn(struct xdr_stream *xdr,
2032 const struct nfs4_layoutreturn_args *args,
2033 struct compound_hdr *hdr)
2034{
2035 __be32 *p;
2036
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002037 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2038 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002039 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2040 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002041 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002042 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002043 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002044 p = xdr_encode_hyper(p, args->range.offset);
2045 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002046 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002047 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002048 spin_unlock(&args->inode->i_lock);
Trond Myklebust4d796d72016-09-23 11:38:08 -04002049 if (args->ld_private->ops && args->ld_private->ops->encode)
2050 args->ld_private->ops->encode(xdr, args, args->ld_private);
Trond Myklebust94e5c572016-09-15 18:49:52 -04002051 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002052 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002053}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002054
2055static int
2056encode_secinfo_no_name(struct xdr_stream *xdr,
2057 const struct nfs41_secinfo_no_name_args *args,
2058 struct compound_hdr *hdr)
2059{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002060 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2061 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002062 return 0;
2063}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002064
2065static void encode_test_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002066 const struct nfs41_test_stateid_args *args,
Bryan Schumaker7d974792011-06-02 14:59:08 -04002067 struct compound_hdr *hdr)
2068{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002069 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2070 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002071 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002072}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002073
2074static void encode_free_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002075 const struct nfs41_free_stateid_args *args,
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002076 struct compound_hdr *hdr)
2077{
Trond Myklebustab19b482012-03-04 18:13:57 -05002078 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002079 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002080}
Trond Myklebustcf805162016-11-15 14:56:07 -05002081#else
2082static inline void
2083encode_layoutreturn(struct xdr_stream *xdr,
2084 const struct nfs4_layoutreturn_args *args,
2085 struct compound_hdr *hdr)
2086{
2087}
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 }
Arnd Bergmannae084832019-11-11 21:16:23 +01004100 dprintk("%s: atime=%lld\n", __func__, 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 }
Arnd Bergmannae084832019-11-11 21:16:23 +01004118 dprintk("%s: ctime=%lld\n", __func__, 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 }
Arnd Bergmannae084832019-11-11 21:16:23 +01004135 dprintk("%s: time_delta=%lld %ld\n", __func__, time->tv_sec,
4136 time->tv_nsec);
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004137 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 }
Arnd Bergmannae084832019-11-11 21:16:23 +01004200 dprintk("%s: mtime=%lld\n", __func__, 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{
Trond Myklebust221203c2020-01-06 15:25:04 -05004316 struct nfs_writeverf *verf = res->verf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317 int status;
4318
4319 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004320 if (!status)
Trond Myklebust221203c2020-01-06 15:25:04 -05004321 status = decode_write_verifier(xdr, &verf->verifier);
4322 if (!status)
4323 verf->committed = NFS_FILE_SYNC;
Benny Halevydb942bb2009-08-14 17:19:56 +03004324 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325}
4326
4327static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4328{
Al Viro8687b632006-10-19 23:28:48 -07004329 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330 uint32_t bmlen;
4331 int status;
4332
4333 status = decode_op_hdr(xdr, OP_CREATE);
4334 if (status)
4335 return status;
4336 if ((status = decode_change_info(xdr, cinfo)))
4337 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004338 p = xdr_inline_decode(xdr, 4);
4339 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004340 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004341 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004342 p = xdr_inline_decode(xdr, bmlen << 2);
4343 if (likely(p))
4344 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004345 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346}
4347
4348static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4349{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004350 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004351 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 int status;
4353
4354 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4355 goto xdr_error;
4356 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4357 goto xdr_error;
4358 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4359 goto xdr_error;
4360 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4361 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004362 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4363 &res->fh_expire_type)) != 0)
4364 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4366 goto xdr_error;
4367 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4368 goto xdr_error;
4369 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4370 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004371 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4372 res->exclcreat_bitmask)) != 0)
4373 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374 status = verify_attr_len(xdr, savep, attrlen);
4375xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004376 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377 return status;
4378}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004379
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4381{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004382 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004383 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004385
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4387 goto xdr_error;
4388 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4389 goto xdr_error;
4390 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4391 goto xdr_error;
4392
4393 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4394 goto xdr_error;
4395 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4396 goto xdr_error;
4397 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4398 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004399
4400 status = -EIO;
4401 if (unlikely(bitmap[0]))
4402 goto xdr_error;
4403
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4405 goto xdr_error;
4406 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4407 goto xdr_error;
4408 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4409 goto xdr_error;
4410
4411 status = verify_attr_len(xdr, savep, attrlen);
4412xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004413 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414 return status;
4415}
4416
4417static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4418{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004419 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004420 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004422
Linus Torvalds1da177e2005-04-16 15:20:36 -07004423 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4424 goto xdr_error;
4425 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4426 goto xdr_error;
4427 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4428 goto xdr_error;
4429
4430 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4431 goto xdr_error;
4432 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4433 goto xdr_error;
4434
4435 status = verify_attr_len(xdr, savep, attrlen);
4436xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004437 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 return status;
4439}
4440
Andy Adamson88034c32012-05-23 05:02:34 -04004441static int decode_threshold_hint(struct xdr_stream *xdr,
4442 uint32_t *bitmap,
4443 uint64_t *res,
4444 uint32_t hint_bit)
4445{
4446 __be32 *p;
4447
4448 *res = 0;
4449 if (likely(bitmap[0] & hint_bit)) {
4450 p = xdr_inline_decode(xdr, 8);
4451 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004452 return -EIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004453 xdr_decode_hyper(p, res);
4454 }
4455 return 0;
Andy Adamson88034c32012-05-23 05:02:34 -04004456}
4457
4458static int decode_first_threshold_item4(struct xdr_stream *xdr,
4459 struct nfs4_threshold *res)
4460{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004461 __be32 *p;
4462 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004463 uint32_t bitmap[3] = {0,}, attrlen;
4464 int status;
4465
4466 /* layout type */
4467 p = xdr_inline_decode(xdr, 4);
Chuck Levereb72f482019-02-11 11:24:21 -05004468 if (unlikely(!p))
Andy Adamson88034c32012-05-23 05:02:34 -04004469 return -EIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004470 res->l_type = be32_to_cpup(p);
4471
4472 /* thi_hintset bitmap */
4473 status = decode_attr_bitmap(xdr, bitmap);
4474 if (status < 0)
4475 goto xdr_error;
4476
4477 /* thi_hintlist length */
4478 status = decode_attr_length(xdr, &attrlen, &savep);
4479 if (status < 0)
4480 goto xdr_error;
4481 /* thi_hintlist */
4482 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4483 if (status < 0)
4484 goto xdr_error;
4485 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4486 if (status < 0)
4487 goto xdr_error;
4488 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4489 THRESHOLD_RD_IO);
4490 if (status < 0)
4491 goto xdr_error;
4492 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4493 THRESHOLD_WR_IO);
4494 if (status < 0)
4495 goto xdr_error;
4496
4497 status = verify_attr_len(xdr, savep, attrlen);
4498 res->bm = bitmap[0];
4499
4500 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4501 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4502 res->wr_io_sz);
4503xdr_error:
4504 dprintk("%s ret=%d!\n", __func__, status);
4505 return status;
4506}
4507
4508/*
4509 * Thresholds on pNFS direct I/O vrs MDS I/O
4510 */
4511static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4512 uint32_t *bitmap,
4513 struct nfs4_threshold *res)
4514{
4515 __be32 *p;
4516 int status = 0;
4517 uint32_t num;
4518
4519 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4520 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004521 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004522 /* Did the server return an unrequested attribute? */
4523 if (unlikely(res == NULL))
4524 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004525 p = xdr_inline_decode(xdr, 4);
4526 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004527 return -EIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004528 num = be32_to_cpup(p);
4529 if (num == 0)
4530 return 0;
4531 if (num > 1)
4532 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4533 "drivers per filesystem not supported\n",
4534 __func__);
4535
4536 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004537 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004538 }
4539 return status;
Andy Adamson88034c32012-05-23 05:02:34 -04004540}
4541
Bryan Schumakerae42c702010-10-21 16:33:17 -04004542static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4543 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004544 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004545 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004546{
Trond Myklebustbca79472009-03-11 14:10:26 -04004547 int status;
4548 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004549 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004550 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004552 status = decode_attr_type(xdr, bitmap, &type);
4553 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004554 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004555 fattr->mode = 0;
4556 if (status != 0) {
4557 fattr->mode |= nfs_type2fmt[type];
4558 fattr->valid |= status;
4559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004561 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4562 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004564 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004565
4566 status = decode_attr_size(xdr, bitmap, &fattr->size);
4567 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004569 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004570
4571 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4572 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004574 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004575
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004576 err = 0;
4577 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004578 if (status < 0)
4579 goto xdr_error;
4580
4581 status = decode_attr_filehandle(xdr, bitmap, fh);
4582 if (status < 0)
4583 goto xdr_error;
4584
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004585 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4586 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004588 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004589
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004590 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004591 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004592 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004593 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004594
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004595 status = -EIO;
4596 if (unlikely(bitmap[0]))
4597 goto xdr_error;
4598
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004599 status = decode_attr_mode(xdr, bitmap, &fmode);
4600 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004602 if (status != 0) {
4603 fattr->mode |= fmode;
4604 fattr->valid |= status;
4605 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004606
4607 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4608 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004609 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004610 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004611
Trond Myklebust6926afd12012-01-07 13:22:46 -05004612 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004613 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004614 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004615 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004616
Trond Myklebust6926afd12012-01-07 13:22:46 -05004617 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004618 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004620 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004621
4622 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4623 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004625 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004626
4627 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4628 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004630 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004631
4632 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4633 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004635 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004636
4637 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4638 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004640 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004641
4642 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4643 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004645 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004646
Trond Myklebust28331a42011-04-27 13:47:52 -04004647 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004648 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004649 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004650 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004651
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004652 status = -EIO;
4653 if (unlikely(bitmap[1]))
4654 goto xdr_error;
4655
Andy Adamson88034c32012-05-23 05:02:34 -04004656 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4657 if (status < 0)
4658 goto xdr_error;
4659
David Quigleyaa9c2662013-05-22 12:50:44 -04004660 if (label) {
4661 status = decode_attr_security_label(xdr, bitmap, label);
4662 if (status < 0)
4663 goto xdr_error;
4664 fattr->valid |= status;
4665 }
4666
Bryan Schumakerae42c702010-10-21 16:33:17 -04004667xdr_error:
4668 dprintk("%s: xdr returned %d\n", __func__, -status);
4669 return status;
4670}
4671
4672static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004673 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004674 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004675{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004676 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004677 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004678 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004679 int status;
4680
4681 status = decode_op_hdr(xdr, OP_GETATTR);
4682 if (status < 0)
4683 goto xdr_error;
4684
4685 status = decode_attr_bitmap(xdr, bitmap);
4686 if (status < 0)
4687 goto xdr_error;
4688
4689 status = decode_attr_length(xdr, &attrlen, &savep);
4690 if (status < 0)
4691 goto xdr_error;
4692
David Quigleyaa9c2662013-05-22 12:50:44 -04004693 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4694 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004695 if (status < 0)
4696 goto xdr_error;
4697
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004698 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004699xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004700 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004701 return status;
4702}
4703
David Quigleyaa9c2662013-05-22 12:50:44 -04004704static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4705 struct nfs4_label *label, const struct nfs_server *server)
4706{
4707 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4708}
4709
Bryan Schumakerae42c702010-10-21 16:33:17 -04004710static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004711 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004712{
David Quigleyaa9c2662013-05-22 12:50:44 -04004713 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004714}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715
Andy Adamson504913f2010-10-20 00:17:57 -04004716/*
Jeff Layton3132e492016-08-10 15:58:24 -04004717 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004718 */
Jeff Layton3132e492016-08-10 15:58:24 -04004719static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004720 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004721{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004722 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004723 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004724
4725 p = xdr_inline_decode(xdr, 4);
4726 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004727 return -EIO;
Jeff Laytonca440c32016-09-15 14:40:49 -04004728 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004729
4730 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004731 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004732 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004733
4734 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004735 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004736 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004737 return -EIO;
Jeff Laytonca440c32016-09-15 14:40:49 -04004738
4739 /* If we get too many, then just cap it at the max */
4740 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4741 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4742 __func__, fsinfo->nlayouttypes);
4743 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4744 }
4745
4746 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4747 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004748 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004749}
4750
4751/*
4752 * The type of file system exported.
4753 * Note we must ensure that layouttype is set in any non-error case.
4754 */
4755static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004756 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004757{
4758 int status = 0;
4759
4760 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4761 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4762 return -EIO;
4763 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004764 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004765 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004766 }
Andy Adamson504913f2010-10-20 00:17:57 -04004767 return status;
4768}
4769
Fred Isamandae100c2011-07-30 20:52:37 -04004770/*
4771 * The prefered block size for layout directed io
4772 */
4773static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4774 uint32_t *res)
4775{
4776 __be32 *p;
4777
4778 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4779 *res = 0;
4780 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4781 p = xdr_inline_decode(xdr, 4);
Chuck Levereb72f482019-02-11 11:24:21 -05004782 if (unlikely(!p))
Fred Isamandae100c2011-07-30 20:52:37 -04004783 return -EIO;
Fred Isamandae100c2011-07-30 20:52:37 -04004784 *res = be32_to_cpup(p);
4785 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4786 }
4787 return 0;
4788}
4789
Peng Tao2a92ee92015-09-26 02:24:37 +08004790/*
4791 * The granularity of a CLONE operation.
4792 */
4793static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4794 uint32_t *res)
4795{
4796 __be32 *p;
4797
4798 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4799 *res = 0;
4800 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4801 p = xdr_inline_decode(xdr, 4);
Chuck Levereb72f482019-02-11 11:24:21 -05004802 if (unlikely(!p))
Peng Tao2a92ee92015-09-26 02:24:37 +08004803 return -EIO;
Peng Tao2a92ee92015-09-26 02:24:37 +08004804 *res = be32_to_cpup(p);
4805 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4806 }
4807 return 0;
4808}
4809
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4811{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004812 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004813 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814 int status;
4815
4816 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4817 goto xdr_error;
4818 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4819 goto xdr_error;
4820 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4821 goto xdr_error;
4822
4823 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4824
4825 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4826 goto xdr_error;
4827 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4828 goto xdr_error;
4829 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4830 goto xdr_error;
4831 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4832 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4833 goto xdr_error;
4834 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004835
4836 status = -EIO;
4837 if (unlikely(bitmap[0]))
4838 goto xdr_error;
4839
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004840 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4841 if (status != 0)
4842 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004843 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004844 if (status != 0)
4845 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004846
4847 status = -EIO;
4848 if (unlikely(bitmap[1]))
4849 goto xdr_error;
4850
Fred Isamandae100c2011-07-30 20:52:37 -04004851 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4852 if (status)
4853 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004854 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4855 if (status)
4856 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857
4858 status = verify_attr_len(xdr, savep, attrlen);
4859xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004860 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861 return status;
4862}
4863
4864static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4865{
Al Viro8687b632006-10-19 23:28:48 -07004866 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867 uint32_t len;
4868 int status;
4869
Trond Myklebust99367812007-07-17 21:52:41 -04004870 /* Zero handle first to allow comparisons */
4871 memset(fh, 0, sizeof(*fh));
4872
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873 status = decode_op_hdr(xdr, OP_GETFH);
4874 if (status)
4875 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876
Benny Halevyc0eae662009-08-14 17:20:14 +03004877 p = xdr_inline_decode(xdr, 4);
4878 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004879 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004880 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 if (len > NFS4_FHSIZE)
4882 return -EIO;
4883 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004884 p = xdr_inline_decode(xdr, len);
4885 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004886 return -EIO;
Benny Halevy99398d02009-08-14 17:20:05 +03004887 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004888 return 0;
4889}
4890
4891static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4892{
4893 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004894
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895 status = decode_op_hdr(xdr, OP_LINK);
4896 if (status)
4897 return status;
4898 return decode_change_info(xdr, cinfo);
4899}
4900
4901/*
4902 * We create the owner, so we know a proper owner.id length is 4.
4903 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004904static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004906 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004907 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004908 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004909
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004910 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004911 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004912 return -EIO;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004913 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004914 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004915 type = be32_to_cpup(p++); /* 4 byte read */
4916 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004917 fl->fl_start = (loff_t)offset;
4918 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4919 if (length == ~(uint64_t)0)
4920 fl->fl_end = OFFSET_MAX;
4921 fl->fl_type = F_WRLCK;
4922 if (type & 1)
4923 fl->fl_type = F_RDLCK;
4924 fl->fl_pid = 0;
4925 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004926 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4927 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4928 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Chuck Levereb72f482019-02-11 11:24:21 -05004929 if (likely(!p))
4930 return -EIO;
4931 return -NFS4ERR_DENIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004932}
4933
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004934static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936 int status;
4937
4938 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004939 if (status == -EIO)
4940 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004941 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04004942 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004943 if (unlikely(status))
4944 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004946 status = decode_lock_denied(xdr, NULL);
4947 if (res->open_seqid != NULL)
4948 nfs_increment_open_seqid(status, res->open_seqid);
4949 nfs_increment_lock_seqid(status, res->lock_seqid);
4950out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951 return status;
4952}
4953
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004954static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004955{
4956 int status;
4957 status = decode_op_hdr(xdr, OP_LOCKT);
4958 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004959 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960 return status;
4961}
4962
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004963static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965 int status;
4966
4967 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004968 if (status != -EIO)
4969 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004970 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04004971 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972 return status;
4973}
4974
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004975static int decode_release_lockowner(struct xdr_stream *xdr)
4976{
4977 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4978}
4979
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980static int decode_lookup(struct xdr_stream *xdr)
4981{
4982 return decode_op_hdr(xdr, OP_LOOKUP);
4983}
4984
Jeff Layton5b5faaf2017-06-29 06:34:52 -07004985static int decode_lookupp(struct xdr_stream *xdr)
4986{
4987 return decode_op_hdr(xdr, OP_LOOKUPP);
4988}
4989
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04004991static int decode_space_limit(struct xdr_stream *xdr,
4992 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993{
Andy Adamson05d564f2008-12-23 16:06:15 -05004994 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04004996 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004997
Benny Halevyc0eae662009-08-14 17:20:14 +03004998 p = xdr_inline_decode(xdr, 12);
4999 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005000 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005001 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005002 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005003 case NFS4_LIMIT_SIZE:
5004 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005005 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005006 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005007 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005008 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005009 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005011 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005012 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013 return 0;
5014}
5015
Trond Myklebust6ae37332015-01-30 14:21:14 -05005016static int decode_rw_delegation(struct xdr_stream *xdr,
5017 uint32_t delegation_type,
5018 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019{
Andy Adamson05d564f2008-12-23 16:06:15 -05005020 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005021 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005022
Trond Myklebust93b717f2016-05-16 17:42:43 -04005023 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005024 if (unlikely(status))
5025 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005026 p = xdr_inline_decode(xdr, 4);
5027 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005028 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005029 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005030
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005032 case NFS4_OPEN_DELEGATE_READ:
5033 res->delegation_type = FMODE_READ;
5034 break;
5035 case NFS4_OPEN_DELEGATE_WRITE:
5036 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005037 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038 return -EIO;
5039 }
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05005040 return decode_ace(xdr, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041}
5042
Trond Myklebust6ae37332015-01-30 14:21:14 -05005043static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5044{
5045 __be32 *p;
5046 uint32_t why_no_delegation;
5047
5048 p = xdr_inline_decode(xdr, 4);
5049 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005050 return -EIO;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005051 why_no_delegation = be32_to_cpup(p);
5052 switch (why_no_delegation) {
5053 case WND4_CONTENTION:
5054 case WND4_RESOURCE:
5055 xdr_inline_decode(xdr, 4);
5056 /* Ignore for now */
5057 }
5058 return 0;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005059}
5060
5061static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5062{
5063 __be32 *p;
5064 uint32_t delegation_type;
5065
5066 p = xdr_inline_decode(xdr, 4);
5067 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005068 return -EIO;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005069 delegation_type = be32_to_cpup(p);
5070 res->delegation_type = 0;
5071 switch (delegation_type) {
5072 case NFS4_OPEN_DELEGATE_NONE:
5073 return 0;
5074 case NFS4_OPEN_DELEGATE_READ:
5075 case NFS4_OPEN_DELEGATE_WRITE:
5076 return decode_rw_delegation(xdr, delegation_type, res);
5077 case NFS4_OPEN_DELEGATE_NONE_EXT:
5078 return decode_no_delegation(xdr, res);
5079 }
5080 return -EIO;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005081}
5082
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5084{
Andy Adamson05d564f2008-12-23 16:06:15 -05005085 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005086 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005087 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088
Trond Myklebustc7848f62013-12-04 17:39:23 -05005089 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5090 return status;
5091 nfs_increment_open_seqid(status, res->seqid);
5092 if (status)
5093 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005094 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005095 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005096 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005097
Andy Adamson05d564f2008-12-23 16:06:15 -05005098 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005099
Benny Halevyc0eae662009-08-14 17:20:14 +03005100 p = xdr_inline_decode(xdr, 8);
5101 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005102 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005103 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005104 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005105 if (bmlen > 10)
5106 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107
Benny Halevyc0eae662009-08-14 17:20:14 +03005108 p = xdr_inline_decode(xdr, bmlen << 2);
5109 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005110 return -EIO;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005111 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5112 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005113 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005114 for (; i < NFS4_BITMAP_SIZE; i++)
5115 res->attrset[i] = 0;
5116
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117 return decode_delegation(xdr, res);
5118xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005119 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120 return -EIO;
5121}
5122
5123static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5124{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005125 int status;
5126
Andy Adamson05d564f2008-12-23 16:06:15 -05005127 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005128 if (status != -EIO)
5129 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005130 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005131 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005132 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133}
5134
5135static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5136{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005137 int status;
5138
5139 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005140 if (status != -EIO)
5141 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005142 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005143 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005144 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005145}
5146
5147static int decode_putfh(struct xdr_stream *xdr)
5148{
5149 return decode_op_hdr(xdr, OP_PUTFH);
5150}
5151
5152static int decode_putrootfh(struct xdr_stream *xdr)
5153{
5154 return decode_op_hdr(xdr, OP_PUTROOTFH);
5155}
5156
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005157static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5158 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005159{
Al Viro8687b632006-10-19 23:28:48 -07005160 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005161 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162 int status;
5163
5164 status = decode_op_hdr(xdr, OP_READ);
5165 if (status)
5166 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005167 p = xdr_inline_decode(xdr, 8);
5168 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005169 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005170 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005171 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005172 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005174 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175 "count %u > recvd %u\n", count, recvd);
5176 count = recvd;
5177 eof = 0;
5178 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005179 res->eof = eof;
5180 res->count = count;
5181 return 0;
5182}
5183
5184static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5185{
Chuck Leverbcecff72007-10-26 13:32:03 -04005186 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005187 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005188
5189 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005190 if (!status)
5191 status = decode_verifier(xdr, readdir->verifier.data);
5192 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005193 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005194 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005195 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005196 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005197 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005198}
5199
5200static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5201{
5202 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005203 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005204 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205 int status;
5206
5207 status = decode_op_hdr(xdr, OP_READLINK);
5208 if (status)
5209 return status;
5210
5211 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005212 p = xdr_inline_decode(xdr, 4);
5213 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005214 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005215 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005216 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005217 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218 return -ENAMETOOLONG;
5219 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005220 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005221 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005222 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223 "count %u > recvd %u\n", len, recvd);
5224 return -EIO;
5225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005226 /*
5227 * The XDR encode routine has set things up so that
5228 * the link text will be copied directly into the
5229 * buffer. We just have to do overflow-checking,
5230 * and and null-terminate the text (the VFS expects
5231 * null-termination).
5232 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005233 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234 return 0;
5235}
5236
5237static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5238{
5239 int status;
5240
5241 status = decode_op_hdr(xdr, OP_REMOVE);
5242 if (status)
5243 goto out;
5244 status = decode_change_info(xdr, cinfo);
5245out:
5246 return status;
5247}
5248
5249static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5250 struct nfs4_change_info *new_cinfo)
5251{
5252 int status;
5253
5254 status = decode_op_hdr(xdr, OP_RENAME);
5255 if (status)
5256 goto out;
5257 if ((status = decode_change_info(xdr, old_cinfo)))
5258 goto out;
5259 status = decode_change_info(xdr, new_cinfo);
5260out:
5261 return status;
5262}
5263
5264static int decode_renew(struct xdr_stream *xdr)
5265{
5266 return decode_op_hdr(xdr, OP_RENEW);
5267}
5268
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005269static int
5270decode_restorefh(struct xdr_stream *xdr)
5271{
5272 return decode_op_hdr(xdr, OP_RESTOREFH);
5273}
5274
J. Bruce Fields029d1052005-06-22 17:16:22 +00005275static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005276 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005277{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005278 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005279 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005280 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005281 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005282 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005283
Andy Adamsonbf118a32011-12-07 11:55:27 -05005284 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005285 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5286 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005287
Trond Myklebust519d3952012-08-14 17:30:10 -04005288 xdr_enter_page(xdr, xdr->buf->page_len);
5289
Trond Myklebustcff298c2012-08-14 17:14:17 -04005290 /* Calculate the offset of the page data */
5291 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005292
J. Bruce Fields029d1052005-06-22 17:16:22 +00005293 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5294 goto out;
5295 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5296 goto out;
5297
5298 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5299 return -EIO;
5300 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005301
Andy Adamsonbf118a32011-12-07 11:55:27 -05005302 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5303 * are stored with the acl data to handle the problem of
5304 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005305 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005306 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005307
5308 /* Check for receive buffer overflow */
5309 if (res->acl_len > (xdr->nwords << 2) ||
5310 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5311 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005312 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005313 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005314 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005315 } else
5316 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005317
5318out:
5319 return status;
5320}
5321
Linus Torvalds1da177e2005-04-16 15:20:36 -07005322static int
5323decode_savefh(struct xdr_stream *xdr)
5324{
5325 return decode_op_hdr(xdr, OP_SAVEFH);
5326}
5327
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005328static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005329{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005330 int status;
5331
Linus Torvalds1da177e2005-04-16 15:20:36 -07005332 status = decode_op_hdr(xdr, OP_SETATTR);
5333 if (status)
5334 return status;
Trond Myklebust37c88762018-03-20 17:03:08 -04005335 if (decode_bitmap4(xdr, NULL, 0) >= 0)
Benny Halevyc0eae662009-08-14 17:20:14 +03005336 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005337 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005338}
5339
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005340static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005341{
Al Viro8687b632006-10-19 23:28:48 -07005342 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005343 uint32_t opnum;
5344 int32_t nfserr;
5345
Benny Halevyc0eae662009-08-14 17:20:14 +03005346 p = xdr_inline_decode(xdr, 8);
5347 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005348 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005349 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005350 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005351 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005352 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005353 return -EIO;
5354 }
Benny Halevycccddf42009-08-14 17:20:19 +03005355 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005356 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005357 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5358 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005359 return -EIO;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005360 p = xdr_decode_hyper(p, &res->clientid);
5361 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005362 } else if (nfserr == NFSERR_CLID_INUSE) {
5363 uint32_t len;
5364
5365 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005366 p = xdr_inline_decode(xdr, 4);
5367 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005368 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005369 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005370 p = xdr_inline_decode(xdr, len);
5371 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005372 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005373
5374 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005375 p = xdr_inline_decode(xdr, 4);
5376 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005377 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005378 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005379 p = xdr_inline_decode(xdr, len);
5380 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005381 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005382 return -NFSERR_CLID_INUSE;
5383 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005384 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005385
5386 return 0;
5387}
5388
5389static int decode_setclientid_confirm(struct xdr_stream *xdr)
5390{
5391 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5392}
5393
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005394static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005395{
Al Viro8687b632006-10-19 23:28:48 -07005396 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005397 int status;
5398
5399 status = decode_op_hdr(xdr, OP_WRITE);
5400 if (status)
5401 return status;
5402
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005403 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005404 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005405 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005406 res->count = be32_to_cpup(p++);
5407 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005408 return decode_write_verifier(xdr, &res->verf->verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005409}
5410
5411static int decode_delegreturn(struct xdr_stream *xdr)
5412{
5413 return decode_op_hdr(xdr, OP_DELEGRETURN);
5414}
5415
Chuck Leverfb15b262013-03-16 15:54:34 -04005416static int decode_secinfo_gss(struct xdr_stream *xdr,
5417 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005418{
Chuck Leverfb15b262013-03-16 15:54:34 -04005419 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005420 __be32 *p;
5421
5422 p = xdr_inline_decode(xdr, 4);
5423 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005424 return -EIO;
Chuck Leverfb15b262013-03-16 15:54:34 -04005425 oid_len = be32_to_cpup(p);
5426 if (oid_len > GSS_OID_MAX_LEN)
Chuck Levereb72f482019-02-11 11:24:21 -05005427 return -EINVAL;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005428
Chuck Leverfb15b262013-03-16 15:54:34 -04005429 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005430 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005431 return -EIO;
Chuck Leverfb15b262013-03-16 15:54:34 -04005432 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5433 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005434
5435 p = xdr_inline_decode(xdr, 8);
5436 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005437 return -EIO;
Chuck Leverfb15b262013-03-16 15:54:34 -04005438 flavor->flavor_info.qop = be32_to_cpup(p++);
5439 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005440
5441 return 0;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005442}
5443
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005444static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005445{
Chuck Leverfb15b262013-03-16 15:54:34 -04005446 struct nfs4_secinfo4 *sec_flavor;
5447 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005448 int status;
5449 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005450
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005451 p = xdr_inline_decode(xdr, 4);
5452 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005453 return -EIO;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005454
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005455 res->flavors->num_flavors = 0;
5456 num_flavors = be32_to_cpup(p);
5457
5458 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005459 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005460 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005461 break;
5462
5463 p = xdr_inline_decode(xdr, 4);
5464 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005465 return -EIO;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005466 sec_flavor->flavor = be32_to_cpup(p);
5467
5468 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005469 status = decode_secinfo_gss(xdr, sec_flavor);
5470 if (status)
5471 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005472 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005473 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005474 }
5475
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005476 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005477out:
5478 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005479}
5480
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005481static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5482{
5483 int status = decode_op_hdr(xdr, OP_SECINFO);
5484 if (status)
5485 return status;
5486 return decode_secinfo_common(xdr, res);
5487}
5488
Benny Halevy99fe60d2009-04-01 09:22:29 -04005489#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005490static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5491{
5492 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5493 if (status)
5494 return status;
5495 return decode_secinfo_common(xdr, res);
5496}
5497
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005498static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5499{
5500 __be32 *p;
5501 uint32_t bitmap_words;
5502 unsigned int i;
5503
5504 p = xdr_inline_decode(xdr, 4);
Pan Bian4edabfd2017-04-23 14:49:41 +08005505 if (!p)
5506 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005507 bitmap_words = be32_to_cpup(p++);
5508 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5509 return -EIO;
5510 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5511 for (i = 0; i < bitmap_words; i++)
5512 op_map->u.words[i] = be32_to_cpup(p++);
5513
5514 return 0;
5515}
5516
Benny Halevy99fe60d2009-04-01 09:22:29 -04005517static int decode_exchange_id(struct xdr_stream *xdr,
5518 struct nfs41_exchange_id_res *res)
5519{
5520 __be32 *p;
5521 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005522 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005523 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005524 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005525
5526 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5527 if (status)
5528 return status;
5529
Benny Halevyc0eae662009-08-14 17:20:14 +03005530 p = xdr_inline_decode(xdr, 8);
5531 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005532 return -EIO;
Trond Myklebust32b01312012-05-26 13:41:04 -04005533 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005534 p = xdr_inline_decode(xdr, 12);
5535 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005536 return -EIO;
Trond Myklebust32b01312012-05-26 13:41:04 -04005537 res->seqid = be32_to_cpup(p++);
5538 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005539
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005540 res->state_protect.how = be32_to_cpup(p);
5541 switch (res->state_protect.how) {
5542 case SP4_NONE:
5543 break;
5544 case SP4_MACH_CRED:
5545 status = decode_op_map(xdr, &res->state_protect.enforce);
5546 if (status)
5547 return status;
5548 status = decode_op_map(xdr, &res->state_protect.allow);
5549 if (status)
5550 return status;
5551 break;
5552 default:
5553 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005554 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005555 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005556
Chuck Leveracdeb692012-05-21 22:46:16 -04005557 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005558 p = xdr_inline_decode(xdr, 8);
5559 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005560 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005561 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005562
Chuck Leveracdeb692012-05-21 22:46:16 -04005563 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005564 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5565 if (unlikely(status))
5566 return status;
Chuck Leveracdeb692012-05-21 22:46:16 -04005567 memcpy(res->server_owner->major_id, dummy_str, dummy);
5568 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005569
Chuck Leveracdeb692012-05-21 22:46:16 -04005570 /* server_scope4 */
5571 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5572 if (unlikely(status))
5573 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005574 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5575 res->server_scope->server_scope_sz = dummy;
5576
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005577 /* Implementation Id */
5578 p = xdr_inline_decode(xdr, 4);
5579 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005580 return -EIO;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005581 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005582
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005583 if (impl_id_count) {
5584 /* nii_domain */
5585 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5586 if (unlikely(status))
5587 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005588 memcpy(res->impl_id->domain, dummy_str, dummy);
5589
5590 /* nii_name */
5591 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5592 if (unlikely(status))
5593 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005594 memcpy(res->impl_id->name, dummy_str, dummy);
5595
5596 /* nii_date */
5597 p = xdr_inline_decode(xdr, 12);
5598 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005599 return -EIO;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005600 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5601 res->impl_id->date.nseconds = be32_to_cpup(p);
5602
5603 /* if there's more than one entry, ignore the rest */
5604 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005605 return 0;
5606}
Andy Adamsonfc931582009-04-01 09:22:31 -04005607
5608static int decode_chan_attrs(struct xdr_stream *xdr,
5609 struct nfs4_channel_attrs *attrs)
5610{
5611 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005612 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005613
Benny Halevyc0eae662009-08-14 17:20:14 +03005614 p = xdr_inline_decode(xdr, 28);
5615 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005616 return -EIO;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005617 val = be32_to_cpup(p++); /* headerpadsz */
5618 if (val)
5619 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005620 attrs->max_rqst_sz = be32_to_cpup(p++);
5621 attrs->max_resp_sz = be32_to_cpup(p++);
5622 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5623 attrs->max_ops = be32_to_cpup(p++);
5624 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005625 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005626 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005627 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5628 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005629 return -EINVAL;
5630 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005631 if (nr_attrs == 1) {
5632 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5633 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005634 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005635 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005636 return 0;
5637}
5638
Benny Halevye78291e2009-08-14 17:20:00 +03005639static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5640{
5641 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005642}
5643
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005644static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5645 struct nfs41_bind_conn_to_session_res *res)
5646{
5647 __be32 *p;
5648 int status;
5649
5650 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5651 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005652 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005653 if (unlikely(status))
5654 return status;
5655
5656 /* dir flags, rdma mode bool */
5657 p = xdr_inline_decode(xdr, 8);
5658 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005659 return -EIO;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005660
5661 res->dir = be32_to_cpup(p++);
5662 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5663 return -EIO;
5664 if (be32_to_cpup(p) == 0)
5665 res->use_conn_in_rdma_mode = false;
5666 else
5667 res->use_conn_in_rdma_mode = true;
5668
5669 return 0;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005670}
5671
Andy Adamsonfc931582009-04-01 09:22:31 -04005672static int decode_create_session(struct xdr_stream *xdr,
5673 struct nfs41_create_session_res *res)
5674{
5675 __be32 *p;
5676 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005677
5678 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005679 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005680 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005681 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005682 return status;
5683
Andy Adamsonfc931582009-04-01 09:22:31 -04005684 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005685 p = xdr_inline_decode(xdr, 8);
5686 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005687 return -EIO;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005688 res->seqid = be32_to_cpup(p++);
5689 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005690
5691 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005692 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005693 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005694 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005695 return status;
5696}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005697
5698static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5699{
5700 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5701}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005702
Trond Myklebust66245532012-05-25 17:18:09 -04005703static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5704{
5705 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5706}
5707
Ricardo Labiaga180197532009-12-05 16:08:40 -05005708static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5709{
5710 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5711}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005712#endif /* CONFIG_NFS_V4_1 */
5713
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005714static int decode_sequence(struct xdr_stream *xdr,
5715 struct nfs4_sequence_res *res,
5716 struct rpc_rqst *rqstp)
5717{
5718#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005719 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005720 struct nfs4_sessionid id;
5721 u32 dummy;
5722 int status;
5723 __be32 *p;
5724
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005725 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005726 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005727 if (!res->sr_slot->table->session)
5728 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005729
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005730 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005731 if (!status)
5732 status = decode_sessionid(xdr, &id);
5733 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005734 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005735
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005736 /*
5737 * If the server returns different values for sessionID, slotID or
5738 * sequence number, the server is looney tunes.
5739 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005740 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005741 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005742
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005743 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005744 NFS4_MAX_SESSIONID_LEN)) {
5745 dprintk("%s Invalid session id\n", __func__);
5746 goto out_err;
5747 }
Benny Halevye78291e2009-08-14 17:20:00 +03005748
Benny Halevyc0eae662009-08-14 17:20:14 +03005749 p = xdr_inline_decode(xdr, 20);
5750 if (unlikely(!p))
5751 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005752
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005753 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005754 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005755 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005756 dprintk("%s Invalid sequence number\n", __func__);
5757 goto out_err;
5758 }
5759 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005760 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005761 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005762 dprintk("%s Invalid slot id\n", __func__);
5763 goto out_err;
5764 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005765 /* highest slot id */
5766 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005767 /* target highest slot id */
5768 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005769 /* result flags */
5770 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005771 status = 0;
5772out_err:
5773 res->sr_status = status;
5774 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005775out_overflow:
Benny Halevyc0eae662009-08-14 17:20:14 +03005776 status = -EIO;
5777 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005778#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005779 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005780#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005781}
5782
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005783#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005784static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5785{
5786 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5787 return decode_stateid(xdr, stateid);
5788}
5789
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005790static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005791 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005792{
Trond Myklebust4e590802015-03-09 14:01:25 -04005793 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005794 __be32 *p;
5795 uint32_t len, type;
5796 int status;
5797
5798 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5799 if (status) {
5800 if (status == -ETOOSMALL) {
5801 p = xdr_inline_decode(xdr, 4);
5802 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005803 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005804 pdev->mincount = be32_to_cpup(p);
5805 dprintk("%s: Min count too small. mincnt = %u\n",
5806 __func__, pdev->mincount);
5807 }
5808 return status;
5809 }
5810
5811 p = xdr_inline_decode(xdr, 8);
5812 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005813 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005814 type = be32_to_cpup(p++);
5815 if (type != pdev->layout_type) {
5816 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5817 __func__, pdev->layout_type, type);
5818 return -EINVAL;
5819 }
5820 /*
5821 * Get the length of the opaque device_addr4. xdr_read_pages places
5822 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5823 * and places the remaining xdr data in xdr_buf->tail
5824 */
5825 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005826 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
Chuck Levereb72f482019-02-11 11:24:21 -05005827 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005828
5829 /* Parse notification bitmap, verifying that it is zero. */
5830 p = xdr_inline_decode(xdr, 4);
5831 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005832 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005833 len = be32_to_cpup(p);
5834 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005835 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005836
5837 p = xdr_inline_decode(xdr, 4 * len);
5838 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005839 return -EIO;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005840
Trond Myklebust4e590802015-03-09 14:01:25 -04005841 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005842 for (i = 1; i < len; i++) {
5843 if (be32_to_cpup(p++)) {
5844 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005845 __func__);
5846 return -EIO;
5847 }
5848 }
5849 }
5850 return 0;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005851}
5852
5853static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5854 struct nfs4_layoutget_res *res)
5855{
5856 __be32 *p;
5857 int status;
5858 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005859 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005860
5861 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5862 if (status)
Fred Isaman808ba322016-10-04 15:02:21 -04005863 goto out;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005864 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005865 if (unlikely(!p))
5866 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005867 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04005868 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005869 p = xdr_inline_decode(xdr, 4);
5870 if (unlikely(!p))
5871 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005872 layout_count = be32_to_cpup(p);
5873 if (!layout_count) {
5874 dprintk("%s: server responded with empty layout array\n",
5875 __func__);
Fred Isaman808ba322016-10-04 15:02:21 -04005876 status = -EINVAL;
5877 goto out;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005878 }
5879
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005880 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005881 if (unlikely(!p))
5882 goto out_overflow;
5883 p = xdr_decode_hyper(p, &res->range.offset);
5884 p = xdr_decode_hyper(p, &res->range.length);
5885 res->range.iomode = be32_to_cpup(p++);
5886 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005887 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005888
5889 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5890 __func__,
5891 (unsigned long)res->range.offset,
5892 (unsigned long)res->range.length,
5893 res->range.iomode,
5894 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005895 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005896
Trond Myklebust64bd5772012-06-20 22:35:05 -04005897 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005898 if (res->layoutp->len > recvd) {
5899 dprintk("NFS: server cheating in layoutget reply: "
5900 "layout len %u > recvd %u\n",
5901 res->layoutp->len, recvd);
Fred Isaman808ba322016-10-04 15:02:21 -04005902 status = -EINVAL;
5903 goto out;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005904 }
5905
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005906 if (layout_count > 1) {
5907 /* We only handle a length one array at the moment. Any
5908 * further entries are just ignored. Note that this means
5909 * the client may see a response that is less than the
5910 * minimum it requested.
5911 */
5912 dprintk("%s: server responded with %d layouts, dropping tail\n",
5913 __func__, layout_count);
5914 }
5915
Fred Isaman808ba322016-10-04 15:02:21 -04005916out:
5917 res->status = status;
5918 return status;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005919out_overflow:
Fred Isaman808ba322016-10-04 15:02:21 -04005920 status = -EIO;
5921 goto out;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005922}
Andy Adamson863a3c62011-03-23 13:27:54 +00005923
Benny Halevycbe82602011-05-22 19:52:37 +03005924static int decode_layoutreturn(struct xdr_stream *xdr,
5925 struct nfs4_layoutreturn_res *res)
5926{
5927 __be32 *p;
5928 int status;
5929
5930 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5931 if (status)
5932 return status;
5933 p = xdr_inline_decode(xdr, 4);
5934 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005935 return -EIO;
Benny Halevycbe82602011-05-22 19:52:37 +03005936 res->lrs_present = be32_to_cpup(p);
5937 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005938 status = decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustfcd88432017-11-07 12:39:44 -05005939 else
5940 nfs4_stateid_copy(&res->stateid, &invalid_stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03005941 return status;
Benny Halevycbe82602011-05-22 19:52:37 +03005942}
5943
Andy Adamson863a3c62011-03-23 13:27:54 +00005944static int decode_layoutcommit(struct xdr_stream *xdr,
5945 struct rpc_rqst *req,
5946 struct nfs4_layoutcommit_res *res)
5947{
5948 __be32 *p;
5949 __u32 sizechanged;
5950 int status;
5951
5952 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005953 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005954 if (status)
5955 return status;
5956
5957 p = xdr_inline_decode(xdr, 4);
5958 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005959 return -EIO;
Andy Adamson863a3c62011-03-23 13:27:54 +00005960 sizechanged = be32_to_cpup(p);
5961
5962 if (sizechanged) {
5963 /* throw away new size */
5964 p = xdr_inline_decode(xdr, 8);
5965 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005966 return -EIO;
Andy Adamson863a3c62011-03-23 13:27:54 +00005967 }
5968 return 0;
Andy Adamson863a3c62011-03-23 13:27:54 +00005969}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005970
5971static int decode_test_stateid(struct xdr_stream *xdr,
5972 struct nfs41_test_stateid_res *res)
5973{
5974 __be32 *p;
5975 int status;
5976 int num_res;
5977
5978 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5979 if (status)
5980 return status;
5981
5982 p = xdr_inline_decode(xdr, 4);
5983 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005984 return -EIO;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005985 num_res = be32_to_cpup(p++);
5986 if (num_res != 1)
Chuck Levereb72f482019-02-11 11:24:21 -05005987 return -EIO;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005988
5989 p = xdr_inline_decode(xdr, 4);
5990 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005991 return -EIO;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005992 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005993
5994 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005995}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005996
5997static int decode_free_stateid(struct xdr_stream *xdr,
5998 struct nfs41_free_stateid_res *res)
5999{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006000 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006001 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006002}
Trond Myklebustcf805162016-11-15 14:56:07 -05006003#else
6004static inline
6005int decode_layoutreturn(struct xdr_stream *xdr,
6006 struct nfs4_layoutreturn_res *res)
6007{
6008 return 0;
6009}
Fred Isaman56f487f2016-09-21 11:43:41 -04006010
6011static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6012 struct nfs4_layoutget_res *res)
6013{
6014 return 0;
6015}
6016
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006017#endif /* CONFIG_NFS_V4_1 */
6018
Linus Torvalds1da177e2005-04-16 15:20:36 -07006019/*
Benny Halevy49c25592008-12-23 16:06:16 -05006020 * END OF "GENERIC" DECODE ROUTINES.
6021 */
6022
6023/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024 * Decode OPEN_DOWNGRADE response
6025 */
Chuck Leverbf269552010-12-14 14:59:29 +00006026static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6027 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006028 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006029{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006030 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006031 struct compound_hdr hdr;
6032 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006033
Chuck Leverbf269552010-12-14 14:59:29 +00006034 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006035 if (status)
6036 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006037 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006038 if (status)
6039 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006040 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006041 if (status)
6042 goto out;
Trond Myklebustb6808142016-11-20 13:34:16 -05006043 if (res->lr_res) {
6044 status = decode_layoutreturn(xdr, res->lr_res);
6045 res->lr_ret = status;
6046 if (status)
6047 goto out;
6048 }
Chuck Leverbf269552010-12-14 14:59:29 +00006049 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006050out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006051 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006052}
6053
6054/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006055 * Decode ACCESS response
6056 */
Chuck Leverbf269552010-12-14 14:59:29 +00006057static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006058 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006059{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006060 struct nfs4_accessres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061 struct compound_hdr hdr;
6062 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006063
Chuck Leverbf269552010-12-14 14:59:29 +00006064 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006065 if (status)
6066 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006067 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006068 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006069 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006070 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006071 if (status != 0)
6072 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006073 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006074 if (status != 0)
6075 goto out;
Trond Myklebust8bcbe7d2018-03-20 17:03:11 -04006076 if (res->fattr)
6077 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078out:
6079 return status;
6080}
6081
6082/*
6083 * Decode LOOKUP response
6084 */
Chuck Leverbf269552010-12-14 14:59:29 +00006085static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006086 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006087{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006088 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089 struct compound_hdr hdr;
6090 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006091
Chuck Leverbf269552010-12-14 14:59:29 +00006092 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006093 if (status)
6094 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006095 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006096 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006098 status = decode_putfh(xdr);
6099 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006100 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006101 status = decode_lookup(xdr);
6102 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006104 status = decode_getfh(xdr, res->fh);
6105 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006107 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006108out:
6109 return status;
6110}
6111
6112/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07006113 * Decode LOOKUPP response
6114 */
6115static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6116 void *data)
6117{
6118 struct nfs4_lookupp_res *res = data;
6119 struct compound_hdr hdr;
6120 int status;
6121
6122 status = decode_compound_hdr(xdr, &hdr);
6123 if (status)
6124 goto out;
6125 status = decode_sequence(xdr, &res->seq_res, rqstp);
6126 if (status)
6127 goto out;
6128 status = decode_putfh(xdr);
6129 if (status)
6130 goto out;
6131 status = decode_lookupp(xdr);
6132 if (status)
6133 goto out;
6134 status = decode_getfh(xdr, res->fh);
6135 if (status)
6136 goto out;
6137 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6138out:
6139 return status;
6140}
6141
6142/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143 * Decode LOOKUP_ROOT response
6144 */
Chuck Leverbf269552010-12-14 14:59:29 +00006145static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6146 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006147 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006148{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006149 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006150 struct compound_hdr hdr;
6151 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006152
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006154 if (status)
6155 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006157 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006158 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_putrootfh(xdr);
6160 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006161 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006162 status = decode_getfh(xdr, res->fh);
6163 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006164 status = decode_getfattr_label(xdr, res->fattr,
6165 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006166out:
6167 return status;
6168}
6169
6170/*
6171 * Decode REMOVE response
6172 */
Chuck Leverbf269552010-12-14 14:59:29 +00006173static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006174 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006175{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006176 struct nfs_removeres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006177 struct compound_hdr hdr;
6178 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006179
Chuck Leverbf269552010-12-14 14:59:29 +00006180 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006181 if (status)
6182 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006183 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006184 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006186 status = decode_putfh(xdr);
6187 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006188 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006189 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006190out:
6191 return status;
6192}
6193
6194/*
6195 * Decode RENAME response
6196 */
Chuck Leverbf269552010-12-14 14:59:29 +00006197static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006198 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006199{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006200 struct nfs_renameres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006201 struct compound_hdr hdr;
6202 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006203
Chuck Leverbf269552010-12-14 14:59:29 +00006204 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006205 if (status)
6206 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006207 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006208 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006210 status = decode_putfh(xdr);
6211 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006212 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006213 status = decode_savefh(xdr);
6214 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006215 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006216 status = decode_putfh(xdr);
6217 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006219 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006220out:
6221 return status;
6222}
6223
6224/*
6225 * Decode LINK response
6226 */
Chuck Leverbf269552010-12-14 14:59:29 +00006227static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006228 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006230 struct nfs4_link_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006231 struct compound_hdr hdr;
6232 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006233
Chuck Leverbf269552010-12-14 14:59:29 +00006234 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006235 if (status)
6236 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006237 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006238 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006240 status = decode_putfh(xdr);
6241 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006243 status = decode_savefh(xdr);
6244 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006245 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006246 status = decode_putfh(xdr);
6247 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006249 status = decode_link(xdr, &res->cinfo);
6250 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006251 goto out;
6252 /*
6253 * Note order: OP_LINK leaves the directory as the current
6254 * filehandle.
6255 */
Chuck Leverbf269552010-12-14 14:59:29 +00006256 status = decode_restorefh(xdr);
6257 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006258 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006259 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260out:
6261 return status;
6262}
6263
6264/*
6265 * Decode CREATE response
6266 */
Chuck Leverbf269552010-12-14 14:59:29 +00006267static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006268 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006269{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006270 struct nfs4_create_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271 struct compound_hdr hdr;
6272 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006273
Chuck Leverbf269552010-12-14 14:59:29 +00006274 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006275 if (status)
6276 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006277 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006278 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006279 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006280 status = decode_putfh(xdr);
6281 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006282 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006283 status = decode_create(xdr, &res->dir_cinfo);
6284 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006286 status = decode_getfh(xdr, res->fh);
6287 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006288 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006289 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290out:
6291 return status;
6292}
6293
6294/*
6295 * Decode SYMLINK response
6296 */
Chuck Leverbf269552010-12-14 14:59:29 +00006297static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006298 void *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299{
Chuck Leverbf269552010-12-14 14:59:29 +00006300 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006301}
6302
6303/*
6304 * Decode GETATTR response
6305 */
Chuck Leverbf269552010-12-14 14:59:29 +00006306static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006307 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006308{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006309 struct nfs4_getattr_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006310 struct compound_hdr hdr;
6311 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006312
Chuck Leverbf269552010-12-14 14:59:29 +00006313 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006314 if (status)
6315 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006316 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006317 if (status)
6318 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006319 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006320 if (status)
6321 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006322 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323out:
6324 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325}
6326
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006327/*
6328 * Encode an SETACL request
6329 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006330static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006331 const void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006332{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006333 const struct nfs_setaclargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006334 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006335 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006336 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006337
Chuck Lever9f06c712010-12-14 14:59:18 +00006338 encode_compound_hdr(xdr, req, &hdr);
6339 encode_sequence(xdr, &args->seq_args, &hdr);
6340 encode_putfh(xdr, args->fh, &hdr);
6341 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006342 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006343}
Andy Adamson05d564f2008-12-23 16:06:15 -05006344
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006345/*
6346 * Decode SETACL response
6347 */
6348static int
Chuck Leverbf269552010-12-14 14:59:29 +00006349nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006350 void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006351{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006352 struct nfs_setaclres *res = data;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006353 struct compound_hdr hdr;
6354 int status;
6355
Chuck Leverbf269552010-12-14 14:59:29 +00006356 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006357 if (status)
6358 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006359 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006360 if (status)
6361 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006362 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006363 if (status)
6364 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006365 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006366out:
6367 return status;
6368}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006369
6370/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006371 * Decode GETACL response
6372 */
6373static int
Chuck Leverbf269552010-12-14 14:59:29 +00006374nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006375 void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006376{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006377 struct nfs_getaclres *res = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00006378 struct compound_hdr hdr;
6379 int status;
6380
Trond Myklebust331818f2012-02-03 18:30:53 -05006381 if (res->acl_scratch != NULL) {
6382 void *p = page_address(res->acl_scratch);
6383 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6384 }
Chuck Leverbf269552010-12-14 14:59:29 +00006385 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006386 if (status)
6387 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006388 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006389 if (status)
6390 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006391 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006392 if (status)
6393 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006394 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006395
6396out:
6397 return status;
6398}
6399
6400/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006401 * Decode CLOSE response
6402 */
Chuck Leverbf269552010-12-14 14:59:29 +00006403static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006404 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006405{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006406 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006407 struct compound_hdr hdr;
6408 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006409
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006411 if (status)
6412 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006413 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006414 if (status)
6415 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006416 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006417 if (status)
6418 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006419 if (res->lr_res) {
6420 status = decode_layoutreturn(xdr, res->lr_res);
6421 res->lr_ret = status;
6422 if (status)
6423 goto out;
6424 }
Trond Myklebustd8d84982016-12-19 12:14:44 -05006425 if (res->fattr != NULL) {
6426 status = decode_getfattr(xdr, res->fattr, res->server);
6427 if (status != 0)
6428 goto out;
6429 }
Chuck Leverbf269552010-12-14 14:59:29 +00006430 status = decode_close(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006432 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006433}
6434
6435/*
6436 * Decode OPEN response
6437 */
Chuck Leverbf269552010-12-14 14:59:29 +00006438static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006439 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006441 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006442 struct compound_hdr hdr;
6443 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444
Chuck Leverbf269552010-12-14 14:59:29 +00006445 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006446 if (status)
6447 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006448 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006449 if (status)
6450 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006451 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006452 if (status)
6453 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006454 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006455 if (status)
6456 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006457 status = decode_getfh(xdr, &res->fh);
6458 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006459 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006460 if (res->access_request)
6461 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006462 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Fred Isaman56f487f2016-09-21 11:43:41 -04006463 if (res->lg_res)
6464 decode_layoutget(xdr, rqstp, res->lg_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006466 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467}
6468
6469/*
6470 * Decode OPEN_CONFIRM response
6471 */
Chuck Leverbf269552010-12-14 14:59:29 +00006472static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6473 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006474 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006476 struct nfs_open_confirmres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006477 struct compound_hdr hdr;
6478 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479
Chuck Leverbf269552010-12-14 14:59:29 +00006480 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006481 if (status)
6482 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006483 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006484 if (status)
6485 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006486 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006487out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006488 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006489}
6490
6491/*
6492 * Decode OPEN response
6493 */
Chuck Leverbf269552010-12-14 14:59:29 +00006494static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6495 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006496 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006498 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006499 struct compound_hdr hdr;
6500 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006501
Chuck Leverbf269552010-12-14 14:59:29 +00006502 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006503 if (status)
6504 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006505 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006506 if (status)
6507 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006508 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006509 if (status)
6510 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006511 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006512 if (status)
6513 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006514 if (res->access_request)
6515 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd12012-01-07 13:22:46 -05006516 decode_getfattr(xdr, res->f_attr, res->server);
Fred Isaman56f487f2016-09-21 11:43:41 -04006517 if (res->lg_res)
6518 decode_layoutget(xdr, rqstp, res->lg_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006519out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006520 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006521}
6522
6523/*
6524 * Decode SETATTR response
6525 */
Chuck Leverbf269552010-12-14 14:59:29 +00006526static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6527 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006528 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006530 struct nfs_setattrres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006531 struct compound_hdr hdr;
6532 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006533
Chuck Leverbf269552010-12-14 14:59:29 +00006534 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006535 if (status)
6536 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006537 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006538 if (status)
6539 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006540 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006541 if (status)
6542 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006543 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006544 if (status)
6545 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006546 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006548 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006549}
6550
6551/*
6552 * Decode LOCK response
6553 */
Chuck Leverbf269552010-12-14 14:59:29 +00006554static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006555 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006557 struct nfs_lock_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006558 struct compound_hdr hdr;
6559 int status;
6560
Chuck Leverbf269552010-12-14 14:59:29 +00006561 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006562 if (status)
6563 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006564 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006565 if (status)
6566 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006567 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006568 if (status)
6569 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006570 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006571out:
6572 return status;
6573}
6574
6575/*
6576 * Decode LOCKT response
6577 */
Chuck Leverbf269552010-12-14 14:59:29 +00006578static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006579 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006580{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006581 struct nfs_lockt_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006582 struct compound_hdr hdr;
6583 int status;
6584
Chuck Leverbf269552010-12-14 14:59:29 +00006585 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006586 if (status)
6587 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006588 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006589 if (status)
6590 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006591 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006592 if (status)
6593 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006594 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595out:
6596 return status;
6597}
6598
6599/*
6600 * Decode LOCKU response
6601 */
Chuck Leverbf269552010-12-14 14:59:29 +00006602static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006603 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006604{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006605 struct nfs_locku_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606 struct compound_hdr hdr;
6607 int status;
6608
Chuck Leverbf269552010-12-14 14:59:29 +00006609 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006610 if (status)
6611 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006612 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006613 if (status)
6614 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006615 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006616 if (status)
6617 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006618 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006619out:
6620 return status;
6621}
6622
Chuck Leverbf269552010-12-14 14:59:29 +00006623static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6624 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006625{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006626 struct compound_hdr hdr;
6627 int status;
6628
Chuck Leverbf269552010-12-14 14:59:29 +00006629 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006630 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006631 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006632 return status;
6633}
6634
Linus Torvalds1da177e2005-04-16 15:20:36 -07006635/*
6636 * Decode READLINK response
6637 */
Chuck Leverbf269552010-12-14 14:59:29 +00006638static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6639 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006640 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006641{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006642 struct nfs4_readlink_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643 struct compound_hdr hdr;
6644 int status;
6645
Chuck Leverbf269552010-12-14 14:59:29 +00006646 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647 if (status)
6648 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006649 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006650 if (status)
6651 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006652 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653 if (status)
6654 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006655 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006656out:
6657 return status;
6658}
6659
6660/*
6661 * Decode READDIR response
6662 */
Chuck Leverbf269552010-12-14 14:59:29 +00006663static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006664 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006665{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006666 struct nfs4_readdir_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006667 struct compound_hdr hdr;
6668 int status;
6669
Chuck Leverbf269552010-12-14 14:59:29 +00006670 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006671 if (status)
6672 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006673 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006674 if (status)
6675 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006676 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006677 if (status)
6678 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006679 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006680out:
6681 return status;
6682}
6683
6684/*
6685 * Decode Read response
6686 */
Chuck Leverbf269552010-12-14 14:59:29 +00006687static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006688 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006689{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006690 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006691 struct compound_hdr hdr;
6692 int status;
6693
Chuck Leverbf269552010-12-14 14:59:29 +00006694 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006695 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006696 if (status)
6697 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006698 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006699 if (status)
6700 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006701 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006702 if (status)
6703 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006704 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006705 if (!status)
6706 status = res->count;
6707out:
6708 return status;
6709}
6710
6711/*
6712 * Decode WRITE response
6713 */
Chuck Leverbf269552010-12-14 14:59:29 +00006714static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006715 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006716{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006717 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006718 struct compound_hdr hdr;
6719 int status;
6720
Chuck Leverbf269552010-12-14 14:59:29 +00006721 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006722 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006723 if (status)
6724 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006725 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006726 if (status)
6727 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006728 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006729 if (status)
6730 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006731 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006732 if (status)
6733 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006734 if (res->fattr)
Trond Myklebust6926afd12012-01-07 13:22:46 -05006735 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736 if (!status)
6737 status = res->count;
6738out:
6739 return status;
6740}
6741
6742/*
6743 * Decode COMMIT response
6744 */
Chuck Leverbf269552010-12-14 14:59:29 +00006745static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006746 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006747{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006748 struct nfs_commitres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749 struct compound_hdr hdr;
6750 int status;
6751
Chuck Leverbf269552010-12-14 14:59:29 +00006752 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006753 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006754 if (status)
6755 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006756 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006757 if (status)
6758 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006759 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006760 if (status)
6761 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006762 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006763out:
6764 return status;
6765}
6766
6767/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006768 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006769 */
Chuck Leverbf269552010-12-14 14:59:29 +00006770static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006771 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006772{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006773 struct nfs4_fsinfo_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006774 struct compound_hdr hdr;
6775 int status;
6776
Chuck Leverbf269552010-12-14 14:59:29 +00006777 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006778 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006779 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006780 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006781 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006782 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006783 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006784 return status;
6785}
6786
6787/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006788 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006789 */
Chuck Leverbf269552010-12-14 14:59:29 +00006790static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006791 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006792{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006793 struct nfs4_pathconf_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006794 struct compound_hdr hdr;
6795 int status;
6796
Chuck Leverbf269552010-12-14 14:59:29 +00006797 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006798 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006799 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006800 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006801 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006802 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006803 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006804 return status;
6805}
6806
6807/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006808 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006809 */
Chuck Leverbf269552010-12-14 14:59:29 +00006810static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006811 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006812{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006813 struct nfs4_statfs_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006814 struct compound_hdr hdr;
6815 int status;
6816
Chuck Leverbf269552010-12-14 14:59:29 +00006817 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006818 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006819 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006820 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006821 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006822 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006823 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006824 return status;
6825}
6826
6827/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006828 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006829 */
Chuck Leverbf269552010-12-14 14:59:29 +00006830static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6831 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006832 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006833{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006834 struct nfs4_server_caps_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006835 struct compound_hdr hdr;
6836 int status;
6837
Chuck Leverbf269552010-12-14 14:59:29 +00006838 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006839 if (status)
6840 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006841 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006842 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006843 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006844 status = decode_putfh(xdr);
6845 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006846 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006847 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006848out:
6849 return status;
6850}
6851
6852/*
6853 * Decode RENEW response
6854 */
Chuck Leverbf269552010-12-14 14:59:29 +00006855static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6856 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006857{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006858 struct compound_hdr hdr;
6859 int status;
6860
Chuck Leverbf269552010-12-14 14:59:29 +00006861 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006862 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006863 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006864 return status;
6865}
6866
6867/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006868 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006869 */
Chuck Leverbf269552010-12-14 14:59:29 +00006870static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6871 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006872 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006873{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006874 struct nfs4_setclientid_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006875 struct compound_hdr hdr;
6876 int status;
6877
Chuck Leverbf269552010-12-14 14:59:29 +00006878 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006879 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006880 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006881 return status;
6882}
6883
6884/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006885 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006886 */
Chuck Leverbf269552010-12-14 14:59:29 +00006887static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006888 struct xdr_stream *xdr,
6889 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006890{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006891 struct compound_hdr hdr;
6892 int status;
6893
Chuck Leverbf269552010-12-14 14:59:29 +00006894 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006895 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006896 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006897 return status;
6898}
6899
6900/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006901 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006902 */
Chuck Leverbf269552010-12-14 14:59:29 +00006903static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6904 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006905 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006906{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006907 struct nfs4_delegreturnres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006908 struct compound_hdr hdr;
6909 int status;
6910
Chuck Leverbf269552010-12-14 14:59:29 +00006911 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006912 if (status)
6913 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006914 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006915 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006916 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006917 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006918 if (status != 0)
6919 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05006920 if (res->lr_res) {
6921 status = decode_layoutreturn(xdr, res->lr_res);
6922 res->lr_ret = status;
6923 if (status)
6924 goto out;
6925 }
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05006926 if (res->fattr) {
6927 status = decode_getfattr(xdr, res->fattr, res->server);
6928 if (status != 0)
6929 goto out;
6930 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006931 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006932out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006933 return status;
6934}
6935
Trond Myklebust683b57b2006-06-09 09:34:22 -04006936/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006937 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006938 */
Chuck Leverbf269552010-12-14 14:59:29 +00006939static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6940 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006941 void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006942{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006943 struct nfs4_fs_locations_res *res = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04006944 struct compound_hdr hdr;
6945 int status;
6946
Chuck Leverbf269552010-12-14 14:59:29 +00006947 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006948 if (status)
6949 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006950 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006951 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006952 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006953 status = decode_putfh(xdr);
6954 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006955 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006956 if (res->migration) {
6957 xdr_enter_page(xdr, PAGE_SIZE);
6958 status = decode_getfattr_generic(xdr,
6959 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006960 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006961 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006962 if (status)
6963 goto out;
6964 if (res->renew)
6965 status = decode_renew(xdr);
6966 } else {
6967 status = decode_lookup(xdr);
6968 if (status)
6969 goto out;
6970 xdr_enter_page(xdr, PAGE_SIZE);
6971 status = decode_getfattr_generic(xdr,
6972 &res->fs_locations->fattr,
6973 NULL, res->fs_locations,
6974 NULL, res->fs_locations->server);
6975 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006976out:
6977 return status;
6978}
6979
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006980/*
6981 * Decode SECINFO response
6982 */
6983static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6984 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006985 void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006986{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006987 struct nfs4_secinfo_res *res = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006988 struct compound_hdr hdr;
6989 int status;
6990
6991 status = decode_compound_hdr(xdr, &hdr);
6992 if (status)
6993 goto out;
6994 status = decode_sequence(xdr, &res->seq_res, rqstp);
6995 if (status)
6996 goto out;
6997 status = decode_putfh(xdr);
6998 if (status)
6999 goto out;
7000 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007001out:
7002 return status;
7003}
7004
Chuck Lever44c99932013-10-17 14:13:30 -04007005/*
7006 * Decode FSID_PRESENT response
7007 */
7008static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7009 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007010 void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04007011{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007012 struct nfs4_fsid_present_res *res = data;
Chuck Lever44c99932013-10-17 14:13:30 -04007013 struct compound_hdr hdr;
7014 int status;
7015
7016 status = decode_compound_hdr(xdr, &hdr);
7017 if (status)
7018 goto out;
7019 status = decode_sequence(xdr, &res->seq_res, rqstp);
7020 if (status)
7021 goto out;
7022 status = decode_putfh(xdr);
7023 if (status)
7024 goto out;
7025 status = decode_getfh(xdr, res->fh);
7026 if (status)
7027 goto out;
7028 if (res->renew)
7029 status = decode_renew(xdr);
7030out:
7031 return status;
7032}
7033
Benny Halevy99fe60d2009-04-01 09:22:29 -04007034#if defined(CONFIG_NFS_V4_1)
7035/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007036 * Decode BIND_CONN_TO_SESSION response
7037 */
7038static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7039 struct xdr_stream *xdr,
7040 void *res)
7041{
7042 struct compound_hdr hdr;
7043 int status;
7044
7045 status = decode_compound_hdr(xdr, &hdr);
7046 if (!status)
7047 status = decode_bind_conn_to_session(xdr, res);
7048 return status;
7049}
7050
7051/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007052 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007053 */
Chuck Leverbf269552010-12-14 14:59:29 +00007054static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7055 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007056 void *res)
7057{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007058 struct compound_hdr hdr;
7059 int status;
7060
Chuck Leverbf269552010-12-14 14:59:29 +00007061 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007062 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007063 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007064 return status;
7065}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007066
7067/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007068 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007069 */
Chuck Leverbf269552010-12-14 14:59:29 +00007070static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7071 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007072 void *res)
Andy Adamsonfc931582009-04-01 09:22:31 -04007073{
Andy Adamsonfc931582009-04-01 09:22:31 -04007074 struct compound_hdr hdr;
7075 int status;
7076
Chuck Leverbf269552010-12-14 14:59:29 +00007077 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007078 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007079 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007080 return status;
7081}
7082
7083/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007084 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007085 */
Chuck Leverbf269552010-12-14 14:59:29 +00007086static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7087 struct xdr_stream *xdr,
7088 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007089{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007090 struct compound_hdr hdr;
7091 int status;
7092
Chuck Leverbf269552010-12-14 14:59:29 +00007093 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007094 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007095 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007096 return status;
7097}
7098
7099/*
Trond Myklebust66245532012-05-25 17:18:09 -04007100 * Decode DESTROY_CLIENTID response
7101 */
7102static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7103 struct xdr_stream *xdr,
7104 void *res)
7105{
7106 struct compound_hdr hdr;
7107 int status;
7108
7109 status = decode_compound_hdr(xdr, &hdr);
7110 if (!status)
7111 status = decode_destroy_clientid(xdr, res);
7112 return status;
7113}
7114
7115/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007116 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007117 */
Chuck Leverbf269552010-12-14 14:59:29 +00007118static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7119 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007120 void *res)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007121{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007122 struct compound_hdr hdr;
7123 int status;
7124
Chuck Leverbf269552010-12-14 14:59:29 +00007125 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007126 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007127 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007128 return status;
7129}
7130
Donald Buczek0efb01b2019-07-07 21:26:08 +02007131#endif
7132
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007133/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007134 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007135 */
Chuck Leverbf269552010-12-14 14:59:29 +00007136static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7137 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007138 void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04007139{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007140 struct nfs4_get_lease_time_res *res = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04007141 struct compound_hdr hdr;
7142 int status;
7143
Chuck Leverbf269552010-12-14 14:59:29 +00007144 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007145 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007146 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007147 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007148 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007149 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007150 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007151 return status;
7152}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007153
Donald Buczek0efb01b2019-07-07 21:26:08 +02007154#ifdef CONFIG_NFS_V4_1
7155
Ricardo Labiaga180197532009-12-05 16:08:40 -05007156/*
7157 * Decode RECLAIM_COMPLETE response
7158 */
Chuck Leverbf269552010-12-14 14:59:29 +00007159static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7160 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007161 void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05007162{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007163 struct nfs41_reclaim_complete_res *res = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05007164 struct compound_hdr hdr;
7165 int status;
7166
Chuck Leverbf269552010-12-14 14:59:29 +00007167 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007168 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007169 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007170 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307171 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007172 return status;
7173}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007174
7175/*
7176 * Decode GETDEVINFO response
7177 */
Chuck Leverbf269552010-12-14 14:59:29 +00007178static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7179 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007180 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007181{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007182 struct nfs4_getdeviceinfo_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007183 struct compound_hdr hdr;
7184 int status;
7185
Chuck Leverbf269552010-12-14 14:59:29 +00007186 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007187 if (status != 0)
7188 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007189 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007190 if (status != 0)
7191 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007192 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007193out:
7194 return status;
7195}
7196
7197/*
7198 * Decode LAYOUTGET response
7199 */
Chuck Leverbf269552010-12-14 14:59:29 +00007200static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7201 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007202 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007203{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007204 struct nfs4_layoutget_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007205 struct compound_hdr hdr;
7206 int status;
7207
Chuck Leverbf269552010-12-14 14:59:29 +00007208 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007209 if (status)
7210 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007211 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007212 if (status)
7213 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007214 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007215 if (status)
7216 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007217 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007218out:
7219 return status;
7220}
Andy Adamson863a3c62011-03-23 13:27:54 +00007221
7222/*
Benny Halevycbe82602011-05-22 19:52:37 +03007223 * Decode LAYOUTRETURN response
7224 */
7225static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7226 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007227 void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03007228{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007229 struct nfs4_layoutreturn_res *res = data;
Benny Halevycbe82602011-05-22 19:52:37 +03007230 struct compound_hdr hdr;
7231 int status;
7232
7233 status = decode_compound_hdr(xdr, &hdr);
7234 if (status)
7235 goto out;
7236 status = decode_sequence(xdr, &res->seq_res, rqstp);
7237 if (status)
7238 goto out;
7239 status = decode_putfh(xdr);
7240 if (status)
7241 goto out;
7242 status = decode_layoutreturn(xdr, res);
7243out:
7244 return status;
7245}
7246
7247/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007248 * Decode LAYOUTCOMMIT response
7249 */
7250static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7251 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007252 void *data)
Andy Adamson863a3c62011-03-23 13:27:54 +00007253{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007254 struct nfs4_layoutcommit_res *res = data;
Andy Adamson863a3c62011-03-23 13:27:54 +00007255 struct compound_hdr hdr;
7256 int status;
7257
7258 status = decode_compound_hdr(xdr, &hdr);
7259 if (status)
7260 goto out;
7261 status = decode_sequence(xdr, &res->seq_res, rqstp);
7262 if (status)
7263 goto out;
7264 status = decode_putfh(xdr);
7265 if (status)
7266 goto out;
7267 status = decode_layoutcommit(xdr, rqstp, res);
7268 if (status)
7269 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05007270 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007271out:
7272 return status;
7273}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007274
7275/*
7276 * Decode SECINFO_NO_NAME response
7277 */
7278static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7279 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007280 void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007281{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007282 struct nfs4_secinfo_res *res = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007283 struct compound_hdr hdr;
7284 int status;
7285
7286 status = decode_compound_hdr(xdr, &hdr);
7287 if (status)
7288 goto out;
7289 status = decode_sequence(xdr, &res->seq_res, rqstp);
7290 if (status)
7291 goto out;
7292 status = decode_putrootfh(xdr);
7293 if (status)
7294 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007295 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007296out:
7297 return status;
7298}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007299
7300/*
7301 * Decode TEST_STATEID response
7302 */
7303static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7304 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007305 void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04007306{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007307 struct nfs41_test_stateid_res *res = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04007308 struct compound_hdr hdr;
7309 int status;
7310
7311 status = decode_compound_hdr(xdr, &hdr);
7312 if (status)
7313 goto out;
7314 status = decode_sequence(xdr, &res->seq_res, rqstp);
7315 if (status)
7316 goto out;
7317 status = decode_test_stateid(xdr, res);
7318out:
7319 return status;
7320}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007321
7322/*
7323 * Decode FREE_STATEID response
7324 */
7325static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7326 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007327 void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007328{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007329 struct nfs41_free_stateid_res *res = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007330 struct compound_hdr hdr;
7331 int status;
7332
7333 status = decode_compound_hdr(xdr, &hdr);
7334 if (status)
7335 goto out;
7336 status = decode_sequence(xdr, &res->seq_res, rqstp);
7337 if (status)
7338 goto out;
7339 status = decode_free_stateid(xdr, res);
7340out:
7341 return status;
7342}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007343#endif /* CONFIG_NFS_V4_1 */
7344
Chuck Lever573c4e12010-12-14 14:58:11 +00007345/**
7346 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7347 * the local page cache.
7348 * @xdr: XDR stream where entry resides
7349 * @entry: buffer to fill in with entry data
7350 * @plus: boolean indicating whether this should be a readdirplus entry
7351 *
7352 * Returns zero if successful, otherwise a negative errno value is
7353 * returned.
7354 *
7355 * This function is not invoked during READDIR reply decoding, but
7356 * rather whenever an application invokes the getdents(2) system call
7357 * on a directory already in our cache.
7358 */
7359int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -04007360 bool plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007361{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007362 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007363 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007364 uint32_t len;
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007365 uint64_t new_cookie;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007366 __be32 *p = xdr_inline_decode(xdr, 4);
7367 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007368 return -EAGAIN;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007369 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007370 p = xdr_inline_decode(xdr, 4);
7371 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007372 return -EAGAIN;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007373 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007374 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007375 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007376 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007377 }
7378
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007379 p = xdr_inline_decode(xdr, 12);
7380 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007381 return -EAGAIN;
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007382 p = xdr_decode_hyper(p, &new_cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007383 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007384
Trond Myklebust9af8c222010-10-24 11:52:55 -04007385 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007386 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007387 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007388 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007389
7390 /*
7391 * In case the server doesn't return an inode number,
7392 * we fake one here. (We don't use inode number 0,
7393 * since glibc seems to choke on it...)
7394 */
7395 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007396 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007397
Trond Myklebust9af8c222010-10-24 11:52:55 -04007398 if (decode_attr_bitmap(xdr, bitmap) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05007399 return -EAGAIN;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007400
Trond Myklebust256e48b2012-06-21 11:18:13 -04007401 if (decode_attr_length(xdr, &len, &savep) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05007402 return -EAGAIN;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007403
Chuck Lever573c4e12010-12-14 14:58:11 +00007404 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007405 NULL, entry->label, entry->server) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05007406 return -EAGAIN;
Trond Myklebust28331a42011-04-27 13:47:52 -04007407 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7408 entry->ino = entry->fattr->mounted_on_fileid;
7409 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007410 entry->ino = entry->fattr->fileid;
7411
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007412 entry->d_type = DT_UNKNOWN;
7413 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7414 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7415
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007416 entry->prev_cookie = entry->cookie;
7417 entry->cookie = new_cookie;
7418
Chuck Lever573c4e12010-12-14 14:58:11 +00007419 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007420}
7421
7422/*
7423 * We need to translate between nfs status return values and
7424 * the local errno values which may not be the same.
7425 */
7426static struct {
7427 int stat;
7428 int errno;
7429} nfs_errtbl[] = {
7430 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007431 { NFS4ERR_PERM, -EPERM },
7432 { NFS4ERR_NOENT, -ENOENT },
7433 { NFS4ERR_IO, -errno_NFSERR_IO},
7434 { NFS4ERR_NXIO, -ENXIO },
7435 { NFS4ERR_ACCESS, -EACCES },
7436 { NFS4ERR_EXIST, -EEXIST },
7437 { NFS4ERR_XDEV, -EXDEV },
7438 { NFS4ERR_NOTDIR, -ENOTDIR },
7439 { NFS4ERR_ISDIR, -EISDIR },
7440 { NFS4ERR_INVAL, -EINVAL },
7441 { NFS4ERR_FBIG, -EFBIG },
7442 { NFS4ERR_NOSPC, -ENOSPC },
7443 { NFS4ERR_ROFS, -EROFS },
7444 { NFS4ERR_MLINK, -EMLINK },
7445 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7446 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7447 { NFS4ERR_DQUOT, -EDQUOT },
7448 { NFS4ERR_STALE, -ESTALE },
7449 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007450 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7451 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7452 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007453 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007454 { NFS4ERR_BADTYPE, -EBADTYPE },
7455 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007456 { NFS4ERR_SYMLINK, -ELOOP },
7457 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7458 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007459 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007460};
7461
7462/*
7463 * Convert an NFS error code to a local one.
7464 * This one is used jointly by NFSv2 and NFSv3.
7465 */
7466static int
David Howells0a8ea432006-08-22 20:06:08 -04007467nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007468{
7469 int i;
7470 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7471 if (nfs_errtbl[i].stat == stat)
7472 return nfs_errtbl[i].errno;
7473 }
7474 if (stat <= 10000 || stat > 10100) {
7475 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007476 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007477 }
7478 /* If we cannot translate the error, the recovery routines should
7479 * handle it.
7480 * Note: remaining NFSv4 error codes have values > 10000, so should
7481 * not conflict with native Linux error codes.
7482 */
Benny Halevy856dff32008-03-31 17:39:06 +03007483 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007484}
7485
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007486#ifdef CONFIG_NFS_V4_2
7487#include "nfs42xdr.c"
7488#endif /* CONFIG_NFS_V4_2 */
7489
Linus Torvalds1da177e2005-04-16 15:20:36 -07007490#define PROC(proc, argtype, restype) \
7491[NFSPROC4_CLNT_##proc] = { \
7492 .p_proc = NFSPROC4_COMPOUND, \
Christoph Hellwigfcc85812017-05-08 10:01:49 +02007493 .p_encode = nfs4_xdr_##argtype, \
Christoph Hellwigfc016482017-05-08 15:09:02 +02007494 .p_decode = nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007495 .p_arglen = NFS4_##argtype##_sz, \
7496 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007497 .p_statidx = NFSPROC4_CLNT_##proc, \
7498 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007499}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007500
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007501#define STUB(proc) \
7502[NFSPROC4_CLNT_##proc] = { \
7503 .p_name = #proc, \
7504}
7505
Trond Myklebust8634ef52018-01-06 09:53:49 -05007506#if defined(CONFIG_NFS_V4_1)
7507#define PROC41(proc, argtype, restype) \
7508 PROC(proc, argtype, restype)
7509#else
7510#define PROC41(proc, argtype, restype) \
7511 STUB(proc)
7512#endif
7513
7514#if defined(CONFIG_NFS_V4_2)
7515#define PROC42(proc, argtype, restype) \
7516 PROC(proc, argtype, restype)
7517#else
7518#define PROC42(proc, argtype, restype) \
7519 STUB(proc)
7520#endif
7521
Christoph Hellwig511e9362017-05-12 15:36:49 +02007522const struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007523 PROC(READ, enc_read, dec_read),
7524 PROC(WRITE, enc_write, dec_write),
7525 PROC(COMMIT, enc_commit, dec_commit),
7526 PROC(OPEN, enc_open, dec_open),
7527 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7528 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7529 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7530 PROC(CLOSE, enc_close, dec_close),
7531 PROC(SETATTR, enc_setattr, dec_setattr),
7532 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7533 PROC(RENEW, enc_renew, dec_renew),
7534 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7535 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7536 PROC(LOCK, enc_lock, dec_lock),
7537 PROC(LOCKT, enc_lockt, dec_lockt),
7538 PROC(LOCKU, enc_locku, dec_locku),
7539 PROC(ACCESS, enc_access, dec_access),
7540 PROC(GETATTR, enc_getattr, dec_getattr),
7541 PROC(LOOKUP, enc_lookup, dec_lookup),
7542 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7543 PROC(REMOVE, enc_remove, dec_remove),
7544 PROC(RENAME, enc_rename, dec_rename),
7545 PROC(LINK, enc_link, dec_link),
7546 PROC(SYMLINK, enc_symlink, dec_symlink),
7547 PROC(CREATE, enc_create, dec_create),
7548 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7549 PROC(STATFS, enc_statfs, dec_statfs),
7550 PROC(READLINK, enc_readlink, dec_readlink),
7551 PROC(READDIR, enc_readdir, dec_readdir),
7552 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7553 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7554 PROC(GETACL, enc_getacl, dec_getacl),
7555 PROC(SETACL, enc_setacl, dec_setacl),
7556 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7557 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007558 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007559 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007560 PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7561 PROC41(CREATE_SESSION, enc_create_session, dec_create_session),
7562 PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7563 PROC41(SEQUENCE, enc_sequence, dec_sequence),
Donald Buczek0efb01b2019-07-07 21:26:08 +02007564 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007565 PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete),
7566 PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7567 PROC41(LAYOUTGET, enc_layoutget, dec_layoutget),
7568 PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7569 PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7570 PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7571 PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7572 PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007573 STUB(GETDEVICELIST),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007574 PROC41(BIND_CONN_TO_SESSION,
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007575 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007576 PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid),
7577 PROC42(SEEK, enc_seek, dec_seek),
7578 PROC42(ALLOCATE, enc_allocate, dec_allocate),
7579 PROC42(DEALLOCATE, enc_deallocate, dec_deallocate),
7580 PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
7581 PROC42(CLONE, enc_clone, dec_clone),
7582 PROC42(COPY, enc_copy, dec_copy),
Olga Kornievskaiacb95dee2018-07-09 15:13:29 -04007583 PROC42(OFFLOAD_CANCEL, enc_offload_cancel, dec_offload_cancel),
Olga Kornievskaia04915672019-06-04 16:14:30 -04007584 PROC42(COPY_NOTIFY, enc_copy_notify, dec_copy_notify),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007585 PROC(LOOKUPP, enc_lookupp, dec_lookupp),
Trond Myklebust3eb86092019-02-08 10:31:05 -05007586 PROC42(LAYOUTERROR, enc_layouterror, dec_layouterror),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007587};
7588
Christoph Hellwigc5518582017-05-08 23:27:10 +02007589static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
Trond Myklebusta613fa12012-01-20 13:53:56 -05007590const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007591 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007592 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Christoph Hellwigc5518582017-05-08 23:27:10 +02007593 .procs = nfs4_procedures,
7594 .counts = nfs_version4_counts,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007595};
7596
7597/*
7598 * Local variables:
7599 * c-basic-offset: 8
7600 * End:
7601 */