blob: cfcabc33e24d01136ba00c336f90497f657fb0a5 [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)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400840#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
841 encode_sequence_maxsz + \
842 encode_putrootfh_maxsz + \
843 encode_fsinfo_maxsz)
844#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
845 decode_sequence_maxsz + \
846 decode_putrootfh_maxsz + \
847 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500848#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
849 encode_sequence_maxsz + \
850 encode_reclaim_complete_maxsz)
851#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
852 decode_sequence_maxsz + \
853 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400854#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
855 encode_sequence_maxsz +\
856 encode_getdeviceinfo_maxsz)
857#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
858 decode_sequence_maxsz + \
859 decode_getdeviceinfo_maxsz)
860#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
861 encode_sequence_maxsz + \
862 encode_putfh_maxsz + \
863 encode_layoutget_maxsz)
864#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
865 decode_sequence_maxsz + \
866 decode_putfh_maxsz + \
867 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000868#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
869 encode_sequence_maxsz +\
870 encode_putfh_maxsz + \
871 encode_layoutcommit_maxsz + \
872 encode_getattr_maxsz)
873#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
874 decode_sequence_maxsz + \
875 decode_putfh_maxsz + \
876 decode_layoutcommit_maxsz + \
877 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300878#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
879 encode_sequence_maxsz + \
880 encode_putfh_maxsz + \
881 encode_layoutreturn_maxsz)
882#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
883 decode_sequence_maxsz + \
884 decode_putfh_maxsz + \
885 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400886#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
887 encode_sequence_maxsz + \
888 encode_putrootfh_maxsz +\
889 encode_secinfo_no_name_maxsz)
890#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
891 decode_sequence_maxsz + \
892 decode_putrootfh_maxsz + \
893 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400894#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
895 encode_sequence_maxsz + \
896 encode_test_stateid_maxsz)
897#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
898 decode_sequence_maxsz + \
899 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400900#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
901 encode_sequence_maxsz + \
902 encode_free_stateid_maxsz)
903#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
904 decode_sequence_maxsz + \
905 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500906
907const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
908 compound_encode_hdr_maxsz +
909 encode_sequence_maxsz +
910 encode_putfh_maxsz +
911 encode_getattr_maxsz) *
912 XDR_UNIT);
913
914const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
915 compound_decode_hdr_maxsz +
916 decode_sequence_maxsz +
917 decode_putfh_maxsz) *
918 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400919
920const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
921 compound_decode_hdr_maxsz +
922 decode_sequence_maxsz) *
923 XDR_UNIT);
924EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400925#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
Trond Myklebustbca79472009-03-11 14:10:26 -0400927static const umode_t nfs_type2fmt[] = {
928 [NF4BAD] = 0,
929 [NF4REG] = S_IFREG,
930 [NF4DIR] = S_IFDIR,
931 [NF4BLK] = S_IFBLK,
932 [NF4CHR] = S_IFCHR,
933 [NF4LNK] = S_IFLNK,
934 [NF4SOCK] = S_IFSOCK,
935 [NF4FIFO] = S_IFIFO,
936 [NF4ATTRDIR] = 0,
937 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938};
939
940struct compound_hdr {
941 int32_t status;
942 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500943 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 uint32_t taglen;
945 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400946 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400947 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948};
949
Benny Halevy13c65ce2009-08-14 17:19:25 +0300950static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
951{
952 __be32 *p = xdr_reserve_space(xdr, nbytes);
953 BUG_ON(!p);
954 return p;
955}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Trond Myklebustcb17e552012-03-04 18:13:56 -0500957static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
958{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500959 WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
Trond Myklebustcb17e552012-03-04 18:13:56 -0500960}
961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
963{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500964 WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965}
966
Trond Myklebust4ade9822012-03-04 18:13:57 -0500967static void encode_uint32(struct xdr_stream *xdr, u32 n)
968{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500969 WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500970}
971
Trond Myklebustff2eb682012-03-05 11:40:12 -0500972static void encode_uint64(struct xdr_stream *xdr, u64 n)
973{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500974 WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
Trond Myklebustff2eb682012-03-05 11:40:12 -0500975}
976
Trond Myklebust37c88762018-03-20 17:03:08 -0400977static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
978 const __u32 *bitmap, size_t len)
979{
980 ssize_t ret;
981
982 /* Trim empty words */
983 while (len > 0 && bitmap[len-1] == 0)
984 len--;
985 ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
986 if (WARN_ON_ONCE(ret < 0))
987 return ret;
988 return len;
989}
990
991static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
992 __u32 *res, size_t len)
993{
994 size_t i;
995 __u32 tmp;
996
997 while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
998 len--;
999 for (i = len; i-- > 0;) {
1000 tmp = bitmap[i] & mask[i];
1001 res[i] = tmp;
1002 }
1003 return len;
1004}
1005
Trond Myklebust4ade9822012-03-04 18:13:57 -05001006static void encode_nfs4_seqid(struct xdr_stream *xdr,
1007 const struct nfs_seqid *seqid)
1008{
Trond Myklebusta6796412015-01-23 19:04:44 -05001009 if (seqid != NULL)
1010 encode_uint32(xdr, seqid->sequence->counter);
1011 else
1012 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001013}
1014
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001015static void encode_compound_hdr(struct xdr_stream *xdr,
1016 struct rpc_rqst *req,
1017 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018{
Al Viro8687b632006-10-19 23:28:48 -07001019 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001020
1021 /* initialize running count of expected bytes in reply.
1022 * NOTE: the replied tag SHOULD be the same is the one sent,
1023 * but this is not required as a MUST for the server to do so. */
Chuck Levercf500ba2019-02-11 11:25:20 -05001024 hdr->replen = 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
Trond Myklebust7fc38842012-10-15 11:51:21 -04001026 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001027 encode_string(xdr, hdr->taglen, hdr->tag);
1028 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001029 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -05001030 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +03001031 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -05001032}
1033
Trond Myklebustab19b482012-03-04 18:13:57 -05001034static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
1035 uint32_t replen,
1036 struct compound_hdr *hdr)
1037{
1038 encode_uint32(xdr, op);
1039 hdr->nops++;
1040 hdr->replen += replen;
1041}
1042
Andy Adamsond0179312008-12-23 16:06:17 -05001043static void encode_nops(struct compound_hdr *hdr)
1044{
Trond Myklebust7fc38842012-10-15 11:51:21 -04001045 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -05001046 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047}
1048
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001049static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1050{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001051 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001052}
1053
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1055{
Trond Myklebustcb17e552012-03-04 18:13:56 -05001056 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057}
1058
Trond Myklebust36b37432018-03-20 17:03:10 -04001059static __be32 *
1060xdr_encode_nfstime4(__be32 *p, const struct timespec *t)
1061{
1062 p = xdr_encode_hyper(p, (__s64)t->tv_sec);
1063 *p++ = cpu_to_be32(t->tv_nsec);
1064 return p;
1065}
1066
David Quigleyaa9c2662013-05-22 12:50:44 -04001067static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1068 const struct nfs4_label *label,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001069 const umode_t *umask,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001070 const struct nfs_server *server,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001071 const uint32_t attrmask[])
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072{
Deepa Dinamani95582b02018-05-08 19:36:02 -07001073 struct timespec ts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 char owner_name[IDMAP_NAMESZ];
1075 char owner_group[IDMAP_NAMESZ];
1076 int owner_namelen = 0;
1077 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001078 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001079 uint32_t len = 0;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001080 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
1082 /*
1083 * We reserve enough space to write the entire attribute buffer at once.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 */
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001085 if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001086 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001088 }
1089 if (iap->ia_valid & ATTR_MODE) {
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001090 if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001091 bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1092 len += 8;
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001093 } else if (attrmask[1] & FATTR4_WORD1_MODE) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001094 bmval[1] |= FATTR4_WORD1_MODE;
1095 len += 4;
1096 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001097 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001098 if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001099 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001101 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001102 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 /* XXX */
1104 strcpy(owner_name, "nobody");
1105 owner_namelen = sizeof("nobody") - 1;
1106 /* goto out; */
1107 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001108 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1110 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001111 if ((iap->ia_valid & ATTR_GID) &&
1112 (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001113 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001115 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001116 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 strcpy(owner_group, "nobody");
1118 owner_grouplen = sizeof("nobody") - 1;
1119 /* goto out; */
1120 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001121 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1123 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001124 if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1125 if (iap->ia_valid & ATTR_ATIME_SET) {
1126 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
Trond Myklebust36b37432018-03-20 17:03:10 -04001127 len += 4 + (nfstime4_maxsz << 2);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001128 } else if (iap->ia_valid & ATTR_ATIME) {
1129 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1130 len += 4;
1131 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001133 if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1134 if (iap->ia_valid & ATTR_MTIME_SET) {
1135 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
Trond Myklebust36b37432018-03-20 17:03:10 -04001136 len += 4 + (nfstime4_maxsz << 2);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001137 } else if (iap->ia_valid & ATTR_MTIME) {
1138 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1139 len += 4;
1140 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001142
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001143 if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001144 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1145 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1146 }
1147
Trond Myklebust40a3426c2018-03-20 17:03:09 -04001148 xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
1149 xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001150
1151 if (bmval[0] & FATTR4_WORD0_SIZE)
1152 p = xdr_encode_hyper(p, iap->ia_size);
1153 if (bmval[1] & FATTR4_WORD1_MODE)
1154 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1155 if (bmval[1] & FATTR4_WORD1_OWNER)
1156 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1157 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1158 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1159 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1160 if (iap->ia_valid & ATTR_ATIME_SET) {
1161 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Deepa Dinamani95582b02018-05-08 19:36:02 -07001162 ts = timespec64_to_timespec(iap->ia_atime);
1163 p = xdr_encode_nfstime4(p, &ts);
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);
Deepa Dinamani95582b02018-05-08 19:36:02 -07001170 ts = timespec64_to_timespec(iap->ia_mtime);
1171 p = xdr_encode_nfstime4(p, &ts);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001172 } else
1173 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1174 }
1175 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001176 *p++ = cpu_to_be32(label->lfs);
1177 *p++ = cpu_to_be32(label->pi);
1178 *p++ = cpu_to_be32(label->len);
1179 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1180 }
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001181 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1182 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1183 *p++ = cpu_to_be32(*umask);
1184 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001185
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187}
1188
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001189static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001191 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1192 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193}
1194
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001195static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196{
Trond Myklebustab19b482012-03-04 18:13:57 -05001197 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001198 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001199 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200}
1201
Fred Isaman0b7c0152012-04-20 14:47:39 -04001202static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203{
Al Viro8687b632006-10-19 23:28:48 -07001204 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001205
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001206 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1207 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001208 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001209 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210}
1211
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001212static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
Al Viro8687b632006-10-19 23:28:48 -07001214 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001215
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001216 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1217 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
1219 switch (create->ftype) {
1220 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001221 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001222 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001223 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1224 create->u.symlink.len);
1225 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 break;
1227
1228 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001229 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001230 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001231 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 break;
1233
1234 default:
1235 break;
1236 }
1237
Benny Halevy811652b2009-08-14 17:19:34 +03001238 encode_string(xdr, create->name->len, create->name->name);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001239 encode_attrs(xdr, create->attrs, create->label, &create->umask,
1240 create->server, create->server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241}
1242
Trond Myklebust37c88762018-03-20 17:03:08 -04001243static void encode_getattr(struct xdr_stream *xdr,
1244 const __u32 *bitmap, const __u32 *mask, size_t len,
1245 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246{
Trond Myklebust37c88762018-03-20 17:03:08 -04001247 __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001249 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04001250 if (mask) {
1251 if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
1252 len = ARRAY_SIZE(masked_bitmap);
1253 len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
1254 bitmap = masked_bitmap;
Fred Isamandae100c2011-07-30 20:52:37 -04001255 }
Trond Myklebust37c88762018-03-20 17:03:08 -04001256 xdr_encode_bitmap4(xdr, bitmap, len);
Fred Isamandae100c2011-07-30 20:52:37 -04001257}
1258
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001259static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260{
Trond Myklebust37c88762018-03-20 17:03:08 -04001261 encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
1262 ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263}
1264
Andy Adamson88034c32012-05-23 05:02:34 -04001265static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001266 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001267 struct compound_hdr *hdr)
1268{
Trond Myklebust37c88762018-03-20 17:03:08 -04001269 encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
Andy Adamson88034c32012-05-23 05:02:34 -04001270}
1271
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001272static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273{
Trond Myklebust37c88762018-03-20 17:03:08 -04001274 encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
1275 ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276}
1277
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001278static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001279{
Trond Myklebust37c88762018-03-20 17:03:08 -04001280 encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
1281 ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001282}
1283
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001284static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285{
Trond Myklebustab19b482012-03-04 18:13:57 -05001286 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287}
1288
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001289static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290{
Trond Myklebustab19b482012-03-04 18:13:57 -05001291 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001292 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293}
1294
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001295static inline int nfs4_lock_type(struct file_lock *fl, int block)
1296{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001297 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001298 return block ? NFS4_READW_LT : NFS4_READ_LT;
1299 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1300}
1301
1302static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1303{
1304 if (fl->fl_end == OFFSET_MAX)
1305 return ~(uint64_t)0;
1306 return fl->fl_end - fl->fl_start + 1;
1307}
1308
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001309static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1310{
1311 __be32 *p;
1312
Trond Myklebustd035c362010-12-21 10:45:27 -05001313 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001314 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001315 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001316 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001317 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001318 xdr_encode_hyper(p, lowner->id);
1319}
1320
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321/*
1322 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1323 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1324 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001325static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326{
Al Viro8687b632006-10-19 23:28:48 -07001327 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001329 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1330 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001331 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1332 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001333 p = xdr_encode_hyper(p, args->fl->fl_start);
1334 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001335 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001336 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001337 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001338 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001339 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001340 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 }
1342 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001343 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001344 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346}
1347
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001348static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349{
Al Viro8687b632006-10-19 23:28:48 -07001350 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001352 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1353 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001354 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001355 p = xdr_encode_hyper(p, args->fl->fl_start);
1356 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001357 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358}
1359
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001360static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361{
Al Viro8687b632006-10-19 23:28:48 -07001362 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001364 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1365 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001366 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001367 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001368 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001369 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001370 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371}
1372
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001373static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1374{
Trond Myklebustab19b482012-03-04 18:13:57 -05001375 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001376 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001377}
1378
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001379static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380{
Trond Myklebustab19b482012-03-04 18:13:57 -05001381 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001382 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383}
1384
Jeff Layton5b5faaf2017-06-29 06:34:52 -07001385static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
1386{
1387 encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
1388}
1389
Trond Myklebust6ae37332015-01-30 14:21:14 -05001390static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391{
Al Viro8687b632006-10-19 23:28:48 -07001392 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
Benny Halevy13c65ce2009-08-14 17:19:25 +03001394 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001395 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001396 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397}
1398
1399static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1400{
Al Viro8687b632006-10-19 23:28:48 -07001401 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 /*
1403 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1404 * owner 4 = 32
1405 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001406 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001407 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001408 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001409 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001410 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001411 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001412 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001413 *p++ = cpu_to_be32(arg->id.uniquifier);
1414 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415}
1416
1417static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1418{
Al Viro8687b632006-10-19 23:28:48 -07001419 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Benny Halevy13c65ce2009-08-14 17:19:25 +03001421 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001422 switch(arg->createmode) {
1423 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001424 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001425 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1426 arg->server, arg->server->attr_bitmask);
Andy Adamson05d564f2008-12-23 16:06:15 -05001427 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001428 case NFS4_CREATE_GUARDED:
1429 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001430 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1431 arg->server, arg->server->attr_bitmask);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001432 break;
1433 case NFS4_CREATE_EXCLUSIVE:
1434 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1435 encode_nfs4_verifier(xdr, &arg->u.verifier);
1436 break;
1437 case NFS4_CREATE_EXCLUSIVE4_1:
1438 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1439 encode_nfs4_verifier(xdr, &arg->u.verifier);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001440 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1441 arg->server, arg->server->exclcreat_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 }
1443}
1444
1445static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1446{
Al Viro8687b632006-10-19 23:28:48 -07001447 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Benny Halevy13c65ce2009-08-14 17:19:25 +03001449 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001451 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001452 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001453 break;
1454 default:
Benny Halevy34558512009-08-14 17:19:30 +03001455 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001456 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 }
1458}
1459
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001460static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461{
Al Viro8687b632006-10-19 23:28:48 -07001462 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Benny Halevy13c65ce2009-08-14 17:19:25 +03001464 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001466 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001467 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001468 break;
1469 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001470 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001471 break;
1472 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001473 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001474 break;
1475 default:
1476 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 }
1478}
1479
1480static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1481{
Al Viro8687b632006-10-19 23:28:48 -07001482 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Benny Halevy13c65ce2009-08-14 17:19:25 +03001484 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001485 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 encode_string(xdr, name->len, name->name);
1487}
1488
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001489static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490{
Al Viro8687b632006-10-19 23:28:48 -07001491 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
Benny Halevy13c65ce2009-08-14 17:19:25 +03001493 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001494 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 encode_delegation_type(xdr, type);
1496}
1497
1498static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1499{
Al Viro8687b632006-10-19 23:28:48 -07001500 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001502 p = reserve_space(xdr, 4);
1503 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1504 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 encode_string(xdr, name->len, name->name);
1506}
1507
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001508static inline void encode_claim_fh(struct xdr_stream *xdr)
1509{
1510 __be32 *p;
1511
1512 p = reserve_space(xdr, 4);
1513 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1514}
1515
1516static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1517{
1518 __be32 *p;
1519
1520 p = reserve_space(xdr, 4);
1521 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1522 encode_nfs4_stateid(xdr, stateid);
1523}
1524
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001525static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
Trond Myklebustab19b482012-03-04 18:13:57 -05001527 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 encode_openhdr(xdr, arg);
1529 encode_opentype(xdr, arg);
1530 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001531 case NFS4_OPEN_CLAIM_NULL:
1532 encode_claim_null(xdr, arg->name);
1533 break;
1534 case NFS4_OPEN_CLAIM_PREVIOUS:
1535 encode_claim_previous(xdr, arg->u.delegation_type);
1536 break;
1537 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1538 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1539 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001540 case NFS4_OPEN_CLAIM_FH:
1541 encode_claim_fh(xdr);
1542 break;
1543 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1544 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1545 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001546 default:
1547 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549}
1550
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001551static 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 -07001552{
Trond Myklebustab19b482012-03-04 18:13:57 -05001553 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001554 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001555 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556}
1557
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001558static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559{
Trond Myklebustab19b482012-03-04 18:13:57 -05001560 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001561 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001562 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001563 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564}
1565
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001566static void
Andy Adamsond0179312008-12-23 16:06:17 -05001567encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568{
Trond Myklebustab19b482012-03-04 18:13:57 -05001569 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001570 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571}
1572
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001573static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574{
Trond Myklebustab19b482012-03-04 18:13:57 -05001575 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
1577
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001578static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1579 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580{
Al Viro8687b632006-10-19 23:28:48 -07001581 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
Trond Myklebustab19b482012-03-04 18:13:57 -05001583 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001584 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
Benny Halevy13c65ce2009-08-14 17:19:25 +03001586 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001587 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001588 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589}
1590
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001591static 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 -07001592{
David Quigleyaa9c2662013-05-22 12:50:44 -04001593 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001594 FATTR4_WORD0_RDATTR_ERROR,
1595 FATTR4_WORD1_MOUNTED_ON_FILEID,
1596 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001597 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001598 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001599 uint32_t attrlen = 0;
1600 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001602 if (readdir->plus) {
1603 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001604 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001605 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1606 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1607 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1608 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001609 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001610 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001611 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001612 /* Use mounted_on_fileid only if the server supports it */
1613 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1614 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001615 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1616 attrs[i] &= readdir->bitmask[i];
1617 if (attrs[i] != 0)
1618 attrlen = i+1;
1619 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001620
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001621 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001622 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001623 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001624 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001625 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001626 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001627 *p++ = cpu_to_be32(attrlen);
1628 for (i = 0; i < attrlen; i++)
1629 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001630 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001631
1632 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001633 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001634 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001635 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001636 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001637 attrs[1] & readdir->bitmask[1],
1638 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639}
1640
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001641static 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 -07001642{
Trond Myklebustab19b482012-03-04 18:13:57 -05001643 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644}
1645
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001646static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647{
Trond Myklebustab19b482012-03-04 18:13:57 -05001648 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001649 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650}
1651
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001652static 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 -07001653{
Trond Myklebustab19b482012-03-04 18:13:57 -05001654 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001655 encode_string(xdr, oldname->len, oldname->name);
1656 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657}
1658
Chuck Leverbb4dae52012-03-01 17:01:48 -05001659static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1660 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001662 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001663 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664}
1665
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001666static void
Andy Adamsond0179312008-12-23 16:06:17 -05001667encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001668{
Trond Myklebustab19b482012-03-04 18:13:57 -05001669 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001670}
1671
Chuck Lever9f06c712010-12-14 14:59:18 +00001672static void
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001673encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1674 struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001675{
Al Viro8687b632006-10-19 23:28:48 -07001676 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001677
Trond Myklebustab19b482012-03-04 18:13:57 -05001678 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001679 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001680 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001681 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001682 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001683 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001684 *p = cpu_to_be32(arg->acl_len);
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01001685 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001686}
1687
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001688static void
Andy Adamsond0179312008-12-23 16:06:17 -05001689encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690{
Trond Myklebustab19b482012-03-04 18:13:57 -05001691 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692}
1693
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001694static 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 -07001695{
Trond Myklebustab19b482012-03-04 18:13:57 -05001696 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001697 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001698 encode_attrs(xdr, arg->iap, arg->label, NULL, server,
1699 server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700}
1701
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001702static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703{
Al Viro8687b632006-10-19 23:28:48 -07001704 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
Trond Myklebust70019512012-03-04 20:49:32 -05001706 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001707 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
Jeff Layton3a6bb732015-06-09 19:43:57 -04001709 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1710 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001711 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001712 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1714 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001715 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001716 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717}
1718
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001719static 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 -07001720{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001721 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1722 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001723 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001724 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725}
1726
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001727static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1728 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729{
Al Viro8687b632006-10-19 23:28:48 -07001730 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Trond Myklebustab19b482012-03-04 18:13:57 -05001732 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001733 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
Benny Halevy13c65ce2009-08-14 17:19:25 +03001735 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001736 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001737 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001738 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
1740 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741}
1742
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001743static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744{
Trond Myklebustab19b482012-03-04 18:13:57 -05001745 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001746 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001748
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001749static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1750{
Trond Myklebustab19b482012-03-04 18:13:57 -05001751 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001752 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001753}
1754
Benny Halevy99fe60d2009-04-01 09:22:29 -04001755#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001756/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001757static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001758 const struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001759 struct compound_hdr *hdr)
1760{
1761 __be32 *p;
1762
1763 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1764 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001765 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001766 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001767 *p++ = cpu_to_be32(args->dir);
1768 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001769}
1770
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001771static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001772{
1773 unsigned int i;
1774 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1775 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1776 encode_uint32(xdr, op_map->u.words[i]);
1777}
1778
Benny Halevy99fe60d2009-04-01 09:22:29 -04001779static void encode_exchange_id(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001780 const struct nfs41_exchange_id_args *args,
Benny Halevy99fe60d2009-04-01 09:22:29 -04001781 struct compound_hdr *hdr)
1782{
1783 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001784 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001785 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001786
Trond Myklebust70019512012-03-04 20:49:32 -05001787 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Trond Myklebustfd405592017-08-01 16:02:47 -04001788 encode_nfs4_verifier(xdr, &args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001789
Jeff Layton3a6bb732015-06-09 19:43:57 -04001790 encode_string(xdr, strlen(args->client->cl_owner_id),
1791 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001792
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001793 encode_uint32(xdr, args->flags);
1794 encode_uint32(xdr, args->state_protect.how);
1795
1796 switch (args->state_protect.how) {
1797 case SP4_NONE:
1798 break;
1799 case SP4_MACH_CRED:
1800 encode_op_map(xdr, &args->state_protect.enforce);
1801 encode_op_map(xdr, &args->state_protect.allow);
1802 break;
1803 default:
1804 WARN_ON_ONCE(1);
1805 break;
1806 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001807
1808 if (send_implementation_id &&
1809 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1810 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001811 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001812 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1813 utsname()->sysname, utsname()->release,
1814 utsname()->version, utsname()->machine);
1815
1816 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001817 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001818
1819 encode_string(xdr,
1820 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1821 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1822 encode_string(xdr, len, impl_name);
1823 /* just send zeros for nii_date - the date is in nii_name */
1824 p = reserve_space(xdr, 12);
1825 p = xdr_encode_hyper(p, 0);
1826 *p = cpu_to_be32(0);
1827 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001828 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001829}
Andy Adamsonfc931582009-04-01 09:22:31 -04001830
1831static void encode_create_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001832 const struct nfs41_create_session_args *args,
Andy Adamsonfc931582009-04-01 09:22:31 -04001833 struct compound_hdr *hdr)
1834{
1835 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001836 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001837 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001838 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001839 u32 max_resp_sz_cached;
1840
1841 /*
1842 * Assumes OPEN is the biggest non-idempotent compound.
1843 * 2 is the verifier.
1844 */
J. Bruce Fields35c036e2017-09-20 12:42:13 -04001845 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
1846 * XDR_UNIT + RPC_MAX_AUTH_SIZE;
Andy Adamsonfc931582009-04-01 09:22:31 -04001847
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001848 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001849 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001850 p = xdr_encode_hyper(p, args->clientid);
1851 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001852 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001853
Andy Adamsonfc931582009-04-01 09:22:31 -04001854 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001855 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001856 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1857 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001858 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001859 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1860 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1861 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001862
1863 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001864 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001865 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1866 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1867 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1868 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1869 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1870 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001871
Benny Halevye75bc1c2009-08-14 17:18:54 +03001872 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001873 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001874 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001875
1876 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001877 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001878 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001879 *p++ = cpu_to_be32(0); /* UID */
1880 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001881 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001882}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001883
1884static void encode_destroy_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001885 const struct nfs4_session *session,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001886 struct compound_hdr *hdr)
1887{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001888 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1889 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001890}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001891
Trond Myklebust66245532012-05-25 17:18:09 -04001892static void encode_destroy_clientid(struct xdr_stream *xdr,
1893 uint64_t clientid,
1894 struct compound_hdr *hdr)
1895{
1896 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1897 encode_uint64(xdr, clientid);
1898}
1899
Ricardo Labiaga180197532009-12-05 16:08:40 -05001900static void encode_reclaim_complete(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001901 const struct nfs41_reclaim_complete_args *args,
Ricardo Labiaga180197532009-12-05 16:08:40 -05001902 struct compound_hdr *hdr)
1903{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001904 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1905 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001906}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001907#endif /* CONFIG_NFS_V4_1 */
1908
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001909static void encode_sequence(struct xdr_stream *xdr,
1910 const struct nfs4_sequence_args *args,
1911 struct compound_hdr *hdr)
1912{
1913#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001914 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001915 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001916 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001917 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001918
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001919 tp = slot->table;
1920 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001921 if (!session)
1922 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001923
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001924 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001925
1926 /*
1927 * Sessionid + seqid + slotid + max slotid + cache_this
1928 */
1929 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1930 "max_slotid=%d cache_this=%d\n",
1931 __func__,
1932 ((u32 *)session->sess_id.data)[0],
1933 ((u32 *)session->sess_id.data)[1],
1934 ((u32 *)session->sess_id.data)[2],
1935 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001936 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001937 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001938 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001939 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001940 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001941 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001942 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001943 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001944#endif /* CONFIG_NFS_V4_1 */
1945}
1946
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001947#ifdef CONFIG_NFS_V4_1
1948static void
1949encode_getdeviceinfo(struct xdr_stream *xdr,
1950 const struct nfs4_getdeviceinfo_args *args,
1951 struct compound_hdr *hdr)
1952{
1953 __be32 *p;
1954
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001955 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001956 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001957 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1958 NFS4_DEVICEID4_SIZE);
1959 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001960 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001961
1962 p = reserve_space(xdr, 4 + 4);
1963 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001964 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001965}
1966
1967static void
1968encode_layoutget(struct xdr_stream *xdr,
1969 const struct nfs4_layoutget_args *args,
1970 struct compound_hdr *hdr)
1971{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001972 __be32 *p;
1973
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001974 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1975 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001976 *p++ = cpu_to_be32(0); /* Signal layout available */
1977 *p++ = cpu_to_be32(args->type);
1978 *p++ = cpu_to_be32(args->range.iomode);
1979 p = xdr_encode_hyper(p, args->range.offset);
1980 p = xdr_encode_hyper(p, args->range.length);
1981 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001982 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001983 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001984
1985 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1986 __func__,
1987 args->type,
1988 args->range.iomode,
1989 (unsigned long)args->range.offset,
1990 (unsigned long)args->range.length,
1991 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001992}
Andy Adamson863a3c62011-03-23 13:27:54 +00001993
1994static int
1995encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001996 struct inode *inode,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001997 const struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001998 struct compound_hdr *hdr)
1999{
2000 __be32 *p;
2001
2002 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2003 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2004
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002005 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2006 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00002007 /* Only whole file layouts */
2008 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002009 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002010 *p = cpu_to_be32(0); /* reclaim */
2011 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04002012 if (args->lastbytewritten != U64_MAX) {
2013 p = reserve_space(xdr, 20);
2014 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2015 p = xdr_encode_hyper(p, args->lastbytewritten);
2016 } else {
2017 p = reserve_space(xdr, 12);
2018 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2019 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002020 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2021 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002022
Trond Myklebust73504742017-04-20 16:48:14 -04002023 encode_uint32(xdr, args->layoutupdate_len);
2024 if (args->layoutupdate_pages)
2025 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2026 args->layoutupdate_len);
Andy Adamson863a3c62011-03-23 13:27:54 +00002027
Andy Adamson863a3c62011-03-23 13:27:54 +00002028 return 0;
2029}
Benny Halevycbe82602011-05-22 19:52:37 +03002030
2031static void
2032encode_layoutreturn(struct xdr_stream *xdr,
2033 const struct nfs4_layoutreturn_args *args,
2034 struct compound_hdr *hdr)
2035{
2036 __be32 *p;
2037
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002038 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2039 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002040 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2041 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002042 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002043 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002044 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002045 p = xdr_encode_hyper(p, args->range.offset);
2046 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002047 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002048 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002049 spin_unlock(&args->inode->i_lock);
Trond Myklebust4d796d72016-09-23 11:38:08 -04002050 if (args->ld_private->ops && args->ld_private->ops->encode)
2051 args->ld_private->ops->encode(xdr, args, args->ld_private);
Trond Myklebust94e5c572016-09-15 18:49:52 -04002052 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002053 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002054}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002055
2056static int
2057encode_secinfo_no_name(struct xdr_stream *xdr,
2058 const struct nfs41_secinfo_no_name_args *args,
2059 struct compound_hdr *hdr)
2060{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002061 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2062 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002063 return 0;
2064}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002065
2066static void encode_test_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002067 const struct nfs41_test_stateid_args *args,
Bryan Schumaker7d974792011-06-02 14:59:08 -04002068 struct compound_hdr *hdr)
2069{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002070 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2071 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002072 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002073}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002074
2075static void encode_free_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002076 const struct nfs41_free_stateid_args *args,
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002077 struct compound_hdr *hdr)
2078{
Trond Myklebustab19b482012-03-04 18:13:57 -05002079 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002080 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002081}
Trond Myklebustcf805162016-11-15 14:56:07 -05002082#else
2083static inline void
2084encode_layoutreturn(struct xdr_stream *xdr,
2085 const struct nfs4_layoutreturn_args *args,
2086 struct compound_hdr *hdr)
2087{
2088}
Fred Isaman56f487f2016-09-21 11:43:41 -04002089
2090static void
2091encode_layoutget(struct xdr_stream *xdr,
2092 const struct nfs4_layoutget_args *args,
2093 struct compound_hdr *hdr)
2094{
2095}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002096#endif /* CONFIG_NFS_V4_1 */
2097
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098/*
2099 * END OF "GENERIC" ENCODE ROUTINES.
2100 */
2101
Benny Halevy66cc0422009-04-01 09:22:10 -04002102static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2103{
2104#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002105 struct nfs4_session *session = args->sa_slot->table->session;
2106 if (session)
2107 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002108#endif /* CONFIG_NFS_V4_1 */
2109 return 0;
2110}
2111
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112/*
2113 * Encode an ACCESS request
2114 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002115static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002116 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002118 const struct nfs4_accessargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002120 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122
Chuck Lever9f06c712010-12-14 14:59:18 +00002123 encode_compound_hdr(xdr, req, &hdr);
2124 encode_sequence(xdr, &args->seq_args, &hdr);
2125 encode_putfh(xdr, args->fh, &hdr);
2126 encode_access(xdr, args->access, &hdr);
Trond Myklebust8bcbe7d2018-03-20 17:03:11 -04002127 if (args->bitmask)
2128 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002129 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130}
2131
2132/*
2133 * Encode LOOKUP request
2134 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002135static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002136 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002138 const struct nfs4_lookup_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002140 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
Chuck Lever9f06c712010-12-14 14:59:18 +00002143 encode_compound_hdr(xdr, req, &hdr);
2144 encode_sequence(xdr, &args->seq_args, &hdr);
2145 encode_putfh(xdr, args->dir_fh, &hdr);
2146 encode_lookup(xdr, args->name, &hdr);
2147 encode_getfh(xdr, &hdr);
2148 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002149 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150}
2151
2152/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07002153 * Encode LOOKUPP request
2154 */
2155static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
2156 const void *data)
2157{
2158 const struct nfs4_lookupp_arg *args = data;
2159 struct compound_hdr hdr = {
2160 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2161 };
2162
2163 encode_compound_hdr(xdr, req, &hdr);
2164 encode_sequence(xdr, &args->seq_args, &hdr);
2165 encode_putfh(xdr, args->fh, &hdr);
2166 encode_lookupp(xdr, &hdr);
2167 encode_getfh(xdr, &hdr);
2168 encode_getfattr(xdr, args->bitmask, &hdr);
2169 encode_nops(&hdr);
2170}
2171
2172/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 * Encode LOOKUP_ROOT request
2174 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002175static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2176 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002177 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002179 const struct nfs4_lookup_root_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002181 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183
Chuck Lever9f06c712010-12-14 14:59:18 +00002184 encode_compound_hdr(xdr, req, &hdr);
2185 encode_sequence(xdr, &args->seq_args, &hdr);
2186 encode_putrootfh(xdr, &hdr);
2187 encode_getfh(xdr, &hdr);
2188 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002189 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190}
2191
2192/*
2193 * Encode REMOVE request
2194 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002195static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002196 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002198 const struct nfs_removeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002200 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
Chuck Lever9f06c712010-12-14 14:59:18 +00002203 encode_compound_hdr(xdr, req, &hdr);
2204 encode_sequence(xdr, &args->seq_args, &hdr);
2205 encode_putfh(xdr, args->fh, &hdr);
2206 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002207 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208}
2209
2210/*
2211 * Encode RENAME request
2212 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002213static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002214 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002216 const struct nfs_renameargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002218 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
Chuck Lever9f06c712010-12-14 14:59:18 +00002221 encode_compound_hdr(xdr, req, &hdr);
2222 encode_sequence(xdr, &args->seq_args, &hdr);
2223 encode_putfh(xdr, args->old_dir, &hdr);
2224 encode_savefh(xdr, &hdr);
2225 encode_putfh(xdr, args->new_dir, &hdr);
2226 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002227 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228}
2229
2230/*
2231 * Encode LINK request
2232 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002233static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002234 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002236 const struct nfs4_link_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002238 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
Chuck Lever9f06c712010-12-14 14:59:18 +00002241 encode_compound_hdr(xdr, req, &hdr);
2242 encode_sequence(xdr, &args->seq_args, &hdr);
2243 encode_putfh(xdr, args->fh, &hdr);
2244 encode_savefh(xdr, &hdr);
2245 encode_putfh(xdr, args->dir_fh, &hdr);
2246 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002247 encode_restorefh(xdr, &hdr);
2248 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002249 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250}
2251
2252/*
2253 * Encode CREATE request
2254 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002255static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002256 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002258 const struct nfs4_create_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002260 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
Chuck Lever9f06c712010-12-14 14:59:18 +00002263 encode_compound_hdr(xdr, req, &hdr);
2264 encode_sequence(xdr, &args->seq_args, &hdr);
2265 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002266 encode_create(xdr, args, &hdr);
2267 encode_getfh(xdr, &hdr);
2268 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002269 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270}
2271
2272/*
2273 * Encode SYMLINK request
2274 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002275static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002276 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002278 const struct nfs4_create_arg *args = data;
2279
Chuck Lever9f06c712010-12-14 14:59:18 +00002280 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281}
2282
2283/*
2284 * Encode GETATTR request
2285 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002286static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002287 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002289 const struct nfs4_getattr_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002291 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293
Chuck Lever9f06c712010-12-14 14:59:18 +00002294 encode_compound_hdr(xdr, req, &hdr);
2295 encode_sequence(xdr, &args->seq_args, &hdr);
2296 encode_putfh(xdr, args->fh, &hdr);
2297 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002298 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299}
2300
2301/*
2302 * Encode a CLOSE request
2303 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002304static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002305 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002307 const struct nfs_closeargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002308 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002309 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002310 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
Chuck Lever9f06c712010-12-14 14:59:18 +00002312 encode_compound_hdr(xdr, req, &hdr);
2313 encode_sequence(xdr, &args->seq_args, &hdr);
2314 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002315 if (args->lr_args)
2316 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002317 if (args->bitmask != NULL)
2318 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebustd8d84982016-12-19 12:14:44 -05002319 encode_close(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002320 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321}
2322
2323/*
2324 * Encode an OPEN request
2325 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002326static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002327 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002329 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002331 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
Chuck Lever9f06c712010-12-14 14:59:18 +00002334 encode_compound_hdr(xdr, req, &hdr);
2335 encode_sequence(xdr, &args->seq_args, &hdr);
2336 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002337 encode_open(xdr, args, &hdr);
2338 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002339 if (args->access)
2340 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002341 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Fred Isaman56f487f2016-09-21 11:43:41 -04002342 if (args->lg_args) {
2343 encode_layoutget(xdr, args->lg_args, &hdr);
Chuck Levercf500ba2019-02-11 11:25:20 -05002344 rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2345 args->lg_args->layout.pglen,
2346 hdr.replen);
Fred Isaman56f487f2016-09-21 11:43:41 -04002347 }
Andy Adamsond0179312008-12-23 16:06:17 -05002348 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349}
2350
2351/*
2352 * Encode an OPEN_CONFIRM request
2353 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002354static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2355 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002356 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002358 const struct nfs_open_confirmargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002360 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
Chuck Lever9f06c712010-12-14 14:59:18 +00002363 encode_compound_hdr(xdr, req, &hdr);
2364 encode_putfh(xdr, args->fh, &hdr);
2365 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002366 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367}
2368
2369/*
2370 * Encode an OPEN request with no attributes.
2371 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002372static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2373 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002374 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002376 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002378 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380
Chuck Lever9f06c712010-12-14 14:59:18 +00002381 encode_compound_hdr(xdr, req, &hdr);
2382 encode_sequence(xdr, &args->seq_args, &hdr);
2383 encode_putfh(xdr, args->fh, &hdr);
2384 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002385 if (args->access)
2386 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002387 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Fred Isaman56f487f2016-09-21 11:43:41 -04002388 if (args->lg_args) {
2389 encode_layoutget(xdr, args->lg_args, &hdr);
Chuck Levercf500ba2019-02-11 11:25:20 -05002390 rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2391 args->lg_args->layout.pglen,
2392 hdr.replen);
Fred Isaman56f487f2016-09-21 11:43:41 -04002393 }
Andy Adamsond0179312008-12-23 16:06:17 -05002394 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395}
2396
2397/*
2398 * Encode an OPEN_DOWNGRADE request
2399 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002400static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2401 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002402 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002404 const struct nfs_closeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002406 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408
Chuck Lever9f06c712010-12-14 14:59:18 +00002409 encode_compound_hdr(xdr, req, &hdr);
2410 encode_sequence(xdr, &args->seq_args, &hdr);
2411 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustb6808142016-11-20 13:34:16 -05002412 if (args->lr_args)
2413 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002414 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002415 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416}
2417
2418/*
2419 * Encode a LOCK request
2420 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002421static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002422 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002424 const struct nfs_lock_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002426 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
Chuck Lever9f06c712010-12-14 14:59:18 +00002429 encode_compound_hdr(xdr, req, &hdr);
2430 encode_sequence(xdr, &args->seq_args, &hdr);
2431 encode_putfh(xdr, args->fh, &hdr);
2432 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002433 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434}
2435
2436/*
2437 * Encode a LOCKT request
2438 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002439static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002440 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002442 const struct nfs_lockt_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002444 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446
Chuck Lever9f06c712010-12-14 14:59:18 +00002447 encode_compound_hdr(xdr, req, &hdr);
2448 encode_sequence(xdr, &args->seq_args, &hdr);
2449 encode_putfh(xdr, args->fh, &hdr);
2450 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002451 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452}
2453
2454/*
2455 * Encode a LOCKU request
2456 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002457static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002458 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002460 const struct nfs_locku_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002462 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464
Chuck Lever9f06c712010-12-14 14:59:18 +00002465 encode_compound_hdr(xdr, req, &hdr);
2466 encode_sequence(xdr, &args->seq_args, &hdr);
2467 encode_putfh(xdr, args->fh, &hdr);
2468 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002469 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470}
2471
Chuck Lever9f06c712010-12-14 14:59:18 +00002472static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2473 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002474 const void *data)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002475{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002476 const struct nfs_release_lockowner_args *args = data;
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002477 struct compound_hdr hdr = {
2478 .minorversion = 0,
2479 };
2480
Chuck Lever9f06c712010-12-14 14:59:18 +00002481 encode_compound_hdr(xdr, req, &hdr);
2482 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002483 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002484}
2485
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486/*
2487 * Encode a READLINK request
2488 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002489static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002490 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002492 const struct nfs4_readlink *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002494 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496
Chuck Lever9f06c712010-12-14 14:59:18 +00002497 encode_compound_hdr(xdr, req, &hdr);
2498 encode_sequence(xdr, &args->seq_args, &hdr);
2499 encode_putfh(xdr, args->fh, &hdr);
2500 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002501
Chuck Levercf500ba2019-02-11 11:25:20 -05002502 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2503 args->pglen, hdr.replen);
Andy Adamsond0179312008-12-23 16:06:17 -05002504 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505}
2506
2507/*
2508 * Encode a READDIR request
2509 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002510static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002511 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002513 const struct nfs4_readdir_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002515 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517
Chuck Lever9f06c712010-12-14 14:59:18 +00002518 encode_compound_hdr(xdr, req, &hdr);
2519 encode_sequence(xdr, &args->seq_args, &hdr);
2520 encode_putfh(xdr, args->fh, &hdr);
2521 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002522
Chuck Levercf500ba2019-02-11 11:25:20 -05002523 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2524 args->count, hdr.replen);
Andy Adamsond0179312008-12-23 16:06:17 -05002525 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526}
2527
2528/*
2529 * Encode a READ request
2530 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002531static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002532 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002534 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002536 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538
Chuck Lever9f06c712010-12-14 14:59:18 +00002539 encode_compound_hdr(xdr, req, &hdr);
2540 encode_sequence(xdr, &args->seq_args, &hdr);
2541 encode_putfh(xdr, args->fh, &hdr);
2542 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543
Chuck Levercf500ba2019-02-11 11:25:20 -05002544 rpc_prepare_reply_pages(req, args->pages, args->pgbase,
2545 args->count, hdr.replen);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002546 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002547 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548}
2549
2550/*
2551 * Encode an SETATTR request
2552 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002553static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002554 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002556 const struct nfs_setattrargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002557 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002558 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002559 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560
Chuck Lever9f06c712010-12-14 14:59:18 +00002561 encode_compound_hdr(xdr, req, &hdr);
2562 encode_sequence(xdr, &args->seq_args, &hdr);
2563 encode_putfh(xdr, args->fh, &hdr);
2564 encode_setattr(xdr, args, args->server, &hdr);
2565 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002566 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567}
2568
2569/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002570 * Encode a GETACL request
2571 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002572static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002573 const void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002574{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002575 const struct nfs_getaclargs *args = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002576 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002577 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002578 };
Trond Myklebust37c88762018-03-20 17:03:08 -04002579 const __u32 nfs4_acl_bitmap[1] = {
2580 [0] = FATTR4_WORD0_ACL,
2581 };
Benny Halevy28f56692009-04-01 09:22:09 -04002582 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002583
Chuck Lever9f06c712010-12-14 14:59:18 +00002584 encode_compound_hdr(xdr, req, &hdr);
2585 encode_sequence(xdr, &args->seq_args, &hdr);
2586 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fields6682c142017-02-23 14:53:39 -05002587 replen = hdr.replen + op_decode_hdr_maxsz;
Trond Myklebust37c88762018-03-20 17:03:08 -04002588 encode_getattr(xdr, nfs4_acl_bitmap, NULL,
2589 ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002590
Chuck Levercf500ba2019-02-11 11:25:20 -05002591 rpc_prepare_reply_pages(req, args->acl_pages, 0,
2592 args->acl_len, replen);
Andy Adamsond0179312008-12-23 16:06:17 -05002593 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002594}
2595
2596/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 * Encode a WRITE request
2598 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002599static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002600 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002602 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002604 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606
Chuck Lever9f06c712010-12-14 14:59:18 +00002607 encode_compound_hdr(xdr, req, &hdr);
2608 encode_sequence(xdr, &args->seq_args, &hdr);
2609 encode_putfh(xdr, args->fh, &hdr);
2610 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002611 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002612 if (args->bitmask)
2613 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002614 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615}
2616
2617/*
2618 * a COMMIT request
2619 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002620static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002621 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002623 const struct nfs_commitargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002625 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627
Chuck Lever9f06c712010-12-14 14:59:18 +00002628 encode_compound_hdr(xdr, req, &hdr);
2629 encode_sequence(xdr, &args->seq_args, &hdr);
2630 encode_putfh(xdr, args->fh, &hdr);
2631 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002632 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633}
2634
2635/*
2636 * FSINFO request
2637 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002638static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002639 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002641 const struct nfs4_fsinfo_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002643 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645
Chuck Lever9f06c712010-12-14 14:59:18 +00002646 encode_compound_hdr(xdr, req, &hdr);
2647 encode_sequence(xdr, &args->seq_args, &hdr);
2648 encode_putfh(xdr, args->fh, &hdr);
2649 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002650 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651}
2652
2653/*
2654 * a PATHCONF request
2655 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002656static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002657 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002659 const struct nfs4_pathconf_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002661 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
Chuck Lever9f06c712010-12-14 14:59:18 +00002664 encode_compound_hdr(xdr, req, &hdr);
2665 encode_sequence(xdr, &args->seq_args, &hdr);
2666 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002667 encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
2668 ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002669 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670}
2671
2672/*
2673 * a STATFS request
2674 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002675static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002676 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002678 const struct nfs4_statfs_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002680 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
Chuck Lever9f06c712010-12-14 14:59:18 +00002683 encode_compound_hdr(xdr, req, &hdr);
2684 encode_sequence(xdr, &args->seq_args, &hdr);
2685 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002686 encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
2687 ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002688 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689}
2690
2691/*
2692 * GETATTR_BITMAP request
2693 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002694static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2695 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002696 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002698 const struct nfs4_server_caps_arg *args = data;
Kinglong Mee8c612822015-08-26 21:12:58 +08002699 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002701 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703
Chuck Lever9f06c712010-12-14 14:59:18 +00002704 encode_compound_hdr(xdr, req, &hdr);
2705 encode_sequence(xdr, &args->seq_args, &hdr);
2706 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002707 encode_getattr(xdr, bitmask, NULL, 3, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002708 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709}
2710
2711/*
2712 * a RENEW request
2713 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002714static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002715 const void *data)
2716
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002718 const struct nfs_client *clp = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002720 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 };
2722
Chuck Lever9f06c712010-12-14 14:59:18 +00002723 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002724 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002725 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726}
2727
2728/*
2729 * a SETCLIENTID request
2730 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002731static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2732 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002733 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002735 const struct nfs4_setclientid *sc = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002737 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 };
2739
Chuck Lever9f06c712010-12-14 14:59:18 +00002740 encode_compound_hdr(xdr, req, &hdr);
2741 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002742 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743}
2744
2745/*
2746 * a SETCLIENTID_CONFIRM request
2747 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002748static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2749 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002750 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002752 const struct nfs4_setclientid_res *arg = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002754 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756
Chuck Lever9f06c712010-12-14 14:59:18 +00002757 encode_compound_hdr(xdr, req, &hdr);
2758 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002759 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760}
2761
2762/*
2763 * DELEGRETURN request
2764 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002765static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2766 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002767 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002769 const struct nfs4_delegreturnargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002771 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773
Chuck Lever9f06c712010-12-14 14:59:18 +00002774 encode_compound_hdr(xdr, req, &hdr);
2775 encode_sequence(xdr, &args->seq_args, &hdr);
2776 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust586f1c32016-11-15 15:03:33 -05002777 if (args->lr_args)
2778 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05002779 if (args->bitmask)
2780 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002781 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002782 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783}
2784
2785/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002786 * Encode FS_LOCATIONS request
2787 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002788static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2789 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002790 const void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002791{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002792 const struct nfs4_fs_locations_arg *args = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002793 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002794 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002795 };
Benny Halevy28f56692009-04-01 09:22:09 -04002796 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002797
Chuck Lever9f06c712010-12-14 14:59:18 +00002798 encode_compound_hdr(xdr, req, &hdr);
2799 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002800 if (args->migration) {
2801 encode_putfh(xdr, args->fh, &hdr);
2802 replen = hdr.replen;
2803 encode_fs_locations(xdr, args->bitmask, &hdr);
2804 if (args->renew)
2805 encode_renew(xdr, args->clientid, &hdr);
2806 } else {
2807 encode_putfh(xdr, args->dir_fh, &hdr);
2808 encode_lookup(xdr, args->name, &hdr);
2809 replen = hdr.replen;
2810 encode_fs_locations(xdr, args->bitmask, &hdr);
2811 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002812
Chuck Levercf500ba2019-02-11 11:25:20 -05002813 rpc_prepare_reply_pages(req, (struct page **)&args->page, 0,
2814 PAGE_SIZE, replen);
Andy Adamsond0179312008-12-23 16:06:17 -05002815 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002816}
2817
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002818/*
2819 * Encode SECINFO request
2820 */
2821static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2822 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002823 const void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002824{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002825 const struct nfs4_secinfo_arg *args = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002826 struct compound_hdr hdr = {
2827 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2828 };
2829
2830 encode_compound_hdr(xdr, req, &hdr);
2831 encode_sequence(xdr, &args->seq_args, &hdr);
2832 encode_putfh(xdr, args->dir_fh, &hdr);
2833 encode_secinfo(xdr, args->name, &hdr);
2834 encode_nops(&hdr);
2835}
2836
Chuck Lever44c99932013-10-17 14:13:30 -04002837/*
2838 * Encode FSID_PRESENT request
2839 */
2840static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2841 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002842 const void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04002843{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002844 const struct nfs4_fsid_present_arg *args = data;
Chuck Lever44c99932013-10-17 14:13:30 -04002845 struct compound_hdr hdr = {
2846 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2847 };
2848
2849 encode_compound_hdr(xdr, req, &hdr);
2850 encode_sequence(xdr, &args->seq_args, &hdr);
2851 encode_putfh(xdr, args->fh, &hdr);
2852 encode_getfh(xdr, &hdr);
2853 if (args->renew)
2854 encode_renew(xdr, args->clientid, &hdr);
2855 encode_nops(&hdr);
2856}
2857
Benny Halevy99fe60d2009-04-01 09:22:29 -04002858#if defined(CONFIG_NFS_V4_1)
2859/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002860 * BIND_CONN_TO_SESSION request
2861 */
2862static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2863 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002864 const void *data)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002865{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002866 const struct nfs41_bind_conn_to_session_args *args = data;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002867 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002868 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002869 };
2870
2871 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002872 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002873 encode_nops(&hdr);
2874}
2875
2876/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002877 * EXCHANGE_ID request
2878 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002879static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2880 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002881 const void *data)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002882{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002883 const struct nfs41_exchange_id_args *args = data;
Benny Halevy99fe60d2009-04-01 09:22:29 -04002884 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002885 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002886 };
2887
Chuck Lever9f06c712010-12-14 14:59:18 +00002888 encode_compound_hdr(xdr, req, &hdr);
2889 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002890 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002891}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002892
2893/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002894 * a CREATE_SESSION request
2895 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002896static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2897 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002898 const void *data)
Andy Adamsonfc931582009-04-01 09:22:31 -04002899{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002900 const struct nfs41_create_session_args *args = data;
Andy Adamsonfc931582009-04-01 09:22:31 -04002901 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002902 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002903 };
2904
Chuck Lever9f06c712010-12-14 14:59:18 +00002905 encode_compound_hdr(xdr, req, &hdr);
2906 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002907 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002908}
2909
2910/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002911 * a DESTROY_SESSION request
2912 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002913static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2914 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002915 const void *data)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002916{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002917 const struct nfs4_session *session = data;
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002918 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002919 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002920 };
2921
Chuck Lever9f06c712010-12-14 14:59:18 +00002922 encode_compound_hdr(xdr, req, &hdr);
2923 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002924 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002925}
2926
2927/*
Trond Myklebust66245532012-05-25 17:18:09 -04002928 * a DESTROY_CLIENTID request
2929 */
2930static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2931 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002932 const void *data)
Trond Myklebust66245532012-05-25 17:18:09 -04002933{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002934 const struct nfs_client *clp = data;
Trond Myklebust66245532012-05-25 17:18:09 -04002935 struct compound_hdr hdr = {
2936 .minorversion = clp->cl_mvops->minor_version,
2937 };
2938
2939 encode_compound_hdr(xdr, req, &hdr);
2940 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2941 encode_nops(&hdr);
2942}
2943
2944/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002945 * a SEQUENCE request
2946 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002947static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002948 const void *data)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002949{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002950 const struct nfs4_sequence_args *args = data;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002951 struct compound_hdr hdr = {
2952 .minorversion = nfs4_xdr_minorversion(args),
2953 };
2954
Chuck Lever9f06c712010-12-14 14:59:18 +00002955 encode_compound_hdr(xdr, req, &hdr);
2956 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002957 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002958}
2959
2960/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002961 * a GET_LEASE_TIME request
2962 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002963static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2964 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002965 const void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002966{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002967 const struct nfs4_get_lease_time_args *args = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04002968 struct compound_hdr hdr = {
2969 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2970 };
Fred Isamandae100c2011-07-30 20:52:37 -04002971 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002972
Chuck Lever9f06c712010-12-14 14:59:18 +00002973 encode_compound_hdr(xdr, req, &hdr);
2974 encode_sequence(xdr, &args->la_seq_args, &hdr);
2975 encode_putrootfh(xdr, &hdr);
2976 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002977 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002978}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002979
2980/*
2981 * a RECLAIM_COMPLETE request
2982 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002983static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2984 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002985 const void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002986{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002987 const struct nfs41_reclaim_complete_args *args = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05002988 struct compound_hdr hdr = {
2989 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2990 };
2991
Chuck Lever9f06c712010-12-14 14:59:18 +00002992 encode_compound_hdr(xdr, req, &hdr);
2993 encode_sequence(xdr, &args->seq_args, &hdr);
2994 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002995 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002996}
2997
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002998/*
2999 * Encode GETDEVICEINFO request
3000 */
Chuck Lever9f06c712010-12-14 14:59:18 +00003001static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
3002 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003003 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003004{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003005 const struct nfs4_getdeviceinfo_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003006 struct compound_hdr hdr = {
3007 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3008 };
3009
Chuck Lever9f06c712010-12-14 14:59:18 +00003010 encode_compound_hdr(xdr, req, &hdr);
3011 encode_sequence(xdr, &args->seq_args, &hdr);
3012 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003013
3014 /* set up reply kvec. Subtract notification bitmap max size (2)
3015 * so that notification bitmap is put in xdr_buf tail */
Chuck Levercf500ba2019-02-11 11:25:20 -05003016 rpc_prepare_reply_pages(req, args->pdev->pages, args->pdev->pgbase,
3017 args->pdev->pglen, hdr.replen - 2);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003018 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003019}
3020
3021/*
3022 * Encode LAYOUTGET request
3023 */
Chuck Lever9f06c712010-12-14 14:59:18 +00003024static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
3025 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003026 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003027{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003028 const struct nfs4_layoutget_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003029 struct compound_hdr hdr = {
3030 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3031 };
3032
Chuck Lever9f06c712010-12-14 14:59:18 +00003033 encode_compound_hdr(xdr, req, &hdr);
3034 encode_sequence(xdr, &args->seq_args, &hdr);
3035 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3036 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04003037
Chuck Levercf500ba2019-02-11 11:25:20 -05003038 rpc_prepare_reply_pages(req, args->layout.pages, 0,
3039 args->layout.pglen, hdr.replen);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003040 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003041}
Andy Adamson863a3c62011-03-23 13:27:54 +00003042
3043/*
3044 * Encode LAYOUTCOMMIT request
3045 */
Benny Halevycbe82602011-05-22 19:52:37 +03003046static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3047 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003048 const void *priv)
Andy Adamson863a3c62011-03-23 13:27:54 +00003049{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003050 const struct nfs4_layoutcommit_args *args = priv;
Benny Halevyac7db722011-05-22 19:53:48 +03003051 struct nfs4_layoutcommit_data *data =
3052 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00003053 struct compound_hdr hdr = {
3054 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3055 };
3056
3057 encode_compound_hdr(xdr, req, &hdr);
3058 encode_sequence(xdr, &args->seq_args, &hdr);
3059 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03003060 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003061 encode_getfattr(xdr, args->bitmask, &hdr);
3062 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03003063}
3064
3065/*
3066 * Encode LAYOUTRETURN request
3067 */
3068static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3069 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003070 const void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03003071{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003072 const struct nfs4_layoutreturn_args *args = data;
Benny Halevycbe82602011-05-22 19:52:37 +03003073 struct compound_hdr hdr = {
3074 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3075 };
3076
3077 encode_compound_hdr(xdr, req, &hdr);
3078 encode_sequence(xdr, &args->seq_args, &hdr);
3079 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3080 encode_layoutreturn(xdr, args, &hdr);
3081 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003082}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003083
3084/*
3085 * Encode SECINFO_NO_NAME request
3086 */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003087static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003088 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003089 const void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003090{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003091 const struct nfs41_secinfo_no_name_args *args = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003092 struct compound_hdr hdr = {
3093 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3094 };
3095
3096 encode_compound_hdr(xdr, req, &hdr);
3097 encode_sequence(xdr, &args->seq_args, &hdr);
3098 encode_putrootfh(xdr, &hdr);
3099 encode_secinfo_no_name(xdr, args, &hdr);
3100 encode_nops(&hdr);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003101}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003102
3103/*
3104 * Encode TEST_STATEID request
3105 */
3106static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3107 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003108 const void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04003109{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003110 const struct nfs41_test_stateid_args *args = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04003111 struct compound_hdr hdr = {
3112 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3113 };
3114
3115 encode_compound_hdr(xdr, req, &hdr);
3116 encode_sequence(xdr, &args->seq_args, &hdr);
3117 encode_test_stateid(xdr, args, &hdr);
3118 encode_nops(&hdr);
3119}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003120
3121/*
3122 * Encode FREE_STATEID request
3123 */
3124static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3125 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003126 const void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003127{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003128 const struct nfs41_free_stateid_args *args = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003129 struct compound_hdr hdr = {
3130 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3131 };
3132
3133 encode_compound_hdr(xdr, req, &hdr);
3134 encode_sequence(xdr, &args->seq_args, &hdr);
3135 encode_free_stateid(xdr, args, &hdr);
3136 encode_nops(&hdr);
3137}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003138#endif /* CONFIG_NFS_V4_1 */
3139
Trond Myklebust683b57b2006-06-09 09:34:22 -04003140static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141{
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003142 ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3143 NFS4_OPAQUE_LIMIT);
Chuck Levereb72f482019-02-11 11:24:21 -05003144 if (unlikely(ret < 0))
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003145 return -EIO;
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003146 *len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 return 0;
3148}
3149
3150static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3151{
Al Viro8687b632006-10-19 23:28:48 -07003152 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153
Benny Halevyc0eae662009-08-14 17:20:14 +03003154 p = xdr_inline_decode(xdr, 8);
3155 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003156 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03003157 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003158 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003159
Benny Halevyc0eae662009-08-14 17:20:14 +03003160 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3161 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003162 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 hdr->tag = (char *)p;
3164 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003165 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003166 if (unlikely(hdr->nops < 1))
3167 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 return 0;
3169}
3170
Trond Myklebustc7848f62013-12-04 17:39:23 -05003171static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3172 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173{
Al Viro8687b632006-10-19 23:28:48 -07003174 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 uint32_t opnum;
3176 int32_t nfserr;
3177
Benny Halevyc0eae662009-08-14 17:20:14 +03003178 p = xdr_inline_decode(xdr, 8);
3179 if (unlikely(!p))
3180 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003181 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003182 if (unlikely(opnum != expected))
3183 goto out_bad_operation;
Chuck Leverf23f6582019-02-11 11:24:26 -05003184 if (unlikely(*p != cpu_to_be32(NFS_OK)))
3185 goto out_status;
3186 *nfs_retval = 0;
3187 return true;
3188out_status:
Benny Halevycccddf42009-08-14 17:20:19 +03003189 nfserr = be32_to_cpup(p);
Chuck Leverf23f6582019-02-11 11:24:26 -05003190 trace_nfs4_xdr_status(opnum, nfserr);
3191 *nfs_retval = nfs4_stat_to_errno(nfserr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003192 return true;
3193out_bad_operation:
3194 dprintk("nfs: Server returned operation"
3195 " %d but we issued a request for %d\n",
3196 opnum, expected);
3197 *nfs_retval = -EREMOTEIO;
3198 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003199out_overflow:
Trond Myklebustc7848f62013-12-04 17:39:23 -05003200 *nfs_retval = -EIO;
3201 return false;
3202}
3203
3204static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3205{
3206 int retval;
3207
3208 __decode_op_hdr(xdr, expected, &retval);
3209 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210}
3211
3212/* Dummy routine */
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05003213static int decode_ace(struct xdr_stream *xdr, void *ace)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214{
Al Viro8687b632006-10-19 23:28:48 -07003215 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003216 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 char *str;
3218
Benny Halevyc0eae662009-08-14 17:20:14 +03003219 p = xdr_inline_decode(xdr, 12);
Chuck Levereb72f482019-02-11 11:24:21 -05003220 if (unlikely(!p))
3221 return -EIO;
3222 return decode_opaque_inline(xdr, &strlen, &str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223}
3224
Trond Myklebust37c88762018-03-20 17:03:08 -04003225static ssize_t
3226decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227{
Trond Myklebust37c88762018-03-20 17:03:08 -04003228 ssize_t ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229
Trond Myklebust37c88762018-03-20 17:03:08 -04003230 ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
3231 if (likely(ret >= 0))
3232 return ret;
Chuck Levereb72f482019-02-11 11:24:21 -05003233 if (ret != -EMSGSIZE)
3234 return -EIO;
3235 return sz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236}
3237
Trond Myklebust37c88762018-03-20 17:03:08 -04003238static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3239{
3240 ssize_t ret;
3241 ret = decode_bitmap4(xdr, bitmap, 3);
3242 return ret < 0 ? ret : 0;
3243}
3244
Trond Myklebust256e48b2012-06-21 11:18:13 -04003245static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246{
Al Viro8687b632006-10-19 23:28:48 -07003247 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248
Benny Halevyc0eae662009-08-14 17:20:14 +03003249 p = xdr_inline_decode(xdr, 4);
3250 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003251 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003252 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003253 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 return 0;
3255}
3256
3257static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3258{
3259 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003260 int ret;
3261 ret = decode_attr_bitmap(xdr, bitmask);
3262 if (unlikely(ret < 0))
3263 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3265 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003266 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3267 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3268 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 return 0;
3270}
3271
3272static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3273{
Al Viro8687b632006-10-19 23:28:48 -07003274 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003275 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276
3277 *type = 0;
3278 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3279 return -EIO;
3280 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003281 p = xdr_inline_decode(xdr, 4);
3282 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003283 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003284 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003286 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287 return -EIO;
3288 }
3289 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003290 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003292 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003293 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294}
3295
Chuck Lever264e6352012-03-01 17:02:05 -05003296static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3297 uint32_t *bitmap, uint32_t *type)
3298{
3299 __be32 *p;
3300
3301 *type = 0;
3302 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3303 return -EIO;
3304 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3305 p = xdr_inline_decode(xdr, 4);
3306 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003307 return -EIO;
Chuck Lever264e6352012-03-01 17:02:05 -05003308 *type = be32_to_cpup(p);
3309 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3310 }
3311 dprintk("%s: expire type=0x%x\n", __func__, *type);
3312 return 0;
Chuck Lever264e6352012-03-01 17:02:05 -05003313}
3314
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3316{
Al Viro8687b632006-10-19 23:28:48 -07003317 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003318 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319
3320 *change = 0;
3321 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3322 return -EIO;
3323 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003324 p = xdr_inline_decode(xdr, 8);
3325 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003326 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003327 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003329 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003331 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003333 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334}
3335
3336static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3337{
Al Viro8687b632006-10-19 23:28:48 -07003338 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003339 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340
3341 *size = 0;
3342 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3343 return -EIO;
3344 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003345 p = xdr_inline_decode(xdr, 8);
3346 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003347 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003348 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003350 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003352 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003353 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354}
3355
3356static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3357{
Al Viro8687b632006-10-19 23:28:48 -07003358 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359
3360 *res = 0;
3361 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3362 return -EIO;
3363 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003364 p = xdr_inline_decode(xdr, 4);
3365 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003366 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003367 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3369 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003370 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 return 0;
3372}
3373
3374static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3375{
Al Viro8687b632006-10-19 23:28:48 -07003376 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377
3378 *res = 0;
3379 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3380 return -EIO;
3381 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003382 p = xdr_inline_decode(xdr, 4);
3383 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003384 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003385 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3387 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003388 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 return 0;
3390}
3391
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003392static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393{
Al Viro8687b632006-10-19 23:28:48 -07003394 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003395 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396
3397 fsid->major = 0;
3398 fsid->minor = 0;
3399 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3400 return -EIO;
3401 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003402 p = xdr_inline_decode(xdr, 16);
3403 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003404 return -EIO;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003405 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003406 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003408 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003410 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 (unsigned long long)fsid->major,
3412 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003413 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414}
3415
3416static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3417{
Al Viro8687b632006-10-19 23:28:48 -07003418 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419
3420 *res = 60;
3421 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3422 return -EIO;
3423 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003424 p = xdr_inline_decode(xdr, 4);
3425 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003426 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003427 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3429 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003430 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 return 0;
3432}
3433
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003434static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003435{
3436 __be32 *p;
3437
3438 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3439 return -EIO;
3440 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3441 p = xdr_inline_decode(xdr, 4);
3442 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003443 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003444 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003445 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003446 }
3447 return 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003448}
3449
Kinglong Mee8c612822015-08-26 21:12:58 +08003450static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3451 uint32_t *bitmap, uint32_t *bitmask)
3452{
3453 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3454 int ret;
3455 ret = decode_attr_bitmap(xdr, bitmask);
3456 if (unlikely(ret < 0))
3457 return ret;
3458 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3459 } else
3460 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3461 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3462 bitmask[0], bitmask[1], bitmask[2]);
3463 return 0;
3464}
3465
Bryan Schumakerae42c702010-10-21 16:33:17 -04003466static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3467{
3468 __be32 *p;
Frank Sorenson86bbd742018-10-23 10:34:57 -05003469 u32 len;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003470
Trond Myklebust7ad07352010-10-23 15:34:20 -04003471 if (fh != NULL)
3472 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003473
3474 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3475 return -EIO;
3476 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3477 p = xdr_inline_decode(xdr, 4);
3478 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003479 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003480 len = be32_to_cpup(p);
3481 if (len > NFS4_FHSIZE)
3482 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003483 p = xdr_inline_decode(xdr, len);
3484 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003485 return -EIO;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003486 if (fh != NULL) {
3487 memcpy(fh->data, p, len);
3488 fh->size = len;
3489 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003490 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3491 }
3492 return 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003493}
3494
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3496{
Al Viro8687b632006-10-19 23:28:48 -07003497 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003499 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3501 return -EIO;
3502 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003503 p = xdr_inline_decode(xdr, 4);
3504 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003505 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003506 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3508 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003509 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 return 0;
3511}
3512
3513static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3514{
Al Viro8687b632006-10-19 23:28:48 -07003515 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003516 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517
3518 *fileid = 0;
3519 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3520 return -EIO;
3521 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003522 p = xdr_inline_decode(xdr, 8);
3523 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003524 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003525 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003527 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003529 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003530 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531}
3532
Manoj Naik99baf622006-06-09 09:34:24 -04003533static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3534{
Al Viro8687b632006-10-19 23:28:48 -07003535 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003536 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003537
3538 *fileid = 0;
3539 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3540 return -EIO;
3541 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003542 p = xdr_inline_decode(xdr, 8);
3543 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003544 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003545 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003546 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003547 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003548 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003549 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003550 return ret;
Manoj Naik99baf622006-06-09 09:34:24 -04003551}
3552
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3554{
Al Viro8687b632006-10-19 23:28:48 -07003555 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 int status = 0;
3557
3558 *res = 0;
3559 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3560 return -EIO;
3561 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003562 p = xdr_inline_decode(xdr, 8);
3563 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003564 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003565 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3567 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003568 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 return status;
3570}
3571
3572static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3573{
Al Viro8687b632006-10-19 23:28:48 -07003574 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 int status = 0;
3576
3577 *res = 0;
3578 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3579 return -EIO;
3580 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003581 p = xdr_inline_decode(xdr, 8);
3582 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003583 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003584 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3586 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003587 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 return status;
3589}
3590
3591static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3592{
Al Viro8687b632006-10-19 23:28:48 -07003593 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594 int status = 0;
3595
3596 *res = 0;
3597 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3598 return -EIO;
3599 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003600 p = xdr_inline_decode(xdr, 8);
3601 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003602 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003603 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3605 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003606 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607 return status;
3608}
3609
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003610static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3611{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003612 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003613 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003614 int status = 0;
3615
Benny Halevyc0eae662009-08-14 17:20:14 +03003616 p = xdr_inline_decode(xdr, 4);
3617 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003618 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003619 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003620 if (n == 0)
3621 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003622 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003623 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3624 dprintk("cannot parse %d components in path\n", n);
3625 goto out_eio;
3626 }
3627 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003628 struct nfs4_string *component = &path->components[path->ncomponents];
3629 status = decode_opaque_inline(xdr, &component->len, &component->data);
3630 if (unlikely(status != 0))
3631 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003632 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003633 pr_cont("%s%.*s ",
3634 (path->ncomponents != n ? "/ " : ""),
3635 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003636 }
3637out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003638 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003639root_path:
3640/* a root pathname is sent as a zero component4 */
3641 path->ncomponents = 1;
3642 path->components[0].len=0;
3643 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003644 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003645 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003646out_eio:
3647 dprintk(" status %d", status);
3648 status = -EIO;
3649 goto out;
3650}
3651
3652static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003653{
3654 int n;
Al Viro8687b632006-10-19 23:28:48 -07003655 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003656 int status = -EIO;
3657
3658 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3659 goto out;
3660 status = 0;
3661 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3662 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003663 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003664 status = -EIO;
3665 /* Ignore borken servers that return unrequested attrs */
3666 if (unlikely(res == NULL))
3667 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003668 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003669 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003670 if (unlikely(status != 0))
3671 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003672 p = xdr_inline_decode(xdr, 4);
3673 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003674 goto out_eio;
Benny Halevycccddf42009-08-14 17:20:19 +03003675 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003676 if (n <= 0)
3677 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003678 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003679 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003680 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003681
Trond Myklebust809b4262013-03-27 11:54:45 -04003682 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3683 break;
3684 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003685 p = xdr_inline_decode(xdr, 4);
3686 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003687 goto out_eio;
Benny Halevycccddf42009-08-14 17:20:19 +03003688 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003689
Chuck Lever02a29762012-03-01 17:00:31 -05003690 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003691 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3692 struct nfs4_string *server;
3693
3694 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003695 unsigned int i;
3696 dprintk("%s: using first %u of %u servers "
3697 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003698 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003699 NFS4_FS_LOCATION_MAXSERVERS,
3700 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003701 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003702 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003703 char *data;
3704 status = decode_opaque_inline(xdr, &len, &data);
3705 if (unlikely(status != 0))
3706 goto out_eio;
3707 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003708 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003709 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003710 server = &loc->servers[loc->nservers];
3711 status = decode_opaque_inline(xdr, &server->len, &server->data);
3712 if (unlikely(status != 0))
3713 goto out_eio;
3714 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003715 }
3716 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003717 if (unlikely(status != 0))
3718 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003719 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003720 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003721 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003722out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003723 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003724 return status;
3725out_eio:
3726 status = -EIO;
3727 goto out;
3728}
3729
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3731{
Al Viro8687b632006-10-19 23:28:48 -07003732 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 int status = 0;
3734
3735 *res = 0;
3736 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3737 return -EIO;
3738 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003739 p = xdr_inline_decode(xdr, 8);
3740 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003741 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003742 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3744 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003745 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 return status;
3747}
3748
3749static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3750{
Al Viro8687b632006-10-19 23:28:48 -07003751 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 int status = 0;
3753
3754 *maxlink = 1;
3755 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3756 return -EIO;
3757 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003758 p = xdr_inline_decode(xdr, 4);
3759 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003760 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003761 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3763 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003764 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 return status;
3766}
3767
3768static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3769{
Al Viro8687b632006-10-19 23:28:48 -07003770 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 int status = 0;
3772
3773 *maxname = 1024;
3774 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3775 return -EIO;
3776 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003777 p = xdr_inline_decode(xdr, 4);
3778 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003779 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003780 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3782 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003783 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 return status;
3785}
3786
3787static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3788{
Al Viro8687b632006-10-19 23:28:48 -07003789 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 int status = 0;
3791
3792 *res = 1024;
3793 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3794 return -EIO;
3795 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3796 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003797 p = xdr_inline_decode(xdr, 8);
3798 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003799 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003800 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 if (maxread > 0x7FFFFFFF)
3802 maxread = 0x7FFFFFFF;
3803 *res = (uint32_t)maxread;
3804 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3805 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003806 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 return status;
3808}
3809
3810static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3811{
Al Viro8687b632006-10-19 23:28:48 -07003812 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 int status = 0;
3814
3815 *res = 1024;
3816 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3817 return -EIO;
3818 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3819 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003820 p = xdr_inline_decode(xdr, 8);
3821 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003822 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003823 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 if (maxwrite > 0x7FFFFFFF)
3825 maxwrite = 0x7FFFFFFF;
3826 *res = (uint32_t)maxwrite;
3827 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3828 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003829 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 return status;
3831}
3832
Trond Myklebustbca79472009-03-11 14:10:26 -04003833static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834{
Trond Myklebustbca79472009-03-11 14:10:26 -04003835 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003836 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003837 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838
3839 *mode = 0;
3840 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3841 return -EIO;
3842 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003843 p = xdr_inline_decode(xdr, 4);
3844 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003845 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003846 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003847 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003849 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003851 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003852 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853}
3854
3855static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3856{
Al Viro8687b632006-10-19 23:28:48 -07003857 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003858 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859
3860 *nlink = 1;
3861 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3862 return -EIO;
3863 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003864 p = xdr_inline_decode(xdr, 4);
3865 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003866 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003867 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003869 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003871 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003872 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873}
3874
Trond Myklebust686a8162017-02-19 16:08:32 -05003875static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3876 struct nfs4_string *name, gfp_t gfp_flags)
3877{
3878 ssize_t ret;
3879
3880 ret = xdr_stream_decode_string_dup(xdr, &name->data,
3881 XDR_MAX_NETOBJ, gfp_flags);
3882 name->len = 0;
3883 if (ret > 0)
3884 name->len = ret;
3885 return ret;
3886}
3887
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003888static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003889 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003890 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891{
Trond Myklebust686a8162017-02-19 16:08:32 -05003892 ssize_t len;
3893 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894
Eric W. Biedermane5782072013-02-01 14:22:02 -08003895 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3897 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003898 if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3899 return 0;
3900 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3901
3902 if (owner_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04003903 len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05003904 if (len <= 0)
3905 goto out;
3906 dprintk("%s: name=%s\n", __func__, owner_name->data);
3907 return NFS_ATTR_FATTR_OWNER_NAME;
3908 } else {
3909 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3910 XDR_MAX_NETOBJ);
3911 if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3912 goto out;
3913 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3914 return NFS_ATTR_FATTR_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003916out:
Chuck Levereb72f482019-02-11 11:24:21 -05003917 if (len == -EBADMSG)
3918 return -EIO;
3919 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920}
3921
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003922static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003923 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003924 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925{
Trond Myklebust686a8162017-02-19 16:08:32 -05003926 ssize_t len;
3927 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928
Eric W. Biedermane5782072013-02-01 14:22:02 -08003929 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3931 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003932 if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
3933 return 0;
3934 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3935
3936 if (group_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04003937 len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05003938 if (len <= 0)
3939 goto out;
3940 dprintk("%s: name=%s\n", __func__, group_name->data);
Kinglong Mee6f1f6222017-03-06 17:49:42 +08003941 return NFS_ATTR_FATTR_GROUP_NAME;
Trond Myklebust686a8162017-02-19 16:08:32 -05003942 } else {
3943 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3944 XDR_MAX_NETOBJ);
3945 if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
3946 goto out;
3947 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3948 return NFS_ATTR_FATTR_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003950out:
Chuck Levereb72f482019-02-11 11:24:21 -05003951 if (len == -EBADMSG)
3952 return -EIO;
3953 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954}
3955
3956static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3957{
Al Viro8687b632006-10-19 23:28:48 -07003958 uint32_t major = 0, minor = 0;
3959 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003960 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961
3962 *rdev = MKDEV(0,0);
3963 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3964 return -EIO;
3965 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3966 dev_t tmp;
3967
Benny Halevyc0eae662009-08-14 17:20:14 +03003968 p = xdr_inline_decode(xdr, 8);
3969 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003970 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03003971 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003972 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 tmp = MKDEV(major, minor);
3974 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3975 *rdev = tmp;
3976 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003977 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003979 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003980 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981}
3982
3983static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3984{
Al Viro8687b632006-10-19 23:28:48 -07003985 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 int status = 0;
3987
3988 *res = 0;
3989 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3990 return -EIO;
3991 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003992 p = xdr_inline_decode(xdr, 8);
3993 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05003994 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03003995 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3997 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003998 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 return status;
4000}
4001
4002static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4003{
Al Viro8687b632006-10-19 23:28:48 -07004004 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 int status = 0;
4006
4007 *res = 0;
4008 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4009 return -EIO;
4010 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004011 p = xdr_inline_decode(xdr, 8);
4012 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004013 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004014 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4016 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004017 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018 return status;
4019}
4020
4021static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4022{
Al Viro8687b632006-10-19 23:28:48 -07004023 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 int status = 0;
4025
4026 *res = 0;
4027 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4028 return -EIO;
4029 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004030 p = xdr_inline_decode(xdr, 8);
4031 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004032 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004033 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4035 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004036 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 return status;
4038}
4039
4040static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4041{
Al Viro8687b632006-10-19 23:28:48 -07004042 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004043 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044
4045 *used = 0;
4046 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4047 return -EIO;
4048 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004049 p = xdr_inline_decode(xdr, 8);
4050 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004051 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004052 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004054 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004056 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004058 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059}
4060
Trond Myklebust36b37432018-03-20 17:03:10 -04004061static __be32 *
4062xdr_decode_nfstime4(__be32 *p, struct timespec *t)
4063{
4064 __u64 sec;
4065
4066 p = xdr_decode_hyper(p, &sec);
4067 t-> tv_sec = (time_t)sec;
4068 t->tv_nsec = be32_to_cpup(p++);
4069 return p;
4070}
4071
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4073{
Al Viro8687b632006-10-19 23:28:48 -07004074 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075
Trond Myklebust36b37432018-03-20 17:03:10 -04004076 p = xdr_inline_decode(xdr, nfstime4_maxsz << 2);
Benny Halevyc0eae662009-08-14 17:20:14 +03004077 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004078 return -EIO;
Trond Myklebust36b37432018-03-20 17:03:10 -04004079 xdr_decode_nfstime4(p, time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 return 0;
4081}
4082
4083static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4084{
4085 int status = 0;
4086
4087 time->tv_sec = 0;
4088 time->tv_nsec = 0;
4089 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4090 return -EIO;
4091 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4092 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004093 if (status == 0)
4094 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4096 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004097 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 return status;
4099}
4100
4101static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4102{
4103 int status = 0;
4104
4105 time->tv_sec = 0;
4106 time->tv_nsec = 0;
4107 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4108 return -EIO;
4109 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4110 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004111 if (status == 0)
4112 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4114 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004115 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116 return status;
4117}
4118
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004119static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4120 struct timespec *time)
4121{
4122 int status = 0;
4123
4124 time->tv_sec = 0;
4125 time->tv_nsec = 0;
4126 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4127 return -EIO;
4128 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4129 status = decode_attr_time(xdr, time);
4130 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4131 }
4132 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4133 (long)time->tv_nsec);
4134 return status;
4135}
4136
David Quigleyaa9c2662013-05-22 12:50:44 -04004137static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4138 struct nfs4_label *label)
4139{
4140 uint32_t pi = 0;
4141 uint32_t lfs = 0;
4142 __u32 len;
4143 __be32 *p;
4144 int status = 0;
4145
4146 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4147 return -EIO;
4148 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4149 p = xdr_inline_decode(xdr, 4);
4150 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004151 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004152 lfs = be32_to_cpup(p++);
4153 p = xdr_inline_decode(xdr, 4);
4154 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004155 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004156 pi = be32_to_cpup(p++);
4157 p = xdr_inline_decode(xdr, 4);
4158 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004159 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004160 len = be32_to_cpup(p++);
4161 p = xdr_inline_decode(xdr, len);
4162 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004163 return -EIO;
David Quigleyaa9c2662013-05-22 12:50:44 -04004164 if (len < NFS4_MAXLABELLEN) {
4165 if (label) {
4166 memcpy(label->label, p, len);
4167 label->len = len;
4168 label->pi = pi;
4169 label->lfs = lfs;
4170 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4171 }
4172 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4173 } else
4174 printk(KERN_WARNING "%s: label too long (%u)!\n",
4175 __func__, len);
4176 }
4177 if (label && label->label)
4178 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4179 (char *)label->label, label->len, label->pi, label->lfs);
4180 return status;
David Quigleyaa9c2662013-05-22 12:50:44 -04004181}
4182
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4184{
4185 int status = 0;
4186
4187 time->tv_sec = 0;
4188 time->tv_nsec = 0;
4189 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4190 return -EIO;
4191 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4192 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004193 if (status == 0)
4194 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4196 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004197 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 return status;
4199}
4200
Trond Myklebust256e48b2012-06-21 11:18:13 -04004201static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202{
4203 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004204 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205
4206 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004207 dprintk("%s: server returned incorrect attribute length: "
4208 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004209 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210 attrwords << 2,
4211 (attrwords < nwords) ? '<' : '>',
4212 nwords << 2);
4213 return -EIO;
4214 }
4215 return 0;
4216}
4217
4218static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4219{
Al Viro8687b632006-10-19 23:28:48 -07004220 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221
Benny Halevyc0eae662009-08-14 17:20:14 +03004222 p = xdr_inline_decode(xdr, 20);
4223 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004224 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03004225 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004226 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004227 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228 return 0;
4229}
4230
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004231static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232{
Al Viro8687b632006-10-19 23:28:48 -07004233 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 uint32_t supp, acc;
4235 int status;
4236
4237 status = decode_op_hdr(xdr, OP_ACCESS);
4238 if (status)
4239 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004240 p = xdr_inline_decode(xdr, 8);
4241 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004242 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03004243 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004244 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004245 *supported = supp;
4246 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247 return 0;
4248}
4249
Benny Halevy07d30432009-08-14 17:19:52 +03004250static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004251{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004252 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
Chuck Levereb72f482019-02-11 11:24:21 -05004253 if (unlikely(ret < 0))
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004254 return -EIO;
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004255 return 0;
Benny Halevy07d30432009-08-14 17:19:52 +03004256}
4257
4258static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4259{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004260 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261}
4262
Trond Myklebust93b717f2016-05-16 17:42:43 -04004263static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4264{
4265 stateid->type = NFS4_OPEN_STATEID_TYPE;
4266 return decode_stateid(xdr, stateid);
4267}
4268
4269static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4270{
4271 stateid->type = NFS4_LOCK_STATEID_TYPE;
4272 return decode_stateid(xdr, stateid);
4273}
4274
4275static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4276{
4277 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4278 return decode_stateid(xdr, stateid);
4279}
4280
Trond Myklebustfcd88432017-11-07 12:39:44 -05004281static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4282{
4283 nfs4_stateid dummy;
4284
4285 nfs4_stateid_copy(stateid, &invalid_stateid);
4286 return decode_stateid(xdr, &dummy);
4287}
4288
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4290{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291 int status;
4292
4293 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004294 if (status != -EIO)
4295 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004296 if (!status)
Trond Myklebustfcd88432017-11-07 12:39:44 -05004297 status = decode_invalid_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004298 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299}
4300
Benny Halevydb942bb2009-08-14 17:19:56 +03004301static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4302{
Chuck Levercd937102012-03-02 17:14:31 -05004303 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304}
4305
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004306static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4307{
4308 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4309}
4310
Fred Isaman0b7c0152012-04-20 14:47:39 -04004311static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004313 int status;
4314
4315 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004316 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004317 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004318 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319}
4320
4321static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4322{
Al Viro8687b632006-10-19 23:28:48 -07004323 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324 uint32_t bmlen;
4325 int status;
4326
4327 status = decode_op_hdr(xdr, OP_CREATE);
4328 if (status)
4329 return status;
4330 if ((status = decode_change_info(xdr, cinfo)))
4331 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004332 p = xdr_inline_decode(xdr, 4);
4333 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004334 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004335 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004336 p = xdr_inline_decode(xdr, bmlen << 2);
4337 if (likely(p))
4338 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004339 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004340}
4341
4342static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4343{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004344 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004345 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346 int status;
4347
4348 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4349 goto xdr_error;
4350 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4351 goto xdr_error;
4352 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4353 goto xdr_error;
4354 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4355 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004356 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4357 &res->fh_expire_type)) != 0)
4358 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4360 goto xdr_error;
4361 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4362 goto xdr_error;
4363 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4364 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004365 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4366 res->exclcreat_bitmask)) != 0)
4367 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368 status = verify_attr_len(xdr, savep, attrlen);
4369xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004370 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371 return status;
4372}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004373
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4375{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004376 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004377 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004379
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4381 goto xdr_error;
4382 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4383 goto xdr_error;
4384 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4385 goto xdr_error;
4386
4387 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4388 goto xdr_error;
4389 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4390 goto xdr_error;
4391 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4392 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004393
4394 status = -EIO;
4395 if (unlikely(bitmap[0]))
4396 goto xdr_error;
4397
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4399 goto xdr_error;
4400 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4401 goto xdr_error;
4402 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4403 goto xdr_error;
4404
4405 status = verify_attr_len(xdr, savep, attrlen);
4406xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004407 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408 return status;
4409}
4410
4411static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4412{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004413 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004414 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004416
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4418 goto xdr_error;
4419 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4420 goto xdr_error;
4421 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4422 goto xdr_error;
4423
4424 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4425 goto xdr_error;
4426 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4427 goto xdr_error;
4428
4429 status = verify_attr_len(xdr, savep, attrlen);
4430xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004431 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004432 return status;
4433}
4434
Andy Adamson88034c32012-05-23 05:02:34 -04004435static int decode_threshold_hint(struct xdr_stream *xdr,
4436 uint32_t *bitmap,
4437 uint64_t *res,
4438 uint32_t hint_bit)
4439{
4440 __be32 *p;
4441
4442 *res = 0;
4443 if (likely(bitmap[0] & hint_bit)) {
4444 p = xdr_inline_decode(xdr, 8);
4445 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004446 return -EIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004447 xdr_decode_hyper(p, res);
4448 }
4449 return 0;
Andy Adamson88034c32012-05-23 05:02:34 -04004450}
4451
4452static int decode_first_threshold_item4(struct xdr_stream *xdr,
4453 struct nfs4_threshold *res)
4454{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004455 __be32 *p;
4456 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004457 uint32_t bitmap[3] = {0,}, attrlen;
4458 int status;
4459
4460 /* layout type */
4461 p = xdr_inline_decode(xdr, 4);
Chuck Levereb72f482019-02-11 11:24:21 -05004462 if (unlikely(!p))
Andy Adamson88034c32012-05-23 05:02:34 -04004463 return -EIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004464 res->l_type = be32_to_cpup(p);
4465
4466 /* thi_hintset bitmap */
4467 status = decode_attr_bitmap(xdr, bitmap);
4468 if (status < 0)
4469 goto xdr_error;
4470
4471 /* thi_hintlist length */
4472 status = decode_attr_length(xdr, &attrlen, &savep);
4473 if (status < 0)
4474 goto xdr_error;
4475 /* thi_hintlist */
4476 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4477 if (status < 0)
4478 goto xdr_error;
4479 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4480 if (status < 0)
4481 goto xdr_error;
4482 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4483 THRESHOLD_RD_IO);
4484 if (status < 0)
4485 goto xdr_error;
4486 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4487 THRESHOLD_WR_IO);
4488 if (status < 0)
4489 goto xdr_error;
4490
4491 status = verify_attr_len(xdr, savep, attrlen);
4492 res->bm = bitmap[0];
4493
4494 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4495 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4496 res->wr_io_sz);
4497xdr_error:
4498 dprintk("%s ret=%d!\n", __func__, status);
4499 return status;
4500}
4501
4502/*
4503 * Thresholds on pNFS direct I/O vrs MDS I/O
4504 */
4505static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4506 uint32_t *bitmap,
4507 struct nfs4_threshold *res)
4508{
4509 __be32 *p;
4510 int status = 0;
4511 uint32_t num;
4512
4513 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4514 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004515 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004516 /* Did the server return an unrequested attribute? */
4517 if (unlikely(res == NULL))
4518 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004519 p = xdr_inline_decode(xdr, 4);
4520 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004521 return -EIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004522 num = be32_to_cpup(p);
4523 if (num == 0)
4524 return 0;
4525 if (num > 1)
4526 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4527 "drivers per filesystem not supported\n",
4528 __func__);
4529
4530 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004531 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004532 }
4533 return status;
Andy Adamson88034c32012-05-23 05:02:34 -04004534}
4535
Bryan Schumakerae42c702010-10-21 16:33:17 -04004536static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4537 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004538 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004539 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004540{
Trond Myklebustbca79472009-03-11 14:10:26 -04004541 int status;
4542 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004543 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004544 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004546 status = decode_attr_type(xdr, bitmap, &type);
4547 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004549 fattr->mode = 0;
4550 if (status != 0) {
4551 fattr->mode |= nfs_type2fmt[type];
4552 fattr->valid |= status;
4553 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004554
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004555 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4556 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004558 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004559
4560 status = decode_attr_size(xdr, bitmap, &fattr->size);
4561 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004563 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004564
4565 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4566 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004567 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004568 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004569
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004570 err = 0;
4571 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004572 if (status < 0)
4573 goto xdr_error;
4574
4575 status = decode_attr_filehandle(xdr, bitmap, fh);
4576 if (status < 0)
4577 goto xdr_error;
4578
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004579 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4580 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004582 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004583
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004584 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004585 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004586 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004587 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004588
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004589 status = -EIO;
4590 if (unlikely(bitmap[0]))
4591 goto xdr_error;
4592
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004593 status = decode_attr_mode(xdr, bitmap, &fmode);
4594 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004596 if (status != 0) {
4597 fattr->mode |= fmode;
4598 fattr->valid |= status;
4599 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004600
4601 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4602 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004604 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004605
Trond Myklebust6926afd2012-01-07 13:22:46 -05004606 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004607 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004609 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004610
Trond Myklebust6926afd2012-01-07 13:22:46 -05004611 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004612 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004614 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004615
4616 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4617 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004618 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004619 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004620
4621 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4622 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004624 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004625
4626 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4627 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004629 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004630
4631 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4632 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004634 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004635
4636 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4637 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004639 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004640
Trond Myklebust28331a42011-04-27 13:47:52 -04004641 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004642 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004643 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004644 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004645
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004646 status = -EIO;
4647 if (unlikely(bitmap[1]))
4648 goto xdr_error;
4649
Andy Adamson88034c32012-05-23 05:02:34 -04004650 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4651 if (status < 0)
4652 goto xdr_error;
4653
David Quigleyaa9c2662013-05-22 12:50:44 -04004654 if (label) {
4655 status = decode_attr_security_label(xdr, bitmap, label);
4656 if (status < 0)
4657 goto xdr_error;
4658 fattr->valid |= status;
4659 }
4660
Bryan Schumakerae42c702010-10-21 16:33:17 -04004661xdr_error:
4662 dprintk("%s: xdr returned %d\n", __func__, -status);
4663 return status;
4664}
4665
4666static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004667 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004668 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004669{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004670 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004671 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004672 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004673 int status;
4674
4675 status = decode_op_hdr(xdr, OP_GETATTR);
4676 if (status < 0)
4677 goto xdr_error;
4678
4679 status = decode_attr_bitmap(xdr, bitmap);
4680 if (status < 0)
4681 goto xdr_error;
4682
4683 status = decode_attr_length(xdr, &attrlen, &savep);
4684 if (status < 0)
4685 goto xdr_error;
4686
David Quigleyaa9c2662013-05-22 12:50:44 -04004687 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4688 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004689 if (status < 0)
4690 goto xdr_error;
4691
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004692 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004694 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695 return status;
4696}
4697
David Quigleyaa9c2662013-05-22 12:50:44 -04004698static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4699 struct nfs4_label *label, const struct nfs_server *server)
4700{
4701 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4702}
4703
Bryan Schumakerae42c702010-10-21 16:33:17 -04004704static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004705 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004706{
David Quigleyaa9c2662013-05-22 12:50:44 -04004707 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004708}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709
Andy Adamson504913f2010-10-20 00:17:57 -04004710/*
Jeff Layton3132e492016-08-10 15:58:24 -04004711 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004712 */
Jeff Layton3132e492016-08-10 15:58:24 -04004713static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004714 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004715{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004716 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004717 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004718
4719 p = xdr_inline_decode(xdr, 4);
4720 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004721 return -EIO;
Jeff Laytonca440c32016-09-15 14:40:49 -04004722 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004723
4724 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004725 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004726 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004727
4728 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004729 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004730 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004731 return -EIO;
Jeff Laytonca440c32016-09-15 14:40:49 -04004732
4733 /* If we get too many, then just cap it at the max */
4734 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4735 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4736 __func__, fsinfo->nlayouttypes);
4737 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4738 }
4739
4740 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4741 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004742 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004743}
4744
4745/*
4746 * The type of file system exported.
4747 * Note we must ensure that layouttype is set in any non-error case.
4748 */
4749static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004750 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004751{
4752 int status = 0;
4753
4754 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4755 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4756 return -EIO;
4757 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004758 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004759 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004760 }
Andy Adamson504913f2010-10-20 00:17:57 -04004761 return status;
4762}
4763
Fred Isamandae100c2011-07-30 20:52:37 -04004764/*
4765 * The prefered block size for layout directed io
4766 */
4767static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4768 uint32_t *res)
4769{
4770 __be32 *p;
4771
4772 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4773 *res = 0;
4774 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4775 p = xdr_inline_decode(xdr, 4);
Chuck Levereb72f482019-02-11 11:24:21 -05004776 if (unlikely(!p))
Fred Isamandae100c2011-07-30 20:52:37 -04004777 return -EIO;
Fred Isamandae100c2011-07-30 20:52:37 -04004778 *res = be32_to_cpup(p);
4779 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4780 }
4781 return 0;
4782}
4783
Peng Tao2a92ee92015-09-26 02:24:37 +08004784/*
4785 * The granularity of a CLONE operation.
4786 */
4787static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4788 uint32_t *res)
4789{
4790 __be32 *p;
4791
4792 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4793 *res = 0;
4794 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4795 p = xdr_inline_decode(xdr, 4);
Chuck Levereb72f482019-02-11 11:24:21 -05004796 if (unlikely(!p))
Peng Tao2a92ee92015-09-26 02:24:37 +08004797 return -EIO;
Peng Tao2a92ee92015-09-26 02:24:37 +08004798 *res = be32_to_cpup(p);
4799 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4800 }
4801 return 0;
4802}
4803
Linus Torvalds1da177e2005-04-16 15:20:36 -07004804static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4805{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004806 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004807 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808 int status;
4809
4810 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4811 goto xdr_error;
4812 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4813 goto xdr_error;
4814 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4815 goto xdr_error;
4816
4817 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4818
4819 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4820 goto xdr_error;
4821 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4822 goto xdr_error;
4823 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4824 goto xdr_error;
4825 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4826 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4827 goto xdr_error;
4828 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004829
4830 status = -EIO;
4831 if (unlikely(bitmap[0]))
4832 goto xdr_error;
4833
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004834 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4835 if (status != 0)
4836 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004837 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004838 if (status != 0)
4839 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004840
4841 status = -EIO;
4842 if (unlikely(bitmap[1]))
4843 goto xdr_error;
4844
Fred Isamandae100c2011-07-30 20:52:37 -04004845 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4846 if (status)
4847 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004848 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4849 if (status)
4850 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851
4852 status = verify_attr_len(xdr, savep, attrlen);
4853xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004854 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855 return status;
4856}
4857
4858static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4859{
Al Viro8687b632006-10-19 23:28:48 -07004860 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861 uint32_t len;
4862 int status;
4863
Trond Myklebust99367812007-07-17 21:52:41 -04004864 /* Zero handle first to allow comparisons */
4865 memset(fh, 0, sizeof(*fh));
4866
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867 status = decode_op_hdr(xdr, OP_GETFH);
4868 if (status)
4869 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870
Benny Halevyc0eae662009-08-14 17:20:14 +03004871 p = xdr_inline_decode(xdr, 4);
4872 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004873 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03004874 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004875 if (len > NFS4_FHSIZE)
4876 return -EIO;
4877 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004878 p = xdr_inline_decode(xdr, len);
4879 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004880 return -EIO;
Benny Halevy99398d02009-08-14 17:20:05 +03004881 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882 return 0;
4883}
4884
4885static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4886{
4887 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004888
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889 status = decode_op_hdr(xdr, OP_LINK);
4890 if (status)
4891 return status;
4892 return decode_change_info(xdr, cinfo);
4893}
4894
4895/*
4896 * We create the owner, so we know a proper owner.id length is 4.
4897 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004898static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004900 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004901 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004902 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004904 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004905 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004906 return -EIO;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004907 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004908 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004909 type = be32_to_cpup(p++); /* 4 byte read */
4910 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004911 fl->fl_start = (loff_t)offset;
4912 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4913 if (length == ~(uint64_t)0)
4914 fl->fl_end = OFFSET_MAX;
4915 fl->fl_type = F_WRLCK;
4916 if (type & 1)
4917 fl->fl_type = F_RDLCK;
4918 fl->fl_pid = 0;
4919 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004920 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4921 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4922 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Chuck Levereb72f482019-02-11 11:24:21 -05004923 if (likely(!p))
4924 return -EIO;
4925 return -NFS4ERR_DENIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926}
4927
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004928static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004929{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930 int status;
4931
4932 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004933 if (status == -EIO)
4934 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04004936 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004937 if (unlikely(status))
4938 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004939 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004940 status = decode_lock_denied(xdr, NULL);
4941 if (res->open_seqid != NULL)
4942 nfs_increment_open_seqid(status, res->open_seqid);
4943 nfs_increment_lock_seqid(status, res->lock_seqid);
4944out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945 return status;
4946}
4947
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004948static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004949{
4950 int status;
4951 status = decode_op_hdr(xdr, OP_LOCKT);
4952 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004953 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 return status;
4955}
4956
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004957static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004959 int status;
4960
4961 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004962 if (status != -EIO)
4963 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004964 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04004965 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004966 return status;
4967}
4968
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004969static int decode_release_lockowner(struct xdr_stream *xdr)
4970{
4971 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4972}
4973
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974static int decode_lookup(struct xdr_stream *xdr)
4975{
4976 return decode_op_hdr(xdr, OP_LOOKUP);
4977}
4978
Jeff Layton5b5faaf2017-06-29 06:34:52 -07004979static int decode_lookupp(struct xdr_stream *xdr)
4980{
4981 return decode_op_hdr(xdr, OP_LOOKUPP);
4982}
4983
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04004985static int decode_space_limit(struct xdr_stream *xdr,
4986 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987{
Andy Adamson05d564f2008-12-23 16:06:15 -05004988 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04004990 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004991
Benny Halevyc0eae662009-08-14 17:20:14 +03004992 p = xdr_inline_decode(xdr, 12);
4993 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05004994 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03004995 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04004997 case NFS4_LIMIT_SIZE:
4998 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004999 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005000 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005001 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005002 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005003 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005004 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005005 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005006 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007 return 0;
5008}
5009
Trond Myklebust6ae37332015-01-30 14:21:14 -05005010static int decode_rw_delegation(struct xdr_stream *xdr,
5011 uint32_t delegation_type,
5012 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013{
Andy Adamson05d564f2008-12-23 16:06:15 -05005014 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005015 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016
Trond Myklebust93b717f2016-05-16 17:42:43 -04005017 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005018 if (unlikely(status))
5019 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005020 p = xdr_inline_decode(xdr, 4);
5021 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005022 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005023 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005024
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005026 case NFS4_OPEN_DELEGATE_READ:
5027 res->delegation_type = FMODE_READ;
5028 break;
5029 case NFS4_OPEN_DELEGATE_WRITE:
5030 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005031 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032 return -EIO;
5033 }
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05005034 return decode_ace(xdr, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035}
5036
Trond Myklebust6ae37332015-01-30 14:21:14 -05005037static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5038{
5039 __be32 *p;
5040 uint32_t why_no_delegation;
5041
5042 p = xdr_inline_decode(xdr, 4);
5043 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005044 return -EIO;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005045 why_no_delegation = be32_to_cpup(p);
5046 switch (why_no_delegation) {
5047 case WND4_CONTENTION:
5048 case WND4_RESOURCE:
5049 xdr_inline_decode(xdr, 4);
5050 /* Ignore for now */
5051 }
5052 return 0;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005053}
5054
5055static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5056{
5057 __be32 *p;
5058 uint32_t delegation_type;
5059
5060 p = xdr_inline_decode(xdr, 4);
5061 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005062 return -EIO;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005063 delegation_type = be32_to_cpup(p);
5064 res->delegation_type = 0;
5065 switch (delegation_type) {
5066 case NFS4_OPEN_DELEGATE_NONE:
5067 return 0;
5068 case NFS4_OPEN_DELEGATE_READ:
5069 case NFS4_OPEN_DELEGATE_WRITE:
5070 return decode_rw_delegation(xdr, delegation_type, res);
5071 case NFS4_OPEN_DELEGATE_NONE_EXT:
5072 return decode_no_delegation(xdr, res);
5073 }
5074 return -EIO;
Trond Myklebust6ae37332015-01-30 14:21:14 -05005075}
5076
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5078{
Andy Adamson05d564f2008-12-23 16:06:15 -05005079 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005080 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005081 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082
Trond Myklebustc7848f62013-12-04 17:39:23 -05005083 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5084 return status;
5085 nfs_increment_open_seqid(status, res->seqid);
5086 if (status)
5087 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005088 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005089 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005090 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091
Andy Adamson05d564f2008-12-23 16:06:15 -05005092 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093
Benny Halevyc0eae662009-08-14 17:20:14 +03005094 p = xdr_inline_decode(xdr, 8);
5095 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005096 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005097 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005098 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005099 if (bmlen > 10)
5100 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101
Benny Halevyc0eae662009-08-14 17:20:14 +03005102 p = xdr_inline_decode(xdr, bmlen << 2);
5103 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005104 return -EIO;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005105 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5106 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005107 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005108 for (; i < NFS4_BITMAP_SIZE; i++)
5109 res->attrset[i] = 0;
5110
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111 return decode_delegation(xdr, res);
5112xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005113 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005114 return -EIO;
5115}
5116
5117static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5118{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119 int status;
5120
Andy Adamson05d564f2008-12-23 16:06:15 -05005121 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005122 if (status != -EIO)
5123 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005124 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005125 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005126 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127}
5128
5129static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5130{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005131 int status;
5132
5133 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005134 if (status != -EIO)
5135 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005136 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005137 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005138 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139}
5140
5141static int decode_putfh(struct xdr_stream *xdr)
5142{
5143 return decode_op_hdr(xdr, OP_PUTFH);
5144}
5145
5146static int decode_putrootfh(struct xdr_stream *xdr)
5147{
5148 return decode_op_hdr(xdr, OP_PUTROOTFH);
5149}
5150
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005151static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5152 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153{
Al Viro8687b632006-10-19 23:28:48 -07005154 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005155 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156 int status;
5157
5158 status = decode_op_hdr(xdr, OP_READ);
5159 if (status)
5160 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005161 p = xdr_inline_decode(xdr, 8);
5162 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005163 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005164 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005165 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005166 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005167 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005168 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005169 "count %u > recvd %u\n", count, recvd);
5170 count = recvd;
5171 eof = 0;
5172 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173 res->eof = eof;
5174 res->count = count;
5175 return 0;
5176}
5177
5178static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5179{
Chuck Leverbcecff72007-10-26 13:32:03 -04005180 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005181 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182
5183 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005184 if (!status)
5185 status = decode_verifier(xdr, readdir->verifier.data);
5186 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005187 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005188 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005189 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005190 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005191 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005192}
5193
5194static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5195{
5196 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005197 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005198 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005199 int status;
5200
5201 status = decode_op_hdr(xdr, OP_READLINK);
5202 if (status)
5203 return status;
5204
5205 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005206 p = xdr_inline_decode(xdr, 4);
5207 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005208 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005209 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005210 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005211 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005212 return -ENAMETOOLONG;
5213 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005214 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005216 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005217 "count %u > recvd %u\n", len, recvd);
5218 return -EIO;
5219 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220 /*
5221 * The XDR encode routine has set things up so that
5222 * the link text will be copied directly into the
5223 * buffer. We just have to do overflow-checking,
5224 * and and null-terminate the text (the VFS expects
5225 * null-termination).
5226 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005227 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228 return 0;
5229}
5230
5231static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5232{
5233 int status;
5234
5235 status = decode_op_hdr(xdr, OP_REMOVE);
5236 if (status)
5237 goto out;
5238 status = decode_change_info(xdr, cinfo);
5239out:
5240 return status;
5241}
5242
5243static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5244 struct nfs4_change_info *new_cinfo)
5245{
5246 int status;
5247
5248 status = decode_op_hdr(xdr, OP_RENAME);
5249 if (status)
5250 goto out;
5251 if ((status = decode_change_info(xdr, old_cinfo)))
5252 goto out;
5253 status = decode_change_info(xdr, new_cinfo);
5254out:
5255 return status;
5256}
5257
5258static int decode_renew(struct xdr_stream *xdr)
5259{
5260 return decode_op_hdr(xdr, OP_RENEW);
5261}
5262
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005263static int
5264decode_restorefh(struct xdr_stream *xdr)
5265{
5266 return decode_op_hdr(xdr, OP_RESTOREFH);
5267}
5268
J. Bruce Fields029d1052005-06-22 17:16:22 +00005269static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005270 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005271{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005272 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005273 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005274 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005275 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005276 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005277
Andy Adamsonbf118a32011-12-07 11:55:27 -05005278 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005279 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5280 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005281
Trond Myklebust519d3952012-08-14 17:30:10 -04005282 xdr_enter_page(xdr, xdr->buf->page_len);
5283
Trond Myklebustcff298c2012-08-14 17:14:17 -04005284 /* Calculate the offset of the page data */
5285 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005286
J. Bruce Fields029d1052005-06-22 17:16:22 +00005287 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5288 goto out;
5289 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5290 goto out;
5291
5292 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5293 return -EIO;
5294 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005295
Andy Adamsonbf118a32011-12-07 11:55:27 -05005296 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5297 * are stored with the acl data to handle the problem of
5298 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005299 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005300 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005301
5302 /* Check for receive buffer overflow */
5303 if (res->acl_len > (xdr->nwords << 2) ||
5304 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5305 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005306 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005307 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005308 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005309 } else
5310 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005311
5312out:
5313 return status;
5314}
5315
Linus Torvalds1da177e2005-04-16 15:20:36 -07005316static int
5317decode_savefh(struct xdr_stream *xdr)
5318{
5319 return decode_op_hdr(xdr, OP_SAVEFH);
5320}
5321
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005322static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005323{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005324 int status;
5325
Linus Torvalds1da177e2005-04-16 15:20:36 -07005326 status = decode_op_hdr(xdr, OP_SETATTR);
5327 if (status)
5328 return status;
Trond Myklebust37c88762018-03-20 17:03:08 -04005329 if (decode_bitmap4(xdr, NULL, 0) >= 0)
Benny Halevyc0eae662009-08-14 17:20:14 +03005330 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005331 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005332}
5333
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005334static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005335{
Al Viro8687b632006-10-19 23:28:48 -07005336 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005337 uint32_t opnum;
5338 int32_t nfserr;
5339
Benny Halevyc0eae662009-08-14 17:20:14 +03005340 p = xdr_inline_decode(xdr, 8);
5341 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005342 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005343 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005344 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005345 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005346 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005347 return -EIO;
5348 }
Benny Halevycccddf42009-08-14 17:20:19 +03005349 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005350 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005351 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5352 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005353 return -EIO;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005354 p = xdr_decode_hyper(p, &res->clientid);
5355 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005356 } else if (nfserr == NFSERR_CLID_INUSE) {
5357 uint32_t len;
5358
5359 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005360 p = xdr_inline_decode(xdr, 4);
5361 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005362 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005363 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005364 p = xdr_inline_decode(xdr, len);
5365 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005366 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005367
5368 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005369 p = xdr_inline_decode(xdr, 4);
5370 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005371 return -EIO;
Benny Halevycccddf42009-08-14 17:20:19 +03005372 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005373 p = xdr_inline_decode(xdr, len);
5374 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005375 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005376 return -NFSERR_CLID_INUSE;
5377 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005378 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005379
5380 return 0;
5381}
5382
5383static int decode_setclientid_confirm(struct xdr_stream *xdr)
5384{
5385 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5386}
5387
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005388static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389{
Al Viro8687b632006-10-19 23:28:48 -07005390 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005391 int status;
5392
5393 status = decode_op_hdr(xdr, OP_WRITE);
5394 if (status)
5395 return status;
5396
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005397 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005398 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005399 return -EIO;
Benny Halevy6f723f72009-08-14 17:19:37 +03005400 res->count = be32_to_cpup(p++);
5401 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005402 return decode_write_verifier(xdr, &res->verf->verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005403}
5404
5405static int decode_delegreturn(struct xdr_stream *xdr)
5406{
5407 return decode_op_hdr(xdr, OP_DELEGRETURN);
5408}
5409
Chuck Leverfb15b262013-03-16 15:54:34 -04005410static int decode_secinfo_gss(struct xdr_stream *xdr,
5411 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005412{
Chuck Leverfb15b262013-03-16 15:54:34 -04005413 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005414 __be32 *p;
5415
5416 p = xdr_inline_decode(xdr, 4);
5417 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005418 return -EIO;
Chuck Leverfb15b262013-03-16 15:54:34 -04005419 oid_len = be32_to_cpup(p);
5420 if (oid_len > GSS_OID_MAX_LEN)
Chuck Levereb72f482019-02-11 11:24:21 -05005421 return -EINVAL;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005422
Chuck Leverfb15b262013-03-16 15:54:34 -04005423 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005424 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005425 return -EIO;
Chuck Leverfb15b262013-03-16 15:54:34 -04005426 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5427 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005428
5429 p = xdr_inline_decode(xdr, 8);
5430 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005431 return -EIO;
Chuck Leverfb15b262013-03-16 15:54:34 -04005432 flavor->flavor_info.qop = be32_to_cpup(p++);
5433 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005434
5435 return 0;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005436}
5437
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005438static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005439{
Chuck Leverfb15b262013-03-16 15:54:34 -04005440 struct nfs4_secinfo4 *sec_flavor;
5441 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005442 int status;
5443 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005444
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005445 p = xdr_inline_decode(xdr, 4);
5446 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005447 return -EIO;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005448
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005449 res->flavors->num_flavors = 0;
5450 num_flavors = be32_to_cpup(p);
5451
5452 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005453 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005454 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005455 break;
5456
5457 p = xdr_inline_decode(xdr, 4);
5458 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005459 return -EIO;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005460 sec_flavor->flavor = be32_to_cpup(p);
5461
5462 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005463 status = decode_secinfo_gss(xdr, sec_flavor);
5464 if (status)
5465 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005466 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005467 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005468 }
5469
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005470 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005471out:
5472 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005473}
5474
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005475static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5476{
5477 int status = decode_op_hdr(xdr, OP_SECINFO);
5478 if (status)
5479 return status;
5480 return decode_secinfo_common(xdr, res);
5481}
5482
Benny Halevy99fe60d2009-04-01 09:22:29 -04005483#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005484static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5485{
5486 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5487 if (status)
5488 return status;
5489 return decode_secinfo_common(xdr, res);
5490}
5491
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005492static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5493{
5494 __be32 *p;
5495 uint32_t bitmap_words;
5496 unsigned int i;
5497
5498 p = xdr_inline_decode(xdr, 4);
Pan Bian4edabfd2017-04-23 14:49:41 +08005499 if (!p)
5500 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005501 bitmap_words = be32_to_cpup(p++);
5502 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5503 return -EIO;
5504 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5505 for (i = 0; i < bitmap_words; i++)
5506 op_map->u.words[i] = be32_to_cpup(p++);
5507
5508 return 0;
5509}
5510
Benny Halevy99fe60d2009-04-01 09:22:29 -04005511static int decode_exchange_id(struct xdr_stream *xdr,
5512 struct nfs41_exchange_id_res *res)
5513{
5514 __be32 *p;
5515 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005516 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005517 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005518 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005519
5520 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5521 if (status)
5522 return status;
5523
Benny Halevyc0eae662009-08-14 17:20:14 +03005524 p = xdr_inline_decode(xdr, 8);
5525 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005526 return -EIO;
Trond Myklebust32b01312012-05-26 13:41:04 -04005527 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005528 p = xdr_inline_decode(xdr, 12);
5529 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005530 return -EIO;
Trond Myklebust32b01312012-05-26 13:41:04 -04005531 res->seqid = be32_to_cpup(p++);
5532 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005533
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005534 res->state_protect.how = be32_to_cpup(p);
5535 switch (res->state_protect.how) {
5536 case SP4_NONE:
5537 break;
5538 case SP4_MACH_CRED:
5539 status = decode_op_map(xdr, &res->state_protect.enforce);
5540 if (status)
5541 return status;
5542 status = decode_op_map(xdr, &res->state_protect.allow);
5543 if (status)
5544 return status;
5545 break;
5546 default:
5547 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005548 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005549 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005550
Chuck Leveracdeb692012-05-21 22:46:16 -04005551 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005552 p = xdr_inline_decode(xdr, 8);
5553 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005554 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005555 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005556
Chuck Leveracdeb692012-05-21 22:46:16 -04005557 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005558 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5559 if (unlikely(status))
5560 return status;
Chuck Leveracdeb692012-05-21 22:46:16 -04005561 memcpy(res->server_owner->major_id, dummy_str, dummy);
5562 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005563
Chuck Leveracdeb692012-05-21 22:46:16 -04005564 /* server_scope4 */
5565 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5566 if (unlikely(status))
5567 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005568 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5569 res->server_scope->server_scope_sz = dummy;
5570
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005571 /* Implementation Id */
5572 p = xdr_inline_decode(xdr, 4);
5573 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005574 return -EIO;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005575 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005576
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005577 if (impl_id_count) {
5578 /* nii_domain */
5579 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5580 if (unlikely(status))
5581 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005582 memcpy(res->impl_id->domain, dummy_str, dummy);
5583
5584 /* nii_name */
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->name, dummy_str, dummy);
5589
5590 /* nii_date */
5591 p = xdr_inline_decode(xdr, 12);
5592 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005593 return -EIO;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005594 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5595 res->impl_id->date.nseconds = be32_to_cpup(p);
5596
5597 /* if there's more than one entry, ignore the rest */
5598 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005599 return 0;
5600}
Andy Adamsonfc931582009-04-01 09:22:31 -04005601
5602static int decode_chan_attrs(struct xdr_stream *xdr,
5603 struct nfs4_channel_attrs *attrs)
5604{
5605 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005606 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005607
Benny Halevyc0eae662009-08-14 17:20:14 +03005608 p = xdr_inline_decode(xdr, 28);
5609 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005610 return -EIO;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005611 val = be32_to_cpup(p++); /* headerpadsz */
5612 if (val)
5613 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005614 attrs->max_rqst_sz = be32_to_cpup(p++);
5615 attrs->max_resp_sz = be32_to_cpup(p++);
5616 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5617 attrs->max_ops = be32_to_cpup(p++);
5618 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005619 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005620 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005621 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5622 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005623 return -EINVAL;
5624 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005625 if (nr_attrs == 1) {
5626 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5627 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005628 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005629 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005630 return 0;
5631}
5632
Benny Halevye78291e2009-08-14 17:20:00 +03005633static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5634{
5635 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005636}
5637
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005638static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5639 struct nfs41_bind_conn_to_session_res *res)
5640{
5641 __be32 *p;
5642 int status;
5643
5644 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5645 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005646 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005647 if (unlikely(status))
5648 return status;
5649
5650 /* dir flags, rdma mode bool */
5651 p = xdr_inline_decode(xdr, 8);
5652 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005653 return -EIO;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005654
5655 res->dir = be32_to_cpup(p++);
5656 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5657 return -EIO;
5658 if (be32_to_cpup(p) == 0)
5659 res->use_conn_in_rdma_mode = false;
5660 else
5661 res->use_conn_in_rdma_mode = true;
5662
5663 return 0;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005664}
5665
Andy Adamsonfc931582009-04-01 09:22:31 -04005666static int decode_create_session(struct xdr_stream *xdr,
5667 struct nfs41_create_session_res *res)
5668{
5669 __be32 *p;
5670 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005671
5672 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005673 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005674 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005675 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005676 return status;
5677
Andy Adamsonfc931582009-04-01 09:22:31 -04005678 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005679 p = xdr_inline_decode(xdr, 8);
5680 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005681 return -EIO;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005682 res->seqid = be32_to_cpup(p++);
5683 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005684
5685 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005686 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005687 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005688 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005689 return status;
5690}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005691
5692static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5693{
5694 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5695}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005696
Trond Myklebust66245532012-05-25 17:18:09 -04005697static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5698{
5699 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5700}
5701
Ricardo Labiaga180197532009-12-05 16:08:40 -05005702static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5703{
5704 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5705}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005706#endif /* CONFIG_NFS_V4_1 */
5707
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005708static int decode_sequence(struct xdr_stream *xdr,
5709 struct nfs4_sequence_res *res,
5710 struct rpc_rqst *rqstp)
5711{
5712#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005713 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005714 struct nfs4_sessionid id;
5715 u32 dummy;
5716 int status;
5717 __be32 *p;
5718
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005719 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005720 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005721 if (!res->sr_slot->table->session)
5722 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005723
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005724 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005725 if (!status)
5726 status = decode_sessionid(xdr, &id);
5727 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005728 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005729
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005730 /*
5731 * If the server returns different values for sessionID, slotID or
5732 * sequence number, the server is looney tunes.
5733 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005734 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005735 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005736
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005737 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005738 NFS4_MAX_SESSIONID_LEN)) {
5739 dprintk("%s Invalid session id\n", __func__);
5740 goto out_err;
5741 }
Benny Halevye78291e2009-08-14 17:20:00 +03005742
Benny Halevyc0eae662009-08-14 17:20:14 +03005743 p = xdr_inline_decode(xdr, 20);
5744 if (unlikely(!p))
5745 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005746
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005747 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005748 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005749 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005750 dprintk("%s Invalid sequence number\n", __func__);
5751 goto out_err;
5752 }
5753 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005754 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005755 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005756 dprintk("%s Invalid slot id\n", __func__);
5757 goto out_err;
5758 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005759 /* highest slot id */
5760 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005761 /* target highest slot id */
5762 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005763 /* result flags */
5764 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005765 status = 0;
5766out_err:
5767 res->sr_status = status;
5768 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005769out_overflow:
Benny Halevyc0eae662009-08-14 17:20:14 +03005770 status = -EIO;
5771 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005772#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005773 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005774#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005775}
5776
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005777#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005778static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5779{
5780 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5781 return decode_stateid(xdr, stateid);
5782}
5783
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005784static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005785 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005786{
Trond Myklebust4e590802015-03-09 14:01:25 -04005787 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005788 __be32 *p;
5789 uint32_t len, type;
5790 int status;
5791
5792 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5793 if (status) {
5794 if (status == -ETOOSMALL) {
5795 p = xdr_inline_decode(xdr, 4);
5796 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005797 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005798 pdev->mincount = be32_to_cpup(p);
5799 dprintk("%s: Min count too small. mincnt = %u\n",
5800 __func__, pdev->mincount);
5801 }
5802 return status;
5803 }
5804
5805 p = xdr_inline_decode(xdr, 8);
5806 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005807 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005808 type = be32_to_cpup(p++);
5809 if (type != pdev->layout_type) {
5810 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5811 __func__, pdev->layout_type, type);
5812 return -EINVAL;
5813 }
5814 /*
5815 * Get the length of the opaque device_addr4. xdr_read_pages places
5816 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5817 * and places the remaining xdr data in xdr_buf->tail
5818 */
5819 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005820 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
Chuck Levereb72f482019-02-11 11:24:21 -05005821 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005822
5823 /* Parse notification bitmap, verifying that it is zero. */
5824 p = xdr_inline_decode(xdr, 4);
5825 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005826 return -EIO;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005827 len = be32_to_cpup(p);
5828 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005829 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005830
5831 p = xdr_inline_decode(xdr, 4 * len);
5832 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005833 return -EIO;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005834
Trond Myklebust4e590802015-03-09 14:01:25 -04005835 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005836 for (i = 1; i < len; i++) {
5837 if (be32_to_cpup(p++)) {
5838 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005839 __func__);
5840 return -EIO;
5841 }
5842 }
5843 }
5844 return 0;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005845}
5846
5847static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5848 struct nfs4_layoutget_res *res)
5849{
5850 __be32 *p;
5851 int status;
5852 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005853 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005854
5855 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5856 if (status)
Fred Isaman808ba322016-10-04 15:02:21 -04005857 goto out;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005858 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005859 if (unlikely(!p))
5860 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005861 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04005862 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005863 p = xdr_inline_decode(xdr, 4);
5864 if (unlikely(!p))
5865 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005866 layout_count = be32_to_cpup(p);
5867 if (!layout_count) {
5868 dprintk("%s: server responded with empty layout array\n",
5869 __func__);
Fred Isaman808ba322016-10-04 15:02:21 -04005870 status = -EINVAL;
5871 goto out;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005872 }
5873
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005874 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005875 if (unlikely(!p))
5876 goto out_overflow;
5877 p = xdr_decode_hyper(p, &res->range.offset);
5878 p = xdr_decode_hyper(p, &res->range.length);
5879 res->range.iomode = be32_to_cpup(p++);
5880 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005881 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005882
5883 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5884 __func__,
5885 (unsigned long)res->range.offset,
5886 (unsigned long)res->range.length,
5887 res->range.iomode,
5888 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005889 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005890
Trond Myklebust64bd5772012-06-20 22:35:05 -04005891 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005892 if (res->layoutp->len > recvd) {
5893 dprintk("NFS: server cheating in layoutget reply: "
5894 "layout len %u > recvd %u\n",
5895 res->layoutp->len, recvd);
Fred Isaman808ba322016-10-04 15:02:21 -04005896 status = -EINVAL;
5897 goto out;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005898 }
5899
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005900 if (layout_count > 1) {
5901 /* We only handle a length one array at the moment. Any
5902 * further entries are just ignored. Note that this means
5903 * the client may see a response that is less than the
5904 * minimum it requested.
5905 */
5906 dprintk("%s: server responded with %d layouts, dropping tail\n",
5907 __func__, layout_count);
5908 }
5909
Fred Isaman808ba322016-10-04 15:02:21 -04005910out:
5911 res->status = status;
5912 return status;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005913out_overflow:
Fred Isaman808ba322016-10-04 15:02:21 -04005914 status = -EIO;
5915 goto out;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005916}
Andy Adamson863a3c62011-03-23 13:27:54 +00005917
Benny Halevycbe82602011-05-22 19:52:37 +03005918static int decode_layoutreturn(struct xdr_stream *xdr,
5919 struct nfs4_layoutreturn_res *res)
5920{
5921 __be32 *p;
5922 int status;
5923
5924 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5925 if (status)
5926 return status;
5927 p = xdr_inline_decode(xdr, 4);
5928 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005929 return -EIO;
Benny Halevycbe82602011-05-22 19:52:37 +03005930 res->lrs_present = be32_to_cpup(p);
5931 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005932 status = decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustfcd88432017-11-07 12:39:44 -05005933 else
5934 nfs4_stateid_copy(&res->stateid, &invalid_stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03005935 return status;
Benny Halevycbe82602011-05-22 19:52:37 +03005936}
5937
Andy Adamson863a3c62011-03-23 13:27:54 +00005938static int decode_layoutcommit(struct xdr_stream *xdr,
5939 struct rpc_rqst *req,
5940 struct nfs4_layoutcommit_res *res)
5941{
5942 __be32 *p;
5943 __u32 sizechanged;
5944 int status;
5945
5946 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005947 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005948 if (status)
5949 return status;
5950
5951 p = xdr_inline_decode(xdr, 4);
5952 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005953 return -EIO;
Andy Adamson863a3c62011-03-23 13:27:54 +00005954 sizechanged = be32_to_cpup(p);
5955
5956 if (sizechanged) {
5957 /* throw away new size */
5958 p = xdr_inline_decode(xdr, 8);
5959 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005960 return -EIO;
Andy Adamson863a3c62011-03-23 13:27:54 +00005961 }
5962 return 0;
Andy Adamson863a3c62011-03-23 13:27:54 +00005963}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005964
5965static int decode_test_stateid(struct xdr_stream *xdr,
5966 struct nfs41_test_stateid_res *res)
5967{
5968 __be32 *p;
5969 int status;
5970 int num_res;
5971
5972 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5973 if (status)
5974 return status;
5975
5976 p = xdr_inline_decode(xdr, 4);
5977 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005978 return -EIO;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005979 num_res = be32_to_cpup(p++);
5980 if (num_res != 1)
Chuck Levereb72f482019-02-11 11:24:21 -05005981 return -EIO;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005982
5983 p = xdr_inline_decode(xdr, 4);
5984 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05005985 return -EIO;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005986 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005987
5988 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005989}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005990
5991static int decode_free_stateid(struct xdr_stream *xdr,
5992 struct nfs41_free_stateid_res *res)
5993{
Andy Adamson9f79fb42013-09-10 12:56:29 -04005994 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005995 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005996}
Trond Myklebustcf805162016-11-15 14:56:07 -05005997#else
5998static inline
5999int decode_layoutreturn(struct xdr_stream *xdr,
6000 struct nfs4_layoutreturn_res *res)
6001{
6002 return 0;
6003}
Fred Isaman56f487f2016-09-21 11:43:41 -04006004
6005static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6006 struct nfs4_layoutget_res *res)
6007{
6008 return 0;
6009}
6010
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006011#endif /* CONFIG_NFS_V4_1 */
6012
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013/*
Benny Halevy49c25592008-12-23 16:06:16 -05006014 * END OF "GENERIC" DECODE ROUTINES.
6015 */
6016
6017/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006018 * Decode OPEN_DOWNGRADE response
6019 */
Chuck Leverbf269552010-12-14 14:59:29 +00006020static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6021 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006022 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006023{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006024 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006025 struct compound_hdr hdr;
6026 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006027
Chuck Leverbf269552010-12-14 14:59:29 +00006028 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006029 if (status)
6030 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006031 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006032 if (status)
6033 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006034 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006035 if (status)
6036 goto out;
Trond Myklebustb6808142016-11-20 13:34:16 -05006037 if (res->lr_res) {
6038 status = decode_layoutreturn(xdr, res->lr_res);
6039 res->lr_ret = status;
6040 if (status)
6041 goto out;
6042 }
Chuck Leverbf269552010-12-14 14:59:29 +00006043 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006044out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006045 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006046}
6047
6048/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006049 * Decode ACCESS response
6050 */
Chuck Leverbf269552010-12-14 14:59:29 +00006051static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006052 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006053{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006054 struct nfs4_accessres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006055 struct compound_hdr hdr;
6056 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006057
Chuck Leverbf269552010-12-14 14:59:29 +00006058 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006059 if (status)
6060 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006061 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006062 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006063 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006064 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006065 if (status != 0)
6066 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006067 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006068 if (status != 0)
6069 goto out;
Trond Myklebust8bcbe7d2018-03-20 17:03:11 -04006070 if (res->fattr)
6071 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006072out:
6073 return status;
6074}
6075
6076/*
6077 * Decode LOOKUP response
6078 */
Chuck Leverbf269552010-12-14 14:59:29 +00006079static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006080 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006082 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083 struct compound_hdr hdr;
6084 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006085
Chuck Leverbf269552010-12-14 14:59:29 +00006086 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006087 if (status)
6088 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006089 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006090 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006091 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006092 status = decode_putfh(xdr);
6093 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006094 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006095 status = decode_lookup(xdr);
6096 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006098 status = decode_getfh(xdr, res->fh);
6099 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006100 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006101 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006102out:
6103 return status;
6104}
6105
6106/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07006107 * Decode LOOKUPP response
6108 */
6109static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6110 void *data)
6111{
6112 struct nfs4_lookupp_res *res = data;
6113 struct compound_hdr hdr;
6114 int status;
6115
6116 status = decode_compound_hdr(xdr, &hdr);
6117 if (status)
6118 goto out;
6119 status = decode_sequence(xdr, &res->seq_res, rqstp);
6120 if (status)
6121 goto out;
6122 status = decode_putfh(xdr);
6123 if (status)
6124 goto out;
6125 status = decode_lookupp(xdr);
6126 if (status)
6127 goto out;
6128 status = decode_getfh(xdr, res->fh);
6129 if (status)
6130 goto out;
6131 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6132out:
6133 return status;
6134}
6135
6136/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137 * Decode LOOKUP_ROOT response
6138 */
Chuck Leverbf269552010-12-14 14:59:29 +00006139static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6140 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006141 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006142{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006143 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006144 struct compound_hdr hdr;
6145 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006146
Chuck Leverbf269552010-12-14 14:59:29 +00006147 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006148 if (status)
6149 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006150 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006151 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_putrootfh(xdr);
6154 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_getfh(xdr, res->fh);
6157 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006158 status = decode_getfattr_label(xdr, res->fattr,
6159 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160out:
6161 return status;
6162}
6163
6164/*
6165 * Decode REMOVE response
6166 */
Chuck Leverbf269552010-12-14 14:59:29 +00006167static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006168 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006170 struct nfs_removeres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006171 struct compound_hdr hdr;
6172 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006173
Chuck Leverbf269552010-12-14 14:59:29 +00006174 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006175 if (status)
6176 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006177 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006178 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006179 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006180 status = decode_putfh(xdr);
6181 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006182 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006183 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006184out:
6185 return status;
6186}
6187
6188/*
6189 * Decode RENAME response
6190 */
Chuck Leverbf269552010-12-14 14:59:29 +00006191static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006192 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006194 struct nfs_renameres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195 struct compound_hdr hdr;
6196 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006197
Chuck Leverbf269552010-12-14 14:59:29 +00006198 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006199 if (status)
6200 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006202 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006204 status = decode_putfh(xdr);
6205 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006207 status = decode_savefh(xdr);
6208 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_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214out:
6215 return status;
6216}
6217
6218/*
6219 * Decode LINK response
6220 */
Chuck Leverbf269552010-12-14 14:59:29 +00006221static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006222 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006223{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006224 struct nfs4_link_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225 struct compound_hdr hdr;
6226 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006227
Chuck Leverbf269552010-12-14 14:59:29 +00006228 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006229 if (status)
6230 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006231 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006232 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006234 status = decode_putfh(xdr);
6235 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006236 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006237 status = decode_savefh(xdr);
6238 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_link(xdr, &res->cinfo);
6244 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006245 goto out;
6246 /*
6247 * Note order: OP_LINK leaves the directory as the current
6248 * filehandle.
6249 */
Chuck Leverbf269552010-12-14 14:59:29 +00006250 status = decode_restorefh(xdr);
6251 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006252 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006253 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006254out:
6255 return status;
6256}
6257
6258/*
6259 * Decode CREATE response
6260 */
Chuck Leverbf269552010-12-14 14:59:29 +00006261static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006262 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006263{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006264 struct nfs4_create_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006265 struct compound_hdr hdr;
6266 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006267
Chuck Leverbf269552010-12-14 14:59:29 +00006268 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006269 if (status)
6270 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006271 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006272 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006274 status = decode_putfh(xdr);
6275 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006277 status = decode_create(xdr, &res->dir_cinfo);
6278 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006279 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006280 status = decode_getfh(xdr, res->fh);
6281 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006282 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006283 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006284out:
6285 return status;
6286}
6287
6288/*
6289 * Decode SYMLINK response
6290 */
Chuck Leverbf269552010-12-14 14:59:29 +00006291static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006292 void *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006293{
Chuck Leverbf269552010-12-14 14:59:29 +00006294 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295}
6296
6297/*
6298 * Decode GETATTR response
6299 */
Chuck Leverbf269552010-12-14 14:59:29 +00006300static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006301 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006302{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006303 struct nfs4_getattr_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006304 struct compound_hdr hdr;
6305 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006306
Chuck Leverbf269552010-12-14 14:59:29 +00006307 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006308 if (status)
6309 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006311 if (status)
6312 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006313 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006314 if (status)
6315 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006316 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006317out:
6318 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006319}
6320
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006321/*
6322 * Encode an SETACL request
6323 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006324static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006325 const void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006326{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006327 const struct nfs_setaclargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006328 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006329 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006330 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006331
Chuck Lever9f06c712010-12-14 14:59:18 +00006332 encode_compound_hdr(xdr, req, &hdr);
6333 encode_sequence(xdr, &args->seq_args, &hdr);
6334 encode_putfh(xdr, args->fh, &hdr);
6335 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006336 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006337}
Andy Adamson05d564f2008-12-23 16:06:15 -05006338
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006339/*
6340 * Decode SETACL response
6341 */
6342static int
Chuck Leverbf269552010-12-14 14:59:29 +00006343nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006344 void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006345{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006346 struct nfs_setaclres *res = data;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006347 struct compound_hdr hdr;
6348 int status;
6349
Chuck Leverbf269552010-12-14 14:59:29 +00006350 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006351 if (status)
6352 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006353 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006354 if (status)
6355 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006356 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006357 if (status)
6358 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006359 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006360out:
6361 return status;
6362}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006363
6364/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006365 * Decode GETACL response
6366 */
6367static int
Chuck Leverbf269552010-12-14 14:59:29 +00006368nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006369 void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006370{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006371 struct nfs_getaclres *res = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00006372 struct compound_hdr hdr;
6373 int status;
6374
Trond Myklebust331818f2012-02-03 18:30:53 -05006375 if (res->acl_scratch != NULL) {
6376 void *p = page_address(res->acl_scratch);
6377 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6378 }
Chuck Leverbf269552010-12-14 14:59:29 +00006379 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006380 if (status)
6381 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006382 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006383 if (status)
6384 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006385 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006386 if (status)
6387 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006388 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006389
6390out:
6391 return status;
6392}
6393
6394/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006395 * Decode CLOSE response
6396 */
Chuck Leverbf269552010-12-14 14:59:29 +00006397static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006398 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006399{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006400 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006401 struct compound_hdr hdr;
6402 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006403
Chuck Leverbf269552010-12-14 14:59:29 +00006404 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006405 if (status)
6406 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006407 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006408 if (status)
6409 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006411 if (status)
6412 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006413 if (res->lr_res) {
6414 status = decode_layoutreturn(xdr, res->lr_res);
6415 res->lr_ret = status;
6416 if (status)
6417 goto out;
6418 }
Trond Myklebustd8d84982016-12-19 12:14:44 -05006419 if (res->fattr != NULL) {
6420 status = decode_getfattr(xdr, res->fattr, res->server);
6421 if (status != 0)
6422 goto out;
6423 }
Chuck Leverbf269552010-12-14 14:59:29 +00006424 status = decode_close(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006425out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006426 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427}
6428
6429/*
6430 * Decode OPEN response
6431 */
Chuck Leverbf269552010-12-14 14:59:29 +00006432static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006433 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006434{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006435 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006436 struct compound_hdr hdr;
6437 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006438
Chuck Leverbf269552010-12-14 14:59:29 +00006439 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006440 if (status)
6441 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006442 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006443 if (status)
6444 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006445 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006446 if (status)
6447 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006448 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006449 if (status)
6450 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006451 status = decode_getfh(xdr, &res->fh);
6452 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006454 if (res->access_request)
6455 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006456 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Fred Isaman56f487f2016-09-21 11:43:41 -04006457 if (res->lg_res)
6458 decode_layoutget(xdr, rqstp, res->lg_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006459out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006460 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461}
6462
6463/*
6464 * Decode OPEN_CONFIRM response
6465 */
Chuck Leverbf269552010-12-14 14:59:29 +00006466static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6467 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006468 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006469{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006470 struct nfs_open_confirmres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006471 struct compound_hdr hdr;
6472 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006473
Chuck Leverbf269552010-12-14 14:59:29 +00006474 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006475 if (status)
6476 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006477 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006478 if (status)
6479 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006480 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006481out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006482 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006483}
6484
6485/*
6486 * Decode OPEN response
6487 */
Chuck Leverbf269552010-12-14 14:59:29 +00006488static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6489 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006490 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006492 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006493 struct compound_hdr hdr;
6494 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495
Chuck Leverbf269552010-12-14 14:59:29 +00006496 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006497 if (status)
6498 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006499 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006500 if (status)
6501 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006502 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006503 if (status)
6504 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006505 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006506 if (status)
6507 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006508 if (res->access_request)
6509 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006510 decode_getfattr(xdr, res->f_attr, res->server);
Fred Isaman56f487f2016-09-21 11:43:41 -04006511 if (res->lg_res)
6512 decode_layoutget(xdr, rqstp, res->lg_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006514 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006515}
6516
6517/*
6518 * Decode SETATTR response
6519 */
Chuck Leverbf269552010-12-14 14:59:29 +00006520static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6521 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006522 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006523{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006524 struct nfs_setattrres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006525 struct compound_hdr hdr;
6526 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527
Chuck Leverbf269552010-12-14 14:59:29 +00006528 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006529 if (status)
6530 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006531 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006532 if (status)
6533 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006534 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006535 if (status)
6536 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006537 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006538 if (status)
6539 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006540 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006542 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543}
6544
6545/*
6546 * Decode LOCK response
6547 */
Chuck Leverbf269552010-12-14 14:59:29 +00006548static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006549 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006551 struct nfs_lock_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006552 struct compound_hdr hdr;
6553 int status;
6554
Chuck Leverbf269552010-12-14 14:59:29 +00006555 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556 if (status)
6557 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006559 if (status)
6560 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006561 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006562 if (status)
6563 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006564 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006565out:
6566 return status;
6567}
6568
6569/*
6570 * Decode LOCKT response
6571 */
Chuck Leverbf269552010-12-14 14:59:29 +00006572static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006573 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006575 struct nfs_lockt_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006576 struct compound_hdr hdr;
6577 int status;
6578
Chuck Leverbf269552010-12-14 14:59:29 +00006579 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006580 if (status)
6581 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006582 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006583 if (status)
6584 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006585 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006586 if (status)
6587 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006588 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006589out:
6590 return status;
6591}
6592
6593/*
6594 * Decode LOCKU response
6595 */
Chuck Leverbf269552010-12-14 14:59:29 +00006596static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006597 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006598{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006599 struct nfs_locku_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006600 struct compound_hdr hdr;
6601 int status;
6602
Chuck Leverbf269552010-12-14 14:59:29 +00006603 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006604 if (status)
6605 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006606 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006607 if (status)
6608 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006609 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006610 if (status)
6611 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006612 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613out:
6614 return status;
6615}
6616
Chuck Leverbf269552010-12-14 14:59:29 +00006617static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6618 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006619{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006620 struct compound_hdr hdr;
6621 int status;
6622
Chuck Leverbf269552010-12-14 14:59:29 +00006623 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006624 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006625 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006626 return status;
6627}
6628
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629/*
6630 * Decode READLINK response
6631 */
Chuck Leverbf269552010-12-14 14:59:29 +00006632static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6633 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006634 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006635{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006636 struct nfs4_readlink_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006637 struct compound_hdr hdr;
6638 int status;
6639
Chuck Leverbf269552010-12-14 14:59:29 +00006640 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006641 if (status)
6642 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006643 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006644 if (status)
6645 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006646 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647 if (status)
6648 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006649 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650out:
6651 return status;
6652}
6653
6654/*
6655 * Decode READDIR response
6656 */
Chuck Leverbf269552010-12-14 14:59:29 +00006657static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006658 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006659{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006660 struct nfs4_readdir_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006661 struct compound_hdr hdr;
6662 int status;
6663
Chuck Leverbf269552010-12-14 14:59:29 +00006664 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006665 if (status)
6666 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006668 if (status)
6669 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006670 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006671 if (status)
6672 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006673 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006674out:
6675 return status;
6676}
6677
6678/*
6679 * Decode Read response
6680 */
Chuck Leverbf269552010-12-14 14:59:29 +00006681static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006682 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006683{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006684 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006685 struct compound_hdr hdr;
6686 int status;
6687
Chuck Leverbf269552010-12-14 14:59:29 +00006688 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006689 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006690 if (status)
6691 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006692 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006693 if (status)
6694 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006695 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006696 if (status)
6697 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006698 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699 if (!status)
6700 status = res->count;
6701out:
6702 return status;
6703}
6704
6705/*
6706 * Decode WRITE response
6707 */
Chuck Leverbf269552010-12-14 14:59:29 +00006708static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006709 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006710{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006711 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712 struct compound_hdr hdr;
6713 int status;
6714
Chuck Leverbf269552010-12-14 14:59:29 +00006715 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006716 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006717 if (status)
6718 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006719 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006720 if (status)
6721 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006722 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006723 if (status)
6724 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006725 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006726 if (status)
6727 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006728 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006729 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006730 if (!status)
6731 status = res->count;
6732out:
6733 return status;
6734}
6735
6736/*
6737 * Decode COMMIT response
6738 */
Chuck Leverbf269552010-12-14 14:59:29 +00006739static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006740 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006741{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006742 struct nfs_commitres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006743 struct compound_hdr hdr;
6744 int status;
6745
Chuck Leverbf269552010-12-14 14:59:29 +00006746 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006747 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006748 if (status)
6749 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006750 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006751 if (status)
6752 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006753 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006754 if (status)
6755 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006756 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757out:
6758 return status;
6759}
6760
6761/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006762 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006763 */
Chuck Leverbf269552010-12-14 14:59:29 +00006764static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006765 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006767 struct nfs4_fsinfo_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768 struct compound_hdr hdr;
6769 int status;
6770
Chuck Leverbf269552010-12-14 14:59:29 +00006771 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006772 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006773 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006774 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006775 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006776 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006777 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006778 return status;
6779}
6780
6781/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006782 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006783 */
Chuck Leverbf269552010-12-14 14:59:29 +00006784static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006785 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006786{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006787 struct nfs4_pathconf_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006788 struct compound_hdr hdr;
6789 int status;
6790
Chuck Leverbf269552010-12-14 14:59:29 +00006791 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006792 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006793 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006794 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006795 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006796 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006797 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006798 return status;
6799}
6800
6801/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006802 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006803 */
Chuck Leverbf269552010-12-14 14:59:29 +00006804static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006805 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006806{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006807 struct nfs4_statfs_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006808 struct compound_hdr hdr;
6809 int status;
6810
Chuck Leverbf269552010-12-14 14:59:29 +00006811 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006812 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006813 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006814 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006815 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006816 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006817 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006818 return status;
6819}
6820
6821/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006822 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006823 */
Chuck Leverbf269552010-12-14 14:59:29 +00006824static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6825 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006826 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006827{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006828 struct nfs4_server_caps_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006829 struct compound_hdr hdr;
6830 int status;
6831
Chuck Leverbf269552010-12-14 14:59:29 +00006832 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006833 if (status)
6834 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006835 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006836 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006837 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006838 status = decode_putfh(xdr);
6839 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006840 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006841 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006842out:
6843 return status;
6844}
6845
6846/*
6847 * Decode RENEW response
6848 */
Chuck Leverbf269552010-12-14 14:59:29 +00006849static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6850 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006851{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006852 struct compound_hdr hdr;
6853 int status;
6854
Chuck Leverbf269552010-12-14 14:59:29 +00006855 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006856 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006857 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006858 return status;
6859}
6860
6861/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006862 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006863 */
Chuck Leverbf269552010-12-14 14:59:29 +00006864static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6865 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006866 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006867{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006868 struct nfs4_setclientid_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006869 struct compound_hdr hdr;
6870 int status;
6871
Chuck Leverbf269552010-12-14 14:59:29 +00006872 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006873 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006874 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006875 return status;
6876}
6877
6878/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006879 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006880 */
Chuck Leverbf269552010-12-14 14:59:29 +00006881static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006882 struct xdr_stream *xdr,
6883 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006884{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006885 struct compound_hdr hdr;
6886 int status;
6887
Chuck Leverbf269552010-12-14 14:59:29 +00006888 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006889 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006890 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006891 return status;
6892}
6893
6894/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006895 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006896 */
Chuck Leverbf269552010-12-14 14:59:29 +00006897static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6898 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006899 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006900{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006901 struct nfs4_delegreturnres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006902 struct compound_hdr hdr;
6903 int status;
6904
Chuck Leverbf269552010-12-14 14:59:29 +00006905 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006906 if (status)
6907 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006908 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006909 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006910 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006911 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006912 if (status != 0)
6913 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05006914 if (res->lr_res) {
6915 status = decode_layoutreturn(xdr, res->lr_res);
6916 res->lr_ret = status;
6917 if (status)
6918 goto out;
6919 }
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05006920 if (res->fattr) {
6921 status = decode_getfattr(xdr, res->fattr, res->server);
6922 if (status != 0)
6923 goto out;
6924 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006925 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006926out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006927 return status;
6928}
6929
Trond Myklebust683b57b2006-06-09 09:34:22 -04006930/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006931 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006932 */
Chuck Leverbf269552010-12-14 14:59:29 +00006933static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6934 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006935 void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006936{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006937 struct nfs4_fs_locations_res *res = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04006938 struct compound_hdr hdr;
6939 int status;
6940
Chuck Leverbf269552010-12-14 14:59:29 +00006941 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006942 if (status)
6943 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006944 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006945 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006946 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006947 status = decode_putfh(xdr);
6948 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006949 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006950 if (res->migration) {
6951 xdr_enter_page(xdr, PAGE_SIZE);
6952 status = decode_getfattr_generic(xdr,
6953 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006954 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006955 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006956 if (status)
6957 goto out;
6958 if (res->renew)
6959 status = decode_renew(xdr);
6960 } else {
6961 status = decode_lookup(xdr);
6962 if (status)
6963 goto out;
6964 xdr_enter_page(xdr, PAGE_SIZE);
6965 status = decode_getfattr_generic(xdr,
6966 &res->fs_locations->fattr,
6967 NULL, res->fs_locations,
6968 NULL, res->fs_locations->server);
6969 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006970out:
6971 return status;
6972}
6973
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006974/*
6975 * Decode SECINFO response
6976 */
6977static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6978 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006979 void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006980{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006981 struct nfs4_secinfo_res *res = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006982 struct compound_hdr hdr;
6983 int status;
6984
6985 status = decode_compound_hdr(xdr, &hdr);
6986 if (status)
6987 goto out;
6988 status = decode_sequence(xdr, &res->seq_res, rqstp);
6989 if (status)
6990 goto out;
6991 status = decode_putfh(xdr);
6992 if (status)
6993 goto out;
6994 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006995out:
6996 return status;
6997}
6998
Chuck Lever44c99932013-10-17 14:13:30 -04006999/*
7000 * Decode FSID_PRESENT response
7001 */
7002static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7003 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007004 void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04007005{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007006 struct nfs4_fsid_present_res *res = data;
Chuck Lever44c99932013-10-17 14:13:30 -04007007 struct compound_hdr hdr;
7008 int status;
7009
7010 status = decode_compound_hdr(xdr, &hdr);
7011 if (status)
7012 goto out;
7013 status = decode_sequence(xdr, &res->seq_res, rqstp);
7014 if (status)
7015 goto out;
7016 status = decode_putfh(xdr);
7017 if (status)
7018 goto out;
7019 status = decode_getfh(xdr, res->fh);
7020 if (status)
7021 goto out;
7022 if (res->renew)
7023 status = decode_renew(xdr);
7024out:
7025 return status;
7026}
7027
Benny Halevy99fe60d2009-04-01 09:22:29 -04007028#if defined(CONFIG_NFS_V4_1)
7029/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007030 * Decode BIND_CONN_TO_SESSION response
7031 */
7032static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7033 struct xdr_stream *xdr,
7034 void *res)
7035{
7036 struct compound_hdr hdr;
7037 int status;
7038
7039 status = decode_compound_hdr(xdr, &hdr);
7040 if (!status)
7041 status = decode_bind_conn_to_session(xdr, res);
7042 return status;
7043}
7044
7045/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007046 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007047 */
Chuck Leverbf269552010-12-14 14:59:29 +00007048static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7049 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007050 void *res)
7051{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007052 struct compound_hdr hdr;
7053 int status;
7054
Chuck Leverbf269552010-12-14 14:59:29 +00007055 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007056 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007057 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007058 return status;
7059}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007060
7061/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007062 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007063 */
Chuck Leverbf269552010-12-14 14:59:29 +00007064static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7065 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007066 void *res)
Andy Adamsonfc931582009-04-01 09:22:31 -04007067{
Andy Adamsonfc931582009-04-01 09:22:31 -04007068 struct compound_hdr hdr;
7069 int status;
7070
Chuck Leverbf269552010-12-14 14:59:29 +00007071 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007072 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007073 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007074 return status;
7075}
7076
7077/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007078 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007079 */
Chuck Leverbf269552010-12-14 14:59:29 +00007080static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7081 struct xdr_stream *xdr,
7082 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007083{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007084 struct compound_hdr hdr;
7085 int status;
7086
Chuck Leverbf269552010-12-14 14:59:29 +00007087 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007088 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007089 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007090 return status;
7091}
7092
7093/*
Trond Myklebust66245532012-05-25 17:18:09 -04007094 * Decode DESTROY_CLIENTID response
7095 */
7096static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7097 struct xdr_stream *xdr,
7098 void *res)
7099{
7100 struct compound_hdr hdr;
7101 int status;
7102
7103 status = decode_compound_hdr(xdr, &hdr);
7104 if (!status)
7105 status = decode_destroy_clientid(xdr, res);
7106 return status;
7107}
7108
7109/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007110 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007111 */
Chuck Leverbf269552010-12-14 14:59:29 +00007112static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7113 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007114 void *res)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007115{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007116 struct compound_hdr hdr;
7117 int status;
7118
Chuck Leverbf269552010-12-14 14:59:29 +00007119 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007120 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007121 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007122 return status;
7123}
7124
7125/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007126 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007127 */
Chuck Leverbf269552010-12-14 14:59:29 +00007128static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7129 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007130 void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04007131{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007132 struct nfs4_get_lease_time_res *res = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04007133 struct compound_hdr hdr;
7134 int status;
7135
Chuck Leverbf269552010-12-14 14:59:29 +00007136 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007137 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007138 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007139 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007140 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007141 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007142 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007143 return status;
7144}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007145
7146/*
7147 * Decode RECLAIM_COMPLETE response
7148 */
Chuck Leverbf269552010-12-14 14:59:29 +00007149static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7150 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007151 void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05007152{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007153 struct nfs41_reclaim_complete_res *res = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05007154 struct compound_hdr hdr;
7155 int status;
7156
Chuck Leverbf269552010-12-14 14:59:29 +00007157 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007158 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007159 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007160 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307161 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007162 return status;
7163}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007164
7165/*
7166 * Decode GETDEVINFO response
7167 */
Chuck Leverbf269552010-12-14 14:59:29 +00007168static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7169 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007170 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007171{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007172 struct nfs4_getdeviceinfo_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007173 struct compound_hdr hdr;
7174 int status;
7175
Chuck Leverbf269552010-12-14 14:59:29 +00007176 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007177 if (status != 0)
7178 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007179 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007180 if (status != 0)
7181 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007182 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007183out:
7184 return status;
7185}
7186
7187/*
7188 * Decode LAYOUTGET response
7189 */
Chuck Leverbf269552010-12-14 14:59:29 +00007190static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7191 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007192 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007193{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007194 struct nfs4_layoutget_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007195 struct compound_hdr hdr;
7196 int status;
7197
Chuck Leverbf269552010-12-14 14:59:29 +00007198 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007199 if (status)
7200 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007201 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007202 if (status)
7203 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007204 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007205 if (status)
7206 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007207 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007208out:
7209 return status;
7210}
Andy Adamson863a3c62011-03-23 13:27:54 +00007211
7212/*
Benny Halevycbe82602011-05-22 19:52:37 +03007213 * Decode LAYOUTRETURN response
7214 */
7215static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7216 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007217 void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03007218{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007219 struct nfs4_layoutreturn_res *res = data;
Benny Halevycbe82602011-05-22 19:52:37 +03007220 struct compound_hdr hdr;
7221 int status;
7222
7223 status = decode_compound_hdr(xdr, &hdr);
7224 if (status)
7225 goto out;
7226 status = decode_sequence(xdr, &res->seq_res, rqstp);
7227 if (status)
7228 goto out;
7229 status = decode_putfh(xdr);
7230 if (status)
7231 goto out;
7232 status = decode_layoutreturn(xdr, res);
7233out:
7234 return status;
7235}
7236
7237/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007238 * Decode LAYOUTCOMMIT response
7239 */
7240static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7241 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007242 void *data)
Andy Adamson863a3c62011-03-23 13:27:54 +00007243{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007244 struct nfs4_layoutcommit_res *res = data;
Andy Adamson863a3c62011-03-23 13:27:54 +00007245 struct compound_hdr hdr;
7246 int status;
7247
7248 status = decode_compound_hdr(xdr, &hdr);
7249 if (status)
7250 goto out;
7251 status = decode_sequence(xdr, &res->seq_res, rqstp);
7252 if (status)
7253 goto out;
7254 status = decode_putfh(xdr);
7255 if (status)
7256 goto out;
7257 status = decode_layoutcommit(xdr, rqstp, res);
7258 if (status)
7259 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007260 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007261out:
7262 return status;
7263}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007264
7265/*
7266 * Decode SECINFO_NO_NAME response
7267 */
7268static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7269 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007270 void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007271{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007272 struct nfs4_secinfo_res *res = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007273 struct compound_hdr hdr;
7274 int status;
7275
7276 status = decode_compound_hdr(xdr, &hdr);
7277 if (status)
7278 goto out;
7279 status = decode_sequence(xdr, &res->seq_res, rqstp);
7280 if (status)
7281 goto out;
7282 status = decode_putrootfh(xdr);
7283 if (status)
7284 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007285 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007286out:
7287 return status;
7288}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007289
7290/*
7291 * Decode TEST_STATEID response
7292 */
7293static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7294 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007295 void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04007296{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007297 struct nfs41_test_stateid_res *res = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04007298 struct compound_hdr hdr;
7299 int status;
7300
7301 status = decode_compound_hdr(xdr, &hdr);
7302 if (status)
7303 goto out;
7304 status = decode_sequence(xdr, &res->seq_res, rqstp);
7305 if (status)
7306 goto out;
7307 status = decode_test_stateid(xdr, res);
7308out:
7309 return status;
7310}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007311
7312/*
7313 * Decode FREE_STATEID response
7314 */
7315static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7316 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007317 void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007318{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007319 struct nfs41_free_stateid_res *res = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007320 struct compound_hdr hdr;
7321 int status;
7322
7323 status = decode_compound_hdr(xdr, &hdr);
7324 if (status)
7325 goto out;
7326 status = decode_sequence(xdr, &res->seq_res, rqstp);
7327 if (status)
7328 goto out;
7329 status = decode_free_stateid(xdr, res);
7330out:
7331 return status;
7332}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007333#endif /* CONFIG_NFS_V4_1 */
7334
Chuck Lever573c4e12010-12-14 14:58:11 +00007335/**
7336 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7337 * the local page cache.
7338 * @xdr: XDR stream where entry resides
7339 * @entry: buffer to fill in with entry data
7340 * @plus: boolean indicating whether this should be a readdirplus entry
7341 *
7342 * Returns zero if successful, otherwise a negative errno value is
7343 * returned.
7344 *
7345 * This function is not invoked during READDIR reply decoding, but
7346 * rather whenever an application invokes the getdents(2) system call
7347 * on a directory already in our cache.
7348 */
7349int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -04007350 bool plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007351{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007352 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007353 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007354 uint32_t len;
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007355 uint64_t new_cookie;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007356 __be32 *p = xdr_inline_decode(xdr, 4);
7357 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007358 return -EAGAIN;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007359 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007360 p = xdr_inline_decode(xdr, 4);
7361 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007362 return -EAGAIN;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007363 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007364 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007365 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007366 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007367 }
7368
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007369 p = xdr_inline_decode(xdr, 12);
7370 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007371 return -EAGAIN;
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007372 p = xdr_decode_hyper(p, &new_cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007373 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007374
Trond Myklebust9af8c222010-10-24 11:52:55 -04007375 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007376 if (unlikely(!p))
Chuck Levereb72f482019-02-11 11:24:21 -05007377 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007378 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007379
7380 /*
7381 * In case the server doesn't return an inode number,
7382 * we fake one here. (We don't use inode number 0,
7383 * since glibc seems to choke on it...)
7384 */
7385 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007386 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007387
Trond Myklebust9af8c222010-10-24 11:52:55 -04007388 if (decode_attr_bitmap(xdr, bitmap) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05007389 return -EAGAIN;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007390
Trond Myklebust256e48b2012-06-21 11:18:13 -04007391 if (decode_attr_length(xdr, &len, &savep) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05007392 return -EAGAIN;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007393
Chuck Lever573c4e12010-12-14 14:58:11 +00007394 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007395 NULL, entry->label, entry->server) < 0)
Chuck Levereb72f482019-02-11 11:24:21 -05007396 return -EAGAIN;
Trond Myklebust28331a42011-04-27 13:47:52 -04007397 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7398 entry->ino = entry->fattr->mounted_on_fileid;
7399 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007400 entry->ino = entry->fattr->fileid;
7401
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007402 entry->d_type = DT_UNKNOWN;
7403 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7404 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7405
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007406 entry->prev_cookie = entry->cookie;
7407 entry->cookie = new_cookie;
7408
Chuck Lever573c4e12010-12-14 14:58:11 +00007409 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007410}
7411
7412/*
7413 * We need to translate between nfs status return values and
7414 * the local errno values which may not be the same.
7415 */
7416static struct {
7417 int stat;
7418 int errno;
7419} nfs_errtbl[] = {
7420 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007421 { NFS4ERR_PERM, -EPERM },
7422 { NFS4ERR_NOENT, -ENOENT },
7423 { NFS4ERR_IO, -errno_NFSERR_IO},
7424 { NFS4ERR_NXIO, -ENXIO },
7425 { NFS4ERR_ACCESS, -EACCES },
7426 { NFS4ERR_EXIST, -EEXIST },
7427 { NFS4ERR_XDEV, -EXDEV },
7428 { NFS4ERR_NOTDIR, -ENOTDIR },
7429 { NFS4ERR_ISDIR, -EISDIR },
7430 { NFS4ERR_INVAL, -EINVAL },
7431 { NFS4ERR_FBIG, -EFBIG },
7432 { NFS4ERR_NOSPC, -ENOSPC },
7433 { NFS4ERR_ROFS, -EROFS },
7434 { NFS4ERR_MLINK, -EMLINK },
7435 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7436 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7437 { NFS4ERR_DQUOT, -EDQUOT },
7438 { NFS4ERR_STALE, -ESTALE },
7439 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007440 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7441 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7442 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007443 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007444 { NFS4ERR_BADTYPE, -EBADTYPE },
7445 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007446 { NFS4ERR_SYMLINK, -ELOOP },
7447 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7448 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007449 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007450};
7451
7452/*
7453 * Convert an NFS error code to a local one.
7454 * This one is used jointly by NFSv2 and NFSv3.
7455 */
7456static int
David Howells0a8ea432006-08-22 20:06:08 -04007457nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007458{
7459 int i;
7460 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7461 if (nfs_errtbl[i].stat == stat)
7462 return nfs_errtbl[i].errno;
7463 }
7464 if (stat <= 10000 || stat > 10100) {
7465 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007466 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007467 }
7468 /* If we cannot translate the error, the recovery routines should
7469 * handle it.
7470 * Note: remaining NFSv4 error codes have values > 10000, so should
7471 * not conflict with native Linux error codes.
7472 */
Benny Halevy856dff32008-03-31 17:39:06 +03007473 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007474}
7475
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007476#ifdef CONFIG_NFS_V4_2
7477#include "nfs42xdr.c"
7478#endif /* CONFIG_NFS_V4_2 */
7479
Linus Torvalds1da177e2005-04-16 15:20:36 -07007480#define PROC(proc, argtype, restype) \
7481[NFSPROC4_CLNT_##proc] = { \
7482 .p_proc = NFSPROC4_COMPOUND, \
Christoph Hellwigfcc85812017-05-08 10:01:49 +02007483 .p_encode = nfs4_xdr_##argtype, \
Christoph Hellwigfc016482017-05-08 15:09:02 +02007484 .p_decode = nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007485 .p_arglen = NFS4_##argtype##_sz, \
7486 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007487 .p_statidx = NFSPROC4_CLNT_##proc, \
7488 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007489}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007490
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007491#define STUB(proc) \
7492[NFSPROC4_CLNT_##proc] = { \
7493 .p_name = #proc, \
7494}
7495
Trond Myklebust8634ef52018-01-06 09:53:49 -05007496#if defined(CONFIG_NFS_V4_1)
7497#define PROC41(proc, argtype, restype) \
7498 PROC(proc, argtype, restype)
7499#else
7500#define PROC41(proc, argtype, restype) \
7501 STUB(proc)
7502#endif
7503
7504#if defined(CONFIG_NFS_V4_2)
7505#define PROC42(proc, argtype, restype) \
7506 PROC(proc, argtype, restype)
7507#else
7508#define PROC42(proc, argtype, restype) \
7509 STUB(proc)
7510#endif
7511
Christoph Hellwig511e9362017-05-12 15:36:49 +02007512const struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007513 PROC(READ, enc_read, dec_read),
7514 PROC(WRITE, enc_write, dec_write),
7515 PROC(COMMIT, enc_commit, dec_commit),
7516 PROC(OPEN, enc_open, dec_open),
7517 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7518 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7519 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7520 PROC(CLOSE, enc_close, dec_close),
7521 PROC(SETATTR, enc_setattr, dec_setattr),
7522 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7523 PROC(RENEW, enc_renew, dec_renew),
7524 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7525 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7526 PROC(LOCK, enc_lock, dec_lock),
7527 PROC(LOCKT, enc_lockt, dec_lockt),
7528 PROC(LOCKU, enc_locku, dec_locku),
7529 PROC(ACCESS, enc_access, dec_access),
7530 PROC(GETATTR, enc_getattr, dec_getattr),
7531 PROC(LOOKUP, enc_lookup, dec_lookup),
7532 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7533 PROC(REMOVE, enc_remove, dec_remove),
7534 PROC(RENAME, enc_rename, dec_rename),
7535 PROC(LINK, enc_link, dec_link),
7536 PROC(SYMLINK, enc_symlink, dec_symlink),
7537 PROC(CREATE, enc_create, dec_create),
7538 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7539 PROC(STATFS, enc_statfs, dec_statfs),
7540 PROC(READLINK, enc_readlink, dec_readlink),
7541 PROC(READDIR, enc_readdir, dec_readdir),
7542 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7543 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7544 PROC(GETACL, enc_getacl, dec_getacl),
7545 PROC(SETACL, enc_setacl, dec_setacl),
7546 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7547 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007548 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007549 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007550 PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7551 PROC41(CREATE_SESSION, enc_create_session, dec_create_session),
7552 PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7553 PROC41(SEQUENCE, enc_sequence, dec_sequence),
7554 PROC41(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7555 PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete),
7556 PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7557 PROC41(LAYOUTGET, enc_layoutget, dec_layoutget),
7558 PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7559 PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7560 PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7561 PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7562 PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007563 STUB(GETDEVICELIST),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007564 PROC41(BIND_CONN_TO_SESSION,
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007565 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007566 PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid),
7567 PROC42(SEEK, enc_seek, dec_seek),
7568 PROC42(ALLOCATE, enc_allocate, dec_allocate),
7569 PROC42(DEALLOCATE, enc_deallocate, dec_deallocate),
7570 PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
7571 PROC42(CLONE, enc_clone, dec_clone),
7572 PROC42(COPY, enc_copy, dec_copy),
Olga Kornievskaiacb95dee2018-07-09 15:13:29 -04007573 PROC42(OFFLOAD_CANCEL, enc_offload_cancel, dec_offload_cancel),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007574 PROC(LOOKUPP, enc_lookupp, dec_lookupp),
Trond Myklebust3eb86092019-02-08 10:31:05 -05007575 PROC42(LAYOUTERROR, enc_layouterror, dec_layouterror),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007576};
7577
Christoph Hellwigc5518582017-05-08 23:27:10 +02007578static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
Trond Myklebusta613fa12012-01-20 13:53:56 -05007579const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007580 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007581 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Christoph Hellwigc5518582017-05-08 23:27:10 +02007582 .procs = nfs4_procedures,
7583 .counts = nfs_version4_counts,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007584};
7585
7586/*
7587 * Local variables:
7588 * c-basic-offset: 8
7589 * End:
7590 */