blob: edb8ac7fce0ece159bdc8a09cf333483c79262d2 [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"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040059#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040060#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62#define NFSDBG_FACILITY NFSDBG_XDR
63
64/* Mapping from NFS error code to "errno" error code. */
65#define errno_NFSERR_IO EIO
66
David Howells0a8ea432006-08-22 20:06:08 -040067static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
70#ifdef DEBUG
71#define NFS4_MAXTAGLEN 20
72#else
73#define NFS4_MAXTAGLEN 0
74#endif
75
Andy Adamson6c0195a2008-12-23 16:06:15 -050076/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040077 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040079#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050080#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040081#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
83#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84#define op_encode_hdr_maxsz (1)
85#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040086#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
87#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
89#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
91 (NFS4_FHSIZE >> 2))
92#define decode_putfh_maxsz (op_decode_hdr_maxsz)
93#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
94#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
95#define encode_getfh_maxsz (op_encode_hdr_maxsz)
96#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
97 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040098#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000099#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
101#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400102#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
103#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Andy Adamson88034c32012-05-23 05:02:34 -0400104/* We support only one layout type per file system */
105#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000106/* This is based on getfattr, which uses the most attributes: */
107#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400108 3 + 3 + 3 + nfs4_owner_maxsz + \
109 nfs4_group_maxsz + decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000110#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
111 nfs4_fattr_value_maxsz)
112#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400113#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
114 1 + 2 + 1 + \
115 nfs4_owner_maxsz + \
116 nfs4_group_maxsz + \
117 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#define encode_savefh_maxsz (op_encode_hdr_maxsz)
119#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400120#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
121#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200122#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400123/* The 5 accounts for the PNFS attributes, and assumes that at most three
124 * layout types will be returned.
125 */
126#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
127 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
129#define decode_renew_maxsz (op_decode_hdr_maxsz)
130#define encode_setclientid_maxsz \
131 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500132 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
133 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
134 1 /* sc_prog */ + \
135 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
136 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
137 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#define decode_setclientid_maxsz \
139 (op_decode_hdr_maxsz + \
140 2 + \
141 1024) /* large value for CLID_INUSE */
142#define encode_setclientid_confirm_maxsz \
143 (op_encode_hdr_maxsz + \
144 3 + (NFS4_VERIFIER_SIZE >> 2))
145#define decode_setclientid_confirm_maxsz \
146 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400147#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
148#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400149#define encode_share_access_maxsz \
150 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500151#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400152#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
153#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
154#define encode_open_maxsz (op_encode_hdr_maxsz + \
155 2 + encode_share_access_maxsz + 2 + \
156 open_owner_id_maxsz + \
157 encode_opentype_maxsz + \
158 encode_claim_null_maxsz)
159#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400160#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400161 decode_ace_maxsz)
162#define decode_change_info_maxsz (5)
163#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400164 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400165 decode_change_info_maxsz + 1 + \
166 nfs4_fattr_bitmap_maxsz + \
167 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400168#define encode_open_confirm_maxsz \
169 (op_encode_hdr_maxsz + \
170 encode_stateid_maxsz + 1)
171#define decode_open_confirm_maxsz \
172 (op_decode_hdr_maxsz + \
173 decode_stateid_maxsz)
174#define encode_open_downgrade_maxsz \
175 (op_encode_hdr_maxsz + \
176 encode_stateid_maxsz + 1 + \
177 encode_share_access_maxsz)
178#define decode_open_downgrade_maxsz \
179 (op_decode_hdr_maxsz + \
180 decode_stateid_maxsz)
181#define encode_close_maxsz (op_encode_hdr_maxsz + \
182 1 + encode_stateid_maxsz)
183#define decode_close_maxsz (op_decode_hdr_maxsz + \
184 decode_stateid_maxsz)
185#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + \
187 encode_attrs_maxsz)
188#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
189 nfs4_fattr_bitmap_maxsz)
190#define encode_read_maxsz (op_encode_hdr_maxsz + \
191 encode_stateid_maxsz + 3)
192#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
193#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
194 2 + encode_verifier_maxsz + 5)
195#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
196 decode_verifier_maxsz)
197#define encode_readlink_maxsz (op_encode_hdr_maxsz)
198#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
199#define encode_write_maxsz (op_encode_hdr_maxsz + \
200 encode_stateid_maxsz + 4)
201#define decode_write_maxsz (op_decode_hdr_maxsz + \
202 2 + decode_verifier_maxsz)
203#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
204#define decode_commit_maxsz (op_decode_hdr_maxsz + \
205 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206#define encode_remove_maxsz (op_encode_hdr_maxsz + \
207 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400208#define decode_remove_maxsz (op_decode_hdr_maxsz + \
209 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#define encode_rename_maxsz (op_encode_hdr_maxsz + \
211 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400212#define decode_rename_maxsz (op_decode_hdr_maxsz + \
213 decode_change_info_maxsz + \
214 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215#define encode_link_maxsz (op_encode_hdr_maxsz + \
216 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400217#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400218#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400219#define encode_lock_maxsz (op_encode_hdr_maxsz + \
220 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400221 1 + encode_stateid_maxsz + 1 + \
222 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400223#define decode_lock_denied_maxsz \
224 (8 + decode_lockowner_maxsz)
225#define decode_lock_maxsz (op_decode_hdr_maxsz + \
226 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400227#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
228 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400229#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
230 decode_lock_denied_maxsz)
231#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
232 encode_stateid_maxsz + \
233 4)
234#define decode_locku_maxsz (op_decode_hdr_maxsz + \
235 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400236#define encode_release_lockowner_maxsz \
237 (op_encode_hdr_maxsz + \
238 encode_lockowner_maxsz)
239#define decode_release_lockowner_maxsz \
240 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400241#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
242#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
244 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400245 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000246 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
248#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400249 1 + 2 + nfs4_name_maxsz + \
250 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400251#define decode_create_maxsz (op_decode_hdr_maxsz + \
252 decode_change_info_maxsz + \
253 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400254#define encode_statfs_maxsz (encode_getattr_maxsz)
255#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
257#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400258#define encode_getacl_maxsz (encode_getattr_maxsz)
259#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
260 nfs4_fattr_bitmap_maxsz + 1)
261#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
262 encode_stateid_maxsz + 3)
263#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400264#define encode_fs_locations_maxsz \
265 (encode_getattr_maxsz)
266#define decode_fs_locations_maxsz \
267 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000268#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400269#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 -0400270
271#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400272#define NFS4_MAX_MACHINE_NAME_LEN (64)
273
Benny Halevy99fe60d2009-04-01 09:22:29 -0400274#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
275 encode_verifier_maxsz + \
276 1 /* co_ownerid.len */ + \
277 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
278 1 /* flags */ + \
279 1 /* spa_how */ + \
280 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500281 1 /* implementation id array of size 1 */ + \
282 1 /* nii_domain */ + \
283 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
284 1 /* nii_name */ + \
285 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
286 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400287#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
288 2 /* eir_clientid */ + \
289 1 /* eir_sequenceid */ + \
290 1 /* eir_flags */ + \
291 1 /* spr_how */ + \
292 0 /* SP4_NONE (for now) */ + \
293 2 /* eir_server_owner.so_minor_id */ + \
294 /* eir_server_owner.so_major_id<> */ \
295 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
296 /* eir_server_scope<> */ \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
298 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500299 1 /* nii_domain */ + \
300 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
301 1 /* nii_name */ + \
302 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
303 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400304#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
305#define decode_channel_attrs_maxsz (6 + \
306 1 /* ca_rdma_ird.len */ + \
307 1 /* ca_rdma_ird */)
308#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
309 2 /* csa_clientid */ + \
310 1 /* csa_sequence */ + \
311 1 /* csa_flags */ + \
312 encode_channel_attrs_maxsz + \
313 encode_channel_attrs_maxsz + \
314 1 /* csa_cb_program */ + \
315 1 /* csa_sec_parms.len (1) */ + \
316 1 /* cb_secflavor (AUTH_SYS) */ + \
317 1 /* stamp */ + \
318 1 /* machinename.len */ + \
319 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
320 1 /* uid */ + \
321 1 /* gid */ + \
322 1 /* gids.len (0) */)
323#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
324 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
325 1 /* csr_sequence */ + \
326 1 /* csr_flags */ + \
327 decode_channel_attrs_maxsz + \
328 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400329#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
330#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400331#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
332 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
333#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
334 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500335#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
336#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400337#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
338 encode_verifier_maxsz)
339#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
340 2 /* nfs_cookie4 gdlr_cookie */ + \
341 decode_verifier_maxsz \
342 /* verifier4 gdlr_verifier */ + \
343 1 /* gdlr_deviceid_list count */ + \
344 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
345 NFS4_DEVICEID4_SIZE) \
346 /* gdlr_deviceid_list */ + \
347 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400348#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
349 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
350#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
351 1 /* layout type */ + \
352 1 /* opaque devaddr4 length */ + \
353 /* devaddr4 payload is read into page */ \
354 1 /* notification bitmap length */ + \
355 1 /* notification bitmap */)
356#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
357 encode_stateid_maxsz)
358#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
359 decode_stateid_maxsz + \
360 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000361#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
362 2 /* offset */ + \
363 2 /* length */ + \
364 1 /* reclaim */ + \
365 encode_stateid_maxsz + \
366 1 /* new offset (true) */ + \
367 2 /* last byte written */ + \
368 1 /* nt_timechanged (false) */ + \
369 1 /* layoutupdate4 layout type */ + \
370 1 /* NULL filelayout layoutupdate4 payload */)
371#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300372#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
373 encode_stateid_maxsz + \
374 1 /* FIXME: opaque lrf_body always empty at the moment */)
375#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
376 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400377#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
378#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400379#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
380 XDR_QUADLEN(NFS4_STATEID_SIZE))
381#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400382#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
383 XDR_QUADLEN(NFS4_STATEID_SIZE))
384#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400385#else /* CONFIG_NFS_V4_1 */
386#define encode_sequence_maxsz 0
387#define decode_sequence_maxsz 0
388#endif /* CONFIG_NFS_V4_1 */
389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
391#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
392#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400393 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400395 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400397 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400399 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400401 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400403 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400405 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400407 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400409 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400411 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400413 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400415 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400417 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400420 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400425 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400429 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400431 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400433 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400435 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400436 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400437 encode_open_maxsz + \
438 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400439 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400441 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400442 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400443 decode_open_maxsz + \
444 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400445 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400446#define NFS4_enc_open_confirm_sz \
447 (compound_encode_hdr_maxsz + \
448 encode_putfh_maxsz + \
449 encode_open_confirm_maxsz)
450#define NFS4_dec_open_confirm_sz \
451 (compound_decode_hdr_maxsz + \
452 decode_putfh_maxsz + \
453 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400455 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400457 encode_open_maxsz + \
458 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400460 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400462 decode_open_maxsz + \
463 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464#define NFS4_enc_open_downgrade_sz \
465 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400466 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400467 encode_putfh_maxsz + \
468 encode_open_downgrade_maxsz + \
469 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#define NFS4_dec_open_downgrade_sz \
471 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400472 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400473 decode_putfh_maxsz + \
474 decode_open_downgrade_maxsz + \
475 decode_getattr_maxsz)
476#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400477 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400478 encode_putfh_maxsz + \
479 encode_close_maxsz + \
480 encode_getattr_maxsz)
481#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400482 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400483 decode_putfh_maxsz + \
484 decode_close_maxsz + \
485 decode_getattr_maxsz)
486#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400487 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400488 encode_putfh_maxsz + \
489 encode_setattr_maxsz + \
490 encode_getattr_maxsz)
491#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400493 decode_putfh_maxsz + \
494 decode_setattr_maxsz + \
495 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400497 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 encode_putfh_maxsz + \
499 encode_fsinfo_maxsz)
500#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400501 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 decode_putfh_maxsz + \
503 decode_fsinfo_maxsz)
504#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
505 encode_renew_maxsz)
506#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
507 decode_renew_maxsz)
508#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
509 encode_setclientid_maxsz)
510#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
511 decode_setclientid_maxsz)
512#define NFS4_enc_setclientid_confirm_sz \
513 (compound_encode_hdr_maxsz + \
514 encode_setclientid_confirm_maxsz + \
515 encode_putrootfh_maxsz + \
516 encode_fsinfo_maxsz)
517#define NFS4_dec_setclientid_confirm_sz \
518 (compound_decode_hdr_maxsz + \
519 decode_setclientid_confirm_maxsz + \
520 decode_putrootfh_maxsz + \
521 decode_fsinfo_maxsz)
522#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400523 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400525 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400527 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400529 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400531 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400533 encode_lockt_maxsz)
534#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400535 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400536 decode_putfh_maxsz + \
537 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400539 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400541 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400543 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400545 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400546#define NFS4_enc_release_lockowner_sz \
547 (compound_encode_hdr_maxsz + \
548 encode_lockowner_maxsz)
549#define NFS4_dec_release_lockowner_sz \
550 (compound_decode_hdr_maxsz + \
551 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400553 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400555 encode_access_maxsz + \
556 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400558 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400560 decode_access_maxsz + \
561 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400563 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 encode_putfh_maxsz + \
565 encode_getattr_maxsz)
566#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400567 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 decode_putfh_maxsz + \
569 decode_getattr_maxsz)
570#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400571 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 encode_putfh_maxsz + \
573 encode_lookup_maxsz + \
574 encode_getattr_maxsz + \
575 encode_getfh_maxsz)
576#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400577 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400579 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 decode_getattr_maxsz + \
581 decode_getfh_maxsz)
582#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400583 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 encode_putrootfh_maxsz + \
585 encode_getattr_maxsz + \
586 encode_getfh_maxsz)
587#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400588 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 decode_putrootfh_maxsz + \
590 decode_getattr_maxsz + \
591 decode_getfh_maxsz)
592#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400593 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400595 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400597 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400599 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 encode_putfh_maxsz + \
603 encode_savefh_maxsz + \
604 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400605 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400607 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 decode_putfh_maxsz + \
609 decode_savefh_maxsz + \
610 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400611 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400613 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 encode_putfh_maxsz + \
615 encode_savefh_maxsz + \
616 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400617 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400618 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400619 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620#define NFS4_dec_link_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_putfh_maxsz + \
623 decode_savefh_maxsz + \
624 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400625 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400626 decode_restorefh_maxsz + \
627 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400629 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 encode_putfh_maxsz + \
631 encode_symlink_maxsz + \
632 encode_getattr_maxsz + \
633 encode_getfh_maxsz)
634#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400635 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 decode_putfh_maxsz + \
637 decode_symlink_maxsz + \
638 decode_getattr_maxsz + \
639 decode_getfh_maxsz)
640#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400641 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 encode_putfh_maxsz + \
643 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400644 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400645 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400647 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 decode_putfh_maxsz + \
649 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400650 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400651 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400653 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 encode_putfh_maxsz + \
655 encode_getattr_maxsz)
656#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400657 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 decode_putfh_maxsz + \
659 decode_getattr_maxsz)
660#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400661 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400663 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400665 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400667 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400669 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800670 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 encode_getattr_maxsz)
672#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400673 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800674 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 decode_getattr_maxsz)
676#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400677 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100679 encode_delegreturn_maxsz + \
680 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400682 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100683 decode_delegreturn_maxsz + \
684 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000685#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400686 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000687 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400688 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000689#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400690 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000691 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400692 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000693#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400694 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000695 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400696 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000697#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400698 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000699 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400700 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400701#define NFS4_enc_fs_locations_sz \
702 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400703 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400704 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400705 encode_lookup_maxsz + \
706 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400707#define NFS4_dec_fs_locations_sz \
708 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400709 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400710 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400711 decode_lookup_maxsz + \
712 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000713#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
714 encode_sequence_maxsz + \
715 encode_putfh_maxsz + \
716 encode_secinfo_maxsz)
717#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
718 decode_sequence_maxsz + \
719 decode_putfh_maxsz + \
720 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400721#if defined(CONFIG_NFS_V4_1)
722#define NFS4_enc_exchange_id_sz \
723 (compound_encode_hdr_maxsz + \
724 encode_exchange_id_maxsz)
725#define NFS4_dec_exchange_id_sz \
726 (compound_decode_hdr_maxsz + \
727 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400728#define NFS4_enc_create_session_sz \
729 (compound_encode_hdr_maxsz + \
730 encode_create_session_maxsz)
731#define NFS4_dec_create_session_sz \
732 (compound_decode_hdr_maxsz + \
733 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400734#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
735 encode_destroy_session_maxsz)
736#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
737 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400738#define NFS4_enc_sequence_sz \
739 (compound_decode_hdr_maxsz + \
740 encode_sequence_maxsz)
741#define NFS4_dec_sequence_sz \
742 (compound_decode_hdr_maxsz + \
743 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400744#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
745 encode_sequence_maxsz + \
746 encode_putrootfh_maxsz + \
747 encode_fsinfo_maxsz)
748#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
749 decode_sequence_maxsz + \
750 decode_putrootfh_maxsz + \
751 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500752#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
753 encode_sequence_maxsz + \
754 encode_reclaim_complete_maxsz)
755#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
756 decode_sequence_maxsz + \
757 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400758#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
759 encode_sequence_maxsz + \
760 encode_putfh_maxsz + \
761 encode_getdevicelist_maxsz)
762#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
763 decode_sequence_maxsz + \
764 decode_putfh_maxsz + \
765 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400766#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
767 encode_sequence_maxsz +\
768 encode_getdeviceinfo_maxsz)
769#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
770 decode_sequence_maxsz + \
771 decode_getdeviceinfo_maxsz)
772#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
773 encode_sequence_maxsz + \
774 encode_putfh_maxsz + \
775 encode_layoutget_maxsz)
776#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
777 decode_sequence_maxsz + \
778 decode_putfh_maxsz + \
779 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000780#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
781 encode_sequence_maxsz +\
782 encode_putfh_maxsz + \
783 encode_layoutcommit_maxsz + \
784 encode_getattr_maxsz)
785#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
786 decode_sequence_maxsz + \
787 decode_putfh_maxsz + \
788 decode_layoutcommit_maxsz + \
789 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300790#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
791 encode_sequence_maxsz + \
792 encode_putfh_maxsz + \
793 encode_layoutreturn_maxsz)
794#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
795 decode_sequence_maxsz + \
796 decode_putfh_maxsz + \
797 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400798#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
799 encode_sequence_maxsz + \
800 encode_putrootfh_maxsz +\
801 encode_secinfo_no_name_maxsz)
802#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
803 decode_sequence_maxsz + \
804 decode_putrootfh_maxsz + \
805 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400806#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
807 encode_sequence_maxsz + \
808 encode_test_stateid_maxsz)
809#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
810 decode_sequence_maxsz + \
811 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400812#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
813 encode_sequence_maxsz + \
814 encode_free_stateid_maxsz)
815#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
816 decode_sequence_maxsz + \
817 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500818
819const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
820 compound_encode_hdr_maxsz +
821 encode_sequence_maxsz +
822 encode_putfh_maxsz +
823 encode_getattr_maxsz) *
824 XDR_UNIT);
825
826const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
827 compound_decode_hdr_maxsz +
828 decode_sequence_maxsz +
829 decode_putfh_maxsz) *
830 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400831#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500833static unsigned short send_implementation_id = 1;
834
835module_param(send_implementation_id, ushort, 0644);
836MODULE_PARM_DESC(send_implementation_id,
837 "Send implementation ID with NFSv4.1 exchange_id");
838
Trond Myklebustbca79472009-03-11 14:10:26 -0400839static const umode_t nfs_type2fmt[] = {
840 [NF4BAD] = 0,
841 [NF4REG] = S_IFREG,
842 [NF4DIR] = S_IFDIR,
843 [NF4BLK] = S_IFBLK,
844 [NF4CHR] = S_IFCHR,
845 [NF4LNK] = S_IFLNK,
846 [NF4SOCK] = S_IFSOCK,
847 [NF4FIFO] = S_IFIFO,
848 [NF4ATTRDIR] = 0,
849 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850};
851
852struct compound_hdr {
853 int32_t status;
854 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500855 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 uint32_t taglen;
857 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400858 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400859 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860};
861
Benny Halevy13c65ce2009-08-14 17:19:25 +0300862static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
863{
864 __be32 *p = xdr_reserve_space(xdr, nbytes);
865 BUG_ON(!p);
866 return p;
867}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
Trond Myklebustcb17e552012-03-04 18:13:56 -0500869static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
870{
871 __be32 *p;
872
873 p = xdr_reserve_space(xdr, len);
874 xdr_encode_opaque_fixed(p, buf, len);
875}
876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
878{
Al Viro8687b632006-10-19 23:28:48 -0700879 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500881 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 xdr_encode_opaque(p, str, len);
883}
884
Trond Myklebust4ade9822012-03-04 18:13:57 -0500885static void encode_uint32(struct xdr_stream *xdr, u32 n)
886{
887 __be32 *p;
888
889 p = reserve_space(xdr, 4);
890 *p = cpu_to_be32(n);
891}
892
Trond Myklebustff2eb682012-03-05 11:40:12 -0500893static void encode_uint64(struct xdr_stream *xdr, u64 n)
894{
895 __be32 *p;
896
897 p = reserve_space(xdr, 8);
898 xdr_encode_hyper(p, n);
899}
900
Trond Myklebust4ade9822012-03-04 18:13:57 -0500901static void encode_nfs4_seqid(struct xdr_stream *xdr,
902 const struct nfs_seqid *seqid)
903{
904 encode_uint32(xdr, seqid->sequence->counter);
905}
906
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400907static void encode_compound_hdr(struct xdr_stream *xdr,
908 struct rpc_rqst *req,
909 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910{
Al Viro8687b632006-10-19 23:28:48 -0700911 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400912 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400913
914 /* initialize running count of expected bytes in reply.
915 * NOTE: the replied tag SHOULD be the same is the one sent,
916 * but this is not required as a MUST for the server to do so. */
917 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500920 encode_string(xdr, hdr->taglen, hdr->tag);
921 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300922 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500923 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300924 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500925}
926
Trond Myklebustab19b482012-03-04 18:13:57 -0500927static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
928 uint32_t replen,
929 struct compound_hdr *hdr)
930{
931 encode_uint32(xdr, op);
932 hdr->nops++;
933 hdr->replen += replen;
934}
935
Andy Adamsond0179312008-12-23 16:06:17 -0500936static void encode_nops(struct compound_hdr *hdr)
937{
Andy Adamsonfc931582009-04-01 09:22:31 -0400938 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500939 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940}
941
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500942static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
943{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500944 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500945}
946
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
948{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500949 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950}
951
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500952static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953{
954 char owner_name[IDMAP_NAMESZ];
955 char owner_group[IDMAP_NAMESZ];
956 int owner_namelen = 0;
957 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700958 __be32 *p;
959 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 int len;
961 uint32_t bmval0 = 0;
962 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964 /*
965 * We reserve enough space to write the entire attribute buffer at once.
966 * In the worst-case, this would be
967 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
968 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000969 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 */
971 len = 16;
972
973 /* Sigh */
974 if (iap->ia_valid & ATTR_SIZE)
975 len += 8;
976 if (iap->ia_valid & ATTR_MODE)
977 len += 4;
978 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800979 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400981 dprintk("nfs: couldn't resolve uid %d to string\n",
982 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 /* XXX */
984 strcpy(owner_name, "nobody");
985 owner_namelen = sizeof("nobody") - 1;
986 /* goto out; */
987 }
988 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
989 }
990 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800991 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400993 dprintk("nfs: couldn't resolve gid %d to string\n",
994 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 strcpy(owner_group, "nobody");
996 owner_grouplen = sizeof("nobody") - 1;
997 /* goto out; */
998 }
999 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1000 }
1001 if (iap->ia_valid & ATTR_ATIME_SET)
1002 len += 16;
1003 else if (iap->ia_valid & ATTR_ATIME)
1004 len += 4;
1005 if (iap->ia_valid & ATTR_MTIME_SET)
1006 len += 16;
1007 else if (iap->ia_valid & ATTR_MTIME)
1008 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001009 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
1011 /*
1012 * We write the bitmap length now, but leave the bitmap and the attribute
1013 * buffer length to be backfilled at the end of this routine.
1014 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001015 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 q = p;
1017 p += 3;
1018
1019 if (iap->ia_valid & ATTR_SIZE) {
1020 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001021 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 }
1023 if (iap->ia_valid & ATTR_MODE) {
1024 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001025 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 }
1027 if (iap->ia_valid & ATTR_UID) {
1028 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001029 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 }
1031 if (iap->ia_valid & ATTR_GID) {
1032 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001033 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 }
1035 if (iap->ia_valid & ATTR_ATIME_SET) {
1036 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001037 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1038 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001039 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1040 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 }
1042 else if (iap->ia_valid & ATTR_ATIME) {
1043 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001044 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 }
1046 if (iap->ia_valid & ATTR_MTIME_SET) {
1047 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001048 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1049 *p++ = cpu_to_be32(0);
1050 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1051 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 }
1053 else if (iap->ia_valid & ATTR_MTIME) {
1054 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001055 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 /*
1059 * Now we backfill the bitmap and the attribute buffer length.
1060 */
1061 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001062 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 len, ((char *)p - (char *)q) + 4);
1064 BUG();
1065 }
1066 len = (char *)p - (char *)q - 12;
1067 *q++ = htonl(bmval0);
1068 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001069 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072}
1073
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001074static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001076 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1077 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078}
1079
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001080static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081{
Trond Myklebustab19b482012-03-04 18:13:57 -05001082 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001083 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001084 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085}
1086
Fred Isaman0b7c0152012-04-20 14:47:39 -04001087static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088{
Al Viro8687b632006-10-19 23:28:48 -07001089 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001090
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001091 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1092 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001093 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001094 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095}
1096
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001097static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098{
Al Viro8687b632006-10-19 23:28:48 -07001099 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001100
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001101 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1102 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
1104 switch (create->ftype) {
1105 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001106 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001107 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001108 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 break;
1110
1111 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001112 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001113 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001114 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 break;
1116
1117 default:
1118 break;
1119 }
1120
Benny Halevy811652b2009-08-14 17:19:34 +03001121 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001122 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123}
1124
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001125static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126{
Andy Adamson05d564f2008-12-23 16:06:15 -05001127 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001129 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1130 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001131 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001132 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133}
1134
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001135static 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 -07001136{
Andy Adamson05d564f2008-12-23 16:06:15 -05001137 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001139 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1140 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001141 *p++ = cpu_to_be32(2);
1142 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001143 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144}
1145
Fred Isamandae100c2011-07-30 20:52:37 -04001146static void
1147encode_getattr_three(struct xdr_stream *xdr,
1148 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1149 struct compound_hdr *hdr)
1150{
1151 __be32 *p;
1152
Trond Myklebustab19b482012-03-04 18:13:57 -05001153 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001154 if (bm2) {
1155 p = reserve_space(xdr, 16);
1156 *p++ = cpu_to_be32(3);
1157 *p++ = cpu_to_be32(bm0);
1158 *p++ = cpu_to_be32(bm1);
1159 *p = cpu_to_be32(bm2);
1160 } else if (bm1) {
1161 p = reserve_space(xdr, 12);
1162 *p++ = cpu_to_be32(2);
1163 *p++ = cpu_to_be32(bm0);
1164 *p = cpu_to_be32(bm1);
1165 } else {
1166 p = reserve_space(xdr, 8);
1167 *p++ = cpu_to_be32(1);
1168 *p = cpu_to_be32(bm0);
1169 }
Fred Isamandae100c2011-07-30 20:52:37 -04001170}
1171
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001172static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001174 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1175 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176}
1177
Andy Adamson88034c32012-05-23 05:02:34 -04001178static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
1179 struct compound_hdr *hdr)
1180{
1181 encode_getattr_three(xdr,
1182 bitmask[0] & nfs4_fattr_bitmap[0],
1183 bitmask[1] & nfs4_fattr_bitmap[1],
1184 bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD,
1185 hdr);
1186}
1187
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001188static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189{
Fred Isamandae100c2011-07-30 20:52:37 -04001190 encode_getattr_three(xdr,
1191 bitmask[0] & nfs4_fsinfo_bitmap[0],
1192 bitmask[1] & nfs4_fsinfo_bitmap[1],
1193 bitmask[2] & nfs4_fsinfo_bitmap[2],
1194 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195}
1196
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001197static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001198{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001199 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1200 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001201}
1202
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001203static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204{
Trond Myklebustab19b482012-03-04 18:13:57 -05001205 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206}
1207
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001208static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209{
Trond Myklebustab19b482012-03-04 18:13:57 -05001210 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001211 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212}
1213
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001214static inline int nfs4_lock_type(struct file_lock *fl, int block)
1215{
1216 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1217 return block ? NFS4_READW_LT : NFS4_READ_LT;
1218 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1219}
1220
1221static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1222{
1223 if (fl->fl_end == OFFSET_MAX)
1224 return ~(uint64_t)0;
1225 return fl->fl_end - fl->fl_start + 1;
1226}
1227
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001228static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1229{
1230 __be32 *p;
1231
Trond Myklebustd035c362010-12-21 10:45:27 -05001232 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001233 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001234 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001235 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001236 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001237 xdr_encode_hyper(p, lowner->id);
1238}
1239
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240/*
1241 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1242 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1243 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001244static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245{
Al Viro8687b632006-10-19 23:28:48 -07001246 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001248 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1249 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001250 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1251 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001252 p = xdr_encode_hyper(p, args->fl->fl_start);
1253 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001254 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001255 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001256 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001257 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001258 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001259 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 }
1261 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001262 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001263 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265}
1266
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001267static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268{
Al Viro8687b632006-10-19 23:28:48 -07001269 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001271 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1272 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001273 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001274 p = xdr_encode_hyper(p, args->fl->fl_start);
1275 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001276 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277}
1278
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001279static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280{
Al Viro8687b632006-10-19 23:28:48 -07001281 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001283 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1284 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001285 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001286 encode_nfs4_stateid(xdr, args->stateid);
1287 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001288 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001289 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290}
1291
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001292static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1293{
Trond Myklebustab19b482012-03-04 18:13:57 -05001294 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001295 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001296}
1297
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001298static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299{
Trond Myklebustab19b482012-03-04 18:13:57 -05001300 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001301 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302}
1303
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001304static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305{
Al Viro8687b632006-10-19 23:28:48 -07001306 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
Benny Halevy13c65ce2009-08-14 17:19:25 +03001308 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001309 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001310 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001311 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001312 break;
1313 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001314 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001315 break;
1316 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001317 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001318 break;
1319 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001320 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 }
Benny Halevy34558512009-08-14 17:19:30 +03001322 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323}
1324
1325static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1326{
Al Viro8687b632006-10-19 23:28:48 -07001327 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 /*
1329 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1330 * owner 4 = 32
1331 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001332 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001333 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001334 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001335 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001336 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001337 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001338 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001339 *p++ = cpu_to_be32(arg->id.uniquifier);
1340 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341}
1342
1343static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1344{
Al Viro8687b632006-10-19 23:28:48 -07001345 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001346 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Benny Halevy13c65ce2009-08-14 17:19:25 +03001348 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001350 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001351 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001352 encode_attrs(xdr, arg->u.attrs, arg->server);
1353 break;
1354 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001355 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001356 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001357 if (nfs4_has_persistent_session(clp)) {
1358 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1359 encode_attrs(xdr, arg->u.attrs, arg->server);
1360 } else {
1361 struct iattr dummy;
1362
1363 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1364 encode_nfs4_verifier(xdr, &arg->u.verifier);
1365 dummy.ia_valid = 0;
1366 encode_attrs(xdr, &dummy, arg->server);
1367 }
1368 } else {
1369 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1370 encode_nfs4_verifier(xdr, &arg->u.verifier);
1371 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 }
1373}
1374
1375static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1376{
Al Viro8687b632006-10-19 23:28:48 -07001377 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Benny Halevy13c65ce2009-08-14 17:19:25 +03001379 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001381 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001382 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001383 break;
1384 default:
1385 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001386 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001387 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 }
1389}
1390
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001391static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392{
Al Viro8687b632006-10-19 23:28:48 -07001393 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Benny Halevy13c65ce2009-08-14 17:19:25 +03001395 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001397 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001398 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001399 break;
1400 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001401 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001402 break;
1403 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001404 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001405 break;
1406 default:
1407 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 }
1409}
1410
1411static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1412{
Al Viro8687b632006-10-19 23:28:48 -07001413 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Benny Halevy13c65ce2009-08-14 17:19:25 +03001415 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001416 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 encode_string(xdr, name->len, name->name);
1418}
1419
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001420static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421{
Al Viro8687b632006-10-19 23:28:48 -07001422 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
Benny Halevy13c65ce2009-08-14 17:19:25 +03001424 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001425 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 encode_delegation_type(xdr, type);
1427}
1428
1429static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1430{
Al Viro8687b632006-10-19 23:28:48 -07001431 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001433 p = reserve_space(xdr, 4);
1434 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1435 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 encode_string(xdr, name->len, name->name);
1437}
1438
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001439static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440{
Trond Myklebustab19b482012-03-04 18:13:57 -05001441 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 encode_openhdr(xdr, arg);
1443 encode_opentype(xdr, arg);
1444 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001445 case NFS4_OPEN_CLAIM_NULL:
1446 encode_claim_null(xdr, arg->name);
1447 break;
1448 case NFS4_OPEN_CLAIM_PREVIOUS:
1449 encode_claim_previous(xdr, arg->u.delegation_type);
1450 break;
1451 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1452 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1453 break;
1454 default:
1455 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457}
1458
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001459static 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 -07001460{
Trond Myklebustab19b482012-03-04 18:13:57 -05001461 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001462 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001463 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464}
1465
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001466static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
Trond Myklebustab19b482012-03-04 18:13:57 -05001468 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001469 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001470 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001471 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472}
1473
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001474static void
Andy Adamsond0179312008-12-23 16:06:17 -05001475encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476{
Trond Myklebustab19b482012-03-04 18:13:57 -05001477 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001478 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001481static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482{
Trond Myklebustab19b482012-03-04 18:13:57 -05001483 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484}
1485
Trond Myklebust4fc87962012-03-08 17:42:01 -05001486static void encode_open_stateid(struct xdr_stream *xdr,
1487 const struct nfs_open_context *ctx,
1488 const struct nfs_lock_context *l_ctx,
1489 fmode_t fmode,
1490 int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 nfs4_stateid stateid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 if (ctx->state != NULL) {
Trond Myklebust4fc87962012-03-08 17:42:01 -05001495 nfs4_select_rw_stateid(&stateid, ctx->state,
1496 fmode, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001497 if (zero_seqid)
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001498 stateid.seqid = 0;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001499 encode_nfs4_stateid(xdr, &stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 } else
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001501 encode_nfs4_stateid(xdr, &zero_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502}
1503
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001504static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505{
Al Viro8687b632006-10-19 23:28:48 -07001506 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
Trond Myklebustab19b482012-03-04 18:13:57 -05001508 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001509 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001510 FMODE_READ, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
Benny Halevy13c65ce2009-08-14 17:19:25 +03001512 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001513 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001514 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515}
1516
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001517static 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 -07001518{
Trond Myklebust28331a42011-04-27 13:47:52 -04001519 uint32_t attrs[2] = {
1520 FATTR4_WORD0_RDATTR_ERROR,
1521 FATTR4_WORD1_MOUNTED_ON_FILEID,
1522 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001523 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001524 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001526 if (readdir->plus) {
1527 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001528 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001529 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1530 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1531 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1532 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001533 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001534 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001535 /* Use mounted_on_fileid only if the server supports it */
1536 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1537 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001538
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001539 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001540 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001541 encode_nfs4_verifier(xdr, &readdir->verifier);
1542 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001543 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001544 *p++ = cpu_to_be32(readdir->count);
1545 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001546
Benny Halevye75bc1c2009-08-14 17:18:54 +03001547 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001548 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Chuck Levercd937102012-03-02 17:14:31 -05001549 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001550 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1551 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001552 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001553 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001554 attrs[0] & readdir->bitmask[0],
1555 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556}
1557
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001558static 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 -07001559{
Trond Myklebustab19b482012-03-04 18:13:57 -05001560 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561}
1562
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001563static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564{
Trond Myklebustab19b482012-03-04 18:13:57 -05001565 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001566 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567}
1568
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001569static 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 -07001570{
Trond Myklebustab19b482012-03-04 18:13:57 -05001571 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001572 encode_string(xdr, oldname->len, oldname->name);
1573 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574}
1575
Chuck Leverbb4dae52012-03-01 17:01:48 -05001576static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1577 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001579 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001580 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581}
1582
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001583static void
Andy Adamsond0179312008-12-23 16:06:17 -05001584encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001585{
Trond Myklebustab19b482012-03-04 18:13:57 -05001586 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001587}
1588
Chuck Lever9f06c712010-12-14 14:59:18 +00001589static void
Andy Adamsond0179312008-12-23 16:06:17 -05001590encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001591{
Al Viro8687b632006-10-19 23:28:48 -07001592 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001593
Trond Myklebustab19b482012-03-04 18:13:57 -05001594 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001595 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001596 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001597 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001598 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001599 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001600 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001601 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001602 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001603}
1604
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001605static void
Andy Adamsond0179312008-12-23 16:06:17 -05001606encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607{
Trond Myklebustab19b482012-03-04 18:13:57 -05001608 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609}
1610
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001611static 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 -07001612{
Trond Myklebustab19b482012-03-04 18:13:57 -05001613 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001614 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001615 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616}
1617
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001618static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619{
Al Viro8687b632006-10-19 23:28:48 -07001620 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621
Trond Myklebust70019512012-03-04 20:49:32 -05001622 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001623 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
1625 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001626 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001627 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1629 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001630 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001631 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632}
1633
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001634static 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 -07001635{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001636 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1637 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001638 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001639 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640}
1641
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001642static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643{
Al Viro8687b632006-10-19 23:28:48 -07001644 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
Trond Myklebustab19b482012-03-04 18:13:57 -05001646 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001647 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001648 FMODE_WRITE, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
Benny Halevy13c65ce2009-08-14 17:19:25 +03001650 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001651 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001652 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001653 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
1655 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656}
1657
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001658static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659{
Trond Myklebustab19b482012-03-04 18:13:57 -05001660 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001661 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001663
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001664static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1665{
Trond Myklebustab19b482012-03-04 18:13:57 -05001666 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001667 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001668}
1669
Benny Halevy99fe60d2009-04-01 09:22:29 -04001670#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001671/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001672static void encode_exchange_id(struct xdr_stream *xdr,
1673 struct nfs41_exchange_id_args *args,
1674 struct compound_hdr *hdr)
1675{
1676 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001677 char impl_name[NFS4_OPAQUE_LIMIT];
1678 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001679
Trond Myklebust70019512012-03-04 20:49:32 -05001680 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001681 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001682
1683 encode_string(xdr, args->id_len, args->id);
1684
Benny Halevy13c65ce2009-08-14 17:19:25 +03001685 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001686 *p++ = cpu_to_be32(args->flags);
1687 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001688
1689 if (send_implementation_id &&
1690 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1691 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1692 <= NFS4_OPAQUE_LIMIT + 1)
1693 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1694 utsname()->sysname, utsname()->release,
1695 utsname()->version, utsname()->machine);
1696
1697 if (len > 0) {
1698 *p = cpu_to_be32(1); /* implementation id array length=1 */
1699
1700 encode_string(xdr,
1701 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1702 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1703 encode_string(xdr, len, impl_name);
1704 /* just send zeros for nii_date - the date is in nii_name */
1705 p = reserve_space(xdr, 12);
1706 p = xdr_encode_hyper(p, 0);
1707 *p = cpu_to_be32(0);
1708 } else
1709 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001710}
Andy Adamsonfc931582009-04-01 09:22:31 -04001711
1712static void encode_create_session(struct xdr_stream *xdr,
1713 struct nfs41_create_session_args *args,
1714 struct compound_hdr *hdr)
1715{
1716 __be32 *p;
1717 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1718 uint32_t len;
1719 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001720 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001721 u32 max_resp_sz_cached;
1722
1723 /*
1724 * Assumes OPEN is the biggest non-idempotent compound.
1725 * 2 is the verifier.
1726 */
1727 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1728 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001729
Andy Adamsonfc931582009-04-01 09:22:31 -04001730 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1731 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001732
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001733 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1734 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001735 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001736 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1737 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001738
Andy Adamsonfc931582009-04-01 09:22:31 -04001739 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001740 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001741 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1742 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001743 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001744 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1745 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1746 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001747
1748 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001749 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001750 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1751 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1752 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1753 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1754 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1755 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001756
Benny Halevye75bc1c2009-08-14 17:18:54 +03001757 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001758 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001759 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001760
1761 /* authsys_parms rfc1831 */
Chuck Leverf0920752012-05-21 22:45:41 -04001762 *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001763 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001764 *p++ = cpu_to_be32(0); /* UID */
1765 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001766 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001767}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001768
1769static void encode_destroy_session(struct xdr_stream *xdr,
1770 struct nfs4_session *session,
1771 struct compound_hdr *hdr)
1772{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001773 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1774 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001775}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001776
1777static void encode_reclaim_complete(struct xdr_stream *xdr,
1778 struct nfs41_reclaim_complete_args *args,
1779 struct compound_hdr *hdr)
1780{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001781 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1782 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001783}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001784#endif /* CONFIG_NFS_V4_1 */
1785
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001786static void encode_sequence(struct xdr_stream *xdr,
1787 const struct nfs4_sequence_args *args,
1788 struct compound_hdr *hdr)
1789{
1790#if defined(CONFIG_NFS_V4_1)
1791 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001792 struct nfs4_slot_table *tp;
1793 struct nfs4_slot *slot;
1794 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001795
1796 if (!session)
1797 return;
1798
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001799 tp = &session->fc_slot_table;
1800
1801 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1802 slot = tp->slots + args->sa_slotid;
1803
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001804 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001805
1806 /*
1807 * Sessionid + seqid + slotid + max slotid + cache_this
1808 */
1809 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1810 "max_slotid=%d cache_this=%d\n",
1811 __func__,
1812 ((u32 *)session->sess_id.data)[0],
1813 ((u32 *)session->sess_id.data)[1],
1814 ((u32 *)session->sess_id.data)[2],
1815 ((u32 *)session->sess_id.data)[3],
1816 slot->seq_nr, args->sa_slotid,
1817 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001818 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001819 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001820 *p++ = cpu_to_be32(slot->seq_nr);
1821 *p++ = cpu_to_be32(args->sa_slotid);
1822 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001823 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001824#endif /* CONFIG_NFS_V4_1 */
1825}
1826
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001827#ifdef CONFIG_NFS_V4_1
1828static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001829encode_getdevicelist(struct xdr_stream *xdr,
1830 const struct nfs4_getdevicelist_args *args,
1831 struct compound_hdr *hdr)
1832{
1833 __be32 *p;
1834 nfs4_verifier dummy = {
1835 .data = "dummmmmy",
1836 };
1837
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001838 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1839 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001840 *p++ = cpu_to_be32(args->layoutclass);
1841 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1842 xdr_encode_hyper(p, 0ULL); /* cookie */
1843 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001844}
1845
1846static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001847encode_getdeviceinfo(struct xdr_stream *xdr,
1848 const struct nfs4_getdeviceinfo_args *args,
1849 struct compound_hdr *hdr)
1850{
1851 __be32 *p;
1852
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001853 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1854 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001855 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1856 NFS4_DEVICEID4_SIZE);
1857 *p++ = cpu_to_be32(args->pdev->layout_type);
1858 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1859 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001860}
1861
1862static void
1863encode_layoutget(struct xdr_stream *xdr,
1864 const struct nfs4_layoutget_args *args,
1865 struct compound_hdr *hdr)
1866{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001867 __be32 *p;
1868
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001869 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1870 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001871 *p++ = cpu_to_be32(0); /* Signal layout available */
1872 *p++ = cpu_to_be32(args->type);
1873 *p++ = cpu_to_be32(args->range.iomode);
1874 p = xdr_encode_hyper(p, args->range.offset);
1875 p = xdr_encode_hyper(p, args->range.length);
1876 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001877 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001878 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001879
1880 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1881 __func__,
1882 args->type,
1883 args->range.iomode,
1884 (unsigned long)args->range.offset,
1885 (unsigned long)args->range.length,
1886 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001887}
Andy Adamson863a3c62011-03-23 13:27:54 +00001888
1889static int
1890encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001891 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001892 const struct nfs4_layoutcommit_args *args,
1893 struct compound_hdr *hdr)
1894{
1895 __be32 *p;
1896
1897 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1898 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1899
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001900 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1901 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001902 /* Only whole file layouts */
1903 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001904 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001905 *p = cpu_to_be32(0); /* reclaim */
1906 encode_nfs4_stateid(xdr, &args->stateid);
1907 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001908 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1909 p = xdr_encode_hyper(p, args->lastbytewritten);
1910 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1911 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001912
1913 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1914 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1915 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001916 else
1917 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001918
Andy Adamson863a3c62011-03-23 13:27:54 +00001919 return 0;
1920}
Benny Halevycbe82602011-05-22 19:52:37 +03001921
1922static void
1923encode_layoutreturn(struct xdr_stream *xdr,
1924 const struct nfs4_layoutreturn_args *args,
1925 struct compound_hdr *hdr)
1926{
1927 __be32 *p;
1928
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001929 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1930 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001931 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1932 *p++ = cpu_to_be32(args->layout_type);
1933 *p++ = cpu_to_be32(IOMODE_ANY);
1934 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001935 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001936 p = xdr_encode_hyper(p, 0);
1937 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1938 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001939 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001940 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001941 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1942 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1943 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001944 } else
1945 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03001946}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001947
1948static int
1949encode_secinfo_no_name(struct xdr_stream *xdr,
1950 const struct nfs41_secinfo_no_name_args *args,
1951 struct compound_hdr *hdr)
1952{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001953 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1954 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001955 return 0;
1956}
Bryan Schumaker7d974792011-06-02 14:59:08 -04001957
1958static void encode_test_stateid(struct xdr_stream *xdr,
1959 struct nfs41_test_stateid_args *args,
1960 struct compound_hdr *hdr)
1961{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001962 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
1963 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001964 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04001965}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001966
1967static void encode_free_stateid(struct xdr_stream *xdr,
1968 struct nfs41_free_stateid_args *args,
1969 struct compound_hdr *hdr)
1970{
Trond Myklebustab19b482012-03-04 18:13:57 -05001971 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001972 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001973}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001974#endif /* CONFIG_NFS_V4_1 */
1975
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976/*
1977 * END OF "GENERIC" ENCODE ROUTINES.
1978 */
1979
Benny Halevy66cc0422009-04-01 09:22:10 -04001980static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1981{
1982#if defined(CONFIG_NFS_V4_1)
1983 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001984 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001985#endif /* CONFIG_NFS_V4_1 */
1986 return 0;
1987}
1988
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989/*
1990 * Encode an ACCESS request
1991 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001992static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1993 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001996 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
Chuck Lever9f06c712010-12-14 14:59:18 +00001999 encode_compound_hdr(xdr, req, &hdr);
2000 encode_sequence(xdr, &args->seq_args, &hdr);
2001 encode_putfh(xdr, args->fh, &hdr);
2002 encode_access(xdr, args->access, &hdr);
2003 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002004 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005}
2006
2007/*
2008 * Encode LOOKUP request
2009 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002010static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2011 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002014 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016
Chuck Lever9f06c712010-12-14 14:59:18 +00002017 encode_compound_hdr(xdr, req, &hdr);
2018 encode_sequence(xdr, &args->seq_args, &hdr);
2019 encode_putfh(xdr, args->dir_fh, &hdr);
2020 encode_lookup(xdr, args->name, &hdr);
2021 encode_getfh(xdr, &hdr);
2022 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002023 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024}
2025
2026/*
2027 * Encode LOOKUP_ROOT request
2028 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002029static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2030 struct xdr_stream *xdr,
2031 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002034 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036
Chuck Lever9f06c712010-12-14 14:59:18 +00002037 encode_compound_hdr(xdr, req, &hdr);
2038 encode_sequence(xdr, &args->seq_args, &hdr);
2039 encode_putrootfh(xdr, &hdr);
2040 encode_getfh(xdr, &hdr);
2041 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002042 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043}
2044
2045/*
2046 * Encode REMOVE request
2047 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002048static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2049 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002052 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
Chuck Lever9f06c712010-12-14 14:59:18 +00002055 encode_compound_hdr(xdr, req, &hdr);
2056 encode_sequence(xdr, &args->seq_args, &hdr);
2057 encode_putfh(xdr, args->fh, &hdr);
2058 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002059 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060}
2061
2062/*
2063 * Encode RENAME request
2064 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002065static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2066 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002069 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
Chuck Lever9f06c712010-12-14 14:59:18 +00002072 encode_compound_hdr(xdr, req, &hdr);
2073 encode_sequence(xdr, &args->seq_args, &hdr);
2074 encode_putfh(xdr, args->old_dir, &hdr);
2075 encode_savefh(xdr, &hdr);
2076 encode_putfh(xdr, args->new_dir, &hdr);
2077 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002078 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079}
2080
2081/*
2082 * Encode LINK request
2083 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002084static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2085 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002088 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090
Chuck Lever9f06c712010-12-14 14:59:18 +00002091 encode_compound_hdr(xdr, req, &hdr);
2092 encode_sequence(xdr, &args->seq_args, &hdr);
2093 encode_putfh(xdr, args->fh, &hdr);
2094 encode_savefh(xdr, &hdr);
2095 encode_putfh(xdr, args->dir_fh, &hdr);
2096 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002097 encode_restorefh(xdr, &hdr);
2098 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002099 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100}
2101
2102/*
2103 * Encode CREATE request
2104 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002105static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2106 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002109 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111
Chuck Lever9f06c712010-12-14 14:59:18 +00002112 encode_compound_hdr(xdr, req, &hdr);
2113 encode_sequence(xdr, &args->seq_args, &hdr);
2114 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002115 encode_create(xdr, args, &hdr);
2116 encode_getfh(xdr, &hdr);
2117 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002118 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119}
2120
2121/*
2122 * Encode SYMLINK request
2123 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002124static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2125 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126{
Chuck Lever9f06c712010-12-14 14:59:18 +00002127 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128}
2129
2130/*
2131 * Encode GETATTR request
2132 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002133static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2134 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002137 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
Chuck Lever9f06c712010-12-14 14:59:18 +00002140 encode_compound_hdr(xdr, req, &hdr);
2141 encode_sequence(xdr, &args->seq_args, &hdr);
2142 encode_putfh(xdr, args->fh, &hdr);
2143 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002144 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145}
2146
2147/*
2148 * Encode a CLOSE request
2149 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002150static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2151 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152{
Andy Adamson05d564f2008-12-23 16:06:15 -05002153 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002154 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002155 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156
Chuck Lever9f06c712010-12-14 14:59:18 +00002157 encode_compound_hdr(xdr, req, &hdr);
2158 encode_sequence(xdr, &args->seq_args, &hdr);
2159 encode_putfh(xdr, args->fh, &hdr);
2160 encode_close(xdr, args, &hdr);
2161 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002162 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163}
2164
2165/*
2166 * Encode an OPEN request
2167 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002168static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2169 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002172 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
Chuck Lever9f06c712010-12-14 14:59:18 +00002175 encode_compound_hdr(xdr, req, &hdr);
2176 encode_sequence(xdr, &args->seq_args, &hdr);
2177 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002178 encode_open(xdr, args, &hdr);
2179 encode_getfh(xdr, &hdr);
Andy Adamson88034c32012-05-23 05:02:34 -04002180 encode_getfattr_open(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002181 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182}
2183
2184/*
2185 * Encode an OPEN_CONFIRM request
2186 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002187static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2188 struct xdr_stream *xdr,
2189 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002192 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
Chuck Lever9f06c712010-12-14 14:59:18 +00002195 encode_compound_hdr(xdr, req, &hdr);
2196 encode_putfh(xdr, args->fh, &hdr);
2197 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002198 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199}
2200
2201/*
2202 * Encode an OPEN request with no attributes.
2203 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002204static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2205 struct xdr_stream *xdr,
2206 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002209 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
Chuck Lever9f06c712010-12-14 14:59:18 +00002212 encode_compound_hdr(xdr, req, &hdr);
2213 encode_sequence(xdr, &args->seq_args, &hdr);
2214 encode_putfh(xdr, args->fh, &hdr);
2215 encode_open(xdr, args, &hdr);
2216 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002217 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218}
2219
2220/*
2221 * Encode an OPEN_DOWNGRADE request
2222 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002223static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2224 struct xdr_stream *xdr,
2225 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002228 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
Chuck Lever9f06c712010-12-14 14:59:18 +00002231 encode_compound_hdr(xdr, req, &hdr);
2232 encode_sequence(xdr, &args->seq_args, &hdr);
2233 encode_putfh(xdr, args->fh, &hdr);
2234 encode_open_downgrade(xdr, args, &hdr);
2235 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002236 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237}
2238
2239/*
2240 * Encode a LOCK request
2241 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002242static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2243 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002246 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
Chuck Lever9f06c712010-12-14 14:59:18 +00002249 encode_compound_hdr(xdr, req, &hdr);
2250 encode_sequence(xdr, &args->seq_args, &hdr);
2251 encode_putfh(xdr, args->fh, &hdr);
2252 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002253 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254}
2255
2256/*
2257 * Encode a LOCKT request
2258 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002259static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2260 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002263 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265
Chuck Lever9f06c712010-12-14 14:59:18 +00002266 encode_compound_hdr(xdr, req, &hdr);
2267 encode_sequence(xdr, &args->seq_args, &hdr);
2268 encode_putfh(xdr, args->fh, &hdr);
2269 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002270 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271}
2272
2273/*
2274 * Encode a LOCKU request
2275 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002276static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2277 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002280 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
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_sequence(xdr, &args->seq_args, &hdr);
2285 encode_putfh(xdr, args->fh, &hdr);
2286 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002287 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288}
2289
Chuck Lever9f06c712010-12-14 14:59:18 +00002290static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2291 struct xdr_stream *xdr,
2292 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002293{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002294 struct compound_hdr hdr = {
2295 .minorversion = 0,
2296 };
2297
Chuck Lever9f06c712010-12-14 14:59:18 +00002298 encode_compound_hdr(xdr, req, &hdr);
2299 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002300 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002301}
2302
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303/*
2304 * Encode a READLINK request
2305 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002306static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2307 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002310 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
Chuck Lever9f06c712010-12-14 14:59:18 +00002313 encode_compound_hdr(xdr, req, &hdr);
2314 encode_sequence(xdr, &args->seq_args, &hdr);
2315 encode_putfh(xdr, args->fh, &hdr);
2316 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002317
Benny Halevy28f56692009-04-01 09:22:09 -04002318 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002319 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002320 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321}
2322
2323/*
2324 * Encode a READDIR request
2325 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002326static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2327 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002330 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332
Chuck Lever9f06c712010-12-14 14:59:18 +00002333 encode_compound_hdr(xdr, req, &hdr);
2334 encode_sequence(xdr, &args->seq_args, &hdr);
2335 encode_putfh(xdr, args->fh, &hdr);
2336 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002337
Benny Halevy28f56692009-04-01 09:22:09 -04002338 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002339 args->pgbase, args->count);
2340 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002341 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002342 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002343 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344}
2345
2346/*
2347 * Encode a READ request
2348 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002349static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2350 struct nfs_readargs *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_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360
Benny Halevy28f56692009-04-01 09:22:09 -04002361 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002363 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002364 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365}
2366
2367/*
2368 * Encode an SETATTR request
2369 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002370static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2371 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372{
Andy Adamson05d564f2008-12-23 16:06:15 -05002373 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002374 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002375 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376
Chuck Lever9f06c712010-12-14 14:59:18 +00002377 encode_compound_hdr(xdr, req, &hdr);
2378 encode_sequence(xdr, &args->seq_args, &hdr);
2379 encode_putfh(xdr, args->fh, &hdr);
2380 encode_setattr(xdr, args, args->server, &hdr);
2381 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002382 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383}
2384
2385/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002386 * Encode a GETACL request
2387 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002388static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2389 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002390{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002391 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002392 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002393 };
Benny Halevy28f56692009-04-01 09:22:09 -04002394 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002395
Chuck Lever9f06c712010-12-14 14:59:18 +00002396 encode_compound_hdr(xdr, req, &hdr);
2397 encode_sequence(xdr, &args->seq_args, &hdr);
2398 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002399 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002400 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002401
Benny Halevy28f56692009-04-01 09:22:09 -04002402 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002403 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002404
Andy Adamsond0179312008-12-23 16:06:17 -05002405 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002406}
2407
2408/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 * Encode a WRITE request
2410 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002411static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2412 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002415 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
Chuck Lever9f06c712010-12-14 14:59:18 +00002418 encode_compound_hdr(xdr, req, &hdr);
2419 encode_sequence(xdr, &args->seq_args, &hdr);
2420 encode_putfh(xdr, args->fh, &hdr);
2421 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002422 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002423 if (args->bitmask)
2424 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002425 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426}
2427
2428/*
2429 * a COMMIT request
2430 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002431static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002432 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002435 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437
Chuck Lever9f06c712010-12-14 14:59:18 +00002438 encode_compound_hdr(xdr, req, &hdr);
2439 encode_sequence(xdr, &args->seq_args, &hdr);
2440 encode_putfh(xdr, args->fh, &hdr);
2441 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002442 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443}
2444
2445/*
2446 * FSINFO request
2447 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002448static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2449 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002452 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454
Chuck Lever9f06c712010-12-14 14:59:18 +00002455 encode_compound_hdr(xdr, req, &hdr);
2456 encode_sequence(xdr, &args->seq_args, &hdr);
2457 encode_putfh(xdr, args->fh, &hdr);
2458 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002459 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460}
2461
2462/*
2463 * a PATHCONF request
2464 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002465static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2466 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002469 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
Chuck Lever9f06c712010-12-14 14:59:18 +00002472 encode_compound_hdr(xdr, req, &hdr);
2473 encode_sequence(xdr, &args->seq_args, &hdr);
2474 encode_putfh(xdr, args->fh, &hdr);
2475 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002476 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002477 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478}
2479
2480/*
2481 * a STATFS request
2482 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002483static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2484 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002487 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
Chuck Lever9f06c712010-12-14 14:59:18 +00002490 encode_compound_hdr(xdr, req, &hdr);
2491 encode_sequence(xdr, &args->seq_args, &hdr);
2492 encode_putfh(xdr, args->fh, &hdr);
2493 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002494 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002495 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496}
2497
2498/*
2499 * GETATTR_BITMAP request
2500 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002501static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2502 struct xdr_stream *xdr,
2503 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002506 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508
Chuck Lever9f06c712010-12-14 14:59:18 +00002509 encode_compound_hdr(xdr, req, &hdr);
2510 encode_sequence(xdr, &args->seq_args, &hdr);
2511 encode_putfh(xdr, args->fhandle, &hdr);
2512 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002513 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002514 FATTR4_WORD0_LINK_SUPPORT|
2515 FATTR4_WORD0_SYMLINK_SUPPORT|
2516 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002517 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518}
2519
2520/*
2521 * a RENEW request
2522 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002523static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2524 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002527 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 };
2529
Chuck Lever9f06c712010-12-14 14:59:18 +00002530 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002531 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002532 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533}
2534
2535/*
2536 * a SETCLIENTID request
2537 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002538static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2539 struct xdr_stream *xdr,
2540 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002543 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 };
2545
Chuck Lever9f06c712010-12-14 14:59:18 +00002546 encode_compound_hdr(xdr, req, &hdr);
2547 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002548 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549}
2550
2551/*
2552 * a SETCLIENTID_CONFIRM request
2553 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002554static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2555 struct xdr_stream *xdr,
2556 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002559 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 };
Fred Isamandae100c2011-07-30 20:52:37 -04002561 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562
Chuck Lever9f06c712010-12-14 14:59:18 +00002563 encode_compound_hdr(xdr, req, &hdr);
2564 encode_setclientid_confirm(xdr, arg, &hdr);
2565 encode_putrootfh(xdr, &hdr);
2566 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002567 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568}
2569
2570/*
2571 * DELEGRETURN request
2572 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002573static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2574 struct xdr_stream *xdr,
2575 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002578 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580
Chuck Lever9f06c712010-12-14 14:59:18 +00002581 encode_compound_hdr(xdr, req, &hdr);
2582 encode_sequence(xdr, &args->seq_args, &hdr);
2583 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002584 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002585 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002586 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587}
2588
2589/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002590 * Encode FS_LOCATIONS request
2591 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002592static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2593 struct xdr_stream *xdr,
2594 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002595{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002596 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002597 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002598 };
Benny Halevy28f56692009-04-01 09:22:09 -04002599 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002600
Chuck Lever9f06c712010-12-14 14:59:18 +00002601 encode_compound_hdr(xdr, req, &hdr);
2602 encode_sequence(xdr, &args->seq_args, &hdr);
2603 encode_putfh(xdr, args->dir_fh, &hdr);
2604 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002605 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002606 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002607
Benny Halevy28f56692009-04-01 09:22:09 -04002608 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002609 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002610 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002611}
2612
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002613/*
2614 * Encode SECINFO request
2615 */
2616static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2617 struct xdr_stream *xdr,
2618 struct nfs4_secinfo_arg *args)
2619{
2620 struct compound_hdr hdr = {
2621 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2622 };
2623
2624 encode_compound_hdr(xdr, req, &hdr);
2625 encode_sequence(xdr, &args->seq_args, &hdr);
2626 encode_putfh(xdr, args->dir_fh, &hdr);
2627 encode_secinfo(xdr, args->name, &hdr);
2628 encode_nops(&hdr);
2629}
2630
Benny Halevy99fe60d2009-04-01 09:22:29 -04002631#if defined(CONFIG_NFS_V4_1)
2632/*
2633 * EXCHANGE_ID request
2634 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002635static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2636 struct xdr_stream *xdr,
2637 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002638{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002639 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002640 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002641 };
2642
Chuck Lever9f06c712010-12-14 14:59:18 +00002643 encode_compound_hdr(xdr, req, &hdr);
2644 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002645 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002646}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002647
2648/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002649 * a CREATE_SESSION request
2650 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002651static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2652 struct xdr_stream *xdr,
2653 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002654{
Andy Adamsonfc931582009-04-01 09:22:31 -04002655 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002656 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002657 };
2658
Chuck Lever9f06c712010-12-14 14:59:18 +00002659 encode_compound_hdr(xdr, req, &hdr);
2660 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002661 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002662}
2663
2664/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002665 * a DESTROY_SESSION request
2666 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002667static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2668 struct xdr_stream *xdr,
2669 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002670{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002671 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002672 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002673 };
2674
Chuck Lever9f06c712010-12-14 14:59:18 +00002675 encode_compound_hdr(xdr, req, &hdr);
2676 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002677 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002678}
2679
2680/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002681 * a SEQUENCE request
2682 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002683static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2684 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002685{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002686 struct compound_hdr hdr = {
2687 .minorversion = nfs4_xdr_minorversion(args),
2688 };
2689
Chuck Lever9f06c712010-12-14 14:59:18 +00002690 encode_compound_hdr(xdr, req, &hdr);
2691 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002692 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002693}
2694
2695/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002696 * a GET_LEASE_TIME request
2697 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002698static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2699 struct xdr_stream *xdr,
2700 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002701{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002702 struct compound_hdr hdr = {
2703 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2704 };
Fred Isamandae100c2011-07-30 20:52:37 -04002705 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002706
Chuck Lever9f06c712010-12-14 14:59:18 +00002707 encode_compound_hdr(xdr, req, &hdr);
2708 encode_sequence(xdr, &args->la_seq_args, &hdr);
2709 encode_putrootfh(xdr, &hdr);
2710 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002711 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002712}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002713
2714/*
2715 * a RECLAIM_COMPLETE request
2716 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002717static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2718 struct xdr_stream *xdr,
2719 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002720{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002721 struct compound_hdr hdr = {
2722 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2723 };
2724
Chuck Lever9f06c712010-12-14 14:59:18 +00002725 encode_compound_hdr(xdr, req, &hdr);
2726 encode_sequence(xdr, &args->seq_args, &hdr);
2727 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002728 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002729}
2730
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002731/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002732 * Encode GETDEVICELIST request
2733 */
2734static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2735 struct xdr_stream *xdr,
2736 struct nfs4_getdevicelist_args *args)
2737{
2738 struct compound_hdr hdr = {
2739 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2740 };
2741
2742 encode_compound_hdr(xdr, req, &hdr);
2743 encode_sequence(xdr, &args->seq_args, &hdr);
2744 encode_putfh(xdr, args->fh, &hdr);
2745 encode_getdevicelist(xdr, args, &hdr);
2746 encode_nops(&hdr);
2747}
2748
2749/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002750 * Encode GETDEVICEINFO request
2751 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002752static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2753 struct xdr_stream *xdr,
2754 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002755{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002756 struct compound_hdr hdr = {
2757 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2758 };
2759
Chuck Lever9f06c712010-12-14 14:59:18 +00002760 encode_compound_hdr(xdr, req, &hdr);
2761 encode_sequence(xdr, &args->seq_args, &hdr);
2762 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002763
2764 /* set up reply kvec. Subtract notification bitmap max size (2)
2765 * so that notification bitmap is put in xdr_buf tail */
2766 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2767 args->pdev->pages, args->pdev->pgbase,
2768 args->pdev->pglen);
2769
2770 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002771}
2772
2773/*
2774 * Encode LAYOUTGET request
2775 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002776static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2777 struct xdr_stream *xdr,
2778 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002779{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002780 struct compound_hdr hdr = {
2781 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2782 };
2783
Chuck Lever9f06c712010-12-14 14:59:18 +00002784 encode_compound_hdr(xdr, req, &hdr);
2785 encode_sequence(xdr, &args->seq_args, &hdr);
2786 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2787 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002788
2789 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2790 args->layout.pages, 0, args->layout.pglen);
2791
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002792 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002793}
Andy Adamson863a3c62011-03-23 13:27:54 +00002794
2795/*
2796 * Encode LAYOUTCOMMIT request
2797 */
Benny Halevycbe82602011-05-22 19:52:37 +03002798static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2799 struct xdr_stream *xdr,
2800 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002801{
Benny Halevyac7db722011-05-22 19:53:48 +03002802 struct nfs4_layoutcommit_data *data =
2803 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002804 struct compound_hdr hdr = {
2805 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2806 };
2807
2808 encode_compound_hdr(xdr, req, &hdr);
2809 encode_sequence(xdr, &args->seq_args, &hdr);
2810 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002811 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002812 encode_getfattr(xdr, args->bitmask, &hdr);
2813 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002814}
2815
2816/*
2817 * Encode LAYOUTRETURN request
2818 */
2819static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2820 struct xdr_stream *xdr,
2821 struct nfs4_layoutreturn_args *args)
2822{
2823 struct compound_hdr hdr = {
2824 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2825 };
2826
2827 encode_compound_hdr(xdr, req, &hdr);
2828 encode_sequence(xdr, &args->seq_args, &hdr);
2829 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2830 encode_layoutreturn(xdr, args, &hdr);
2831 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002832}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002833
2834/*
2835 * Encode SECINFO_NO_NAME request
2836 */
2837static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2838 struct xdr_stream *xdr,
2839 struct nfs41_secinfo_no_name_args *args)
2840{
2841 struct compound_hdr hdr = {
2842 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2843 };
2844
2845 encode_compound_hdr(xdr, req, &hdr);
2846 encode_sequence(xdr, &args->seq_args, &hdr);
2847 encode_putrootfh(xdr, &hdr);
2848 encode_secinfo_no_name(xdr, args, &hdr);
2849 encode_nops(&hdr);
2850 return 0;
2851}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002852
2853/*
2854 * Encode TEST_STATEID request
2855 */
2856static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2857 struct xdr_stream *xdr,
2858 struct nfs41_test_stateid_args *args)
2859{
2860 struct compound_hdr hdr = {
2861 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2862 };
2863
2864 encode_compound_hdr(xdr, req, &hdr);
2865 encode_sequence(xdr, &args->seq_args, &hdr);
2866 encode_test_stateid(xdr, args, &hdr);
2867 encode_nops(&hdr);
2868}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002869
2870/*
2871 * Encode FREE_STATEID request
2872 */
2873static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2874 struct xdr_stream *xdr,
2875 struct nfs41_free_stateid_args *args)
2876{
2877 struct compound_hdr hdr = {
2878 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2879 };
2880
2881 encode_compound_hdr(xdr, req, &hdr);
2882 encode_sequence(xdr, &args->seq_args, &hdr);
2883 encode_free_stateid(xdr, args, &hdr);
2884 encode_nops(&hdr);
2885}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002886#endif /* CONFIG_NFS_V4_1 */
2887
Benny Halevy686841b2009-08-14 17:19:48 +03002888static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2889{
2890 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2891 "Remaining buffer length is %tu words.\n",
2892 func, xdr->end - xdr->p);
2893}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894
Trond Myklebust683b57b2006-06-09 09:34:22 -04002895static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896{
Al Viro8687b632006-10-19 23:28:48 -07002897 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898
Benny Halevyc0eae662009-08-14 17:20:14 +03002899 p = xdr_inline_decode(xdr, 4);
2900 if (unlikely(!p))
2901 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002902 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002903 p = xdr_inline_decode(xdr, *len);
2904 if (unlikely(!p))
2905 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 *string = (char *)p;
2907 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002908out_overflow:
2909 print_overflow_msg(__func__, xdr);
2910 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911}
2912
2913static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2914{
Al Viro8687b632006-10-19 23:28:48 -07002915 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916
Benny Halevyc0eae662009-08-14 17:20:14 +03002917 p = xdr_inline_decode(xdr, 8);
2918 if (unlikely(!p))
2919 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002920 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002921 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002922
Benny Halevyc0eae662009-08-14 17:20:14 +03002923 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2924 if (unlikely(!p))
2925 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 hdr->tag = (char *)p;
2927 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002928 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002929 if (unlikely(hdr->nops < 1))
2930 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002932out_overflow:
2933 print_overflow_msg(__func__, xdr);
2934 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935}
2936
2937static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2938{
Al Viro8687b632006-10-19 23:28:48 -07002939 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 uint32_t opnum;
2941 int32_t nfserr;
2942
Benny Halevyc0eae662009-08-14 17:20:14 +03002943 p = xdr_inline_decode(xdr, 8);
2944 if (unlikely(!p))
2945 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002946 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002948 dprintk("nfs: Server returned operation"
2949 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 opnum, expected);
2951 return -EIO;
2952 }
Benny Halevycccddf42009-08-14 17:20:19 +03002953 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002955 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002957out_overflow:
2958 print_overflow_msg(__func__, xdr);
2959 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960}
2961
2962/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002963static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964{
Al Viro8687b632006-10-19 23:28:48 -07002965 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002966 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 char *str;
2968
Benny Halevyc0eae662009-08-14 17:20:14 +03002969 p = xdr_inline_decode(xdr, 12);
2970 if (likely(p))
2971 return decode_opaque_inline(xdr, &strlen, &str);
2972 print_overflow_msg(__func__, xdr);
2973 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974}
2975
2976static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2977{
Al Viro8687b632006-10-19 23:28:48 -07002978 uint32_t bmlen;
2979 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980
Benny Halevyc0eae662009-08-14 17:20:14 +03002981 p = xdr_inline_decode(xdr, 4);
2982 if (unlikely(!p))
2983 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002984 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985
Fred Isamandae100c2011-07-30 20:52:37 -04002986 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002987 p = xdr_inline_decode(xdr, (bmlen << 2));
2988 if (unlikely(!p))
2989 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002991 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04002992 if (bmlen > 1) {
2993 bitmap[1] = be32_to_cpup(p++);
2994 if (bmlen > 2)
2995 bitmap[2] = be32_to_cpup(p);
2996 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 }
2998 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002999out_overflow:
3000 print_overflow_msg(__func__, xdr);
3001 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002}
3003
Al Viro8687b632006-10-19 23:28:48 -07003004static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005{
Al Viro8687b632006-10-19 23:28:48 -07003006 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007
Benny Halevyc0eae662009-08-14 17:20:14 +03003008 p = xdr_inline_decode(xdr, 4);
3009 if (unlikely(!p))
3010 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003011 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 *savep = xdr->p;
3013 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003014out_overflow:
3015 print_overflow_msg(__func__, xdr);
3016 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017}
3018
3019static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3020{
3021 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003022 int ret;
3023 ret = decode_attr_bitmap(xdr, bitmask);
3024 if (unlikely(ret < 0))
3025 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3027 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003028 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3029 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3030 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 return 0;
3032}
3033
3034static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3035{
Al Viro8687b632006-10-19 23:28:48 -07003036 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003037 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038
3039 *type = 0;
3040 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3041 return -EIO;
3042 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003043 p = xdr_inline_decode(xdr, 4);
3044 if (unlikely(!p))
3045 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003046 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003048 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 return -EIO;
3050 }
3051 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003052 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003054 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003055 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003056out_overflow:
3057 print_overflow_msg(__func__, xdr);
3058 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059}
3060
Chuck Lever264e6352012-03-01 17:02:05 -05003061static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3062 uint32_t *bitmap, uint32_t *type)
3063{
3064 __be32 *p;
3065
3066 *type = 0;
3067 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3068 return -EIO;
3069 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3070 p = xdr_inline_decode(xdr, 4);
3071 if (unlikely(!p))
3072 goto out_overflow;
3073 *type = be32_to_cpup(p);
3074 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3075 }
3076 dprintk("%s: expire type=0x%x\n", __func__, *type);
3077 return 0;
3078out_overflow:
3079 print_overflow_msg(__func__, xdr);
3080 return -EIO;
3081}
3082
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3084{
Al Viro8687b632006-10-19 23:28:48 -07003085 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003086 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087
3088 *change = 0;
3089 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3090 return -EIO;
3091 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003092 p = xdr_inline_decode(xdr, 8);
3093 if (unlikely(!p))
3094 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003095 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003097 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003099 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003101 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003102out_overflow:
3103 print_overflow_msg(__func__, xdr);
3104 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105}
3106
3107static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3108{
Al Viro8687b632006-10-19 23:28:48 -07003109 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003110 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111
3112 *size = 0;
3113 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3114 return -EIO;
3115 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003116 p = xdr_inline_decode(xdr, 8);
3117 if (unlikely(!p))
3118 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003119 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003121 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003123 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003124 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003125out_overflow:
3126 print_overflow_msg(__func__, xdr);
3127 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128}
3129
3130static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3131{
Al Viro8687b632006-10-19 23:28:48 -07003132 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133
3134 *res = 0;
3135 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3136 return -EIO;
3137 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003138 p = xdr_inline_decode(xdr, 4);
3139 if (unlikely(!p))
3140 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003141 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3143 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003144 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003146out_overflow:
3147 print_overflow_msg(__func__, xdr);
3148 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149}
3150
3151static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3152{
Al Viro8687b632006-10-19 23:28:48 -07003153 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154
3155 *res = 0;
3156 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3157 return -EIO;
3158 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003159 p = xdr_inline_decode(xdr, 4);
3160 if (unlikely(!p))
3161 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003162 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3164 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003165 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003167out_overflow:
3168 print_overflow_msg(__func__, xdr);
3169 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170}
3171
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003172static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173{
Al Viro8687b632006-10-19 23:28:48 -07003174 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003175 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176
3177 fsid->major = 0;
3178 fsid->minor = 0;
3179 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3180 return -EIO;
3181 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003182 p = xdr_inline_decode(xdr, 16);
3183 if (unlikely(!p))
3184 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003185 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003186 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003188 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003190 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 (unsigned long long)fsid->major,
3192 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003193 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003194out_overflow:
3195 print_overflow_msg(__func__, xdr);
3196 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197}
3198
3199static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3200{
Al Viro8687b632006-10-19 23:28:48 -07003201 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202
3203 *res = 60;
3204 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3205 return -EIO;
3206 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003207 p = xdr_inline_decode(xdr, 4);
3208 if (unlikely(!p))
3209 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003210 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3212 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003213 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003215out_overflow:
3216 print_overflow_msg(__func__, xdr);
3217 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218}
3219
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003220static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003221{
3222 __be32 *p;
3223
3224 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3225 return -EIO;
3226 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3227 p = xdr_inline_decode(xdr, 4);
3228 if (unlikely(!p))
3229 goto out_overflow;
3230 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003231 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003232 }
3233 return 0;
3234out_overflow:
3235 print_overflow_msg(__func__, xdr);
3236 return -EIO;
3237}
3238
3239static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3240{
3241 __be32 *p;
3242 int len;
3243
Trond Myklebust7ad07352010-10-23 15:34:20 -04003244 if (fh != NULL)
3245 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003246
3247 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3248 return -EIO;
3249 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3250 p = xdr_inline_decode(xdr, 4);
3251 if (unlikely(!p))
3252 goto out_overflow;
3253 len = be32_to_cpup(p);
3254 if (len > NFS4_FHSIZE)
3255 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003256 p = xdr_inline_decode(xdr, len);
3257 if (unlikely(!p))
3258 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003259 if (fh != NULL) {
3260 memcpy(fh->data, p, len);
3261 fh->size = len;
3262 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003263 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3264 }
3265 return 0;
3266out_overflow:
3267 print_overflow_msg(__func__, xdr);
3268 return -EIO;
3269}
3270
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3272{
Al Viro8687b632006-10-19 23:28:48 -07003273 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274
3275 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3276 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3277 return -EIO;
3278 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003279 p = xdr_inline_decode(xdr, 4);
3280 if (unlikely(!p))
3281 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003282 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3284 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003285 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003287out_overflow:
3288 print_overflow_msg(__func__, xdr);
3289 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290}
3291
3292static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3293{
Al Viro8687b632006-10-19 23:28:48 -07003294 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003295 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296
3297 *fileid = 0;
3298 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3299 return -EIO;
3300 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003301 p = xdr_inline_decode(xdr, 8);
3302 if (unlikely(!p))
3303 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003304 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003306 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003308 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003309 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003310out_overflow:
3311 print_overflow_msg(__func__, xdr);
3312 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313}
3314
Manoj Naik99baf622006-06-09 09:34:24 -04003315static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3316{
Al Viro8687b632006-10-19 23:28:48 -07003317 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003318 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003319
3320 *fileid = 0;
3321 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3322 return -EIO;
3323 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003324 p = xdr_inline_decode(xdr, 8);
3325 if (unlikely(!p))
3326 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003327 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003328 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003329 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003330 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003331 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003332 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003333out_overflow:
3334 print_overflow_msg(__func__, xdr);
3335 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003336}
3337
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3339{
Al Viro8687b632006-10-19 23:28:48 -07003340 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 int status = 0;
3342
3343 *res = 0;
3344 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3345 return -EIO;
3346 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003347 p = xdr_inline_decode(xdr, 8);
3348 if (unlikely(!p))
3349 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003350 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3352 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003353 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003355out_overflow:
3356 print_overflow_msg(__func__, xdr);
3357 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358}
3359
3360static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3361{
Al Viro8687b632006-10-19 23:28:48 -07003362 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 int status = 0;
3364
3365 *res = 0;
3366 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3367 return -EIO;
3368 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003369 p = xdr_inline_decode(xdr, 8);
3370 if (unlikely(!p))
3371 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003372 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3374 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003375 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003377out_overflow:
3378 print_overflow_msg(__func__, xdr);
3379 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380}
3381
3382static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3383{
Al Viro8687b632006-10-19 23:28:48 -07003384 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 int status = 0;
3386
3387 *res = 0;
3388 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3389 return -EIO;
3390 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003391 p = xdr_inline_decode(xdr, 8);
3392 if (unlikely(!p))
3393 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003394 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3396 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003397 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003399out_overflow:
3400 print_overflow_msg(__func__, xdr);
3401 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402}
3403
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003404static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3405{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003406 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003407 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003408 int status = 0;
3409
Benny Halevyc0eae662009-08-14 17:20:14 +03003410 p = xdr_inline_decode(xdr, 4);
3411 if (unlikely(!p))
3412 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003413 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003414 if (n == 0)
3415 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003416 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003417 path->ncomponents = 0;
3418 while (path->ncomponents < n) {
3419 struct nfs4_string *component = &path->components[path->ncomponents];
3420 status = decode_opaque_inline(xdr, &component->len, &component->data);
3421 if (unlikely(status != 0))
3422 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003423 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003424 pr_cont("%s%.*s ",
3425 (path->ncomponents != n ? "/ " : ""),
3426 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003427 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3428 path->ncomponents++;
3429 else {
3430 dprintk("cannot parse %d components in path\n", n);
3431 goto out_eio;
3432 }
3433 }
3434out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003435 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003436root_path:
3437/* a root pathname is sent as a zero component4 */
3438 path->ncomponents = 1;
3439 path->components[0].len=0;
3440 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003441 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003442 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003443out_eio:
3444 dprintk(" status %d", status);
3445 status = -EIO;
3446 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003447out_overflow:
3448 print_overflow_msg(__func__, xdr);
3449 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003450}
3451
3452static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003453{
3454 int n;
Al Viro8687b632006-10-19 23:28:48 -07003455 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003456 int status = -EIO;
3457
3458 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3459 goto out;
3460 status = 0;
3461 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3462 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003463 status = -EIO;
3464 /* Ignore borken servers that return unrequested attrs */
3465 if (unlikely(res == NULL))
3466 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003467 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003468 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003469 if (unlikely(status != 0))
3470 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003471 p = xdr_inline_decode(xdr, 4);
3472 if (unlikely(!p))
3473 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003474 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003475 if (n <= 0)
3476 goto out_eio;
3477 res->nlocations = 0;
3478 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003479 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003480 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003481
Benny Halevyc0eae662009-08-14 17:20:14 +03003482 p = xdr_inline_decode(xdr, 4);
3483 if (unlikely(!p))
3484 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003485 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003486
3487 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003488 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003489 while (loc->nservers < m) {
3490 struct nfs4_string *server = &loc->servers[loc->nservers];
3491 status = decode_opaque_inline(xdr, &server->len, &server->data);
3492 if (unlikely(status != 0))
3493 goto out_eio;
3494 dprintk("%s ", server->data);
3495 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3496 loc->nservers++;
3497 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003498 unsigned int i;
3499 dprintk("%s: using first %u of %u servers "
3500 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003501 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003502 NFS4_FS_LOCATION_MAXSERVERS,
3503 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003504 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003505 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003506 char *data;
3507 status = decode_opaque_inline(xdr, &len, &data);
3508 if (unlikely(status != 0))
3509 goto out_eio;
3510 }
3511 }
3512 }
3513 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003514 if (unlikely(status != 0))
3515 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003516 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003517 res->nlocations++;
3518 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003519 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003520 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003521out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003522 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003523 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003524out_overflow:
3525 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003526out_eio:
3527 status = -EIO;
3528 goto out;
3529}
3530
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3532{
Al Viro8687b632006-10-19 23:28:48 -07003533 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534 int status = 0;
3535
3536 *res = 0;
3537 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3538 return -EIO;
3539 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003540 p = xdr_inline_decode(xdr, 8);
3541 if (unlikely(!p))
3542 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003543 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3545 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003546 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003548out_overflow:
3549 print_overflow_msg(__func__, xdr);
3550 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551}
3552
3553static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3554{
Al Viro8687b632006-10-19 23:28:48 -07003555 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 int status = 0;
3557
3558 *maxlink = 1;
3559 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3560 return -EIO;
3561 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003562 p = xdr_inline_decode(xdr, 4);
3563 if (unlikely(!p))
3564 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003565 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3567 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003568 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003570out_overflow:
3571 print_overflow_msg(__func__, xdr);
3572 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573}
3574
3575static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3576{
Al Viro8687b632006-10-19 23:28:48 -07003577 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 int status = 0;
3579
3580 *maxname = 1024;
3581 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3582 return -EIO;
3583 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003584 p = xdr_inline_decode(xdr, 4);
3585 if (unlikely(!p))
3586 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003587 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3589 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003590 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003592out_overflow:
3593 print_overflow_msg(__func__, xdr);
3594 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595}
3596
3597static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3598{
Al Viro8687b632006-10-19 23:28:48 -07003599 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 int status = 0;
3601
3602 *res = 1024;
3603 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3604 return -EIO;
3605 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3606 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003607 p = xdr_inline_decode(xdr, 8);
3608 if (unlikely(!p))
3609 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003610 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611 if (maxread > 0x7FFFFFFF)
3612 maxread = 0x7FFFFFFF;
3613 *res = (uint32_t)maxread;
3614 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3615 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003616 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003618out_overflow:
3619 print_overflow_msg(__func__, xdr);
3620 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621}
3622
3623static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3624{
Al Viro8687b632006-10-19 23:28:48 -07003625 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 int status = 0;
3627
3628 *res = 1024;
3629 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3630 return -EIO;
3631 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3632 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003633 p = xdr_inline_decode(xdr, 8);
3634 if (unlikely(!p))
3635 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003636 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 if (maxwrite > 0x7FFFFFFF)
3638 maxwrite = 0x7FFFFFFF;
3639 *res = (uint32_t)maxwrite;
3640 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3641 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003642 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003644out_overflow:
3645 print_overflow_msg(__func__, xdr);
3646 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647}
3648
Trond Myklebustbca79472009-03-11 14:10:26 -04003649static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650{
Trond Myklebustbca79472009-03-11 14:10:26 -04003651 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003652 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003653 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654
3655 *mode = 0;
3656 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3657 return -EIO;
3658 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003659 p = xdr_inline_decode(xdr, 4);
3660 if (unlikely(!p))
3661 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003662 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003663 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003664 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003665 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003667 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003668 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003669out_overflow:
3670 print_overflow_msg(__func__, xdr);
3671 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672}
3673
3674static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3675{
Al Viro8687b632006-10-19 23:28:48 -07003676 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003677 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678
3679 *nlink = 1;
3680 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3681 return -EIO;
3682 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003683 p = xdr_inline_decode(xdr, 4);
3684 if (unlikely(!p))
3685 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003686 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003688 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003690 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003691 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003692out_overflow:
3693 print_overflow_msg(__func__, xdr);
3694 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695}
3696
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003697static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003698 const struct nfs_server *server, uint32_t *uid,
3699 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700{
Al Viro8687b632006-10-19 23:28:48 -07003701 uint32_t len;
3702 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003703 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704
3705 *uid = -2;
3706 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3707 return -EIO;
3708 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003709 p = xdr_inline_decode(xdr, 4);
3710 if (unlikely(!p))
3711 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003712 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003713 p = xdr_inline_decode(xdr, len);
3714 if (unlikely(!p))
3715 goto out_overflow;
Trond Myklebust6926afd12012-01-07 13:22:46 -05003716 if (owner_name != NULL) {
3717 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3718 if (owner_name->data != NULL) {
3719 owner_name->len = len;
3720 ret = NFS_ATTR_FATTR_OWNER_NAME;
3721 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003722 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003723 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003724 ret = NFS_ATTR_FATTR_OWNER;
3725 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003727 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003729 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003730 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3732 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003733 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003734 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003735out_overflow:
3736 print_overflow_msg(__func__, xdr);
3737 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738}
3739
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003740static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003741 const struct nfs_server *server, uint32_t *gid,
3742 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743{
Al Viro8687b632006-10-19 23:28:48 -07003744 uint32_t len;
3745 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003746 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747
3748 *gid = -2;
3749 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3750 return -EIO;
3751 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003752 p = xdr_inline_decode(xdr, 4);
3753 if (unlikely(!p))
3754 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003755 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003756 p = xdr_inline_decode(xdr, len);
3757 if (unlikely(!p))
3758 goto out_overflow;
Trond Myklebust6926afd12012-01-07 13:22:46 -05003759 if (group_name != NULL) {
3760 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3761 if (group_name->data != NULL) {
3762 group_name->len = len;
3763 ret = NFS_ATTR_FATTR_GROUP_NAME;
3764 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003765 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003766 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003767 ret = NFS_ATTR_FATTR_GROUP;
3768 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003770 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003772 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003773 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3775 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003776 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003777 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003778out_overflow:
3779 print_overflow_msg(__func__, xdr);
3780 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781}
3782
3783static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3784{
Al Viro8687b632006-10-19 23:28:48 -07003785 uint32_t major = 0, minor = 0;
3786 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003787 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788
3789 *rdev = MKDEV(0,0);
3790 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3791 return -EIO;
3792 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3793 dev_t tmp;
3794
Benny Halevyc0eae662009-08-14 17:20:14 +03003795 p = xdr_inline_decode(xdr, 8);
3796 if (unlikely(!p))
3797 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003798 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003799 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 tmp = MKDEV(major, minor);
3801 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3802 *rdev = tmp;
3803 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003804 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003806 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
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
3813static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3814{
Al Viro8687b632006-10-19 23:28:48 -07003815 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 int status = 0;
3817
3818 *res = 0;
3819 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3820 return -EIO;
3821 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003822 p = xdr_inline_decode(xdr, 8);
3823 if (unlikely(!p))
3824 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003825 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3827 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003828 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003830out_overflow:
3831 print_overflow_msg(__func__, xdr);
3832 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833}
3834
3835static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3836{
Al Viro8687b632006-10-19 23:28:48 -07003837 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 int status = 0;
3839
3840 *res = 0;
3841 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3842 return -EIO;
3843 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003844 p = xdr_inline_decode(xdr, 8);
3845 if (unlikely(!p))
3846 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003847 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3849 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003850 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003852out_overflow:
3853 print_overflow_msg(__func__, xdr);
3854 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855}
3856
3857static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3858{
Al Viro8687b632006-10-19 23:28:48 -07003859 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 int status = 0;
3861
3862 *res = 0;
3863 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3864 return -EIO;
3865 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003866 p = xdr_inline_decode(xdr, 8);
3867 if (unlikely(!p))
3868 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003869 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3871 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003872 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003874out_overflow:
3875 print_overflow_msg(__func__, xdr);
3876 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877}
3878
3879static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3880{
Al Viro8687b632006-10-19 23:28:48 -07003881 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003882 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883
3884 *used = 0;
3885 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3886 return -EIO;
3887 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003888 p = xdr_inline_decode(xdr, 8);
3889 if (unlikely(!p))
3890 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003891 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003893 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003895 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003897 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003898out_overflow:
3899 print_overflow_msg(__func__, xdr);
3900 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901}
3902
3903static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3904{
Al Viro8687b632006-10-19 23:28:48 -07003905 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 uint64_t sec;
3907 uint32_t nsec;
3908
Benny Halevyc0eae662009-08-14 17:20:14 +03003909 p = xdr_inline_decode(xdr, 12);
3910 if (unlikely(!p))
3911 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003912 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003913 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914 time->tv_sec = (time_t)sec;
3915 time->tv_nsec = (long)nsec;
3916 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003917out_overflow:
3918 print_overflow_msg(__func__, xdr);
3919 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920}
3921
3922static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3923{
3924 int status = 0;
3925
3926 time->tv_sec = 0;
3927 time->tv_nsec = 0;
3928 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3929 return -EIO;
3930 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3931 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003932 if (status == 0)
3933 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3935 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003936 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 return status;
3938}
3939
3940static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3941{
3942 int status = 0;
3943
3944 time->tv_sec = 0;
3945 time->tv_nsec = 0;
3946 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3947 return -EIO;
3948 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3949 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003950 if (status == 0)
3951 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3953 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003954 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955 return status;
3956}
3957
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003958static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3959 struct timespec *time)
3960{
3961 int status = 0;
3962
3963 time->tv_sec = 0;
3964 time->tv_nsec = 0;
3965 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3966 return -EIO;
3967 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3968 status = decode_attr_time(xdr, time);
3969 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3970 }
3971 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3972 (long)time->tv_nsec);
3973 return status;
3974}
3975
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3977{
3978 int status = 0;
3979
3980 time->tv_sec = 0;
3981 time->tv_nsec = 0;
3982 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3983 return -EIO;
3984 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3985 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003986 if (status == 0)
3987 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3989 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003990 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991 return status;
3992}
3993
Al Viro8687b632006-10-19 23:28:48 -07003994static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995{
3996 unsigned int attrwords = XDR_QUADLEN(attrlen);
3997 unsigned int nwords = xdr->p - savep;
3998
3999 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004000 dprintk("%s: server returned incorrect attribute length: "
4001 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004002 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 attrwords << 2,
4004 (attrwords < nwords) ? '<' : '>',
4005 nwords << 2);
4006 return -EIO;
4007 }
4008 return 0;
4009}
4010
4011static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4012{
Al Viro8687b632006-10-19 23:28:48 -07004013 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014
Benny Halevyc0eae662009-08-14 17:20:14 +03004015 p = xdr_inline_decode(xdr, 20);
4016 if (unlikely(!p))
4017 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004018 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004019 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004020 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004022out_overflow:
4023 print_overflow_msg(__func__, xdr);
4024 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025}
4026
4027static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4028{
Al Viro8687b632006-10-19 23:28:48 -07004029 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 uint32_t supp, acc;
4031 int status;
4032
4033 status = decode_op_hdr(xdr, OP_ACCESS);
4034 if (status)
4035 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004036 p = xdr_inline_decode(xdr, 8);
4037 if (unlikely(!p))
4038 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004039 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004040 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041 access->supported = supp;
4042 access->access = acc;
4043 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004044out_overflow:
4045 print_overflow_msg(__func__, xdr);
4046 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047}
4048
Benny Halevy07d30432009-08-14 17:19:52 +03004049static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050{
Al Viro8687b632006-10-19 23:28:48 -07004051 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004052
4053 p = xdr_inline_decode(xdr, len);
4054 if (likely(p)) {
4055 memcpy(buf, p, len);
4056 return 0;
4057 }
4058 print_overflow_msg(__func__, xdr);
4059 return -EIO;
4060}
4061
4062static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4063{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004064 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065}
4066
4067static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4068{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069 int status;
4070
4071 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004072 if (status != -EIO)
4073 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004074 if (!status)
4075 status = decode_stateid(xdr, &res->stateid);
4076 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077}
4078
Benny Halevydb942bb2009-08-14 17:19:56 +03004079static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4080{
Chuck Levercd937102012-03-02 17:14:31 -05004081 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082}
4083
Fred Isaman0b7c0152012-04-20 14:47:39 -04004084static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 int status;
4087
4088 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004089 if (!status)
4090 status = decode_verifier(xdr, res->verf->verifier);
4091 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092}
4093
4094static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4095{
Al Viro8687b632006-10-19 23:28:48 -07004096 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097 uint32_t bmlen;
4098 int status;
4099
4100 status = decode_op_hdr(xdr, OP_CREATE);
4101 if (status)
4102 return status;
4103 if ((status = decode_change_info(xdr, cinfo)))
4104 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004105 p = xdr_inline_decode(xdr, 4);
4106 if (unlikely(!p))
4107 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004108 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004109 p = xdr_inline_decode(xdr, bmlen << 2);
4110 if (likely(p))
4111 return 0;
4112out_overflow:
4113 print_overflow_msg(__func__, xdr);
4114 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115}
4116
4117static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4118{
Al Viro8687b632006-10-19 23:28:48 -07004119 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004120 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 int status;
4122
4123 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4124 goto xdr_error;
4125 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4126 goto xdr_error;
4127 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4128 goto xdr_error;
4129 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4130 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004131 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4132 &res->fh_expire_type)) != 0)
4133 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4135 goto xdr_error;
4136 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4137 goto xdr_error;
4138 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4139 goto xdr_error;
4140 status = verify_attr_len(xdr, savep, attrlen);
4141xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004142 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 return status;
4144}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004145
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4147{
Al Viro8687b632006-10-19 23:28:48 -07004148 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004149 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004151
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4153 goto xdr_error;
4154 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4155 goto xdr_error;
4156 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4157 goto xdr_error;
4158
4159 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4160 goto xdr_error;
4161 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4162 goto xdr_error;
4163 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4164 goto xdr_error;
4165 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4166 goto xdr_error;
4167 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4168 goto xdr_error;
4169 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4170 goto xdr_error;
4171
4172 status = verify_attr_len(xdr, savep, attrlen);
4173xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004174 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175 return status;
4176}
4177
4178static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4179{
Al Viro8687b632006-10-19 23:28:48 -07004180 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004181 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004183
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4185 goto xdr_error;
4186 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4187 goto xdr_error;
4188 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4189 goto xdr_error;
4190
4191 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4192 goto xdr_error;
4193 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4194 goto xdr_error;
4195
4196 status = verify_attr_len(xdr, savep, attrlen);
4197xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004198 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 return status;
4200}
4201
Andy Adamson88034c32012-05-23 05:02:34 -04004202static int decode_threshold_hint(struct xdr_stream *xdr,
4203 uint32_t *bitmap,
4204 uint64_t *res,
4205 uint32_t hint_bit)
4206{
4207 __be32 *p;
4208
4209 *res = 0;
4210 if (likely(bitmap[0] & hint_bit)) {
4211 p = xdr_inline_decode(xdr, 8);
4212 if (unlikely(!p))
4213 goto out_overflow;
4214 xdr_decode_hyper(p, res);
4215 }
4216 return 0;
4217out_overflow:
4218 print_overflow_msg(__func__, xdr);
4219 return -EIO;
4220}
4221
4222static int decode_first_threshold_item4(struct xdr_stream *xdr,
4223 struct nfs4_threshold *res)
4224{
4225 __be32 *p, *savep;
4226 uint32_t bitmap[3] = {0,}, attrlen;
4227 int status;
4228
4229 /* layout type */
4230 p = xdr_inline_decode(xdr, 4);
4231 if (unlikely(!p)) {
4232 print_overflow_msg(__func__, xdr);
4233 return -EIO;
4234 }
4235 res->l_type = be32_to_cpup(p);
4236
4237 /* thi_hintset bitmap */
4238 status = decode_attr_bitmap(xdr, bitmap);
4239 if (status < 0)
4240 goto xdr_error;
4241
4242 /* thi_hintlist length */
4243 status = decode_attr_length(xdr, &attrlen, &savep);
4244 if (status < 0)
4245 goto xdr_error;
4246 /* thi_hintlist */
4247 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4248 if (status < 0)
4249 goto xdr_error;
4250 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4251 if (status < 0)
4252 goto xdr_error;
4253 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4254 THRESHOLD_RD_IO);
4255 if (status < 0)
4256 goto xdr_error;
4257 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4258 THRESHOLD_WR_IO);
4259 if (status < 0)
4260 goto xdr_error;
4261
4262 status = verify_attr_len(xdr, savep, attrlen);
4263 res->bm = bitmap[0];
4264
4265 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4266 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4267 res->wr_io_sz);
4268xdr_error:
4269 dprintk("%s ret=%d!\n", __func__, status);
4270 return status;
4271}
4272
4273/*
4274 * Thresholds on pNFS direct I/O vrs MDS I/O
4275 */
4276static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4277 uint32_t *bitmap,
4278 struct nfs4_threshold *res)
4279{
4280 __be32 *p;
4281 int status = 0;
4282 uint32_t num;
4283
4284 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4285 return -EIO;
4286 if (likely(bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD)) {
4287 p = xdr_inline_decode(xdr, 4);
4288 if (unlikely(!p))
4289 goto out_overflow;
4290 num = be32_to_cpup(p);
4291 if (num == 0)
4292 return 0;
4293 if (num > 1)
4294 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4295 "drivers per filesystem not supported\n",
4296 __func__);
4297
4298 status = decode_first_threshold_item4(xdr, res);
4299 }
4300 return status;
4301out_overflow:
4302 print_overflow_msg(__func__, xdr);
4303 return -EIO;
4304}
4305
Bryan Schumakerae42c702010-10-21 16:33:17 -04004306static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4307 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004308 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004309 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310{
Trond Myklebustbca79472009-03-11 14:10:26 -04004311 int status;
4312 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004313 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004314 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004316 status = decode_attr_type(xdr, bitmap, &type);
4317 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004319 fattr->mode = 0;
4320 if (status != 0) {
4321 fattr->mode |= nfs_type2fmt[type];
4322 fattr->valid |= status;
4323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004325 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4326 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004328 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004329
4330 status = decode_attr_size(xdr, bitmap, &fattr->size);
4331 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004333 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004334
4335 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4336 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004338 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004339
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004340 err = 0;
4341 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004342 if (status < 0)
4343 goto xdr_error;
4344
4345 status = decode_attr_filehandle(xdr, bitmap, fh);
4346 if (status < 0)
4347 goto xdr_error;
4348
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004349 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4350 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004352 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004353
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004354 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004355 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004356 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004357 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004358
4359 status = decode_attr_mode(xdr, bitmap, &fmode);
4360 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004362 if (status != 0) {
4363 fattr->mode |= fmode;
4364 fattr->valid |= status;
4365 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004366
4367 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4368 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004369 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004370 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004371
Trond Myklebust6926afd12012-01-07 13:22:46 -05004372 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004373 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004375 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004376
Trond Myklebust6926afd12012-01-07 13:22:46 -05004377 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004378 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004379 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004380 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004381
4382 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4383 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004385 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004386
4387 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4388 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004390 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004391
4392 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4393 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004395 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004396
4397 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4398 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004400 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004401
4402 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4403 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004405 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004406
Trond Myklebust28331a42011-04-27 13:47:52 -04004407 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004408 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004409 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004410 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004411
Andy Adamson88034c32012-05-23 05:02:34 -04004412 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4413 if (status < 0)
4414 goto xdr_error;
4415
Bryan Schumakerae42c702010-10-21 16:33:17 -04004416xdr_error:
4417 dprintk("%s: xdr returned %d\n", __func__, -status);
4418 return status;
4419}
4420
4421static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004422 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4423 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004424{
4425 __be32 *savep;
4426 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004427 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004428 int status;
4429
4430 status = decode_op_hdr(xdr, OP_GETATTR);
4431 if (status < 0)
4432 goto xdr_error;
4433
4434 status = decode_attr_bitmap(xdr, bitmap);
4435 if (status < 0)
4436 goto xdr_error;
4437
4438 status = decode_attr_length(xdr, &attrlen, &savep);
4439 if (status < 0)
4440 goto xdr_error;
4441
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004442 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004443 if (status < 0)
4444 goto xdr_error;
4445
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004446 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004447xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004448 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449 return status;
4450}
4451
Bryan Schumakerae42c702010-10-21 16:33:17 -04004452static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004453 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004454{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004455 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004456}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004457
Andy Adamson504913f2010-10-20 00:17:57 -04004458/*
4459 * Decode potentially multiple layout types. Currently we only support
4460 * one layout driver per file system.
4461 */
4462static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4463 uint32_t *layouttype)
4464{
4465 uint32_t *p;
4466 int num;
4467
4468 p = xdr_inline_decode(xdr, 4);
4469 if (unlikely(!p))
4470 goto out_overflow;
4471 num = be32_to_cpup(p);
4472
4473 /* pNFS is not supported by the underlying file system */
4474 if (num == 0) {
4475 *layouttype = 0;
4476 return 0;
4477 }
4478 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004479 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4480 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004481
4482 /* Decode and set first layout type, move xdr->p past unused types */
4483 p = xdr_inline_decode(xdr, num * 4);
4484 if (unlikely(!p))
4485 goto out_overflow;
4486 *layouttype = be32_to_cpup(p);
4487 return 0;
4488out_overflow:
4489 print_overflow_msg(__func__, xdr);
4490 return -EIO;
4491}
4492
4493/*
4494 * The type of file system exported.
4495 * Note we must ensure that layouttype is set in any non-error case.
4496 */
4497static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4498 uint32_t *layouttype)
4499{
4500 int status = 0;
4501
4502 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4503 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4504 return -EIO;
4505 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4506 status = decode_first_pnfs_layout_type(xdr, layouttype);
4507 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4508 } else
4509 *layouttype = 0;
4510 return status;
4511}
4512
Fred Isamandae100c2011-07-30 20:52:37 -04004513/*
4514 * The prefered block size for layout directed io
4515 */
4516static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4517 uint32_t *res)
4518{
4519 __be32 *p;
4520
4521 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4522 *res = 0;
4523 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4524 p = xdr_inline_decode(xdr, 4);
4525 if (unlikely(!p)) {
4526 print_overflow_msg(__func__, xdr);
4527 return -EIO;
4528 }
4529 *res = be32_to_cpup(p);
4530 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4531 }
4532 return 0;
4533}
4534
Linus Torvalds1da177e2005-04-16 15:20:36 -07004535static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4536{
Al Viro8687b632006-10-19 23:28:48 -07004537 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004538 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004539 int status;
4540
4541 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4542 goto xdr_error;
4543 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4544 goto xdr_error;
4545 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4546 goto xdr_error;
4547
4548 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4549
4550 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4551 goto xdr_error;
4552 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4553 goto xdr_error;
4554 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4555 goto xdr_error;
4556 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4557 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4558 goto xdr_error;
4559 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004560 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4561 if (status != 0)
4562 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004563 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4564 if (status != 0)
4565 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004566 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4567 if (status)
4568 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004569
4570 status = verify_attr_len(xdr, savep, attrlen);
4571xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004572 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573 return status;
4574}
4575
4576static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4577{
Al Viro8687b632006-10-19 23:28:48 -07004578 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579 uint32_t len;
4580 int status;
4581
Trond Myklebust99367812007-07-17 21:52:41 -04004582 /* Zero handle first to allow comparisons */
4583 memset(fh, 0, sizeof(*fh));
4584
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585 status = decode_op_hdr(xdr, OP_GETFH);
4586 if (status)
4587 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004588
Benny Halevyc0eae662009-08-14 17:20:14 +03004589 p = xdr_inline_decode(xdr, 4);
4590 if (unlikely(!p))
4591 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004592 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593 if (len > NFS4_FHSIZE)
4594 return -EIO;
4595 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004596 p = xdr_inline_decode(xdr, len);
4597 if (unlikely(!p))
4598 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004599 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004601out_overflow:
4602 print_overflow_msg(__func__, xdr);
4603 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004604}
4605
4606static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4607{
4608 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004609
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610 status = decode_op_hdr(xdr, OP_LINK);
4611 if (status)
4612 return status;
4613 return decode_change_info(xdr, cinfo);
4614}
4615
4616/*
4617 * We create the owner, so we know a proper owner.id length is 4.
4618 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004619static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004620{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004621 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004622 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004623 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004625 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004626 if (unlikely(!p))
4627 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004628 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004629 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004630 type = be32_to_cpup(p++); /* 4 byte read */
4631 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004632 fl->fl_start = (loff_t)offset;
4633 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4634 if (length == ~(uint64_t)0)
4635 fl->fl_end = OFFSET_MAX;
4636 fl->fl_type = F_WRLCK;
4637 if (type & 1)
4638 fl->fl_type = F_RDLCK;
4639 fl->fl_pid = 0;
4640 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004641 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4642 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4643 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004644 if (likely(p))
4645 return -NFS4ERR_DENIED;
4646out_overflow:
4647 print_overflow_msg(__func__, xdr);
4648 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649}
4650
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004651static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004653 int status;
4654
4655 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004656 if (status == -EIO)
4657 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004659 status = decode_stateid(xdr, &res->stateid);
4660 if (unlikely(status))
4661 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004663 status = decode_lock_denied(xdr, NULL);
4664 if (res->open_seqid != NULL)
4665 nfs_increment_open_seqid(status, res->open_seqid);
4666 nfs_increment_lock_seqid(status, res->lock_seqid);
4667out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004668 return status;
4669}
4670
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004671static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004672{
4673 int status;
4674 status = decode_op_hdr(xdr, OP_LOCKT);
4675 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004676 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004677 return status;
4678}
4679
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004680static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004681{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682 int status;
4683
4684 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004685 if (status != -EIO)
4686 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004687 if (status == 0)
4688 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004689 return status;
4690}
4691
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004692static int decode_release_lockowner(struct xdr_stream *xdr)
4693{
4694 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4695}
4696
Linus Torvalds1da177e2005-04-16 15:20:36 -07004697static int decode_lookup(struct xdr_stream *xdr)
4698{
4699 return decode_op_hdr(xdr, OP_LOOKUP);
4700}
4701
4702/* This is too sick! */
4703static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4704{
Andy Adamson05d564f2008-12-23 16:06:15 -05004705 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706 uint32_t limit_type, nblocks, blocksize;
4707
Benny Halevyc0eae662009-08-14 17:20:14 +03004708 p = xdr_inline_decode(xdr, 12);
4709 if (unlikely(!p))
4710 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004711 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004713 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004714 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004715 break;
4716 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004717 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004718 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004719 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720 }
4721 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004722out_overflow:
4723 print_overflow_msg(__func__, xdr);
4724 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725}
4726
4727static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4728{
Andy Adamson05d564f2008-12-23 16:06:15 -05004729 __be32 *p;
4730 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004731 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732
Benny Halevyc0eae662009-08-14 17:20:14 +03004733 p = xdr_inline_decode(xdr, 4);
4734 if (unlikely(!p))
4735 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004736 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4738 res->delegation_type = 0;
4739 return 0;
4740 }
Benny Halevy07d30432009-08-14 17:19:52 +03004741 status = decode_stateid(xdr, &res->delegation);
4742 if (unlikely(status))
4743 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004744 p = xdr_inline_decode(xdr, 4);
4745 if (unlikely(!p))
4746 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004747 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004748
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004750 case NFS4_OPEN_DELEGATE_READ:
4751 res->delegation_type = FMODE_READ;
4752 break;
4753 case NFS4_OPEN_DELEGATE_WRITE:
4754 res->delegation_type = FMODE_WRITE|FMODE_READ;
4755 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756 return -EIO;
4757 }
David Howells7539bba2006-08-22 20:06:09 -04004758 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004759out_overflow:
4760 print_overflow_msg(__func__, xdr);
4761 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762}
4763
4764static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4765{
Andy Adamson05d564f2008-12-23 16:06:15 -05004766 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004767 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004768 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004769
Andy Adamson05d564f2008-12-23 16:06:15 -05004770 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004771 if (status != -EIO)
4772 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004773 if (!status)
4774 status = decode_stateid(xdr, &res->stateid);
4775 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004776 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777
Andy Adamson05d564f2008-12-23 16:06:15 -05004778 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004779
Benny Halevyc0eae662009-08-14 17:20:14 +03004780 p = xdr_inline_decode(xdr, 8);
4781 if (unlikely(!p))
4782 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004783 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004784 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004785 if (bmlen > 10)
4786 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787
Benny Halevyc0eae662009-08-14 17:20:14 +03004788 p = xdr_inline_decode(xdr, bmlen << 2);
4789 if (unlikely(!p))
4790 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004791 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4792 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004793 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004794 for (; i < NFS4_BITMAP_SIZE; i++)
4795 res->attrset[i] = 0;
4796
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 return decode_delegation(xdr, res);
4798xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004799 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004801out_overflow:
4802 print_overflow_msg(__func__, xdr);
4803 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004804}
4805
4806static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4807{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808 int status;
4809
Andy Adamson05d564f2008-12-23 16:06:15 -05004810 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004811 if (status != -EIO)
4812 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004813 if (!status)
4814 status = decode_stateid(xdr, &res->stateid);
4815 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816}
4817
4818static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4819{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820 int status;
4821
4822 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004823 if (status != -EIO)
4824 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004825 if (!status)
4826 status = decode_stateid(xdr, &res->stateid);
4827 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004828}
4829
4830static int decode_putfh(struct xdr_stream *xdr)
4831{
4832 return decode_op_hdr(xdr, OP_PUTFH);
4833}
4834
4835static int decode_putrootfh(struct xdr_stream *xdr)
4836{
4837 return decode_op_hdr(xdr, OP_PUTROOTFH);
4838}
4839
4840static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4841{
4842 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004843 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 uint32_t count, eof, recvd, hdrlen;
4845 int status;
4846
4847 status = decode_op_hdr(xdr, OP_READ);
4848 if (status)
4849 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004850 p = xdr_inline_decode(xdr, 8);
4851 if (unlikely(!p))
4852 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004853 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004854 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004855 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004856 recvd = req->rq_rcv_buf.len - hdrlen;
4857 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004858 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004859 "count %u > recvd %u\n", count, recvd);
4860 count = recvd;
4861 eof = 0;
4862 }
4863 xdr_read_pages(xdr, count);
4864 res->eof = eof;
4865 res->count = count;
4866 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004867out_overflow:
4868 print_overflow_msg(__func__, xdr);
4869 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870}
4871
4872static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4873{
4874 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004875 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004876 size_t hdrlen;
4877 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004878 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004879 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880
4881 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004882 if (!status)
4883 status = decode_verifier(xdr, readdir->verifier.data);
4884 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004886 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004887 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004888 __func__, verf[0], verf[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889
Benny Halevydb942bb2009-08-14 17:19:56 +03004890 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891 recvd = rcvbuf->len - hdrlen;
4892 if (pglen > recvd)
4893 pglen = recvd;
4894 xdr_read_pages(xdr, pglen);
4895
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004896
Trond Myklebustac396122010-11-15 20:26:22 -05004897 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898}
4899
4900static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4901{
4902 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4903 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004904 size_t hdrlen;
4905 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004906 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004907 int status;
4908
4909 status = decode_op_hdr(xdr, OP_READLINK);
4910 if (status)
4911 return status;
4912
4913 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004914 p = xdr_inline_decode(xdr, 4);
4915 if (unlikely(!p))
4916 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004917 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004919 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004920 return -ENAMETOOLONG;
4921 }
4922 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4923 recvd = req->rq_rcv_buf.len - hdrlen;
4924 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004925 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926 "count %u > recvd %u\n", len, recvd);
4927 return -EIO;
4928 }
4929 xdr_read_pages(xdr, len);
4930 /*
4931 * The XDR encode routine has set things up so that
4932 * the link text will be copied directly into the
4933 * buffer. We just have to do overflow-checking,
4934 * and and null-terminate the text (the VFS expects
4935 * null-termination).
4936 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004937 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004938 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004939out_overflow:
4940 print_overflow_msg(__func__, xdr);
4941 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942}
4943
4944static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4945{
4946 int status;
4947
4948 status = decode_op_hdr(xdr, OP_REMOVE);
4949 if (status)
4950 goto out;
4951 status = decode_change_info(xdr, cinfo);
4952out:
4953 return status;
4954}
4955
4956static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4957 struct nfs4_change_info *new_cinfo)
4958{
4959 int status;
4960
4961 status = decode_op_hdr(xdr, OP_RENAME);
4962 if (status)
4963 goto out;
4964 if ((status = decode_change_info(xdr, old_cinfo)))
4965 goto out;
4966 status = decode_change_info(xdr, new_cinfo);
4967out:
4968 return status;
4969}
4970
4971static int decode_renew(struct xdr_stream *xdr)
4972{
4973 return decode_op_hdr(xdr, OP_RENEW);
4974}
4975
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004976static int
4977decode_restorefh(struct xdr_stream *xdr)
4978{
4979 return decode_op_hdr(xdr, OP_RESTOREFH);
4980}
4981
J. Bruce Fields029d1052005-06-22 17:16:22 +00004982static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05004983 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004984{
Andy Adamsonbf118a32011-12-07 11:55:27 -05004985 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004986 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004987 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00004988 struct kvec *iov = req->rq_rcv_buf.head;
4989 int status;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004990 size_t page_len = xdr->buf->page_len;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004991
Andy Adamsonbf118a32011-12-07 11:55:27 -05004992 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004993 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4994 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004995
Andy Adamsonbf118a32011-12-07 11:55:27 -05004996 bm_p = xdr->p;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004997 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4998 res->acl_data_offset <<= 2;
4999 /* Check if the acl data starts beyond the allocated buffer */
5000 if (res->acl_data_offset > page_len)
5001 return -ERANGE;
5002
J. Bruce Fields029d1052005-06-22 17:16:22 +00005003 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5004 goto out;
5005 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5006 goto out;
5007
5008 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5009 return -EIO;
5010 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04005011 size_t hdrlen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005012
Andy Adamsonbf118a32011-12-07 11:55:27 -05005013 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5014 * are stored with the acl data to handle the problem of
5015 * variable length bitmaps.*/
5016 xdr->p = bm_p;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005017
J. Bruce Fields029d1052005-06-22 17:16:22 +00005018 /* We ignore &savep and don't do consistency checks on
5019 * the attr length. Let userspace figure it out.... */
5020 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005021 attrlen += res->acl_data_offset;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005022 if (attrlen > page_len) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05005023 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
5024 /* getxattr interface called with a NULL buf */
5025 res->acl_len = attrlen;
5026 goto out;
5027 }
Sachin Prabhu5794d212012-04-17 14:36:40 +01005028 dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
Sachin Prabhu5a006892012-04-17 14:35:39 +01005029 attrlen, page_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005030 return -EINVAL;
5031 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04005032 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05005033 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005034 } else
5035 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005036
5037out:
5038 return status;
5039}
5040
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041static int
5042decode_savefh(struct xdr_stream *xdr)
5043{
5044 return decode_op_hdr(xdr, OP_SAVEFH);
5045}
5046
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005047static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048{
Al Viro8687b632006-10-19 23:28:48 -07005049 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050 uint32_t bmlen;
5051 int status;
5052
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053 status = decode_op_hdr(xdr, OP_SETATTR);
5054 if (status)
5055 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005056 p = xdr_inline_decode(xdr, 4);
5057 if (unlikely(!p))
5058 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005059 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005060 p = xdr_inline_decode(xdr, bmlen << 2);
5061 if (likely(p))
5062 return 0;
5063out_overflow:
5064 print_overflow_msg(__func__, xdr);
5065 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005066}
5067
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005068static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069{
Al Viro8687b632006-10-19 23:28:48 -07005070 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071 uint32_t opnum;
5072 int32_t nfserr;
5073
Benny Halevyc0eae662009-08-14 17:20:14 +03005074 p = xdr_inline_decode(xdr, 8);
5075 if (unlikely(!p))
5076 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005077 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005079 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005080 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081 return -EIO;
5082 }
Benny Halevycccddf42009-08-14 17:20:19 +03005083 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005085 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5086 if (unlikely(!p))
5087 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005088 p = xdr_decode_hyper(p, &res->clientid);
5089 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005090 } else if (nfserr == NFSERR_CLID_INUSE) {
5091 uint32_t len;
5092
5093 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005094 p = xdr_inline_decode(xdr, 4);
5095 if (unlikely(!p))
5096 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005097 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005098 p = xdr_inline_decode(xdr, len);
5099 if (unlikely(!p))
5100 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101
5102 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005103 p = xdr_inline_decode(xdr, 4);
5104 if (unlikely(!p))
5105 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005106 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005107 p = xdr_inline_decode(xdr, len);
5108 if (unlikely(!p))
5109 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005110 return -NFSERR_CLID_INUSE;
5111 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005112 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113
5114 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005115out_overflow:
5116 print_overflow_msg(__func__, xdr);
5117 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005118}
5119
5120static int decode_setclientid_confirm(struct xdr_stream *xdr)
5121{
5122 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5123}
5124
5125static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5126{
Al Viro8687b632006-10-19 23:28:48 -07005127 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128 int status;
5129
5130 status = decode_op_hdr(xdr, OP_WRITE);
5131 if (status)
5132 return status;
5133
Benny Halevyc0eae662009-08-14 17:20:14 +03005134 p = xdr_inline_decode(xdr, 16);
5135 if (unlikely(!p))
5136 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005137 res->count = be32_to_cpup(p++);
5138 res->verf->committed = be32_to_cpup(p++);
Chuck Levercd937102012-03-02 17:14:31 -05005139 memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005140 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005141out_overflow:
5142 print_overflow_msg(__func__, xdr);
5143 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144}
5145
5146static int decode_delegreturn(struct xdr_stream *xdr)
5147{
5148 return decode_op_hdr(xdr, OP_DELEGRETURN);
5149}
5150
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005151static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5152{
5153 __be32 *p;
5154
5155 p = xdr_inline_decode(xdr, 4);
5156 if (unlikely(!p))
5157 goto out_overflow;
5158 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5159 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5160 goto out_err;
5161
5162 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5163 if (unlikely(!p))
5164 goto out_overflow;
5165 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5166
5167 p = xdr_inline_decode(xdr, 8);
5168 if (unlikely(!p))
5169 goto out_overflow;
5170 flavor->gss.qop4 = be32_to_cpup(p++);
5171 flavor->gss.service = be32_to_cpup(p);
5172
5173 return 0;
5174
5175out_overflow:
5176 print_overflow_msg(__func__, xdr);
5177 return -EIO;
5178out_err:
5179 return -EINVAL;
5180}
5181
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005182static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005183{
5184 struct nfs4_secinfo_flavor *sec_flavor;
5185 int status;
5186 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005187 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005188
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005189 p = xdr_inline_decode(xdr, 4);
5190 if (unlikely(!p))
5191 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005192
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005193 res->flavors->num_flavors = 0;
5194 num_flavors = be32_to_cpup(p);
5195
5196 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005197 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005198 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005199 break;
5200
5201 p = xdr_inline_decode(xdr, 4);
5202 if (unlikely(!p))
5203 goto out_overflow;
5204 sec_flavor->flavor = be32_to_cpup(p);
5205
5206 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005207 status = decode_secinfo_gss(xdr, sec_flavor);
5208 if (status)
5209 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005210 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005211 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005212 }
5213
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005214 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005215out:
5216 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005217out_overflow:
5218 print_overflow_msg(__func__, xdr);
5219 return -EIO;
5220}
5221
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005222static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5223{
5224 int status = decode_op_hdr(xdr, OP_SECINFO);
5225 if (status)
5226 return status;
5227 return decode_secinfo_common(xdr, res);
5228}
5229
Benny Halevy99fe60d2009-04-01 09:22:29 -04005230#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005231static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5232{
5233 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5234 if (status)
5235 return status;
5236 return decode_secinfo_common(xdr, res);
5237}
5238
Benny Halevy99fe60d2009-04-01 09:22:29 -04005239static int decode_exchange_id(struct xdr_stream *xdr,
5240 struct nfs41_exchange_id_res *res)
5241{
5242 __be32 *p;
5243 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005244 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005245 int status;
5246 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005247 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005248
5249 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5250 if (status)
5251 return status;
5252
Benny Halevyc0eae662009-08-14 17:20:14 +03005253 p = xdr_inline_decode(xdr, 8);
5254 if (unlikely(!p))
5255 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005256 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005257 p = xdr_inline_decode(xdr, 12);
5258 if (unlikely(!p))
5259 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005260 clp->cl_seqid = be32_to_cpup(p++);
5261 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005262
5263 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005264 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005265 if (dummy != SP4_NONE)
5266 return -EIO;
5267
Chuck Leveracdeb692012-05-21 22:46:16 -04005268 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005269 p = xdr_inline_decode(xdr, 8);
5270 if (unlikely(!p))
5271 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005272 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005273
Chuck Leveracdeb692012-05-21 22:46:16 -04005274 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005275 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5276 if (unlikely(status))
5277 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005278 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5279 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005280 memcpy(res->server_owner->major_id, dummy_str, dummy);
5281 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005282
Chuck Leveracdeb692012-05-21 22:46:16 -04005283 /* server_scope4 */
5284 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5285 if (unlikely(status))
5286 return status;
5287 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5288 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005289 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5290 res->server_scope->server_scope_sz = dummy;
5291
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005292 /* Implementation Id */
5293 p = xdr_inline_decode(xdr, 4);
5294 if (unlikely(!p))
5295 goto out_overflow;
5296 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005297
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005298 if (impl_id_count) {
5299 /* nii_domain */
5300 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5301 if (unlikely(status))
5302 return status;
5303 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5304 return -EIO;
5305 memcpy(res->impl_id->domain, dummy_str, dummy);
5306
5307 /* nii_name */
5308 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5309 if (unlikely(status))
5310 return status;
5311 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5312 return -EIO;
5313 memcpy(res->impl_id->name, dummy_str, dummy);
5314
5315 /* nii_date */
5316 p = xdr_inline_decode(xdr, 12);
5317 if (unlikely(!p))
5318 goto out_overflow;
5319 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5320 res->impl_id->date.nseconds = be32_to_cpup(p);
5321
5322 /* if there's more than one entry, ignore the rest */
5323 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005324 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005325out_overflow:
5326 print_overflow_msg(__func__, xdr);
5327 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005328}
Andy Adamsonfc931582009-04-01 09:22:31 -04005329
5330static int decode_chan_attrs(struct xdr_stream *xdr,
5331 struct nfs4_channel_attrs *attrs)
5332{
5333 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005334 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005335
Benny Halevyc0eae662009-08-14 17:20:14 +03005336 p = xdr_inline_decode(xdr, 28);
5337 if (unlikely(!p))
5338 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005339 val = be32_to_cpup(p++); /* headerpadsz */
5340 if (val)
5341 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005342 attrs->max_rqst_sz = be32_to_cpup(p++);
5343 attrs->max_resp_sz = be32_to_cpup(p++);
5344 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5345 attrs->max_ops = be32_to_cpup(p++);
5346 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005347 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005348 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005349 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5350 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005351 return -EINVAL;
5352 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005353 if (nr_attrs == 1) {
5354 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5355 if (unlikely(!p))
5356 goto out_overflow;
5357 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005358 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005359out_overflow:
5360 print_overflow_msg(__func__, xdr);
5361 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005362}
5363
Benny Halevye78291e2009-08-14 17:20:00 +03005364static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5365{
5366 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005367}
5368
5369static int decode_create_session(struct xdr_stream *xdr,
5370 struct nfs41_create_session_res *res)
5371{
5372 __be32 *p;
5373 int status;
5374 struct nfs_client *clp = res->client;
5375 struct nfs4_session *session = clp->cl_session;
5376
5377 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005378 if (!status)
5379 status = decode_sessionid(xdr, &session->sess_id);
5380 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005381 return status;
5382
Andy Adamsonfc931582009-04-01 09:22:31 -04005383 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005384 p = xdr_inline_decode(xdr, 8);
5385 if (unlikely(!p))
5386 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005387 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005388 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005389
5390 /* Channel attributes */
5391 status = decode_chan_attrs(xdr, &session->fc_attrs);
5392 if (!status)
5393 status = decode_chan_attrs(xdr, &session->bc_attrs);
5394 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005395out_overflow:
5396 print_overflow_msg(__func__, xdr);
5397 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005398}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005399
5400static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5401{
5402 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5403}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005404
5405static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5406{
5407 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5408}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005409#endif /* CONFIG_NFS_V4_1 */
5410
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005411static int decode_sequence(struct xdr_stream *xdr,
5412 struct nfs4_sequence_res *res,
5413 struct rpc_rqst *rqstp)
5414{
5415#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005416 struct nfs4_sessionid id;
5417 u32 dummy;
5418 int status;
5419 __be32 *p;
5420
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005421 if (!res->sr_session)
5422 return 0;
5423
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005424 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005425 if (!status)
5426 status = decode_sessionid(xdr, &id);
5427 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005428 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005429
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005430 /*
5431 * If the server returns different values for sessionID, slotID or
5432 * sequence number, the server is looney tunes.
5433 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005434 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005435
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005436 if (memcmp(id.data, res->sr_session->sess_id.data,
5437 NFS4_MAX_SESSIONID_LEN)) {
5438 dprintk("%s Invalid session id\n", __func__);
5439 goto out_err;
5440 }
Benny Halevye78291e2009-08-14 17:20:00 +03005441
Benny Halevyc0eae662009-08-14 17:20:14 +03005442 p = xdr_inline_decode(xdr, 20);
5443 if (unlikely(!p))
5444 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005445
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005446 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005447 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005448 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005449 dprintk("%s Invalid sequence number\n", __func__);
5450 goto out_err;
5451 }
5452 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005453 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005454 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005455 dprintk("%s Invalid slot id\n", __func__);
5456 goto out_err;
5457 }
5458 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005459 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005460 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005461 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005462 /* result flags */
5463 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005464 status = 0;
5465out_err:
5466 res->sr_status = status;
5467 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005468out_overflow:
5469 print_overflow_msg(__func__, xdr);
5470 status = -EIO;
5471 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005472#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005473 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005474#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005475}
5476
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005477#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005478/*
5479 * TODO: Need to handle case when EOF != true;
5480 */
5481static int decode_getdevicelist(struct xdr_stream *xdr,
5482 struct pnfs_devicelist *res)
5483{
5484 __be32 *p;
5485 int status, i;
5486 struct nfs_writeverf verftemp;
5487
5488 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5489 if (status)
5490 return status;
5491
5492 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5493 if (unlikely(!p))
5494 goto out_overflow;
5495
5496 /* TODO: Skip cookie for now */
5497 p += 2;
5498
5499 /* Read verifier */
Chuck Levercd937102012-03-02 17:14:31 -05005500 p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005501
5502 res->num_devs = be32_to_cpup(p);
5503
5504 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5505
5506 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005507 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005508 __func__, res->num_devs);
5509 return -EIO;
5510 }
5511
5512 p = xdr_inline_decode(xdr,
5513 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5514 if (unlikely(!p))
5515 goto out_overflow;
5516 for (i = 0; i < res->num_devs; i++)
5517 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5518 NFS4_DEVICEID4_SIZE);
5519 res->eof = be32_to_cpup(p);
5520 return 0;
5521out_overflow:
5522 print_overflow_msg(__func__, xdr);
5523 return -EIO;
5524}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005525
5526static int decode_getdeviceinfo(struct xdr_stream *xdr,
5527 struct pnfs_device *pdev)
5528{
5529 __be32 *p;
5530 uint32_t len, type;
5531 int status;
5532
5533 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5534 if (status) {
5535 if (status == -ETOOSMALL) {
5536 p = xdr_inline_decode(xdr, 4);
5537 if (unlikely(!p))
5538 goto out_overflow;
5539 pdev->mincount = be32_to_cpup(p);
5540 dprintk("%s: Min count too small. mincnt = %u\n",
5541 __func__, pdev->mincount);
5542 }
5543 return status;
5544 }
5545
5546 p = xdr_inline_decode(xdr, 8);
5547 if (unlikely(!p))
5548 goto out_overflow;
5549 type = be32_to_cpup(p++);
5550 if (type != pdev->layout_type) {
5551 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5552 __func__, pdev->layout_type, type);
5553 return -EINVAL;
5554 }
5555 /*
5556 * Get the length of the opaque device_addr4. xdr_read_pages places
5557 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5558 * and places the remaining xdr data in xdr_buf->tail
5559 */
5560 pdev->mincount = be32_to_cpup(p);
5561 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5562
5563 /* Parse notification bitmap, verifying that it is zero. */
5564 p = xdr_inline_decode(xdr, 4);
5565 if (unlikely(!p))
5566 goto out_overflow;
5567 len = be32_to_cpup(p);
5568 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005569 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005570
5571 p = xdr_inline_decode(xdr, 4 * len);
5572 if (unlikely(!p))
5573 goto out_overflow;
5574 for (i = 0; i < len; i++, p++) {
5575 if (be32_to_cpup(p)) {
5576 dprintk("%s: notifications not supported\n",
5577 __func__);
5578 return -EIO;
5579 }
5580 }
5581 }
5582 return 0;
5583out_overflow:
5584 print_overflow_msg(__func__, xdr);
5585 return -EIO;
5586}
5587
5588static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5589 struct nfs4_layoutget_res *res)
5590{
5591 __be32 *p;
5592 int status;
5593 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005594 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5595 struct kvec *iov = rcvbuf->head;
5596 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005597
5598 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5599 if (status)
5600 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005601 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005602 if (unlikely(!p))
5603 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005604 res->return_on_close = be32_to_cpup(p);
5605 decode_stateid(xdr, &res->stateid);
5606 p = xdr_inline_decode(xdr, 4);
5607 if (unlikely(!p))
5608 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005609 layout_count = be32_to_cpup(p);
5610 if (!layout_count) {
5611 dprintk("%s: server responded with empty layout array\n",
5612 __func__);
5613 return -EINVAL;
5614 }
5615
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005616 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005617 if (unlikely(!p))
5618 goto out_overflow;
5619 p = xdr_decode_hyper(p, &res->range.offset);
5620 p = xdr_decode_hyper(p, &res->range.length);
5621 res->range.iomode = be32_to_cpup(p++);
5622 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005623 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005624
5625 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5626 __func__,
5627 (unsigned long)res->range.offset,
5628 (unsigned long)res->range.length,
5629 res->range.iomode,
5630 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005631 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005632
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005633 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5634 recvd = req->rq_rcv_buf.len - hdrlen;
5635 if (res->layoutp->len > recvd) {
5636 dprintk("NFS: server cheating in layoutget reply: "
5637 "layout len %u > recvd %u\n",
5638 res->layoutp->len, recvd);
5639 return -EINVAL;
5640 }
5641
5642 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005643
5644 if (layout_count > 1) {
5645 /* We only handle a length one array at the moment. Any
5646 * further entries are just ignored. Note that this means
5647 * the client may see a response that is less than the
5648 * minimum it requested.
5649 */
5650 dprintk("%s: server responded with %d layouts, dropping tail\n",
5651 __func__, layout_count);
5652 }
5653
5654 return 0;
5655out_overflow:
5656 print_overflow_msg(__func__, xdr);
5657 return -EIO;
5658}
Andy Adamson863a3c62011-03-23 13:27:54 +00005659
Benny Halevycbe82602011-05-22 19:52:37 +03005660static int decode_layoutreturn(struct xdr_stream *xdr,
5661 struct nfs4_layoutreturn_res *res)
5662{
5663 __be32 *p;
5664 int status;
5665
5666 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5667 if (status)
5668 return status;
5669 p = xdr_inline_decode(xdr, 4);
5670 if (unlikely(!p))
5671 goto out_overflow;
5672 res->lrs_present = be32_to_cpup(p);
5673 if (res->lrs_present)
5674 status = decode_stateid(xdr, &res->stateid);
5675 return status;
5676out_overflow:
5677 print_overflow_msg(__func__, xdr);
5678 return -EIO;
5679}
5680
Andy Adamson863a3c62011-03-23 13:27:54 +00005681static int decode_layoutcommit(struct xdr_stream *xdr,
5682 struct rpc_rqst *req,
5683 struct nfs4_layoutcommit_res *res)
5684{
5685 __be32 *p;
5686 __u32 sizechanged;
5687 int status;
5688
5689 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005690 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005691 if (status)
5692 return status;
5693
5694 p = xdr_inline_decode(xdr, 4);
5695 if (unlikely(!p))
5696 goto out_overflow;
5697 sizechanged = be32_to_cpup(p);
5698
5699 if (sizechanged) {
5700 /* throw away new size */
5701 p = xdr_inline_decode(xdr, 8);
5702 if (unlikely(!p))
5703 goto out_overflow;
5704 }
5705 return 0;
5706out_overflow:
5707 print_overflow_msg(__func__, xdr);
5708 return -EIO;
5709}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005710
5711static int decode_test_stateid(struct xdr_stream *xdr,
5712 struct nfs41_test_stateid_res *res)
5713{
5714 __be32 *p;
5715 int status;
5716 int num_res;
5717
5718 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5719 if (status)
5720 return status;
5721
5722 p = xdr_inline_decode(xdr, 4);
5723 if (unlikely(!p))
5724 goto out_overflow;
5725 num_res = be32_to_cpup(p++);
5726 if (num_res != 1)
5727 goto out;
5728
5729 p = xdr_inline_decode(xdr, 4);
5730 if (unlikely(!p))
5731 goto out_overflow;
5732 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005733
5734 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005735out_overflow:
5736 print_overflow_msg(__func__, xdr);
5737out:
5738 return -EIO;
5739}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005740
5741static int decode_free_stateid(struct xdr_stream *xdr,
5742 struct nfs41_free_stateid_res *res)
5743{
5744 __be32 *p;
5745 int status;
5746
5747 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5748 if (status)
5749 return status;
5750
5751 p = xdr_inline_decode(xdr, 4);
5752 if (unlikely(!p))
5753 goto out_overflow;
5754 res->status = be32_to_cpup(p++);
5755 return res->status;
5756out_overflow:
5757 print_overflow_msg(__func__, xdr);
5758 return -EIO;
5759}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005760#endif /* CONFIG_NFS_V4_1 */
5761
Linus Torvalds1da177e2005-04-16 15:20:36 -07005762/*
Benny Halevy49c25592008-12-23 16:06:16 -05005763 * END OF "GENERIC" DECODE ROUTINES.
5764 */
5765
5766/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767 * Decode OPEN_DOWNGRADE response
5768 */
Chuck Leverbf269552010-12-14 14:59:29 +00005769static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5770 struct xdr_stream *xdr,
5771 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005772{
Andy Adamson05d564f2008-12-23 16:06:15 -05005773 struct compound_hdr hdr;
5774 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005775
Chuck Leverbf269552010-12-14 14:59:29 +00005776 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005777 if (status)
5778 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005779 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005780 if (status)
5781 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005782 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005783 if (status)
5784 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005785 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005786 if (status != 0)
5787 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005788 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005789out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005790 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005791}
5792
5793/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005794 * Decode ACCESS response
5795 */
Chuck Leverbf269552010-12-14 14:59:29 +00005796static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5797 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005798{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799 struct compound_hdr hdr;
5800 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005801
Chuck Leverbf269552010-12-14 14:59:29 +00005802 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005803 if (status)
5804 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005805 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005806 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005807 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005808 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005809 if (status != 0)
5810 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005811 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005812 if (status != 0)
5813 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005814 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005815out:
5816 return status;
5817}
5818
5819/*
5820 * Decode LOOKUP response
5821 */
Chuck Leverbf269552010-12-14 14:59:29 +00005822static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5823 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005824{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005825 struct compound_hdr hdr;
5826 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005827
Chuck Leverbf269552010-12-14 14:59:29 +00005828 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005829 if (status)
5830 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005831 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005832 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005833 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005834 status = decode_putfh(xdr);
5835 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005837 status = decode_lookup(xdr);
5838 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005839 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005840 status = decode_getfh(xdr, res->fh);
5841 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005842 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005843 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844out:
5845 return status;
5846}
5847
5848/*
5849 * Decode LOOKUP_ROOT response
5850 */
Chuck Leverbf269552010-12-14 14:59:29 +00005851static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5852 struct xdr_stream *xdr,
5853 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005855 struct compound_hdr hdr;
5856 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005857
Chuck Leverbf269552010-12-14 14:59:29 +00005858 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005859 if (status)
5860 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005861 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005862 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005863 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005864 status = decode_putrootfh(xdr);
5865 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005866 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005867 status = decode_getfh(xdr, res->fh);
5868 if (status == 0)
Trond Myklebust6926afd12012-01-07 13:22:46 -05005869 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005870out:
5871 return status;
5872}
5873
5874/*
5875 * Decode REMOVE response
5876 */
Chuck Leverbf269552010-12-14 14:59:29 +00005877static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5878 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005879{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005880 struct compound_hdr hdr;
5881 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005882
Chuck Leverbf269552010-12-14 14:59:29 +00005883 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005884 if (status)
5885 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005886 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005887 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005888 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005889 status = decode_putfh(xdr);
5890 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005891 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005892 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005893out:
5894 return status;
5895}
5896
5897/*
5898 * Decode RENAME response
5899 */
Chuck Leverbf269552010-12-14 14:59:29 +00005900static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5901 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005902{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005903 struct compound_hdr hdr;
5904 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005905
Chuck Leverbf269552010-12-14 14:59:29 +00005906 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005907 if (status)
5908 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005909 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005910 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005911 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005912 status = decode_putfh(xdr);
5913 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005914 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005915 status = decode_savefh(xdr);
5916 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005917 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005918 status = decode_putfh(xdr);
5919 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005920 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005921 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005922out:
5923 return status;
5924}
5925
5926/*
5927 * Decode LINK response
5928 */
Chuck Leverbf269552010-12-14 14:59:29 +00005929static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5930 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005932 struct compound_hdr hdr;
5933 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005934
Chuck Leverbf269552010-12-14 14:59:29 +00005935 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005936 if (status)
5937 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005938 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005939 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005941 status = decode_putfh(xdr);
5942 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005943 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005944 status = decode_savefh(xdr);
5945 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005946 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005947 status = decode_putfh(xdr);
5948 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005949 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005950 status = decode_link(xdr, &res->cinfo);
5951 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005952 goto out;
5953 /*
5954 * Note order: OP_LINK leaves the directory as the current
5955 * filehandle.
5956 */
Chuck Leverbf269552010-12-14 14:59:29 +00005957 status = decode_restorefh(xdr);
5958 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005959 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005960 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005961out:
5962 return status;
5963}
5964
5965/*
5966 * Decode CREATE response
5967 */
Chuck Leverbf269552010-12-14 14:59:29 +00005968static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5969 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005971 struct compound_hdr hdr;
5972 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005973
Chuck Leverbf269552010-12-14 14:59:29 +00005974 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005975 if (status)
5976 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005977 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005978 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005980 status = decode_putfh(xdr);
5981 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005982 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005983 status = decode_create(xdr, &res->dir_cinfo);
5984 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005985 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005986 status = decode_getfh(xdr, res->fh);
5987 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005988 goto out;
Trond Myklebust7c317fc2012-04-27 13:48:18 -04005989 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005990out:
5991 return status;
5992}
5993
5994/*
5995 * Decode SYMLINK response
5996 */
Chuck Leverbf269552010-12-14 14:59:29 +00005997static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5998 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005999{
Chuck Leverbf269552010-12-14 14:59:29 +00006000 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006001}
6002
6003/*
6004 * Decode GETATTR response
6005 */
Chuck Leverbf269552010-12-14 14:59:29 +00006006static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6007 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006009 struct compound_hdr hdr;
6010 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006011
Chuck Leverbf269552010-12-14 14:59:29 +00006012 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013 if (status)
6014 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006015 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006016 if (status)
6017 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006018 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006019 if (status)
6020 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006021 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006022out:
6023 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024}
6025
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006026/*
6027 * Encode an SETACL request
6028 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006029static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6030 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006031{
Andy Adamson05d564f2008-12-23 16:06:15 -05006032 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006033 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006034 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006035
Chuck Lever9f06c712010-12-14 14:59:18 +00006036 encode_compound_hdr(xdr, req, &hdr);
6037 encode_sequence(xdr, &args->seq_args, &hdr);
6038 encode_putfh(xdr, args->fh, &hdr);
6039 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006040 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006041}
Andy Adamson05d564f2008-12-23 16:06:15 -05006042
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006043/*
6044 * Decode SETACL response
6045 */
6046static int
Chuck Leverbf269552010-12-14 14:59:29 +00006047nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006048 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006049{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006050 struct compound_hdr hdr;
6051 int status;
6052
Chuck Leverbf269552010-12-14 14:59:29 +00006053 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006054 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)
6058 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006059 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006060 if (status)
6061 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006062 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006063out:
6064 return status;
6065}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006066
6067/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006068 * Decode GETACL response
6069 */
6070static int
Chuck Leverbf269552010-12-14 14:59:29 +00006071nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006072 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006073{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006074 struct compound_hdr hdr;
6075 int status;
6076
Trond Myklebust331818f2012-02-03 18:30:53 -05006077 if (res->acl_scratch != NULL) {
6078 void *p = page_address(res->acl_scratch);
6079 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6080 }
Chuck Leverbf269552010-12-14 14:59:29 +00006081 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006082 if (status)
6083 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006084 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006085 if (status)
6086 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006087 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006088 if (status)
6089 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006090 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006091
6092out:
6093 return status;
6094}
6095
6096/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097 * Decode CLOSE response
6098 */
Chuck Leverbf269552010-12-14 14:59:29 +00006099static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6100 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101{
Andy Adamson05d564f2008-12-23 16:06:15 -05006102 struct compound_hdr hdr;
6103 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104
Chuck Leverbf269552010-12-14 14:59:29 +00006105 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006106 if (status)
6107 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006108 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006109 if (status)
6110 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006111 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006112 if (status)
6113 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006114 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006115 if (status != 0)
6116 goto out;
6117 /*
6118 * Note: Server may do delete on close for this file
6119 * in which case the getattr call will fail with
6120 * an ESTALE error. Shouldn't be a problem,
6121 * though, since fattr->valid will remain unset.
6122 */
Trond Myklebust6926afd12012-01-07 13:22:46 -05006123 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006124out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006125 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006126}
6127
6128/*
6129 * Decode OPEN response
6130 */
Chuck Leverbf269552010-12-14 14:59:29 +00006131static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6132 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133{
Andy Adamson05d564f2008-12-23 16:06:15 -05006134 struct compound_hdr hdr;
6135 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006136
Chuck Leverbf269552010-12-14 14:59:29 +00006137 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006138 if (status)
6139 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006140 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006141 if (status)
6142 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006143 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006144 if (status)
6145 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006146 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006147 if (status)
6148 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006149 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006150 goto out;
Trond Myklebust90ff0c52012-04-27 13:48:18 -04006151 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006153 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006154}
6155
6156/*
6157 * Decode OPEN_CONFIRM response
6158 */
Chuck Leverbf269552010-12-14 14:59:29 +00006159static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6160 struct xdr_stream *xdr,
6161 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006162{
Andy Adamson05d564f2008-12-23 16:06:15 -05006163 struct compound_hdr hdr;
6164 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006165
Chuck Leverbf269552010-12-14 14:59:29 +00006166 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006167 if (status)
6168 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006169 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006170 if (status)
6171 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006172 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006174 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006175}
6176
6177/*
6178 * Decode OPEN response
6179 */
Chuck Leverbf269552010-12-14 14:59:29 +00006180static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6181 struct xdr_stream *xdr,
6182 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183{
Andy Adamson05d564f2008-12-23 16:06:15 -05006184 struct compound_hdr hdr;
6185 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006186
Chuck Leverbf269552010-12-14 14:59:29 +00006187 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006188 if (status)
6189 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006190 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006191 if (status)
6192 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006193 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006194 if (status)
6195 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006196 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006197 if (status)
6198 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006199 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006201 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202}
6203
6204/*
6205 * Decode SETATTR response
6206 */
Chuck Leverbf269552010-12-14 14:59:29 +00006207static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6208 struct xdr_stream *xdr,
6209 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210{
Andy Adamson05d564f2008-12-23 16:06:15 -05006211 struct compound_hdr hdr;
6212 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006213
Chuck Leverbf269552010-12-14 14:59:29 +00006214 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006215 if (status)
6216 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006217 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006218 if (status)
6219 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006220 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006221 if (status)
6222 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006223 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006224 if (status)
6225 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006226 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006228 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229}
6230
6231/*
6232 * Decode LOCK response
6233 */
Chuck Leverbf269552010-12-14 14:59:29 +00006234static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6235 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006236{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237 struct compound_hdr hdr;
6238 int status;
6239
Chuck Leverbf269552010-12-14 14:59:29 +00006240 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006241 if (status)
6242 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006243 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006244 if (status)
6245 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006246 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006247 if (status)
6248 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006249 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006250out:
6251 return status;
6252}
6253
6254/*
6255 * Decode LOCKT response
6256 */
Chuck Leverbf269552010-12-14 14:59:29 +00006257static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6258 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006259{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260 struct compound_hdr hdr;
6261 int status;
6262
Chuck Leverbf269552010-12-14 14:59:29 +00006263 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006264 if (status)
6265 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006266 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006267 if (status)
6268 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006269 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270 if (status)
6271 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006272 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273out:
6274 return status;
6275}
6276
6277/*
6278 * Decode LOCKU response
6279 */
Chuck Leverbf269552010-12-14 14:59:29 +00006280static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6281 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006282{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006283 struct compound_hdr hdr;
6284 int status;
6285
Chuck Leverbf269552010-12-14 14:59:29 +00006286 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006287 if (status)
6288 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006289 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006290 if (status)
6291 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006292 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006293 if (status)
6294 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006295 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006296out:
6297 return status;
6298}
6299
Chuck Leverbf269552010-12-14 14:59:29 +00006300static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6301 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006302{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006303 struct compound_hdr hdr;
6304 int status;
6305
Chuck Leverbf269552010-12-14 14:59:29 +00006306 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006307 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006308 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006309 return status;
6310}
6311
Linus Torvalds1da177e2005-04-16 15:20:36 -07006312/*
6313 * Decode READLINK response
6314 */
Chuck Leverbf269552010-12-14 14:59:29 +00006315static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6316 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006317 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006318{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006319 struct compound_hdr hdr;
6320 int status;
6321
Chuck Leverbf269552010-12-14 14:59:29 +00006322 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323 if (status)
6324 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006326 if (status)
6327 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006328 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006329 if (status)
6330 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006331 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332out:
6333 return status;
6334}
6335
6336/*
6337 * Decode READDIR response
6338 */
Chuck Leverbf269552010-12-14 14:59:29 +00006339static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6340 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006341{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006342 struct compound_hdr hdr;
6343 int status;
6344
Chuck Leverbf269552010-12-14 14:59:29 +00006345 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006346 if (status)
6347 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006348 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006349 if (status)
6350 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006351 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352 if (status)
6353 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006354 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006355out:
6356 return status;
6357}
6358
6359/*
6360 * Decode Read response
6361 */
Chuck Leverbf269552010-12-14 14:59:29 +00006362static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6363 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006365 struct compound_hdr hdr;
6366 int status;
6367
Chuck Leverbf269552010-12-14 14:59:29 +00006368 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006369 if (status)
6370 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006371 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006372 if (status)
6373 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006374 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006375 if (status)
6376 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006377 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378 if (!status)
6379 status = res->count;
6380out:
6381 return status;
6382}
6383
6384/*
6385 * Decode WRITE response
6386 */
Chuck Leverbf269552010-12-14 14:59:29 +00006387static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6388 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006389{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006390 struct compound_hdr hdr;
6391 int status;
6392
Chuck Leverbf269552010-12-14 14:59:29 +00006393 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006394 if (status)
6395 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006396 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006397 if (status)
6398 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006399 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400 if (status)
6401 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006402 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006403 if (status)
6404 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006405 if (res->fattr)
Trond Myklebust6926afd12012-01-07 13:22:46 -05006406 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407 if (!status)
6408 status = res->count;
6409out:
6410 return status;
6411}
6412
6413/*
6414 * Decode COMMIT response
6415 */
Chuck Leverbf269552010-12-14 14:59:29 +00006416static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006417 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006418{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006419 struct compound_hdr hdr;
6420 int status;
6421
Chuck Leverbf269552010-12-14 14:59:29 +00006422 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006423 if (status)
6424 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006425 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006426 if (status)
6427 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006428 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429 if (status)
6430 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006431 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006432out:
6433 return status;
6434}
6435
6436/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006437 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006438 */
Chuck Leverbf269552010-12-14 14:59:29 +00006439static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006440 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006441{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006442 struct compound_hdr hdr;
6443 int status;
6444
Chuck Leverbf269552010-12-14 14:59:29 +00006445 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006446 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006447 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006448 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006449 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006451 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006452 return status;
6453}
6454
6455/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006456 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006457 */
Chuck Leverbf269552010-12-14 14:59:29 +00006458static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006459 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461 struct compound_hdr hdr;
6462 int status;
6463
Chuck Leverbf269552010-12-14 14:59:29 +00006464 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006466 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006467 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006468 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006469 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006470 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471 return status;
6472}
6473
6474/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006475 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006476 */
Chuck Leverbf269552010-12-14 14:59:29 +00006477static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006478 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480 struct compound_hdr hdr;
6481 int status;
6482
Chuck Leverbf269552010-12-14 14:59:29 +00006483 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006485 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006486 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006487 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006488 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006489 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490 return status;
6491}
6492
6493/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006494 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495 */
Chuck Leverbf269552010-12-14 14:59:29 +00006496static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6497 struct xdr_stream *xdr,
6498 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006499{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006500 struct compound_hdr hdr;
6501 int status;
6502
Chuck Leverbf269552010-12-14 14:59:29 +00006503 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006504 if (status)
6505 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006506 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006507 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006509 status = decode_putfh(xdr);
6510 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006511 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006512 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513out:
6514 return status;
6515}
6516
6517/*
6518 * Decode RENEW response
6519 */
Chuck Leverbf269552010-12-14 14:59:29 +00006520static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6521 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006522{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006523 struct compound_hdr hdr;
6524 int status;
6525
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006528 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529 return status;
6530}
6531
6532/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006533 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006534 */
Chuck Leverbf269552010-12-14 14:59:29 +00006535static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6536 struct xdr_stream *xdr,
6537 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006538{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539 struct compound_hdr hdr;
6540 int status;
6541
Chuck Leverbf269552010-12-14 14:59:29 +00006542 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006544 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545 return status;
6546}
6547
6548/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006549 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550 */
Chuck Leverbf269552010-12-14 14:59:29 +00006551static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6552 struct xdr_stream *xdr,
6553 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006555 struct compound_hdr hdr;
6556 int status;
6557
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006560 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006561 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006562 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006563 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006564 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006565 return status;
6566}
6567
6568/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006569 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006570 */
Chuck Leverbf269552010-12-14 14:59:29 +00006571static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6572 struct xdr_stream *xdr,
6573 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006575 struct compound_hdr hdr;
6576 int status;
6577
Chuck Leverbf269552010-12-14 14:59:29 +00006578 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006579 if (status)
6580 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006581 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006582 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006583 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006584 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006585 if (status != 0)
6586 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006587 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006588 if (status != 0)
6589 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006590 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006591out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006592 return status;
6593}
6594
Trond Myklebust683b57b2006-06-09 09:34:22 -04006595/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006596 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006597 */
Chuck Leverbf269552010-12-14 14:59:29 +00006598static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6599 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006600 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006601{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006602 struct compound_hdr hdr;
6603 int status;
6604
Chuck Leverbf269552010-12-14 14:59:29 +00006605 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006606 if (status)
6607 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006608 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006609 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006610 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006611 status = decode_putfh(xdr);
6612 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006613 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006614 status = decode_lookup(xdr);
6615 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006616 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006617 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006618 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6619 NULL, res->fs_locations,
6620 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006621out:
6622 return status;
6623}
6624
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006625/*
6626 * Decode SECINFO response
6627 */
6628static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6629 struct xdr_stream *xdr,
6630 struct nfs4_secinfo_res *res)
6631{
6632 struct compound_hdr hdr;
6633 int status;
6634
6635 status = decode_compound_hdr(xdr, &hdr);
6636 if (status)
6637 goto out;
6638 status = decode_sequence(xdr, &res->seq_res, rqstp);
6639 if (status)
6640 goto out;
6641 status = decode_putfh(xdr);
6642 if (status)
6643 goto out;
6644 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006645out:
6646 return status;
6647}
6648
Benny Halevy99fe60d2009-04-01 09:22:29 -04006649#if defined(CONFIG_NFS_V4_1)
6650/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006651 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006652 */
Chuck Leverbf269552010-12-14 14:59:29 +00006653static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6654 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006655 void *res)
6656{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006657 struct compound_hdr hdr;
6658 int status;
6659
Chuck Leverbf269552010-12-14 14:59:29 +00006660 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006661 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006662 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006663 return status;
6664}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006665
6666/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006667 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006668 */
Chuck Leverbf269552010-12-14 14:59:29 +00006669static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6670 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006671 struct nfs41_create_session_res *res)
6672{
Andy Adamsonfc931582009-04-01 09:22:31 -04006673 struct compound_hdr hdr;
6674 int status;
6675
Chuck Leverbf269552010-12-14 14:59:29 +00006676 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006677 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006678 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006679 return status;
6680}
6681
6682/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006683 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006684 */
Chuck Leverbf269552010-12-14 14:59:29 +00006685static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6686 struct xdr_stream *xdr,
6687 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006688{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006689 struct compound_hdr hdr;
6690 int status;
6691
Chuck Leverbf269552010-12-14 14:59:29 +00006692 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006693 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006694 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006695 return status;
6696}
6697
6698/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006699 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006700 */
Chuck Leverbf269552010-12-14 14:59:29 +00006701static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6702 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006703 struct nfs4_sequence_res *res)
6704{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006705 struct compound_hdr hdr;
6706 int status;
6707
Chuck Leverbf269552010-12-14 14:59:29 +00006708 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006709 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006710 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006711 return status;
6712}
6713
6714/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006715 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006716 */
Chuck Leverbf269552010-12-14 14:59:29 +00006717static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6718 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006719 struct nfs4_get_lease_time_res *res)
6720{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006721 struct compound_hdr hdr;
6722 int status;
6723
Chuck Leverbf269552010-12-14 14:59:29 +00006724 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006725 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006726 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006727 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006728 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006729 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006730 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006731 return status;
6732}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006733
6734/*
6735 * Decode RECLAIM_COMPLETE response
6736 */
Chuck Leverbf269552010-12-14 14:59:29 +00006737static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6738 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006739 struct nfs41_reclaim_complete_res *res)
6740{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006741 struct compound_hdr hdr;
6742 int status;
6743
Chuck Leverbf269552010-12-14 14:59:29 +00006744 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006745 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006746 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006747 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006748 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006749 return status;
6750}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006751
6752/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006753 * Decode GETDEVICELIST response
6754 */
6755static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6756 struct xdr_stream *xdr,
6757 struct nfs4_getdevicelist_res *res)
6758{
6759 struct compound_hdr hdr;
6760 int status;
6761
6762 dprintk("encoding getdevicelist!\n");
6763
6764 status = decode_compound_hdr(xdr, &hdr);
6765 if (status != 0)
6766 goto out;
6767 status = decode_sequence(xdr, &res->seq_res, rqstp);
6768 if (status != 0)
6769 goto out;
6770 status = decode_putfh(xdr);
6771 if (status != 0)
6772 goto out;
6773 status = decode_getdevicelist(xdr, res->devlist);
6774out:
6775 return status;
6776}
6777
6778/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006779 * Decode GETDEVINFO response
6780 */
Chuck Leverbf269552010-12-14 14:59:29 +00006781static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6782 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006783 struct nfs4_getdeviceinfo_res *res)
6784{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006785 struct compound_hdr hdr;
6786 int status;
6787
Chuck Leverbf269552010-12-14 14:59:29 +00006788 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006789 if (status != 0)
6790 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006791 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006792 if (status != 0)
6793 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006794 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006795out:
6796 return status;
6797}
6798
6799/*
6800 * Decode LAYOUTGET response
6801 */
Chuck Leverbf269552010-12-14 14:59:29 +00006802static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6803 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006804 struct nfs4_layoutget_res *res)
6805{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006806 struct compound_hdr hdr;
6807 int status;
6808
Chuck Leverbf269552010-12-14 14:59:29 +00006809 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006810 if (status)
6811 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006812 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006813 if (status)
6814 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006815 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006816 if (status)
6817 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006818 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006819out:
6820 return status;
6821}
Andy Adamson863a3c62011-03-23 13:27:54 +00006822
6823/*
Benny Halevycbe82602011-05-22 19:52:37 +03006824 * Decode LAYOUTRETURN response
6825 */
6826static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6827 struct xdr_stream *xdr,
6828 struct nfs4_layoutreturn_res *res)
6829{
6830 struct compound_hdr hdr;
6831 int status;
6832
6833 status = decode_compound_hdr(xdr, &hdr);
6834 if (status)
6835 goto out;
6836 status = decode_sequence(xdr, &res->seq_res, rqstp);
6837 if (status)
6838 goto out;
6839 status = decode_putfh(xdr);
6840 if (status)
6841 goto out;
6842 status = decode_layoutreturn(xdr, res);
6843out:
6844 return status;
6845}
6846
6847/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006848 * Decode LAYOUTCOMMIT response
6849 */
6850static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6851 struct xdr_stream *xdr,
6852 struct nfs4_layoutcommit_res *res)
6853{
6854 struct compound_hdr hdr;
6855 int status;
6856
6857 status = decode_compound_hdr(xdr, &hdr);
6858 if (status)
6859 goto out;
6860 status = decode_sequence(xdr, &res->seq_res, rqstp);
6861 if (status)
6862 goto out;
6863 status = decode_putfh(xdr);
6864 if (status)
6865 goto out;
6866 status = decode_layoutcommit(xdr, rqstp, res);
6867 if (status)
6868 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006869 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006870out:
6871 return status;
6872}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006873
6874/*
6875 * Decode SECINFO_NO_NAME response
6876 */
6877static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6878 struct xdr_stream *xdr,
6879 struct nfs4_secinfo_res *res)
6880{
6881 struct compound_hdr hdr;
6882 int status;
6883
6884 status = decode_compound_hdr(xdr, &hdr);
6885 if (status)
6886 goto out;
6887 status = decode_sequence(xdr, &res->seq_res, rqstp);
6888 if (status)
6889 goto out;
6890 status = decode_putrootfh(xdr);
6891 if (status)
6892 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04006893 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006894out:
6895 return status;
6896}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006897
6898/*
6899 * Decode TEST_STATEID response
6900 */
6901static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6902 struct xdr_stream *xdr,
6903 struct nfs41_test_stateid_res *res)
6904{
6905 struct compound_hdr hdr;
6906 int status;
6907
6908 status = decode_compound_hdr(xdr, &hdr);
6909 if (status)
6910 goto out;
6911 status = decode_sequence(xdr, &res->seq_res, rqstp);
6912 if (status)
6913 goto out;
6914 status = decode_test_stateid(xdr, res);
6915out:
6916 return status;
6917}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006918
6919/*
6920 * Decode FREE_STATEID response
6921 */
6922static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6923 struct xdr_stream *xdr,
6924 struct nfs41_free_stateid_res *res)
6925{
6926 struct compound_hdr hdr;
6927 int status;
6928
6929 status = decode_compound_hdr(xdr, &hdr);
6930 if (status)
6931 goto out;
6932 status = decode_sequence(xdr, &res->seq_res, rqstp);
6933 if (status)
6934 goto out;
6935 status = decode_free_stateid(xdr, res);
6936out:
6937 return status;
6938}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006939#endif /* CONFIG_NFS_V4_1 */
6940
Chuck Lever573c4e12010-12-14 14:58:11 +00006941/**
6942 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6943 * the local page cache.
6944 * @xdr: XDR stream where entry resides
6945 * @entry: buffer to fill in with entry data
6946 * @plus: boolean indicating whether this should be a readdirplus entry
6947 *
6948 * Returns zero if successful, otherwise a negative errno value is
6949 * returned.
6950 *
6951 * This function is not invoked during READDIR reply decoding, but
6952 * rather whenever an application invokes the getdents(2) system call
6953 * on a directory already in our cache.
6954 */
6955int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6956 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006957{
Fred Isamandae100c2011-07-30 20:52:37 -04006958 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07006959 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006960 __be32 *p = xdr_inline_decode(xdr, 4);
6961 if (unlikely(!p))
6962 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006963 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006964 p = xdr_inline_decode(xdr, 4);
6965 if (unlikely(!p))
6966 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006967 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006968 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006969 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006970 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006971 }
6972
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006973 p = xdr_inline_decode(xdr, 12);
6974 if (unlikely(!p))
6975 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006976 entry->prev_cookie = entry->cookie;
6977 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006978 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006979
Trond Myklebust9af8c222010-10-24 11:52:55 -04006980 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006981 if (unlikely(!p))
6982 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006983 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006984
6985 /*
6986 * In case the server doesn't return an inode number,
6987 * we fake one here. (We don't use inode number 0,
6988 * since glibc seems to choke on it...)
6989 */
6990 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006991 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006992
Trond Myklebust9af8c222010-10-24 11:52:55 -04006993 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006994 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006995
6996 if (decode_attr_length(xdr, &len, &p) < 0)
6997 goto out_overflow;
6998
Chuck Lever573c4e12010-12-14 14:58:11 +00006999 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007000 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007001 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007002 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7003 entry->ino = entry->fattr->mounted_on_fileid;
7004 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007005 entry->ino = entry->fattr->fileid;
7006
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007007 entry->d_type = DT_UNKNOWN;
7008 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7009 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7010
Chuck Lever573c4e12010-12-14 14:58:11 +00007011 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007012
7013out_overflow:
7014 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007015 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007016}
7017
7018/*
7019 * We need to translate between nfs status return values and
7020 * the local errno values which may not be the same.
7021 */
7022static struct {
7023 int stat;
7024 int errno;
7025} nfs_errtbl[] = {
7026 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007027 { NFS4ERR_PERM, -EPERM },
7028 { NFS4ERR_NOENT, -ENOENT },
7029 { NFS4ERR_IO, -errno_NFSERR_IO},
7030 { NFS4ERR_NXIO, -ENXIO },
7031 { NFS4ERR_ACCESS, -EACCES },
7032 { NFS4ERR_EXIST, -EEXIST },
7033 { NFS4ERR_XDEV, -EXDEV },
7034 { NFS4ERR_NOTDIR, -ENOTDIR },
7035 { NFS4ERR_ISDIR, -EISDIR },
7036 { NFS4ERR_INVAL, -EINVAL },
7037 { NFS4ERR_FBIG, -EFBIG },
7038 { NFS4ERR_NOSPC, -ENOSPC },
7039 { NFS4ERR_ROFS, -EROFS },
7040 { NFS4ERR_MLINK, -EMLINK },
7041 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7042 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7043 { NFS4ERR_DQUOT, -EDQUOT },
7044 { NFS4ERR_STALE, -ESTALE },
7045 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007046 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7047 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7048 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007049 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007050 { NFS4ERR_BADTYPE, -EBADTYPE },
7051 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007052 { NFS4ERR_SYMLINK, -ELOOP },
7053 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7054 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007055 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007056};
7057
7058/*
7059 * Convert an NFS error code to a local one.
7060 * This one is used jointly by NFSv2 and NFSv3.
7061 */
7062static int
David Howells0a8ea432006-08-22 20:06:08 -04007063nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007064{
7065 int i;
7066 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7067 if (nfs_errtbl[i].stat == stat)
7068 return nfs_errtbl[i].errno;
7069 }
7070 if (stat <= 10000 || stat > 10100) {
7071 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007072 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007073 }
7074 /* If we cannot translate the error, the recovery routines should
7075 * handle it.
7076 * Note: remaining NFSv4 error codes have values > 10000, so should
7077 * not conflict with native Linux error codes.
7078 */
Benny Halevy856dff32008-03-31 17:39:06 +03007079 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007080}
7081
Linus Torvalds1da177e2005-04-16 15:20:36 -07007082#define PROC(proc, argtype, restype) \
7083[NFSPROC4_CLNT_##proc] = { \
7084 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007085 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007086 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007087 .p_arglen = NFS4_##argtype##_sz, \
7088 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007089 .p_statidx = NFSPROC4_CLNT_##proc, \
7090 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007091}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007092
7093struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007094 PROC(READ, enc_read, dec_read),
7095 PROC(WRITE, enc_write, dec_write),
7096 PROC(COMMIT, enc_commit, dec_commit),
7097 PROC(OPEN, enc_open, dec_open),
7098 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7099 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7100 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7101 PROC(CLOSE, enc_close, dec_close),
7102 PROC(SETATTR, enc_setattr, dec_setattr),
7103 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7104 PROC(RENEW, enc_renew, dec_renew),
7105 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7106 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7107 PROC(LOCK, enc_lock, dec_lock),
7108 PROC(LOCKT, enc_lockt, dec_lockt),
7109 PROC(LOCKU, enc_locku, dec_locku),
7110 PROC(ACCESS, enc_access, dec_access),
7111 PROC(GETATTR, enc_getattr, dec_getattr),
7112 PROC(LOOKUP, enc_lookup, dec_lookup),
7113 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7114 PROC(REMOVE, enc_remove, dec_remove),
7115 PROC(RENAME, enc_rename, dec_rename),
7116 PROC(LINK, enc_link, dec_link),
7117 PROC(SYMLINK, enc_symlink, dec_symlink),
7118 PROC(CREATE, enc_create, dec_create),
7119 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7120 PROC(STATFS, enc_statfs, dec_statfs),
7121 PROC(READLINK, enc_readlink, dec_readlink),
7122 PROC(READDIR, enc_readdir, dec_readdir),
7123 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7124 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7125 PROC(GETACL, enc_getacl, dec_getacl),
7126 PROC(SETACL, enc_setacl, dec_setacl),
7127 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7128 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007129 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007130#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007131 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7132 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7133 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7134 PROC(SEQUENCE, enc_sequence, dec_sequence),
7135 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7136 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7137 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7138 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007139 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007140 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007141 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007142 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007143 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007144 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007145#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007146};
7147
Trond Myklebusta613fa12012-01-20 13:53:56 -05007148const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007149 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007150 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007151 .procs = nfs4_procedures
7152};
7153
7154/*
7155 * Local variables:
7156 * c-basic-offset: 8
7157 * End:
7158 */