blob: fbdad9e1719fd6ea52548edb4443e4b2a4201582 [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>
55#include <linux/nfs_idmap.h>
Chuck Leverf0920752012-05-21 22:45:41 -040056
Trond Myklebust4ce79712005-06-22 17:16:21 +000057#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050058#include "internal.h"
Trond Myklebust76e697b2012-11-26 14:20:49 -050059#include "nfs4session.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040060#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040061#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63#define NFSDBG_FACILITY NFSDBG_XDR
64
65/* Mapping from NFS error code to "errno" error code. */
66#define errno_NFSERR_IO EIO
67
David Howells0a8ea432006-08-22 20:06:08 -040068static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
71#ifdef DEBUG
72#define NFS4_MAXTAGLEN 20
73#else
74#define NFS4_MAXTAGLEN 0
75#endif
76
Andy Adamson6c0195a2008-12-23 16:06:15 -050077/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040078 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040080#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050081#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040082#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85#define op_encode_hdr_maxsz (1)
86#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040087#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
90#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
92 (NFS4_FHSIZE >> 2))
93#define decode_putfh_maxsz (op_decode_hdr_maxsz)
94#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
95#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
96#define encode_getfh_maxsz (op_encode_hdr_maxsz)
97#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
98 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040099#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +0000100#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
102#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400103#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
104#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
David Quigleyaa9c2662013-05-22 12:50:44 -0400105#ifdef CONFIG_NFS_V4_SECURITY_LABEL
106/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
107#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
108#define encode_readdir_space 24
109#define encode_readdir_bitmask_sz 3
110#else
111#define nfs4_label_maxsz 0
112#define encode_readdir_space 20
113#define encode_readdir_bitmask_sz 2
114#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400115/* We support only one layout type per file system */
116#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000117/* This is based on getfattr, which uses the most attributes: */
118#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400119 3 + 3 + 3 + nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400120 nfs4_group_maxsz + nfs4_label_maxsz + \
121 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000122#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
123 nfs4_fattr_value_maxsz)
124#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400125#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
126 1 + 2 + 1 + \
127 nfs4_owner_maxsz + \
128 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400129 nfs4_label_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400130 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#define encode_savefh_maxsz (op_encode_hdr_maxsz)
132#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400133#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
134#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200135#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400136/* The 5 accounts for the PNFS attributes, and assumes that at most three
137 * layout types will be returned.
138 */
139#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
140 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
142#define decode_renew_maxsz (op_decode_hdr_maxsz)
143#define encode_setclientid_maxsz \
144 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500145 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
146 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
147 1 /* sc_prog */ + \
148 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
149 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
150 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#define decode_setclientid_maxsz \
152 (op_decode_hdr_maxsz + \
153 2 + \
154 1024) /* large value for CLID_INUSE */
155#define encode_setclientid_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 3 + (NFS4_VERIFIER_SIZE >> 2))
158#define decode_setclientid_confirm_maxsz \
159 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400160#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
161#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400162#define encode_share_access_maxsz \
163 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500164#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400165#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
166#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
167#define encode_open_maxsz (op_encode_hdr_maxsz + \
168 2 + encode_share_access_maxsz + 2 + \
169 open_owner_id_maxsz + \
170 encode_opentype_maxsz + \
171 encode_claim_null_maxsz)
172#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400173#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400174 decode_ace_maxsz)
175#define decode_change_info_maxsz (5)
176#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400177 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400178 decode_change_info_maxsz + 1 + \
179 nfs4_fattr_bitmap_maxsz + \
180 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400181#define encode_open_confirm_maxsz \
182 (op_encode_hdr_maxsz + \
183 encode_stateid_maxsz + 1)
184#define decode_open_confirm_maxsz \
185 (op_decode_hdr_maxsz + \
186 decode_stateid_maxsz)
187#define encode_open_downgrade_maxsz \
188 (op_encode_hdr_maxsz + \
189 encode_stateid_maxsz + 1 + \
190 encode_share_access_maxsz)
191#define decode_open_downgrade_maxsz \
192 (op_decode_hdr_maxsz + \
193 decode_stateid_maxsz)
194#define encode_close_maxsz (op_encode_hdr_maxsz + \
195 1 + encode_stateid_maxsz)
196#define decode_close_maxsz (op_decode_hdr_maxsz + \
197 decode_stateid_maxsz)
198#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
199 encode_stateid_maxsz + \
200 encode_attrs_maxsz)
201#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
202 nfs4_fattr_bitmap_maxsz)
203#define encode_read_maxsz (op_encode_hdr_maxsz + \
204 encode_stateid_maxsz + 3)
205#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
206#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400207 2 + encode_verifier_maxsz + 5 + \
208 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400209#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400210 decode_verifier_maxsz + \
211 nfs4_label_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400212#define encode_readlink_maxsz (op_encode_hdr_maxsz)
213#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
214#define encode_write_maxsz (op_encode_hdr_maxsz + \
215 encode_stateid_maxsz + 4)
216#define decode_write_maxsz (op_decode_hdr_maxsz + \
217 2 + decode_verifier_maxsz)
218#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
219#define decode_commit_maxsz (op_decode_hdr_maxsz + \
220 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221#define encode_remove_maxsz (op_encode_hdr_maxsz + \
222 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400223#define decode_remove_maxsz (op_decode_hdr_maxsz + \
224 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#define encode_rename_maxsz (op_encode_hdr_maxsz + \
226 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400227#define decode_rename_maxsz (op_decode_hdr_maxsz + \
228 decode_change_info_maxsz + \
229 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230#define encode_link_maxsz (op_encode_hdr_maxsz + \
231 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400232#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400233#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400234#define encode_lock_maxsz (op_encode_hdr_maxsz + \
235 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400236 1 + encode_stateid_maxsz + 1 + \
237 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400238#define decode_lock_denied_maxsz \
239 (8 + decode_lockowner_maxsz)
240#define decode_lock_maxsz (op_decode_hdr_maxsz + \
241 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400242#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
243 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400244#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
245 decode_lock_denied_maxsz)
246#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
247 encode_stateid_maxsz + \
248 4)
249#define decode_locku_maxsz (op_decode_hdr_maxsz + \
250 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400251#define encode_release_lockowner_maxsz \
252 (op_encode_hdr_maxsz + \
253 encode_lockowner_maxsz)
254#define decode_release_lockowner_maxsz \
255 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400256#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
257#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
259 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400260 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000261 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
263#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400264 1 + 2 + nfs4_name_maxsz + \
265 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400266#define decode_create_maxsz (op_decode_hdr_maxsz + \
267 decode_change_info_maxsz + \
268 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400269#define encode_statfs_maxsz (encode_getattr_maxsz)
270#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
272#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400273#define encode_getacl_maxsz (encode_getattr_maxsz)
274#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
275 nfs4_fattr_bitmap_maxsz + 1)
276#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
277 encode_stateid_maxsz + 3)
278#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400279#define encode_fs_locations_maxsz \
280 (encode_getattr_maxsz)
281#define decode_fs_locations_maxsz \
282 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000283#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400284#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 -0400285
286#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400287#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500288#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
289 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400290
Benny Halevy99fe60d2009-04-01 09:22:29 -0400291#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
292 encode_verifier_maxsz + \
293 1 /* co_ownerid.len */ + \
294 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
295 1 /* flags */ + \
296 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400297 /* max is SP4_MACH_CRED (for now) */ + \
298 1 + NFS4_OP_MAP_NUM_WORDS + \
299 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500300 1 /* implementation id array of size 1 */ + \
301 1 /* nii_domain */ + \
302 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
303 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500304 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500305 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400306#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
307 2 /* eir_clientid */ + \
308 1 /* eir_sequenceid */ + \
309 1 /* eir_flags */ + \
310 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400311 /* max is SP4_MACH_CRED (for now) */ + \
312 1 + NFS4_OP_MAP_NUM_WORDS + \
313 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400314 2 /* eir_server_owner.so_minor_id */ + \
315 /* eir_server_owner.so_major_id<> */ \
316 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
317 /* eir_server_scope<> */ \
318 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
319 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500320 1 /* nii_domain */ + \
321 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
322 1 /* nii_name */ + \
323 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
324 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400325#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
326#define decode_channel_attrs_maxsz (6 + \
327 1 /* ca_rdma_ird.len */ + \
328 1 /* ca_rdma_ird */)
329#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
330 2 /* csa_clientid */ + \
331 1 /* csa_sequence */ + \
332 1 /* csa_flags */ + \
333 encode_channel_attrs_maxsz + \
334 encode_channel_attrs_maxsz + \
335 1 /* csa_cb_program */ + \
336 1 /* csa_sec_parms.len (1) */ + \
337 1 /* cb_secflavor (AUTH_SYS) */ + \
338 1 /* stamp */ + \
339 1 /* machinename.len */ + \
340 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
341 1 /* uid */ + \
342 1 /* gid */ + \
343 1 /* gids.len (0) */)
344#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
345 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
346 1 /* csr_sequence */ + \
347 1 /* csr_flags */ + \
348 decode_channel_attrs_maxsz + \
349 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400350#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
351 /* bctsa_sessid */ \
352 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
353 1 /* bctsa_dir */ + \
354 1 /* bctsa_use_conn_in_rdma_mode */)
355#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
356 /* bctsr_sessid */ \
357 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
358 1 /* bctsr_dir */ + \
359 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400360#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
361#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400362#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
363#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400364#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
365 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
366#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
367 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500368#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
369#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400370#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
371 encode_verifier_maxsz)
372#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
373 2 /* nfs_cookie4 gdlr_cookie */ + \
374 decode_verifier_maxsz \
375 /* verifier4 gdlr_verifier */ + \
376 1 /* gdlr_deviceid_list count */ + \
377 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
378 NFS4_DEVICEID4_SIZE) \
379 /* gdlr_deviceid_list */ + \
380 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400381#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
382 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
383#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
384 1 /* layout type */ + \
385 1 /* opaque devaddr4 length */ + \
386 /* devaddr4 payload is read into page */ \
387 1 /* notification bitmap length */ + \
388 1 /* notification bitmap */)
389#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
390 encode_stateid_maxsz)
391#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
392 decode_stateid_maxsz + \
393 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000394#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
395 2 /* offset */ + \
396 2 /* length */ + \
397 1 /* reclaim */ + \
398 encode_stateid_maxsz + \
399 1 /* new offset (true) */ + \
400 2 /* last byte written */ + \
401 1 /* nt_timechanged (false) */ + \
402 1 /* layoutupdate4 layout type */ + \
403 1 /* NULL filelayout layoutupdate4 payload */)
404#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300405#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
406 encode_stateid_maxsz + \
407 1 /* FIXME: opaque lrf_body always empty at the moment */)
408#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
409 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400410#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
411#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400412#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
413 XDR_QUADLEN(NFS4_STATEID_SIZE))
414#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400415#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
416 XDR_QUADLEN(NFS4_STATEID_SIZE))
417#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400418#else /* CONFIG_NFS_V4_1 */
419#define encode_sequence_maxsz 0
420#define decode_sequence_maxsz 0
421#endif /* CONFIG_NFS_V4_1 */
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
424#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
425#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400426 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400428 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400432 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400434 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400436 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400438 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400440 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_enc_readdir_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_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define NFS4_dec_readdir_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_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#define NFS4_enc_write_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_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400453 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400455 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400457 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400458 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400460 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400462 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400464 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400466 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400468 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400469 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400470 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400471 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400472 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400473 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400475 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400477 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400478 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400479 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400480 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400481#define NFS4_enc_open_confirm_sz \
482 (compound_encode_hdr_maxsz + \
483 encode_putfh_maxsz + \
484 encode_open_confirm_maxsz)
485#define NFS4_dec_open_confirm_sz \
486 (compound_decode_hdr_maxsz + \
487 decode_putfh_maxsz + \
488 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400490 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400492 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400493 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400494 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400498 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400499 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400500 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501#define NFS4_enc_open_downgrade_sz \
502 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400503 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400504 encode_putfh_maxsz + \
505 encode_open_downgrade_maxsz + \
506 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#define NFS4_dec_open_downgrade_sz \
508 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400509 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400510 decode_putfh_maxsz + \
511 decode_open_downgrade_maxsz + \
512 decode_getattr_maxsz)
513#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400514 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400515 encode_putfh_maxsz + \
516 encode_close_maxsz + \
517 encode_getattr_maxsz)
518#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400519 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400520 decode_putfh_maxsz + \
521 decode_close_maxsz + \
522 decode_getattr_maxsz)
523#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400524 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400525 encode_putfh_maxsz + \
526 encode_setattr_maxsz + \
527 encode_getattr_maxsz)
528#define NFS4_dec_setattr_sz (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 + \
531 decode_setattr_maxsz + \
532 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 encode_putfh_maxsz + \
536 encode_fsinfo_maxsz)
537#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 decode_putfh_maxsz + \
540 decode_fsinfo_maxsz)
541#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
542 encode_renew_maxsz)
543#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
544 decode_renew_maxsz)
545#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
546 encode_setclientid_maxsz)
547#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
548 decode_setclientid_maxsz)
549#define NFS4_enc_setclientid_confirm_sz \
550 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400551 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552#define NFS4_dec_setclientid_confirm_sz \
553 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400554 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_enc_lock_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 + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400558 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#define NFS4_dec_lock_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 + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400562 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400566 encode_lockt_maxsz)
567#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400569 decode_putfh_maxsz + \
570 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400574 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400576 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400578 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400579#define NFS4_enc_release_lockowner_sz \
580 (compound_encode_hdr_maxsz + \
581 encode_lockowner_maxsz)
582#define NFS4_dec_release_lockowner_sz \
583 (compound_decode_hdr_maxsz + \
584 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585#define NFS4_enc_access_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 Myklebust76b32992007-08-10 17:45:11 -0400588 encode_access_maxsz + \
589 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400591 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400593 decode_access_maxsz + \
594 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 encode_putfh_maxsz + \
598 encode_getattr_maxsz)
599#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400600 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 decode_putfh_maxsz + \
602 decode_getattr_maxsz)
603#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400604 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 encode_putfh_maxsz + \
606 encode_lookup_maxsz + \
607 encode_getattr_maxsz + \
608 encode_getfh_maxsz)
609#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400610 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400612 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 decode_getattr_maxsz + \
614 decode_getfh_maxsz)
615#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400616 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 encode_putrootfh_maxsz + \
618 encode_getattr_maxsz + \
619 encode_getfh_maxsz)
620#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400621 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 decode_putrootfh_maxsz + \
623 decode_getattr_maxsz + \
624 decode_getfh_maxsz)
625#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400626 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400628 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400630 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400632 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400634 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 encode_putfh_maxsz + \
636 encode_savefh_maxsz + \
637 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400638 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400640 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 decode_putfh_maxsz + \
642 decode_savefh_maxsz + \
643 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400644 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400646 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 encode_putfh_maxsz + \
648 encode_savefh_maxsz + \
649 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400650 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400651 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400652 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 decode_putfh_maxsz + \
656 decode_savefh_maxsz + \
657 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400658 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400659 decode_restorefh_maxsz + \
660 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661#define NFS4_enc_symlink_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 + \
664 encode_symlink_maxsz + \
665 encode_getattr_maxsz + \
666 encode_getfh_maxsz)
667#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400668 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 decode_putfh_maxsz + \
670 decode_symlink_maxsz + \
671 decode_getattr_maxsz + \
672 decode_getfh_maxsz)
673#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400674 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 encode_putfh_maxsz + \
676 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400677 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400678 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 decode_putfh_maxsz + \
682 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400683 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400684 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400686 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 encode_putfh_maxsz + \
688 encode_getattr_maxsz)
689#define NFS4_dec_pathconf_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_getattr_maxsz)
693#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400694 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400696 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400698 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400700 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400702 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800703 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 encode_getattr_maxsz)
705#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400706 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800707 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 decode_getattr_maxsz)
709#define NFS4_enc_delegreturn_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 + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100712 encode_delegreturn_maxsz + \
713 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400715 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100716 decode_delegreturn_maxsz + \
717 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000718#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400719 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000720 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400721 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000722#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400723 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000724 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400725 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000726#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400727 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000728 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400729 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000730#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400731 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000732 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400733 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400734#define NFS4_enc_fs_locations_sz \
735 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400736 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400737 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400738 encode_lookup_maxsz + \
739 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400740#define NFS4_dec_fs_locations_sz \
741 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400742 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400743 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400744 decode_lookup_maxsz + \
745 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000746#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
747 encode_sequence_maxsz + \
748 encode_putfh_maxsz + \
749 encode_secinfo_maxsz)
750#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
751 decode_sequence_maxsz + \
752 decode_putfh_maxsz + \
753 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400754#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400755#define NFS4_enc_bind_conn_to_session_sz \
756 (compound_encode_hdr_maxsz + \
757 encode_bind_conn_to_session_maxsz)
758#define NFS4_dec_bind_conn_to_session_sz \
759 (compound_decode_hdr_maxsz + \
760 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400761#define NFS4_enc_exchange_id_sz \
762 (compound_encode_hdr_maxsz + \
763 encode_exchange_id_maxsz)
764#define NFS4_dec_exchange_id_sz \
765 (compound_decode_hdr_maxsz + \
766 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400767#define NFS4_enc_create_session_sz \
768 (compound_encode_hdr_maxsz + \
769 encode_create_session_maxsz)
770#define NFS4_dec_create_session_sz \
771 (compound_decode_hdr_maxsz + \
772 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400773#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
774 encode_destroy_session_maxsz)
775#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
776 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400777#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
778 encode_destroy_clientid_maxsz)
779#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
780 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400781#define NFS4_enc_sequence_sz \
782 (compound_decode_hdr_maxsz + \
783 encode_sequence_maxsz)
784#define NFS4_dec_sequence_sz \
785 (compound_decode_hdr_maxsz + \
786 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400787#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
788 encode_sequence_maxsz + \
789 encode_putrootfh_maxsz + \
790 encode_fsinfo_maxsz)
791#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
792 decode_sequence_maxsz + \
793 decode_putrootfh_maxsz + \
794 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500795#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
796 encode_sequence_maxsz + \
797 encode_reclaim_complete_maxsz)
798#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
799 decode_sequence_maxsz + \
800 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400801#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
802 encode_sequence_maxsz + \
803 encode_putfh_maxsz + \
804 encode_getdevicelist_maxsz)
805#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
806 decode_sequence_maxsz + \
807 decode_putfh_maxsz + \
808 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400809#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz +\
811 encode_getdeviceinfo_maxsz)
812#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
813 decode_sequence_maxsz + \
814 decode_getdeviceinfo_maxsz)
815#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
816 encode_sequence_maxsz + \
817 encode_putfh_maxsz + \
818 encode_layoutget_maxsz)
819#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
820 decode_sequence_maxsz + \
821 decode_putfh_maxsz + \
822 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000823#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
824 encode_sequence_maxsz +\
825 encode_putfh_maxsz + \
826 encode_layoutcommit_maxsz + \
827 encode_getattr_maxsz)
828#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
829 decode_sequence_maxsz + \
830 decode_putfh_maxsz + \
831 decode_layoutcommit_maxsz + \
832 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300833#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
834 encode_sequence_maxsz + \
835 encode_putfh_maxsz + \
836 encode_layoutreturn_maxsz)
837#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
838 decode_sequence_maxsz + \
839 decode_putfh_maxsz + \
840 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400841#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
842 encode_sequence_maxsz + \
843 encode_putrootfh_maxsz +\
844 encode_secinfo_no_name_maxsz)
845#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
846 decode_sequence_maxsz + \
847 decode_putrootfh_maxsz + \
848 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400849#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
850 encode_sequence_maxsz + \
851 encode_test_stateid_maxsz)
852#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
853 decode_sequence_maxsz + \
854 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400855#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
856 encode_sequence_maxsz + \
857 encode_free_stateid_maxsz)
858#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
859 decode_sequence_maxsz + \
860 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500861
862const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
863 compound_encode_hdr_maxsz +
864 encode_sequence_maxsz +
865 encode_putfh_maxsz +
866 encode_getattr_maxsz) *
867 XDR_UNIT);
868
869const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
870 compound_decode_hdr_maxsz +
871 decode_sequence_maxsz +
872 decode_putfh_maxsz) *
873 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400874
875const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
876 compound_decode_hdr_maxsz +
877 decode_sequence_maxsz) *
878 XDR_UNIT);
879EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400880#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Trond Myklebustbca79472009-03-11 14:10:26 -0400882static const umode_t nfs_type2fmt[] = {
883 [NF4BAD] = 0,
884 [NF4REG] = S_IFREG,
885 [NF4DIR] = S_IFDIR,
886 [NF4BLK] = S_IFBLK,
887 [NF4CHR] = S_IFCHR,
888 [NF4LNK] = S_IFLNK,
889 [NF4SOCK] = S_IFSOCK,
890 [NF4FIFO] = S_IFIFO,
891 [NF4ATTRDIR] = 0,
892 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893};
894
895struct compound_hdr {
896 int32_t status;
897 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500898 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 uint32_t taglen;
900 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400901 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400902 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903};
904
Benny Halevy13c65ce2009-08-14 17:19:25 +0300905static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
906{
907 __be32 *p = xdr_reserve_space(xdr, nbytes);
908 BUG_ON(!p);
909 return p;
910}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
Trond Myklebustcb17e552012-03-04 18:13:56 -0500912static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
913{
914 __be32 *p;
915
916 p = xdr_reserve_space(xdr, len);
917 xdr_encode_opaque_fixed(p, buf, len);
918}
919
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
921{
Al Viro8687b632006-10-19 23:28:48 -0700922 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500924 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 xdr_encode_opaque(p, str, len);
926}
927
Trond Myklebust4ade9822012-03-04 18:13:57 -0500928static void encode_uint32(struct xdr_stream *xdr, u32 n)
929{
930 __be32 *p;
931
932 p = reserve_space(xdr, 4);
933 *p = cpu_to_be32(n);
934}
935
Trond Myklebustff2eb682012-03-05 11:40:12 -0500936static void encode_uint64(struct xdr_stream *xdr, u64 n)
937{
938 __be32 *p;
939
940 p = reserve_space(xdr, 8);
941 xdr_encode_hyper(p, n);
942}
943
Trond Myklebust4ade9822012-03-04 18:13:57 -0500944static void encode_nfs4_seqid(struct xdr_stream *xdr,
945 const struct nfs_seqid *seqid)
946{
947 encode_uint32(xdr, seqid->sequence->counter);
948}
949
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400950static void encode_compound_hdr(struct xdr_stream *xdr,
951 struct rpc_rqst *req,
952 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953{
Al Viro8687b632006-10-19 23:28:48 -0700954 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400955 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400956
957 /* initialize running count of expected bytes in reply.
958 * NOTE: the replied tag SHOULD be the same is the one sent,
959 * but this is not required as a MUST for the server to do so. */
960 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Trond Myklebust7fc38842012-10-15 11:51:21 -0400962 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500963 encode_string(xdr, hdr->taglen, hdr->tag);
964 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300965 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500966 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300967 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500968}
969
Trond Myklebustab19b482012-03-04 18:13:57 -0500970static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
971 uint32_t replen,
972 struct compound_hdr *hdr)
973{
974 encode_uint32(xdr, op);
975 hdr->nops++;
976 hdr->replen += replen;
977}
978
Andy Adamsond0179312008-12-23 16:06:17 -0500979static void encode_nops(struct compound_hdr *hdr)
980{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400981 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500982 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983}
984
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500985static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
986{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500987 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500988}
989
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
991{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500992 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993}
994
David Quigleyaa9c2662013-05-22 12:50:44 -0400995static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
996 const struct nfs4_label *label,
997 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998{
999 char owner_name[IDMAP_NAMESZ];
1000 char owner_group[IDMAP_NAMESZ];
1001 int owner_namelen = 0;
1002 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001003 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001004 unsigned i;
1005 uint32_t len = 0;
1006 uint32_t bmval_len;
1007 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009 /*
1010 * We reserve enough space to write the entire attribute buffer at once.
1011 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001012 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1013 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001014 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001016 if (iap->ia_valid & ATTR_SIZE) {
1017 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001019 }
1020 if (iap->ia_valid & ATTR_MODE) {
1021 bmval[1] |= FATTR4_WORD1_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 len += 4;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001023 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001025 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001027 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001028 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 /* XXX */
1030 strcpy(owner_name, "nobody");
1031 owner_namelen = sizeof("nobody") - 1;
1032 /* goto out; */
1033 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001034 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1036 }
1037 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001038 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001040 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001041 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 strcpy(owner_group, "nobody");
1043 owner_grouplen = sizeof("nobody") - 1;
1044 /* goto out; */
1045 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001046 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1048 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001050 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1051 len += 16;
1052 } else if (iap->ia_valid & ATTR_ATIME) {
1053 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1054 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 }
1056 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001057 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1058 len += 16;
1059 } else if (iap->ia_valid & ATTR_MTIME) {
1060 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1061 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001063 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001064 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1065 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1066 }
1067
1068 if (bmval[2] != 0)
1069 bmval_len = 3;
1070 else if (bmval[1] != 0)
1071 bmval_len = 2;
1072 else
1073 bmval_len = 1;
1074
1075 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1076
1077 *p++ = cpu_to_be32(bmval_len);
1078 for (i = 0; i < bmval_len; i++)
1079 *p++ = cpu_to_be32(bmval[i]);
1080 *p++ = cpu_to_be32(len);
1081
1082 if (bmval[0] & FATTR4_WORD0_SIZE)
1083 p = xdr_encode_hyper(p, iap->ia_size);
1084 if (bmval[1] & FATTR4_WORD1_MODE)
1085 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1086 if (bmval[1] & FATTR4_WORD1_OWNER)
1087 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1088 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1089 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1090 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1091 if (iap->ia_valid & ATTR_ATIME_SET) {
1092 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1093 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1094 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1095 } else
1096 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1097 }
1098 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1099 if (iap->ia_valid & ATTR_MTIME_SET) {
1100 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1101 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1102 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1103 } else
1104 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1105 }
1106 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001107 *p++ = cpu_to_be32(label->lfs);
1108 *p++ = cpu_to_be32(label->pi);
1109 *p++ = cpu_to_be32(label->len);
1110 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1111 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001112
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114}
1115
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001116static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001118 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1119 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120}
1121
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001122static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123{
Trond Myklebustab19b482012-03-04 18:13:57 -05001124 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001125 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001126 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127}
1128
Fred Isaman0b7c0152012-04-20 14:47:39 -04001129static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130{
Al Viro8687b632006-10-19 23:28:48 -07001131 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001132
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001133 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1134 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001135 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001136 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137}
1138
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001139static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140{
Al Viro8687b632006-10-19 23:28:48 -07001141 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001142
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001143 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1144 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146 switch (create->ftype) {
1147 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001148 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001149 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001150 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 break;
1152
1153 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001154 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001155 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001156 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 break;
1158
1159 default:
1160 break;
1161 }
1162
Benny Halevy811652b2009-08-14 17:19:34 +03001163 encode_string(xdr, create->name->len, create->name->name);
David Quigleyaa9c2662013-05-22 12:50:44 -04001164 encode_attrs(xdr, create->attrs, create->label, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165}
1166
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001167static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
Andy Adamson05d564f2008-12-23 16:06:15 -05001169 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001171 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1172 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001173 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001174 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175}
1176
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001177static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178{
Andy Adamson05d564f2008-12-23 16:06:15 -05001179 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001181 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1182 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001183 *p++ = cpu_to_be32(2);
1184 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001185 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186}
1187
Fred Isamandae100c2011-07-30 20:52:37 -04001188static void
1189encode_getattr_three(struct xdr_stream *xdr,
1190 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1191 struct compound_hdr *hdr)
1192{
1193 __be32 *p;
1194
Trond Myklebustab19b482012-03-04 18:13:57 -05001195 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001196 if (bm2) {
1197 p = reserve_space(xdr, 16);
1198 *p++ = cpu_to_be32(3);
1199 *p++ = cpu_to_be32(bm0);
1200 *p++ = cpu_to_be32(bm1);
1201 *p = cpu_to_be32(bm2);
1202 } else if (bm1) {
1203 p = reserve_space(xdr, 12);
1204 *p++ = cpu_to_be32(2);
1205 *p++ = cpu_to_be32(bm0);
1206 *p = cpu_to_be32(bm1);
1207 } else {
1208 p = reserve_space(xdr, 8);
1209 *p++ = cpu_to_be32(1);
1210 *p = cpu_to_be32(bm0);
1211 }
Fred Isamandae100c2011-07-30 20:52:37 -04001212}
1213
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001214static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215{
David Quigleya09df2c2013-05-22 12:50:41 -04001216 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1217 bitmask[1] & nfs4_fattr_bitmap[1],
1218 bitmask[2] & nfs4_fattr_bitmap[2],
1219 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220}
1221
Andy Adamson88034c32012-05-23 05:02:34 -04001222static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001223 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001224 struct compound_hdr *hdr)
1225{
1226 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001227 bitmask[0] & open_bitmap[0],
1228 bitmask[1] & open_bitmap[1],
1229 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001230 hdr);
1231}
1232
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001233static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234{
Fred Isamandae100c2011-07-30 20:52:37 -04001235 encode_getattr_three(xdr,
1236 bitmask[0] & nfs4_fsinfo_bitmap[0],
1237 bitmask[1] & nfs4_fsinfo_bitmap[1],
1238 bitmask[2] & nfs4_fsinfo_bitmap[2],
1239 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240}
1241
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001242static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001243{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001244 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1245 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001246}
1247
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001248static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Trond Myklebustab19b482012-03-04 18:13:57 -05001250 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251}
1252
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001253static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254{
Trond Myklebustab19b482012-03-04 18:13:57 -05001255 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001256 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257}
1258
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001259static inline int nfs4_lock_type(struct file_lock *fl, int block)
1260{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001261 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001262 return block ? NFS4_READW_LT : NFS4_READ_LT;
1263 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1264}
1265
1266static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1267{
1268 if (fl->fl_end == OFFSET_MAX)
1269 return ~(uint64_t)0;
1270 return fl->fl_end - fl->fl_start + 1;
1271}
1272
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001273static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1274{
1275 __be32 *p;
1276
Trond Myklebustd035c362010-12-21 10:45:27 -05001277 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001278 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001279 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001280 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001281 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001282 xdr_encode_hyper(p, lowner->id);
1283}
1284
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285/*
1286 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1287 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1288 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001289static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290{
Al Viro8687b632006-10-19 23:28:48 -07001291 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001293 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1294 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001295 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1296 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001297 p = xdr_encode_hyper(p, args->fl->fl_start);
1298 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001299 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001300 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001301 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001302 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001303 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001304 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 }
1306 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001307 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001308 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310}
1311
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001312static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313{
Al Viro8687b632006-10-19 23:28:48 -07001314 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001316 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1317 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001318 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001319 p = xdr_encode_hyper(p, args->fl->fl_start);
1320 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001321 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322}
1323
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001324static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325{
Al Viro8687b632006-10-19 23:28:48 -07001326 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001328 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1329 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001330 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001331 encode_nfs4_stateid(xdr, args->stateid);
1332 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001333 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001334 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335}
1336
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001337static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1338{
Trond Myklebustab19b482012-03-04 18:13:57 -05001339 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001340 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001341}
1342
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001343static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344{
Trond Myklebustab19b482012-03-04 18:13:57 -05001345 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001346 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001349static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350{
Al Viro8687b632006-10-19 23:28:48 -07001351 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Benny Halevy13c65ce2009-08-14 17:19:25 +03001353 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001354 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001355 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001356 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001357 break;
1358 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001359 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001360 break;
1361 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001362 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001363 break;
1364 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001365 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 }
Benny Halevy34558512009-08-14 17:19:30 +03001367 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368}
1369
1370static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1371{
Al Viro8687b632006-10-19 23:28:48 -07001372 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 /*
1374 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1375 * owner 4 = 32
1376 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001377 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001378 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001379 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001380 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001381 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001382 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001383 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001384 *p++ = cpu_to_be32(arg->id.uniquifier);
1385 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386}
1387
1388static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1389{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001390 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001391 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
Benny Halevy13c65ce2009-08-14 17:19:25 +03001393 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001394 switch(arg->createmode) {
1395 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001396 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001397 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Andy Adamson05d564f2008-12-23 16:06:15 -05001398 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001399 case NFS4_CREATE_GUARDED:
1400 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001401 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001402 break;
1403 case NFS4_CREATE_EXCLUSIVE:
1404 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1405 encode_nfs4_verifier(xdr, &arg->u.verifier);
1406 break;
1407 case NFS4_CREATE_EXCLUSIVE4_1:
1408 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1409 encode_nfs4_verifier(xdr, &arg->u.verifier);
1410 dummy.ia_valid = 0;
David Quigleyaa9c2662013-05-22 12:50:44 -04001411 encode_attrs(xdr, &dummy, arg->label, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 }
1413}
1414
1415static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1416{
Al Viro8687b632006-10-19 23:28:48 -07001417 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Benny Halevy13c65ce2009-08-14 17:19:25 +03001419 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001421 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001422 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001423 break;
1424 default:
Benny Halevy34558512009-08-14 17:19:30 +03001425 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001426 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 }
1428}
1429
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001430static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431{
Al Viro8687b632006-10-19 23:28:48 -07001432 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Benny Halevy13c65ce2009-08-14 17:19:25 +03001434 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001436 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001437 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001438 break;
1439 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001440 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001441 break;
1442 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001443 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001444 break;
1445 default:
1446 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 }
1448}
1449
1450static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1451{
Al Viro8687b632006-10-19 23:28:48 -07001452 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
Benny Halevy13c65ce2009-08-14 17:19:25 +03001454 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001455 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 encode_string(xdr, name->len, name->name);
1457}
1458
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001459static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460{
Al Viro8687b632006-10-19 23:28:48 -07001461 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Benny Halevy13c65ce2009-08-14 17:19:25 +03001463 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001464 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 encode_delegation_type(xdr, type);
1466}
1467
1468static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1469{
Al Viro8687b632006-10-19 23:28:48 -07001470 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001472 p = reserve_space(xdr, 4);
1473 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1474 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 encode_string(xdr, name->len, name->name);
1476}
1477
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001478static inline void encode_claim_fh(struct xdr_stream *xdr)
1479{
1480 __be32 *p;
1481
1482 p = reserve_space(xdr, 4);
1483 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1484}
1485
1486static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1487{
1488 __be32 *p;
1489
1490 p = reserve_space(xdr, 4);
1491 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1492 encode_nfs4_stateid(xdr, stateid);
1493}
1494
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001495static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496{
Trond Myklebustab19b482012-03-04 18:13:57 -05001497 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 encode_openhdr(xdr, arg);
1499 encode_opentype(xdr, arg);
1500 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001501 case NFS4_OPEN_CLAIM_NULL:
1502 encode_claim_null(xdr, arg->name);
1503 break;
1504 case NFS4_OPEN_CLAIM_PREVIOUS:
1505 encode_claim_previous(xdr, arg->u.delegation_type);
1506 break;
1507 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1508 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1509 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001510 case NFS4_OPEN_CLAIM_FH:
1511 encode_claim_fh(xdr);
1512 break;
1513 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1514 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1515 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001516 default:
1517 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519}
1520
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001521static 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 -07001522{
Trond Myklebustab19b482012-03-04 18:13:57 -05001523 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001524 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001525 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526}
1527
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001528static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529{
Trond Myklebustab19b482012-03-04 18:13:57 -05001530 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001531 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001532 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001533 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534}
1535
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001536static void
Andy Adamsond0179312008-12-23 16:06:17 -05001537encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538{
Trond Myklebustab19b482012-03-04 18:13:57 -05001539 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001540 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541}
1542
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001543static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544{
Trond Myklebustab19b482012-03-04 18:13:57 -05001545 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546}
1547
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001548static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549{
Al Viro8687b632006-10-19 23:28:48 -07001550 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
Trond Myklebustab19b482012-03-04 18:13:57 -05001552 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001553 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Benny Halevy13c65ce2009-08-14 17:19:25 +03001555 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001556 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001557 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558}
1559
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001560static 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 -07001561{
David Quigleyaa9c2662013-05-22 12:50:44 -04001562 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001563 FATTR4_WORD0_RDATTR_ERROR,
1564 FATTR4_WORD1_MOUNTED_ON_FILEID,
1565 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001566 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001567 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001569 if (readdir->plus) {
1570 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001571 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001572 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1573 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1574 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1575 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001576 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001577 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001578 /* Use mounted_on_fileid only if the server supports it */
1579 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1580 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001581
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001582 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001583 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001584 encode_nfs4_verifier(xdr, &readdir->verifier);
David Quigleyaa9c2662013-05-22 12:50:44 -04001585 p = reserve_space(xdr, encode_readdir_space);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001586 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001587 *p++ = cpu_to_be32(readdir->count);
David Quigleyaa9c2662013-05-22 12:50:44 -04001588 *p++ = cpu_to_be32(encode_readdir_bitmask_sz);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001589 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
David Quigleyaa9c2662013-05-22 12:50:44 -04001590 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1591 if (encode_readdir_bitmask_sz > 2) {
1592 if (hdr->minorversion > 1)
1593 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1594 p++, *p++ = cpu_to_be32(attrs[2] & readdir->bitmask[2]);
1595 }
Chuck Levercd937102012-03-02 17:14:31 -05001596 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001597
1598 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001599 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001600 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001601 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001602 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001603 attrs[1] & readdir->bitmask[1],
1604 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605}
1606
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001607static 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 -07001608{
Trond Myklebustab19b482012-03-04 18:13:57 -05001609 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610}
1611
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001612static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613{
Trond Myklebustab19b482012-03-04 18:13:57 -05001614 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001615 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616}
1617
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001618static 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 -07001619{
Trond Myklebustab19b482012-03-04 18:13:57 -05001620 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001621 encode_string(xdr, oldname->len, oldname->name);
1622 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623}
1624
Chuck Leverbb4dae52012-03-01 17:01:48 -05001625static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1626 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001628 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001629 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630}
1631
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001632static void
Andy Adamsond0179312008-12-23 16:06:17 -05001633encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001634{
Trond Myklebustab19b482012-03-04 18:13:57 -05001635 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001636}
1637
Chuck Lever9f06c712010-12-14 14:59:18 +00001638static void
Andy Adamsond0179312008-12-23 16:06:17 -05001639encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001640{
Al Viro8687b632006-10-19 23:28:48 -07001641 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001642
Trond Myklebustab19b482012-03-04 18:13:57 -05001643 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001644 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001645 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001646 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001647 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001648 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001649 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001650 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001651}
1652
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001653static void
Andy Adamsond0179312008-12-23 16:06:17 -05001654encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655{
Trond Myklebustab19b482012-03-04 18:13:57 -05001656 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657}
1658
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001659static 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 -07001660{
Trond Myklebustab19b482012-03-04 18:13:57 -05001661 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001662 encode_nfs4_stateid(xdr, &arg->stateid);
David Quigleyaa9c2662013-05-22 12:50:44 -04001663 encode_attrs(xdr, arg->iap, arg->label, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664}
1665
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001666static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667{
Al Viro8687b632006-10-19 23:28:48 -07001668 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
Trond Myklebust70019512012-03-04 20:49:32 -05001670 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001671 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
1673 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001674 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001675 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1677 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001678 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001679 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680}
1681
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001682static 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 -07001683{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001684 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1685 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001686 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001687 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688}
1689
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001690static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691{
Al Viro8687b632006-10-19 23:28:48 -07001692 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
Trond Myklebustab19b482012-03-04 18:13:57 -05001694 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001695 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696
Benny Halevy13c65ce2009-08-14 17:19:25 +03001697 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001698 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001699 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001700 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
1702 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703}
1704
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001705static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706{
Trond Myklebustab19b482012-03-04 18:13:57 -05001707 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001708 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001710
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001711static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1712{
Trond Myklebustab19b482012-03-04 18:13:57 -05001713 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001714 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001715}
1716
Benny Halevy99fe60d2009-04-01 09:22:29 -04001717#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001718/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001719static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1720 struct nfs4_session *session,
1721 struct compound_hdr *hdr)
1722{
1723 __be32 *p;
1724
1725 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1726 decode_bind_conn_to_session_maxsz, hdr);
1727 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1728 p = xdr_reserve_space(xdr, 8);
1729 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1730 *p = 0; /* use_conn_in_rdma_mode = False */
1731}
1732
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001733static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1734{
1735 unsigned int i;
1736 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1737 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1738 encode_uint32(xdr, op_map->u.words[i]);
1739}
1740
Benny Halevy99fe60d2009-04-01 09:22:29 -04001741static void encode_exchange_id(struct xdr_stream *xdr,
1742 struct nfs41_exchange_id_args *args,
1743 struct compound_hdr *hdr)
1744{
1745 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001746 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001747 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001748
Trond Myklebust70019512012-03-04 20:49:32 -05001749 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001750 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001751
1752 encode_string(xdr, args->id_len, args->id);
1753
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001754 encode_uint32(xdr, args->flags);
1755 encode_uint32(xdr, args->state_protect.how);
1756
1757 switch (args->state_protect.how) {
1758 case SP4_NONE:
1759 break;
1760 case SP4_MACH_CRED:
1761 encode_op_map(xdr, &args->state_protect.enforce);
1762 encode_op_map(xdr, &args->state_protect.allow);
1763 break;
1764 default:
1765 WARN_ON_ONCE(1);
1766 break;
1767 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001768
1769 if (send_implementation_id &&
1770 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1771 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001772 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001773 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1774 utsname()->sysname, utsname()->release,
1775 utsname()->version, utsname()->machine);
1776
1777 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001778 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001779
1780 encode_string(xdr,
1781 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1782 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1783 encode_string(xdr, len, impl_name);
1784 /* just send zeros for nii_date - the date is in nii_name */
1785 p = reserve_space(xdr, 12);
1786 p = xdr_encode_hyper(p, 0);
1787 *p = cpu_to_be32(0);
1788 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001789 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001790}
Andy Adamsonfc931582009-04-01 09:22:31 -04001791
1792static void encode_create_session(struct xdr_stream *xdr,
1793 struct nfs41_create_session_args *args,
1794 struct compound_hdr *hdr)
1795{
1796 __be32 *p;
1797 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1798 uint32_t len;
1799 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001800 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001801 u32 max_resp_sz_cached;
1802
1803 /*
1804 * Assumes OPEN is the biggest non-idempotent compound.
1805 * 2 is the verifier.
1806 */
1807 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1808 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001809
Andy Adamsonfc931582009-04-01 09:22:31 -04001810 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1811 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001812
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001813 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1814 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001815 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001816 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1817 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001818
Andy Adamsonfc931582009-04-01 09:22:31 -04001819 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001820 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001821 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1822 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001823 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001824 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1825 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1826 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001827
1828 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001829 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001830 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1831 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1832 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1833 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1834 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1835 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001836
Benny Halevye75bc1c2009-08-14 17:18:54 +03001837 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001838 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001839 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001840
1841 /* authsys_parms rfc1831 */
Trond Myklebust17f26b12013-08-21 15:48:42 -04001842 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001843 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001844 *p++ = cpu_to_be32(0); /* UID */
1845 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001846 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001847}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001848
1849static void encode_destroy_session(struct xdr_stream *xdr,
1850 struct nfs4_session *session,
1851 struct compound_hdr *hdr)
1852{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001853 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1854 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001855}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001856
Trond Myklebust66245532012-05-25 17:18:09 -04001857static void encode_destroy_clientid(struct xdr_stream *xdr,
1858 uint64_t clientid,
1859 struct compound_hdr *hdr)
1860{
1861 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1862 encode_uint64(xdr, clientid);
1863}
1864
Ricardo Labiaga180197532009-12-05 16:08:40 -05001865static void encode_reclaim_complete(struct xdr_stream *xdr,
1866 struct nfs41_reclaim_complete_args *args,
1867 struct compound_hdr *hdr)
1868{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001869 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1870 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001871}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001872#endif /* CONFIG_NFS_V4_1 */
1873
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001874static void encode_sequence(struct xdr_stream *xdr,
1875 const struct nfs4_sequence_args *args,
1876 struct compound_hdr *hdr)
1877{
1878#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001879 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001880 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001881 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001882 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001883
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001884 tp = slot->table;
1885 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001886 if (!session)
1887 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001888
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001889 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001890
1891 /*
1892 * Sessionid + seqid + slotid + max slotid + cache_this
1893 */
1894 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1895 "max_slotid=%d cache_this=%d\n",
1896 __func__,
1897 ((u32 *)session->sess_id.data)[0],
1898 ((u32 *)session->sess_id.data)[1],
1899 ((u32 *)session->sess_id.data)[2],
1900 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001901 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001902 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001903 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001904 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001905 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001906 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001907 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001908 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001909#endif /* CONFIG_NFS_V4_1 */
1910}
1911
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001912#ifdef CONFIG_NFS_V4_1
1913static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001914encode_getdevicelist(struct xdr_stream *xdr,
1915 const struct nfs4_getdevicelist_args *args,
1916 struct compound_hdr *hdr)
1917{
1918 __be32 *p;
1919 nfs4_verifier dummy = {
1920 .data = "dummmmmy",
1921 };
1922
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001923 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1924 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001925 *p++ = cpu_to_be32(args->layoutclass);
1926 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1927 xdr_encode_hyper(p, 0ULL); /* cookie */
1928 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001929}
1930
1931static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001932encode_getdeviceinfo(struct xdr_stream *xdr,
1933 const struct nfs4_getdeviceinfo_args *args,
1934 struct compound_hdr *hdr)
1935{
1936 __be32 *p;
1937
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001938 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1939 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001940 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1941 NFS4_DEVICEID4_SIZE);
1942 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001943 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001944 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001945}
1946
1947static void
1948encode_layoutget(struct xdr_stream *xdr,
1949 const struct nfs4_layoutget_args *args,
1950 struct compound_hdr *hdr)
1951{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001952 __be32 *p;
1953
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001954 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1955 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001956 *p++ = cpu_to_be32(0); /* Signal layout available */
1957 *p++ = cpu_to_be32(args->type);
1958 *p++ = cpu_to_be32(args->range.iomode);
1959 p = xdr_encode_hyper(p, args->range.offset);
1960 p = xdr_encode_hyper(p, args->range.length);
1961 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001962 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001963 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001964
1965 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1966 __func__,
1967 args->type,
1968 args->range.iomode,
1969 (unsigned long)args->range.offset,
1970 (unsigned long)args->range.length,
1971 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001972}
Andy Adamson863a3c62011-03-23 13:27:54 +00001973
1974static int
1975encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001976 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001977 const struct nfs4_layoutcommit_args *args,
1978 struct compound_hdr *hdr)
1979{
1980 __be32 *p;
1981
1982 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1983 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1984
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001985 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1986 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001987 /* Only whole file layouts */
1988 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001989 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001990 *p = cpu_to_be32(0); /* reclaim */
1991 encode_nfs4_stateid(xdr, &args->stateid);
1992 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001993 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1994 p = xdr_encode_hyper(p, args->lastbytewritten);
1995 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1996 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001997
1998 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1999 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2000 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002001 else
2002 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00002003
Andy Adamson863a3c62011-03-23 13:27:54 +00002004 return 0;
2005}
Benny Halevycbe82602011-05-22 19:52:37 +03002006
2007static void
2008encode_layoutreturn(struct xdr_stream *xdr,
2009 const struct nfs4_layoutreturn_args *args,
2010 struct compound_hdr *hdr)
2011{
2012 __be32 *p;
2013
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002014 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2015 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002016 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2017 *p++ = cpu_to_be32(args->layout_type);
2018 *p++ = cpu_to_be32(IOMODE_ANY);
2019 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002020 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002021 p = xdr_encode_hyper(p, 0);
2022 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2023 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002024 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002025 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002026 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2027 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2028 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002029 } else
2030 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002031}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002032
2033static int
2034encode_secinfo_no_name(struct xdr_stream *xdr,
2035 const struct nfs41_secinfo_no_name_args *args,
2036 struct compound_hdr *hdr)
2037{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002038 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2039 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002040 return 0;
2041}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002042
2043static void encode_test_stateid(struct xdr_stream *xdr,
2044 struct nfs41_test_stateid_args *args,
2045 struct compound_hdr *hdr)
2046{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002047 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2048 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002049 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002050}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002051
2052static void encode_free_stateid(struct xdr_stream *xdr,
2053 struct nfs41_free_stateid_args *args,
2054 struct compound_hdr *hdr)
2055{
Trond Myklebustab19b482012-03-04 18:13:57 -05002056 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002057 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002058}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002059#endif /* CONFIG_NFS_V4_1 */
2060
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061/*
2062 * END OF "GENERIC" ENCODE ROUTINES.
2063 */
2064
Benny Halevy66cc0422009-04-01 09:22:10 -04002065static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2066{
2067#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002068 struct nfs4_session *session = args->sa_slot->table->session;
2069 if (session)
2070 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002071#endif /* CONFIG_NFS_V4_1 */
2072 return 0;
2073}
2074
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075/*
2076 * Encode an ACCESS request
2077 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002078static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2079 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002082 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
Chuck Lever9f06c712010-12-14 14:59:18 +00002085 encode_compound_hdr(xdr, req, &hdr);
2086 encode_sequence(xdr, &args->seq_args, &hdr);
2087 encode_putfh(xdr, args->fh, &hdr);
2088 encode_access(xdr, args->access, &hdr);
2089 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002090 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091}
2092
2093/*
2094 * Encode LOOKUP request
2095 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002096static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2097 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002100 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
Chuck Lever9f06c712010-12-14 14:59:18 +00002103 encode_compound_hdr(xdr, req, &hdr);
2104 encode_sequence(xdr, &args->seq_args, &hdr);
2105 encode_putfh(xdr, args->dir_fh, &hdr);
2106 encode_lookup(xdr, args->name, &hdr);
2107 encode_getfh(xdr, &hdr);
2108 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002109 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110}
2111
2112/*
2113 * Encode LOOKUP_ROOT request
2114 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002115static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2116 struct xdr_stream *xdr,
2117 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118{
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_putrootfh(xdr, &hdr);
2126 encode_getfh(xdr, &hdr);
2127 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002128 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129}
2130
2131/*
2132 * Encode REMOVE request
2133 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002134static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2135 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002138 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
Chuck Lever9f06c712010-12-14 14:59:18 +00002141 encode_compound_hdr(xdr, req, &hdr);
2142 encode_sequence(xdr, &args->seq_args, &hdr);
2143 encode_putfh(xdr, args->fh, &hdr);
2144 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002145 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146}
2147
2148/*
2149 * Encode RENAME request
2150 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002151static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2152 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002155 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
Chuck Lever9f06c712010-12-14 14:59:18 +00002158 encode_compound_hdr(xdr, req, &hdr);
2159 encode_sequence(xdr, &args->seq_args, &hdr);
2160 encode_putfh(xdr, args->old_dir, &hdr);
2161 encode_savefh(xdr, &hdr);
2162 encode_putfh(xdr, args->new_dir, &hdr);
2163 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002164 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165}
2166
2167/*
2168 * Encode LINK request
2169 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002170static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2171 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002174 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
Chuck Lever9f06c712010-12-14 14:59:18 +00002177 encode_compound_hdr(xdr, req, &hdr);
2178 encode_sequence(xdr, &args->seq_args, &hdr);
2179 encode_putfh(xdr, args->fh, &hdr);
2180 encode_savefh(xdr, &hdr);
2181 encode_putfh(xdr, args->dir_fh, &hdr);
2182 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002183 encode_restorefh(xdr, &hdr);
2184 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002185 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186}
2187
2188/*
2189 * Encode CREATE request
2190 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002191static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2192 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002195 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
Chuck Lever9f06c712010-12-14 14:59:18 +00002198 encode_compound_hdr(xdr, req, &hdr);
2199 encode_sequence(xdr, &args->seq_args, &hdr);
2200 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002201 encode_create(xdr, args, &hdr);
2202 encode_getfh(xdr, &hdr);
2203 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002204 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205}
2206
2207/*
2208 * Encode SYMLINK request
2209 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002210static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2211 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212{
Chuck Lever9f06c712010-12-14 14:59:18 +00002213 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214}
2215
2216/*
2217 * Encode GETATTR request
2218 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002219static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2220 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002223 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225
Chuck Lever9f06c712010-12-14 14:59:18 +00002226 encode_compound_hdr(xdr, req, &hdr);
2227 encode_sequence(xdr, &args->seq_args, &hdr);
2228 encode_putfh(xdr, args->fh, &hdr);
2229 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002230 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231}
2232
2233/*
2234 * Encode a CLOSE request
2235 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002236static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2237 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238{
Andy Adamson05d564f2008-12-23 16:06:15 -05002239 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002240 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002241 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
Chuck Lever9f06c712010-12-14 14:59:18 +00002243 encode_compound_hdr(xdr, req, &hdr);
2244 encode_sequence(xdr, &args->seq_args, &hdr);
2245 encode_putfh(xdr, args->fh, &hdr);
2246 encode_close(xdr, args, &hdr);
2247 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002248 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249}
2250
2251/*
2252 * Encode an OPEN request
2253 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002254static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2255 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002258 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260
Chuck Lever9f06c712010-12-14 14:59:18 +00002261 encode_compound_hdr(xdr, req, &hdr);
2262 encode_sequence(xdr, &args->seq_args, &hdr);
2263 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002264 encode_open(xdr, args, &hdr);
2265 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002266 if (args->access)
2267 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002268 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002269 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270}
2271
2272/*
2273 * Encode an OPEN_CONFIRM request
2274 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002275static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2276 struct xdr_stream *xdr,
2277 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002280 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282
Chuck Lever9f06c712010-12-14 14:59:18 +00002283 encode_compound_hdr(xdr, req, &hdr);
2284 encode_putfh(xdr, args->fh, &hdr);
2285 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002286 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287}
2288
2289/*
2290 * Encode an OPEN request with no attributes.
2291 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002292static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2293 struct xdr_stream *xdr,
2294 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002297 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299
Chuck Lever9f06c712010-12-14 14:59:18 +00002300 encode_compound_hdr(xdr, req, &hdr);
2301 encode_sequence(xdr, &args->seq_args, &hdr);
2302 encode_putfh(xdr, args->fh, &hdr);
2303 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002304 if (args->access)
2305 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002306 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002307 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308}
2309
2310/*
2311 * Encode an OPEN_DOWNGRADE request
2312 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002313static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2314 struct xdr_stream *xdr,
2315 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002318 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
Chuck Lever9f06c712010-12-14 14:59:18 +00002321 encode_compound_hdr(xdr, req, &hdr);
2322 encode_sequence(xdr, &args->seq_args, &hdr);
2323 encode_putfh(xdr, args->fh, &hdr);
2324 encode_open_downgrade(xdr, args, &hdr);
2325 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002326 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327}
2328
2329/*
2330 * Encode a LOCK request
2331 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002332static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2333 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002336 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
Chuck Lever9f06c712010-12-14 14:59:18 +00002339 encode_compound_hdr(xdr, req, &hdr);
2340 encode_sequence(xdr, &args->seq_args, &hdr);
2341 encode_putfh(xdr, args->fh, &hdr);
2342 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002343 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344}
2345
2346/*
2347 * Encode a LOCKT request
2348 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002349static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2350 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002353 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
Chuck Lever9f06c712010-12-14 14:59:18 +00002356 encode_compound_hdr(xdr, req, &hdr);
2357 encode_sequence(xdr, &args->seq_args, &hdr);
2358 encode_putfh(xdr, args->fh, &hdr);
2359 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002360 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361}
2362
2363/*
2364 * Encode a LOCKU request
2365 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002366static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2367 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002370 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372
Chuck Lever9f06c712010-12-14 14:59:18 +00002373 encode_compound_hdr(xdr, req, &hdr);
2374 encode_sequence(xdr, &args->seq_args, &hdr);
2375 encode_putfh(xdr, args->fh, &hdr);
2376 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002377 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378}
2379
Chuck Lever9f06c712010-12-14 14:59:18 +00002380static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2381 struct xdr_stream *xdr,
2382 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002383{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002384 struct compound_hdr hdr = {
2385 .minorversion = 0,
2386 };
2387
Chuck Lever9f06c712010-12-14 14:59:18 +00002388 encode_compound_hdr(xdr, req, &hdr);
2389 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002390 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002391}
2392
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393/*
2394 * Encode a READLINK request
2395 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002396static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2397 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002400 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
Chuck Lever9f06c712010-12-14 14:59:18 +00002403 encode_compound_hdr(xdr, req, &hdr);
2404 encode_sequence(xdr, &args->seq_args, &hdr);
2405 encode_putfh(xdr, args->fh, &hdr);
2406 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002407
Benny Halevy28f56692009-04-01 09:22:09 -04002408 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002409 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002410 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411}
2412
2413/*
2414 * Encode a READDIR request
2415 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002416static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2417 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002420 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422
Chuck Lever9f06c712010-12-14 14:59:18 +00002423 encode_compound_hdr(xdr, req, &hdr);
2424 encode_sequence(xdr, &args->seq_args, &hdr);
2425 encode_putfh(xdr, args->fh, &hdr);
2426 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002427
Benny Halevy28f56692009-04-01 09:22:09 -04002428 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002429 args->pgbase, args->count);
2430 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002431 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002432 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002433 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434}
2435
2436/*
2437 * Encode a READ request
2438 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002439static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2440 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002443 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
Chuck Lever9f06c712010-12-14 14:59:18 +00002446 encode_compound_hdr(xdr, req, &hdr);
2447 encode_sequence(xdr, &args->seq_args, &hdr);
2448 encode_putfh(xdr, args->fh, &hdr);
2449 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
Benny Halevy28f56692009-04-01 09:22:09 -04002451 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002453 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002454 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455}
2456
2457/*
2458 * Encode an SETATTR request
2459 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002460static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2461 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462{
Andy Adamson05d564f2008-12-23 16:06:15 -05002463 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002464 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002465 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466
Chuck Lever9f06c712010-12-14 14:59:18 +00002467 encode_compound_hdr(xdr, req, &hdr);
2468 encode_sequence(xdr, &args->seq_args, &hdr);
2469 encode_putfh(xdr, args->fh, &hdr);
2470 encode_setattr(xdr, args, args->server, &hdr);
2471 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002472 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473}
2474
2475/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002476 * Encode a GETACL request
2477 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002478static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2479 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002480{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002481 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002482 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002483 };
Benny Halevy28f56692009-04-01 09:22:09 -04002484 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002485
Chuck Lever9f06c712010-12-14 14:59:18 +00002486 encode_compound_hdr(xdr, req, &hdr);
2487 encode_sequence(xdr, &args->seq_args, &hdr);
2488 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002489 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002490 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002491
Benny Halevy28f56692009-04-01 09:22:09 -04002492 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002493 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002494
Andy Adamsond0179312008-12-23 16:06:17 -05002495 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002496}
2497
2498/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 * Encode a WRITE request
2500 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002501static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2502 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002505 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507
Chuck Lever9f06c712010-12-14 14:59:18 +00002508 encode_compound_hdr(xdr, req, &hdr);
2509 encode_sequence(xdr, &args->seq_args, &hdr);
2510 encode_putfh(xdr, args->fh, &hdr);
2511 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002512 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002513 if (args->bitmask)
2514 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002515 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516}
2517
2518/*
2519 * a COMMIT request
2520 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002521static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002522 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002525 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527
Chuck Lever9f06c712010-12-14 14:59:18 +00002528 encode_compound_hdr(xdr, req, &hdr);
2529 encode_sequence(xdr, &args->seq_args, &hdr);
2530 encode_putfh(xdr, args->fh, &hdr);
2531 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002532 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533}
2534
2535/*
2536 * FSINFO request
2537 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002538static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2539 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002542 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544
Chuck Lever9f06c712010-12-14 14:59:18 +00002545 encode_compound_hdr(xdr, req, &hdr);
2546 encode_sequence(xdr, &args->seq_args, &hdr);
2547 encode_putfh(xdr, args->fh, &hdr);
2548 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002549 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550}
2551
2552/*
2553 * a PATHCONF request
2554 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002555static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2556 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002559 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561
Chuck Lever9f06c712010-12-14 14:59:18 +00002562 encode_compound_hdr(xdr, req, &hdr);
2563 encode_sequence(xdr, &args->seq_args, &hdr);
2564 encode_putfh(xdr, args->fh, &hdr);
2565 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002566 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002567 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568}
2569
2570/*
2571 * a STATFS request
2572 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002573static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2574 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002577 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579
Chuck Lever9f06c712010-12-14 14:59:18 +00002580 encode_compound_hdr(xdr, req, &hdr);
2581 encode_sequence(xdr, &args->seq_args, &hdr);
2582 encode_putfh(xdr, args->fh, &hdr);
2583 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002584 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002585 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586}
2587
2588/*
2589 * GETATTR_BITMAP request
2590 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002591static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2592 struct xdr_stream *xdr,
2593 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002596 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598
Chuck Lever9f06c712010-12-14 14:59:18 +00002599 encode_compound_hdr(xdr, req, &hdr);
2600 encode_sequence(xdr, &args->seq_args, &hdr);
2601 encode_putfh(xdr, args->fhandle, &hdr);
2602 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002603 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002604 FATTR4_WORD0_LINK_SUPPORT|
2605 FATTR4_WORD0_SYMLINK_SUPPORT|
2606 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002607 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608}
2609
2610/*
2611 * a RENEW request
2612 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002613static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2614 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002617 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 };
2619
Chuck Lever9f06c712010-12-14 14:59:18 +00002620 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002621 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002622 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623}
2624
2625/*
2626 * a SETCLIENTID request
2627 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002628static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2629 struct xdr_stream *xdr,
2630 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002633 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 };
2635
Chuck Lever9f06c712010-12-14 14:59:18 +00002636 encode_compound_hdr(xdr, req, &hdr);
2637 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002638 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639}
2640
2641/*
2642 * a SETCLIENTID_CONFIRM request
2643 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002644static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2645 struct xdr_stream *xdr,
2646 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002649 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
Chuck Lever9f06c712010-12-14 14:59:18 +00002652 encode_compound_hdr(xdr, req, &hdr);
2653 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002654 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655}
2656
2657/*
2658 * DELEGRETURN request
2659 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002660static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2661 struct xdr_stream *xdr,
2662 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002665 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667
Chuck Lever9f06c712010-12-14 14:59:18 +00002668 encode_compound_hdr(xdr, req, &hdr);
2669 encode_sequence(xdr, &args->seq_args, &hdr);
2670 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002671 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002672 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002673 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674}
2675
2676/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002677 * Encode FS_LOCATIONS request
2678 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002679static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2680 struct xdr_stream *xdr,
2681 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002682{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002683 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002684 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002685 };
Benny Halevy28f56692009-04-01 09:22:09 -04002686 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002687
Chuck Lever9f06c712010-12-14 14:59:18 +00002688 encode_compound_hdr(xdr, req, &hdr);
2689 encode_sequence(xdr, &args->seq_args, &hdr);
2690 encode_putfh(xdr, args->dir_fh, &hdr);
2691 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002692 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002693 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002694
Benny Halevy28f56692009-04-01 09:22:09 -04002695 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002696 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002697 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002698}
2699
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002700/*
2701 * Encode SECINFO request
2702 */
2703static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2704 struct xdr_stream *xdr,
2705 struct nfs4_secinfo_arg *args)
2706{
2707 struct compound_hdr hdr = {
2708 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2709 };
2710
2711 encode_compound_hdr(xdr, req, &hdr);
2712 encode_sequence(xdr, &args->seq_args, &hdr);
2713 encode_putfh(xdr, args->dir_fh, &hdr);
2714 encode_secinfo(xdr, args->name, &hdr);
2715 encode_nops(&hdr);
2716}
2717
Benny Halevy99fe60d2009-04-01 09:22:29 -04002718#if defined(CONFIG_NFS_V4_1)
2719/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002720 * BIND_CONN_TO_SESSION request
2721 */
2722static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2723 struct xdr_stream *xdr,
2724 struct nfs_client *clp)
2725{
2726 struct compound_hdr hdr = {
2727 .minorversion = clp->cl_mvops->minor_version,
2728 };
2729
2730 encode_compound_hdr(xdr, req, &hdr);
2731 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2732 encode_nops(&hdr);
2733}
2734
2735/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002736 * EXCHANGE_ID request
2737 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002738static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2739 struct xdr_stream *xdr,
2740 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002741{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002742 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002743 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002744 };
2745
Chuck Lever9f06c712010-12-14 14:59:18 +00002746 encode_compound_hdr(xdr, req, &hdr);
2747 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002748 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002749}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002750
2751/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002752 * a CREATE_SESSION request
2753 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002754static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2755 struct xdr_stream *xdr,
2756 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002757{
Andy Adamsonfc931582009-04-01 09:22:31 -04002758 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002759 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002760 };
2761
Chuck Lever9f06c712010-12-14 14:59:18 +00002762 encode_compound_hdr(xdr, req, &hdr);
2763 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002764 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002765}
2766
2767/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002768 * a DESTROY_SESSION request
2769 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002770static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2771 struct xdr_stream *xdr,
2772 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002773{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002774 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002775 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002776 };
2777
Chuck Lever9f06c712010-12-14 14:59:18 +00002778 encode_compound_hdr(xdr, req, &hdr);
2779 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002780 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002781}
2782
2783/*
Trond Myklebust66245532012-05-25 17:18:09 -04002784 * a DESTROY_CLIENTID request
2785 */
2786static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2787 struct xdr_stream *xdr,
2788 struct nfs_client *clp)
2789{
2790 struct compound_hdr hdr = {
2791 .minorversion = clp->cl_mvops->minor_version,
2792 };
2793
2794 encode_compound_hdr(xdr, req, &hdr);
2795 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2796 encode_nops(&hdr);
2797}
2798
2799/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002800 * a SEQUENCE request
2801 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002802static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2803 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002804{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002805 struct compound_hdr hdr = {
2806 .minorversion = nfs4_xdr_minorversion(args),
2807 };
2808
Chuck Lever9f06c712010-12-14 14:59:18 +00002809 encode_compound_hdr(xdr, req, &hdr);
2810 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002811 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002812}
2813
2814/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002815 * a GET_LEASE_TIME request
2816 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002817static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2818 struct xdr_stream *xdr,
2819 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002820{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002821 struct compound_hdr hdr = {
2822 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2823 };
Fred Isamandae100c2011-07-30 20:52:37 -04002824 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002825
Chuck Lever9f06c712010-12-14 14:59:18 +00002826 encode_compound_hdr(xdr, req, &hdr);
2827 encode_sequence(xdr, &args->la_seq_args, &hdr);
2828 encode_putrootfh(xdr, &hdr);
2829 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002830 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002831}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002832
2833/*
2834 * a RECLAIM_COMPLETE request
2835 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002836static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2837 struct xdr_stream *xdr,
2838 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002839{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002840 struct compound_hdr hdr = {
2841 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2842 };
2843
Chuck Lever9f06c712010-12-14 14:59:18 +00002844 encode_compound_hdr(xdr, req, &hdr);
2845 encode_sequence(xdr, &args->seq_args, &hdr);
2846 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002847 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002848}
2849
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002850/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002851 * Encode GETDEVICELIST request
2852 */
2853static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2854 struct xdr_stream *xdr,
2855 struct nfs4_getdevicelist_args *args)
2856{
2857 struct compound_hdr hdr = {
2858 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2859 };
2860
2861 encode_compound_hdr(xdr, req, &hdr);
2862 encode_sequence(xdr, &args->seq_args, &hdr);
2863 encode_putfh(xdr, args->fh, &hdr);
2864 encode_getdevicelist(xdr, args, &hdr);
2865 encode_nops(&hdr);
2866}
2867
2868/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002869 * Encode GETDEVICEINFO request
2870 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002871static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2872 struct xdr_stream *xdr,
2873 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002874{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002875 struct compound_hdr hdr = {
2876 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2877 };
2878
Chuck Lever9f06c712010-12-14 14:59:18 +00002879 encode_compound_hdr(xdr, req, &hdr);
2880 encode_sequence(xdr, &args->seq_args, &hdr);
2881 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002882
2883 /* set up reply kvec. Subtract notification bitmap max size (2)
2884 * so that notification bitmap is put in xdr_buf tail */
2885 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2886 args->pdev->pages, args->pdev->pgbase,
2887 args->pdev->pglen);
2888
2889 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002890}
2891
2892/*
2893 * Encode LAYOUTGET request
2894 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002895static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2896 struct xdr_stream *xdr,
2897 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002898{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002899 struct compound_hdr hdr = {
2900 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2901 };
2902
Chuck Lever9f06c712010-12-14 14:59:18 +00002903 encode_compound_hdr(xdr, req, &hdr);
2904 encode_sequence(xdr, &args->seq_args, &hdr);
2905 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2906 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002907
2908 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2909 args->layout.pages, 0, args->layout.pglen);
2910
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002911 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002912}
Andy Adamson863a3c62011-03-23 13:27:54 +00002913
2914/*
2915 * Encode LAYOUTCOMMIT request
2916 */
Benny Halevycbe82602011-05-22 19:52:37 +03002917static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2918 struct xdr_stream *xdr,
2919 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002920{
Benny Halevyac7db722011-05-22 19:53:48 +03002921 struct nfs4_layoutcommit_data *data =
2922 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002923 struct compound_hdr hdr = {
2924 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2925 };
2926
2927 encode_compound_hdr(xdr, req, &hdr);
2928 encode_sequence(xdr, &args->seq_args, &hdr);
2929 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002930 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002931 encode_getfattr(xdr, args->bitmask, &hdr);
2932 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002933}
2934
2935/*
2936 * Encode LAYOUTRETURN request
2937 */
2938static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2939 struct xdr_stream *xdr,
2940 struct nfs4_layoutreturn_args *args)
2941{
2942 struct compound_hdr hdr = {
2943 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2944 };
2945
2946 encode_compound_hdr(xdr, req, &hdr);
2947 encode_sequence(xdr, &args->seq_args, &hdr);
2948 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2949 encode_layoutreturn(xdr, args, &hdr);
2950 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002951}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002952
2953/*
2954 * Encode SECINFO_NO_NAME request
2955 */
2956static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2957 struct xdr_stream *xdr,
2958 struct nfs41_secinfo_no_name_args *args)
2959{
2960 struct compound_hdr hdr = {
2961 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2962 };
2963
2964 encode_compound_hdr(xdr, req, &hdr);
2965 encode_sequence(xdr, &args->seq_args, &hdr);
2966 encode_putrootfh(xdr, &hdr);
2967 encode_secinfo_no_name(xdr, args, &hdr);
2968 encode_nops(&hdr);
2969 return 0;
2970}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002971
2972/*
2973 * Encode TEST_STATEID request
2974 */
2975static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2976 struct xdr_stream *xdr,
2977 struct nfs41_test_stateid_args *args)
2978{
2979 struct compound_hdr hdr = {
2980 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2981 };
2982
2983 encode_compound_hdr(xdr, req, &hdr);
2984 encode_sequence(xdr, &args->seq_args, &hdr);
2985 encode_test_stateid(xdr, args, &hdr);
2986 encode_nops(&hdr);
2987}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002988
2989/*
2990 * Encode FREE_STATEID request
2991 */
2992static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2993 struct xdr_stream *xdr,
2994 struct nfs41_free_stateid_args *args)
2995{
2996 struct compound_hdr hdr = {
2997 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2998 };
2999
3000 encode_compound_hdr(xdr, req, &hdr);
3001 encode_sequence(xdr, &args->seq_args, &hdr);
3002 encode_free_stateid(xdr, args, &hdr);
3003 encode_nops(&hdr);
3004}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003005#endif /* CONFIG_NFS_V4_1 */
3006
Benny Halevy686841b2009-08-14 17:19:48 +03003007static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3008{
3009 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3010 "Remaining buffer length is %tu words.\n",
3011 func, xdr->end - xdr->p);
3012}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013
Trond Myklebust683b57b2006-06-09 09:34:22 -04003014static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015{
Al Viro8687b632006-10-19 23:28:48 -07003016 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017
Benny Halevyc0eae662009-08-14 17:20:14 +03003018 p = xdr_inline_decode(xdr, 4);
3019 if (unlikely(!p))
3020 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003021 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003022 p = xdr_inline_decode(xdr, *len);
3023 if (unlikely(!p))
3024 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 *string = (char *)p;
3026 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003027out_overflow:
3028 print_overflow_msg(__func__, xdr);
3029 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030}
3031
3032static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3033{
Al Viro8687b632006-10-19 23:28:48 -07003034 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035
Benny Halevyc0eae662009-08-14 17:20:14 +03003036 p = xdr_inline_decode(xdr, 8);
3037 if (unlikely(!p))
3038 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003039 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003040 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003041
Benny Halevyc0eae662009-08-14 17:20:14 +03003042 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3043 if (unlikely(!p))
3044 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 hdr->tag = (char *)p;
3046 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003047 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003048 if (unlikely(hdr->nops < 1))
3049 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003051out_overflow:
3052 print_overflow_msg(__func__, xdr);
3053 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054}
3055
3056static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3057{
Al Viro8687b632006-10-19 23:28:48 -07003058 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 uint32_t opnum;
3060 int32_t nfserr;
3061
Benny Halevyc0eae662009-08-14 17:20:14 +03003062 p = xdr_inline_decode(xdr, 8);
3063 if (unlikely(!p))
3064 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003065 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003067 dprintk("nfs: Server returned operation"
3068 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 opnum, expected);
3070 return -EIO;
3071 }
Benny Halevycccddf42009-08-14 17:20:19 +03003072 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003074 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003076out_overflow:
3077 print_overflow_msg(__func__, xdr);
3078 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079}
3080
3081/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003082static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083{
Al Viro8687b632006-10-19 23:28:48 -07003084 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003085 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 char *str;
3087
Benny Halevyc0eae662009-08-14 17:20:14 +03003088 p = xdr_inline_decode(xdr, 12);
3089 if (likely(p))
3090 return decode_opaque_inline(xdr, &strlen, &str);
3091 print_overflow_msg(__func__, xdr);
3092 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093}
3094
3095static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3096{
Al Viro8687b632006-10-19 23:28:48 -07003097 uint32_t bmlen;
3098 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099
Benny Halevyc0eae662009-08-14 17:20:14 +03003100 p = xdr_inline_decode(xdr, 4);
3101 if (unlikely(!p))
3102 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003103 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104
Fred Isamandae100c2011-07-30 20:52:37 -04003105 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003106 p = xdr_inline_decode(xdr, (bmlen << 2));
3107 if (unlikely(!p))
3108 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003110 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003111 if (bmlen > 1) {
3112 bitmap[1] = be32_to_cpup(p++);
3113 if (bmlen > 2)
3114 bitmap[2] = be32_to_cpup(p);
3115 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 }
3117 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003118out_overflow:
3119 print_overflow_msg(__func__, xdr);
3120 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121}
3122
Trond Myklebust256e48b2012-06-21 11:18:13 -04003123static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124{
Al Viro8687b632006-10-19 23:28:48 -07003125 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126
Benny Halevyc0eae662009-08-14 17:20:14 +03003127 p = xdr_inline_decode(xdr, 4);
3128 if (unlikely(!p))
3129 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003130 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003131 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003133out_overflow:
3134 print_overflow_msg(__func__, xdr);
3135 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136}
3137
3138static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3139{
3140 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003141 int ret;
3142 ret = decode_attr_bitmap(xdr, bitmask);
3143 if (unlikely(ret < 0))
3144 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3146 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003147 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3148 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3149 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 return 0;
3151}
3152
3153static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3154{
Al Viro8687b632006-10-19 23:28:48 -07003155 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003156 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157
3158 *type = 0;
3159 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3160 return -EIO;
3161 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003162 p = xdr_inline_decode(xdr, 4);
3163 if (unlikely(!p))
3164 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003165 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003167 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 return -EIO;
3169 }
3170 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003171 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003173 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003174 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003175out_overflow:
3176 print_overflow_msg(__func__, xdr);
3177 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178}
3179
Chuck Lever264e6352012-03-01 17:02:05 -05003180static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3181 uint32_t *bitmap, uint32_t *type)
3182{
3183 __be32 *p;
3184
3185 *type = 0;
3186 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3187 return -EIO;
3188 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3189 p = xdr_inline_decode(xdr, 4);
3190 if (unlikely(!p))
3191 goto out_overflow;
3192 *type = be32_to_cpup(p);
3193 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3194 }
3195 dprintk("%s: expire type=0x%x\n", __func__, *type);
3196 return 0;
3197out_overflow:
3198 print_overflow_msg(__func__, xdr);
3199 return -EIO;
3200}
3201
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3203{
Al Viro8687b632006-10-19 23:28:48 -07003204 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003205 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206
3207 *change = 0;
3208 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3209 return -EIO;
3210 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003211 p = xdr_inline_decode(xdr, 8);
3212 if (unlikely(!p))
3213 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003214 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003216 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003218 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003220 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003221out_overflow:
3222 print_overflow_msg(__func__, xdr);
3223 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224}
3225
3226static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3227{
Al Viro8687b632006-10-19 23:28:48 -07003228 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003229 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230
3231 *size = 0;
3232 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3233 return -EIO;
3234 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003235 p = xdr_inline_decode(xdr, 8);
3236 if (unlikely(!p))
3237 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003238 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003240 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003242 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003243 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003244out_overflow:
3245 print_overflow_msg(__func__, xdr);
3246 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247}
3248
3249static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3250{
Al Viro8687b632006-10-19 23:28:48 -07003251 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252
3253 *res = 0;
3254 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3255 return -EIO;
3256 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003257 p = xdr_inline_decode(xdr, 4);
3258 if (unlikely(!p))
3259 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003260 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3262 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003263 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003265out_overflow:
3266 print_overflow_msg(__func__, xdr);
3267 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268}
3269
3270static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3271{
Al Viro8687b632006-10-19 23:28:48 -07003272 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273
3274 *res = 0;
3275 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3276 return -EIO;
3277 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003278 p = xdr_inline_decode(xdr, 4);
3279 if (unlikely(!p))
3280 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003281 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3283 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003284 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003286out_overflow:
3287 print_overflow_msg(__func__, xdr);
3288 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289}
3290
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003291static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292{
Al Viro8687b632006-10-19 23:28:48 -07003293 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003294 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295
3296 fsid->major = 0;
3297 fsid->minor = 0;
3298 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3299 return -EIO;
3300 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003301 p = xdr_inline_decode(xdr, 16);
3302 if (unlikely(!p))
3303 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003304 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003305 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003307 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003309 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 (unsigned long long)fsid->major,
3311 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003312 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003313out_overflow:
3314 print_overflow_msg(__func__, xdr);
3315 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316}
3317
3318static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3319{
Al Viro8687b632006-10-19 23:28:48 -07003320 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321
3322 *res = 60;
3323 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3324 return -EIO;
3325 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003326 p = xdr_inline_decode(xdr, 4);
3327 if (unlikely(!p))
3328 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003329 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3331 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003332 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003334out_overflow:
3335 print_overflow_msg(__func__, xdr);
3336 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337}
3338
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003339static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003340{
3341 __be32 *p;
3342
3343 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3344 return -EIO;
3345 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3346 p = xdr_inline_decode(xdr, 4);
3347 if (unlikely(!p))
3348 goto out_overflow;
3349 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003350 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003351 }
3352 return 0;
3353out_overflow:
3354 print_overflow_msg(__func__, xdr);
3355 return -EIO;
3356}
3357
3358static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3359{
3360 __be32 *p;
3361 int len;
3362
Trond Myklebust7ad07352010-10-23 15:34:20 -04003363 if (fh != NULL)
3364 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003365
3366 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3367 return -EIO;
3368 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3369 p = xdr_inline_decode(xdr, 4);
3370 if (unlikely(!p))
3371 goto out_overflow;
3372 len = be32_to_cpup(p);
3373 if (len > NFS4_FHSIZE)
3374 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003375 p = xdr_inline_decode(xdr, len);
3376 if (unlikely(!p))
3377 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003378 if (fh != NULL) {
3379 memcpy(fh->data, p, len);
3380 fh->size = len;
3381 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003382 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3383 }
3384 return 0;
3385out_overflow:
3386 print_overflow_msg(__func__, xdr);
3387 return -EIO;
3388}
3389
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3391{
Al Viro8687b632006-10-19 23:28:48 -07003392 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393
3394 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3395 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3396 return -EIO;
3397 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003398 p = xdr_inline_decode(xdr, 4);
3399 if (unlikely(!p))
3400 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003401 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3403 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003404 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003406out_overflow:
3407 print_overflow_msg(__func__, xdr);
3408 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409}
3410
3411static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3412{
Al Viro8687b632006-10-19 23:28:48 -07003413 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003414 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415
3416 *fileid = 0;
3417 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3418 return -EIO;
3419 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003420 p = xdr_inline_decode(xdr, 8);
3421 if (unlikely(!p))
3422 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003423 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003425 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003427 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003428 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003429out_overflow:
3430 print_overflow_msg(__func__, xdr);
3431 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432}
3433
Manoj Naik99baf622006-06-09 09:34:24 -04003434static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3435{
Al Viro8687b632006-10-19 23:28:48 -07003436 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003437 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003438
3439 *fileid = 0;
3440 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3441 return -EIO;
3442 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003443 p = xdr_inline_decode(xdr, 8);
3444 if (unlikely(!p))
3445 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003446 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003447 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003448 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003449 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003450 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003451 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003452out_overflow:
3453 print_overflow_msg(__func__, xdr);
3454 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003455}
3456
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3458{
Al Viro8687b632006-10-19 23:28:48 -07003459 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 int status = 0;
3461
3462 *res = 0;
3463 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3464 return -EIO;
3465 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003466 p = xdr_inline_decode(xdr, 8);
3467 if (unlikely(!p))
3468 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003469 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3471 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003472 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003474out_overflow:
3475 print_overflow_msg(__func__, xdr);
3476 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477}
3478
3479static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3480{
Al Viro8687b632006-10-19 23:28:48 -07003481 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 int status = 0;
3483
3484 *res = 0;
3485 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3486 return -EIO;
3487 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003488 p = xdr_inline_decode(xdr, 8);
3489 if (unlikely(!p))
3490 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003491 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3493 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003494 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003496out_overflow:
3497 print_overflow_msg(__func__, xdr);
3498 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499}
3500
3501static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3502{
Al Viro8687b632006-10-19 23:28:48 -07003503 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 int status = 0;
3505
3506 *res = 0;
3507 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3508 return -EIO;
3509 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003510 p = xdr_inline_decode(xdr, 8);
3511 if (unlikely(!p))
3512 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003513 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3515 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003516 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003518out_overflow:
3519 print_overflow_msg(__func__, xdr);
3520 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521}
3522
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003523static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3524{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003525 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003526 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003527 int status = 0;
3528
Benny Halevyc0eae662009-08-14 17:20:14 +03003529 p = xdr_inline_decode(xdr, 4);
3530 if (unlikely(!p))
3531 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003532 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003533 if (n == 0)
3534 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003535 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003536 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3537 dprintk("cannot parse %d components in path\n", n);
3538 goto out_eio;
3539 }
3540 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003541 struct nfs4_string *component = &path->components[path->ncomponents];
3542 status = decode_opaque_inline(xdr, &component->len, &component->data);
3543 if (unlikely(status != 0))
3544 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003545 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003546 pr_cont("%s%.*s ",
3547 (path->ncomponents != n ? "/ " : ""),
3548 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003549 }
3550out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003551 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003552root_path:
3553/* a root pathname is sent as a zero component4 */
3554 path->ncomponents = 1;
3555 path->components[0].len=0;
3556 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003557 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003558 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003559out_eio:
3560 dprintk(" status %d", status);
3561 status = -EIO;
3562 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003563out_overflow:
3564 print_overflow_msg(__func__, xdr);
3565 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003566}
3567
3568static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003569{
3570 int n;
Al Viro8687b632006-10-19 23:28:48 -07003571 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003572 int status = -EIO;
3573
3574 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3575 goto out;
3576 status = 0;
3577 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3578 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003579 status = -EIO;
3580 /* Ignore borken servers that return unrequested attrs */
3581 if (unlikely(res == NULL))
3582 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003583 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003584 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003585 if (unlikely(status != 0))
3586 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003587 p = xdr_inline_decode(xdr, 4);
3588 if (unlikely(!p))
3589 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003590 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003591 if (n <= 0)
3592 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003593 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003594 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003595 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003596
Trond Myklebust809b4262013-03-27 11:54:45 -04003597 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3598 break;
3599 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003600 p = xdr_inline_decode(xdr, 4);
3601 if (unlikely(!p))
3602 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003603 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003604
Chuck Lever02a29762012-03-01 17:00:31 -05003605 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003606 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3607 struct nfs4_string *server;
3608
3609 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003610 unsigned int i;
3611 dprintk("%s: using first %u of %u servers "
3612 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003613 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003614 NFS4_FS_LOCATION_MAXSERVERS,
3615 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003616 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003617 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003618 char *data;
3619 status = decode_opaque_inline(xdr, &len, &data);
3620 if (unlikely(status != 0))
3621 goto out_eio;
3622 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003623 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003624 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003625 server = &loc->servers[loc->nservers];
3626 status = decode_opaque_inline(xdr, &server->len, &server->data);
3627 if (unlikely(status != 0))
3628 goto out_eio;
3629 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003630 }
3631 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003632 if (unlikely(status != 0))
3633 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003634 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003635 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003636 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003637out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003638 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003639 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003640out_overflow:
3641 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003642out_eio:
3643 status = -EIO;
3644 goto out;
3645}
3646
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3648{
Al Viro8687b632006-10-19 23:28:48 -07003649 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650 int status = 0;
3651
3652 *res = 0;
3653 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3654 return -EIO;
3655 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003656 p = xdr_inline_decode(xdr, 8);
3657 if (unlikely(!p))
3658 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003659 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3661 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003662 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003664out_overflow:
3665 print_overflow_msg(__func__, xdr);
3666 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667}
3668
3669static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3670{
Al Viro8687b632006-10-19 23:28:48 -07003671 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 int status = 0;
3673
3674 *maxlink = 1;
3675 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3676 return -EIO;
3677 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003678 p = xdr_inline_decode(xdr, 4);
3679 if (unlikely(!p))
3680 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003681 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3683 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003684 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003686out_overflow:
3687 print_overflow_msg(__func__, xdr);
3688 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689}
3690
3691static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3692{
Al Viro8687b632006-10-19 23:28:48 -07003693 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694 int status = 0;
3695
3696 *maxname = 1024;
3697 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3698 return -EIO;
3699 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003700 p = xdr_inline_decode(xdr, 4);
3701 if (unlikely(!p))
3702 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003703 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3705 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003706 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003708out_overflow:
3709 print_overflow_msg(__func__, xdr);
3710 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711}
3712
3713static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3714{
Al Viro8687b632006-10-19 23:28:48 -07003715 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 int status = 0;
3717
3718 *res = 1024;
3719 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3720 return -EIO;
3721 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3722 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003723 p = xdr_inline_decode(xdr, 8);
3724 if (unlikely(!p))
3725 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003726 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727 if (maxread > 0x7FFFFFFF)
3728 maxread = 0x7FFFFFFF;
3729 *res = (uint32_t)maxread;
3730 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3731 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003732 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003734out_overflow:
3735 print_overflow_msg(__func__, xdr);
3736 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737}
3738
3739static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3740{
Al Viro8687b632006-10-19 23:28:48 -07003741 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 int status = 0;
3743
3744 *res = 1024;
3745 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3746 return -EIO;
3747 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3748 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003749 p = xdr_inline_decode(xdr, 8);
3750 if (unlikely(!p))
3751 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003752 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 if (maxwrite > 0x7FFFFFFF)
3754 maxwrite = 0x7FFFFFFF;
3755 *res = (uint32_t)maxwrite;
3756 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3757 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003758 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003760out_overflow:
3761 print_overflow_msg(__func__, xdr);
3762 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763}
3764
Trond Myklebustbca79472009-03-11 14:10:26 -04003765static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766{
Trond Myklebustbca79472009-03-11 14:10:26 -04003767 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003768 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003769 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770
3771 *mode = 0;
3772 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3773 return -EIO;
3774 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003775 p = xdr_inline_decode(xdr, 4);
3776 if (unlikely(!p))
3777 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003778 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003779 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003781 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003783 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003784 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003785out_overflow:
3786 print_overflow_msg(__func__, xdr);
3787 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788}
3789
3790static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3791{
Al Viro8687b632006-10-19 23:28:48 -07003792 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003793 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794
3795 *nlink = 1;
3796 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3797 return -EIO;
3798 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003799 p = xdr_inline_decode(xdr, 4);
3800 if (unlikely(!p))
3801 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003802 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003804 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003806 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003807 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003808out_overflow:
3809 print_overflow_msg(__func__, xdr);
3810 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811}
3812
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003813static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003814 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003815 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816{
Al Viro8687b632006-10-19 23:28:48 -07003817 uint32_t len;
3818 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003819 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820
Eric W. Biedermane5782072013-02-01 14:22:02 -08003821 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3823 return -EIO;
3824 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003825 p = xdr_inline_decode(xdr, 4);
3826 if (unlikely(!p))
3827 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003828 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003829 p = xdr_inline_decode(xdr, len);
3830 if (unlikely(!p))
3831 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003832 if (owner_name != NULL) {
3833 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3834 if (owner_name->data != NULL) {
3835 owner_name->len = len;
3836 ret = NFS_ATTR_FATTR_OWNER_NAME;
3837 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003838 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003839 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003840 ret = NFS_ATTR_FATTR_OWNER;
3841 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003843 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003845 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003846 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3848 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003849 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003850 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003851out_overflow:
3852 print_overflow_msg(__func__, xdr);
3853 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854}
3855
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003856static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003857 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003858 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859{
Al Viro8687b632006-10-19 23:28:48 -07003860 uint32_t len;
3861 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003862 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863
Eric W. Biedermane5782072013-02-01 14:22:02 -08003864 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3866 return -EIO;
3867 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003868 p = xdr_inline_decode(xdr, 4);
3869 if (unlikely(!p))
3870 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003871 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003872 p = xdr_inline_decode(xdr, len);
3873 if (unlikely(!p))
3874 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003875 if (group_name != NULL) {
3876 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3877 if (group_name->data != NULL) {
3878 group_name->len = len;
3879 ret = NFS_ATTR_FATTR_GROUP_NAME;
3880 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003881 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003882 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003883 ret = NFS_ATTR_FATTR_GROUP;
3884 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003886 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003888 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003889 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3891 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003892 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003893 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003894out_overflow:
3895 print_overflow_msg(__func__, xdr);
3896 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897}
3898
3899static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3900{
Al Viro8687b632006-10-19 23:28:48 -07003901 uint32_t major = 0, minor = 0;
3902 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003903 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904
3905 *rdev = MKDEV(0,0);
3906 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3907 return -EIO;
3908 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3909 dev_t tmp;
3910
Benny Halevyc0eae662009-08-14 17:20:14 +03003911 p = xdr_inline_decode(xdr, 8);
3912 if (unlikely(!p))
3913 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003914 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003915 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 tmp = MKDEV(major, minor);
3917 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3918 *rdev = tmp;
3919 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003920 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003922 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003923 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003924out_overflow:
3925 print_overflow_msg(__func__, xdr);
3926 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927}
3928
3929static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3930{
Al Viro8687b632006-10-19 23:28:48 -07003931 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932 int status = 0;
3933
3934 *res = 0;
3935 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3936 return -EIO;
3937 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003938 p = xdr_inline_decode(xdr, 8);
3939 if (unlikely(!p))
3940 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003941 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3943 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003944 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003946out_overflow:
3947 print_overflow_msg(__func__, xdr);
3948 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949}
3950
3951static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3952{
Al Viro8687b632006-10-19 23:28:48 -07003953 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 int status = 0;
3955
3956 *res = 0;
3957 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3958 return -EIO;
3959 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003960 p = xdr_inline_decode(xdr, 8);
3961 if (unlikely(!p))
3962 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003963 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3965 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003966 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003968out_overflow:
3969 print_overflow_msg(__func__, xdr);
3970 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971}
3972
3973static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3974{
Al Viro8687b632006-10-19 23:28:48 -07003975 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 int status = 0;
3977
3978 *res = 0;
3979 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3980 return -EIO;
3981 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003982 p = xdr_inline_decode(xdr, 8);
3983 if (unlikely(!p))
3984 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003985 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3987 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003988 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003990out_overflow:
3991 print_overflow_msg(__func__, xdr);
3992 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993}
3994
3995static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3996{
Al Viro8687b632006-10-19 23:28:48 -07003997 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003998 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999
4000 *used = 0;
4001 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4002 return -EIO;
4003 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004004 p = xdr_inline_decode(xdr, 8);
4005 if (unlikely(!p))
4006 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004007 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004009 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004011 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004013 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004014out_overflow:
4015 print_overflow_msg(__func__, xdr);
4016 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017}
4018
4019static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4020{
Al Viro8687b632006-10-19 23:28:48 -07004021 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 uint64_t sec;
4023 uint32_t nsec;
4024
Benny Halevyc0eae662009-08-14 17:20:14 +03004025 p = xdr_inline_decode(xdr, 12);
4026 if (unlikely(!p))
4027 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004028 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004029 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 time->tv_sec = (time_t)sec;
4031 time->tv_nsec = (long)nsec;
4032 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004033out_overflow:
4034 print_overflow_msg(__func__, xdr);
4035 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036}
4037
4038static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4039{
4040 int status = 0;
4041
4042 time->tv_sec = 0;
4043 time->tv_nsec = 0;
4044 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4045 return -EIO;
4046 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4047 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004048 if (status == 0)
4049 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4051 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004052 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053 return status;
4054}
4055
4056static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4057{
4058 int status = 0;
4059
4060 time->tv_sec = 0;
4061 time->tv_nsec = 0;
4062 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4063 return -EIO;
4064 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4065 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004066 if (status == 0)
4067 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4069 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004070 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 return status;
4072}
4073
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004074static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4075 struct timespec *time)
4076{
4077 int status = 0;
4078
4079 time->tv_sec = 0;
4080 time->tv_nsec = 0;
4081 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4082 return -EIO;
4083 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4084 status = decode_attr_time(xdr, time);
4085 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4086 }
4087 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4088 (long)time->tv_nsec);
4089 return status;
4090}
4091
David Quigleyaa9c2662013-05-22 12:50:44 -04004092static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4093 struct nfs4_label *label)
4094{
4095 uint32_t pi = 0;
4096 uint32_t lfs = 0;
4097 __u32 len;
4098 __be32 *p;
4099 int status = 0;
4100
4101 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4102 return -EIO;
4103 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4104 p = xdr_inline_decode(xdr, 4);
4105 if (unlikely(!p))
4106 goto out_overflow;
4107 lfs = be32_to_cpup(p++);
4108 p = xdr_inline_decode(xdr, 4);
4109 if (unlikely(!p))
4110 goto out_overflow;
4111 pi = be32_to_cpup(p++);
4112 p = xdr_inline_decode(xdr, 4);
4113 if (unlikely(!p))
4114 goto out_overflow;
4115 len = be32_to_cpup(p++);
4116 p = xdr_inline_decode(xdr, len);
4117 if (unlikely(!p))
4118 goto out_overflow;
4119 if (len < NFS4_MAXLABELLEN) {
4120 if (label) {
4121 memcpy(label->label, p, len);
4122 label->len = len;
4123 label->pi = pi;
4124 label->lfs = lfs;
4125 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4126 }
4127 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4128 } else
4129 printk(KERN_WARNING "%s: label too long (%u)!\n",
4130 __func__, len);
4131 }
4132 if (label && label->label)
4133 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4134 (char *)label->label, label->len, label->pi, label->lfs);
4135 return status;
4136
4137out_overflow:
4138 print_overflow_msg(__func__, xdr);
4139 return -EIO;
4140}
4141
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4143{
4144 int status = 0;
4145
4146 time->tv_sec = 0;
4147 time->tv_nsec = 0;
4148 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4149 return -EIO;
4150 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4151 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004152 if (status == 0)
4153 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4155 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004156 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 return status;
4158}
4159
Trond Myklebust256e48b2012-06-21 11:18:13 -04004160static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161{
4162 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004163 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164
4165 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004166 dprintk("%s: server returned incorrect attribute length: "
4167 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004168 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 attrwords << 2,
4170 (attrwords < nwords) ? '<' : '>',
4171 nwords << 2);
4172 return -EIO;
4173 }
4174 return 0;
4175}
4176
4177static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4178{
Al Viro8687b632006-10-19 23:28:48 -07004179 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180
Benny Halevyc0eae662009-08-14 17:20:14 +03004181 p = xdr_inline_decode(xdr, 20);
4182 if (unlikely(!p))
4183 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004184 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004185 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004186 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004188out_overflow:
4189 print_overflow_msg(__func__, xdr);
4190 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191}
4192
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004193static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194{
Al Viro8687b632006-10-19 23:28:48 -07004195 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196 uint32_t supp, acc;
4197 int status;
4198
4199 status = decode_op_hdr(xdr, OP_ACCESS);
4200 if (status)
4201 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004202 p = xdr_inline_decode(xdr, 8);
4203 if (unlikely(!p))
4204 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004205 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004206 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004207 *supported = supp;
4208 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004210out_overflow:
4211 print_overflow_msg(__func__, xdr);
4212 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213}
4214
Benny Halevy07d30432009-08-14 17:19:52 +03004215static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216{
Al Viro8687b632006-10-19 23:28:48 -07004217 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004218
4219 p = xdr_inline_decode(xdr, len);
4220 if (likely(p)) {
4221 memcpy(buf, p, len);
4222 return 0;
4223 }
4224 print_overflow_msg(__func__, xdr);
4225 return -EIO;
4226}
4227
4228static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4229{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004230 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231}
4232
4233static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4234{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 int status;
4236
4237 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004238 if (status != -EIO)
4239 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004240 if (!status)
4241 status = decode_stateid(xdr, &res->stateid);
4242 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243}
4244
Benny Halevydb942bb2009-08-14 17:19:56 +03004245static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4246{
Chuck Levercd937102012-03-02 17:14:31 -05004247 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248}
4249
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004250static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4251{
4252 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4253}
4254
Fred Isaman0b7c0152012-04-20 14:47:39 -04004255static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 int status;
4258
4259 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004260 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004261 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004262 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263}
4264
4265static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4266{
Al Viro8687b632006-10-19 23:28:48 -07004267 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268 uint32_t bmlen;
4269 int status;
4270
4271 status = decode_op_hdr(xdr, OP_CREATE);
4272 if (status)
4273 return status;
4274 if ((status = decode_change_info(xdr, cinfo)))
4275 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004276 p = xdr_inline_decode(xdr, 4);
4277 if (unlikely(!p))
4278 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004279 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004280 p = xdr_inline_decode(xdr, bmlen << 2);
4281 if (likely(p))
4282 return 0;
4283out_overflow:
4284 print_overflow_msg(__func__, xdr);
4285 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286}
4287
4288static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4289{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004290 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004291 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 int status;
4293
4294 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4295 goto xdr_error;
4296 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4297 goto xdr_error;
4298 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4299 goto xdr_error;
4300 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4301 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004302 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4303 &res->fh_expire_type)) != 0)
4304 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4306 goto xdr_error;
4307 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4308 goto xdr_error;
4309 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4310 goto xdr_error;
4311 status = verify_attr_len(xdr, savep, attrlen);
4312xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004313 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314 return status;
4315}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004316
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4318{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004319 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004320 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004322
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4324 goto xdr_error;
4325 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4326 goto xdr_error;
4327 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4328 goto xdr_error;
4329
4330 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4331 goto xdr_error;
4332 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4333 goto xdr_error;
4334 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4335 goto xdr_error;
4336 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4337 goto xdr_error;
4338 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4339 goto xdr_error;
4340 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4341 goto xdr_error;
4342
4343 status = verify_attr_len(xdr, savep, attrlen);
4344xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004345 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346 return status;
4347}
4348
4349static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4350{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004351 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004352 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004354
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4356 goto xdr_error;
4357 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4358 goto xdr_error;
4359 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4360 goto xdr_error;
4361
4362 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4363 goto xdr_error;
4364 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4365 goto xdr_error;
4366
4367 status = verify_attr_len(xdr, savep, attrlen);
4368xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004369 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004370 return status;
4371}
4372
Andy Adamson88034c32012-05-23 05:02:34 -04004373static int decode_threshold_hint(struct xdr_stream *xdr,
4374 uint32_t *bitmap,
4375 uint64_t *res,
4376 uint32_t hint_bit)
4377{
4378 __be32 *p;
4379
4380 *res = 0;
4381 if (likely(bitmap[0] & hint_bit)) {
4382 p = xdr_inline_decode(xdr, 8);
4383 if (unlikely(!p))
4384 goto out_overflow;
4385 xdr_decode_hyper(p, res);
4386 }
4387 return 0;
4388out_overflow:
4389 print_overflow_msg(__func__, xdr);
4390 return -EIO;
4391}
4392
4393static int decode_first_threshold_item4(struct xdr_stream *xdr,
4394 struct nfs4_threshold *res)
4395{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004396 __be32 *p;
4397 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004398 uint32_t bitmap[3] = {0,}, attrlen;
4399 int status;
4400
4401 /* layout type */
4402 p = xdr_inline_decode(xdr, 4);
4403 if (unlikely(!p)) {
4404 print_overflow_msg(__func__, xdr);
4405 return -EIO;
4406 }
4407 res->l_type = be32_to_cpup(p);
4408
4409 /* thi_hintset bitmap */
4410 status = decode_attr_bitmap(xdr, bitmap);
4411 if (status < 0)
4412 goto xdr_error;
4413
4414 /* thi_hintlist length */
4415 status = decode_attr_length(xdr, &attrlen, &savep);
4416 if (status < 0)
4417 goto xdr_error;
4418 /* thi_hintlist */
4419 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4420 if (status < 0)
4421 goto xdr_error;
4422 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4423 if (status < 0)
4424 goto xdr_error;
4425 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4426 THRESHOLD_RD_IO);
4427 if (status < 0)
4428 goto xdr_error;
4429 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4430 THRESHOLD_WR_IO);
4431 if (status < 0)
4432 goto xdr_error;
4433
4434 status = verify_attr_len(xdr, savep, attrlen);
4435 res->bm = bitmap[0];
4436
4437 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4438 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4439 res->wr_io_sz);
4440xdr_error:
4441 dprintk("%s ret=%d!\n", __func__, status);
4442 return status;
4443}
4444
4445/*
4446 * Thresholds on pNFS direct I/O vrs MDS I/O
4447 */
4448static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4449 uint32_t *bitmap,
4450 struct nfs4_threshold *res)
4451{
4452 __be32 *p;
4453 int status = 0;
4454 uint32_t num;
4455
4456 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4457 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004458 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004459 /* Did the server return an unrequested attribute? */
4460 if (unlikely(res == NULL))
4461 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004462 p = xdr_inline_decode(xdr, 4);
4463 if (unlikely(!p))
4464 goto out_overflow;
4465 num = be32_to_cpup(p);
4466 if (num == 0)
4467 return 0;
4468 if (num > 1)
4469 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4470 "drivers per filesystem not supported\n",
4471 __func__);
4472
4473 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004474 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004475 }
4476 return status;
4477out_overflow:
4478 print_overflow_msg(__func__, xdr);
4479 return -EIO;
4480}
4481
Bryan Schumakerae42c702010-10-21 16:33:17 -04004482static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4483 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004484 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004485 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486{
Trond Myklebustbca79472009-03-11 14:10:26 -04004487 int status;
4488 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004489 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004490 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004492 status = decode_attr_type(xdr, bitmap, &type);
4493 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004494 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004495 fattr->mode = 0;
4496 if (status != 0) {
4497 fattr->mode |= nfs_type2fmt[type];
4498 fattr->valid |= status;
4499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004500
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004501 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4502 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004504 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004505
4506 status = decode_attr_size(xdr, bitmap, &fattr->size);
4507 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004509 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004510
4511 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4512 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004514 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004515
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004516 err = 0;
4517 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004518 if (status < 0)
4519 goto xdr_error;
4520
4521 status = decode_attr_filehandle(xdr, bitmap, fh);
4522 if (status < 0)
4523 goto xdr_error;
4524
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004525 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4526 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004528 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004529
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004530 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004531 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004532 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004533 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004534
4535 status = decode_attr_mode(xdr, bitmap, &fmode);
4536 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004537 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004538 if (status != 0) {
4539 fattr->mode |= fmode;
4540 fattr->valid |= status;
4541 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004542
4543 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4544 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004546 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004547
Trond Myklebust6926afd2012-01-07 13:22:46 -05004548 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004549 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004550 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004551 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004552
Trond Myklebust6926afd2012-01-07 13:22:46 -05004553 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004554 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004555 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004556 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004557
4558 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4559 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004561 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004562
4563 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4564 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004565 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004566 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004567
4568 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4569 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004571 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004572
4573 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4574 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004575 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004576 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004577
4578 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4579 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004581 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004582
Trond Myklebust28331a42011-04-27 13:47:52 -04004583 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004584 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004585 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004586 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004587
Andy Adamson88034c32012-05-23 05:02:34 -04004588 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4589 if (status < 0)
4590 goto xdr_error;
4591
David Quigleyaa9c2662013-05-22 12:50:44 -04004592 if (label) {
4593 status = decode_attr_security_label(xdr, bitmap, label);
4594 if (status < 0)
4595 goto xdr_error;
4596 fattr->valid |= status;
4597 }
4598
Bryan Schumakerae42c702010-10-21 16:33:17 -04004599xdr_error:
4600 dprintk("%s: xdr returned %d\n", __func__, -status);
4601 return status;
4602}
4603
4604static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004605 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004606 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004607{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004608 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004609 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004610 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004611 int status;
4612
4613 status = decode_op_hdr(xdr, OP_GETATTR);
4614 if (status < 0)
4615 goto xdr_error;
4616
4617 status = decode_attr_bitmap(xdr, bitmap);
4618 if (status < 0)
4619 goto xdr_error;
4620
4621 status = decode_attr_length(xdr, &attrlen, &savep);
4622 if (status < 0)
4623 goto xdr_error;
4624
David Quigleyaa9c2662013-05-22 12:50:44 -04004625 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4626 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004627 if (status < 0)
4628 goto xdr_error;
4629
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004630 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004632 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633 return status;
4634}
4635
David Quigleyaa9c2662013-05-22 12:50:44 -04004636static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4637 struct nfs4_label *label, const struct nfs_server *server)
4638{
4639 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4640}
4641
Bryan Schumakerae42c702010-10-21 16:33:17 -04004642static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004643 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004644{
David Quigleyaa9c2662013-05-22 12:50:44 -04004645 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004646}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647
Andy Adamson504913f2010-10-20 00:17:57 -04004648/*
4649 * Decode potentially multiple layout types. Currently we only support
4650 * one layout driver per file system.
4651 */
4652static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4653 uint32_t *layouttype)
4654{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004655 __be32 *p;
Andy Adamson504913f2010-10-20 00:17:57 -04004656 int num;
4657
4658 p = xdr_inline_decode(xdr, 4);
4659 if (unlikely(!p))
4660 goto out_overflow;
4661 num = be32_to_cpup(p);
4662
4663 /* pNFS is not supported by the underlying file system */
4664 if (num == 0) {
4665 *layouttype = 0;
4666 return 0;
4667 }
4668 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004669 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4670 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004671
4672 /* Decode and set first layout type, move xdr->p past unused types */
4673 p = xdr_inline_decode(xdr, num * 4);
4674 if (unlikely(!p))
4675 goto out_overflow;
4676 *layouttype = be32_to_cpup(p);
4677 return 0;
4678out_overflow:
4679 print_overflow_msg(__func__, xdr);
4680 return -EIO;
4681}
4682
4683/*
4684 * The type of file system exported.
4685 * Note we must ensure that layouttype is set in any non-error case.
4686 */
4687static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4688 uint32_t *layouttype)
4689{
4690 int status = 0;
4691
4692 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4693 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4694 return -EIO;
4695 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4696 status = decode_first_pnfs_layout_type(xdr, layouttype);
4697 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4698 } else
4699 *layouttype = 0;
4700 return status;
4701}
4702
Fred Isamandae100c2011-07-30 20:52:37 -04004703/*
4704 * The prefered block size for layout directed io
4705 */
4706static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4707 uint32_t *res)
4708{
4709 __be32 *p;
4710
4711 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4712 *res = 0;
4713 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4714 p = xdr_inline_decode(xdr, 4);
4715 if (unlikely(!p)) {
4716 print_overflow_msg(__func__, xdr);
4717 return -EIO;
4718 }
4719 *res = be32_to_cpup(p);
4720 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4721 }
4722 return 0;
4723}
4724
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4726{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004727 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004728 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004729 int status;
4730
4731 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4732 goto xdr_error;
4733 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4734 goto xdr_error;
4735 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4736 goto xdr_error;
4737
4738 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4739
4740 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4741 goto xdr_error;
4742 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4743 goto xdr_error;
4744 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4745 goto xdr_error;
4746 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4747 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4748 goto xdr_error;
4749 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004750 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4751 if (status != 0)
4752 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004753 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4754 if (status != 0)
4755 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004756 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4757 if (status)
4758 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759
4760 status = verify_attr_len(xdr, savep, attrlen);
4761xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004762 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004763 return status;
4764}
4765
4766static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4767{
Al Viro8687b632006-10-19 23:28:48 -07004768 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004769 uint32_t len;
4770 int status;
4771
Trond Myklebust99367812007-07-17 21:52:41 -04004772 /* Zero handle first to allow comparisons */
4773 memset(fh, 0, sizeof(*fh));
4774
Linus Torvalds1da177e2005-04-16 15:20:36 -07004775 status = decode_op_hdr(xdr, OP_GETFH);
4776 if (status)
4777 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778
Benny Halevyc0eae662009-08-14 17:20:14 +03004779 p = xdr_inline_decode(xdr, 4);
4780 if (unlikely(!p))
4781 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004782 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 if (len > NFS4_FHSIZE)
4784 return -EIO;
4785 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004786 p = xdr_inline_decode(xdr, len);
4787 if (unlikely(!p))
4788 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004789 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004791out_overflow:
4792 print_overflow_msg(__func__, xdr);
4793 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794}
4795
4796static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4797{
4798 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004799
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800 status = decode_op_hdr(xdr, OP_LINK);
4801 if (status)
4802 return status;
4803 return decode_change_info(xdr, cinfo);
4804}
4805
4806/*
4807 * We create the owner, so we know a proper owner.id length is 4.
4808 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004809static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004811 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004812 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004813 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004815 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004816 if (unlikely(!p))
4817 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004818 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004819 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004820 type = be32_to_cpup(p++); /* 4 byte read */
4821 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004822 fl->fl_start = (loff_t)offset;
4823 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4824 if (length == ~(uint64_t)0)
4825 fl->fl_end = OFFSET_MAX;
4826 fl->fl_type = F_WRLCK;
4827 if (type & 1)
4828 fl->fl_type = F_RDLCK;
4829 fl->fl_pid = 0;
4830 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004831 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4832 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4833 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004834 if (likely(p))
4835 return -NFS4ERR_DENIED;
4836out_overflow:
4837 print_overflow_msg(__func__, xdr);
4838 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004839}
4840
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004841static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004843 int status;
4844
4845 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004846 if (status == -EIO)
4847 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004849 status = decode_stateid(xdr, &res->stateid);
4850 if (unlikely(status))
4851 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004852 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004853 status = decode_lock_denied(xdr, NULL);
4854 if (res->open_seqid != NULL)
4855 nfs_increment_open_seqid(status, res->open_seqid);
4856 nfs_increment_lock_seqid(status, res->lock_seqid);
4857out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858 return status;
4859}
4860
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004861static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862{
4863 int status;
4864 status = decode_op_hdr(xdr, OP_LOCKT);
4865 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004866 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867 return status;
4868}
4869
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004870static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004871{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872 int status;
4873
4874 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004875 if (status != -EIO)
4876 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004877 if (status == 0)
4878 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879 return status;
4880}
4881
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004882static int decode_release_lockowner(struct xdr_stream *xdr)
4883{
4884 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4885}
4886
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887static int decode_lookup(struct xdr_stream *xdr)
4888{
4889 return decode_op_hdr(xdr, OP_LOOKUP);
4890}
4891
4892/* This is too sick! */
4893static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4894{
Andy Adamson05d564f2008-12-23 16:06:15 -05004895 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004896 uint32_t limit_type, nblocks, blocksize;
4897
Benny Halevyc0eae662009-08-14 17:20:14 +03004898 p = xdr_inline_decode(xdr, 12);
4899 if (unlikely(!p))
4900 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004901 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004903 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004904 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004905 break;
4906 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004907 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004908 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004909 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910 }
4911 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004912out_overflow:
4913 print_overflow_msg(__func__, xdr);
4914 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004915}
4916
4917static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4918{
Andy Adamson05d564f2008-12-23 16:06:15 -05004919 __be32 *p;
4920 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004921 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922
Benny Halevyc0eae662009-08-14 17:20:14 +03004923 p = xdr_inline_decode(xdr, 4);
4924 if (unlikely(!p))
4925 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004926 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004927 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4928 res->delegation_type = 0;
4929 return 0;
4930 }
Benny Halevy07d30432009-08-14 17:19:52 +03004931 status = decode_stateid(xdr, &res->delegation);
4932 if (unlikely(status))
4933 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004934 p = xdr_inline_decode(xdr, 4);
4935 if (unlikely(!p))
4936 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004937 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004938
Linus Torvalds1da177e2005-04-16 15:20:36 -07004939 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004940 case NFS4_OPEN_DELEGATE_READ:
4941 res->delegation_type = FMODE_READ;
4942 break;
4943 case NFS4_OPEN_DELEGATE_WRITE:
4944 res->delegation_type = FMODE_WRITE|FMODE_READ;
4945 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946 return -EIO;
4947 }
David Howells7539bba2006-08-22 20:06:09 -04004948 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004949out_overflow:
4950 print_overflow_msg(__func__, xdr);
4951 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952}
4953
4954static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4955{
Andy Adamson05d564f2008-12-23 16:06:15 -05004956 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004957 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004958 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004959
Andy Adamson05d564f2008-12-23 16:06:15 -05004960 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004961 if (status != -EIO)
4962 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004963 if (!status)
4964 status = decode_stateid(xdr, &res->stateid);
4965 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004966 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967
Andy Adamson05d564f2008-12-23 16:06:15 -05004968 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004969
Benny Halevyc0eae662009-08-14 17:20:14 +03004970 p = xdr_inline_decode(xdr, 8);
4971 if (unlikely(!p))
4972 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004973 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004974 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004975 if (bmlen > 10)
4976 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977
Benny Halevyc0eae662009-08-14 17:20:14 +03004978 p = xdr_inline_decode(xdr, bmlen << 2);
4979 if (unlikely(!p))
4980 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004981 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4982 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004983 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004984 for (; i < NFS4_BITMAP_SIZE; i++)
4985 res->attrset[i] = 0;
4986
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987 return decode_delegation(xdr, res);
4988xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004989 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004991out_overflow:
4992 print_overflow_msg(__func__, xdr);
4993 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994}
4995
4996static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4997{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998 int status;
4999
Andy Adamson05d564f2008-12-23 16:06:15 -05005000 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005001 if (status != -EIO)
5002 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005003 if (!status)
5004 status = decode_stateid(xdr, &res->stateid);
5005 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006}
5007
5008static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5009{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010 int status;
5011
5012 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005013 if (status != -EIO)
5014 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005015 if (!status)
5016 status = decode_stateid(xdr, &res->stateid);
5017 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018}
5019
5020static int decode_putfh(struct xdr_stream *xdr)
5021{
5022 return decode_op_hdr(xdr, OP_PUTFH);
5023}
5024
5025static int decode_putrootfh(struct xdr_stream *xdr)
5026{
5027 return decode_op_hdr(xdr, OP_PUTROOTFH);
5028}
5029
5030static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
5031{
Al Viro8687b632006-10-19 23:28:48 -07005032 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005033 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034 int status;
5035
5036 status = decode_op_hdr(xdr, OP_READ);
5037 if (status)
5038 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005039 p = xdr_inline_decode(xdr, 8);
5040 if (unlikely(!p))
5041 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005042 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005043 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005044 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005046 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005047 "count %u > recvd %u\n", count, recvd);
5048 count = recvd;
5049 eof = 0;
5050 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005051 res->eof = eof;
5052 res->count = count;
5053 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005054out_overflow:
5055 print_overflow_msg(__func__, xdr);
5056 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057}
5058
5059static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5060{
Chuck Leverbcecff72007-10-26 13:32:03 -04005061 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005062 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005063
5064 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005065 if (!status)
5066 status = decode_verifier(xdr, readdir->verifier.data);
5067 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005069 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005070 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005071 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005072 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073}
5074
5075static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5076{
5077 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005078 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005079 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005080 int status;
5081
5082 status = decode_op_hdr(xdr, OP_READLINK);
5083 if (status)
5084 return status;
5085
5086 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005087 p = xdr_inline_decode(xdr, 4);
5088 if (unlikely(!p))
5089 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005090 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005092 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093 return -ENAMETOOLONG;
5094 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005095 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005096 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005097 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005098 "count %u > recvd %u\n", len, recvd);
5099 return -EIO;
5100 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101 /*
5102 * The XDR encode routine has set things up so that
5103 * the link text will be copied directly into the
5104 * buffer. We just have to do overflow-checking,
5105 * and and null-terminate the text (the VFS expects
5106 * null-termination).
5107 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005108 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005110out_overflow:
5111 print_overflow_msg(__func__, xdr);
5112 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113}
5114
5115static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5116{
5117 int status;
5118
5119 status = decode_op_hdr(xdr, OP_REMOVE);
5120 if (status)
5121 goto out;
5122 status = decode_change_info(xdr, cinfo);
5123out:
5124 return status;
5125}
5126
5127static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5128 struct nfs4_change_info *new_cinfo)
5129{
5130 int status;
5131
5132 status = decode_op_hdr(xdr, OP_RENAME);
5133 if (status)
5134 goto out;
5135 if ((status = decode_change_info(xdr, old_cinfo)))
5136 goto out;
5137 status = decode_change_info(xdr, new_cinfo);
5138out:
5139 return status;
5140}
5141
5142static int decode_renew(struct xdr_stream *xdr)
5143{
5144 return decode_op_hdr(xdr, OP_RENEW);
5145}
5146
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005147static int
5148decode_restorefh(struct xdr_stream *xdr)
5149{
5150 return decode_op_hdr(xdr, OP_RESTOREFH);
5151}
5152
J. Bruce Fields029d1052005-06-22 17:16:22 +00005153static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005154 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005155{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005156 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005157 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005158 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005159 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005160 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005161
Andy Adamsonbf118a32011-12-07 11:55:27 -05005162 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005163 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5164 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005165
Trond Myklebust519d3952012-08-14 17:30:10 -04005166 xdr_enter_page(xdr, xdr->buf->page_len);
5167
Trond Myklebustcff298c2012-08-14 17:14:17 -04005168 /* Calculate the offset of the page data */
5169 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005170
J. Bruce Fields029d1052005-06-22 17:16:22 +00005171 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5172 goto out;
5173 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5174 goto out;
5175
5176 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5177 return -EIO;
5178 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005179
Andy Adamsonbf118a32011-12-07 11:55:27 -05005180 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5181 * are stored with the acl data to handle the problem of
5182 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005183 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005184 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005185
5186 /* Check for receive buffer overflow */
5187 if (res->acl_len > (xdr->nwords << 2) ||
5188 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5189 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005190 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005191 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005192 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005193 } else
5194 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005195
5196out:
5197 return status;
5198}
5199
Linus Torvalds1da177e2005-04-16 15:20:36 -07005200static int
5201decode_savefh(struct xdr_stream *xdr)
5202{
5203 return decode_op_hdr(xdr, OP_SAVEFH);
5204}
5205
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005206static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207{
Al Viro8687b632006-10-19 23:28:48 -07005208 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005209 uint32_t bmlen;
5210 int status;
5211
Linus Torvalds1da177e2005-04-16 15:20:36 -07005212 status = decode_op_hdr(xdr, OP_SETATTR);
5213 if (status)
5214 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005215 p = xdr_inline_decode(xdr, 4);
5216 if (unlikely(!p))
5217 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005218 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005219 p = xdr_inline_decode(xdr, bmlen << 2);
5220 if (likely(p))
5221 return 0;
5222out_overflow:
5223 print_overflow_msg(__func__, xdr);
5224 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005225}
5226
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005227static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228{
Al Viro8687b632006-10-19 23:28:48 -07005229 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005230 uint32_t opnum;
5231 int32_t nfserr;
5232
Benny Halevyc0eae662009-08-14 17:20:14 +03005233 p = xdr_inline_decode(xdr, 8);
5234 if (unlikely(!p))
5235 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005236 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005237 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005238 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005239 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240 return -EIO;
5241 }
Benny Halevycccddf42009-08-14 17:20:19 +03005242 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005243 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005244 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5245 if (unlikely(!p))
5246 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005247 p = xdr_decode_hyper(p, &res->clientid);
5248 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249 } else if (nfserr == NFSERR_CLID_INUSE) {
5250 uint32_t len;
5251
5252 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005253 p = xdr_inline_decode(xdr, 4);
5254 if (unlikely(!p))
5255 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005256 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005257 p = xdr_inline_decode(xdr, len);
5258 if (unlikely(!p))
5259 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005260
5261 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005262 p = xdr_inline_decode(xdr, 4);
5263 if (unlikely(!p))
5264 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005265 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005266 p = xdr_inline_decode(xdr, len);
5267 if (unlikely(!p))
5268 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269 return -NFSERR_CLID_INUSE;
5270 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005271 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005272
5273 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005274out_overflow:
5275 print_overflow_msg(__func__, xdr);
5276 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277}
5278
5279static int decode_setclientid_confirm(struct xdr_stream *xdr)
5280{
5281 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5282}
5283
5284static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5285{
Al Viro8687b632006-10-19 23:28:48 -07005286 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005287 int status;
5288
5289 status = decode_op_hdr(xdr, OP_WRITE);
5290 if (status)
5291 return status;
5292
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005293 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005294 if (unlikely(!p))
5295 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005296 res->count = be32_to_cpup(p++);
5297 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005298 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005299out_overflow:
5300 print_overflow_msg(__func__, xdr);
5301 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302}
5303
5304static int decode_delegreturn(struct xdr_stream *xdr)
5305{
5306 return decode_op_hdr(xdr, OP_DELEGRETURN);
5307}
5308
Chuck Leverfb15b262013-03-16 15:54:34 -04005309static int decode_secinfo_gss(struct xdr_stream *xdr,
5310 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005311{
Chuck Leverfb15b262013-03-16 15:54:34 -04005312 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005313 __be32 *p;
5314
5315 p = xdr_inline_decode(xdr, 4);
5316 if (unlikely(!p))
5317 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005318 oid_len = be32_to_cpup(p);
5319 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005320 goto out_err;
5321
Chuck Leverfb15b262013-03-16 15:54:34 -04005322 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005323 if (unlikely(!p))
5324 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005325 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5326 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005327
5328 p = xdr_inline_decode(xdr, 8);
5329 if (unlikely(!p))
5330 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005331 flavor->flavor_info.qop = be32_to_cpup(p++);
5332 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005333
5334 return 0;
5335
5336out_overflow:
5337 print_overflow_msg(__func__, xdr);
5338 return -EIO;
5339out_err:
5340 return -EINVAL;
5341}
5342
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005343static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005344{
Chuck Leverfb15b262013-03-16 15:54:34 -04005345 struct nfs4_secinfo4 *sec_flavor;
5346 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005347 int status;
5348 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005349
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005350 p = xdr_inline_decode(xdr, 4);
5351 if (unlikely(!p))
5352 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005353
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005354 res->flavors->num_flavors = 0;
5355 num_flavors = be32_to_cpup(p);
5356
5357 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005358 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005359 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005360 break;
5361
5362 p = xdr_inline_decode(xdr, 4);
5363 if (unlikely(!p))
5364 goto out_overflow;
5365 sec_flavor->flavor = be32_to_cpup(p);
5366
5367 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005368 status = decode_secinfo_gss(xdr, sec_flavor);
5369 if (status)
5370 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005371 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005372 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005373 }
5374
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005375 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005376out:
5377 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005378out_overflow:
5379 print_overflow_msg(__func__, xdr);
5380 return -EIO;
5381}
5382
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005383static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5384{
5385 int status = decode_op_hdr(xdr, OP_SECINFO);
5386 if (status)
5387 return status;
5388 return decode_secinfo_common(xdr, res);
5389}
5390
Benny Halevy99fe60d2009-04-01 09:22:29 -04005391#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005392static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5393{
5394 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5395 if (status)
5396 return status;
5397 return decode_secinfo_common(xdr, res);
5398}
5399
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005400static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5401{
5402 __be32 *p;
5403 uint32_t bitmap_words;
5404 unsigned int i;
5405
5406 p = xdr_inline_decode(xdr, 4);
5407 bitmap_words = be32_to_cpup(p++);
5408 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5409 return -EIO;
5410 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5411 for (i = 0; i < bitmap_words; i++)
5412 op_map->u.words[i] = be32_to_cpup(p++);
5413
5414 return 0;
5415}
5416
Benny Halevy99fe60d2009-04-01 09:22:29 -04005417static int decode_exchange_id(struct xdr_stream *xdr,
5418 struct nfs41_exchange_id_res *res)
5419{
5420 __be32 *p;
5421 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005422 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005423 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005424 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005425
5426 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5427 if (status)
5428 return status;
5429
Benny Halevyc0eae662009-08-14 17:20:14 +03005430 p = xdr_inline_decode(xdr, 8);
5431 if (unlikely(!p))
5432 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005433 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005434 p = xdr_inline_decode(xdr, 12);
5435 if (unlikely(!p))
5436 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005437 res->seqid = be32_to_cpup(p++);
5438 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005439
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005440 res->state_protect.how = be32_to_cpup(p);
5441 switch (res->state_protect.how) {
5442 case SP4_NONE:
5443 break;
5444 case SP4_MACH_CRED:
5445 status = decode_op_map(xdr, &res->state_protect.enforce);
5446 if (status)
5447 return status;
5448 status = decode_op_map(xdr, &res->state_protect.allow);
5449 if (status)
5450 return status;
5451 break;
5452 default:
5453 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005454 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005455 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005456
Chuck Leveracdeb692012-05-21 22:46:16 -04005457 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005458 p = xdr_inline_decode(xdr, 8);
5459 if (unlikely(!p))
5460 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005461 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005462
Chuck Leveracdeb692012-05-21 22:46:16 -04005463 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005464 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5465 if (unlikely(status))
5466 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005467 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5468 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005469 memcpy(res->server_owner->major_id, dummy_str, dummy);
5470 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005471
Chuck Leveracdeb692012-05-21 22:46:16 -04005472 /* server_scope4 */
5473 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5474 if (unlikely(status))
5475 return status;
5476 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5477 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005478 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5479 res->server_scope->server_scope_sz = dummy;
5480
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005481 /* Implementation Id */
5482 p = xdr_inline_decode(xdr, 4);
5483 if (unlikely(!p))
5484 goto out_overflow;
5485 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005486
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005487 if (impl_id_count) {
5488 /* nii_domain */
5489 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5490 if (unlikely(status))
5491 return status;
5492 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5493 return -EIO;
5494 memcpy(res->impl_id->domain, dummy_str, dummy);
5495
5496 /* nii_name */
5497 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5498 if (unlikely(status))
5499 return status;
5500 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5501 return -EIO;
5502 memcpy(res->impl_id->name, dummy_str, dummy);
5503
5504 /* nii_date */
5505 p = xdr_inline_decode(xdr, 12);
5506 if (unlikely(!p))
5507 goto out_overflow;
5508 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5509 res->impl_id->date.nseconds = be32_to_cpup(p);
5510
5511 /* if there's more than one entry, ignore the rest */
5512 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005513 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005514out_overflow:
5515 print_overflow_msg(__func__, xdr);
5516 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005517}
Andy Adamsonfc931582009-04-01 09:22:31 -04005518
5519static int decode_chan_attrs(struct xdr_stream *xdr,
5520 struct nfs4_channel_attrs *attrs)
5521{
5522 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005523 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005524
Benny Halevyc0eae662009-08-14 17:20:14 +03005525 p = xdr_inline_decode(xdr, 28);
5526 if (unlikely(!p))
5527 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005528 val = be32_to_cpup(p++); /* headerpadsz */
5529 if (val)
5530 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005531 attrs->max_rqst_sz = be32_to_cpup(p++);
5532 attrs->max_resp_sz = be32_to_cpup(p++);
5533 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5534 attrs->max_ops = be32_to_cpup(p++);
5535 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005536 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005537 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005538 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5539 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005540 return -EINVAL;
5541 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005542 if (nr_attrs == 1) {
5543 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5544 if (unlikely(!p))
5545 goto out_overflow;
5546 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005547 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005548out_overflow:
5549 print_overflow_msg(__func__, xdr);
5550 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005551}
5552
Benny Halevye78291e2009-08-14 17:20:00 +03005553static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5554{
5555 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005556}
5557
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005558static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5559 struct nfs41_bind_conn_to_session_res *res)
5560{
5561 __be32 *p;
5562 int status;
5563
5564 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5565 if (!status)
5566 status = decode_sessionid(xdr, &res->session->sess_id);
5567 if (unlikely(status))
5568 return status;
5569
5570 /* dir flags, rdma mode bool */
5571 p = xdr_inline_decode(xdr, 8);
5572 if (unlikely(!p))
5573 goto out_overflow;
5574
5575 res->dir = be32_to_cpup(p++);
5576 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5577 return -EIO;
5578 if (be32_to_cpup(p) == 0)
5579 res->use_conn_in_rdma_mode = false;
5580 else
5581 res->use_conn_in_rdma_mode = true;
5582
5583 return 0;
5584out_overflow:
5585 print_overflow_msg(__func__, xdr);
5586 return -EIO;
5587}
5588
Andy Adamsonfc931582009-04-01 09:22:31 -04005589static int decode_create_session(struct xdr_stream *xdr,
5590 struct nfs41_create_session_res *res)
5591{
5592 __be32 *p;
5593 int status;
5594 struct nfs_client *clp = res->client;
5595 struct nfs4_session *session = clp->cl_session;
5596
5597 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005598 if (!status)
5599 status = decode_sessionid(xdr, &session->sess_id);
5600 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005601 return status;
5602
Andy Adamsonfc931582009-04-01 09:22:31 -04005603 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005604 p = xdr_inline_decode(xdr, 8);
5605 if (unlikely(!p))
5606 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005607 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005608 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005609
5610 /* Channel attributes */
5611 status = decode_chan_attrs(xdr, &session->fc_attrs);
5612 if (!status)
5613 status = decode_chan_attrs(xdr, &session->bc_attrs);
5614 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005615out_overflow:
5616 print_overflow_msg(__func__, xdr);
5617 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005618}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005619
5620static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5621{
5622 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5623}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005624
Trond Myklebust66245532012-05-25 17:18:09 -04005625static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5626{
5627 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5628}
5629
Ricardo Labiaga180197532009-12-05 16:08:40 -05005630static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5631{
5632 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5633}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005634#endif /* CONFIG_NFS_V4_1 */
5635
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005636static int decode_sequence(struct xdr_stream *xdr,
5637 struct nfs4_sequence_res *res,
5638 struct rpc_rqst *rqstp)
5639{
5640#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005641 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005642 struct nfs4_sessionid id;
5643 u32 dummy;
5644 int status;
5645 __be32 *p;
5646
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005647 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005648 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005649 if (!res->sr_slot->table->session)
5650 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005651
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005652 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005653 if (!status)
5654 status = decode_sessionid(xdr, &id);
5655 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005656 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005657
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005658 /*
5659 * If the server returns different values for sessionID, slotID or
5660 * sequence number, the server is looney tunes.
5661 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005662 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005663 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005664
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005665 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005666 NFS4_MAX_SESSIONID_LEN)) {
5667 dprintk("%s Invalid session id\n", __func__);
5668 goto out_err;
5669 }
Benny Halevye78291e2009-08-14 17:20:00 +03005670
Benny Halevyc0eae662009-08-14 17:20:14 +03005671 p = xdr_inline_decode(xdr, 20);
5672 if (unlikely(!p))
5673 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005674
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005675 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005676 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005677 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005678 dprintk("%s Invalid sequence number\n", __func__);
5679 goto out_err;
5680 }
5681 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005682 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005683 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005684 dprintk("%s Invalid slot id\n", __func__);
5685 goto out_err;
5686 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005687 /* highest slot id */
5688 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005689 /* target highest slot id */
5690 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005691 /* result flags */
5692 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005693 status = 0;
5694out_err:
5695 res->sr_status = status;
5696 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005697out_overflow:
5698 print_overflow_msg(__func__, xdr);
5699 status = -EIO;
5700 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005701#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005702 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005703#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005704}
5705
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005706#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005707/*
5708 * TODO: Need to handle case when EOF != true;
5709 */
5710static int decode_getdevicelist(struct xdr_stream *xdr,
5711 struct pnfs_devicelist *res)
5712{
5713 __be32 *p;
5714 int status, i;
Trond Myklebust98d94522012-06-08 12:01:14 -04005715 nfs4_verifier verftemp;
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005716
5717 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5718 if (status)
5719 return status;
5720
5721 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5722 if (unlikely(!p))
5723 goto out_overflow;
5724
5725 /* TODO: Skip cookie for now */
5726 p += 2;
5727
5728 /* Read verifier */
Trond Myklebust98d94522012-06-08 12:01:14 -04005729 p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005730
5731 res->num_devs = be32_to_cpup(p);
5732
5733 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5734
5735 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005736 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005737 __func__, res->num_devs);
5738 return -EIO;
5739 }
5740
5741 p = xdr_inline_decode(xdr,
5742 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5743 if (unlikely(!p))
5744 goto out_overflow;
5745 for (i = 0; i < res->num_devs; i++)
5746 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5747 NFS4_DEVICEID4_SIZE);
5748 res->eof = be32_to_cpup(p);
5749 return 0;
5750out_overflow:
5751 print_overflow_msg(__func__, xdr);
5752 return -EIO;
5753}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005754
5755static int decode_getdeviceinfo(struct xdr_stream *xdr,
5756 struct pnfs_device *pdev)
5757{
5758 __be32 *p;
5759 uint32_t len, type;
5760 int status;
5761
5762 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5763 if (status) {
5764 if (status == -ETOOSMALL) {
5765 p = xdr_inline_decode(xdr, 4);
5766 if (unlikely(!p))
5767 goto out_overflow;
5768 pdev->mincount = be32_to_cpup(p);
5769 dprintk("%s: Min count too small. mincnt = %u\n",
5770 __func__, pdev->mincount);
5771 }
5772 return status;
5773 }
5774
5775 p = xdr_inline_decode(xdr, 8);
5776 if (unlikely(!p))
5777 goto out_overflow;
5778 type = be32_to_cpup(p++);
5779 if (type != pdev->layout_type) {
5780 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5781 __func__, pdev->layout_type, type);
5782 return -EINVAL;
5783 }
5784 /*
5785 * Get the length of the opaque device_addr4. xdr_read_pages places
5786 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5787 * and places the remaining xdr data in xdr_buf->tail
5788 */
5789 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005790 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5791 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005792
5793 /* Parse notification bitmap, verifying that it is zero. */
5794 p = xdr_inline_decode(xdr, 4);
5795 if (unlikely(!p))
5796 goto out_overflow;
5797 len = be32_to_cpup(p);
5798 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005799 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005800
5801 p = xdr_inline_decode(xdr, 4 * len);
5802 if (unlikely(!p))
5803 goto out_overflow;
5804 for (i = 0; i < len; i++, p++) {
5805 if (be32_to_cpup(p)) {
5806 dprintk("%s: notifications not supported\n",
5807 __func__);
5808 return -EIO;
5809 }
5810 }
5811 }
5812 return 0;
5813out_overflow:
5814 print_overflow_msg(__func__, xdr);
5815 return -EIO;
5816}
5817
5818static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5819 struct nfs4_layoutget_res *res)
5820{
5821 __be32 *p;
5822 int status;
5823 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005824 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005825
5826 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5827 if (status)
5828 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005829 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005830 if (unlikely(!p))
5831 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005832 res->return_on_close = be32_to_cpup(p);
5833 decode_stateid(xdr, &res->stateid);
5834 p = xdr_inline_decode(xdr, 4);
5835 if (unlikely(!p))
5836 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005837 layout_count = be32_to_cpup(p);
5838 if (!layout_count) {
5839 dprintk("%s: server responded with empty layout array\n",
5840 __func__);
5841 return -EINVAL;
5842 }
5843
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005844 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005845 if (unlikely(!p))
5846 goto out_overflow;
5847 p = xdr_decode_hyper(p, &res->range.offset);
5848 p = xdr_decode_hyper(p, &res->range.length);
5849 res->range.iomode = be32_to_cpup(p++);
5850 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005851 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005852
5853 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5854 __func__,
5855 (unsigned long)res->range.offset,
5856 (unsigned long)res->range.length,
5857 res->range.iomode,
5858 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005859 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005860
Trond Myklebust64bd5772012-06-20 22:35:05 -04005861 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005862 if (res->layoutp->len > recvd) {
5863 dprintk("NFS: server cheating in layoutget reply: "
5864 "layout len %u > recvd %u\n",
5865 res->layoutp->len, recvd);
5866 return -EINVAL;
5867 }
5868
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005869 if (layout_count > 1) {
5870 /* We only handle a length one array at the moment. Any
5871 * further entries are just ignored. Note that this means
5872 * the client may see a response that is less than the
5873 * minimum it requested.
5874 */
5875 dprintk("%s: server responded with %d layouts, dropping tail\n",
5876 __func__, layout_count);
5877 }
5878
5879 return 0;
5880out_overflow:
5881 print_overflow_msg(__func__, xdr);
5882 return -EIO;
5883}
Andy Adamson863a3c62011-03-23 13:27:54 +00005884
Benny Halevycbe82602011-05-22 19:52:37 +03005885static int decode_layoutreturn(struct xdr_stream *xdr,
5886 struct nfs4_layoutreturn_res *res)
5887{
5888 __be32 *p;
5889 int status;
5890
5891 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5892 if (status)
5893 return status;
5894 p = xdr_inline_decode(xdr, 4);
5895 if (unlikely(!p))
5896 goto out_overflow;
5897 res->lrs_present = be32_to_cpup(p);
5898 if (res->lrs_present)
5899 status = decode_stateid(xdr, &res->stateid);
5900 return status;
5901out_overflow:
5902 print_overflow_msg(__func__, xdr);
5903 return -EIO;
5904}
5905
Andy Adamson863a3c62011-03-23 13:27:54 +00005906static int decode_layoutcommit(struct xdr_stream *xdr,
5907 struct rpc_rqst *req,
5908 struct nfs4_layoutcommit_res *res)
5909{
5910 __be32 *p;
5911 __u32 sizechanged;
5912 int status;
5913
5914 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005915 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005916 if (status)
5917 return status;
5918
5919 p = xdr_inline_decode(xdr, 4);
5920 if (unlikely(!p))
5921 goto out_overflow;
5922 sizechanged = be32_to_cpup(p);
5923
5924 if (sizechanged) {
5925 /* throw away new size */
5926 p = xdr_inline_decode(xdr, 8);
5927 if (unlikely(!p))
5928 goto out_overflow;
5929 }
5930 return 0;
5931out_overflow:
5932 print_overflow_msg(__func__, xdr);
5933 return -EIO;
5934}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005935
5936static int decode_test_stateid(struct xdr_stream *xdr,
5937 struct nfs41_test_stateid_res *res)
5938{
5939 __be32 *p;
5940 int status;
5941 int num_res;
5942
5943 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5944 if (status)
5945 return status;
5946
5947 p = xdr_inline_decode(xdr, 4);
5948 if (unlikely(!p))
5949 goto out_overflow;
5950 num_res = be32_to_cpup(p++);
5951 if (num_res != 1)
5952 goto out;
5953
5954 p = xdr_inline_decode(xdr, 4);
5955 if (unlikely(!p))
5956 goto out_overflow;
5957 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005958
5959 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005960out_overflow:
5961 print_overflow_msg(__func__, xdr);
5962out:
5963 return -EIO;
5964}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005965
5966static int decode_free_stateid(struct xdr_stream *xdr,
5967 struct nfs41_free_stateid_res *res)
5968{
5969 __be32 *p;
5970 int status;
5971
5972 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5973 if (status)
5974 return status;
5975
5976 p = xdr_inline_decode(xdr, 4);
5977 if (unlikely(!p))
5978 goto out_overflow;
5979 res->status = be32_to_cpup(p++);
5980 return res->status;
5981out_overflow:
5982 print_overflow_msg(__func__, xdr);
5983 return -EIO;
5984}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005985#endif /* CONFIG_NFS_V4_1 */
5986
Linus Torvalds1da177e2005-04-16 15:20:36 -07005987/*
Benny Halevy49c25592008-12-23 16:06:16 -05005988 * END OF "GENERIC" DECODE ROUTINES.
5989 */
5990
5991/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005992 * Decode OPEN_DOWNGRADE response
5993 */
Chuck Leverbf269552010-12-14 14:59:29 +00005994static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5995 struct xdr_stream *xdr,
5996 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997{
Andy Adamson05d564f2008-12-23 16:06:15 -05005998 struct compound_hdr hdr;
5999 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006000
Chuck Leverbf269552010-12-14 14:59:29 +00006001 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006002 if (status)
6003 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006004 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006005 if (status)
6006 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006007 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006008 if (status)
6009 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006010 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006011 if (status != 0)
6012 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006013 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006015 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006016}
6017
6018/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006019 * Decode ACCESS response
6020 */
Chuck Leverbf269552010-12-14 14:59:29 +00006021static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6022 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006023{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024 struct compound_hdr hdr;
6025 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006026
Chuck Leverbf269552010-12-14 14:59:29 +00006027 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006028 if (status)
6029 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006030 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006031 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006032 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006033 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006034 if (status != 0)
6035 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006036 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006037 if (status != 0)
6038 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006039 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006040out:
6041 return status;
6042}
6043
6044/*
6045 * Decode LOOKUP response
6046 */
Chuck Leverbf269552010-12-14 14:59:29 +00006047static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6048 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006049{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006050 struct compound_hdr hdr;
6051 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006052
Chuck Leverbf269552010-12-14 14:59:29 +00006053 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006054 if (status)
6055 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006056 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006057 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006058 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006059 status = decode_putfh(xdr);
6060 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006062 status = decode_lookup(xdr);
6063 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006064 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006065 status = decode_getfh(xdr, res->fh);
6066 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006068 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006069out:
6070 return status;
6071}
6072
6073/*
6074 * Decode LOOKUP_ROOT response
6075 */
Chuck Leverbf269552010-12-14 14:59:29 +00006076static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6077 struct xdr_stream *xdr,
6078 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006079{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006080 struct compound_hdr hdr;
6081 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006082
Chuck Leverbf269552010-12-14 14:59:29 +00006083 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006084 if (status)
6085 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006086 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006087 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006088 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006089 status = decode_putrootfh(xdr);
6090 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006091 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006092 status = decode_getfh(xdr, res->fh);
6093 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006094 status = decode_getfattr_label(xdr, res->fattr,
6095 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096out:
6097 return status;
6098}
6099
6100/*
6101 * Decode REMOVE response
6102 */
Chuck Leverbf269552010-12-14 14:59:29 +00006103static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6104 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006105{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106 struct compound_hdr hdr;
6107 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006108
Chuck Leverbf269552010-12-14 14:59:29 +00006109 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006110 if (status)
6111 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006112 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006113 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006115 status = decode_putfh(xdr);
6116 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006117 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006118 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006119out:
6120 return status;
6121}
6122
6123/*
6124 * Decode RENAME response
6125 */
Chuck Leverbf269552010-12-14 14:59:29 +00006126static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6127 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006128{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006129 struct compound_hdr hdr;
6130 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006131
Chuck Leverbf269552010-12-14 14:59:29 +00006132 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006133 if (status)
6134 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006135 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006136 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006138 status = decode_putfh(xdr);
6139 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006140 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006141 status = decode_savefh(xdr);
6142 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006144 status = decode_putfh(xdr);
6145 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006147 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006148out:
6149 return status;
6150}
6151
6152/*
6153 * Decode LINK response
6154 */
Chuck Leverbf269552010-12-14 14:59:29 +00006155static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6156 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006157{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006158 struct compound_hdr hdr;
6159 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006160
Chuck Leverbf269552010-12-14 14:59:29 +00006161 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006162 if (status)
6163 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006164 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006165 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006166 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006167 status = decode_putfh(xdr);
6168 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006170 status = decode_savefh(xdr);
6171 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006173 status = decode_putfh(xdr);
6174 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006175 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006176 status = decode_link(xdr, &res->cinfo);
6177 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006178 goto out;
6179 /*
6180 * Note order: OP_LINK leaves the directory as the current
6181 * filehandle.
6182 */
Chuck Leverbf269552010-12-14 14:59:29 +00006183 status = decode_restorefh(xdr);
6184 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006185 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006186 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187out:
6188 return status;
6189}
6190
6191/*
6192 * Decode CREATE response
6193 */
Chuck Leverbf269552010-12-14 14:59:29 +00006194static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6195 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197 struct compound_hdr hdr;
6198 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006199
Chuck Leverbf269552010-12-14 14:59:29 +00006200 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006201 if (status)
6202 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006203 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006204 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006206 status = decode_putfh(xdr);
6207 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006209 status = decode_create(xdr, &res->dir_cinfo);
6210 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006211 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006212 status = decode_getfh(xdr, res->fh);
6213 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006215 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216out:
6217 return status;
6218}
6219
6220/*
6221 * Decode SYMLINK response
6222 */
Chuck Leverbf269552010-12-14 14:59:29 +00006223static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6224 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225{
Chuck Leverbf269552010-12-14 14:59:29 +00006226 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227}
6228
6229/*
6230 * Decode GETATTR response
6231 */
Chuck Leverbf269552010-12-14 14:59:29 +00006232static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6233 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006234{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235 struct compound_hdr hdr;
6236 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006237
Chuck Leverbf269552010-12-14 14:59:29 +00006238 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239 if (status)
6240 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006241 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006242 if (status)
6243 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006244 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006245 if (status)
6246 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006247 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248out:
6249 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006250}
6251
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006252/*
6253 * Encode an SETACL request
6254 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006255static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6256 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006257{
Andy Adamson05d564f2008-12-23 16:06:15 -05006258 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006259 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006260 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006261
Chuck Lever9f06c712010-12-14 14:59:18 +00006262 encode_compound_hdr(xdr, req, &hdr);
6263 encode_sequence(xdr, &args->seq_args, &hdr);
6264 encode_putfh(xdr, args->fh, &hdr);
6265 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006266 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006267}
Andy Adamson05d564f2008-12-23 16:06:15 -05006268
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006269/*
6270 * Decode SETACL response
6271 */
6272static int
Chuck Leverbf269552010-12-14 14:59:29 +00006273nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006274 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006275{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006276 struct compound_hdr hdr;
6277 int status;
6278
Chuck Leverbf269552010-12-14 14:59:29 +00006279 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006280 if (status)
6281 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006282 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006283 if (status)
6284 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006285 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006286 if (status)
6287 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006288 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006289out:
6290 return status;
6291}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006292
6293/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006294 * Decode GETACL response
6295 */
6296static int
Chuck Leverbf269552010-12-14 14:59:29 +00006297nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006298 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006299{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006300 struct compound_hdr hdr;
6301 int status;
6302
Trond Myklebust331818f2012-02-03 18:30:53 -05006303 if (res->acl_scratch != NULL) {
6304 void *p = page_address(res->acl_scratch);
6305 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6306 }
Chuck Leverbf269552010-12-14 14:59:29 +00006307 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006308 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);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006314 if (status)
6315 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006316 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006317
6318out:
6319 return status;
6320}
6321
6322/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323 * Decode CLOSE response
6324 */
Chuck Leverbf269552010-12-14 14:59:29 +00006325static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6326 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006327{
Andy Adamson05d564f2008-12-23 16:06:15 -05006328 struct compound_hdr hdr;
6329 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006330
Chuck Leverbf269552010-12-14 14:59:29 +00006331 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006332 if (status)
6333 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006334 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006335 if (status)
6336 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006337 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006338 if (status)
6339 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006340 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006341 if (status != 0)
6342 goto out;
6343 /*
6344 * Note: Server may do delete on close for this file
6345 * in which case the getattr call will fail with
6346 * an ESTALE error. Shouldn't be a problem,
6347 * though, since fattr->valid will remain unset.
6348 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006349 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006351 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352}
6353
6354/*
6355 * Decode OPEN response
6356 */
Chuck Leverbf269552010-12-14 14:59:29 +00006357static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6358 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359{
Andy Adamson05d564f2008-12-23 16:06:15 -05006360 struct compound_hdr hdr;
6361 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362
Chuck Leverbf269552010-12-14 14:59:29 +00006363 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006364 if (status)
6365 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006366 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006367 if (status)
6368 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006369 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006370 if (status)
6371 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006372 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006373 if (status)
6374 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006375 status = decode_getfh(xdr, &res->fh);
6376 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006378 if (res->access_request)
6379 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006380 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006382 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006383}
6384
6385/*
6386 * Decode OPEN_CONFIRM response
6387 */
Chuck Leverbf269552010-12-14 14:59:29 +00006388static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6389 struct xdr_stream *xdr,
6390 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391{
Andy Adamson05d564f2008-12-23 16:06:15 -05006392 struct compound_hdr hdr;
6393 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006394
Chuck Leverbf269552010-12-14 14:59:29 +00006395 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006396 if (status)
6397 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006398 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006399 if (status)
6400 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006401 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006402out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006403 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006404}
6405
6406/*
6407 * Decode OPEN response
6408 */
Chuck Leverbf269552010-12-14 14:59:29 +00006409static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6410 struct xdr_stream *xdr,
6411 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006412{
Andy Adamson05d564f2008-12-23 16:06:15 -05006413 struct compound_hdr hdr;
6414 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006415
Chuck Leverbf269552010-12-14 14:59:29 +00006416 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006417 if (status)
6418 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006419 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006420 if (status)
6421 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006422 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006423 if (status)
6424 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006425 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006426 if (status)
6427 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006428 if (res->access_request)
6429 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006430 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006432 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006433}
6434
6435/*
6436 * Decode SETATTR response
6437 */
Chuck Leverbf269552010-12-14 14:59:29 +00006438static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6439 struct xdr_stream *xdr,
6440 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006441{
Andy Adamson05d564f2008-12-23 16:06:15 -05006442 struct compound_hdr hdr;
6443 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444
Chuck Leverbf269552010-12-14 14:59:29 +00006445 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006446 if (status)
6447 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006448 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006449 if (status)
6450 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006451 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006452 if (status)
6453 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006454 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006455 if (status)
6456 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006457 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006458out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006459 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460}
6461
6462/*
6463 * Decode LOCK response
6464 */
Chuck Leverbf269552010-12-14 14:59:29 +00006465static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6466 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006468 struct compound_hdr hdr;
6469 int status;
6470
Chuck Leverbf269552010-12-14 14:59:29 +00006471 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472 if (status)
6473 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006474 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006475 if (status)
6476 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006477 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006478 if (status)
6479 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006480 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006481out:
6482 return status;
6483}
6484
6485/*
6486 * Decode LOCKT response
6487 */
Chuck Leverbf269552010-12-14 14:59:29 +00006488static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6489 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491 struct compound_hdr hdr;
6492 int status;
6493
Chuck Leverbf269552010-12-14 14:59:29 +00006494 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495 if (status)
6496 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006497 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006498 if (status)
6499 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006500 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006501 if (status)
6502 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006503 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006504out:
6505 return status;
6506}
6507
6508/*
6509 * Decode LOCKU response
6510 */
Chuck Leverbf269552010-12-14 14:59:29 +00006511static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6512 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006514 struct compound_hdr hdr;
6515 int status;
6516
Chuck Leverbf269552010-12-14 14:59:29 +00006517 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518 if (status)
6519 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006520 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006521 if (status)
6522 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006523 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524 if (status)
6525 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527out:
6528 return status;
6529}
6530
Chuck Leverbf269552010-12-14 14:59:29 +00006531static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6532 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006533{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006534 struct compound_hdr hdr;
6535 int status;
6536
Chuck Leverbf269552010-12-14 14:59:29 +00006537 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006538 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006539 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006540 return status;
6541}
6542
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543/*
6544 * Decode READLINK response
6545 */
Chuck Leverbf269552010-12-14 14:59:29 +00006546static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6547 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006548 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006549{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550 struct compound_hdr hdr;
6551 int status;
6552
Chuck Leverbf269552010-12-14 14:59:29 +00006553 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554 if (status)
6555 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006556 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006557 if (status)
6558 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006559 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006560 if (status)
6561 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006562 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006563out:
6564 return status;
6565}
6566
6567/*
6568 * Decode READDIR response
6569 */
Chuck Leverbf269552010-12-14 14:59:29 +00006570static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6571 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006572{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006573 struct compound_hdr hdr;
6574 int status;
6575
Chuck Leverbf269552010-12-14 14:59:29 +00006576 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006577 if (status)
6578 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006579 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006580 if (status)
6581 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006582 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583 if (status)
6584 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006585 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006586out:
6587 return status;
6588}
6589
6590/*
6591 * Decode Read response
6592 */
Chuck Leverbf269552010-12-14 14:59:29 +00006593static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6594 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006596 struct compound_hdr hdr;
6597 int status;
6598
Chuck Leverbf269552010-12-14 14:59:29 +00006599 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006600 if (status)
6601 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006602 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006603 if (status)
6604 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006605 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606 if (status)
6607 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006608 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006609 if (!status)
6610 status = res->count;
6611out:
6612 return status;
6613}
6614
6615/*
6616 * Decode WRITE response
6617 */
Chuck Leverbf269552010-12-14 14:59:29 +00006618static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6619 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006620{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006621 struct compound_hdr hdr;
6622 int status;
6623
Chuck Leverbf269552010-12-14 14:59:29 +00006624 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006625 if (status)
6626 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006627 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006628 if (status)
6629 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006630 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631 if (status)
6632 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006633 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006634 if (status)
6635 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006636 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006637 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638 if (!status)
6639 status = res->count;
6640out:
6641 return status;
6642}
6643
6644/*
6645 * Decode COMMIT response
6646 */
Chuck Leverbf269552010-12-14 14:59:29 +00006647static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006648 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650 struct compound_hdr hdr;
6651 int status;
6652
Chuck Leverbf269552010-12-14 14:59:29 +00006653 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006654 if (status)
6655 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006656 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006657 if (status)
6658 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006659 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006660 if (status)
6661 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006662 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006663out:
6664 return status;
6665}
6666
6667/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006668 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006669 */
Chuck Leverbf269552010-12-14 14:59:29 +00006670static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006671 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006673 struct compound_hdr hdr;
6674 int status;
6675
Chuck Leverbf269552010-12-14 14:59:29 +00006676 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006677 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006678 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006679 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006680 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006681 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006682 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006683 return status;
6684}
6685
6686/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006687 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006688 */
Chuck Leverbf269552010-12-14 14:59:29 +00006689static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006690 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006691{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006692 struct compound_hdr hdr;
6693 int status;
6694
Chuck Leverbf269552010-12-14 14:59:29 +00006695 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006696 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006697 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006698 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006699 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006700 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006701 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006702 return status;
6703}
6704
6705/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006706 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006707 */
Chuck Leverbf269552010-12-14 14:59:29 +00006708static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006709 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006710{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006711 struct compound_hdr hdr;
6712 int status;
6713
Chuck Leverbf269552010-12-14 14:59:29 +00006714 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006715 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006716 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006717 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006718 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006719 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006720 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006721 return status;
6722}
6723
6724/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006725 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006726 */
Chuck Leverbf269552010-12-14 14:59:29 +00006727static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6728 struct xdr_stream *xdr,
6729 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006730{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006731 struct compound_hdr hdr;
6732 int status;
6733
Chuck Leverbf269552010-12-14 14:59:29 +00006734 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006735 if (status)
6736 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006737 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006738 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006739 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006740 status = decode_putfh(xdr);
6741 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006742 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006743 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006744out:
6745 return status;
6746}
6747
6748/*
6749 * Decode RENEW response
6750 */
Chuck Leverbf269552010-12-14 14:59:29 +00006751static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6752 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006753{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006754 struct compound_hdr hdr;
6755 int status;
6756
Chuck Leverbf269552010-12-14 14:59:29 +00006757 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006758 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006759 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006760 return status;
6761}
6762
6763/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006764 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006765 */
Chuck Leverbf269552010-12-14 14:59:29 +00006766static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6767 struct xdr_stream *xdr,
6768 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006769{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006770 struct compound_hdr hdr;
6771 int status;
6772
Chuck Leverbf269552010-12-14 14:59:29 +00006773 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006774 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006775 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006776 return status;
6777}
6778
6779/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006780 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006781 */
Chuck Leverbf269552010-12-14 14:59:29 +00006782static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006783 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006784{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006785 struct compound_hdr hdr;
6786 int status;
6787
Chuck Leverbf269552010-12-14 14:59:29 +00006788 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006789 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006790 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006791 return status;
6792}
6793
6794/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006795 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006796 */
Chuck Leverbf269552010-12-14 14:59:29 +00006797static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6798 struct xdr_stream *xdr,
6799 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006800{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006801 struct compound_hdr hdr;
6802 int status;
6803
Chuck Leverbf269552010-12-14 14:59:29 +00006804 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006805 if (status)
6806 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006807 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006808 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006809 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006810 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006811 if (status != 0)
6812 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006813 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006814 if (status != 0)
6815 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006816 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006817out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006818 return status;
6819}
6820
Trond Myklebust683b57b2006-06-09 09:34:22 -04006821/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006822 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006823 */
Chuck Leverbf269552010-12-14 14:59:29 +00006824static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6825 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006826 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006827{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006828 struct compound_hdr hdr;
6829 int status;
6830
Chuck Leverbf269552010-12-14 14:59:29 +00006831 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006832 if (status)
6833 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006834 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006835 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006836 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006837 status = decode_putfh(xdr);
6838 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006839 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006840 status = decode_lookup(xdr);
6841 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006842 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006843 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006844 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6845 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006846 NULL, res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006847out:
6848 return status;
6849}
6850
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006851/*
6852 * Decode SECINFO response
6853 */
6854static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6855 struct xdr_stream *xdr,
6856 struct nfs4_secinfo_res *res)
6857{
6858 struct compound_hdr hdr;
6859 int status;
6860
6861 status = decode_compound_hdr(xdr, &hdr);
6862 if (status)
6863 goto out;
6864 status = decode_sequence(xdr, &res->seq_res, rqstp);
6865 if (status)
6866 goto out;
6867 status = decode_putfh(xdr);
6868 if (status)
6869 goto out;
6870 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006871out:
6872 return status;
6873}
6874
Benny Halevy99fe60d2009-04-01 09:22:29 -04006875#if defined(CONFIG_NFS_V4_1)
6876/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006877 * Decode BIND_CONN_TO_SESSION response
6878 */
6879static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6880 struct xdr_stream *xdr,
6881 void *res)
6882{
6883 struct compound_hdr hdr;
6884 int status;
6885
6886 status = decode_compound_hdr(xdr, &hdr);
6887 if (!status)
6888 status = decode_bind_conn_to_session(xdr, res);
6889 return status;
6890}
6891
6892/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006893 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006894 */
Chuck Leverbf269552010-12-14 14:59:29 +00006895static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6896 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006897 void *res)
6898{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006899 struct compound_hdr hdr;
6900 int status;
6901
Chuck Leverbf269552010-12-14 14:59:29 +00006902 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006903 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006904 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006905 return status;
6906}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006907
6908/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006909 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006910 */
Chuck Leverbf269552010-12-14 14:59:29 +00006911static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6912 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006913 struct nfs41_create_session_res *res)
6914{
Andy Adamsonfc931582009-04-01 09:22:31 -04006915 struct compound_hdr hdr;
6916 int status;
6917
Chuck Leverbf269552010-12-14 14:59:29 +00006918 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006919 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006920 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006921 return status;
6922}
6923
6924/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006925 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006926 */
Chuck Leverbf269552010-12-14 14:59:29 +00006927static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6928 struct xdr_stream *xdr,
6929 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006930{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006931 struct compound_hdr hdr;
6932 int status;
6933
Chuck Leverbf269552010-12-14 14:59:29 +00006934 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006935 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006936 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006937 return status;
6938}
6939
6940/*
Trond Myklebust66245532012-05-25 17:18:09 -04006941 * Decode DESTROY_CLIENTID response
6942 */
6943static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6944 struct xdr_stream *xdr,
6945 void *res)
6946{
6947 struct compound_hdr hdr;
6948 int status;
6949
6950 status = decode_compound_hdr(xdr, &hdr);
6951 if (!status)
6952 status = decode_destroy_clientid(xdr, res);
6953 return status;
6954}
6955
6956/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006957 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006958 */
Chuck Leverbf269552010-12-14 14:59:29 +00006959static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6960 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006961 struct nfs4_sequence_res *res)
6962{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006963 struct compound_hdr hdr;
6964 int status;
6965
Chuck Leverbf269552010-12-14 14:59:29 +00006966 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006967 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006968 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006969 return status;
6970}
6971
6972/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006973 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006974 */
Chuck Leverbf269552010-12-14 14:59:29 +00006975static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6976 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006977 struct nfs4_get_lease_time_res *res)
6978{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006979 struct compound_hdr hdr;
6980 int status;
6981
Chuck Leverbf269552010-12-14 14:59:29 +00006982 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006983 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006984 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006985 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006986 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006987 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006988 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006989 return status;
6990}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006991
6992/*
6993 * Decode RECLAIM_COMPLETE response
6994 */
Chuck Leverbf269552010-12-14 14:59:29 +00006995static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6996 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006997 struct nfs41_reclaim_complete_res *res)
6998{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006999 struct compound_hdr hdr;
7000 int status;
7001
Chuck Leverbf269552010-12-14 14:59:29 +00007002 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007003 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007004 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007005 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007006 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007007 return status;
7008}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007009
7010/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007011 * Decode GETDEVICELIST response
7012 */
7013static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
7014 struct xdr_stream *xdr,
7015 struct nfs4_getdevicelist_res *res)
7016{
7017 struct compound_hdr hdr;
7018 int status;
7019
7020 dprintk("encoding getdevicelist!\n");
7021
7022 status = decode_compound_hdr(xdr, &hdr);
7023 if (status != 0)
7024 goto out;
7025 status = decode_sequence(xdr, &res->seq_res, rqstp);
7026 if (status != 0)
7027 goto out;
7028 status = decode_putfh(xdr);
7029 if (status != 0)
7030 goto out;
7031 status = decode_getdevicelist(xdr, res->devlist);
7032out:
7033 return status;
7034}
7035
7036/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007037 * Decode GETDEVINFO response
7038 */
Chuck Leverbf269552010-12-14 14:59:29 +00007039static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7040 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007041 struct nfs4_getdeviceinfo_res *res)
7042{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007043 struct compound_hdr hdr;
7044 int status;
7045
Chuck Leverbf269552010-12-14 14:59:29 +00007046 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007047 if (status != 0)
7048 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007049 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007050 if (status != 0)
7051 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007052 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007053out:
7054 return status;
7055}
7056
7057/*
7058 * Decode LAYOUTGET response
7059 */
Chuck Leverbf269552010-12-14 14:59:29 +00007060static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7061 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007062 struct nfs4_layoutget_res *res)
7063{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007064 struct compound_hdr hdr;
7065 int status;
7066
Chuck Leverbf269552010-12-14 14:59:29 +00007067 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007068 if (status)
7069 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007070 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007071 if (status)
7072 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007073 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007074 if (status)
7075 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007076 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007077out:
7078 return status;
7079}
Andy Adamson863a3c62011-03-23 13:27:54 +00007080
7081/*
Benny Halevycbe82602011-05-22 19:52:37 +03007082 * Decode LAYOUTRETURN response
7083 */
7084static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7085 struct xdr_stream *xdr,
7086 struct nfs4_layoutreturn_res *res)
7087{
7088 struct compound_hdr hdr;
7089 int status;
7090
7091 status = decode_compound_hdr(xdr, &hdr);
7092 if (status)
7093 goto out;
7094 status = decode_sequence(xdr, &res->seq_res, rqstp);
7095 if (status)
7096 goto out;
7097 status = decode_putfh(xdr);
7098 if (status)
7099 goto out;
7100 status = decode_layoutreturn(xdr, res);
7101out:
7102 return status;
7103}
7104
7105/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007106 * Decode LAYOUTCOMMIT response
7107 */
7108static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7109 struct xdr_stream *xdr,
7110 struct nfs4_layoutcommit_res *res)
7111{
7112 struct compound_hdr hdr;
7113 int status;
7114
7115 status = decode_compound_hdr(xdr, &hdr);
7116 if (status)
7117 goto out;
7118 status = decode_sequence(xdr, &res->seq_res, rqstp);
7119 if (status)
7120 goto out;
7121 status = decode_putfh(xdr);
7122 if (status)
7123 goto out;
7124 status = decode_layoutcommit(xdr, rqstp, res);
7125 if (status)
7126 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007127 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007128out:
7129 return status;
7130}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007131
7132/*
7133 * Decode SECINFO_NO_NAME response
7134 */
7135static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7136 struct xdr_stream *xdr,
7137 struct nfs4_secinfo_res *res)
7138{
7139 struct compound_hdr hdr;
7140 int status;
7141
7142 status = decode_compound_hdr(xdr, &hdr);
7143 if (status)
7144 goto out;
7145 status = decode_sequence(xdr, &res->seq_res, rqstp);
7146 if (status)
7147 goto out;
7148 status = decode_putrootfh(xdr);
7149 if (status)
7150 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007151 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007152out:
7153 return status;
7154}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007155
7156/*
7157 * Decode TEST_STATEID response
7158 */
7159static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7160 struct xdr_stream *xdr,
7161 struct nfs41_test_stateid_res *res)
7162{
7163 struct compound_hdr hdr;
7164 int status;
7165
7166 status = decode_compound_hdr(xdr, &hdr);
7167 if (status)
7168 goto out;
7169 status = decode_sequence(xdr, &res->seq_res, rqstp);
7170 if (status)
7171 goto out;
7172 status = decode_test_stateid(xdr, res);
7173out:
7174 return status;
7175}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007176
7177/*
7178 * Decode FREE_STATEID response
7179 */
7180static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7181 struct xdr_stream *xdr,
7182 struct nfs41_free_stateid_res *res)
7183{
7184 struct compound_hdr hdr;
7185 int status;
7186
7187 status = decode_compound_hdr(xdr, &hdr);
7188 if (status)
7189 goto out;
7190 status = decode_sequence(xdr, &res->seq_res, rqstp);
7191 if (status)
7192 goto out;
7193 status = decode_free_stateid(xdr, res);
7194out:
7195 return status;
7196}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007197#endif /* CONFIG_NFS_V4_1 */
7198
Chuck Lever573c4e12010-12-14 14:58:11 +00007199/**
7200 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7201 * the local page cache.
7202 * @xdr: XDR stream where entry resides
7203 * @entry: buffer to fill in with entry data
7204 * @plus: boolean indicating whether this should be a readdirplus entry
7205 *
7206 * Returns zero if successful, otherwise a negative errno value is
7207 * returned.
7208 *
7209 * This function is not invoked during READDIR reply decoding, but
7210 * rather whenever an application invokes the getdents(2) system call
7211 * on a directory already in our cache.
7212 */
7213int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7214 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007215{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007216 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007217 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007218 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007219 __be32 *p = xdr_inline_decode(xdr, 4);
7220 if (unlikely(!p))
7221 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007222 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007223 p = xdr_inline_decode(xdr, 4);
7224 if (unlikely(!p))
7225 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007226 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007227 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007228 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007229 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007230 }
7231
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007232 p = xdr_inline_decode(xdr, 12);
7233 if (unlikely(!p))
7234 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007235 entry->prev_cookie = entry->cookie;
7236 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007237 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007238
Trond Myklebust9af8c222010-10-24 11:52:55 -04007239 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007240 if (unlikely(!p))
7241 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007242 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007243
7244 /*
7245 * In case the server doesn't return an inode number,
7246 * we fake one here. (We don't use inode number 0,
7247 * since glibc seems to choke on it...)
7248 */
7249 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007250 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007251
Trond Myklebust9af8c222010-10-24 11:52:55 -04007252 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007253 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007254
Trond Myklebust256e48b2012-06-21 11:18:13 -04007255 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007256 goto out_overflow;
7257
Chuck Lever573c4e12010-12-14 14:58:11 +00007258 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007259 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007260 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007261 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7262 entry->ino = entry->fattr->mounted_on_fileid;
7263 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007264 entry->ino = entry->fattr->fileid;
7265
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007266 entry->d_type = DT_UNKNOWN;
7267 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7268 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7269
Chuck Lever573c4e12010-12-14 14:58:11 +00007270 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007271
7272out_overflow:
7273 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007274 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007275}
7276
7277/*
7278 * We need to translate between nfs status return values and
7279 * the local errno values which may not be the same.
7280 */
7281static struct {
7282 int stat;
7283 int errno;
7284} nfs_errtbl[] = {
7285 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007286 { NFS4ERR_PERM, -EPERM },
7287 { NFS4ERR_NOENT, -ENOENT },
7288 { NFS4ERR_IO, -errno_NFSERR_IO},
7289 { NFS4ERR_NXIO, -ENXIO },
7290 { NFS4ERR_ACCESS, -EACCES },
7291 { NFS4ERR_EXIST, -EEXIST },
7292 { NFS4ERR_XDEV, -EXDEV },
7293 { NFS4ERR_NOTDIR, -ENOTDIR },
7294 { NFS4ERR_ISDIR, -EISDIR },
7295 { NFS4ERR_INVAL, -EINVAL },
7296 { NFS4ERR_FBIG, -EFBIG },
7297 { NFS4ERR_NOSPC, -ENOSPC },
7298 { NFS4ERR_ROFS, -EROFS },
7299 { NFS4ERR_MLINK, -EMLINK },
7300 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7301 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7302 { NFS4ERR_DQUOT, -EDQUOT },
7303 { NFS4ERR_STALE, -ESTALE },
7304 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007305 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7306 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7307 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007308 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007309 { NFS4ERR_BADTYPE, -EBADTYPE },
7310 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007311 { NFS4ERR_SYMLINK, -ELOOP },
7312 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7313 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007314 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007315};
7316
7317/*
7318 * Convert an NFS error code to a local one.
7319 * This one is used jointly by NFSv2 and NFSv3.
7320 */
7321static int
David Howells0a8ea432006-08-22 20:06:08 -04007322nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007323{
7324 int i;
7325 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7326 if (nfs_errtbl[i].stat == stat)
7327 return nfs_errtbl[i].errno;
7328 }
7329 if (stat <= 10000 || stat > 10100) {
7330 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007331 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007332 }
7333 /* If we cannot translate the error, the recovery routines should
7334 * handle it.
7335 * Note: remaining NFSv4 error codes have values > 10000, so should
7336 * not conflict with native Linux error codes.
7337 */
Benny Halevy856dff32008-03-31 17:39:06 +03007338 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007339}
7340
Linus Torvalds1da177e2005-04-16 15:20:36 -07007341#define PROC(proc, argtype, restype) \
7342[NFSPROC4_CLNT_##proc] = { \
7343 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007344 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007345 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007346 .p_arglen = NFS4_##argtype##_sz, \
7347 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007348 .p_statidx = NFSPROC4_CLNT_##proc, \
7349 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007350}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007351
7352struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007353 PROC(READ, enc_read, dec_read),
7354 PROC(WRITE, enc_write, dec_write),
7355 PROC(COMMIT, enc_commit, dec_commit),
7356 PROC(OPEN, enc_open, dec_open),
7357 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7358 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7359 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7360 PROC(CLOSE, enc_close, dec_close),
7361 PROC(SETATTR, enc_setattr, dec_setattr),
7362 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7363 PROC(RENEW, enc_renew, dec_renew),
7364 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7365 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7366 PROC(LOCK, enc_lock, dec_lock),
7367 PROC(LOCKT, enc_lockt, dec_lockt),
7368 PROC(LOCKU, enc_locku, dec_locku),
7369 PROC(ACCESS, enc_access, dec_access),
7370 PROC(GETATTR, enc_getattr, dec_getattr),
7371 PROC(LOOKUP, enc_lookup, dec_lookup),
7372 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7373 PROC(REMOVE, enc_remove, dec_remove),
7374 PROC(RENAME, enc_rename, dec_rename),
7375 PROC(LINK, enc_link, dec_link),
7376 PROC(SYMLINK, enc_symlink, dec_symlink),
7377 PROC(CREATE, enc_create, dec_create),
7378 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7379 PROC(STATFS, enc_statfs, dec_statfs),
7380 PROC(READLINK, enc_readlink, dec_readlink),
7381 PROC(READDIR, enc_readdir, dec_readdir),
7382 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7383 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7384 PROC(GETACL, enc_getacl, dec_getacl),
7385 PROC(SETACL, enc_setacl, dec_setacl),
7386 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7387 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007388 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007389#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007390 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7391 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7392 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7393 PROC(SEQUENCE, enc_sequence, dec_sequence),
7394 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7395 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7396 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7397 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007398 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007399 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007400 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007401 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007402 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007403 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007404 PROC(BIND_CONN_TO_SESSION,
7405 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007406 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007407#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007408};
7409
Trond Myklebusta613fa12012-01-20 13:53:56 -05007410const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007411 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007412 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007413 .procs = nfs4_procedures
7414};
7415
7416/*
7417 * Local variables:
7418 * c-basic-offset: 8
7419 * End:
7420 */