blob: b851b560a6f83e3e0184499a7d2416b3f8c5921a [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>
47#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050048#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000049#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/nfs.h>
51#include <linux/nfs4.h>
52#include <linux/nfs_fs.h>
53#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000054#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050055#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040056#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58#define NFSDBG_FACILITY NFSDBG_XDR
59
60/* Mapping from NFS error code to "errno" error code. */
61#define errno_NFSERR_IO EIO
62
David Howells0a8ea432006-08-22 20:06:08 -040063static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
66#ifdef DEBUG
67#define NFS4_MAXTAGLEN 20
68#else
69#define NFS4_MAXTAGLEN 0
70#endif
71
Andy Adamson6c0195a2008-12-23 16:06:15 -050072/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040073 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 */
Trond Myklebustd035c362010-12-21 10:45:27 -050075#define open_owner_id_maxsz (1 + 1 + 4)
76#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040077#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
80#define op_encode_hdr_maxsz (1)
81#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040082#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
84#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
85#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
87 (NFS4_FHSIZE >> 2))
88#define decode_putfh_maxsz (op_decode_hdr_maxsz)
89#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
90#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
91#define encode_getfh_maxsz (op_encode_hdr_maxsz)
92#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
93 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040094#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000095#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
97#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040098#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
99#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000100/* This is based on getfattr, which uses the most attributes: */
101#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400102 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000103#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
104 nfs4_fattr_value_maxsz)
105#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400106#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
107 1 + 2 + 1 + \
108 nfs4_owner_maxsz + \
109 nfs4_group_maxsz + \
110 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define encode_savefh_maxsz (op_encode_hdr_maxsz)
112#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400113#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
114#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200115#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Bryan Schumaker7ebb9312011-03-24 17:12:30 +0000116#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 15)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
118#define decode_renew_maxsz (op_decode_hdr_maxsz)
119#define encode_setclientid_maxsz \
120 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500121 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
122 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
123 1 /* sc_prog */ + \
124 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
125 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
126 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define decode_setclientid_maxsz \
128 (op_decode_hdr_maxsz + \
129 2 + \
130 1024) /* large value for CLID_INUSE */
131#define encode_setclientid_confirm_maxsz \
132 (op_encode_hdr_maxsz + \
133 3 + (NFS4_VERIFIER_SIZE >> 2))
134#define decode_setclientid_confirm_maxsz \
135 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400136#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
137#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400138#define encode_share_access_maxsz \
139 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500140#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400141#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
142#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
143#define encode_open_maxsz (op_encode_hdr_maxsz + \
144 2 + encode_share_access_maxsz + 2 + \
145 open_owner_id_maxsz + \
146 encode_opentype_maxsz + \
147 encode_claim_null_maxsz)
148#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400149#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400150 decode_ace_maxsz)
151#define decode_change_info_maxsz (5)
152#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400153 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400154 decode_change_info_maxsz + 1 + \
155 nfs4_fattr_bitmap_maxsz + \
156 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400157#define encode_open_confirm_maxsz \
158 (op_encode_hdr_maxsz + \
159 encode_stateid_maxsz + 1)
160#define decode_open_confirm_maxsz \
161 (op_decode_hdr_maxsz + \
162 decode_stateid_maxsz)
163#define encode_open_downgrade_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1 + \
166 encode_share_access_maxsz)
167#define decode_open_downgrade_maxsz \
168 (op_decode_hdr_maxsz + \
169 decode_stateid_maxsz)
170#define encode_close_maxsz (op_encode_hdr_maxsz + \
171 1 + encode_stateid_maxsz)
172#define decode_close_maxsz (op_decode_hdr_maxsz + \
173 decode_stateid_maxsz)
174#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
175 encode_stateid_maxsz + \
176 encode_attrs_maxsz)
177#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
178 nfs4_fattr_bitmap_maxsz)
179#define encode_read_maxsz (op_encode_hdr_maxsz + \
180 encode_stateid_maxsz + 3)
181#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
182#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
183 2 + encode_verifier_maxsz + 5)
184#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
185 decode_verifier_maxsz)
186#define encode_readlink_maxsz (op_encode_hdr_maxsz)
187#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
188#define encode_write_maxsz (op_encode_hdr_maxsz + \
189 encode_stateid_maxsz + 4)
190#define decode_write_maxsz (op_decode_hdr_maxsz + \
191 2 + decode_verifier_maxsz)
192#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
193#define decode_commit_maxsz (op_decode_hdr_maxsz + \
194 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195#define encode_remove_maxsz (op_encode_hdr_maxsz + \
196 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400197#define decode_remove_maxsz (op_decode_hdr_maxsz + \
198 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199#define encode_rename_maxsz (op_encode_hdr_maxsz + \
200 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400201#define decode_rename_maxsz (op_decode_hdr_maxsz + \
202 decode_change_info_maxsz + \
203 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204#define encode_link_maxsz (op_encode_hdr_maxsz + \
205 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400206#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400207#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400208#define encode_lock_maxsz (op_encode_hdr_maxsz + \
209 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400210 1 + encode_stateid_maxsz + 1 + \
211 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400212#define decode_lock_denied_maxsz \
213 (8 + decode_lockowner_maxsz)
214#define decode_lock_maxsz (op_decode_hdr_maxsz + \
215 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400216#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
217 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400218#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
219 decode_lock_denied_maxsz)
220#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
221 encode_stateid_maxsz + \
222 4)
223#define decode_locku_maxsz (op_decode_hdr_maxsz + \
224 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400225#define encode_release_lockowner_maxsz \
226 (op_encode_hdr_maxsz + \
227 encode_lockowner_maxsz)
228#define decode_release_lockowner_maxsz \
229 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400230#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
231#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
233 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400234 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000235 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
237#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400238 1 + 2 + nfs4_name_maxsz + \
239 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400240#define decode_create_maxsz (op_decode_hdr_maxsz + \
241 decode_change_info_maxsz + \
242 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400243#define encode_statfs_maxsz (encode_getattr_maxsz)
244#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
246#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400247#define encode_getacl_maxsz (encode_getattr_maxsz)
248#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
249 nfs4_fattr_bitmap_maxsz + 1)
250#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
251 encode_stateid_maxsz + 3)
252#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400253#define encode_fs_locations_maxsz \
254 (encode_getattr_maxsz)
255#define decode_fs_locations_maxsz \
256 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000257#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400258#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 -0400259
260#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400261#define NFS4_MAX_MACHINE_NAME_LEN (64)
262
Benny Halevy99fe60d2009-04-01 09:22:29 -0400263#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
264 encode_verifier_maxsz + \
265 1 /* co_ownerid.len */ + \
266 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
267 1 /* flags */ + \
268 1 /* spa_how */ + \
269 0 /* SP4_NONE (for now) */ + \
270 1 /* zero implemetation id array */)
271#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
272 2 /* eir_clientid */ + \
273 1 /* eir_sequenceid */ + \
274 1 /* eir_flags */ + \
275 1 /* spr_how */ + \
276 0 /* SP4_NONE (for now) */ + \
277 2 /* eir_server_owner.so_minor_id */ + \
278 /* eir_server_owner.so_major_id<> */ \
279 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
280 /* eir_server_scope<> */ \
281 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
282 1 /* eir_server_impl_id array length */ + \
283 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400284#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
285#define decode_channel_attrs_maxsz (6 + \
286 1 /* ca_rdma_ird.len */ + \
287 1 /* ca_rdma_ird */)
288#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
289 2 /* csa_clientid */ + \
290 1 /* csa_sequence */ + \
291 1 /* csa_flags */ + \
292 encode_channel_attrs_maxsz + \
293 encode_channel_attrs_maxsz + \
294 1 /* csa_cb_program */ + \
295 1 /* csa_sec_parms.len (1) */ + \
296 1 /* cb_secflavor (AUTH_SYS) */ + \
297 1 /* stamp */ + \
298 1 /* machinename.len */ + \
299 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
300 1 /* uid */ + \
301 1 /* gid */ + \
302 1 /* gids.len (0) */)
303#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
304 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
305 1 /* csr_sequence */ + \
306 1 /* csr_flags */ + \
307 decode_channel_attrs_maxsz + \
308 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400309#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
310#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400311#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
312 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
313#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
314 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500315#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
316#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400317#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
318 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
319#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
320 1 /* layout type */ + \
321 1 /* opaque devaddr4 length */ + \
322 /* devaddr4 payload is read into page */ \
323 1 /* notification bitmap length */ + \
324 1 /* notification bitmap */)
325#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
326 encode_stateid_maxsz)
327#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
328 decode_stateid_maxsz + \
329 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000330#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
331 2 /* offset */ + \
332 2 /* length */ + \
333 1 /* reclaim */ + \
334 encode_stateid_maxsz + \
335 1 /* new offset (true) */ + \
336 2 /* last byte written */ + \
337 1 /* nt_timechanged (false) */ + \
338 1 /* layoutupdate4 layout type */ + \
339 1 /* NULL filelayout layoutupdate4 payload */)
340#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300341#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
342 encode_stateid_maxsz + \
343 1 /* FIXME: opaque lrf_body always empty at the moment */)
344#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
345 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400346#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
347#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400348#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
349 XDR_QUADLEN(NFS4_STATEID_SIZE))
350#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400351#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
352 XDR_QUADLEN(NFS4_STATEID_SIZE))
353#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400354#else /* CONFIG_NFS_V4_1 */
355#define encode_sequence_maxsz 0
356#define decode_sequence_maxsz 0
357#endif /* CONFIG_NFS_V4_1 */
358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
360#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
361#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400362 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400364 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400366 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400368 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400370 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400372 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400374 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400376 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400378 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400380 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400382 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400384 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400386 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400388 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400389 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400391 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400393 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400394 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400396 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400398 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400399 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400401 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400403 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400404 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400406 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400407 encode_putfh_maxsz + \
408 encode_savefh_maxsz + \
409 encode_open_maxsz + \
410 encode_getfh_maxsz + \
411 encode_getattr_maxsz + \
412 encode_restorefh_maxsz + \
413 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400415 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400416 decode_putfh_maxsz + \
417 decode_savefh_maxsz + \
418 decode_open_maxsz + \
419 decode_getfh_maxsz + \
420 decode_getattr_maxsz + \
421 decode_restorefh_maxsz + \
422 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400423#define NFS4_enc_open_confirm_sz \
424 (compound_encode_hdr_maxsz + \
425 encode_putfh_maxsz + \
426 encode_open_confirm_maxsz)
427#define NFS4_dec_open_confirm_sz \
428 (compound_decode_hdr_maxsz + \
429 decode_putfh_maxsz + \
430 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400434 encode_open_maxsz + \
435 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400439 decode_open_maxsz + \
440 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_enc_open_downgrade_sz \
442 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400443 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400444 encode_putfh_maxsz + \
445 encode_open_downgrade_maxsz + \
446 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447#define NFS4_dec_open_downgrade_sz \
448 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400449 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400450 decode_putfh_maxsz + \
451 decode_open_downgrade_maxsz + \
452 decode_getattr_maxsz)
453#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400454 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400455 encode_putfh_maxsz + \
456 encode_close_maxsz + \
457 encode_getattr_maxsz)
458#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400459 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400460 decode_putfh_maxsz + \
461 decode_close_maxsz + \
462 decode_getattr_maxsz)
463#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400464 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400465 encode_putfh_maxsz + \
466 encode_setattr_maxsz + \
467 encode_getattr_maxsz)
468#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400470 decode_putfh_maxsz + \
471 decode_setattr_maxsz + \
472 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400474 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 encode_putfh_maxsz + \
476 encode_fsinfo_maxsz)
477#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400478 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 decode_putfh_maxsz + \
480 decode_fsinfo_maxsz)
481#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
482 encode_renew_maxsz)
483#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
484 decode_renew_maxsz)
485#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
486 encode_setclientid_maxsz)
487#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
488 decode_setclientid_maxsz)
489#define NFS4_enc_setclientid_confirm_sz \
490 (compound_encode_hdr_maxsz + \
491 encode_setclientid_confirm_maxsz + \
492 encode_putrootfh_maxsz + \
493 encode_fsinfo_maxsz)
494#define NFS4_dec_setclientid_confirm_sz \
495 (compound_decode_hdr_maxsz + \
496 decode_setclientid_confirm_maxsz + \
497 decode_putrootfh_maxsz + \
498 decode_fsinfo_maxsz)
499#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400500 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400502 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400504 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400506 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400508 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400510 encode_lockt_maxsz)
511#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400512 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400513 decode_putfh_maxsz + \
514 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400516 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400518 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400522 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400523#define NFS4_enc_release_lockowner_sz \
524 (compound_encode_hdr_maxsz + \
525 encode_lockowner_maxsz)
526#define NFS4_dec_release_lockowner_sz \
527 (compound_decode_hdr_maxsz + \
528 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400532 encode_access_maxsz + \
533 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400535 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400537 decode_access_maxsz + \
538 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400540 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 encode_putfh_maxsz + \
542 encode_getattr_maxsz)
543#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400544 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 decode_putfh_maxsz + \
546 decode_getattr_maxsz)
547#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400548 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 encode_putfh_maxsz + \
550 encode_lookup_maxsz + \
551 encode_getattr_maxsz + \
552 encode_getfh_maxsz)
553#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400554 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400556 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 decode_getattr_maxsz + \
558 decode_getfh_maxsz)
559#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400560 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 encode_putrootfh_maxsz + \
562 encode_getattr_maxsz + \
563 encode_getfh_maxsz)
564#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400565 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 decode_putrootfh_maxsz + \
567 decode_getattr_maxsz + \
568 decode_getfh_maxsz)
569#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400572 encode_remove_maxsz + \
573 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400575 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400577 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400578 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 encode_putfh_maxsz + \
582 encode_savefh_maxsz + \
583 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400584 encode_rename_maxsz + \
585 encode_getattr_maxsz + \
586 encode_restorefh_maxsz + \
587 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400589 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 decode_putfh_maxsz + \
591 decode_savefh_maxsz + \
592 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400593 decode_rename_maxsz + \
594 decode_getattr_maxsz + \
595 decode_restorefh_maxsz + \
596 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400598 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 encode_putfh_maxsz + \
600 encode_savefh_maxsz + \
601 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400602 encode_link_maxsz + \
603 decode_getattr_maxsz + \
604 encode_restorefh_maxsz + \
605 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606#define NFS4_dec_link_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 Myklebust91ba2ee2005-10-27 22:12:42 -0400611 decode_link_maxsz + \
612 decode_getattr_maxsz + \
613 decode_restorefh_maxsz + \
614 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400616 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 encode_putfh_maxsz + \
618 encode_symlink_maxsz + \
619 encode_getattr_maxsz + \
620 encode_getfh_maxsz)
621#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 decode_putfh_maxsz + \
624 decode_symlink_maxsz + \
625 decode_getattr_maxsz + \
626 decode_getfh_maxsz)
627#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400628 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400630 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400632 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400634 encode_restorefh_maxsz + \
635 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400637 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400639 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400641 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400643 decode_restorefh_maxsz + \
644 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400646 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 encode_putfh_maxsz + \
648 encode_getattr_maxsz)
649#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 decode_putfh_maxsz + \
652 decode_getattr_maxsz)
653#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400656 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400658 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400660 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400662 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800663 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 encode_getattr_maxsz)
665#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400666 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800667 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 decode_getattr_maxsz)
669#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400670 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100672 encode_delegreturn_maxsz + \
673 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400675 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100676 decode_delegreturn_maxsz + \
677 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000678#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400679 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000680 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400681 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000682#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400683 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000684 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400685 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000686#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400687 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000688 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400689 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000690#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400691 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000692 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400693 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400694#define NFS4_enc_fs_locations_sz \
695 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400697 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400698 encode_lookup_maxsz + \
699 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400700#define NFS4_dec_fs_locations_sz \
701 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400702 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400703 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400704 decode_lookup_maxsz + \
705 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000706#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
707 encode_sequence_maxsz + \
708 encode_putfh_maxsz + \
709 encode_secinfo_maxsz)
710#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
711 decode_sequence_maxsz + \
712 decode_putfh_maxsz + \
713 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400714#if defined(CONFIG_NFS_V4_1)
715#define NFS4_enc_exchange_id_sz \
716 (compound_encode_hdr_maxsz + \
717 encode_exchange_id_maxsz)
718#define NFS4_dec_exchange_id_sz \
719 (compound_decode_hdr_maxsz + \
720 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400721#define NFS4_enc_create_session_sz \
722 (compound_encode_hdr_maxsz + \
723 encode_create_session_maxsz)
724#define NFS4_dec_create_session_sz \
725 (compound_decode_hdr_maxsz + \
726 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400727#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
728 encode_destroy_session_maxsz)
729#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
730 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400731#define NFS4_enc_sequence_sz \
732 (compound_decode_hdr_maxsz + \
733 encode_sequence_maxsz)
734#define NFS4_dec_sequence_sz \
735 (compound_decode_hdr_maxsz + \
736 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400737#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
738 encode_sequence_maxsz + \
739 encode_putrootfh_maxsz + \
740 encode_fsinfo_maxsz)
741#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
742 decode_sequence_maxsz + \
743 decode_putrootfh_maxsz + \
744 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500745#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
746 encode_sequence_maxsz + \
747 encode_reclaim_complete_maxsz)
748#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
749 decode_sequence_maxsz + \
750 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400751#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
752 encode_sequence_maxsz +\
753 encode_getdeviceinfo_maxsz)
754#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
755 decode_sequence_maxsz + \
756 decode_getdeviceinfo_maxsz)
757#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
758 encode_sequence_maxsz + \
759 encode_putfh_maxsz + \
760 encode_layoutget_maxsz)
761#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz + \
763 decode_putfh_maxsz + \
764 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000765#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
766 encode_sequence_maxsz +\
767 encode_putfh_maxsz + \
768 encode_layoutcommit_maxsz + \
769 encode_getattr_maxsz)
770#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
771 decode_sequence_maxsz + \
772 decode_putfh_maxsz + \
773 decode_layoutcommit_maxsz + \
774 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300775#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
776 encode_sequence_maxsz + \
777 encode_putfh_maxsz + \
778 encode_layoutreturn_maxsz)
779#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
780 decode_sequence_maxsz + \
781 decode_putfh_maxsz + \
782 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400783#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
784 encode_sequence_maxsz + \
785 encode_putrootfh_maxsz +\
786 encode_secinfo_no_name_maxsz)
787#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
788 decode_sequence_maxsz + \
789 decode_putrootfh_maxsz + \
790 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400791#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
792 encode_sequence_maxsz + \
793 encode_test_stateid_maxsz)
794#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
795 decode_sequence_maxsz + \
796 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400797#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
798 encode_sequence_maxsz + \
799 encode_free_stateid_maxsz)
800#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
801 decode_sequence_maxsz + \
802 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500803
804const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
805 compound_encode_hdr_maxsz +
806 encode_sequence_maxsz +
807 encode_putfh_maxsz +
808 encode_getattr_maxsz) *
809 XDR_UNIT);
810
811const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
812 compound_decode_hdr_maxsz +
813 decode_sequence_maxsz +
814 decode_putfh_maxsz) *
815 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400816#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Trond Myklebustbca79472009-03-11 14:10:26 -0400818static const umode_t nfs_type2fmt[] = {
819 [NF4BAD] = 0,
820 [NF4REG] = S_IFREG,
821 [NF4DIR] = S_IFDIR,
822 [NF4BLK] = S_IFBLK,
823 [NF4CHR] = S_IFCHR,
824 [NF4LNK] = S_IFLNK,
825 [NF4SOCK] = S_IFSOCK,
826 [NF4FIFO] = S_IFIFO,
827 [NF4ATTRDIR] = 0,
828 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829};
830
831struct compound_hdr {
832 int32_t status;
833 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500834 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 uint32_t taglen;
836 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400837 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400838 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839};
840
Benny Halevy13c65ce2009-08-14 17:19:25 +0300841static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
842{
843 __be32 *p = xdr_reserve_space(xdr, nbytes);
844 BUG_ON(!p);
845 return p;
846}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
848static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
849{
Al Viro8687b632006-10-19 23:28:48 -0700850 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
852 p = xdr_reserve_space(xdr, 4 + len);
853 BUG_ON(p == NULL);
854 xdr_encode_opaque(p, str, len);
855}
856
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400857static void encode_compound_hdr(struct xdr_stream *xdr,
858 struct rpc_rqst *req,
859 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860{
Al Viro8687b632006-10-19 23:28:48 -0700861 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400862 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400863
864 /* initialize running count of expected bytes in reply.
865 * NOTE: the replied tag SHOULD be the same is the one sent,
866 * but this is not required as a MUST for the server to do so. */
867 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
869 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
870 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300871 p = reserve_space(xdr, 4 + hdr->taglen + 8);
872 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300873 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500874 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300875 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500876}
877
878static void encode_nops(struct compound_hdr *hdr)
879{
Andy Adamsonfc931582009-04-01 09:22:31 -0400880 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500881 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882}
883
884static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
885{
Al Viro8687b632006-10-19 23:28:48 -0700886 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
888 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
889 BUG_ON(p == NULL);
890 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
891}
892
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500893static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894{
895 char owner_name[IDMAP_NAMESZ];
896 char owner_group[IDMAP_NAMESZ];
897 int owner_namelen = 0;
898 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700899 __be32 *p;
900 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 int len;
902 uint32_t bmval0 = 0;
903 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
905 /*
906 * We reserve enough space to write the entire attribute buffer at once.
907 * In the worst-case, this would be
908 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
909 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000910 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 */
912 len = 16;
913
914 /* Sigh */
915 if (iap->ia_valid & ATTR_SIZE)
916 len += 8;
917 if (iap->ia_valid & ATTR_MODE)
918 len += 4;
919 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800920 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400922 dprintk("nfs: couldn't resolve uid %d to string\n",
923 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 /* XXX */
925 strcpy(owner_name, "nobody");
926 owner_namelen = sizeof("nobody") - 1;
927 /* goto out; */
928 }
929 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
930 }
931 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800932 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400934 dprintk("nfs: couldn't resolve gid %d to string\n",
935 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 strcpy(owner_group, "nobody");
937 owner_grouplen = sizeof("nobody") - 1;
938 /* goto out; */
939 }
940 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
941 }
942 if (iap->ia_valid & ATTR_ATIME_SET)
943 len += 16;
944 else if (iap->ia_valid & ATTR_ATIME)
945 len += 4;
946 if (iap->ia_valid & ATTR_MTIME_SET)
947 len += 16;
948 else if (iap->ia_valid & ATTR_MTIME)
949 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300950 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 /*
953 * We write the bitmap length now, but leave the bitmap and the attribute
954 * buffer length to be backfilled at the end of this routine.
955 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300956 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 q = p;
958 p += 3;
959
960 if (iap->ia_valid & ATTR_SIZE) {
961 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300962 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 }
964 if (iap->ia_valid & ATTR_MODE) {
965 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300966 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 }
968 if (iap->ia_valid & ATTR_UID) {
969 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300970 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 }
972 if (iap->ia_valid & ATTR_GID) {
973 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300974 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 }
976 if (iap->ia_valid & ATTR_ATIME_SET) {
977 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300978 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
979 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -0400980 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
981 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 }
983 else if (iap->ia_valid & ATTR_ATIME) {
984 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300985 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 }
987 if (iap->ia_valid & ATTR_MTIME_SET) {
988 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300989 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
990 *p++ = cpu_to_be32(0);
991 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
992 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 }
994 else if (iap->ia_valid & ATTR_MTIME) {
995 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300996 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500998
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 /*
1000 * Now we backfill the bitmap and the attribute buffer length.
1001 */
1002 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001003 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 len, ((char *)p - (char *)q) + 4);
1005 BUG();
1006 }
1007 len = (char *)p - (char *)q - 12;
1008 *q++ = htonl(bmval0);
1009 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001010 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013}
1014
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001015static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016{
Al Viro8687b632006-10-19 23:28:48 -07001017 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
Benny Halevy13c65ce2009-08-14 17:19:25 +03001019 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001020 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +03001021 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -05001022 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001023 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024}
1025
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001026static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027{
Al Viro8687b632006-10-19 23:28:48 -07001028 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
Benny Halevy13c65ce2009-08-14 17:19:25 +03001030 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001031 *p++ = cpu_to_be32(OP_CLOSE);
1032 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +03001033 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001034 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001035 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036}
1037
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001038static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039{
Al Viro8687b632006-10-19 23:28:48 -07001040 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001041
Benny Halevy13c65ce2009-08-14 17:19:25 +03001042 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001043 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001044 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001045 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001046 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001047 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048}
1049
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001050static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051{
Al Viro8687b632006-10-19 23:28:48 -07001052 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001053
Benny Halevy13c65ce2009-08-14 17:19:25 +03001054 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001055 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001056 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
1058 switch (create->ftype) {
1059 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001060 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001061 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001062 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 break;
1064
1065 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001066 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001067 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001068 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 break;
1070
1071 default:
1072 break;
1073 }
1074
Benny Halevy811652b2009-08-14 17:19:34 +03001075 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001076 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001077 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001079 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080}
1081
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001082static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083{
Andy Adamson05d564f2008-12-23 16:06:15 -05001084 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
Benny Halevy13c65ce2009-08-14 17:19:25 +03001086 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001087 *p++ = cpu_to_be32(OP_GETATTR);
1088 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001089 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001090 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001091 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092}
1093
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001094static 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 -07001095{
Andy Adamson05d564f2008-12-23 16:06:15 -05001096 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Benny Halevy13c65ce2009-08-14 17:19:25 +03001098 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001099 *p++ = cpu_to_be32(OP_GETATTR);
1100 *p++ = cpu_to_be32(2);
1101 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001102 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001103 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001104 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105}
1106
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001107static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001109 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1110 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111}
1112
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001113static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001115 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1116 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117}
1118
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001119static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001120{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001121 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1122 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001123}
1124
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001125static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126{
Al Viro8687b632006-10-19 23:28:48 -07001127 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Benny Halevy13c65ce2009-08-14 17:19:25 +03001129 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001130 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001131 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001132 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133}
1134
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001135static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136{
Al Viro8687b632006-10-19 23:28:48 -07001137 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Benny Halevy13c65ce2009-08-14 17:19:25 +03001139 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001140 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001141 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001142 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001143 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144}
1145
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001146static inline int nfs4_lock_type(struct file_lock *fl, int block)
1147{
1148 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1149 return block ? NFS4_READW_LT : NFS4_READ_LT;
1150 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1151}
1152
1153static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1154{
1155 if (fl->fl_end == OFFSET_MAX)
1156 return ~(uint64_t)0;
1157 return fl->fl_end - fl->fl_start + 1;
1158}
1159
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001160static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1161{
1162 __be32 *p;
1163
Trond Myklebustd035c362010-12-21 10:45:27 -05001164 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001165 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001166 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001167 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001168 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001169 xdr_encode_hyper(p, lowner->id);
1170}
1171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172/*
1173 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1174 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1175 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001176static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177{
Al Viro8687b632006-10-19 23:28:48 -07001178 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
Benny Halevy13c65ce2009-08-14 17:19:25 +03001180 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001181 *p++ = cpu_to_be32(OP_LOCK);
1182 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1183 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001184 p = xdr_encode_hyper(p, args->fl->fl_start);
1185 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001186 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001187 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001188 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001189 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001190 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001191 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001192 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 }
1194 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001195 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001196 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001197 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 }
Andy Adamsond0179312008-12-23 16:06:17 -05001199 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001200 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201}
1202
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001203static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204{
Al Viro8687b632006-10-19 23:28:48 -07001205 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001207 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001208 *p++ = cpu_to_be32(OP_LOCKT);
1209 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001210 p = xdr_encode_hyper(p, args->fl->fl_start);
1211 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001212 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001213 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001214 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215}
1216
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001217static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218{
Al Viro8687b632006-10-19 23:28:48 -07001219 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
Benny Halevy13c65ce2009-08-14 17:19:25 +03001221 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001222 *p++ = cpu_to_be32(OP_LOCKU);
1223 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1224 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001225 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001226 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001227 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001228 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001229 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230}
1231
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001232static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1233{
1234 __be32 *p;
1235
1236 p = reserve_space(xdr, 4);
1237 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1238 encode_lockowner(xdr, lowner);
1239 hdr->nops++;
1240 hdr->replen += decode_release_lockowner_maxsz;
1241}
1242
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001243static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244{
1245 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001246 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Benny Halevy13c65ce2009-08-14 17:19:25 +03001248 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001249 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001250 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001251 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001252 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253}
1254
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001255static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256{
Al Viro8687b632006-10-19 23:28:48 -07001257 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
Benny Halevy13c65ce2009-08-14 17:19:25 +03001259 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001260 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001261 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001262 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001263 break;
1264 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001265 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001266 break;
1267 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001268 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001269 break;
1270 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001271 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 }
Benny Halevy34558512009-08-14 17:19:30 +03001273 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274}
1275
1276static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1277{
Al Viro8687b632006-10-19 23:28:48 -07001278 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 /*
1280 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1281 * owner 4 = 32
1282 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001283 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001284 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001285 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001286 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001287 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001288 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001289 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001290 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001291 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001292 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293}
1294
1295static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1296{
Al Viro8687b632006-10-19 23:28:48 -07001297 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001298 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
Benny Halevy13c65ce2009-08-14 17:19:25 +03001300 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001302 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001303 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001304 encode_attrs(xdr, arg->u.attrs, arg->server);
1305 break;
1306 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001307 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001308 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001309 if (nfs4_has_persistent_session(clp)) {
1310 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1311 encode_attrs(xdr, arg->u.attrs, arg->server);
1312 } else {
1313 struct iattr dummy;
1314
1315 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1316 encode_nfs4_verifier(xdr, &arg->u.verifier);
1317 dummy.ia_valid = 0;
1318 encode_attrs(xdr, &dummy, arg->server);
1319 }
1320 } else {
1321 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1322 encode_nfs4_verifier(xdr, &arg->u.verifier);
1323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 }
1325}
1326
1327static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1328{
Al Viro8687b632006-10-19 23:28:48 -07001329 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Benny Halevy13c65ce2009-08-14 17:19:25 +03001331 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001333 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001334 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001335 break;
1336 default:
1337 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001338 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001339 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 }
1341}
1342
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001343static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344{
Al Viro8687b632006-10-19 23:28:48 -07001345 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
Benny Halevy13c65ce2009-08-14 17:19:25 +03001347 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001349 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001350 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001351 break;
1352 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001353 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001354 break;
1355 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001356 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001357 break;
1358 default:
1359 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 }
1361}
1362
1363static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1364{
Al Viro8687b632006-10-19 23:28:48 -07001365 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
Benny Halevy13c65ce2009-08-14 17:19:25 +03001367 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001368 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 encode_string(xdr, name->len, name->name);
1370}
1371
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001372static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373{
Al Viro8687b632006-10-19 23:28:48 -07001374 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
Benny Halevy13c65ce2009-08-14 17:19:25 +03001376 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001377 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 encode_delegation_type(xdr, type);
1379}
1380
1381static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1382{
Al Viro8687b632006-10-19 23:28:48 -07001383 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
Benny Halevy13c65ce2009-08-14 17:19:25 +03001385 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001386 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001387 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 encode_string(xdr, name->len, name->name);
1389}
1390
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001391static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392{
1393 encode_openhdr(xdr, arg);
1394 encode_opentype(xdr, arg);
1395 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001396 case NFS4_OPEN_CLAIM_NULL:
1397 encode_claim_null(xdr, arg->name);
1398 break;
1399 case NFS4_OPEN_CLAIM_PREVIOUS:
1400 encode_claim_previous(xdr, arg->u.delegation_type);
1401 break;
1402 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1403 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1404 break;
1405 default:
1406 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 }
Andy Adamsond0179312008-12-23 16:06:17 -05001408 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001409 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410}
1411
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001412static 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 -07001413{
Al Viro8687b632006-10-19 23:28:48 -07001414 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415
Benny Halevy13c65ce2009-08-14 17:19:25 +03001416 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001417 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001418 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001419 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001420 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001421 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422}
1423
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001424static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425{
Al Viro8687b632006-10-19 23:28:48 -07001426 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
Benny Halevy13c65ce2009-08-14 17:19:25 +03001428 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001429 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001430 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001431 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001432 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001433 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001434 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435}
1436
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001437static void
Andy Adamsond0179312008-12-23 16:06:17 -05001438encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
1440 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001441 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
Benny Halevy13c65ce2009-08-14 17:19:25 +03001443 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001444 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001445 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001446 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001447 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448}
1449
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001450static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451{
Andy Adamson05d564f2008-12-23 16:06:15 -05001452 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001453
Benny Halevy13c65ce2009-08-14 17:19:25 +03001454 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001455 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001456 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001457 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458}
1459
Andy Adamson89d1ea62011-03-01 01:34:09 +00001460static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001463 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Benny Halevy13c65ce2009-08-14 17:19:25 +03001465 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001467 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001468 if (zero_seqid)
1469 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001470 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 } else
Benny Halevy34558512009-08-14 17:19:30 +03001472 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473}
1474
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001475static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476{
Al Viro8687b632006-10-19 23:28:48 -07001477 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
Benny Halevy13c65ce2009-08-14 17:19:25 +03001479 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001480 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
Andy Adamson89d1ea62011-03-01 01:34:09 +00001482 encode_stateid(xdr, args->context, args->lock_context,
1483 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
Benny Halevy13c65ce2009-08-14 17:19:25 +03001485 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001486 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001487 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001488 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001489 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490}
1491
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001492static 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 -07001493{
Trond Myklebust28331a42011-04-27 13:47:52 -04001494 uint32_t attrs[2] = {
1495 FATTR4_WORD0_RDATTR_ERROR,
1496 FATTR4_WORD1_MOUNTED_ON_FILEID,
1497 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001498 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001499 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001501 if (readdir->plus) {
1502 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001503 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001504 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1505 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1506 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1507 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001508 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001509 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001510 /* Use mounted_on_fileid only if the server supports it */
1511 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1512 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001513
Benny Halevy13c65ce2009-08-14 17:19:25 +03001514 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001515 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001516 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001517 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001518 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001519 *p++ = cpu_to_be32(readdir->count);
1520 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001521
Benny Halevye75bc1c2009-08-14 17:18:54 +03001522 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001523 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001524 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001525 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001526 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1527 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001528 (unsigned long long)readdir->cookie,
1529 ((u32 *)readdir->verifier.data)[0],
1530 ((u32 *)readdir->verifier.data)[1],
1531 attrs[0] & readdir->bitmask[0],
1532 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533}
1534
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001535static 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 -07001536{
Al Viro8687b632006-10-19 23:28:48 -07001537 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
Benny Halevy13c65ce2009-08-14 17:19:25 +03001539 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001540 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001541 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001542 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543}
1544
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001545static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546{
Al Viro8687b632006-10-19 23:28:48 -07001547 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
Benny Halevy13c65ce2009-08-14 17:19:25 +03001549 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001550 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001551 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001552 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001553 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554}
1555
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001556static 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 -07001557{
Al Viro8687b632006-10-19 23:28:48 -07001558 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
Benny Halevy811652b2009-08-14 17:19:34 +03001560 p = reserve_space(xdr, 4);
1561 *p = cpu_to_be32(OP_RENAME);
1562 encode_string(xdr, oldname->len, oldname->name);
1563 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001564 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001565 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566}
1567
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001568static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569{
Al Viro8687b632006-10-19 23:28:48 -07001570 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
Benny Halevy13c65ce2009-08-14 17:19:25 +03001572 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001573 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001574 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001575 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001576 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577}
1578
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001579static void
Andy Adamsond0179312008-12-23 16:06:17 -05001580encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001581{
Al Viro8687b632006-10-19 23:28:48 -07001582 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001583
Benny Halevy13c65ce2009-08-14 17:19:25 +03001584 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001585 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001586 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001587 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001588}
1589
Chuck Lever9f06c712010-12-14 14:59:18 +00001590static void
Andy Adamsond0179312008-12-23 16:06:17 -05001591encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001592{
Al Viro8687b632006-10-19 23:28:48 -07001593 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001594
Benny Halevy13c65ce2009-08-14 17:19:25 +03001595 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001596 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001597 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001598 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001599 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001600 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001601 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001602 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001603 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001604 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001605 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001606 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001607}
1608
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001609static void
Andy Adamsond0179312008-12-23 16:06:17 -05001610encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611{
Al Viro8687b632006-10-19 23:28:48 -07001612 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
Benny Halevy13c65ce2009-08-14 17:19:25 +03001614 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001615 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001616 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001617 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618}
1619
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001620static 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 -07001621{
Al Viro8687b632006-10-19 23:28:48 -07001622 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001623
Benny Halevy13c65ce2009-08-14 17:19:25 +03001624 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001625 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001626 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001627 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001628 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001629 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630}
1631
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001632static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633{
Al Viro8687b632006-10-19 23:28:48 -07001634 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635
Benny Halevy13c65ce2009-08-14 17:19:25 +03001636 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001637 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001638 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
1640 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001641 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001642 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1644 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001645 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001646 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001647 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001648 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
1650
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001651static 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 -07001652{
Andy Adamson05d564f2008-12-23 16:06:15 -05001653 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
Benny Halevy13c65ce2009-08-14 17:19:25 +03001655 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001656 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001657 p = xdr_encode_hyper(p, arg->clientid);
1658 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001659 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001660 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661}
1662
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001663static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664{
Al Viro8687b632006-10-19 23:28:48 -07001665 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
Benny Halevy13c65ce2009-08-14 17:19:25 +03001667 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001668 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
Andy Adamson89d1ea62011-03-01 01:34:09 +00001670 encode_stateid(xdr, args->context, args->lock_context,
1671 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
Benny Halevy13c65ce2009-08-14 17:19:25 +03001673 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001674 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001675 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001676 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
1678 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001679 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001680 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681}
1682
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001683static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684{
Al Viro8687b632006-10-19 23:28:48 -07001685 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686
Benny Halevy13c65ce2009-08-14 17:19:25 +03001687 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
Benny Halevye75bc1c2009-08-14 17:18:54 +03001689 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001690 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001691 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001692 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001694
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001695static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1696{
1697 int len = name->len;
1698 __be32 *p;
1699
1700 p = reserve_space(xdr, 8 + len);
1701 *p++ = cpu_to_be32(OP_SECINFO);
1702 xdr_encode_opaque(p, name->name, len);
1703 hdr->nops++;
1704 hdr->replen += decode_secinfo_maxsz;
1705}
1706
Benny Halevy99fe60d2009-04-01 09:22:29 -04001707#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001708/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001709static void encode_exchange_id(struct xdr_stream *xdr,
1710 struct nfs41_exchange_id_args *args,
1711 struct compound_hdr *hdr)
1712{
1713 __be32 *p;
1714
Benny Halevy13c65ce2009-08-14 17:19:25 +03001715 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001716 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001717 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001718
1719 encode_string(xdr, args->id_len, args->id);
1720
Benny Halevy13c65ce2009-08-14 17:19:25 +03001721 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001722 *p++ = cpu_to_be32(args->flags);
1723 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001724 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001725 hdr->nops++;
1726 hdr->replen += decode_exchange_id_maxsz;
1727}
Andy Adamsonfc931582009-04-01 09:22:31 -04001728
1729static void encode_create_session(struct xdr_stream *xdr,
1730 struct nfs41_create_session_args *args,
1731 struct compound_hdr *hdr)
1732{
1733 __be32 *p;
1734 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1735 uint32_t len;
1736 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001737 u32 max_resp_sz_cached;
1738
1739 /*
1740 * Assumes OPEN is the biggest non-idempotent compound.
1741 * 2 is the verifier.
1742 */
1743 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1744 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001745
Andy Adamsonfc931582009-04-01 09:22:31 -04001746 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1747 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001748
Benny Halevy13c65ce2009-08-14 17:19:25 +03001749 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001750 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001751 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001752 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1753 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001754
Andy Adamsonfc931582009-04-01 09:22:31 -04001755 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001756 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001757 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1758 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001759 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001760 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1761 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1762 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001763
1764 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001765 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001766 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1767 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1768 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1769 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1770 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1771 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001772
Benny Halevye75bc1c2009-08-14 17:18:54 +03001773 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001774 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001775 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001776
1777 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001778 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001779 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001780 *p++ = cpu_to_be32(0); /* UID */
1781 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001782 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001783 hdr->nops++;
1784 hdr->replen += decode_create_session_maxsz;
1785}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001786
1787static void encode_destroy_session(struct xdr_stream *xdr,
1788 struct nfs4_session *session,
1789 struct compound_hdr *hdr)
1790{
1791 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001792 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001793 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001794 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001795 hdr->nops++;
1796 hdr->replen += decode_destroy_session_maxsz;
1797}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001798
1799static void encode_reclaim_complete(struct xdr_stream *xdr,
1800 struct nfs41_reclaim_complete_args *args,
1801 struct compound_hdr *hdr)
1802{
1803 __be32 *p;
1804
1805 p = reserve_space(xdr, 8);
1806 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1807 *p++ = cpu_to_be32(args->one_fs);
1808 hdr->nops++;
1809 hdr->replen += decode_reclaim_complete_maxsz;
1810}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001811#endif /* CONFIG_NFS_V4_1 */
1812
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001813static void encode_sequence(struct xdr_stream *xdr,
1814 const struct nfs4_sequence_args *args,
1815 struct compound_hdr *hdr)
1816{
1817#if defined(CONFIG_NFS_V4_1)
1818 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001819 struct nfs4_slot_table *tp;
1820 struct nfs4_slot *slot;
1821 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001822
1823 if (!session)
1824 return;
1825
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001826 tp = &session->fc_slot_table;
1827
1828 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1829 slot = tp->slots + args->sa_slotid;
1830
Benny Halevy13c65ce2009-08-14 17:19:25 +03001831 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001832 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001833
1834 /*
1835 * Sessionid + seqid + slotid + max slotid + cache_this
1836 */
1837 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1838 "max_slotid=%d cache_this=%d\n",
1839 __func__,
1840 ((u32 *)session->sess_id.data)[0],
1841 ((u32 *)session->sess_id.data)[1],
1842 ((u32 *)session->sess_id.data)[2],
1843 ((u32 *)session->sess_id.data)[3],
1844 slot->seq_nr, args->sa_slotid,
1845 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001846 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001847 *p++ = cpu_to_be32(slot->seq_nr);
1848 *p++ = cpu_to_be32(args->sa_slotid);
1849 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001850 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001851 hdr->nops++;
1852 hdr->replen += decode_sequence_maxsz;
1853#endif /* CONFIG_NFS_V4_1 */
1854}
1855
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001856#ifdef CONFIG_NFS_V4_1
1857static void
1858encode_getdeviceinfo(struct xdr_stream *xdr,
1859 const struct nfs4_getdeviceinfo_args *args,
1860 struct compound_hdr *hdr)
1861{
1862 __be32 *p;
1863
1864 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1865 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1866 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1867 NFS4_DEVICEID4_SIZE);
1868 *p++ = cpu_to_be32(args->pdev->layout_type);
1869 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1870 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1871 hdr->nops++;
1872 hdr->replen += decode_getdeviceinfo_maxsz;
1873}
1874
1875static void
1876encode_layoutget(struct xdr_stream *xdr,
1877 const struct nfs4_layoutget_args *args,
1878 struct compound_hdr *hdr)
1879{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001880 __be32 *p;
1881
1882 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1883 *p++ = cpu_to_be32(OP_LAYOUTGET);
1884 *p++ = cpu_to_be32(0); /* Signal layout available */
1885 *p++ = cpu_to_be32(args->type);
1886 *p++ = cpu_to_be32(args->range.iomode);
1887 p = xdr_encode_hyper(p, args->range.offset);
1888 p = xdr_encode_hyper(p, args->range.length);
1889 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00001890 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001891 *p = cpu_to_be32(args->maxcount);
1892
1893 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1894 __func__,
1895 args->type,
1896 args->range.iomode,
1897 (unsigned long)args->range.offset,
1898 (unsigned long)args->range.length,
1899 args->maxcount);
1900 hdr->nops++;
1901 hdr->replen += decode_layoutget_maxsz;
1902}
Andy Adamson863a3c62011-03-23 13:27:54 +00001903
1904static int
1905encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001906 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001907 const struct nfs4_layoutcommit_args *args,
1908 struct compound_hdr *hdr)
1909{
1910 __be32 *p;
1911
1912 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1913 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1914
Benny Halevyac7db722011-05-22 19:53:48 +03001915 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
Andy Adamson863a3c62011-03-23 13:27:54 +00001916 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1917 /* Only whole file layouts */
1918 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001919 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Andy Adamson863a3c62011-03-23 13:27:54 +00001920 *p++ = cpu_to_be32(0); /* reclaim */
1921 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1922 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1923 p = xdr_encode_hyper(p, args->lastbytewritten);
1924 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1925 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001926
1927 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1928 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1929 NFS_I(inode)->layout, xdr, args);
1930 else {
1931 p = reserve_space(xdr, 4);
1932 *p = cpu_to_be32(0); /* no layout-type payload */
1933 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001934
1935 hdr->nops++;
1936 hdr->replen += decode_layoutcommit_maxsz;
1937 return 0;
1938}
Benny Halevycbe82602011-05-22 19:52:37 +03001939
1940static void
1941encode_layoutreturn(struct xdr_stream *xdr,
1942 const struct nfs4_layoutreturn_args *args,
1943 struct compound_hdr *hdr)
1944{
1945 __be32 *p;
1946
1947 p = reserve_space(xdr, 20);
1948 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
1949 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1950 *p++ = cpu_to_be32(args->layout_type);
1951 *p++ = cpu_to_be32(IOMODE_ANY);
1952 *p = cpu_to_be32(RETURN_FILE);
1953 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
1954 p = xdr_encode_hyper(p, 0);
1955 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1956 spin_lock(&args->inode->i_lock);
1957 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1958 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001959 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1960 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1961 NFS_I(args->inode)->layout, xdr, args);
1962 } else {
1963 p = reserve_space(xdr, 4);
1964 *p = cpu_to_be32(0);
1965 }
Benny Halevycbe82602011-05-22 19:52:37 +03001966 hdr->nops++;
1967 hdr->replen += decode_layoutreturn_maxsz;
1968}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001969
1970static int
1971encode_secinfo_no_name(struct xdr_stream *xdr,
1972 const struct nfs41_secinfo_no_name_args *args,
1973 struct compound_hdr *hdr)
1974{
1975 __be32 *p;
1976 p = reserve_space(xdr, 8);
1977 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
1978 *p++ = cpu_to_be32(args->style);
1979 hdr->nops++;
1980 hdr->replen += decode_secinfo_no_name_maxsz;
1981 return 0;
1982}
Bryan Schumaker7d974792011-06-02 14:59:08 -04001983
1984static void encode_test_stateid(struct xdr_stream *xdr,
1985 struct nfs41_test_stateid_args *args,
1986 struct compound_hdr *hdr)
1987{
1988 __be32 *p;
1989
1990 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
1991 *p++ = cpu_to_be32(OP_TEST_STATEID);
1992 *p++ = cpu_to_be32(1);
1993 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
1994 hdr->nops++;
1995 hdr->replen += decode_test_stateid_maxsz;
1996}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001997
1998static void encode_free_stateid(struct xdr_stream *xdr,
1999 struct nfs41_free_stateid_args *args,
2000 struct compound_hdr *hdr)
2001{
2002 __be32 *p;
2003 p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
2004 *p++ = cpu_to_be32(OP_FREE_STATEID);
2005 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2006 hdr->nops++;
2007 hdr->replen += decode_free_stateid_maxsz;
2008}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002009#endif /* CONFIG_NFS_V4_1 */
2010
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011/*
2012 * END OF "GENERIC" ENCODE ROUTINES.
2013 */
2014
Benny Halevy66cc0422009-04-01 09:22:10 -04002015static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2016{
2017#if defined(CONFIG_NFS_V4_1)
2018 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04002019 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002020#endif /* CONFIG_NFS_V4_1 */
2021 return 0;
2022}
2023
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024/*
2025 * Encode an ACCESS request
2026 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002027static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2028 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002031 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033
Chuck Lever9f06c712010-12-14 14:59:18 +00002034 encode_compound_hdr(xdr, req, &hdr);
2035 encode_sequence(xdr, &args->seq_args, &hdr);
2036 encode_putfh(xdr, args->fh, &hdr);
2037 encode_access(xdr, args->access, &hdr);
2038 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002039 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040}
2041
2042/*
2043 * Encode LOOKUP request
2044 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002045static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2046 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002049 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051
Chuck Lever9f06c712010-12-14 14:59:18 +00002052 encode_compound_hdr(xdr, req, &hdr);
2053 encode_sequence(xdr, &args->seq_args, &hdr);
2054 encode_putfh(xdr, args->dir_fh, &hdr);
2055 encode_lookup(xdr, args->name, &hdr);
2056 encode_getfh(xdr, &hdr);
2057 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002058 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059}
2060
2061/*
2062 * Encode LOOKUP_ROOT request
2063 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002064static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2065 struct xdr_stream *xdr,
2066 const struct nfs4_lookup_root_arg *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_putrootfh(xdr, &hdr);
2075 encode_getfh(xdr, &hdr);
2076 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002077 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078}
2079
2080/*
2081 * Encode REMOVE request
2082 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002083static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2084 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002087 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089
Chuck Lever9f06c712010-12-14 14:59:18 +00002090 encode_compound_hdr(xdr, req, &hdr);
2091 encode_sequence(xdr, &args->seq_args, &hdr);
2092 encode_putfh(xdr, args->fh, &hdr);
2093 encode_remove(xdr, &args->name, &hdr);
2094 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002095 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096}
2097
2098/*
2099 * Encode RENAME request
2100 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002101static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2102 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002105 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
Chuck Lever9f06c712010-12-14 14:59:18 +00002108 encode_compound_hdr(xdr, req, &hdr);
2109 encode_sequence(xdr, &args->seq_args, &hdr);
2110 encode_putfh(xdr, args->old_dir, &hdr);
2111 encode_savefh(xdr, &hdr);
2112 encode_putfh(xdr, args->new_dir, &hdr);
2113 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2114 encode_getfattr(xdr, args->bitmask, &hdr);
2115 encode_restorefh(xdr, &hdr);
2116 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002117 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118}
2119
2120/*
2121 * Encode LINK request
2122 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002123static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2124 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002127 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
Chuck Lever9f06c712010-12-14 14:59:18 +00002130 encode_compound_hdr(xdr, req, &hdr);
2131 encode_sequence(xdr, &args->seq_args, &hdr);
2132 encode_putfh(xdr, args->fh, &hdr);
2133 encode_savefh(xdr, &hdr);
2134 encode_putfh(xdr, args->dir_fh, &hdr);
2135 encode_link(xdr, args->name, &hdr);
2136 encode_getfattr(xdr, args->bitmask, &hdr);
2137 encode_restorefh(xdr, &hdr);
2138 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002139 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140}
2141
2142/*
2143 * Encode CREATE request
2144 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002145static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2146 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002149 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151
Chuck Lever9f06c712010-12-14 14:59:18 +00002152 encode_compound_hdr(xdr, req, &hdr);
2153 encode_sequence(xdr, &args->seq_args, &hdr);
2154 encode_putfh(xdr, args->dir_fh, &hdr);
2155 encode_savefh(xdr, &hdr);
2156 encode_create(xdr, args, &hdr);
2157 encode_getfh(xdr, &hdr);
2158 encode_getfattr(xdr, args->bitmask, &hdr);
2159 encode_restorefh(xdr, &hdr);
2160 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002161 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162}
2163
2164/*
2165 * Encode SYMLINK request
2166 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002167static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2168 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
Chuck Lever9f06c712010-12-14 14:59:18 +00002170 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171}
2172
2173/*
2174 * Encode GETATTR request
2175 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002176static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2177 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002180 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
Chuck Lever9f06c712010-12-14 14:59:18 +00002183 encode_compound_hdr(xdr, req, &hdr);
2184 encode_sequence(xdr, &args->seq_args, &hdr);
2185 encode_putfh(xdr, args->fh, &hdr);
2186 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002187 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188}
2189
2190/*
2191 * Encode a CLOSE request
2192 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002193static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2194 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195{
Andy Adamson05d564f2008-12-23 16:06:15 -05002196 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002197 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002198 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199
Chuck Lever9f06c712010-12-14 14:59:18 +00002200 encode_compound_hdr(xdr, req, &hdr);
2201 encode_sequence(xdr, &args->seq_args, &hdr);
2202 encode_putfh(xdr, args->fh, &hdr);
2203 encode_close(xdr, args, &hdr);
2204 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002205 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206}
2207
2208/*
2209 * Encode an OPEN request
2210 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002211static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2212 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002215 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217
Chuck Lever9f06c712010-12-14 14:59:18 +00002218 encode_compound_hdr(xdr, req, &hdr);
2219 encode_sequence(xdr, &args->seq_args, &hdr);
2220 encode_putfh(xdr, args->fh, &hdr);
2221 encode_savefh(xdr, &hdr);
2222 encode_open(xdr, args, &hdr);
2223 encode_getfh(xdr, &hdr);
2224 encode_getfattr(xdr, args->bitmask, &hdr);
2225 encode_restorefh(xdr, &hdr);
2226 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002227 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228}
2229
2230/*
2231 * Encode an OPEN_CONFIRM request
2232 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002233static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2234 struct xdr_stream *xdr,
2235 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002238 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
Chuck Lever9f06c712010-12-14 14:59:18 +00002241 encode_compound_hdr(xdr, req, &hdr);
2242 encode_putfh(xdr, args->fh, &hdr);
2243 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002244 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245}
2246
2247/*
2248 * Encode an OPEN request with no attributes.
2249 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002250static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2251 struct xdr_stream *xdr,
2252 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002255 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257
Chuck Lever9f06c712010-12-14 14:59:18 +00002258 encode_compound_hdr(xdr, req, &hdr);
2259 encode_sequence(xdr, &args->seq_args, &hdr);
2260 encode_putfh(xdr, args->fh, &hdr);
2261 encode_open(xdr, args, &hdr);
2262 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002263 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264}
2265
2266/*
2267 * Encode an OPEN_DOWNGRADE request
2268 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002269static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2270 struct xdr_stream *xdr,
2271 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002274 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
Chuck Lever9f06c712010-12-14 14:59:18 +00002277 encode_compound_hdr(xdr, req, &hdr);
2278 encode_sequence(xdr, &args->seq_args, &hdr);
2279 encode_putfh(xdr, args->fh, &hdr);
2280 encode_open_downgrade(xdr, args, &hdr);
2281 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002282 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283}
2284
2285/*
2286 * Encode a LOCK request
2287 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002288static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2289 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002292 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
Chuck Lever9f06c712010-12-14 14:59:18 +00002295 encode_compound_hdr(xdr, req, &hdr);
2296 encode_sequence(xdr, &args->seq_args, &hdr);
2297 encode_putfh(xdr, args->fh, &hdr);
2298 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002299 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300}
2301
2302/*
2303 * Encode a LOCKT request
2304 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002305static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2306 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002309 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
Chuck Lever9f06c712010-12-14 14:59:18 +00002312 encode_compound_hdr(xdr, req, &hdr);
2313 encode_sequence(xdr, &args->seq_args, &hdr);
2314 encode_putfh(xdr, args->fh, &hdr);
2315 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002316 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317}
2318
2319/*
2320 * Encode a LOCKU request
2321 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002322static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2323 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002326 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
Chuck Lever9f06c712010-12-14 14:59:18 +00002329 encode_compound_hdr(xdr, req, &hdr);
2330 encode_sequence(xdr, &args->seq_args, &hdr);
2331 encode_putfh(xdr, args->fh, &hdr);
2332 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002333 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334}
2335
Chuck Lever9f06c712010-12-14 14:59:18 +00002336static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2337 struct xdr_stream *xdr,
2338 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002339{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002340 struct compound_hdr hdr = {
2341 .minorversion = 0,
2342 };
2343
Chuck Lever9f06c712010-12-14 14:59:18 +00002344 encode_compound_hdr(xdr, req, &hdr);
2345 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002346 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002347}
2348
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349/*
2350 * Encode a READLINK request
2351 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002352static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2353 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002356 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358
Chuck Lever9f06c712010-12-14 14:59:18 +00002359 encode_compound_hdr(xdr, req, &hdr);
2360 encode_sequence(xdr, &args->seq_args, &hdr);
2361 encode_putfh(xdr, args->fh, &hdr);
2362 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002363
Benny Halevy28f56692009-04-01 09:22:09 -04002364 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002365 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002366 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367}
2368
2369/*
2370 * Encode a READDIR request
2371 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002372static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2373 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002376 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378
Chuck Lever9f06c712010-12-14 14:59:18 +00002379 encode_compound_hdr(xdr, req, &hdr);
2380 encode_sequence(xdr, &args->seq_args, &hdr);
2381 encode_putfh(xdr, args->fh, &hdr);
2382 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002383
Benny Halevy28f56692009-04-01 09:22:09 -04002384 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002385 args->pgbase, args->count);
2386 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002387 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002388 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002389 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390}
2391
2392/*
2393 * Encode a READ request
2394 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002395static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2396 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002399 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
Chuck Lever9f06c712010-12-14 14:59:18 +00002402 encode_compound_hdr(xdr, req, &hdr);
2403 encode_sequence(xdr, &args->seq_args, &hdr);
2404 encode_putfh(xdr, args->fh, &hdr);
2405 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
Benny Halevy28f56692009-04-01 09:22:09 -04002407 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002409 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002410 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411}
2412
2413/*
2414 * Encode an SETATTR request
2415 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002416static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2417 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418{
Andy Adamson05d564f2008-12-23 16:06:15 -05002419 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002420 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002421 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422
Chuck Lever9f06c712010-12-14 14:59:18 +00002423 encode_compound_hdr(xdr, req, &hdr);
2424 encode_sequence(xdr, &args->seq_args, &hdr);
2425 encode_putfh(xdr, args->fh, &hdr);
2426 encode_setattr(xdr, args, args->server, &hdr);
2427 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002428 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429}
2430
2431/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002432 * Encode a GETACL request
2433 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002434static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2435 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002436{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002437 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002438 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002439 };
Benny Halevy28f56692009-04-01 09:22:09 -04002440 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002441
Chuck Lever9f06c712010-12-14 14:59:18 +00002442 encode_compound_hdr(xdr, req, &hdr);
2443 encode_sequence(xdr, &args->seq_args, &hdr);
2444 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002445 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002446 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002447
Benny Halevy28f56692009-04-01 09:22:09 -04002448 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002449 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002450 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002451}
2452
2453/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 * Encode a WRITE request
2455 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002456static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2457 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002460 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462
Chuck Lever9f06c712010-12-14 14:59:18 +00002463 encode_compound_hdr(xdr, req, &hdr);
2464 encode_sequence(xdr, &args->seq_args, &hdr);
2465 encode_putfh(xdr, args->fh, &hdr);
2466 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002467 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002468 if (args->bitmask)
2469 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002470 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471}
2472
2473/*
2474 * a COMMIT request
2475 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002476static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2477 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002480 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482
Chuck Lever9f06c712010-12-14 14:59:18 +00002483 encode_compound_hdr(xdr, req, &hdr);
2484 encode_sequence(xdr, &args->seq_args, &hdr);
2485 encode_putfh(xdr, args->fh, &hdr);
2486 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002487 if (args->bitmask)
2488 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002489 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490}
2491
2492/*
2493 * FSINFO request
2494 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002495static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2496 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002499 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501
Chuck Lever9f06c712010-12-14 14:59:18 +00002502 encode_compound_hdr(xdr, req, &hdr);
2503 encode_sequence(xdr, &args->seq_args, &hdr);
2504 encode_putfh(xdr, args->fh, &hdr);
2505 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002506 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507}
2508
2509/*
2510 * a PATHCONF request
2511 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002512static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2513 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002516 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
Chuck Lever9f06c712010-12-14 14:59:18 +00002519 encode_compound_hdr(xdr, req, &hdr);
2520 encode_sequence(xdr, &args->seq_args, &hdr);
2521 encode_putfh(xdr, args->fh, &hdr);
2522 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002523 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002524 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525}
2526
2527/*
2528 * a STATFS request
2529 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002530static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2531 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002534 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536
Chuck Lever9f06c712010-12-14 14:59:18 +00002537 encode_compound_hdr(xdr, req, &hdr);
2538 encode_sequence(xdr, &args->seq_args, &hdr);
2539 encode_putfh(xdr, args->fh, &hdr);
2540 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002541 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002542 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543}
2544
2545/*
2546 * GETATTR_BITMAP request
2547 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002548static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2549 struct xdr_stream *xdr,
2550 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002553 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555
Chuck Lever9f06c712010-12-14 14:59:18 +00002556 encode_compound_hdr(xdr, req, &hdr);
2557 encode_sequence(xdr, &args->seq_args, &hdr);
2558 encode_putfh(xdr, args->fhandle, &hdr);
2559 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002560 FATTR4_WORD0_LINK_SUPPORT|
2561 FATTR4_WORD0_SYMLINK_SUPPORT|
2562 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002563 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564}
2565
2566/*
2567 * a RENEW request
2568 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002569static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2570 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002573 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 };
2575
Chuck Lever9f06c712010-12-14 14:59:18 +00002576 encode_compound_hdr(xdr, req, &hdr);
2577 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002578 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579}
2580
2581/*
2582 * a SETCLIENTID request
2583 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002584static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2585 struct xdr_stream *xdr,
2586 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002589 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 };
2591
Chuck Lever9f06c712010-12-14 14:59:18 +00002592 encode_compound_hdr(xdr, req, &hdr);
2593 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002594 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595}
2596
2597/*
2598 * a SETCLIENTID_CONFIRM request
2599 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002600static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2601 struct xdr_stream *xdr,
2602 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002605 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 };
2607 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608
Chuck Lever9f06c712010-12-14 14:59:18 +00002609 encode_compound_hdr(xdr, req, &hdr);
2610 encode_setclientid_confirm(xdr, arg, &hdr);
2611 encode_putrootfh(xdr, &hdr);
2612 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002613 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614}
2615
2616/*
2617 * DELEGRETURN request
2618 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002619static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2620 struct xdr_stream *xdr,
2621 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002624 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
Chuck Lever9f06c712010-12-14 14:59:18 +00002627 encode_compound_hdr(xdr, req, &hdr);
2628 encode_sequence(xdr, &args->seq_args, &hdr);
2629 encode_putfh(xdr, args->fhandle, &hdr);
2630 encode_delegreturn(xdr, args->stateid, &hdr);
2631 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002632 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633}
2634
2635/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002636 * Encode FS_LOCATIONS request
2637 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002638static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2639 struct xdr_stream *xdr,
2640 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002641{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002642 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002643 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002644 };
Benny Halevy28f56692009-04-01 09:22:09 -04002645 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002646
Chuck Lever9f06c712010-12-14 14:59:18 +00002647 encode_compound_hdr(xdr, req, &hdr);
2648 encode_sequence(xdr, &args->seq_args, &hdr);
2649 encode_putfh(xdr, args->dir_fh, &hdr);
2650 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002651 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002652 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002653
Benny Halevy28f56692009-04-01 09:22:09 -04002654 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002655 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002656 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002657}
2658
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002659/*
2660 * Encode SECINFO request
2661 */
2662static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2663 struct xdr_stream *xdr,
2664 struct nfs4_secinfo_arg *args)
2665{
2666 struct compound_hdr hdr = {
2667 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2668 };
2669
2670 encode_compound_hdr(xdr, req, &hdr);
2671 encode_sequence(xdr, &args->seq_args, &hdr);
2672 encode_putfh(xdr, args->dir_fh, &hdr);
2673 encode_secinfo(xdr, args->name, &hdr);
2674 encode_nops(&hdr);
2675}
2676
Benny Halevy99fe60d2009-04-01 09:22:29 -04002677#if defined(CONFIG_NFS_V4_1)
2678/*
2679 * EXCHANGE_ID request
2680 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002681static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2682 struct xdr_stream *xdr,
2683 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002684{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002685 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002686 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002687 };
2688
Chuck Lever9f06c712010-12-14 14:59:18 +00002689 encode_compound_hdr(xdr, req, &hdr);
2690 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002691 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002692}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002693
2694/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002695 * a CREATE_SESSION request
2696 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002697static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2698 struct xdr_stream *xdr,
2699 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002700{
Andy Adamsonfc931582009-04-01 09:22:31 -04002701 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002702 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002703 };
2704
Chuck Lever9f06c712010-12-14 14:59:18 +00002705 encode_compound_hdr(xdr, req, &hdr);
2706 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002707 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002708}
2709
2710/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002711 * a DESTROY_SESSION request
2712 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002713static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2714 struct xdr_stream *xdr,
2715 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002716{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002717 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002718 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002719 };
2720
Chuck Lever9f06c712010-12-14 14:59:18 +00002721 encode_compound_hdr(xdr, req, &hdr);
2722 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002723 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002724}
2725
2726/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002727 * a SEQUENCE request
2728 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002729static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2730 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002731{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002732 struct compound_hdr hdr = {
2733 .minorversion = nfs4_xdr_minorversion(args),
2734 };
2735
Chuck Lever9f06c712010-12-14 14:59:18 +00002736 encode_compound_hdr(xdr, req, &hdr);
2737 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002738 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002739}
2740
2741/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002742 * a GET_LEASE_TIME request
2743 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002744static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2745 struct xdr_stream *xdr,
2746 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002747{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002748 struct compound_hdr hdr = {
2749 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2750 };
2751 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2752
Chuck Lever9f06c712010-12-14 14:59:18 +00002753 encode_compound_hdr(xdr, req, &hdr);
2754 encode_sequence(xdr, &args->la_seq_args, &hdr);
2755 encode_putrootfh(xdr, &hdr);
2756 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002757 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002758}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002759
2760/*
2761 * a RECLAIM_COMPLETE request
2762 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002763static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2764 struct xdr_stream *xdr,
2765 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002766{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002767 struct compound_hdr hdr = {
2768 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2769 };
2770
Chuck Lever9f06c712010-12-14 14:59:18 +00002771 encode_compound_hdr(xdr, req, &hdr);
2772 encode_sequence(xdr, &args->seq_args, &hdr);
2773 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002774 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002775}
2776
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002777/*
2778 * Encode GETDEVICEINFO request
2779 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002780static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2781 struct xdr_stream *xdr,
2782 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002783{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002784 struct compound_hdr hdr = {
2785 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2786 };
2787
Chuck Lever9f06c712010-12-14 14:59:18 +00002788 encode_compound_hdr(xdr, req, &hdr);
2789 encode_sequence(xdr, &args->seq_args, &hdr);
2790 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002791
2792 /* set up reply kvec. Subtract notification bitmap max size (2)
2793 * so that notification bitmap is put in xdr_buf tail */
2794 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2795 args->pdev->pages, args->pdev->pgbase,
2796 args->pdev->pglen);
2797
2798 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002799}
2800
2801/*
2802 * Encode LAYOUTGET request
2803 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002804static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2805 struct xdr_stream *xdr,
2806 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002807{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002808 struct compound_hdr hdr = {
2809 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2810 };
2811
Chuck Lever9f06c712010-12-14 14:59:18 +00002812 encode_compound_hdr(xdr, req, &hdr);
2813 encode_sequence(xdr, &args->seq_args, &hdr);
2814 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2815 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002816
2817 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2818 args->layout.pages, 0, args->layout.pglen);
2819
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002820 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002821}
Andy Adamson863a3c62011-03-23 13:27:54 +00002822
2823/*
2824 * Encode LAYOUTCOMMIT request
2825 */
Benny Halevycbe82602011-05-22 19:52:37 +03002826static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2827 struct xdr_stream *xdr,
2828 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002829{
Benny Halevyac7db722011-05-22 19:53:48 +03002830 struct nfs4_layoutcommit_data *data =
2831 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002832 struct compound_hdr hdr = {
2833 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2834 };
2835
2836 encode_compound_hdr(xdr, req, &hdr);
2837 encode_sequence(xdr, &args->seq_args, &hdr);
2838 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002839 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002840 encode_getfattr(xdr, args->bitmask, &hdr);
2841 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002842}
2843
2844/*
2845 * Encode LAYOUTRETURN request
2846 */
2847static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2848 struct xdr_stream *xdr,
2849 struct nfs4_layoutreturn_args *args)
2850{
2851 struct compound_hdr hdr = {
2852 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2853 };
2854
2855 encode_compound_hdr(xdr, req, &hdr);
2856 encode_sequence(xdr, &args->seq_args, &hdr);
2857 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2858 encode_layoutreturn(xdr, args, &hdr);
2859 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002860}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002861
2862/*
2863 * Encode SECINFO_NO_NAME request
2864 */
2865static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2866 struct xdr_stream *xdr,
2867 struct nfs41_secinfo_no_name_args *args)
2868{
2869 struct compound_hdr hdr = {
2870 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2871 };
2872
2873 encode_compound_hdr(xdr, req, &hdr);
2874 encode_sequence(xdr, &args->seq_args, &hdr);
2875 encode_putrootfh(xdr, &hdr);
2876 encode_secinfo_no_name(xdr, args, &hdr);
2877 encode_nops(&hdr);
2878 return 0;
2879}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002880
2881/*
2882 * Encode TEST_STATEID request
2883 */
2884static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2885 struct xdr_stream *xdr,
2886 struct nfs41_test_stateid_args *args)
2887{
2888 struct compound_hdr hdr = {
2889 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2890 };
2891
2892 encode_compound_hdr(xdr, req, &hdr);
2893 encode_sequence(xdr, &args->seq_args, &hdr);
2894 encode_test_stateid(xdr, args, &hdr);
2895 encode_nops(&hdr);
2896}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002897
2898/*
2899 * Encode FREE_STATEID request
2900 */
2901static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2902 struct xdr_stream *xdr,
2903 struct nfs41_free_stateid_args *args)
2904{
2905 struct compound_hdr hdr = {
2906 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2907 };
2908
2909 encode_compound_hdr(xdr, req, &hdr);
2910 encode_sequence(xdr, &args->seq_args, &hdr);
2911 encode_free_stateid(xdr, args, &hdr);
2912 encode_nops(&hdr);
2913}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002914#endif /* CONFIG_NFS_V4_1 */
2915
Benny Halevy686841b2009-08-14 17:19:48 +03002916static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2917{
2918 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2919 "Remaining buffer length is %tu words.\n",
2920 func, xdr->end - xdr->p);
2921}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922
Trond Myklebust683b57b2006-06-09 09:34:22 -04002923static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924{
Al Viro8687b632006-10-19 23:28:48 -07002925 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926
Benny Halevyc0eae662009-08-14 17:20:14 +03002927 p = xdr_inline_decode(xdr, 4);
2928 if (unlikely(!p))
2929 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002930 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002931 p = xdr_inline_decode(xdr, *len);
2932 if (unlikely(!p))
2933 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 *string = (char *)p;
2935 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002936out_overflow:
2937 print_overflow_msg(__func__, xdr);
2938 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939}
2940
2941static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2942{
Al Viro8687b632006-10-19 23:28:48 -07002943 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944
Benny Halevyc0eae662009-08-14 17:20:14 +03002945 p = xdr_inline_decode(xdr, 8);
2946 if (unlikely(!p))
2947 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002948 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002949 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002950
Benny Halevyc0eae662009-08-14 17:20:14 +03002951 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2952 if (unlikely(!p))
2953 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 hdr->tag = (char *)p;
2955 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002956 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002957 if (unlikely(hdr->nops < 1))
2958 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002960out_overflow:
2961 print_overflow_msg(__func__, xdr);
2962 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963}
2964
2965static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2966{
Al Viro8687b632006-10-19 23:28:48 -07002967 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 uint32_t opnum;
2969 int32_t nfserr;
2970
Benny Halevyc0eae662009-08-14 17:20:14 +03002971 p = xdr_inline_decode(xdr, 8);
2972 if (unlikely(!p))
2973 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002974 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002976 dprintk("nfs: Server returned operation"
2977 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 opnum, expected);
2979 return -EIO;
2980 }
Benny Halevycccddf42009-08-14 17:20:19 +03002981 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002983 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002985out_overflow:
2986 print_overflow_msg(__func__, xdr);
2987 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988}
2989
2990/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002991static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992{
Al Viro8687b632006-10-19 23:28:48 -07002993 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002994 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 char *str;
2996
Benny Halevyc0eae662009-08-14 17:20:14 +03002997 p = xdr_inline_decode(xdr, 12);
2998 if (likely(p))
2999 return decode_opaque_inline(xdr, &strlen, &str);
3000 print_overflow_msg(__func__, xdr);
3001 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002}
3003
3004static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3005{
Al Viro8687b632006-10-19 23:28:48 -07003006 uint32_t bmlen;
3007 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008
Benny Halevyc0eae662009-08-14 17:20:14 +03003009 p = xdr_inline_decode(xdr, 4);
3010 if (unlikely(!p))
3011 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003012 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013
3014 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003015 p = xdr_inline_decode(xdr, (bmlen << 2));
3016 if (unlikely(!p))
3017 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003019 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03003021 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 }
3023 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003024out_overflow:
3025 print_overflow_msg(__func__, xdr);
3026 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027}
3028
Al Viro8687b632006-10-19 23:28:48 -07003029static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030{
Al Viro8687b632006-10-19 23:28:48 -07003031 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032
Benny Halevyc0eae662009-08-14 17:20:14 +03003033 p = xdr_inline_decode(xdr, 4);
3034 if (unlikely(!p))
3035 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003036 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 *savep = xdr->p;
3038 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003039out_overflow:
3040 print_overflow_msg(__func__, xdr);
3041 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042}
3043
3044static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3045{
3046 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003047 int ret;
3048 ret = decode_attr_bitmap(xdr, bitmask);
3049 if (unlikely(ret < 0))
3050 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3052 } else
3053 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03003054 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 return 0;
3056}
3057
3058static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3059{
Al Viro8687b632006-10-19 23:28:48 -07003060 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003061 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062
3063 *type = 0;
3064 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3065 return -EIO;
3066 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003067 p = xdr_inline_decode(xdr, 4);
3068 if (unlikely(!p))
3069 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003070 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003072 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 return -EIO;
3074 }
3075 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003076 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003078 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003079 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003080out_overflow:
3081 print_overflow_msg(__func__, xdr);
3082 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083}
3084
3085static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3086{
Al Viro8687b632006-10-19 23:28:48 -07003087 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003088 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089
3090 *change = 0;
3091 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3092 return -EIO;
3093 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003094 p = xdr_inline_decode(xdr, 8);
3095 if (unlikely(!p))
3096 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003097 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003099 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003101 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003103 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003104out_overflow:
3105 print_overflow_msg(__func__, xdr);
3106 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107}
3108
3109static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3110{
Al Viro8687b632006-10-19 23:28:48 -07003111 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003112 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113
3114 *size = 0;
3115 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3116 return -EIO;
3117 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003118 p = xdr_inline_decode(xdr, 8);
3119 if (unlikely(!p))
3120 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003121 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003123 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003125 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003126 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003127out_overflow:
3128 print_overflow_msg(__func__, xdr);
3129 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130}
3131
3132static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3133{
Al Viro8687b632006-10-19 23:28:48 -07003134 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135
3136 *res = 0;
3137 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3138 return -EIO;
3139 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003140 p = xdr_inline_decode(xdr, 4);
3141 if (unlikely(!p))
3142 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003143 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3145 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003146 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003148out_overflow:
3149 print_overflow_msg(__func__, xdr);
3150 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151}
3152
3153static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3154{
Al Viro8687b632006-10-19 23:28:48 -07003155 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156
3157 *res = 0;
3158 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3159 return -EIO;
3160 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003161 p = xdr_inline_decode(xdr, 4);
3162 if (unlikely(!p))
3163 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003164 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3166 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003167 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003169out_overflow:
3170 print_overflow_msg(__func__, xdr);
3171 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172}
3173
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003174static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175{
Al Viro8687b632006-10-19 23:28:48 -07003176 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003177 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178
3179 fsid->major = 0;
3180 fsid->minor = 0;
3181 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3182 return -EIO;
3183 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003184 p = xdr_inline_decode(xdr, 16);
3185 if (unlikely(!p))
3186 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003187 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003188 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003190 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003192 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 (unsigned long long)fsid->major,
3194 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003195 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003196out_overflow:
3197 print_overflow_msg(__func__, xdr);
3198 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199}
3200
3201static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3202{
Al Viro8687b632006-10-19 23:28:48 -07003203 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204
3205 *res = 60;
3206 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3207 return -EIO;
3208 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003209 p = xdr_inline_decode(xdr, 4);
3210 if (unlikely(!p))
3211 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003212 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3214 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003215 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003217out_overflow:
3218 print_overflow_msg(__func__, xdr);
3219 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220}
3221
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003222static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003223{
3224 __be32 *p;
3225
3226 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3227 return -EIO;
3228 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3229 p = xdr_inline_decode(xdr, 4);
3230 if (unlikely(!p))
3231 goto out_overflow;
3232 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003233 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003234 }
3235 return 0;
3236out_overflow:
3237 print_overflow_msg(__func__, xdr);
3238 return -EIO;
3239}
3240
3241static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3242{
3243 __be32 *p;
3244 int len;
3245
Trond Myklebust7ad07352010-10-23 15:34:20 -04003246 if (fh != NULL)
3247 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003248
3249 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3250 return -EIO;
3251 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3252 p = xdr_inline_decode(xdr, 4);
3253 if (unlikely(!p))
3254 goto out_overflow;
3255 len = be32_to_cpup(p);
3256 if (len > NFS4_FHSIZE)
3257 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003258 p = xdr_inline_decode(xdr, len);
3259 if (unlikely(!p))
3260 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003261 if (fh != NULL) {
3262 memcpy(fh->data, p, len);
3263 fh->size = len;
3264 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003265 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3266 }
3267 return 0;
3268out_overflow:
3269 print_overflow_msg(__func__, xdr);
3270 return -EIO;
3271}
3272
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3274{
Al Viro8687b632006-10-19 23:28:48 -07003275 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276
3277 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3278 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3279 return -EIO;
3280 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003281 p = xdr_inline_decode(xdr, 4);
3282 if (unlikely(!p))
3283 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003284 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3286 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003287 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003289out_overflow:
3290 print_overflow_msg(__func__, xdr);
3291 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292}
3293
3294static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3295{
Al Viro8687b632006-10-19 23:28:48 -07003296 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003297 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298
3299 *fileid = 0;
3300 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3301 return -EIO;
3302 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003303 p = xdr_inline_decode(xdr, 8);
3304 if (unlikely(!p))
3305 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003306 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003308 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003310 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003311 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003312out_overflow:
3313 print_overflow_msg(__func__, xdr);
3314 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315}
3316
Manoj Naik99baf622006-06-09 09:34:24 -04003317static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3318{
Al Viro8687b632006-10-19 23:28:48 -07003319 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003320 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003321
3322 *fileid = 0;
3323 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3324 return -EIO;
3325 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003326 p = xdr_inline_decode(xdr, 8);
3327 if (unlikely(!p))
3328 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003329 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003330 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003331 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003332 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003333 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003334 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003335out_overflow:
3336 print_overflow_msg(__func__, xdr);
3337 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003338}
3339
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3341{
Al Viro8687b632006-10-19 23:28:48 -07003342 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 int status = 0;
3344
3345 *res = 0;
3346 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3347 return -EIO;
3348 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003349 p = xdr_inline_decode(xdr, 8);
3350 if (unlikely(!p))
3351 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003352 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3354 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003355 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003357out_overflow:
3358 print_overflow_msg(__func__, xdr);
3359 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360}
3361
3362static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3363{
Al Viro8687b632006-10-19 23:28:48 -07003364 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 int status = 0;
3366
3367 *res = 0;
3368 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3369 return -EIO;
3370 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003371 p = xdr_inline_decode(xdr, 8);
3372 if (unlikely(!p))
3373 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003374 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3376 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003377 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003379out_overflow:
3380 print_overflow_msg(__func__, xdr);
3381 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382}
3383
3384static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3385{
Al Viro8687b632006-10-19 23:28:48 -07003386 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 int status = 0;
3388
3389 *res = 0;
3390 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3391 return -EIO;
3392 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003393 p = xdr_inline_decode(xdr, 8);
3394 if (unlikely(!p))
3395 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003396 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3398 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003399 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003401out_overflow:
3402 print_overflow_msg(__func__, xdr);
3403 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404}
3405
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003406static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3407{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003408 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003409 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003410 int status = 0;
3411
Benny Halevyc0eae662009-08-14 17:20:14 +03003412 p = xdr_inline_decode(xdr, 4);
3413 if (unlikely(!p))
3414 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003415 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003416 if (n == 0)
3417 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003418 dprintk("path ");
3419 path->ncomponents = 0;
3420 while (path->ncomponents < n) {
3421 struct nfs4_string *component = &path->components[path->ncomponents];
3422 status = decode_opaque_inline(xdr, &component->len, &component->data);
3423 if (unlikely(status != 0))
3424 goto out_eio;
3425 if (path->ncomponents != n)
3426 dprintk("/");
3427 dprintk("%s", component->data);
3428 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3429 path->ncomponents++;
3430 else {
3431 dprintk("cannot parse %d components in path\n", n);
3432 goto out_eio;
3433 }
3434 }
3435out:
3436 dprintk("\n");
3437 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003438root_path:
3439/* a root pathname is sent as a zero component4 */
3440 path->ncomponents = 1;
3441 path->components[0].len=0;
3442 path->components[0].data=NULL;
3443 dprintk("path /\n");
3444 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003445out_eio:
3446 dprintk(" status %d", status);
3447 status = -EIO;
3448 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003449out_overflow:
3450 print_overflow_msg(__func__, xdr);
3451 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003452}
3453
3454static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003455{
3456 int n;
Al Viro8687b632006-10-19 23:28:48 -07003457 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003458 int status = -EIO;
3459
3460 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3461 goto out;
3462 status = 0;
3463 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3464 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003465 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003466 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003467 if (unlikely(status != 0))
3468 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003469 p = xdr_inline_decode(xdr, 4);
3470 if (unlikely(!p))
3471 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003472 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003473 if (n <= 0)
3474 goto out_eio;
3475 res->nlocations = 0;
3476 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003477 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003478 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003479
Benny Halevyc0eae662009-08-14 17:20:14 +03003480 p = xdr_inline_decode(xdr, 4);
3481 if (unlikely(!p))
3482 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003483 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003484
3485 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003486 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003487 while (loc->nservers < m) {
3488 struct nfs4_string *server = &loc->servers[loc->nservers];
3489 status = decode_opaque_inline(xdr, &server->len, &server->data);
3490 if (unlikely(status != 0))
3491 goto out_eio;
3492 dprintk("%s ", server->data);
3493 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3494 loc->nservers++;
3495 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003496 unsigned int i;
3497 dprintk("%s: using first %u of %u servers "
3498 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003499 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003500 NFS4_FS_LOCATION_MAXSERVERS,
3501 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003502 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003503 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003504 char *data;
3505 status = decode_opaque_inline(xdr, &len, &data);
3506 if (unlikely(status != 0))
3507 goto out_eio;
3508 }
3509 }
3510 }
3511 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003512 if (unlikely(status != 0))
3513 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003514 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003515 res->nlocations++;
3516 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003517 if (res->nlocations != 0)
3518 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003519out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003520 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003521 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003522out_overflow:
3523 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003524out_eio:
3525 status = -EIO;
3526 goto out;
3527}
3528
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3530{
Al Viro8687b632006-10-19 23:28:48 -07003531 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 int status = 0;
3533
3534 *res = 0;
3535 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3536 return -EIO;
3537 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003538 p = xdr_inline_decode(xdr, 8);
3539 if (unlikely(!p))
3540 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003541 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3543 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003544 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003546out_overflow:
3547 print_overflow_msg(__func__, xdr);
3548 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549}
3550
3551static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3552{
Al Viro8687b632006-10-19 23:28:48 -07003553 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554 int status = 0;
3555
3556 *maxlink = 1;
3557 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3558 return -EIO;
3559 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003560 p = xdr_inline_decode(xdr, 4);
3561 if (unlikely(!p))
3562 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003563 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3565 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003566 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003568out_overflow:
3569 print_overflow_msg(__func__, xdr);
3570 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571}
3572
3573static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3574{
Al Viro8687b632006-10-19 23:28:48 -07003575 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576 int status = 0;
3577
3578 *maxname = 1024;
3579 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3580 return -EIO;
3581 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003582 p = xdr_inline_decode(xdr, 4);
3583 if (unlikely(!p))
3584 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003585 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3587 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003588 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003590out_overflow:
3591 print_overflow_msg(__func__, xdr);
3592 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593}
3594
3595static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3596{
Al Viro8687b632006-10-19 23:28:48 -07003597 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598 int status = 0;
3599
3600 *res = 1024;
3601 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3602 return -EIO;
3603 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3604 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003605 p = xdr_inline_decode(xdr, 8);
3606 if (unlikely(!p))
3607 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003608 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609 if (maxread > 0x7FFFFFFF)
3610 maxread = 0x7FFFFFFF;
3611 *res = (uint32_t)maxread;
3612 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3613 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003614 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003616out_overflow:
3617 print_overflow_msg(__func__, xdr);
3618 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619}
3620
3621static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3622{
Al Viro8687b632006-10-19 23:28:48 -07003623 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 int status = 0;
3625
3626 *res = 1024;
3627 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3628 return -EIO;
3629 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3630 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003631 p = xdr_inline_decode(xdr, 8);
3632 if (unlikely(!p))
3633 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003634 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 if (maxwrite > 0x7FFFFFFF)
3636 maxwrite = 0x7FFFFFFF;
3637 *res = (uint32_t)maxwrite;
3638 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3639 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003640 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003642out_overflow:
3643 print_overflow_msg(__func__, xdr);
3644 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645}
3646
Trond Myklebustbca79472009-03-11 14:10:26 -04003647static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648{
Trond Myklebustbca79472009-03-11 14:10:26 -04003649 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003650 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003651 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652
3653 *mode = 0;
3654 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3655 return -EIO;
3656 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003657 p = xdr_inline_decode(xdr, 4);
3658 if (unlikely(!p))
3659 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003660 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003661 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003663 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003664 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003665 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003666 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003667out_overflow:
3668 print_overflow_msg(__func__, xdr);
3669 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670}
3671
3672static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3673{
Al Viro8687b632006-10-19 23:28:48 -07003674 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003675 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676
3677 *nlink = 1;
3678 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3679 return -EIO;
3680 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003681 p = xdr_inline_decode(xdr, 4);
3682 if (unlikely(!p))
3683 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003684 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003686 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003688 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003689 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003690out_overflow:
3691 print_overflow_msg(__func__, xdr);
3692 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693}
3694
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003695static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003696 const struct nfs_server *server, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697{
Al Viro8687b632006-10-19 23:28:48 -07003698 uint32_t len;
3699 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003700 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701
3702 *uid = -2;
3703 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3704 return -EIO;
3705 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003706 p = xdr_inline_decode(xdr, 4);
3707 if (unlikely(!p))
3708 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003709 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003710 p = xdr_inline_decode(xdr, len);
3711 if (unlikely(!p))
3712 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003713 if (!may_sleep) {
3714 /* do nothing */
3715 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003716 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003717 ret = NFS_ATTR_FATTR_OWNER;
3718 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003720 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003722 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003723 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3725 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003726 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003727 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003728out_overflow:
3729 print_overflow_msg(__func__, xdr);
3730 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731}
3732
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003733static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003734 const struct nfs_server *server, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735{
Al Viro8687b632006-10-19 23:28:48 -07003736 uint32_t len;
3737 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003738 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739
3740 *gid = -2;
3741 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3742 return -EIO;
3743 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003744 p = xdr_inline_decode(xdr, 4);
3745 if (unlikely(!p))
3746 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003747 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003748 p = xdr_inline_decode(xdr, len);
3749 if (unlikely(!p))
3750 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003751 if (!may_sleep) {
3752 /* do nothing */
3753 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003754 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003755 ret = NFS_ATTR_FATTR_GROUP;
3756 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003758 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003760 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003761 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3763 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003764 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003765 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003766out_overflow:
3767 print_overflow_msg(__func__, xdr);
3768 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769}
3770
3771static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3772{
Al Viro8687b632006-10-19 23:28:48 -07003773 uint32_t major = 0, minor = 0;
3774 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003775 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776
3777 *rdev = MKDEV(0,0);
3778 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3779 return -EIO;
3780 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3781 dev_t tmp;
3782
Benny Halevyc0eae662009-08-14 17:20:14 +03003783 p = xdr_inline_decode(xdr, 8);
3784 if (unlikely(!p))
3785 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003786 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003787 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 tmp = MKDEV(major, minor);
3789 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3790 *rdev = tmp;
3791 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003792 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003794 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003795 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003796out_overflow:
3797 print_overflow_msg(__func__, xdr);
3798 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799}
3800
3801static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3802{
Al Viro8687b632006-10-19 23:28:48 -07003803 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 int status = 0;
3805
3806 *res = 0;
3807 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3808 return -EIO;
3809 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003810 p = xdr_inline_decode(xdr, 8);
3811 if (unlikely(!p))
3812 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003813 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3815 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003816 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003818out_overflow:
3819 print_overflow_msg(__func__, xdr);
3820 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821}
3822
3823static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3824{
Al Viro8687b632006-10-19 23:28:48 -07003825 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 int status = 0;
3827
3828 *res = 0;
3829 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3830 return -EIO;
3831 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003832 p = xdr_inline_decode(xdr, 8);
3833 if (unlikely(!p))
3834 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003835 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3837 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003838 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003840out_overflow:
3841 print_overflow_msg(__func__, xdr);
3842 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843}
3844
3845static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3846{
Al Viro8687b632006-10-19 23:28:48 -07003847 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 int status = 0;
3849
3850 *res = 0;
3851 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3852 return -EIO;
3853 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003854 p = xdr_inline_decode(xdr, 8);
3855 if (unlikely(!p))
3856 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003857 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3859 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003860 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003862out_overflow:
3863 print_overflow_msg(__func__, xdr);
3864 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865}
3866
3867static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3868{
Al Viro8687b632006-10-19 23:28:48 -07003869 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003870 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871
3872 *used = 0;
3873 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3874 return -EIO;
3875 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003876 p = xdr_inline_decode(xdr, 8);
3877 if (unlikely(!p))
3878 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003879 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003881 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003883 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003885 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003886out_overflow:
3887 print_overflow_msg(__func__, xdr);
3888 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889}
3890
3891static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3892{
Al Viro8687b632006-10-19 23:28:48 -07003893 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 uint64_t sec;
3895 uint32_t nsec;
3896
Benny Halevyc0eae662009-08-14 17:20:14 +03003897 p = xdr_inline_decode(xdr, 12);
3898 if (unlikely(!p))
3899 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003900 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003901 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 time->tv_sec = (time_t)sec;
3903 time->tv_nsec = (long)nsec;
3904 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003905out_overflow:
3906 print_overflow_msg(__func__, xdr);
3907 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908}
3909
3910static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3911{
3912 int status = 0;
3913
3914 time->tv_sec = 0;
3915 time->tv_nsec = 0;
3916 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3917 return -EIO;
3918 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3919 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003920 if (status == 0)
3921 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3923 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003924 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925 return status;
3926}
3927
3928static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3929{
3930 int status = 0;
3931
3932 time->tv_sec = 0;
3933 time->tv_nsec = 0;
3934 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3935 return -EIO;
3936 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3937 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003938 if (status == 0)
3939 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3941 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003942 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 return status;
3944}
3945
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003946static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3947 struct timespec *time)
3948{
3949 int status = 0;
3950
3951 time->tv_sec = 0;
3952 time->tv_nsec = 0;
3953 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3954 return -EIO;
3955 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3956 status = decode_attr_time(xdr, time);
3957 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3958 }
3959 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3960 (long)time->tv_nsec);
3961 return status;
3962}
3963
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3965{
3966 int status = 0;
3967
3968 time->tv_sec = 0;
3969 time->tv_nsec = 0;
3970 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3971 return -EIO;
3972 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3973 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003974 if (status == 0)
3975 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3977 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003978 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 return status;
3980}
3981
Al Viro8687b632006-10-19 23:28:48 -07003982static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983{
3984 unsigned int attrwords = XDR_QUADLEN(attrlen);
3985 unsigned int nwords = xdr->p - savep;
3986
3987 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003988 dprintk("%s: server returned incorrect attribute length: "
3989 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003990 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991 attrwords << 2,
3992 (attrwords < nwords) ? '<' : '>',
3993 nwords << 2);
3994 return -EIO;
3995 }
3996 return 0;
3997}
3998
3999static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4000{
Al Viro8687b632006-10-19 23:28:48 -07004001 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002
Benny Halevyc0eae662009-08-14 17:20:14 +03004003 p = xdr_inline_decode(xdr, 20);
4004 if (unlikely(!p))
4005 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004006 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004007 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004008 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004010out_overflow:
4011 print_overflow_msg(__func__, xdr);
4012 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013}
4014
4015static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4016{
Al Viro8687b632006-10-19 23:28:48 -07004017 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018 uint32_t supp, acc;
4019 int status;
4020
4021 status = decode_op_hdr(xdr, OP_ACCESS);
4022 if (status)
4023 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004024 p = xdr_inline_decode(xdr, 8);
4025 if (unlikely(!p))
4026 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004027 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004028 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029 access->supported = supp;
4030 access->access = acc;
4031 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004032out_overflow:
4033 print_overflow_msg(__func__, xdr);
4034 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035}
4036
Benny Halevy07d30432009-08-14 17:19:52 +03004037static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038{
Al Viro8687b632006-10-19 23:28:48 -07004039 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004040
4041 p = xdr_inline_decode(xdr, len);
4042 if (likely(p)) {
4043 memcpy(buf, p, len);
4044 return 0;
4045 }
4046 print_overflow_msg(__func__, xdr);
4047 return -EIO;
4048}
4049
4050static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4051{
4052 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053}
4054
4055static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4056{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 int status;
4058
4059 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004060 if (status != -EIO)
4061 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004062 if (!status)
4063 status = decode_stateid(xdr, &res->stateid);
4064 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065}
4066
Benny Halevydb942bb2009-08-14 17:19:56 +03004067static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4068{
4069 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070}
4071
4072static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4073{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074 int status;
4075
4076 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004077 if (!status)
4078 status = decode_verifier(xdr, res->verf->verifier);
4079 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080}
4081
4082static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4083{
Al Viro8687b632006-10-19 23:28:48 -07004084 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 uint32_t bmlen;
4086 int status;
4087
4088 status = decode_op_hdr(xdr, OP_CREATE);
4089 if (status)
4090 return status;
4091 if ((status = decode_change_info(xdr, cinfo)))
4092 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004093 p = xdr_inline_decode(xdr, 4);
4094 if (unlikely(!p))
4095 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004096 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004097 p = xdr_inline_decode(xdr, bmlen << 2);
4098 if (likely(p))
4099 return 0;
4100out_overflow:
4101 print_overflow_msg(__func__, xdr);
4102 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103}
4104
4105static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4106{
Al Viro8687b632006-10-19 23:28:48 -07004107 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004108 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 int status;
4110
4111 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4112 goto xdr_error;
4113 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4114 goto xdr_error;
4115 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4116 goto xdr_error;
4117 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4118 goto xdr_error;
4119 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4120 goto xdr_error;
4121 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4122 goto xdr_error;
4123 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4124 goto xdr_error;
4125 status = verify_attr_len(xdr, savep, attrlen);
4126xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004127 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128 return status;
4129}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004130
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4132{
Al Viro8687b632006-10-19 23:28:48 -07004133 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004134 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004136
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4138 goto xdr_error;
4139 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4140 goto xdr_error;
4141 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4142 goto xdr_error;
4143
4144 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4145 goto xdr_error;
4146 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4147 goto xdr_error;
4148 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4149 goto xdr_error;
4150 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4151 goto xdr_error;
4152 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4153 goto xdr_error;
4154 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4155 goto xdr_error;
4156
4157 status = verify_attr_len(xdr, savep, attrlen);
4158xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004159 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 return status;
4161}
4162
4163static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4164{
Al Viro8687b632006-10-19 23:28:48 -07004165 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004166 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004168
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4170 goto xdr_error;
4171 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4172 goto xdr_error;
4173 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4174 goto xdr_error;
4175
4176 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4177 goto xdr_error;
4178 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4179 goto xdr_error;
4180
4181 status = verify_attr_len(xdr, savep, attrlen);
4182xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004183 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 return status;
4185}
4186
Bryan Schumakerae42c702010-10-21 16:33:17 -04004187static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4188 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004189 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190{
Trond Myklebustbca79472009-03-11 14:10:26 -04004191 int status;
4192 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004193 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004194 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004196 status = decode_attr_type(xdr, bitmap, &type);
4197 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004199 fattr->mode = 0;
4200 if (status != 0) {
4201 fattr->mode |= nfs_type2fmt[type];
4202 fattr->valid |= status;
4203 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004205 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4206 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004208 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004209
4210 status = decode_attr_size(xdr, bitmap, &fattr->size);
4211 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004213 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004214
4215 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4216 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004218 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004219
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004220 err = 0;
4221 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004222 if (status < 0)
4223 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004224 if (err == -NFS4ERR_WRONGSEC)
4225 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004226
4227 status = decode_attr_filehandle(xdr, bitmap, fh);
4228 if (status < 0)
4229 goto xdr_error;
4230
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004231 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4232 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004234 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004235
4236 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04004237 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004238 fattr));
4239 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004240 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004241 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004242
4243 status = decode_attr_mode(xdr, bitmap, &fmode);
4244 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004246 if (status != 0) {
4247 fattr->mode |= fmode;
4248 fattr->valid |= status;
4249 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004250
4251 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4252 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004254 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004255
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004256 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004257 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004259 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004260
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004261 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004262 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004264 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004265
4266 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4267 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004269 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004270
4271 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4272 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004274 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004275
4276 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4277 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004279 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004280
4281 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4282 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004284 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004285
4286 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4287 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004289 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004290
Trond Myklebust28331a42011-04-27 13:47:52 -04004291 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004292 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004293 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004294 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004295
Bryan Schumakerae42c702010-10-21 16:33:17 -04004296xdr_error:
4297 dprintk("%s: xdr returned %d\n", __func__, -status);
4298 return status;
4299}
4300
4301static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4302 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4303{
4304 __be32 *savep;
4305 uint32_t attrlen,
4306 bitmap[2] = {0};
4307 int status;
4308
4309 status = decode_op_hdr(xdr, OP_GETATTR);
4310 if (status < 0)
4311 goto xdr_error;
4312
4313 status = decode_attr_bitmap(xdr, bitmap);
4314 if (status < 0)
4315 goto xdr_error;
4316
4317 status = decode_attr_length(xdr, &attrlen, &savep);
4318 if (status < 0)
4319 goto xdr_error;
4320
4321 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4322 if (status < 0)
4323 goto xdr_error;
4324
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004325 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004327 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 return status;
4329}
4330
Bryan Schumakerae42c702010-10-21 16:33:17 -04004331static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4332 const struct nfs_server *server, int may_sleep)
4333{
4334 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4335}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336
Andy Adamson504913f2010-10-20 00:17:57 -04004337/*
4338 * Decode potentially multiple layout types. Currently we only support
4339 * one layout driver per file system.
4340 */
4341static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4342 uint32_t *layouttype)
4343{
4344 uint32_t *p;
4345 int num;
4346
4347 p = xdr_inline_decode(xdr, 4);
4348 if (unlikely(!p))
4349 goto out_overflow;
4350 num = be32_to_cpup(p);
4351
4352 /* pNFS is not supported by the underlying file system */
4353 if (num == 0) {
4354 *layouttype = 0;
4355 return 0;
4356 }
4357 if (num > 1)
4358 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4359 "per filesystem not supported\n", __func__);
4360
4361 /* Decode and set first layout type, move xdr->p past unused types */
4362 p = xdr_inline_decode(xdr, num * 4);
4363 if (unlikely(!p))
4364 goto out_overflow;
4365 *layouttype = be32_to_cpup(p);
4366 return 0;
4367out_overflow:
4368 print_overflow_msg(__func__, xdr);
4369 return -EIO;
4370}
4371
4372/*
4373 * The type of file system exported.
4374 * Note we must ensure that layouttype is set in any non-error case.
4375 */
4376static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4377 uint32_t *layouttype)
4378{
4379 int status = 0;
4380
4381 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4382 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4383 return -EIO;
4384 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4385 status = decode_first_pnfs_layout_type(xdr, layouttype);
4386 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4387 } else
4388 *layouttype = 0;
4389 return status;
4390}
4391
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4393{
Al Viro8687b632006-10-19 23:28:48 -07004394 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395 uint32_t attrlen, bitmap[2];
4396 int status;
4397
4398 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4399 goto xdr_error;
4400 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4401 goto xdr_error;
4402 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4403 goto xdr_error;
4404
4405 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4406
4407 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4408 goto xdr_error;
4409 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4410 goto xdr_error;
4411 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4412 goto xdr_error;
4413 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4414 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4415 goto xdr_error;
4416 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004417 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4418 if (status != 0)
4419 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004420 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4421 if (status != 0)
4422 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004423
4424 status = verify_attr_len(xdr, savep, attrlen);
4425xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004426 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427 return status;
4428}
4429
4430static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4431{
Al Viro8687b632006-10-19 23:28:48 -07004432 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004433 uint32_t len;
4434 int status;
4435
Trond Myklebust99367812007-07-17 21:52:41 -04004436 /* Zero handle first to allow comparisons */
4437 memset(fh, 0, sizeof(*fh));
4438
Linus Torvalds1da177e2005-04-16 15:20:36 -07004439 status = decode_op_hdr(xdr, OP_GETFH);
4440 if (status)
4441 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442
Benny Halevyc0eae662009-08-14 17:20:14 +03004443 p = xdr_inline_decode(xdr, 4);
4444 if (unlikely(!p))
4445 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004446 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004447 if (len > NFS4_FHSIZE)
4448 return -EIO;
4449 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004450 p = xdr_inline_decode(xdr, len);
4451 if (unlikely(!p))
4452 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004453 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004455out_overflow:
4456 print_overflow_msg(__func__, xdr);
4457 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458}
4459
4460static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4461{
4462 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004463
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 status = decode_op_hdr(xdr, OP_LINK);
4465 if (status)
4466 return status;
4467 return decode_change_info(xdr, cinfo);
4468}
4469
4470/*
4471 * We create the owner, so we know a proper owner.id length is 4.
4472 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004473static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004474{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004475 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004476 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004477 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004479 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004480 if (unlikely(!p))
4481 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004482 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004483 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004484 type = be32_to_cpup(p++); /* 4 byte read */
4485 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004486 fl->fl_start = (loff_t)offset;
4487 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4488 if (length == ~(uint64_t)0)
4489 fl->fl_end = OFFSET_MAX;
4490 fl->fl_type = F_WRLCK;
4491 if (type & 1)
4492 fl->fl_type = F_RDLCK;
4493 fl->fl_pid = 0;
4494 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004495 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4496 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4497 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004498 if (likely(p))
4499 return -NFS4ERR_DENIED;
4500out_overflow:
4501 print_overflow_msg(__func__, xdr);
4502 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503}
4504
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004505static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507 int status;
4508
4509 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004510 if (status == -EIO)
4511 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004512 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004513 status = decode_stateid(xdr, &res->stateid);
4514 if (unlikely(status))
4515 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004517 status = decode_lock_denied(xdr, NULL);
4518 if (res->open_seqid != NULL)
4519 nfs_increment_open_seqid(status, res->open_seqid);
4520 nfs_increment_lock_seqid(status, res->lock_seqid);
4521out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004522 return status;
4523}
4524
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004525static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004526{
4527 int status;
4528 status = decode_op_hdr(xdr, OP_LOCKT);
4529 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004530 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004531 return status;
4532}
4533
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004534static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004535{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004536 int status;
4537
4538 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004539 if (status != -EIO)
4540 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004541 if (status == 0)
4542 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543 return status;
4544}
4545
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004546static int decode_release_lockowner(struct xdr_stream *xdr)
4547{
4548 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4549}
4550
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551static int decode_lookup(struct xdr_stream *xdr)
4552{
4553 return decode_op_hdr(xdr, OP_LOOKUP);
4554}
4555
4556/* This is too sick! */
4557static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4558{
Andy Adamson05d564f2008-12-23 16:06:15 -05004559 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560 uint32_t limit_type, nblocks, blocksize;
4561
Benny Halevyc0eae662009-08-14 17:20:14 +03004562 p = xdr_inline_decode(xdr, 12);
4563 if (unlikely(!p))
4564 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004565 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004567 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004568 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004569 break;
4570 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004571 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004572 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004573 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574 }
4575 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004576out_overflow:
4577 print_overflow_msg(__func__, xdr);
4578 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579}
4580
4581static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4582{
Andy Adamson05d564f2008-12-23 16:06:15 -05004583 __be32 *p;
4584 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004585 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586
Benny Halevyc0eae662009-08-14 17:20:14 +03004587 p = xdr_inline_decode(xdr, 4);
4588 if (unlikely(!p))
4589 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004590 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4592 res->delegation_type = 0;
4593 return 0;
4594 }
Benny Halevy07d30432009-08-14 17:19:52 +03004595 status = decode_stateid(xdr, &res->delegation);
4596 if (unlikely(status))
4597 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004598 p = xdr_inline_decode(xdr, 4);
4599 if (unlikely(!p))
4600 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004601 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004602
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004604 case NFS4_OPEN_DELEGATE_READ:
4605 res->delegation_type = FMODE_READ;
4606 break;
4607 case NFS4_OPEN_DELEGATE_WRITE:
4608 res->delegation_type = FMODE_WRITE|FMODE_READ;
4609 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610 return -EIO;
4611 }
David Howells7539bba2006-08-22 20:06:09 -04004612 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004613out_overflow:
4614 print_overflow_msg(__func__, xdr);
4615 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616}
4617
4618static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4619{
Andy Adamson05d564f2008-12-23 16:06:15 -05004620 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004621 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004622 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623
Andy Adamson05d564f2008-12-23 16:06:15 -05004624 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004625 if (status != -EIO)
4626 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004627 if (!status)
4628 status = decode_stateid(xdr, &res->stateid);
4629 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004630 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631
Andy Adamson05d564f2008-12-23 16:06:15 -05004632 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633
Benny Halevyc0eae662009-08-14 17:20:14 +03004634 p = xdr_inline_decode(xdr, 8);
4635 if (unlikely(!p))
4636 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004637 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004638 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004639 if (bmlen > 10)
4640 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641
Benny Halevyc0eae662009-08-14 17:20:14 +03004642 p = xdr_inline_decode(xdr, bmlen << 2);
4643 if (unlikely(!p))
4644 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004645 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4646 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004647 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004648 for (; i < NFS4_BITMAP_SIZE; i++)
4649 res->attrset[i] = 0;
4650
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651 return decode_delegation(xdr, res);
4652xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004653 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004655out_overflow:
4656 print_overflow_msg(__func__, xdr);
4657 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658}
4659
4660static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4661{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 int status;
4663
Andy Adamson05d564f2008-12-23 16:06:15 -05004664 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004665 if (status != -EIO)
4666 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004667 if (!status)
4668 status = decode_stateid(xdr, &res->stateid);
4669 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670}
4671
4672static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4673{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674 int status;
4675
4676 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004677 if (status != -EIO)
4678 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004679 if (!status)
4680 status = decode_stateid(xdr, &res->stateid);
4681 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682}
4683
4684static int decode_putfh(struct xdr_stream *xdr)
4685{
4686 return decode_op_hdr(xdr, OP_PUTFH);
4687}
4688
4689static int decode_putrootfh(struct xdr_stream *xdr)
4690{
4691 return decode_op_hdr(xdr, OP_PUTROOTFH);
4692}
4693
4694static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4695{
4696 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004697 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698 uint32_t count, eof, recvd, hdrlen;
4699 int status;
4700
4701 status = decode_op_hdr(xdr, OP_READ);
4702 if (status)
4703 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004704 p = xdr_inline_decode(xdr, 8);
4705 if (unlikely(!p))
4706 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004707 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004708 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004709 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004710 recvd = req->rq_rcv_buf.len - hdrlen;
4711 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004712 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004713 "count %u > recvd %u\n", count, recvd);
4714 count = recvd;
4715 eof = 0;
4716 }
4717 xdr_read_pages(xdr, count);
4718 res->eof = eof;
4719 res->count = count;
4720 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004721out_overflow:
4722 print_overflow_msg(__func__, xdr);
4723 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724}
4725
4726static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4727{
4728 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004729 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004730 size_t hdrlen;
4731 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004732 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004733
4734 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004735 if (!status)
4736 status = decode_verifier(xdr, readdir->verifier.data);
4737 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004738 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004739 dprintk("%s: verifier = %08x:%08x\n",
4740 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004741 ((u32 *)readdir->verifier.data)[0],
4742 ((u32 *)readdir->verifier.data)[1]);
4743
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744
Benny Halevydb942bb2009-08-14 17:19:56 +03004745 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746 recvd = rcvbuf->len - hdrlen;
4747 if (pglen > recvd)
4748 pglen = recvd;
4749 xdr_read_pages(xdr, pglen);
4750
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004751
Trond Myklebustac396122010-11-15 20:26:22 -05004752 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004753}
4754
4755static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4756{
4757 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4758 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004759 size_t hdrlen;
4760 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004761 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762 int status;
4763
4764 status = decode_op_hdr(xdr, OP_READLINK);
4765 if (status)
4766 return status;
4767
4768 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004769 p = xdr_inline_decode(xdr, 4);
4770 if (unlikely(!p))
4771 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004772 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004774 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004775 return -ENAMETOOLONG;
4776 }
4777 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4778 recvd = req->rq_rcv_buf.len - hdrlen;
4779 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004780 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004781 "count %u > recvd %u\n", len, recvd);
4782 return -EIO;
4783 }
4784 xdr_read_pages(xdr, len);
4785 /*
4786 * The XDR encode routine has set things up so that
4787 * the link text will be copied directly into the
4788 * buffer. We just have to do overflow-checking,
4789 * and and null-terminate the text (the VFS expects
4790 * null-termination).
4791 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004792 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004794out_overflow:
4795 print_overflow_msg(__func__, xdr);
4796 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797}
4798
4799static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4800{
4801 int status;
4802
4803 status = decode_op_hdr(xdr, OP_REMOVE);
4804 if (status)
4805 goto out;
4806 status = decode_change_info(xdr, cinfo);
4807out:
4808 return status;
4809}
4810
4811static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4812 struct nfs4_change_info *new_cinfo)
4813{
4814 int status;
4815
4816 status = decode_op_hdr(xdr, OP_RENAME);
4817 if (status)
4818 goto out;
4819 if ((status = decode_change_info(xdr, old_cinfo)))
4820 goto out;
4821 status = decode_change_info(xdr, new_cinfo);
4822out:
4823 return status;
4824}
4825
4826static int decode_renew(struct xdr_stream *xdr)
4827{
4828 return decode_op_hdr(xdr, OP_RENEW);
4829}
4830
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004831static int
4832decode_restorefh(struct xdr_stream *xdr)
4833{
4834 return decode_op_hdr(xdr, OP_RESTOREFH);
4835}
4836
J. Bruce Fields029d1052005-06-22 17:16:22 +00004837static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4838 size_t *acl_len)
4839{
Al Viro8687b632006-10-19 23:28:48 -07004840 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004841 uint32_t attrlen,
4842 bitmap[2] = {0};
4843 struct kvec *iov = req->rq_rcv_buf.head;
4844 int status;
4845
4846 *acl_len = 0;
4847 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4848 goto out;
4849 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4850 goto out;
4851 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4852 goto out;
4853
4854 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4855 return -EIO;
4856 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004857 size_t hdrlen;
4858 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004859
4860 /* We ignore &savep and don't do consistency checks on
4861 * the attr length. Let userspace figure it out.... */
4862 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4863 recvd = req->rq_rcv_buf.len - hdrlen;
4864 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004865 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004866 " acl reply: attrlen %u > recvd %u\n",
4867 attrlen, recvd);
4868 return -EINVAL;
4869 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004870 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004871 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004872 } else
4873 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004874
4875out:
4876 return status;
4877}
4878
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879static int
4880decode_savefh(struct xdr_stream *xdr)
4881{
4882 return decode_op_hdr(xdr, OP_SAVEFH);
4883}
4884
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004885static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886{
Al Viro8687b632006-10-19 23:28:48 -07004887 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004888 uint32_t bmlen;
4889 int status;
4890
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891 status = decode_op_hdr(xdr, OP_SETATTR);
4892 if (status)
4893 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004894 p = xdr_inline_decode(xdr, 4);
4895 if (unlikely(!p))
4896 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004897 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004898 p = xdr_inline_decode(xdr, bmlen << 2);
4899 if (likely(p))
4900 return 0;
4901out_overflow:
4902 print_overflow_msg(__func__, xdr);
4903 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904}
4905
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004906static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004907{
Al Viro8687b632006-10-19 23:28:48 -07004908 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004909 uint32_t opnum;
4910 int32_t nfserr;
4911
Benny Halevyc0eae662009-08-14 17:20:14 +03004912 p = xdr_inline_decode(xdr, 8);
4913 if (unlikely(!p))
4914 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004915 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004917 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004918 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919 return -EIO;
4920 }
Benny Halevycccddf42009-08-14 17:20:19 +03004921 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004923 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4924 if (unlikely(!p))
4925 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004926 p = xdr_decode_hyper(p, &res->clientid);
4927 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928 } else if (nfserr == NFSERR_CLID_INUSE) {
4929 uint32_t len;
4930
4931 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004932 p = xdr_inline_decode(xdr, 4);
4933 if (unlikely(!p))
4934 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004935 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004936 p = xdr_inline_decode(xdr, len);
4937 if (unlikely(!p))
4938 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004939
4940 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004941 p = xdr_inline_decode(xdr, 4);
4942 if (unlikely(!p))
4943 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004944 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004945 p = xdr_inline_decode(xdr, len);
4946 if (unlikely(!p))
4947 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948 return -NFSERR_CLID_INUSE;
4949 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004950 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951
4952 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004953out_overflow:
4954 print_overflow_msg(__func__, xdr);
4955 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004956}
4957
4958static int decode_setclientid_confirm(struct xdr_stream *xdr)
4959{
4960 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4961}
4962
4963static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4964{
Al Viro8687b632006-10-19 23:28:48 -07004965 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004966 int status;
4967
4968 status = decode_op_hdr(xdr, OP_WRITE);
4969 if (status)
4970 return status;
4971
Benny Halevyc0eae662009-08-14 17:20:14 +03004972 p = xdr_inline_decode(xdr, 16);
4973 if (unlikely(!p))
4974 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004975 res->count = be32_to_cpup(p++);
4976 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004977 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004978 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004979out_overflow:
4980 print_overflow_msg(__func__, xdr);
4981 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982}
4983
4984static int decode_delegreturn(struct xdr_stream *xdr)
4985{
4986 return decode_op_hdr(xdr, OP_DELEGRETURN);
4987}
4988
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004989static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
4990{
4991 __be32 *p;
4992
4993 p = xdr_inline_decode(xdr, 4);
4994 if (unlikely(!p))
4995 goto out_overflow;
4996 flavor->gss.sec_oid4.len = be32_to_cpup(p);
4997 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
4998 goto out_err;
4999
5000 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5001 if (unlikely(!p))
5002 goto out_overflow;
5003 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5004
5005 p = xdr_inline_decode(xdr, 8);
5006 if (unlikely(!p))
5007 goto out_overflow;
5008 flavor->gss.qop4 = be32_to_cpup(p++);
5009 flavor->gss.service = be32_to_cpup(p);
5010
5011 return 0;
5012
5013out_overflow:
5014 print_overflow_msg(__func__, xdr);
5015 return -EIO;
5016out_err:
5017 return -EINVAL;
5018}
5019
5020static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5021{
5022 struct nfs4_secinfo_flavor *sec_flavor;
5023 int status;
5024 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005025 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005026
5027 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04005028 if (status)
5029 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005030 p = xdr_inline_decode(xdr, 4);
5031 if (unlikely(!p))
5032 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005033
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005034 res->flavors->num_flavors = 0;
5035 num_flavors = be32_to_cpup(p);
5036
5037 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005038 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005039 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005040 break;
5041
5042 p = xdr_inline_decode(xdr, 4);
5043 if (unlikely(!p))
5044 goto out_overflow;
5045 sec_flavor->flavor = be32_to_cpup(p);
5046
5047 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005048 status = decode_secinfo_gss(xdr, sec_flavor);
5049 if (status)
5050 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005051 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005052 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005053 }
5054
Bryan Schumaker613e9012011-04-27 15:28:44 -04005055out:
5056 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005057out_overflow:
5058 print_overflow_msg(__func__, xdr);
5059 return -EIO;
5060}
5061
Benny Halevy99fe60d2009-04-01 09:22:29 -04005062#if defined(CONFIG_NFS_V4_1)
5063static int decode_exchange_id(struct xdr_stream *xdr,
5064 struct nfs41_exchange_id_res *res)
5065{
5066 __be32 *p;
5067 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005068 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005069 int status;
5070 struct nfs_client *clp = res->client;
5071
5072 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5073 if (status)
5074 return status;
5075
Benny Halevyc0eae662009-08-14 17:20:14 +03005076 p = xdr_inline_decode(xdr, 8);
5077 if (unlikely(!p))
5078 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005079 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005080 p = xdr_inline_decode(xdr, 12);
5081 if (unlikely(!p))
5082 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005083 clp->cl_seqid = be32_to_cpup(p++);
5084 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005085
5086 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005087 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005088 if (dummy != SP4_NONE)
5089 return -EIO;
5090
5091 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005092 p = xdr_inline_decode(xdr, 8);
5093 if (unlikely(!p))
5094 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005095
5096 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005097 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5098 if (unlikely(status))
5099 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005100
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005101 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005102 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5103 if (unlikely(status))
5104 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005105
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005106 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5107 return -EIO;
5108
5109 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5110 res->server_scope->server_scope_sz = dummy;
5111
Benny Halevy99fe60d2009-04-01 09:22:29 -04005112 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03005113 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5114 if (unlikely(status))
5115 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005116
5117 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005118out_overflow:
5119 print_overflow_msg(__func__, xdr);
5120 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005121}
Andy Adamsonfc931582009-04-01 09:22:31 -04005122
5123static int decode_chan_attrs(struct xdr_stream *xdr,
5124 struct nfs4_channel_attrs *attrs)
5125{
5126 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005127 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005128
Benny Halevyc0eae662009-08-14 17:20:14 +03005129 p = xdr_inline_decode(xdr, 28);
5130 if (unlikely(!p))
5131 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005132 val = be32_to_cpup(p++); /* headerpadsz */
5133 if (val)
5134 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005135 attrs->max_rqst_sz = be32_to_cpup(p++);
5136 attrs->max_resp_sz = be32_to_cpup(p++);
5137 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5138 attrs->max_ops = be32_to_cpup(p++);
5139 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005140 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005141 if (unlikely(nr_attrs > 1)) {
5142 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
5143 __func__, nr_attrs);
5144 return -EINVAL;
5145 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005146 if (nr_attrs == 1) {
5147 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5148 if (unlikely(!p))
5149 goto out_overflow;
5150 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005151 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005152out_overflow:
5153 print_overflow_msg(__func__, xdr);
5154 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005155}
5156
Benny Halevye78291e2009-08-14 17:20:00 +03005157static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5158{
5159 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005160}
5161
5162static int decode_create_session(struct xdr_stream *xdr,
5163 struct nfs41_create_session_res *res)
5164{
5165 __be32 *p;
5166 int status;
5167 struct nfs_client *clp = res->client;
5168 struct nfs4_session *session = clp->cl_session;
5169
5170 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005171 if (!status)
5172 status = decode_sessionid(xdr, &session->sess_id);
5173 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005174 return status;
5175
Andy Adamsonfc931582009-04-01 09:22:31 -04005176 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005177 p = xdr_inline_decode(xdr, 8);
5178 if (unlikely(!p))
5179 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005180 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005181 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005182
5183 /* Channel attributes */
5184 status = decode_chan_attrs(xdr, &session->fc_attrs);
5185 if (!status)
5186 status = decode_chan_attrs(xdr, &session->bc_attrs);
5187 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005188out_overflow:
5189 print_overflow_msg(__func__, xdr);
5190 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005191}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005192
5193static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5194{
5195 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5196}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005197
5198static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5199{
5200 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5201}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005202#endif /* CONFIG_NFS_V4_1 */
5203
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005204static int decode_sequence(struct xdr_stream *xdr,
5205 struct nfs4_sequence_res *res,
5206 struct rpc_rqst *rqstp)
5207{
5208#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005209 struct nfs4_sessionid id;
5210 u32 dummy;
5211 int status;
5212 __be32 *p;
5213
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005214 if (!res->sr_session)
5215 return 0;
5216
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005217 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005218 if (!status)
5219 status = decode_sessionid(xdr, &id);
5220 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005221 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005222
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005223 /*
5224 * If the server returns different values for sessionID, slotID or
5225 * sequence number, the server is looney tunes.
5226 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005227 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005228
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005229 if (memcmp(id.data, res->sr_session->sess_id.data,
5230 NFS4_MAX_SESSIONID_LEN)) {
5231 dprintk("%s Invalid session id\n", __func__);
5232 goto out_err;
5233 }
Benny Halevye78291e2009-08-14 17:20:00 +03005234
Benny Halevyc0eae662009-08-14 17:20:14 +03005235 p = xdr_inline_decode(xdr, 20);
5236 if (unlikely(!p))
5237 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005238
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005239 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005240 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005241 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005242 dprintk("%s Invalid sequence number\n", __func__);
5243 goto out_err;
5244 }
5245 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005246 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005247 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005248 dprintk("%s Invalid slot id\n", __func__);
5249 goto out_err;
5250 }
5251 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005252 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005253 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005254 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005255 /* result flags */
5256 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005257 status = 0;
5258out_err:
5259 res->sr_status = status;
5260 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005261out_overflow:
5262 print_overflow_msg(__func__, xdr);
5263 status = -EIO;
5264 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005265#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005266 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005267#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005268}
5269
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005270#if defined(CONFIG_NFS_V4_1)
5271
5272static int decode_getdeviceinfo(struct xdr_stream *xdr,
5273 struct pnfs_device *pdev)
5274{
5275 __be32 *p;
5276 uint32_t len, type;
5277 int status;
5278
5279 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5280 if (status) {
5281 if (status == -ETOOSMALL) {
5282 p = xdr_inline_decode(xdr, 4);
5283 if (unlikely(!p))
5284 goto out_overflow;
5285 pdev->mincount = be32_to_cpup(p);
5286 dprintk("%s: Min count too small. mincnt = %u\n",
5287 __func__, pdev->mincount);
5288 }
5289 return status;
5290 }
5291
5292 p = xdr_inline_decode(xdr, 8);
5293 if (unlikely(!p))
5294 goto out_overflow;
5295 type = be32_to_cpup(p++);
5296 if (type != pdev->layout_type) {
5297 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5298 __func__, pdev->layout_type, type);
5299 return -EINVAL;
5300 }
5301 /*
5302 * Get the length of the opaque device_addr4. xdr_read_pages places
5303 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5304 * and places the remaining xdr data in xdr_buf->tail
5305 */
5306 pdev->mincount = be32_to_cpup(p);
5307 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5308
5309 /* Parse notification bitmap, verifying that it is zero. */
5310 p = xdr_inline_decode(xdr, 4);
5311 if (unlikely(!p))
5312 goto out_overflow;
5313 len = be32_to_cpup(p);
5314 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005315 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005316
5317 p = xdr_inline_decode(xdr, 4 * len);
5318 if (unlikely(!p))
5319 goto out_overflow;
5320 for (i = 0; i < len; i++, p++) {
5321 if (be32_to_cpup(p)) {
5322 dprintk("%s: notifications not supported\n",
5323 __func__);
5324 return -EIO;
5325 }
5326 }
5327 }
5328 return 0;
5329out_overflow:
5330 print_overflow_msg(__func__, xdr);
5331 return -EIO;
5332}
5333
5334static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5335 struct nfs4_layoutget_res *res)
5336{
5337 __be32 *p;
5338 int status;
5339 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005340 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5341 struct kvec *iov = rcvbuf->head;
5342 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005343
5344 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5345 if (status)
5346 return status;
5347 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5348 if (unlikely(!p))
5349 goto out_overflow;
5350 res->return_on_close = be32_to_cpup(p++);
5351 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5352 layout_count = be32_to_cpup(p);
5353 if (!layout_count) {
5354 dprintk("%s: server responded with empty layout array\n",
5355 __func__);
5356 return -EINVAL;
5357 }
5358
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005359 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005360 if (unlikely(!p))
5361 goto out_overflow;
5362 p = xdr_decode_hyper(p, &res->range.offset);
5363 p = xdr_decode_hyper(p, &res->range.length);
5364 res->range.iomode = be32_to_cpup(p++);
5365 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005366 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005367
5368 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5369 __func__,
5370 (unsigned long)res->range.offset,
5371 (unsigned long)res->range.length,
5372 res->range.iomode,
5373 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005374 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005375
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005376 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5377 recvd = req->rq_rcv_buf.len - hdrlen;
5378 if (res->layoutp->len > recvd) {
5379 dprintk("NFS: server cheating in layoutget reply: "
5380 "layout len %u > recvd %u\n",
5381 res->layoutp->len, recvd);
5382 return -EINVAL;
5383 }
5384
5385 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005386
5387 if (layout_count > 1) {
5388 /* We only handle a length one array at the moment. Any
5389 * further entries are just ignored. Note that this means
5390 * the client may see a response that is less than the
5391 * minimum it requested.
5392 */
5393 dprintk("%s: server responded with %d layouts, dropping tail\n",
5394 __func__, layout_count);
5395 }
5396
5397 return 0;
5398out_overflow:
5399 print_overflow_msg(__func__, xdr);
5400 return -EIO;
5401}
Andy Adamson863a3c62011-03-23 13:27:54 +00005402
Benny Halevycbe82602011-05-22 19:52:37 +03005403static int decode_layoutreturn(struct xdr_stream *xdr,
5404 struct nfs4_layoutreturn_res *res)
5405{
5406 __be32 *p;
5407 int status;
5408
5409 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5410 if (status)
5411 return status;
5412 p = xdr_inline_decode(xdr, 4);
5413 if (unlikely(!p))
5414 goto out_overflow;
5415 res->lrs_present = be32_to_cpup(p);
5416 if (res->lrs_present)
5417 status = decode_stateid(xdr, &res->stateid);
5418 return status;
5419out_overflow:
5420 print_overflow_msg(__func__, xdr);
5421 return -EIO;
5422}
5423
Andy Adamson863a3c62011-03-23 13:27:54 +00005424static int decode_layoutcommit(struct xdr_stream *xdr,
5425 struct rpc_rqst *req,
5426 struct nfs4_layoutcommit_res *res)
5427{
5428 __be32 *p;
5429 __u32 sizechanged;
5430 int status;
5431
5432 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5433 if (status)
5434 return status;
5435
5436 p = xdr_inline_decode(xdr, 4);
5437 if (unlikely(!p))
5438 goto out_overflow;
5439 sizechanged = be32_to_cpup(p);
5440
5441 if (sizechanged) {
5442 /* throw away new size */
5443 p = xdr_inline_decode(xdr, 8);
5444 if (unlikely(!p))
5445 goto out_overflow;
5446 }
5447 return 0;
5448out_overflow:
5449 print_overflow_msg(__func__, xdr);
5450 return -EIO;
5451}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005452
5453static int decode_test_stateid(struct xdr_stream *xdr,
5454 struct nfs41_test_stateid_res *res)
5455{
5456 __be32 *p;
5457 int status;
5458 int num_res;
5459
5460 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5461 if (status)
5462 return status;
5463
5464 p = xdr_inline_decode(xdr, 4);
5465 if (unlikely(!p))
5466 goto out_overflow;
5467 num_res = be32_to_cpup(p++);
5468 if (num_res != 1)
5469 goto out;
5470
5471 p = xdr_inline_decode(xdr, 4);
5472 if (unlikely(!p))
5473 goto out_overflow;
5474 res->status = be32_to_cpup(p++);
5475 return res->status;
5476out_overflow:
5477 print_overflow_msg(__func__, xdr);
5478out:
5479 return -EIO;
5480}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005481
5482static int decode_free_stateid(struct xdr_stream *xdr,
5483 struct nfs41_free_stateid_res *res)
5484{
5485 __be32 *p;
5486 int status;
5487
5488 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5489 if (status)
5490 return status;
5491
5492 p = xdr_inline_decode(xdr, 4);
5493 if (unlikely(!p))
5494 goto out_overflow;
5495 res->status = be32_to_cpup(p++);
5496 return res->status;
5497out_overflow:
5498 print_overflow_msg(__func__, xdr);
5499 return -EIO;
5500}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005501#endif /* CONFIG_NFS_V4_1 */
5502
Linus Torvalds1da177e2005-04-16 15:20:36 -07005503/*
Benny Halevy49c25592008-12-23 16:06:16 -05005504 * END OF "GENERIC" DECODE ROUTINES.
5505 */
5506
5507/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005508 * Decode OPEN_DOWNGRADE response
5509 */
Chuck Leverbf269552010-12-14 14:59:29 +00005510static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5511 struct xdr_stream *xdr,
5512 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005513{
Andy Adamson05d564f2008-12-23 16:06:15 -05005514 struct compound_hdr hdr;
5515 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005516
Chuck Leverbf269552010-12-14 14:59:29 +00005517 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005518 if (status)
5519 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005520 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005521 if (status)
5522 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005523 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005524 if (status)
5525 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005526 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005527 if (status != 0)
5528 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005529 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005530 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005531out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005532 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005533}
5534
5535/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005536 * Decode ACCESS response
5537 */
Chuck Leverbf269552010-12-14 14:59:29 +00005538static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5539 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005540{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005541 struct compound_hdr hdr;
5542 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005543
Chuck Leverbf269552010-12-14 14:59:29 +00005544 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005545 if (status)
5546 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005547 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005548 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005549 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005550 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005551 if (status != 0)
5552 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005553 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005554 if (status != 0)
5555 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005556 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005557 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005558out:
5559 return status;
5560}
5561
5562/*
5563 * Decode LOOKUP response
5564 */
Chuck Leverbf269552010-12-14 14:59:29 +00005565static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5566 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005567{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005568 struct compound_hdr hdr;
5569 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005570
Chuck Leverbf269552010-12-14 14:59:29 +00005571 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005572 if (status)
5573 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005574 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005575 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005576 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005577 status = decode_putfh(xdr);
5578 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005579 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005580 status = decode_lookup(xdr);
5581 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005582 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005583 status = decode_getfh(xdr, res->fh);
5584 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005585 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005586 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005587 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005588out:
5589 return status;
5590}
5591
5592/*
5593 * Decode LOOKUP_ROOT response
5594 */
Chuck Leverbf269552010-12-14 14:59:29 +00005595static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5596 struct xdr_stream *xdr,
5597 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005598{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005599 struct compound_hdr hdr;
5600 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005601
Chuck Leverbf269552010-12-14 14:59:29 +00005602 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005603 if (status)
5604 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005605 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005606 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005607 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005608 status = decode_putrootfh(xdr);
5609 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005610 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005611 status = decode_getfh(xdr, res->fh);
5612 if (status == 0)
5613 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005614 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005615out:
5616 return status;
5617}
5618
5619/*
5620 * Decode REMOVE response
5621 */
Chuck Leverbf269552010-12-14 14:59:29 +00005622static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5623 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005624{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005625 struct compound_hdr hdr;
5626 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005627
Chuck Leverbf269552010-12-14 14:59:29 +00005628 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005629 if (status)
5630 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005631 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005632 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005633 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005634 status = decode_putfh(xdr);
5635 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005636 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005637 status = decode_remove(xdr, &res->cinfo);
5638 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005639 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005640 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005641 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005642out:
5643 return status;
5644}
5645
5646/*
5647 * Decode RENAME response
5648 */
Chuck Leverbf269552010-12-14 14:59:29 +00005649static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5650 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005651{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005652 struct compound_hdr hdr;
5653 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005654
Chuck Leverbf269552010-12-14 14:59:29 +00005655 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005656 if (status)
5657 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005658 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005659 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005660 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005661 status = decode_putfh(xdr);
5662 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005663 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005664 status = decode_savefh(xdr);
5665 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005666 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005667 status = decode_putfh(xdr);
5668 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005669 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005670 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5671 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005672 goto out;
5673 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005674 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005675 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005676 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005677 status = decode_restorefh(xdr);
5678 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005679 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005680 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005681 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005682out:
5683 return status;
5684}
5685
5686/*
5687 * Decode LINK response
5688 */
Chuck Leverbf269552010-12-14 14:59:29 +00005689static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5690 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005691{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005692 struct compound_hdr hdr;
5693 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005694
Chuck Leverbf269552010-12-14 14:59:29 +00005695 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005696 if (status)
5697 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005698 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005699 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005700 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005701 status = decode_putfh(xdr);
5702 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005703 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005704 status = decode_savefh(xdr);
5705 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005706 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005707 status = decode_putfh(xdr);
5708 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005709 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005710 status = decode_link(xdr, &res->cinfo);
5711 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005712 goto out;
5713 /*
5714 * Note order: OP_LINK leaves the directory as the current
5715 * filehandle.
5716 */
Chuck Leverbf269552010-12-14 14:59:29 +00005717 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005718 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005719 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005720 status = decode_restorefh(xdr);
5721 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005722 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005723 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005724 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005725out:
5726 return status;
5727}
5728
5729/*
5730 * Decode CREATE response
5731 */
Chuck Leverbf269552010-12-14 14:59:29 +00005732static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5733 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005734{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005735 struct compound_hdr hdr;
5736 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005737
Chuck Leverbf269552010-12-14 14:59:29 +00005738 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005739 if (status)
5740 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005741 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005742 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005743 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005744 status = decode_putfh(xdr);
5745 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005746 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005747 status = decode_savefh(xdr);
5748 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005749 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005750 status = decode_create(xdr, &res->dir_cinfo);
5751 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005752 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005753 status = decode_getfh(xdr, res->fh);
5754 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005756 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005757 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005758 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005759 status = decode_restorefh(xdr);
5760 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005761 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005762 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005763 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005764out:
5765 return status;
5766}
5767
5768/*
5769 * Decode SYMLINK response
5770 */
Chuck Leverbf269552010-12-14 14:59:29 +00005771static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5772 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005773{
Chuck Leverbf269552010-12-14 14:59:29 +00005774 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005775}
5776
5777/*
5778 * Decode GETATTR response
5779 */
Chuck Leverbf269552010-12-14 14:59:29 +00005780static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5781 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005782{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005783 struct compound_hdr hdr;
5784 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005785
Chuck Leverbf269552010-12-14 14:59:29 +00005786 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005787 if (status)
5788 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005789 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005790 if (status)
5791 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005792 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005793 if (status)
5794 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005795 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005796 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005797out:
5798 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799}
5800
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005801/*
5802 * Encode an SETACL request
5803 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005804static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5805 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005806{
Andy Adamson05d564f2008-12-23 16:06:15 -05005807 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005808 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005809 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005810
Chuck Lever9f06c712010-12-14 14:59:18 +00005811 encode_compound_hdr(xdr, req, &hdr);
5812 encode_sequence(xdr, &args->seq_args, &hdr);
5813 encode_putfh(xdr, args->fh, &hdr);
5814 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005815 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005816}
Andy Adamson05d564f2008-12-23 16:06:15 -05005817
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005818/*
5819 * Decode SETACL response
5820 */
5821static int
Chuck Leverbf269552010-12-14 14:59:29 +00005822nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005823 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005824{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005825 struct compound_hdr hdr;
5826 int status;
5827
Chuck Leverbf269552010-12-14 14:59:29 +00005828 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005829 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)
5833 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005834 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005835 if (status)
5836 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005837 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005838out:
5839 return status;
5840}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005841
5842/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005843 * Decode GETACL response
5844 */
5845static int
Chuck Leverbf269552010-12-14 14:59:29 +00005846nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005847 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005848{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005849 struct compound_hdr hdr;
5850 int status;
5851
Chuck Leverbf269552010-12-14 14:59:29 +00005852 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005853 if (status)
5854 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005855 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005856 if (status)
5857 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005858 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005859 if (status)
5860 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005861 status = decode_getacl(xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005862
5863out:
5864 return status;
5865}
5866
5867/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868 * Decode CLOSE response
5869 */
Chuck Leverbf269552010-12-14 14:59:29 +00005870static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5871 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005872{
Andy Adamson05d564f2008-12-23 16:06:15 -05005873 struct compound_hdr hdr;
5874 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005875
Chuck Leverbf269552010-12-14 14:59:29 +00005876 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005877 if (status)
5878 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005879 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005880 if (status)
5881 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005882 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005883 if (status)
5884 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005885 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005886 if (status != 0)
5887 goto out;
5888 /*
5889 * Note: Server may do delete on close for this file
5890 * in which case the getattr call will fail with
5891 * an ESTALE error. Shouldn't be a problem,
5892 * though, since fattr->valid will remain unset.
5893 */
Chuck Leverbf269552010-12-14 14:59:29 +00005894 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005895 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005896out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005897 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005898}
5899
5900/*
5901 * Decode OPEN response
5902 */
Chuck Leverbf269552010-12-14 14:59:29 +00005903static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5904 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005905{
Andy Adamson05d564f2008-12-23 16:06:15 -05005906 struct compound_hdr hdr;
5907 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005908
Chuck Leverbf269552010-12-14 14:59:29 +00005909 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005910 if (status)
5911 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005912 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005913 if (status)
5914 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005915 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005916 if (status)
5917 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005918 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005919 if (status)
5920 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005921 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005922 if (status)
5923 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005924 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005925 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005926 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005927 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005928 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005929 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005930 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005931 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005932 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005933out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005934 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005935}
5936
5937/*
5938 * Decode OPEN_CONFIRM response
5939 */
Chuck Leverbf269552010-12-14 14:59:29 +00005940static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5941 struct xdr_stream *xdr,
5942 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005943{
Andy Adamson05d564f2008-12-23 16:06:15 -05005944 struct compound_hdr hdr;
5945 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005946
Chuck Leverbf269552010-12-14 14:59:29 +00005947 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005948 if (status)
5949 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005950 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005951 if (status)
5952 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005953 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005955 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005956}
5957
5958/*
5959 * Decode OPEN response
5960 */
Chuck Leverbf269552010-12-14 14:59:29 +00005961static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5962 struct xdr_stream *xdr,
5963 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005964{
Andy Adamson05d564f2008-12-23 16:06:15 -05005965 struct compound_hdr hdr;
5966 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005967
Chuck Leverbf269552010-12-14 14:59:29 +00005968 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005969 if (status)
5970 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005971 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005972 if (status)
5973 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005974 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005975 if (status)
5976 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005977 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005978 if (status)
5979 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005980 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005981 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005982out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005983 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984}
5985
5986/*
5987 * Decode SETATTR response
5988 */
Chuck Leverbf269552010-12-14 14:59:29 +00005989static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5990 struct xdr_stream *xdr,
5991 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005992{
Andy Adamson05d564f2008-12-23 16:06:15 -05005993 struct compound_hdr hdr;
5994 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005995
Chuck Leverbf269552010-12-14 14:59:29 +00005996 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005997 if (status)
5998 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005999 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006000 if (status)
6001 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006002 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006003 if (status)
6004 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006005 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006006 if (status)
6007 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006008 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006009 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006011 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012}
6013
6014/*
6015 * Decode LOCK response
6016 */
Chuck Leverbf269552010-12-14 14:59:29 +00006017static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6018 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006019{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006020 struct compound_hdr hdr;
6021 int status;
6022
Chuck Leverbf269552010-12-14 14:59:29 +00006023 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024 if (status)
6025 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006026 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006027 if (status)
6028 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006029 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030 if (status)
6031 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006032 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006033out:
6034 return status;
6035}
6036
6037/*
6038 * Decode LOCKT response
6039 */
Chuck Leverbf269552010-12-14 14:59:29 +00006040static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6041 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006042{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006043 struct compound_hdr hdr;
6044 int status;
6045
Chuck Leverbf269552010-12-14 14:59:29 +00006046 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006047 if (status)
6048 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006049 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006050 if (status)
6051 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006052 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006053 if (status)
6054 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006055 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056out:
6057 return status;
6058}
6059
6060/*
6061 * Decode LOCKU response
6062 */
Chuck Leverbf269552010-12-14 14:59:29 +00006063static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6064 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006065{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006066 struct compound_hdr hdr;
6067 int status;
6068
Chuck Leverbf269552010-12-14 14:59:29 +00006069 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006070 if (status)
6071 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006072 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006073 if (status)
6074 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006075 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006076 if (status)
6077 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006078 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006079out:
6080 return status;
6081}
6082
Chuck Leverbf269552010-12-14 14:59:29 +00006083static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6084 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006085{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006086 struct compound_hdr hdr;
6087 int status;
6088
Chuck Leverbf269552010-12-14 14:59:29 +00006089 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006090 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006091 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006092 return status;
6093}
6094
Linus Torvalds1da177e2005-04-16 15:20:36 -07006095/*
6096 * Decode READLINK response
6097 */
Chuck Leverbf269552010-12-14 14:59:29 +00006098static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6099 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006100 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006102 struct compound_hdr hdr;
6103 int status;
6104
Chuck Leverbf269552010-12-14 14:59:29 +00006105 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006112 if (status)
6113 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006114 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006115out:
6116 return status;
6117}
6118
6119/*
6120 * Decode READDIR response
6121 */
Chuck Leverbf269552010-12-14 14:59:29 +00006122static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6123 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006124{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125 struct compound_hdr hdr;
6126 int status;
6127
Chuck Leverbf269552010-12-14 14:59:29 +00006128 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006129 if (status)
6130 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006131 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006132 if (status)
6133 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006134 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006135 if (status)
6136 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006137 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006138out:
6139 return status;
6140}
6141
6142/*
6143 * Decode Read response
6144 */
Chuck Leverbf269552010-12-14 14:59:29 +00006145static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6146 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006147{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006148 struct compound_hdr hdr;
6149 int status;
6150
Chuck Leverbf269552010-12-14 14:59:29 +00006151 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152 if (status)
6153 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006154 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006155 if (status)
6156 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006157 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006158 if (status)
6159 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006160 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006161 if (!status)
6162 status = res->count;
6163out:
6164 return status;
6165}
6166
6167/*
6168 * Decode WRITE response
6169 */
Chuck Leverbf269552010-12-14 14:59:29 +00006170static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6171 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173 struct compound_hdr hdr;
6174 int status;
6175
Chuck Leverbf269552010-12-14 14:59:29 +00006176 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006177 if (status)
6178 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006179 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006180 if (status)
6181 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006182 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183 if (status)
6184 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006185 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006186 if (status)
6187 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006188 if (res->fattr)
6189 decode_getfattr(xdr, res->fattr, res->server,
6190 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191 if (!status)
6192 status = res->count;
6193out:
6194 return status;
6195}
6196
6197/*
6198 * Decode COMMIT response
6199 */
Chuck Leverbf269552010-12-14 14:59:29 +00006200static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6201 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203 struct compound_hdr hdr;
6204 int status;
6205
Chuck Leverbf269552010-12-14 14:59:29 +00006206 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207 if (status)
6208 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006209 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006210 if (status)
6211 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006212 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006213 if (status)
6214 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006215 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006216 if (status)
6217 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006218 if (res->fattr)
6219 decode_getfattr(xdr, res->fattr, res->server,
6220 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221out:
6222 return status;
6223}
6224
6225/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006226 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227 */
Chuck Leverbf269552010-12-14 14:59:29 +00006228static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006229 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006230{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006231 struct compound_hdr hdr;
6232 int status;
6233
Chuck Leverbf269552010-12-14 14:59:29 +00006234 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006236 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006237 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006238 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006240 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006241 return status;
6242}
6243
6244/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006245 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246 */
Chuck Leverbf269552010-12-14 14:59:29 +00006247static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006248 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006249{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006250 struct compound_hdr hdr;
6251 int status;
6252
Chuck Leverbf269552010-12-14 14:59:29 +00006253 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006254 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006256 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006257 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006258 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006259 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260 return status;
6261}
6262
6263/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006264 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006265 */
Chuck Leverbf269552010-12-14 14:59:29 +00006266static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006267 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006268{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006269 struct compound_hdr hdr;
6270 int status;
6271
Chuck Leverbf269552010-12-14 14:59:29 +00006272 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006274 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006275 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006276 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006278 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006279 return status;
6280}
6281
6282/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006283 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006284 */
Chuck Leverbf269552010-12-14 14:59:29 +00006285static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6286 struct xdr_stream *xdr,
6287 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006288{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006289 struct compound_hdr hdr;
6290 int status;
6291
Chuck Leverbf269552010-12-14 14:59:29 +00006292 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006293 if (status)
6294 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006295 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006296 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006297 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006298 status = decode_putfh(xdr);
6299 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006300 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006301 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006302out:
6303 return status;
6304}
6305
6306/*
6307 * Decode RENEW response
6308 */
Chuck Leverbf269552010-12-14 14:59:29 +00006309static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6310 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006312 struct compound_hdr hdr;
6313 int status;
6314
Chuck Leverbf269552010-12-14 14:59:29 +00006315 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006316 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006317 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006318 return status;
6319}
6320
6321/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006322 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323 */
Chuck Leverbf269552010-12-14 14:59:29 +00006324static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6325 struct xdr_stream *xdr,
6326 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006327{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006328 struct compound_hdr hdr;
6329 int status;
6330
Chuck Leverbf269552010-12-14 14:59:29 +00006331 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006333 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006334 return status;
6335}
6336
6337/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006338 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339 */
Chuck Leverbf269552010-12-14 14:59:29 +00006340static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6341 struct xdr_stream *xdr,
6342 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006343{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006344 struct compound_hdr hdr;
6345 int status;
6346
Chuck Leverbf269552010-12-14 14:59:29 +00006347 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006349 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006351 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006353 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354 return status;
6355}
6356
6357/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006358 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359 */
Chuck Leverbf269552010-12-14 14:59:29 +00006360static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6361 struct xdr_stream *xdr,
6362 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006363{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364 struct compound_hdr hdr;
6365 int status;
6366
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006368 if (status)
6369 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006370 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006371 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006372 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006373 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006374 if (status != 0)
6375 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006376 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006377 if (status != 0)
6378 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006379 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006380 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01006381out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006382 return status;
6383}
6384
Trond Myklebust683b57b2006-06-09 09:34:22 -04006385/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006386 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006387 */
Chuck Leverbf269552010-12-14 14:59:29 +00006388static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6389 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006390 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006391{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006392 struct compound_hdr hdr;
6393 int status;
6394
Chuck Leverbf269552010-12-14 14:59:29 +00006395 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006396 if (status)
6397 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006398 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006399 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006400 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006401 status = decode_putfh(xdr);
6402 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006403 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006404 status = decode_lookup(xdr);
6405 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006406 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006407 xdr_enter_page(xdr, PAGE_SIZE);
6408 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006409 res->fs_locations->server,
6410 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04006411out:
6412 return status;
6413}
6414
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006415/*
6416 * Decode SECINFO response
6417 */
6418static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6419 struct xdr_stream *xdr,
6420 struct nfs4_secinfo_res *res)
6421{
6422 struct compound_hdr hdr;
6423 int status;
6424
6425 status = decode_compound_hdr(xdr, &hdr);
6426 if (status)
6427 goto out;
6428 status = decode_sequence(xdr, &res->seq_res, rqstp);
6429 if (status)
6430 goto out;
6431 status = decode_putfh(xdr);
6432 if (status)
6433 goto out;
6434 status = decode_secinfo(xdr, res);
6435 if (status)
6436 goto out;
6437out:
6438 return status;
6439}
6440
Benny Halevy99fe60d2009-04-01 09:22:29 -04006441#if defined(CONFIG_NFS_V4_1)
6442/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006443 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006444 */
Chuck Leverbf269552010-12-14 14:59:29 +00006445static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6446 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006447 void *res)
6448{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006449 struct compound_hdr hdr;
6450 int status;
6451
Chuck Leverbf269552010-12-14 14:59:29 +00006452 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006453 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006454 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006455 return status;
6456}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006457
6458/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006459 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006460 */
Chuck Leverbf269552010-12-14 14:59:29 +00006461static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6462 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006463 struct nfs41_create_session_res *res)
6464{
Andy Adamsonfc931582009-04-01 09:22:31 -04006465 struct compound_hdr hdr;
6466 int status;
6467
Chuck Leverbf269552010-12-14 14:59:29 +00006468 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006469 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006470 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006471 return status;
6472}
6473
6474/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006475 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006476 */
Chuck Leverbf269552010-12-14 14:59:29 +00006477static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6478 struct xdr_stream *xdr,
6479 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006480{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006481 struct compound_hdr hdr;
6482 int status;
6483
Chuck Leverbf269552010-12-14 14:59:29 +00006484 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006485 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006486 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006487 return status;
6488}
6489
6490/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006491 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006492 */
Chuck Leverbf269552010-12-14 14:59:29 +00006493static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6494 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006495 struct nfs4_sequence_res *res)
6496{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006497 struct compound_hdr hdr;
6498 int status;
6499
Chuck Leverbf269552010-12-14 14:59:29 +00006500 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006501 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006502 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006503 return status;
6504}
6505
6506/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006507 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006508 */
Chuck Leverbf269552010-12-14 14:59:29 +00006509static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6510 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006511 struct nfs4_get_lease_time_res *res)
6512{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006513 struct compound_hdr hdr;
6514 int status;
6515
Chuck Leverbf269552010-12-14 14:59:29 +00006516 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006517 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006518 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006519 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006520 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006521 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006522 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006523 return status;
6524}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006525
6526/*
6527 * Decode RECLAIM_COMPLETE response
6528 */
Chuck Leverbf269552010-12-14 14:59:29 +00006529static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6530 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006531 struct nfs41_reclaim_complete_res *res)
6532{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006533 struct compound_hdr hdr;
6534 int status;
6535
Chuck Leverbf269552010-12-14 14:59:29 +00006536 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006537 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006538 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006539 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006540 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006541 return status;
6542}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006543
6544/*
6545 * Decode GETDEVINFO response
6546 */
Chuck Leverbf269552010-12-14 14:59:29 +00006547static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6548 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006549 struct nfs4_getdeviceinfo_res *res)
6550{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006551 struct compound_hdr hdr;
6552 int status;
6553
Chuck Leverbf269552010-12-14 14:59:29 +00006554 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006555 if (status != 0)
6556 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006557 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006558 if (status != 0)
6559 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006560 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006561out:
6562 return status;
6563}
6564
6565/*
6566 * Decode LAYOUTGET response
6567 */
Chuck Leverbf269552010-12-14 14:59:29 +00006568static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6569 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006570 struct nfs4_layoutget_res *res)
6571{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006572 struct compound_hdr hdr;
6573 int status;
6574
Chuck Leverbf269552010-12-14 14:59:29 +00006575 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006576 if (status)
6577 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006578 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006579 if (status)
6580 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006581 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006582 if (status)
6583 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006584 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006585out:
6586 return status;
6587}
Andy Adamson863a3c62011-03-23 13:27:54 +00006588
6589/*
Benny Halevycbe82602011-05-22 19:52:37 +03006590 * Decode LAYOUTRETURN response
6591 */
6592static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6593 struct xdr_stream *xdr,
6594 struct nfs4_layoutreturn_res *res)
6595{
6596 struct compound_hdr hdr;
6597 int status;
6598
6599 status = decode_compound_hdr(xdr, &hdr);
6600 if (status)
6601 goto out;
6602 status = decode_sequence(xdr, &res->seq_res, rqstp);
6603 if (status)
6604 goto out;
6605 status = decode_putfh(xdr);
6606 if (status)
6607 goto out;
6608 status = decode_layoutreturn(xdr, res);
6609out:
6610 return status;
6611}
6612
6613/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006614 * Decode LAYOUTCOMMIT response
6615 */
6616static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6617 struct xdr_stream *xdr,
6618 struct nfs4_layoutcommit_res *res)
6619{
6620 struct compound_hdr hdr;
6621 int status;
6622
6623 status = decode_compound_hdr(xdr, &hdr);
6624 if (status)
6625 goto out;
6626 status = decode_sequence(xdr, &res->seq_res, rqstp);
6627 if (status)
6628 goto out;
6629 status = decode_putfh(xdr);
6630 if (status)
6631 goto out;
6632 status = decode_layoutcommit(xdr, rqstp, res);
6633 if (status)
6634 goto out;
6635 decode_getfattr(xdr, res->fattr, res->server,
6636 !RPC_IS_ASYNC(rqstp->rq_task));
6637out:
6638 return status;
6639}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006640
6641/*
6642 * Decode SECINFO_NO_NAME response
6643 */
6644static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6645 struct xdr_stream *xdr,
6646 struct nfs4_secinfo_res *res)
6647{
6648 struct compound_hdr hdr;
6649 int status;
6650
6651 status = decode_compound_hdr(xdr, &hdr);
6652 if (status)
6653 goto out;
6654 status = decode_sequence(xdr, &res->seq_res, rqstp);
6655 if (status)
6656 goto out;
6657 status = decode_putrootfh(xdr);
6658 if (status)
6659 goto out;
6660 status = decode_secinfo(xdr, res);
6661out:
6662 return status;
6663}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006664
6665/*
6666 * Decode TEST_STATEID response
6667 */
6668static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6669 struct xdr_stream *xdr,
6670 struct nfs41_test_stateid_res *res)
6671{
6672 struct compound_hdr hdr;
6673 int status;
6674
6675 status = decode_compound_hdr(xdr, &hdr);
6676 if (status)
6677 goto out;
6678 status = decode_sequence(xdr, &res->seq_res, rqstp);
6679 if (status)
6680 goto out;
6681 status = decode_test_stateid(xdr, res);
6682out:
6683 return status;
6684}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006685
6686/*
6687 * Decode FREE_STATEID response
6688 */
6689static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6690 struct xdr_stream *xdr,
6691 struct nfs41_free_stateid_res *res)
6692{
6693 struct compound_hdr hdr;
6694 int status;
6695
6696 status = decode_compound_hdr(xdr, &hdr);
6697 if (status)
6698 goto out;
6699 status = decode_sequence(xdr, &res->seq_res, rqstp);
6700 if (status)
6701 goto out;
6702 status = decode_free_stateid(xdr, res);
6703out:
6704 return status;
6705}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006706#endif /* CONFIG_NFS_V4_1 */
6707
Chuck Lever573c4e12010-12-14 14:58:11 +00006708/**
6709 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6710 * the local page cache.
6711 * @xdr: XDR stream where entry resides
6712 * @entry: buffer to fill in with entry data
6713 * @plus: boolean indicating whether this should be a readdirplus entry
6714 *
6715 * Returns zero if successful, otherwise a negative errno value is
6716 * returned.
6717 *
6718 * This function is not invoked during READDIR reply decoding, but
6719 * rather whenever an application invokes the getdents(2) system call
6720 * on a directory already in our cache.
6721 */
6722int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6723 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006724{
6725 uint32_t bitmap[2] = {0};
6726 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006727 __be32 *p = xdr_inline_decode(xdr, 4);
6728 if (unlikely(!p))
6729 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006730 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006731 p = xdr_inline_decode(xdr, 4);
6732 if (unlikely(!p))
6733 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006734 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006735 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006737 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006738 }
6739
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006740 p = xdr_inline_decode(xdr, 12);
6741 if (unlikely(!p))
6742 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006743 entry->prev_cookie = entry->cookie;
6744 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006745 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006746
Trond Myklebust9af8c222010-10-24 11:52:55 -04006747 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006748 if (unlikely(!p))
6749 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006750 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006751
6752 /*
6753 * In case the server doesn't return an inode number,
6754 * we fake one here. (We don't use inode number 0,
6755 * since glibc seems to choke on it...)
6756 */
6757 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006758 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006759
Trond Myklebust9af8c222010-10-24 11:52:55 -04006760 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006761 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006762
6763 if (decode_attr_length(xdr, &len, &p) < 0)
6764 goto out_overflow;
6765
Chuck Lever573c4e12010-12-14 14:58:11 +00006766 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6767 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006768 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006769 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6770 entry->ino = entry->fattr->mounted_on_fileid;
6771 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006772 entry->ino = entry->fattr->fileid;
6773
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006774 entry->d_type = DT_UNKNOWN;
6775 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6776 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6777
Chuck Lever573c4e12010-12-14 14:58:11 +00006778 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006779
6780out_overflow:
6781 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006782 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006783}
6784
6785/*
6786 * We need to translate between nfs status return values and
6787 * the local errno values which may not be the same.
6788 */
6789static struct {
6790 int stat;
6791 int errno;
6792} nfs_errtbl[] = {
6793 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006794 { NFS4ERR_PERM, -EPERM },
6795 { NFS4ERR_NOENT, -ENOENT },
6796 { NFS4ERR_IO, -errno_NFSERR_IO},
6797 { NFS4ERR_NXIO, -ENXIO },
6798 { NFS4ERR_ACCESS, -EACCES },
6799 { NFS4ERR_EXIST, -EEXIST },
6800 { NFS4ERR_XDEV, -EXDEV },
6801 { NFS4ERR_NOTDIR, -ENOTDIR },
6802 { NFS4ERR_ISDIR, -EISDIR },
6803 { NFS4ERR_INVAL, -EINVAL },
6804 { NFS4ERR_FBIG, -EFBIG },
6805 { NFS4ERR_NOSPC, -ENOSPC },
6806 { NFS4ERR_ROFS, -EROFS },
6807 { NFS4ERR_MLINK, -EMLINK },
6808 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6809 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6810 { NFS4ERR_DQUOT, -EDQUOT },
6811 { NFS4ERR_STALE, -ESTALE },
6812 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006813 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6814 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6815 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006816 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006817 { NFS4ERR_BADTYPE, -EBADTYPE },
6818 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006819 { NFS4ERR_SYMLINK, -ELOOP },
6820 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6821 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006822 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006823};
6824
6825/*
6826 * Convert an NFS error code to a local one.
6827 * This one is used jointly by NFSv2 and NFSv3.
6828 */
6829static int
David Howells0a8ea432006-08-22 20:06:08 -04006830nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006831{
6832 int i;
6833 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6834 if (nfs_errtbl[i].stat == stat)
6835 return nfs_errtbl[i].errno;
6836 }
6837 if (stat <= 10000 || stat > 10100) {
6838 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006839 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006840 }
6841 /* If we cannot translate the error, the recovery routines should
6842 * handle it.
6843 * Note: remaining NFSv4 error codes have values > 10000, so should
6844 * not conflict with native Linux error codes.
6845 */
Benny Halevy856dff32008-03-31 17:39:06 +03006846 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006847}
6848
Linus Torvalds1da177e2005-04-16 15:20:36 -07006849#define PROC(proc, argtype, restype) \
6850[NFSPROC4_CLNT_##proc] = { \
6851 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006852 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006853 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006854 .p_arglen = NFS4_##argtype##_sz, \
6855 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006856 .p_statidx = NFSPROC4_CLNT_##proc, \
6857 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006858}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006859
6860struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006861 PROC(READ, enc_read, dec_read),
6862 PROC(WRITE, enc_write, dec_write),
6863 PROC(COMMIT, enc_commit, dec_commit),
6864 PROC(OPEN, enc_open, dec_open),
6865 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6866 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6867 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6868 PROC(CLOSE, enc_close, dec_close),
6869 PROC(SETATTR, enc_setattr, dec_setattr),
6870 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6871 PROC(RENEW, enc_renew, dec_renew),
6872 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6873 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6874 PROC(LOCK, enc_lock, dec_lock),
6875 PROC(LOCKT, enc_lockt, dec_lockt),
6876 PROC(LOCKU, enc_locku, dec_locku),
6877 PROC(ACCESS, enc_access, dec_access),
6878 PROC(GETATTR, enc_getattr, dec_getattr),
6879 PROC(LOOKUP, enc_lookup, dec_lookup),
6880 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6881 PROC(REMOVE, enc_remove, dec_remove),
6882 PROC(RENAME, enc_rename, dec_rename),
6883 PROC(LINK, enc_link, dec_link),
6884 PROC(SYMLINK, enc_symlink, dec_symlink),
6885 PROC(CREATE, enc_create, dec_create),
6886 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6887 PROC(STATFS, enc_statfs, dec_statfs),
6888 PROC(READLINK, enc_readlink, dec_readlink),
6889 PROC(READDIR, enc_readdir, dec_readdir),
6890 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6891 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6892 PROC(GETACL, enc_getacl, dec_getacl),
6893 PROC(SETACL, enc_setacl, dec_setacl),
6894 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6895 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006896 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006897#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00006898 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6899 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6900 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6901 PROC(SEQUENCE, enc_sequence, dec_sequence),
6902 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6903 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6904 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6905 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00006906 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03006907 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006908 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04006909 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006910 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006911#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006912};
6913
6914struct rpc_version nfs_version4 = {
6915 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08006916 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07006917 .procs = nfs4_procedures
6918};
6919
6920/*
6921 * Local variables:
6922 * c-basic-offset: 8
6923 * End:
6924 */