blob: 40da65e8fa2aa91508b8a22b0ce5186fbb8c79f0 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/nfs.h>
50#include <linux/nfs4.h>
51#include <linux/nfs_fs.h>
52#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000053#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050054#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040055#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#define NFSDBG_FACILITY NFSDBG_XDR
58
59/* Mapping from NFS error code to "errno" error code. */
60#define errno_NFSERR_IO EIO
61
David Howells0a8ea432006-08-22 20:06:08 -040062static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65#ifdef DEBUG
66#define NFS4_MAXTAGLEN 20
67#else
68#define NFS4_MAXTAGLEN 0
69#endif
70
Andy Adamson6c0195a2008-12-23 16:06:15 -050071/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040072 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 */
Trond Myklebustd035c362010-12-21 10:45:27 -050074#define open_owner_id_maxsz (1 + 1 + 4)
75#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040076#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79#define op_encode_hdr_maxsz (1)
80#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040081#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
84#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
86 (NFS4_FHSIZE >> 2))
87#define decode_putfh_maxsz (op_decode_hdr_maxsz)
88#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
89#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
90#define encode_getfh_maxsz (op_encode_hdr_maxsz)
91#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
92 ((3+NFS4_FHSIZE) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000093#define nfs4_fattr_bitmap_maxsz 3
94#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
96#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040097#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +000099/* This is based on getfattr, which uses the most attributes: */
100#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400101 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000102#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
103 nfs4_fattr_value_maxsz)
104#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400105#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
106 1 + 2 + 1 + \
107 nfs4_owner_maxsz + \
108 nfs4_group_maxsz + \
109 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#define encode_savefh_maxsz (op_encode_hdr_maxsz)
111#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400112#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
113#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200114#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
116#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
117#define decode_renew_maxsz (op_decode_hdr_maxsz)
118#define encode_setclientid_maxsz \
119 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500120 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
121 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
122 1 /* sc_prog */ + \
123 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
124 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
125 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#define decode_setclientid_maxsz \
127 (op_decode_hdr_maxsz + \
128 2 + \
129 1024) /* large value for CLID_INUSE */
130#define encode_setclientid_confirm_maxsz \
131 (op_encode_hdr_maxsz + \
132 3 + (NFS4_VERIFIER_SIZE >> 2))
133#define decode_setclientid_confirm_maxsz \
134 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400135#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
136#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400137#define encode_share_access_maxsz \
138 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500139#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400140#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
141#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
142#define encode_open_maxsz (op_encode_hdr_maxsz + \
143 2 + encode_share_access_maxsz + 2 + \
144 open_owner_id_maxsz + \
145 encode_opentype_maxsz + \
146 encode_claim_null_maxsz)
147#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400148#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400149 decode_ace_maxsz)
150#define decode_change_info_maxsz (5)
151#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400152 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400153 decode_change_info_maxsz + 1 + \
154 nfs4_fattr_bitmap_maxsz + \
155 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400156#define encode_open_confirm_maxsz \
157 (op_encode_hdr_maxsz + \
158 encode_stateid_maxsz + 1)
159#define decode_open_confirm_maxsz \
160 (op_decode_hdr_maxsz + \
161 decode_stateid_maxsz)
162#define encode_open_downgrade_maxsz \
163 (op_encode_hdr_maxsz + \
164 encode_stateid_maxsz + 1 + \
165 encode_share_access_maxsz)
166#define decode_open_downgrade_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169#define encode_close_maxsz (op_encode_hdr_maxsz + \
170 1 + encode_stateid_maxsz)
171#define decode_close_maxsz (op_decode_hdr_maxsz + \
172 decode_stateid_maxsz)
173#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
174 encode_stateid_maxsz + \
175 encode_attrs_maxsz)
176#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
177 nfs4_fattr_bitmap_maxsz)
178#define encode_read_maxsz (op_encode_hdr_maxsz + \
179 encode_stateid_maxsz + 3)
180#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
181#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
182 2 + encode_verifier_maxsz + 5)
183#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
184 decode_verifier_maxsz)
185#define encode_readlink_maxsz (op_encode_hdr_maxsz)
186#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
187#define encode_write_maxsz (op_encode_hdr_maxsz + \
188 encode_stateid_maxsz + 4)
189#define decode_write_maxsz (op_decode_hdr_maxsz + \
190 2 + decode_verifier_maxsz)
191#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
192#define decode_commit_maxsz (op_decode_hdr_maxsz + \
193 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194#define encode_remove_maxsz (op_encode_hdr_maxsz + \
195 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400196#define decode_remove_maxsz (op_decode_hdr_maxsz + \
197 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#define encode_rename_maxsz (op_encode_hdr_maxsz + \
199 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400200#define decode_rename_maxsz (op_decode_hdr_maxsz + \
201 decode_change_info_maxsz + \
202 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203#define encode_link_maxsz (op_encode_hdr_maxsz + \
204 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400205#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400206#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400207#define encode_lock_maxsz (op_encode_hdr_maxsz + \
208 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400209 1 + encode_stateid_maxsz + 1 + \
210 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400211#define decode_lock_denied_maxsz \
212 (8 + decode_lockowner_maxsz)
213#define decode_lock_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400215#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
216 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400217#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
218 decode_lock_denied_maxsz)
219#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
220 encode_stateid_maxsz + \
221 4)
222#define decode_locku_maxsz (op_decode_hdr_maxsz + \
223 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400224#define encode_release_lockowner_maxsz \
225 (op_encode_hdr_maxsz + \
226 encode_lockowner_maxsz)
227#define decode_release_lockowner_maxsz \
228 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400229#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
230#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
232 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400233 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000234 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
236#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400237 1 + 2 + nfs4_name_maxsz + \
238 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400239#define decode_create_maxsz (op_decode_hdr_maxsz + \
240 decode_change_info_maxsz + \
241 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400242#define encode_statfs_maxsz (encode_getattr_maxsz)
243#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
245#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400246#define encode_getacl_maxsz (encode_getattr_maxsz)
247#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
248 nfs4_fattr_bitmap_maxsz + 1)
249#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
250 encode_stateid_maxsz + 3)
251#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400252#define encode_fs_locations_maxsz \
253 (encode_getattr_maxsz)
254#define decode_fs_locations_maxsz \
255 (0)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400256
257#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400258#define NFS4_MAX_MACHINE_NAME_LEN (64)
259
Benny Halevy99fe60d2009-04-01 09:22:29 -0400260#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
261 encode_verifier_maxsz + \
262 1 /* co_ownerid.len */ + \
263 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
264 1 /* flags */ + \
265 1 /* spa_how */ + \
266 0 /* SP4_NONE (for now) */ + \
267 1 /* zero implemetation id array */)
268#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
269 2 /* eir_clientid */ + \
270 1 /* eir_sequenceid */ + \
271 1 /* eir_flags */ + \
272 1 /* spr_how */ + \
273 0 /* SP4_NONE (for now) */ + \
274 2 /* eir_server_owner.so_minor_id */ + \
275 /* eir_server_owner.so_major_id<> */ \
276 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
277 /* eir_server_scope<> */ \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
279 1 /* eir_server_impl_id array length */ + \
280 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400281#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
282#define decode_channel_attrs_maxsz (6 + \
283 1 /* ca_rdma_ird.len */ + \
284 1 /* ca_rdma_ird */)
285#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
286 2 /* csa_clientid */ + \
287 1 /* csa_sequence */ + \
288 1 /* csa_flags */ + \
289 encode_channel_attrs_maxsz + \
290 encode_channel_attrs_maxsz + \
291 1 /* csa_cb_program */ + \
292 1 /* csa_sec_parms.len (1) */ + \
293 1 /* cb_secflavor (AUTH_SYS) */ + \
294 1 /* stamp */ + \
295 1 /* machinename.len */ + \
296 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
297 1 /* uid */ + \
298 1 /* gid */ + \
299 1 /* gids.len (0) */)
300#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
301 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
302 1 /* csr_sequence */ + \
303 1 /* csr_flags */ + \
304 decode_channel_attrs_maxsz + \
305 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400306#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
307#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400308#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
309 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
310#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
311 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500312#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
313#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400314#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
315 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
316#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
317 1 /* layout type */ + \
318 1 /* opaque devaddr4 length */ + \
319 /* devaddr4 payload is read into page */ \
320 1 /* notification bitmap length */ + \
321 1 /* notification bitmap */)
322#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
323 encode_stateid_maxsz)
324#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
325 decode_stateid_maxsz + \
326 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000327#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
328 2 /* offset */ + \
329 2 /* length */ + \
330 1 /* reclaim */ + \
331 encode_stateid_maxsz + \
332 1 /* new offset (true) */ + \
333 2 /* last byte written */ + \
334 1 /* nt_timechanged (false) */ + \
335 1 /* layoutupdate4 layout type */ + \
336 1 /* NULL filelayout layoutupdate4 payload */)
337#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
338
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400339#else /* CONFIG_NFS_V4_1 */
340#define encode_sequence_maxsz 0
341#define decode_sequence_maxsz 0
342#endif /* CONFIG_NFS_V4_1 */
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
345#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
346#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400347 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400349 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400351 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400353 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400355 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400357 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400359 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400361 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400363 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400365 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400367 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400369 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400371 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400373 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400374 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400376 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400378 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400379 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400381 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400383 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400384 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400386 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400388 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400389 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400391 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400392 encode_putfh_maxsz + \
393 encode_savefh_maxsz + \
394 encode_open_maxsz + \
395 encode_getfh_maxsz + \
396 encode_getattr_maxsz + \
397 encode_restorefh_maxsz + \
398 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400400 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400401 decode_putfh_maxsz + \
402 decode_savefh_maxsz + \
403 decode_open_maxsz + \
404 decode_getfh_maxsz + \
405 decode_getattr_maxsz + \
406 decode_restorefh_maxsz + \
407 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400408#define NFS4_enc_open_confirm_sz \
409 (compound_encode_hdr_maxsz + \
410 encode_putfh_maxsz + \
411 encode_open_confirm_maxsz)
412#define NFS4_dec_open_confirm_sz \
413 (compound_decode_hdr_maxsz + \
414 decode_putfh_maxsz + \
415 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400417 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400419 encode_open_maxsz + \
420 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400424 decode_open_maxsz + \
425 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#define NFS4_enc_open_downgrade_sz \
427 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400428 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400429 encode_putfh_maxsz + \
430 encode_open_downgrade_maxsz + \
431 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432#define NFS4_dec_open_downgrade_sz \
433 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400434 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400435 decode_putfh_maxsz + \
436 decode_open_downgrade_maxsz + \
437 decode_getattr_maxsz)
438#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400439 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400440 encode_putfh_maxsz + \
441 encode_close_maxsz + \
442 encode_getattr_maxsz)
443#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400444 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400445 decode_putfh_maxsz + \
446 decode_close_maxsz + \
447 decode_getattr_maxsz)
448#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400449 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400450 encode_putfh_maxsz + \
451 encode_setattr_maxsz + \
452 encode_getattr_maxsz)
453#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400454 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400455 decode_putfh_maxsz + \
456 decode_setattr_maxsz + \
457 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400459 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 encode_putfh_maxsz + \
461 encode_fsinfo_maxsz)
462#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 decode_putfh_maxsz + \
465 decode_fsinfo_maxsz)
466#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
467 encode_renew_maxsz)
468#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
469 decode_renew_maxsz)
470#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
471 encode_setclientid_maxsz)
472#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
473 decode_setclientid_maxsz)
474#define NFS4_enc_setclientid_confirm_sz \
475 (compound_encode_hdr_maxsz + \
476 encode_setclientid_confirm_maxsz + \
477 encode_putrootfh_maxsz + \
478 encode_fsinfo_maxsz)
479#define NFS4_dec_setclientid_confirm_sz \
480 (compound_decode_hdr_maxsz + \
481 decode_setclientid_confirm_maxsz + \
482 decode_putrootfh_maxsz + \
483 decode_fsinfo_maxsz)
484#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400487 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400489 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400491 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400493 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400495 encode_lockt_maxsz)
496#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400497 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400498 decode_putfh_maxsz + \
499 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400501 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400503 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400505 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400507 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400508#define NFS4_enc_release_lockowner_sz \
509 (compound_encode_hdr_maxsz + \
510 encode_lockowner_maxsz)
511#define NFS4_dec_release_lockowner_sz \
512 (compound_decode_hdr_maxsz + \
513 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400515 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400517 encode_access_maxsz + \
518 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519#define NFS4_dec_access_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 Myklebust76b32992007-08-10 17:45:11 -0400522 decode_access_maxsz + \
523 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400525 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 encode_putfh_maxsz + \
527 encode_getattr_maxsz)
528#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400529 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 decode_putfh_maxsz + \
531 decode_getattr_maxsz)
532#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400533 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 encode_putfh_maxsz + \
535 encode_lookup_maxsz + \
536 encode_getattr_maxsz + \
537 encode_getfh_maxsz)
538#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400539 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400541 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 decode_getattr_maxsz + \
543 decode_getfh_maxsz)
544#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400545 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 encode_putrootfh_maxsz + \
547 encode_getattr_maxsz + \
548 encode_getfh_maxsz)
549#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400550 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 decode_putrootfh_maxsz + \
552 decode_getattr_maxsz + \
553 decode_getfh_maxsz)
554#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400555 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400557 encode_remove_maxsz + \
558 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400560 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400562 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400563 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400565 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 encode_putfh_maxsz + \
567 encode_savefh_maxsz + \
568 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400569 encode_rename_maxsz + \
570 encode_getattr_maxsz + \
571 encode_restorefh_maxsz + \
572 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 decode_putfh_maxsz + \
576 decode_savefh_maxsz + \
577 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400578 decode_rename_maxsz + \
579 decode_getattr_maxsz + \
580 decode_restorefh_maxsz + \
581 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400583 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 encode_putfh_maxsz + \
585 encode_savefh_maxsz + \
586 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400587 encode_link_maxsz + \
588 decode_getattr_maxsz + \
589 encode_restorefh_maxsz + \
590 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400592 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 decode_putfh_maxsz + \
594 decode_savefh_maxsz + \
595 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400596 decode_link_maxsz + \
597 decode_getattr_maxsz + \
598 decode_restorefh_maxsz + \
599 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 encode_putfh_maxsz + \
603 encode_symlink_maxsz + \
604 encode_getattr_maxsz + \
605 encode_getfh_maxsz)
606#define NFS4_dec_symlink_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_symlink_maxsz + \
610 decode_getattr_maxsz + \
611 decode_getfh_maxsz)
612#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400613 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400615 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400617 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400619 encode_restorefh_maxsz + \
620 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621#define NFS4_dec_create_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 + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400624 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400626 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400628 decode_restorefh_maxsz + \
629 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400631 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 encode_putfh_maxsz + \
633 encode_getattr_maxsz)
634#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400635 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 decode_putfh_maxsz + \
637 decode_getattr_maxsz)
638#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400639 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400641 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400643 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400645 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400647 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800648 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 encode_getattr_maxsz)
650#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400651 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800652 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 decode_getattr_maxsz)
654#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400655 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100657 encode_delegreturn_maxsz + \
658 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400660 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100661 decode_delegreturn_maxsz + \
662 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000663#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400664 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000665 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400666 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000667#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400668 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000669 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400670 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000671#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000673 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400674 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000675#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000677 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400678 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400679#define NFS4_enc_fs_locations_sz \
680 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400681 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400682 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400683 encode_lookup_maxsz + \
684 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400685#define NFS4_dec_fs_locations_sz \
686 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400687 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400688 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400689 decode_lookup_maxsz + \
690 decode_fs_locations_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400691#if defined(CONFIG_NFS_V4_1)
692#define NFS4_enc_exchange_id_sz \
693 (compound_encode_hdr_maxsz + \
694 encode_exchange_id_maxsz)
695#define NFS4_dec_exchange_id_sz \
696 (compound_decode_hdr_maxsz + \
697 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400698#define NFS4_enc_create_session_sz \
699 (compound_encode_hdr_maxsz + \
700 encode_create_session_maxsz)
701#define NFS4_dec_create_session_sz \
702 (compound_decode_hdr_maxsz + \
703 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400704#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
705 encode_destroy_session_maxsz)
706#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
707 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400708#define NFS4_enc_sequence_sz \
709 (compound_decode_hdr_maxsz + \
710 encode_sequence_maxsz)
711#define NFS4_dec_sequence_sz \
712 (compound_decode_hdr_maxsz + \
713 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400714#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
715 encode_sequence_maxsz + \
716 encode_putrootfh_maxsz + \
717 encode_fsinfo_maxsz)
718#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
719 decode_sequence_maxsz + \
720 decode_putrootfh_maxsz + \
721 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500722#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
723 encode_sequence_maxsz + \
724 encode_reclaim_complete_maxsz)
725#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
726 decode_sequence_maxsz + \
727 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400728#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
729 encode_sequence_maxsz +\
730 encode_getdeviceinfo_maxsz)
731#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
732 decode_sequence_maxsz + \
733 decode_getdeviceinfo_maxsz)
734#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
735 encode_sequence_maxsz + \
736 encode_putfh_maxsz + \
737 encode_layoutget_maxsz)
738#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
739 decode_sequence_maxsz + \
740 decode_putfh_maxsz + \
741 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000742#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
743 encode_sequence_maxsz +\
744 encode_putfh_maxsz + \
745 encode_layoutcommit_maxsz + \
746 encode_getattr_maxsz)
747#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
748 decode_sequence_maxsz + \
749 decode_putfh_maxsz + \
750 decode_layoutcommit_maxsz + \
751 decode_getattr_maxsz)
752
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500753
754const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
755 compound_encode_hdr_maxsz +
756 encode_sequence_maxsz +
757 encode_putfh_maxsz +
758 encode_getattr_maxsz) *
759 XDR_UNIT);
760
761const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
762 compound_decode_hdr_maxsz +
763 decode_sequence_maxsz +
764 decode_putfh_maxsz) *
765 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400766#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Trond Myklebustbca79472009-03-11 14:10:26 -0400768static const umode_t nfs_type2fmt[] = {
769 [NF4BAD] = 0,
770 [NF4REG] = S_IFREG,
771 [NF4DIR] = S_IFDIR,
772 [NF4BLK] = S_IFBLK,
773 [NF4CHR] = S_IFCHR,
774 [NF4LNK] = S_IFLNK,
775 [NF4SOCK] = S_IFSOCK,
776 [NF4FIFO] = S_IFIFO,
777 [NF4ATTRDIR] = 0,
778 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779};
780
781struct compound_hdr {
782 int32_t status;
783 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500784 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 uint32_t taglen;
786 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400787 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400788 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789};
790
Benny Halevy13c65ce2009-08-14 17:19:25 +0300791static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
792{
793 __be32 *p = xdr_reserve_space(xdr, nbytes);
794 BUG_ON(!p);
795 return p;
796}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
799{
Al Viro8687b632006-10-19 23:28:48 -0700800 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 p = xdr_reserve_space(xdr, 4 + len);
803 BUG_ON(p == NULL);
804 xdr_encode_opaque(p, str, len);
805}
806
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400807static void encode_compound_hdr(struct xdr_stream *xdr,
808 struct rpc_rqst *req,
809 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
Al Viro8687b632006-10-19 23:28:48 -0700811 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400812 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400813
814 /* initialize running count of expected bytes in reply.
815 * NOTE: the replied tag SHOULD be the same is the one sent,
816 * but this is not required as a MUST for the server to do so. */
817 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
819 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
820 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300821 p = reserve_space(xdr, 4 + hdr->taglen + 8);
822 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300823 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500824 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300825 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500826}
827
828static void encode_nops(struct compound_hdr *hdr)
829{
Andy Adamsonfc931582009-04-01 09:22:31 -0400830 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500831 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832}
833
834static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
835{
Al Viro8687b632006-10-19 23:28:48 -0700836 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
838 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
839 BUG_ON(p == NULL);
840 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
841}
842
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500843static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844{
845 char owner_name[IDMAP_NAMESZ];
846 char owner_group[IDMAP_NAMESZ];
847 int owner_namelen = 0;
848 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700849 __be32 *p;
850 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 int len;
852 uint32_t bmval0 = 0;
853 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
855 /*
856 * We reserve enough space to write the entire attribute buffer at once.
857 * In the worst-case, this would be
858 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
859 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000860 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 */
862 len = 16;
863
864 /* Sigh */
865 if (iap->ia_valid & ATTR_SIZE)
866 len += 8;
867 if (iap->ia_valid & ATTR_MODE)
868 len += 4;
869 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800870 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400872 dprintk("nfs: couldn't resolve uid %d to string\n",
873 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 /* XXX */
875 strcpy(owner_name, "nobody");
876 owner_namelen = sizeof("nobody") - 1;
877 /* goto out; */
878 }
879 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
880 }
881 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800882 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400884 dprintk("nfs: couldn't resolve gid %d to string\n",
885 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 strcpy(owner_group, "nobody");
887 owner_grouplen = sizeof("nobody") - 1;
888 /* goto out; */
889 }
890 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
891 }
892 if (iap->ia_valid & ATTR_ATIME_SET)
893 len += 16;
894 else if (iap->ia_valid & ATTR_ATIME)
895 len += 4;
896 if (iap->ia_valid & ATTR_MTIME_SET)
897 len += 16;
898 else if (iap->ia_valid & ATTR_MTIME)
899 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300900 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
902 /*
903 * We write the bitmap length now, but leave the bitmap and the attribute
904 * buffer length to be backfilled at the end of this routine.
905 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300906 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 q = p;
908 p += 3;
909
910 if (iap->ia_valid & ATTR_SIZE) {
911 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300912 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 }
914 if (iap->ia_valid & ATTR_MODE) {
915 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300916 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 }
918 if (iap->ia_valid & ATTR_UID) {
919 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300920 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 }
922 if (iap->ia_valid & ATTR_GID) {
923 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300924 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 }
926 if (iap->ia_valid & ATTR_ATIME_SET) {
927 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300928 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
929 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -0400930 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
931 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 }
933 else if (iap->ia_valid & ATTR_ATIME) {
934 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300935 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 }
937 if (iap->ia_valid & ATTR_MTIME_SET) {
938 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300939 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
940 *p++ = cpu_to_be32(0);
941 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
942 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 }
944 else if (iap->ia_valid & ATTR_MTIME) {
945 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300946 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500948
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 /*
950 * Now we backfill the bitmap and the attribute buffer length.
951 */
952 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400953 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 len, ((char *)p - (char *)q) + 4);
955 BUG();
956 }
957 len = (char *)p - (char *)q - 12;
958 *q++ = htonl(bmval0);
959 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300960 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963}
964
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500965static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
Al Viro8687b632006-10-19 23:28:48 -0700967 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
Benny Halevy13c65ce2009-08-14 17:19:25 +0300969 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300970 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +0300971 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500972 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400973 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974}
975
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500976static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977{
Al Viro8687b632006-10-19 23:28:48 -0700978 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
Benny Halevy13c65ce2009-08-14 17:19:25 +0300980 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300981 *p++ = cpu_to_be32(OP_CLOSE);
982 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +0300983 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500984 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400985 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986}
987
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500988static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989{
Al Viro8687b632006-10-19 23:28:48 -0700990 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500991
Benny Halevy13c65ce2009-08-14 17:19:25 +0300992 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300993 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +0300994 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +0300995 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500996 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400997 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998}
999
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001000static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001{
Al Viro8687b632006-10-19 23:28:48 -07001002 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001003
Benny Halevy13c65ce2009-08-14 17:19:25 +03001004 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001005 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001006 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
1008 switch (create->ftype) {
1009 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001010 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001011 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001012 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 break;
1014
1015 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001016 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001017 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001018 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 break;
1020
1021 default:
1022 break;
1023 }
1024
Benny Halevy811652b2009-08-14 17:19:34 +03001025 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001026 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001027 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001029 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030}
1031
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001032static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033{
Andy Adamson05d564f2008-12-23 16:06:15 -05001034 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
Benny Halevy13c65ce2009-08-14 17:19:25 +03001036 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001037 *p++ = cpu_to_be32(OP_GETATTR);
1038 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001039 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001040 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001041 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042}
1043
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001044static 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 -07001045{
Andy Adamson05d564f2008-12-23 16:06:15 -05001046 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Benny Halevy13c65ce2009-08-14 17:19:25 +03001048 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001049 *p++ = cpu_to_be32(OP_GETATTR);
1050 *p++ = cpu_to_be32(2);
1051 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001052 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001053 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001054 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055}
1056
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001057static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001059 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1060 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061}
1062
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001063static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001065 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1066 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067}
1068
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001069static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001070{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001071 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1072 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001073}
1074
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001075static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076{
Al Viro8687b632006-10-19 23:28:48 -07001077 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
Benny Halevy13c65ce2009-08-14 17:19:25 +03001079 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001080 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001081 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001082 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083}
1084
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001085static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086{
Al Viro8687b632006-10-19 23:28:48 -07001087 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Benny Halevy13c65ce2009-08-14 17:19:25 +03001089 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001090 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001091 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001092 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001093 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094}
1095
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001096static inline int nfs4_lock_type(struct file_lock *fl, int block)
1097{
1098 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1099 return block ? NFS4_READW_LT : NFS4_READ_LT;
1100 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1101}
1102
1103static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1104{
1105 if (fl->fl_end == OFFSET_MAX)
1106 return ~(uint64_t)0;
1107 return fl->fl_end - fl->fl_start + 1;
1108}
1109
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001110static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1111{
1112 __be32 *p;
1113
Trond Myklebustd035c362010-12-21 10:45:27 -05001114 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001115 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001116 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001117 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001118 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001119 xdr_encode_hyper(p, lowner->id);
1120}
1121
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122/*
1123 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1124 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1125 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001126static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127{
Al Viro8687b632006-10-19 23:28:48 -07001128 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Benny Halevy13c65ce2009-08-14 17:19:25 +03001130 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001131 *p++ = cpu_to_be32(OP_LOCK);
1132 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1133 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001134 p = xdr_encode_hyper(p, args->fl->fl_start);
1135 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001136 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001137 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001138 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001139 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001140 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001141 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001142 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 }
1144 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001145 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001146 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001147 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 }
Andy Adamsond0179312008-12-23 16:06:17 -05001149 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001150 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151}
1152
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001153static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154{
Al Viro8687b632006-10-19 23:28:48 -07001155 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001157 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001158 *p++ = cpu_to_be32(OP_LOCKT);
1159 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001160 p = xdr_encode_hyper(p, args->fl->fl_start);
1161 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001162 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001163 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001164 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165}
1166
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001167static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
Al Viro8687b632006-10-19 23:28:48 -07001169 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Benny Halevy13c65ce2009-08-14 17:19:25 +03001171 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001172 *p++ = cpu_to_be32(OP_LOCKU);
1173 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1174 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001175 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001176 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001177 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001178 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001179 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180}
1181
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001182static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1183{
1184 __be32 *p;
1185
1186 p = reserve_space(xdr, 4);
1187 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1188 encode_lockowner(xdr, lowner);
1189 hdr->nops++;
1190 hdr->replen += decode_release_lockowner_maxsz;
1191}
1192
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001193static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194{
1195 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001196 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Benny Halevy13c65ce2009-08-14 17:19:25 +03001198 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001199 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001200 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001201 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001202 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203}
1204
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001205static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206{
Al Viro8687b632006-10-19 23:28:48 -07001207 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
Benny Halevy13c65ce2009-08-14 17:19:25 +03001209 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001210 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001211 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001212 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001213 break;
1214 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001215 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001216 break;
1217 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001218 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001219 break;
1220 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001221 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 }
Benny Halevy34558512009-08-14 17:19:30 +03001223 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224}
1225
1226static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1227{
Al Viro8687b632006-10-19 23:28:48 -07001228 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 /*
1230 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1231 * owner 4 = 32
1232 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001233 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001234 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001235 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001236 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001237 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001238 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001239 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001240 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001241 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001242 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243}
1244
1245static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1246{
Al Viro8687b632006-10-19 23:28:48 -07001247 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001248 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
Benny Halevy13c65ce2009-08-14 17:19:25 +03001250 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001252 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001253 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001254 encode_attrs(xdr, arg->u.attrs, arg->server);
1255 break;
1256 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001257 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001258 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001259 if (nfs4_has_persistent_session(clp)) {
1260 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1261 encode_attrs(xdr, arg->u.attrs, arg->server);
1262 } else {
1263 struct iattr dummy;
1264
1265 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1266 encode_nfs4_verifier(xdr, &arg->u.verifier);
1267 dummy.ia_valid = 0;
1268 encode_attrs(xdr, &dummy, arg->server);
1269 }
1270 } else {
1271 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1272 encode_nfs4_verifier(xdr, &arg->u.verifier);
1273 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 }
1275}
1276
1277static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1278{
Al Viro8687b632006-10-19 23:28:48 -07001279 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
Benny Halevy13c65ce2009-08-14 17:19:25 +03001281 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001283 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001284 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001285 break;
1286 default:
1287 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001288 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001289 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 }
1291}
1292
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001293static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294{
Al Viro8687b632006-10-19 23:28:48 -07001295 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
Benny Halevy13c65ce2009-08-14 17:19:25 +03001297 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001299 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001300 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001301 break;
1302 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001303 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001304 break;
1305 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001306 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001307 break;
1308 default:
1309 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 }
1311}
1312
1313static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1314{
Al Viro8687b632006-10-19 23:28:48 -07001315 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316
Benny Halevy13c65ce2009-08-14 17:19:25 +03001317 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001318 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 encode_string(xdr, name->len, name->name);
1320}
1321
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001322static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323{
Al Viro8687b632006-10-19 23:28:48 -07001324 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
Benny Halevy13c65ce2009-08-14 17:19:25 +03001326 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001327 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 encode_delegation_type(xdr, type);
1329}
1330
1331static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1332{
Al Viro8687b632006-10-19 23:28:48 -07001333 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
Benny Halevy13c65ce2009-08-14 17:19:25 +03001335 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001336 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001337 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 encode_string(xdr, name->len, name->name);
1339}
1340
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001341static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342{
1343 encode_openhdr(xdr, arg);
1344 encode_opentype(xdr, arg);
1345 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001346 case NFS4_OPEN_CLAIM_NULL:
1347 encode_claim_null(xdr, arg->name);
1348 break;
1349 case NFS4_OPEN_CLAIM_PREVIOUS:
1350 encode_claim_previous(xdr, arg->u.delegation_type);
1351 break;
1352 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1353 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1354 break;
1355 default:
1356 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 }
Andy Adamsond0179312008-12-23 16:06:17 -05001358 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001359 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360}
1361
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001362static 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 -07001363{
Al Viro8687b632006-10-19 23:28:48 -07001364 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Benny Halevy13c65ce2009-08-14 17:19:25 +03001366 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001367 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001368 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001369 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001370 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001371 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372}
1373
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001374static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375{
Al Viro8687b632006-10-19 23:28:48 -07001376 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
Benny Halevy13c65ce2009-08-14 17:19:25 +03001378 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001379 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001380 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001381 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001382 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001383 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001384 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385}
1386
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001387static void
Andy Adamsond0179312008-12-23 16:06:17 -05001388encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389{
1390 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001391 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
Benny Halevy13c65ce2009-08-14 17:19:25 +03001393 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001394 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001395 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001396 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001397 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398}
1399
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001400static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401{
Andy Adamson05d564f2008-12-23 16:06:15 -05001402 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001403
Benny Halevy13c65ce2009-08-14 17:19:25 +03001404 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001405 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001406 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001407 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408}
1409
Andy Adamson89d1ea62011-03-01 01:34:09 +00001410static 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 -07001411{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001413 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Benny Halevy13c65ce2009-08-14 17:19:25 +03001415 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001417 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001418 if (zero_seqid)
1419 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001420 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 } else
Benny Halevy34558512009-08-14 17:19:30 +03001422 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423}
1424
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001425static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426{
Al Viro8687b632006-10-19 23:28:48 -07001427 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
Benny Halevy13c65ce2009-08-14 17:19:25 +03001429 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001430 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
Andy Adamson89d1ea62011-03-01 01:34:09 +00001432 encode_stateid(xdr, args->context, args->lock_context,
1433 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
Benny Halevy13c65ce2009-08-14 17:19:25 +03001435 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001436 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001437 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001438 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001439 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440}
1441
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001442static 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 -07001443{
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001444 uint32_t attrs[2] = {0, 0};
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001445 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001446 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001448 if (readdir->plus) {
1449 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1450 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE;
1451 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1452 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1453 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1454 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001455 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001456 }
1457 attrs[0] |= FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID;
1458 attrs[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001459 /* Switch to mounted_on_fileid if the server supports it */
1460 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1461 attrs[0] &= ~FATTR4_WORD0_FILEID;
1462 else
1463 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001464
Benny Halevy13c65ce2009-08-14 17:19:25 +03001465 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001466 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001467 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001468 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001469 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001470 *p++ = cpu_to_be32(readdir->count);
1471 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001472
Benny Halevye75bc1c2009-08-14 17:18:54 +03001473 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001474 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001475 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001476 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001477 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1478 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001479 (unsigned long long)readdir->cookie,
1480 ((u32 *)readdir->verifier.data)[0],
1481 ((u32 *)readdir->verifier.data)[1],
1482 attrs[0] & readdir->bitmask[0],
1483 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484}
1485
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001486static 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 -07001487{
Al Viro8687b632006-10-19 23:28:48 -07001488 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
Benny Halevy13c65ce2009-08-14 17:19:25 +03001490 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001491 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001492 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001493 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494}
1495
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001496static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497{
Al Viro8687b632006-10-19 23:28:48 -07001498 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
Benny Halevy13c65ce2009-08-14 17:19:25 +03001500 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001501 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001502 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001503 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001504 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505}
1506
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001507static 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 -07001508{
Al Viro8687b632006-10-19 23:28:48 -07001509 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Benny Halevy811652b2009-08-14 17:19:34 +03001511 p = reserve_space(xdr, 4);
1512 *p = cpu_to_be32(OP_RENAME);
1513 encode_string(xdr, oldname->len, oldname->name);
1514 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001515 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001516 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517}
1518
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001519static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520{
Al Viro8687b632006-10-19 23:28:48 -07001521 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
Benny Halevy13c65ce2009-08-14 17:19:25 +03001523 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001524 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001525 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001526 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001527 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528}
1529
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001530static void
Andy Adamsond0179312008-12-23 16:06:17 -05001531encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001532{
Al Viro8687b632006-10-19 23:28:48 -07001533 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001534
Benny Halevy13c65ce2009-08-14 17:19:25 +03001535 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001536 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001537 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001538 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001539}
1540
Chuck Lever9f06c712010-12-14 14:59:18 +00001541static void
Andy Adamsond0179312008-12-23 16:06:17 -05001542encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001543{
Al Viro8687b632006-10-19 23:28:48 -07001544 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001545
Benny Halevy13c65ce2009-08-14 17:19:25 +03001546 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001547 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001548 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001549 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001550 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001551 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001552 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001553 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001554 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001555 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001556 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001557 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001558}
1559
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001560static void
Andy Adamsond0179312008-12-23 16:06:17 -05001561encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562{
Al Viro8687b632006-10-19 23:28:48 -07001563 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
Benny Halevy13c65ce2009-08-14 17:19:25 +03001565 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001566 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001567 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001568 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569}
1570
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001571static 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 -07001572{
Al Viro8687b632006-10-19 23:28:48 -07001573 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001574
Benny Halevy13c65ce2009-08-14 17:19:25 +03001575 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001576 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001577 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001578 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001579 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001580 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581}
1582
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001583static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584{
Al Viro8687b632006-10-19 23:28:48 -07001585 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586
Benny Halevy13c65ce2009-08-14 17:19:25 +03001587 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001588 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001589 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
1591 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001592 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001593 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1595 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001596 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001597 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001598 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001599 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600}
1601
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001602static 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 -07001603{
Andy Adamson05d564f2008-12-23 16:06:15 -05001604 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
Benny Halevy13c65ce2009-08-14 17:19:25 +03001606 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001607 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001608 p = xdr_encode_hyper(p, arg->clientid);
1609 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001610 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001611 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612}
1613
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001614static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615{
Al Viro8687b632006-10-19 23:28:48 -07001616 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
Benny Halevy13c65ce2009-08-14 17:19:25 +03001618 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001619 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
Andy Adamson89d1ea62011-03-01 01:34:09 +00001621 encode_stateid(xdr, args->context, args->lock_context,
1622 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623
Benny Halevy13c65ce2009-08-14 17:19:25 +03001624 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001625 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001626 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001627 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628
1629 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001630 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001631 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632}
1633
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001634static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635{
Al Viro8687b632006-10-19 23:28:48 -07001636 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
Benny Halevy13c65ce2009-08-14 17:19:25 +03001638 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
Benny Halevye75bc1c2009-08-14 17:18:54 +03001640 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001641 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001642 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001643 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001645
Benny Halevy99fe60d2009-04-01 09:22:29 -04001646#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001647/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001648static void encode_exchange_id(struct xdr_stream *xdr,
1649 struct nfs41_exchange_id_args *args,
1650 struct compound_hdr *hdr)
1651{
1652 __be32 *p;
1653
Benny Halevy13c65ce2009-08-14 17:19:25 +03001654 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001655 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001656 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001657
1658 encode_string(xdr, args->id_len, args->id);
1659
Benny Halevy13c65ce2009-08-14 17:19:25 +03001660 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001661 *p++ = cpu_to_be32(args->flags);
1662 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001663 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001664 hdr->nops++;
1665 hdr->replen += decode_exchange_id_maxsz;
1666}
Andy Adamsonfc931582009-04-01 09:22:31 -04001667
1668static void encode_create_session(struct xdr_stream *xdr,
1669 struct nfs41_create_session_args *args,
1670 struct compound_hdr *hdr)
1671{
1672 __be32 *p;
1673 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1674 uint32_t len;
1675 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001676 u32 max_resp_sz_cached;
1677
1678 /*
1679 * Assumes OPEN is the biggest non-idempotent compound.
1680 * 2 is the verifier.
1681 */
1682 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1683 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001684
Andy Adamsonfc931582009-04-01 09:22:31 -04001685 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1686 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001687
Benny Halevy13c65ce2009-08-14 17:19:25 +03001688 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001689 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001690 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001691 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1692 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001693
Andy Adamsonfc931582009-04-01 09:22:31 -04001694 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001695 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1696 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1697 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001698 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001699 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1700 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1701 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001702
1703 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001704 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1705 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1706 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1707 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1708 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1709 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1710 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001711
Benny Halevye75bc1c2009-08-14 17:18:54 +03001712 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001713 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001714 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001715
1716 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001717 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001718 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001719 *p++ = cpu_to_be32(0); /* UID */
1720 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001721 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001722 hdr->nops++;
1723 hdr->replen += decode_create_session_maxsz;
1724}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001725
1726static void encode_destroy_session(struct xdr_stream *xdr,
1727 struct nfs4_session *session,
1728 struct compound_hdr *hdr)
1729{
1730 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001731 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001732 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001733 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001734 hdr->nops++;
1735 hdr->replen += decode_destroy_session_maxsz;
1736}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001737
1738static void encode_reclaim_complete(struct xdr_stream *xdr,
1739 struct nfs41_reclaim_complete_args *args,
1740 struct compound_hdr *hdr)
1741{
1742 __be32 *p;
1743
1744 p = reserve_space(xdr, 8);
1745 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1746 *p++ = cpu_to_be32(args->one_fs);
1747 hdr->nops++;
1748 hdr->replen += decode_reclaim_complete_maxsz;
1749}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001750#endif /* CONFIG_NFS_V4_1 */
1751
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001752static void encode_sequence(struct xdr_stream *xdr,
1753 const struct nfs4_sequence_args *args,
1754 struct compound_hdr *hdr)
1755{
1756#if defined(CONFIG_NFS_V4_1)
1757 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001758 struct nfs4_slot_table *tp;
1759 struct nfs4_slot *slot;
1760 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001761
1762 if (!session)
1763 return;
1764
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001765 tp = &session->fc_slot_table;
1766
1767 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1768 slot = tp->slots + args->sa_slotid;
1769
Benny Halevy13c65ce2009-08-14 17:19:25 +03001770 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001771 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001772
1773 /*
1774 * Sessionid + seqid + slotid + max slotid + cache_this
1775 */
1776 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1777 "max_slotid=%d cache_this=%d\n",
1778 __func__,
1779 ((u32 *)session->sess_id.data)[0],
1780 ((u32 *)session->sess_id.data)[1],
1781 ((u32 *)session->sess_id.data)[2],
1782 ((u32 *)session->sess_id.data)[3],
1783 slot->seq_nr, args->sa_slotid,
1784 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001785 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001786 *p++ = cpu_to_be32(slot->seq_nr);
1787 *p++ = cpu_to_be32(args->sa_slotid);
1788 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001789 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001790 hdr->nops++;
1791 hdr->replen += decode_sequence_maxsz;
1792#endif /* CONFIG_NFS_V4_1 */
1793}
1794
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001795#ifdef CONFIG_NFS_V4_1
1796static void
1797encode_getdeviceinfo(struct xdr_stream *xdr,
1798 const struct nfs4_getdeviceinfo_args *args,
1799 struct compound_hdr *hdr)
1800{
1801 __be32 *p;
1802
1803 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1804 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1805 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1806 NFS4_DEVICEID4_SIZE);
1807 *p++ = cpu_to_be32(args->pdev->layout_type);
1808 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1809 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1810 hdr->nops++;
1811 hdr->replen += decode_getdeviceinfo_maxsz;
1812}
1813
1814static void
1815encode_layoutget(struct xdr_stream *xdr,
1816 const struct nfs4_layoutget_args *args,
1817 struct compound_hdr *hdr)
1818{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001819 __be32 *p;
1820
1821 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1822 *p++ = cpu_to_be32(OP_LAYOUTGET);
1823 *p++ = cpu_to_be32(0); /* Signal layout available */
1824 *p++ = cpu_to_be32(args->type);
1825 *p++ = cpu_to_be32(args->range.iomode);
1826 p = xdr_encode_hyper(p, args->range.offset);
1827 p = xdr_encode_hyper(p, args->range.length);
1828 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00001829 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001830 *p = cpu_to_be32(args->maxcount);
1831
1832 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1833 __func__,
1834 args->type,
1835 args->range.iomode,
1836 (unsigned long)args->range.offset,
1837 (unsigned long)args->range.length,
1838 args->maxcount);
1839 hdr->nops++;
1840 hdr->replen += decode_layoutget_maxsz;
1841}
Andy Adamson863a3c62011-03-23 13:27:54 +00001842
1843static int
1844encode_layoutcommit(struct xdr_stream *xdr,
1845 const struct nfs4_layoutcommit_args *args,
1846 struct compound_hdr *hdr)
1847{
1848 __be32 *p;
1849
1850 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1851 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1852
1853 p = reserve_space(xdr, 48 + NFS4_STATEID_SIZE);
1854 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1855 /* Only whole file layouts */
1856 p = xdr_encode_hyper(p, 0); /* offset */
1857 p = xdr_encode_hyper(p, NFS4_MAX_UINT64); /* length */
1858 *p++ = cpu_to_be32(0); /* reclaim */
1859 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1860 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1861 p = xdr_encode_hyper(p, args->lastbytewritten);
1862 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1863 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1864 *p++ = cpu_to_be32(0); /* no file layout payload */
1865
1866 hdr->nops++;
1867 hdr->replen += decode_layoutcommit_maxsz;
1868 return 0;
1869}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001870#endif /* CONFIG_NFS_V4_1 */
1871
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872/*
1873 * END OF "GENERIC" ENCODE ROUTINES.
1874 */
1875
Benny Halevy66cc0422009-04-01 09:22:10 -04001876static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1877{
1878#if defined(CONFIG_NFS_V4_1)
1879 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001880 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001881#endif /* CONFIG_NFS_V4_1 */
1882 return 0;
1883}
1884
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885/*
1886 * Encode an ACCESS request
1887 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001888static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1889 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001892 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894
Chuck Lever9f06c712010-12-14 14:59:18 +00001895 encode_compound_hdr(xdr, req, &hdr);
1896 encode_sequence(xdr, &args->seq_args, &hdr);
1897 encode_putfh(xdr, args->fh, &hdr);
1898 encode_access(xdr, args->access, &hdr);
1899 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001900 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901}
1902
1903/*
1904 * Encode LOOKUP request
1905 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001906static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1907 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001910 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
Chuck Lever9f06c712010-12-14 14:59:18 +00001913 encode_compound_hdr(xdr, req, &hdr);
1914 encode_sequence(xdr, &args->seq_args, &hdr);
1915 encode_putfh(xdr, args->dir_fh, &hdr);
1916 encode_lookup(xdr, args->name, &hdr);
1917 encode_getfh(xdr, &hdr);
1918 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001919 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920}
1921
1922/*
1923 * Encode LOOKUP_ROOT request
1924 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001925static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
1926 struct xdr_stream *xdr,
1927 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001930 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
Chuck Lever9f06c712010-12-14 14:59:18 +00001933 encode_compound_hdr(xdr, req, &hdr);
1934 encode_sequence(xdr, &args->seq_args, &hdr);
1935 encode_putrootfh(xdr, &hdr);
1936 encode_getfh(xdr, &hdr);
1937 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001938 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939}
1940
1941/*
1942 * Encode REMOVE request
1943 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001944static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
1945 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001948 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
Chuck Lever9f06c712010-12-14 14:59:18 +00001951 encode_compound_hdr(xdr, req, &hdr);
1952 encode_sequence(xdr, &args->seq_args, &hdr);
1953 encode_putfh(xdr, args->fh, &hdr);
1954 encode_remove(xdr, &args->name, &hdr);
1955 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001956 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957}
1958
1959/*
1960 * Encode RENAME request
1961 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001962static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
1963 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001966 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968
Chuck Lever9f06c712010-12-14 14:59:18 +00001969 encode_compound_hdr(xdr, req, &hdr);
1970 encode_sequence(xdr, &args->seq_args, &hdr);
1971 encode_putfh(xdr, args->old_dir, &hdr);
1972 encode_savefh(xdr, &hdr);
1973 encode_putfh(xdr, args->new_dir, &hdr);
1974 encode_rename(xdr, args->old_name, args->new_name, &hdr);
1975 encode_getfattr(xdr, args->bitmask, &hdr);
1976 encode_restorefh(xdr, &hdr);
1977 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001978 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979}
1980
1981/*
1982 * Encode LINK request
1983 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001984static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
1985 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001988 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
Chuck Lever9f06c712010-12-14 14:59:18 +00001991 encode_compound_hdr(xdr, req, &hdr);
1992 encode_sequence(xdr, &args->seq_args, &hdr);
1993 encode_putfh(xdr, args->fh, &hdr);
1994 encode_savefh(xdr, &hdr);
1995 encode_putfh(xdr, args->dir_fh, &hdr);
1996 encode_link(xdr, args->name, &hdr);
1997 encode_getfattr(xdr, args->bitmask, &hdr);
1998 encode_restorefh(xdr, &hdr);
1999 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002000 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001}
2002
2003/*
2004 * Encode CREATE request
2005 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002006static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2007 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002010 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012
Chuck Lever9f06c712010-12-14 14:59:18 +00002013 encode_compound_hdr(xdr, req, &hdr);
2014 encode_sequence(xdr, &args->seq_args, &hdr);
2015 encode_putfh(xdr, args->dir_fh, &hdr);
2016 encode_savefh(xdr, &hdr);
2017 encode_create(xdr, args, &hdr);
2018 encode_getfh(xdr, &hdr);
2019 encode_getfattr(xdr, args->bitmask, &hdr);
2020 encode_restorefh(xdr, &hdr);
2021 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002022 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023}
2024
2025/*
2026 * Encode SYMLINK request
2027 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002028static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2029 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030{
Chuck Lever9f06c712010-12-14 14:59:18 +00002031 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032}
2033
2034/*
2035 * Encode GETATTR request
2036 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002037static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2038 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002041 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043
Chuck Lever9f06c712010-12-14 14:59:18 +00002044 encode_compound_hdr(xdr, req, &hdr);
2045 encode_sequence(xdr, &args->seq_args, &hdr);
2046 encode_putfh(xdr, args->fh, &hdr);
2047 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002048 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049}
2050
2051/*
2052 * Encode a CLOSE request
2053 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002054static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2055 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056{
Andy Adamson05d564f2008-12-23 16:06:15 -05002057 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002058 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002059 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
Chuck Lever9f06c712010-12-14 14:59:18 +00002061 encode_compound_hdr(xdr, req, &hdr);
2062 encode_sequence(xdr, &args->seq_args, &hdr);
2063 encode_putfh(xdr, args->fh, &hdr);
2064 encode_close(xdr, args, &hdr);
2065 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002066 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067}
2068
2069/*
2070 * Encode an OPEN request
2071 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002072static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2073 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002076 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078
Chuck Lever9f06c712010-12-14 14:59:18 +00002079 encode_compound_hdr(xdr, req, &hdr);
2080 encode_sequence(xdr, &args->seq_args, &hdr);
2081 encode_putfh(xdr, args->fh, &hdr);
2082 encode_savefh(xdr, &hdr);
2083 encode_open(xdr, args, &hdr);
2084 encode_getfh(xdr, &hdr);
2085 encode_getfattr(xdr, args->bitmask, &hdr);
2086 encode_restorefh(xdr, &hdr);
2087 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002088 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089}
2090
2091/*
2092 * Encode an OPEN_CONFIRM request
2093 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002094static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2095 struct xdr_stream *xdr,
2096 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002099 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
Chuck Lever9f06c712010-12-14 14:59:18 +00002102 encode_compound_hdr(xdr, req, &hdr);
2103 encode_putfh(xdr, args->fh, &hdr);
2104 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002105 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}
2107
2108/*
2109 * Encode an OPEN request with no attributes.
2110 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002111static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2112 struct xdr_stream *xdr,
2113 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002116 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
Chuck Lever9f06c712010-12-14 14:59:18 +00002119 encode_compound_hdr(xdr, req, &hdr);
2120 encode_sequence(xdr, &args->seq_args, &hdr);
2121 encode_putfh(xdr, args->fh, &hdr);
2122 encode_open(xdr, args, &hdr);
2123 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002124 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125}
2126
2127/*
2128 * Encode an OPEN_DOWNGRADE request
2129 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002130static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2131 struct xdr_stream *xdr,
2132 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002135 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
Chuck Lever9f06c712010-12-14 14:59:18 +00002138 encode_compound_hdr(xdr, req, &hdr);
2139 encode_sequence(xdr, &args->seq_args, &hdr);
2140 encode_putfh(xdr, args->fh, &hdr);
2141 encode_open_downgrade(xdr, args, &hdr);
2142 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002143 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144}
2145
2146/*
2147 * Encode a LOCK request
2148 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002149static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2150 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002153 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
Chuck Lever9f06c712010-12-14 14:59:18 +00002156 encode_compound_hdr(xdr, req, &hdr);
2157 encode_sequence(xdr, &args->seq_args, &hdr);
2158 encode_putfh(xdr, args->fh, &hdr);
2159 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002160 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161}
2162
2163/*
2164 * Encode a LOCKT request
2165 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002166static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2167 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002170 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
Chuck Lever9f06c712010-12-14 14:59:18 +00002173 encode_compound_hdr(xdr, req, &hdr);
2174 encode_sequence(xdr, &args->seq_args, &hdr);
2175 encode_putfh(xdr, args->fh, &hdr);
2176 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002177 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178}
2179
2180/*
2181 * Encode a LOCKU request
2182 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002183static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2184 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002187 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189
Chuck Lever9f06c712010-12-14 14:59:18 +00002190 encode_compound_hdr(xdr, req, &hdr);
2191 encode_sequence(xdr, &args->seq_args, &hdr);
2192 encode_putfh(xdr, args->fh, &hdr);
2193 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002194 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195}
2196
Chuck Lever9f06c712010-12-14 14:59:18 +00002197static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2198 struct xdr_stream *xdr,
2199 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002200{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002201 struct compound_hdr hdr = {
2202 .minorversion = 0,
2203 };
2204
Chuck Lever9f06c712010-12-14 14:59:18 +00002205 encode_compound_hdr(xdr, req, &hdr);
2206 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002207 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002208}
2209
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210/*
2211 * Encode a READLINK request
2212 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002213static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2214 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002217 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219
Chuck Lever9f06c712010-12-14 14:59:18 +00002220 encode_compound_hdr(xdr, req, &hdr);
2221 encode_sequence(xdr, &args->seq_args, &hdr);
2222 encode_putfh(xdr, args->fh, &hdr);
2223 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002224
Benny Halevy28f56692009-04-01 09:22:09 -04002225 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002226 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002227 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228}
2229
2230/*
2231 * Encode a READDIR request
2232 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002233static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2234 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002237 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239
Chuck Lever9f06c712010-12-14 14:59:18 +00002240 encode_compound_hdr(xdr, req, &hdr);
2241 encode_sequence(xdr, &args->seq_args, &hdr);
2242 encode_putfh(xdr, args->fh, &hdr);
2243 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002244
Benny Halevy28f56692009-04-01 09:22:09 -04002245 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002246 args->pgbase, args->count);
2247 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002248 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002249 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002250 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251}
2252
2253/*
2254 * Encode a READ request
2255 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002256static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2257 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002260 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
Chuck Lever9f06c712010-12-14 14:59:18 +00002263 encode_compound_hdr(xdr, req, &hdr);
2264 encode_sequence(xdr, &args->seq_args, &hdr);
2265 encode_putfh(xdr, args->fh, &hdr);
2266 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
Benny Halevy28f56692009-04-01 09:22:09 -04002268 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002270 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002271 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272}
2273
2274/*
2275 * Encode an SETATTR request
2276 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002277static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2278 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279{
Andy Adamson05d564f2008-12-23 16:06:15 -05002280 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002281 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002282 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283
Chuck Lever9f06c712010-12-14 14:59:18 +00002284 encode_compound_hdr(xdr, req, &hdr);
2285 encode_sequence(xdr, &args->seq_args, &hdr);
2286 encode_putfh(xdr, args->fh, &hdr);
2287 encode_setattr(xdr, args, args->server, &hdr);
2288 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002289 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290}
2291
2292/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002293 * Encode a GETACL request
2294 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002295static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2296 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002297{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002298 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002299 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002300 };
Benny Halevy28f56692009-04-01 09:22:09 -04002301 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002302
Chuck Lever9f06c712010-12-14 14:59:18 +00002303 encode_compound_hdr(xdr, req, &hdr);
2304 encode_sequence(xdr, &args->seq_args, &hdr);
2305 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002306 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002307 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002308
Benny Halevy28f56692009-04-01 09:22:09 -04002309 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002310 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002311 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002312}
2313
2314/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 * Encode a WRITE request
2316 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002317static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2318 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002321 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323
Chuck Lever9f06c712010-12-14 14:59:18 +00002324 encode_compound_hdr(xdr, req, &hdr);
2325 encode_sequence(xdr, &args->seq_args, &hdr);
2326 encode_putfh(xdr, args->fh, &hdr);
2327 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002328 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002329 if (args->bitmask)
2330 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002331 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332}
2333
2334/*
2335 * a COMMIT request
2336 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002337static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2338 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002341 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343
Chuck Lever9f06c712010-12-14 14:59:18 +00002344 encode_compound_hdr(xdr, req, &hdr);
2345 encode_sequence(xdr, &args->seq_args, &hdr);
2346 encode_putfh(xdr, args->fh, &hdr);
2347 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002348 if (args->bitmask)
2349 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002350 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351}
2352
2353/*
2354 * FSINFO request
2355 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002356static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2357 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002360 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
Chuck Lever9f06c712010-12-14 14:59:18 +00002363 encode_compound_hdr(xdr, req, &hdr);
2364 encode_sequence(xdr, &args->seq_args, &hdr);
2365 encode_putfh(xdr, args->fh, &hdr);
2366 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002367 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368}
2369
2370/*
2371 * a PATHCONF request
2372 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002373static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2374 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002377 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379
Chuck Lever9f06c712010-12-14 14:59:18 +00002380 encode_compound_hdr(xdr, req, &hdr);
2381 encode_sequence(xdr, &args->seq_args, &hdr);
2382 encode_putfh(xdr, args->fh, &hdr);
2383 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002384 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002385 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386}
2387
2388/*
2389 * a STATFS request
2390 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002391static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2392 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002395 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397
Chuck Lever9f06c712010-12-14 14:59:18 +00002398 encode_compound_hdr(xdr, req, &hdr);
2399 encode_sequence(xdr, &args->seq_args, &hdr);
2400 encode_putfh(xdr, args->fh, &hdr);
2401 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002402 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002403 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404}
2405
2406/*
2407 * GETATTR_BITMAP request
2408 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002409static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2410 struct xdr_stream *xdr,
2411 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002414 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416
Chuck Lever9f06c712010-12-14 14:59:18 +00002417 encode_compound_hdr(xdr, req, &hdr);
2418 encode_sequence(xdr, &args->seq_args, &hdr);
2419 encode_putfh(xdr, args->fhandle, &hdr);
2420 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002421 FATTR4_WORD0_LINK_SUPPORT|
2422 FATTR4_WORD0_SYMLINK_SUPPORT|
2423 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002424 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425}
2426
2427/*
2428 * a RENEW request
2429 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002430static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2431 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002434 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 };
2436
Chuck Lever9f06c712010-12-14 14:59:18 +00002437 encode_compound_hdr(xdr, req, &hdr);
2438 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002439 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440}
2441
2442/*
2443 * a SETCLIENTID request
2444 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002445static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2446 struct xdr_stream *xdr,
2447 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002450 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 };
2452
Chuck Lever9f06c712010-12-14 14:59:18 +00002453 encode_compound_hdr(xdr, req, &hdr);
2454 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002455 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456}
2457
2458/*
2459 * a SETCLIENTID_CONFIRM request
2460 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002461static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2462 struct xdr_stream *xdr,
2463 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002466 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 };
2468 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469
Chuck Lever9f06c712010-12-14 14:59:18 +00002470 encode_compound_hdr(xdr, req, &hdr);
2471 encode_setclientid_confirm(xdr, arg, &hdr);
2472 encode_putrootfh(xdr, &hdr);
2473 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002474 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475}
2476
2477/*
2478 * DELEGRETURN request
2479 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002480static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2481 struct xdr_stream *xdr,
2482 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002485 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
Chuck Lever9f06c712010-12-14 14:59:18 +00002488 encode_compound_hdr(xdr, req, &hdr);
2489 encode_sequence(xdr, &args->seq_args, &hdr);
2490 encode_putfh(xdr, args->fhandle, &hdr);
2491 encode_delegreturn(xdr, args->stateid, &hdr);
2492 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002493 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494}
2495
2496/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002497 * Encode FS_LOCATIONS request
2498 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002499static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2500 struct xdr_stream *xdr,
2501 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002502{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002503 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002504 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002505 };
Benny Halevy28f56692009-04-01 09:22:09 -04002506 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002507
Chuck Lever9f06c712010-12-14 14:59:18 +00002508 encode_compound_hdr(xdr, req, &hdr);
2509 encode_sequence(xdr, &args->seq_args, &hdr);
2510 encode_putfh(xdr, args->dir_fh, &hdr);
2511 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002512 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002513 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002514
Benny Halevy28f56692009-04-01 09:22:09 -04002515 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002516 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002517 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002518}
2519
Benny Halevy99fe60d2009-04-01 09:22:29 -04002520#if defined(CONFIG_NFS_V4_1)
2521/*
2522 * EXCHANGE_ID request
2523 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002524static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2525 struct xdr_stream *xdr,
2526 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002527{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002528 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002529 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002530 };
2531
Chuck Lever9f06c712010-12-14 14:59:18 +00002532 encode_compound_hdr(xdr, req, &hdr);
2533 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002534 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002535}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002536
2537/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002538 * a CREATE_SESSION request
2539 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002540static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2541 struct xdr_stream *xdr,
2542 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002543{
Andy Adamsonfc931582009-04-01 09:22:31 -04002544 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002545 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002546 };
2547
Chuck Lever9f06c712010-12-14 14:59:18 +00002548 encode_compound_hdr(xdr, req, &hdr);
2549 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002550 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002551}
2552
2553/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002554 * a DESTROY_SESSION request
2555 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002556static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2557 struct xdr_stream *xdr,
2558 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002559{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002560 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002561 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002562 };
2563
Chuck Lever9f06c712010-12-14 14:59:18 +00002564 encode_compound_hdr(xdr, req, &hdr);
2565 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002566 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002567}
2568
2569/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002570 * a SEQUENCE request
2571 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002572static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2573 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002574{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002575 struct compound_hdr hdr = {
2576 .minorversion = nfs4_xdr_minorversion(args),
2577 };
2578
Chuck Lever9f06c712010-12-14 14:59:18 +00002579 encode_compound_hdr(xdr, req, &hdr);
2580 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002581 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002582}
2583
2584/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002585 * a GET_LEASE_TIME request
2586 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002587static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2588 struct xdr_stream *xdr,
2589 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002590{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002591 struct compound_hdr hdr = {
2592 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2593 };
2594 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2595
Chuck Lever9f06c712010-12-14 14:59:18 +00002596 encode_compound_hdr(xdr, req, &hdr);
2597 encode_sequence(xdr, &args->la_seq_args, &hdr);
2598 encode_putrootfh(xdr, &hdr);
2599 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002600 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002601}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002602
2603/*
2604 * a RECLAIM_COMPLETE request
2605 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002606static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2607 struct xdr_stream *xdr,
2608 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002609{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002610 struct compound_hdr hdr = {
2611 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2612 };
2613
Chuck Lever9f06c712010-12-14 14:59:18 +00002614 encode_compound_hdr(xdr, req, &hdr);
2615 encode_sequence(xdr, &args->seq_args, &hdr);
2616 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002617 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002618}
2619
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002620/*
2621 * Encode GETDEVICEINFO request
2622 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002623static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2624 struct xdr_stream *xdr,
2625 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002626{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002627 struct compound_hdr hdr = {
2628 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2629 };
2630
Chuck Lever9f06c712010-12-14 14:59:18 +00002631 encode_compound_hdr(xdr, req, &hdr);
2632 encode_sequence(xdr, &args->seq_args, &hdr);
2633 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002634
2635 /* set up reply kvec. Subtract notification bitmap max size (2)
2636 * so that notification bitmap is put in xdr_buf tail */
2637 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2638 args->pdev->pages, args->pdev->pgbase,
2639 args->pdev->pglen);
2640
2641 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002642}
2643
2644/*
2645 * Encode LAYOUTGET request
2646 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002647static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2648 struct xdr_stream *xdr,
2649 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002650{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002651 struct compound_hdr hdr = {
2652 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2653 };
2654
Chuck Lever9f06c712010-12-14 14:59:18 +00002655 encode_compound_hdr(xdr, req, &hdr);
2656 encode_sequence(xdr, &args->seq_args, &hdr);
2657 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2658 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002659
2660 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2661 args->layout.pages, 0, args->layout.pglen);
2662
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002663 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002664}
Andy Adamson863a3c62011-03-23 13:27:54 +00002665
2666/*
2667 * Encode LAYOUTCOMMIT request
2668 */
2669static int nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2670 struct xdr_stream *xdr,
2671 struct nfs4_layoutcommit_args *args)
2672{
2673 struct compound_hdr hdr = {
2674 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2675 };
2676
2677 encode_compound_hdr(xdr, req, &hdr);
2678 encode_sequence(xdr, &args->seq_args, &hdr);
2679 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2680 encode_layoutcommit(xdr, args, &hdr);
2681 encode_getfattr(xdr, args->bitmask, &hdr);
2682 encode_nops(&hdr);
2683 return 0;
2684}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002685#endif /* CONFIG_NFS_V4_1 */
2686
Benny Halevy686841b2009-08-14 17:19:48 +03002687static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2688{
2689 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2690 "Remaining buffer length is %tu words.\n",
2691 func, xdr->end - xdr->p);
2692}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693
Trond Myklebust683b57b2006-06-09 09:34:22 -04002694static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695{
Al Viro8687b632006-10-19 23:28:48 -07002696 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697
Benny Halevyc0eae662009-08-14 17:20:14 +03002698 p = xdr_inline_decode(xdr, 4);
2699 if (unlikely(!p))
2700 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002701 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002702 p = xdr_inline_decode(xdr, *len);
2703 if (unlikely(!p))
2704 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 *string = (char *)p;
2706 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002707out_overflow:
2708 print_overflow_msg(__func__, xdr);
2709 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710}
2711
2712static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2713{
Al Viro8687b632006-10-19 23:28:48 -07002714 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715
Benny Halevyc0eae662009-08-14 17:20:14 +03002716 p = xdr_inline_decode(xdr, 8);
2717 if (unlikely(!p))
2718 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002719 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002720 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002721
Benny Halevyc0eae662009-08-14 17:20:14 +03002722 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2723 if (unlikely(!p))
2724 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 hdr->tag = (char *)p;
2726 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002727 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002728 if (unlikely(hdr->nops < 1))
2729 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002731out_overflow:
2732 print_overflow_msg(__func__, xdr);
2733 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734}
2735
2736static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2737{
Al Viro8687b632006-10-19 23:28:48 -07002738 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 uint32_t opnum;
2740 int32_t nfserr;
2741
Benny Halevyc0eae662009-08-14 17:20:14 +03002742 p = xdr_inline_decode(xdr, 8);
2743 if (unlikely(!p))
2744 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002745 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002747 dprintk("nfs: Server returned operation"
2748 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 opnum, expected);
2750 return -EIO;
2751 }
Benny Halevycccddf42009-08-14 17:20:19 +03002752 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002754 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002756out_overflow:
2757 print_overflow_msg(__func__, xdr);
2758 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759}
2760
2761/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002762static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763{
Al Viro8687b632006-10-19 23:28:48 -07002764 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002765 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 char *str;
2767
Benny Halevyc0eae662009-08-14 17:20:14 +03002768 p = xdr_inline_decode(xdr, 12);
2769 if (likely(p))
2770 return decode_opaque_inline(xdr, &strlen, &str);
2771 print_overflow_msg(__func__, xdr);
2772 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773}
2774
2775static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2776{
Al Viro8687b632006-10-19 23:28:48 -07002777 uint32_t bmlen;
2778 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779
Benny Halevyc0eae662009-08-14 17:20:14 +03002780 p = xdr_inline_decode(xdr, 4);
2781 if (unlikely(!p))
2782 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002783 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784
2785 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002786 p = xdr_inline_decode(xdr, (bmlen << 2));
2787 if (unlikely(!p))
2788 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002790 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002792 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 }
2794 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002795out_overflow:
2796 print_overflow_msg(__func__, xdr);
2797 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798}
2799
Al Viro8687b632006-10-19 23:28:48 -07002800static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801{
Al Viro8687b632006-10-19 23:28:48 -07002802 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803
Benny Halevyc0eae662009-08-14 17:20:14 +03002804 p = xdr_inline_decode(xdr, 4);
2805 if (unlikely(!p))
2806 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002807 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 *savep = xdr->p;
2809 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002810out_overflow:
2811 print_overflow_msg(__func__, xdr);
2812 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813}
2814
2815static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2816{
2817 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04002818 int ret;
2819 ret = decode_attr_bitmap(xdr, bitmask);
2820 if (unlikely(ret < 0))
2821 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2823 } else
2824 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002825 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 return 0;
2827}
2828
2829static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2830{
Al Viro8687b632006-10-19 23:28:48 -07002831 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002832 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833
2834 *type = 0;
2835 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2836 return -EIO;
2837 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002838 p = xdr_inline_decode(xdr, 4);
2839 if (unlikely(!p))
2840 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002841 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002843 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 return -EIO;
2845 }
2846 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002847 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002849 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002850 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002851out_overflow:
2852 print_overflow_msg(__func__, xdr);
2853 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854}
2855
2856static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2857{
Al Viro8687b632006-10-19 23:28:48 -07002858 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002859 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860
2861 *change = 0;
2862 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2863 return -EIO;
2864 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002865 p = xdr_inline_decode(xdr, 8);
2866 if (unlikely(!p))
2867 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002868 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002870 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002872 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002874 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002875out_overflow:
2876 print_overflow_msg(__func__, xdr);
2877 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878}
2879
2880static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2881{
Al Viro8687b632006-10-19 23:28:48 -07002882 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002883 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884
2885 *size = 0;
2886 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2887 return -EIO;
2888 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002889 p = xdr_inline_decode(xdr, 8);
2890 if (unlikely(!p))
2891 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002892 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002894 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002896 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002897 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002898out_overflow:
2899 print_overflow_msg(__func__, xdr);
2900 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901}
2902
2903static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2904{
Al Viro8687b632006-10-19 23:28:48 -07002905 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906
2907 *res = 0;
2908 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2909 return -EIO;
2910 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002911 p = xdr_inline_decode(xdr, 4);
2912 if (unlikely(!p))
2913 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002914 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2916 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002917 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002919out_overflow:
2920 print_overflow_msg(__func__, xdr);
2921 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922}
2923
2924static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2925{
Al Viro8687b632006-10-19 23:28:48 -07002926 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927
2928 *res = 0;
2929 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2930 return -EIO;
2931 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002932 p = xdr_inline_decode(xdr, 4);
2933 if (unlikely(!p))
2934 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002935 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2937 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002938 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002940out_overflow:
2941 print_overflow_msg(__func__, xdr);
2942 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943}
2944
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002945static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946{
Al Viro8687b632006-10-19 23:28:48 -07002947 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002948 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949
2950 fsid->major = 0;
2951 fsid->minor = 0;
2952 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2953 return -EIO;
2954 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002955 p = xdr_inline_decode(xdr, 16);
2956 if (unlikely(!p))
2957 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03002958 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03002959 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002961 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002963 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 (unsigned long long)fsid->major,
2965 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002966 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002967out_overflow:
2968 print_overflow_msg(__func__, xdr);
2969 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970}
2971
2972static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2973{
Al Viro8687b632006-10-19 23:28:48 -07002974 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975
2976 *res = 60;
2977 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2978 return -EIO;
2979 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002980 p = xdr_inline_decode(xdr, 4);
2981 if (unlikely(!p))
2982 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002983 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2985 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002986 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002988out_overflow:
2989 print_overflow_msg(__func__, xdr);
2990 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991}
2992
Bryan Schumakerae42c702010-10-21 16:33:17 -04002993static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
2994{
2995 __be32 *p;
2996
2997 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
2998 return -EIO;
2999 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3000 p = xdr_inline_decode(xdr, 4);
3001 if (unlikely(!p))
3002 goto out_overflow;
3003 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3004 }
3005 return 0;
3006out_overflow:
3007 print_overflow_msg(__func__, xdr);
3008 return -EIO;
3009}
3010
3011static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3012{
3013 __be32 *p;
3014 int len;
3015
Trond Myklebust7ad07352010-10-23 15:34:20 -04003016 if (fh != NULL)
3017 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003018
3019 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3020 return -EIO;
3021 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3022 p = xdr_inline_decode(xdr, 4);
3023 if (unlikely(!p))
3024 goto out_overflow;
3025 len = be32_to_cpup(p);
3026 if (len > NFS4_FHSIZE)
3027 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003028 p = xdr_inline_decode(xdr, len);
3029 if (unlikely(!p))
3030 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003031 if (fh != NULL) {
3032 memcpy(fh->data, p, len);
3033 fh->size = len;
3034 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003035 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3036 }
3037 return 0;
3038out_overflow:
3039 print_overflow_msg(__func__, xdr);
3040 return -EIO;
3041}
3042
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3044{
Al Viro8687b632006-10-19 23:28:48 -07003045 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046
3047 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3048 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3049 return -EIO;
3050 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003051 p = xdr_inline_decode(xdr, 4);
3052 if (unlikely(!p))
3053 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003054 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3056 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003057 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003059out_overflow:
3060 print_overflow_msg(__func__, xdr);
3061 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062}
3063
3064static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3065{
Al Viro8687b632006-10-19 23:28:48 -07003066 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003067 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068
3069 *fileid = 0;
3070 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3071 return -EIO;
3072 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003073 p = xdr_inline_decode(xdr, 8);
3074 if (unlikely(!p))
3075 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003076 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003078 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003080 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003081 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003082out_overflow:
3083 print_overflow_msg(__func__, xdr);
3084 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085}
3086
Manoj Naik99baf622006-06-09 09:34:24 -04003087static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3088{
Al Viro8687b632006-10-19 23:28:48 -07003089 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003090 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003091
3092 *fileid = 0;
3093 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3094 return -EIO;
3095 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003096 p = xdr_inline_decode(xdr, 8);
3097 if (unlikely(!p))
3098 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003099 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003100 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003101 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003102 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003103 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003104 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003105out_overflow:
3106 print_overflow_msg(__func__, xdr);
3107 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003108}
3109
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3111{
Al Viro8687b632006-10-19 23:28:48 -07003112 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 int status = 0;
3114
3115 *res = 0;
3116 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3117 return -EIO;
3118 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003119 p = xdr_inline_decode(xdr, 8);
3120 if (unlikely(!p))
3121 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003122 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3124 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003125 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 return status;
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_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3133{
Al Viro8687b632006-10-19 23:28:48 -07003134 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 int status = 0;
3136
3137 *res = 0;
3138 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3139 return -EIO;
3140 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003141 p = xdr_inline_decode(xdr, 8);
3142 if (unlikely(!p))
3143 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003144 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3146 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003147 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003149out_overflow:
3150 print_overflow_msg(__func__, xdr);
3151 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152}
3153
3154static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3155{
Al Viro8687b632006-10-19 23:28:48 -07003156 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 int status = 0;
3158
3159 *res = 0;
3160 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3161 return -EIO;
3162 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003163 p = xdr_inline_decode(xdr, 8);
3164 if (unlikely(!p))
3165 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003166 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3168 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003169 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003171out_overflow:
3172 print_overflow_msg(__func__, xdr);
3173 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174}
3175
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003176static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3177{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003178 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003179 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003180 int status = 0;
3181
Benny Halevyc0eae662009-08-14 17:20:14 +03003182 p = xdr_inline_decode(xdr, 4);
3183 if (unlikely(!p))
3184 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003185 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003186 if (n == 0)
3187 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003188 dprintk("path ");
3189 path->ncomponents = 0;
3190 while (path->ncomponents < n) {
3191 struct nfs4_string *component = &path->components[path->ncomponents];
3192 status = decode_opaque_inline(xdr, &component->len, &component->data);
3193 if (unlikely(status != 0))
3194 goto out_eio;
3195 if (path->ncomponents != n)
3196 dprintk("/");
3197 dprintk("%s", component->data);
3198 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3199 path->ncomponents++;
3200 else {
3201 dprintk("cannot parse %d components in path\n", n);
3202 goto out_eio;
3203 }
3204 }
3205out:
3206 dprintk("\n");
3207 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003208root_path:
3209/* a root pathname is sent as a zero component4 */
3210 path->ncomponents = 1;
3211 path->components[0].len=0;
3212 path->components[0].data=NULL;
3213 dprintk("path /\n");
3214 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003215out_eio:
3216 dprintk(" status %d", status);
3217 status = -EIO;
3218 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003219out_overflow:
3220 print_overflow_msg(__func__, xdr);
3221 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003222}
3223
3224static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003225{
3226 int n;
Al Viro8687b632006-10-19 23:28:48 -07003227 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003228 int status = -EIO;
3229
3230 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3231 goto out;
3232 status = 0;
3233 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3234 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003235 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003236 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003237 if (unlikely(status != 0))
3238 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003239 p = xdr_inline_decode(xdr, 4);
3240 if (unlikely(!p))
3241 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003242 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003243 if (n <= 0)
3244 goto out_eio;
3245 res->nlocations = 0;
3246 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003247 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003248 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003249
Benny Halevyc0eae662009-08-14 17:20:14 +03003250 p = xdr_inline_decode(xdr, 4);
3251 if (unlikely(!p))
3252 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003253 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003254
3255 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003256 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003257 while (loc->nservers < m) {
3258 struct nfs4_string *server = &loc->servers[loc->nservers];
3259 status = decode_opaque_inline(xdr, &server->len, &server->data);
3260 if (unlikely(status != 0))
3261 goto out_eio;
3262 dprintk("%s ", server->data);
3263 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3264 loc->nservers++;
3265 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003266 unsigned int i;
3267 dprintk("%s: using first %u of %u servers "
3268 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003269 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003270 NFS4_FS_LOCATION_MAXSERVERS,
3271 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003272 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003273 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003274 char *data;
3275 status = decode_opaque_inline(xdr, &len, &data);
3276 if (unlikely(status != 0))
3277 goto out_eio;
3278 }
3279 }
3280 }
3281 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003282 if (unlikely(status != 0))
3283 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003284 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003285 res->nlocations++;
3286 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003287 if (res->nlocations != 0)
3288 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003289out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003290 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003291 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003292out_overflow:
3293 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003294out_eio:
3295 status = -EIO;
3296 goto out;
3297}
3298
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3300{
Al Viro8687b632006-10-19 23:28:48 -07003301 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 int status = 0;
3303
3304 *res = 0;
3305 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3306 return -EIO;
3307 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003308 p = xdr_inline_decode(xdr, 8);
3309 if (unlikely(!p))
3310 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003311 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3313 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003314 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003316out_overflow:
3317 print_overflow_msg(__func__, xdr);
3318 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319}
3320
3321static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3322{
Al Viro8687b632006-10-19 23:28:48 -07003323 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 int status = 0;
3325
3326 *maxlink = 1;
3327 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3328 return -EIO;
3329 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003330 p = xdr_inline_decode(xdr, 4);
3331 if (unlikely(!p))
3332 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003333 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3335 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003336 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003338out_overflow:
3339 print_overflow_msg(__func__, xdr);
3340 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341}
3342
3343static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3344{
Al Viro8687b632006-10-19 23:28:48 -07003345 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 int status = 0;
3347
3348 *maxname = 1024;
3349 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3350 return -EIO;
3351 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003352 p = xdr_inline_decode(xdr, 4);
3353 if (unlikely(!p))
3354 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003355 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3357 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003358 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003360out_overflow:
3361 print_overflow_msg(__func__, xdr);
3362 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363}
3364
3365static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3366{
Al Viro8687b632006-10-19 23:28:48 -07003367 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 int status = 0;
3369
3370 *res = 1024;
3371 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3372 return -EIO;
3373 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3374 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003375 p = xdr_inline_decode(xdr, 8);
3376 if (unlikely(!p))
3377 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003378 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 if (maxread > 0x7FFFFFFF)
3380 maxread = 0x7FFFFFFF;
3381 *res = (uint32_t)maxread;
3382 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3383 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003384 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003386out_overflow:
3387 print_overflow_msg(__func__, xdr);
3388 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389}
3390
3391static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3392{
Al Viro8687b632006-10-19 23:28:48 -07003393 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 int status = 0;
3395
3396 *res = 1024;
3397 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3398 return -EIO;
3399 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3400 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003401 p = xdr_inline_decode(xdr, 8);
3402 if (unlikely(!p))
3403 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003404 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405 if (maxwrite > 0x7FFFFFFF)
3406 maxwrite = 0x7FFFFFFF;
3407 *res = (uint32_t)maxwrite;
3408 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3409 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003410 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003412out_overflow:
3413 print_overflow_msg(__func__, xdr);
3414 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415}
3416
Trond Myklebustbca79472009-03-11 14:10:26 -04003417static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418{
Trond Myklebustbca79472009-03-11 14:10:26 -04003419 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003420 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003421 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422
3423 *mode = 0;
3424 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3425 return -EIO;
3426 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003427 p = xdr_inline_decode(xdr, 4);
3428 if (unlikely(!p))
3429 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003430 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003431 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003433 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003435 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003436 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003437out_overflow:
3438 print_overflow_msg(__func__, xdr);
3439 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440}
3441
3442static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3443{
Al Viro8687b632006-10-19 23:28:48 -07003444 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003445 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446
3447 *nlink = 1;
3448 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3449 return -EIO;
3450 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003451 p = xdr_inline_decode(xdr, 4);
3452 if (unlikely(!p))
3453 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003454 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003456 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003458 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003459 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003460out_overflow:
3461 print_overflow_msg(__func__, xdr);
3462 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463}
3464
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003465static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003466 const struct nfs_server *server, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467{
Al Viro8687b632006-10-19 23:28:48 -07003468 uint32_t len;
3469 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003470 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471
3472 *uid = -2;
3473 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3474 return -EIO;
3475 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003476 p = xdr_inline_decode(xdr, 4);
3477 if (unlikely(!p))
3478 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003479 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003480 p = xdr_inline_decode(xdr, len);
3481 if (unlikely(!p))
3482 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003483 if (!may_sleep) {
3484 /* do nothing */
3485 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003486 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003487 ret = NFS_ATTR_FATTR_OWNER;
3488 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003490 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003492 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003493 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3495 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003496 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003497 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003498out_overflow:
3499 print_overflow_msg(__func__, xdr);
3500 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501}
3502
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003503static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003504 const struct nfs_server *server, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505{
Al Viro8687b632006-10-19 23:28:48 -07003506 uint32_t len;
3507 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003508 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509
3510 *gid = -2;
3511 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3512 return -EIO;
3513 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003514 p = xdr_inline_decode(xdr, 4);
3515 if (unlikely(!p))
3516 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003517 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003518 p = xdr_inline_decode(xdr, len);
3519 if (unlikely(!p))
3520 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003521 if (!may_sleep) {
3522 /* do nothing */
3523 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003524 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003525 ret = NFS_ATTR_FATTR_GROUP;
3526 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003528 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003530 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003531 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3533 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003534 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003535 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003536out_overflow:
3537 print_overflow_msg(__func__, xdr);
3538 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539}
3540
3541static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3542{
Al Viro8687b632006-10-19 23:28:48 -07003543 uint32_t major = 0, minor = 0;
3544 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003545 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546
3547 *rdev = MKDEV(0,0);
3548 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3549 return -EIO;
3550 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3551 dev_t tmp;
3552
Benny Halevyc0eae662009-08-14 17:20:14 +03003553 p = xdr_inline_decode(xdr, 8);
3554 if (unlikely(!p))
3555 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003556 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003557 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558 tmp = MKDEV(major, minor);
3559 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3560 *rdev = tmp;
3561 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003562 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003564 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003565 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003566out_overflow:
3567 print_overflow_msg(__func__, xdr);
3568 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569}
3570
3571static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3572{
Al Viro8687b632006-10-19 23:28:48 -07003573 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 int status = 0;
3575
3576 *res = 0;
3577 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3578 return -EIO;
3579 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003580 p = xdr_inline_decode(xdr, 8);
3581 if (unlikely(!p))
3582 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003583 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3585 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003586 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003588out_overflow:
3589 print_overflow_msg(__func__, xdr);
3590 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591}
3592
3593static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3594{
Al Viro8687b632006-10-19 23:28:48 -07003595 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596 int status = 0;
3597
3598 *res = 0;
3599 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3600 return -EIO;
3601 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003602 p = xdr_inline_decode(xdr, 8);
3603 if (unlikely(!p))
3604 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003605 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3607 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003608 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003610out_overflow:
3611 print_overflow_msg(__func__, xdr);
3612 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613}
3614
3615static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3616{
Al Viro8687b632006-10-19 23:28:48 -07003617 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618 int status = 0;
3619
3620 *res = 0;
3621 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3622 return -EIO;
3623 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003624 p = xdr_inline_decode(xdr, 8);
3625 if (unlikely(!p))
3626 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003627 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3629 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003630 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003632out_overflow:
3633 print_overflow_msg(__func__, xdr);
3634 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635}
3636
3637static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3638{
Al Viro8687b632006-10-19 23:28:48 -07003639 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003640 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641
3642 *used = 0;
3643 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3644 return -EIO;
3645 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003646 p = xdr_inline_decode(xdr, 8);
3647 if (unlikely(!p))
3648 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003649 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003651 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003653 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003655 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003656out_overflow:
3657 print_overflow_msg(__func__, xdr);
3658 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659}
3660
3661static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3662{
Al Viro8687b632006-10-19 23:28:48 -07003663 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003664 uint64_t sec;
3665 uint32_t nsec;
3666
Benny Halevyc0eae662009-08-14 17:20:14 +03003667 p = xdr_inline_decode(xdr, 12);
3668 if (unlikely(!p))
3669 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003670 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003671 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 time->tv_sec = (time_t)sec;
3673 time->tv_nsec = (long)nsec;
3674 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003675out_overflow:
3676 print_overflow_msg(__func__, xdr);
3677 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678}
3679
3680static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3681{
3682 int status = 0;
3683
3684 time->tv_sec = 0;
3685 time->tv_nsec = 0;
3686 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3687 return -EIO;
3688 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3689 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003690 if (status == 0)
3691 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3693 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003694 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 return status;
3696}
3697
3698static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3699{
3700 int status = 0;
3701
3702 time->tv_sec = 0;
3703 time->tv_nsec = 0;
3704 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3705 return -EIO;
3706 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3707 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003708 if (status == 0)
3709 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3711 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003712 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 return status;
3714}
3715
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003716static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3717 struct timespec *time)
3718{
3719 int status = 0;
3720
3721 time->tv_sec = 0;
3722 time->tv_nsec = 0;
3723 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3724 return -EIO;
3725 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3726 status = decode_attr_time(xdr, time);
3727 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3728 }
3729 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3730 (long)time->tv_nsec);
3731 return status;
3732}
3733
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3735{
3736 int status = 0;
3737
3738 time->tv_sec = 0;
3739 time->tv_nsec = 0;
3740 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3741 return -EIO;
3742 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3743 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003744 if (status == 0)
3745 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3747 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003748 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 return status;
3750}
3751
Al Viro8687b632006-10-19 23:28:48 -07003752static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753{
3754 unsigned int attrwords = XDR_QUADLEN(attrlen);
3755 unsigned int nwords = xdr->p - savep;
3756
3757 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003758 dprintk("%s: server returned incorrect attribute length: "
3759 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003760 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 attrwords << 2,
3762 (attrwords < nwords) ? '<' : '>',
3763 nwords << 2);
3764 return -EIO;
3765 }
3766 return 0;
3767}
3768
3769static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3770{
Al Viro8687b632006-10-19 23:28:48 -07003771 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772
Benny Halevyc0eae662009-08-14 17:20:14 +03003773 p = xdr_inline_decode(xdr, 20);
3774 if (unlikely(!p))
3775 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003776 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003777 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003778 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003780out_overflow:
3781 print_overflow_msg(__func__, xdr);
3782 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783}
3784
3785static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3786{
Al Viro8687b632006-10-19 23:28:48 -07003787 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 uint32_t supp, acc;
3789 int status;
3790
3791 status = decode_op_hdr(xdr, OP_ACCESS);
3792 if (status)
3793 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003794 p = xdr_inline_decode(xdr, 8);
3795 if (unlikely(!p))
3796 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003797 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003798 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799 access->supported = supp;
3800 access->access = acc;
3801 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003802out_overflow:
3803 print_overflow_msg(__func__, xdr);
3804 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805}
3806
Benny Halevy07d30432009-08-14 17:19:52 +03003807static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808{
Al Viro8687b632006-10-19 23:28:48 -07003809 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003810
3811 p = xdr_inline_decode(xdr, len);
3812 if (likely(p)) {
3813 memcpy(buf, p, len);
3814 return 0;
3815 }
3816 print_overflow_msg(__func__, xdr);
3817 return -EIO;
3818}
3819
3820static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3821{
3822 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823}
3824
3825static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3826{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827 int status;
3828
3829 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003830 if (status != -EIO)
3831 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003832 if (!status)
3833 status = decode_stateid(xdr, &res->stateid);
3834 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835}
3836
Benny Halevydb942bb2009-08-14 17:19:56 +03003837static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3838{
3839 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840}
3841
3842static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3843{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 int status;
3845
3846 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003847 if (!status)
3848 status = decode_verifier(xdr, res->verf->verifier);
3849 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850}
3851
3852static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3853{
Al Viro8687b632006-10-19 23:28:48 -07003854 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 uint32_t bmlen;
3856 int status;
3857
3858 status = decode_op_hdr(xdr, OP_CREATE);
3859 if (status)
3860 return status;
3861 if ((status = decode_change_info(xdr, cinfo)))
3862 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003863 p = xdr_inline_decode(xdr, 4);
3864 if (unlikely(!p))
3865 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003866 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003867 p = xdr_inline_decode(xdr, bmlen << 2);
3868 if (likely(p))
3869 return 0;
3870out_overflow:
3871 print_overflow_msg(__func__, xdr);
3872 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873}
3874
3875static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3876{
Al Viro8687b632006-10-19 23:28:48 -07003877 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003878 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879 int status;
3880
3881 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3882 goto xdr_error;
3883 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3884 goto xdr_error;
3885 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3886 goto xdr_error;
3887 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3888 goto xdr_error;
3889 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3890 goto xdr_error;
3891 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3892 goto xdr_error;
3893 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3894 goto xdr_error;
3895 status = verify_attr_len(xdr, savep, attrlen);
3896xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003897 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 return status;
3899}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003900
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3902{
Al Viro8687b632006-10-19 23:28:48 -07003903 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003904 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003906
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3908 goto xdr_error;
3909 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3910 goto xdr_error;
3911 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3912 goto xdr_error;
3913
3914 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3915 goto xdr_error;
3916 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3917 goto xdr_error;
3918 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3919 goto xdr_error;
3920 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3921 goto xdr_error;
3922 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3923 goto xdr_error;
3924 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3925 goto xdr_error;
3926
3927 status = verify_attr_len(xdr, savep, attrlen);
3928xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003929 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930 return status;
3931}
3932
3933static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3934{
Al Viro8687b632006-10-19 23:28:48 -07003935 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003936 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003938
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3940 goto xdr_error;
3941 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3942 goto xdr_error;
3943 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3944 goto xdr_error;
3945
3946 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3947 goto xdr_error;
3948 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3949 goto xdr_error;
3950
3951 status = verify_attr_len(xdr, savep, attrlen);
3952xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003953 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 return status;
3955}
3956
Bryan Schumakerae42c702010-10-21 16:33:17 -04003957static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
3958 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003959 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960{
Trond Myklebustbca79472009-03-11 14:10:26 -04003961 int status;
3962 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003963 uint64_t fileid;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003964 uint32_t type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003966 status = decode_attr_type(xdr, bitmap, &type);
3967 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003969 fattr->mode = 0;
3970 if (status != 0) {
3971 fattr->mode |= nfs_type2fmt[type];
3972 fattr->valid |= status;
3973 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003975 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3976 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003978 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003979
3980 status = decode_attr_size(xdr, bitmap, &fattr->size);
3981 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003983 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003984
3985 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3986 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003988 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003989
Bryan Schumakerae42c702010-10-21 16:33:17 -04003990 status = decode_attr_error(xdr, bitmap);
3991 if (status < 0)
3992 goto xdr_error;
3993
3994 status = decode_attr_filehandle(xdr, bitmap, fh);
3995 if (status < 0)
3996 goto xdr_error;
3997
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003998 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3999 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004001 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004002
4003 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04004004 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004005 fattr));
4006 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004007 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004008 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004009
4010 status = decode_attr_mode(xdr, bitmap, &fmode);
4011 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004013 if (status != 0) {
4014 fattr->mode |= fmode;
4015 fattr->valid |= status;
4016 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004017
4018 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4019 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004021 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004022
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004023 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004024 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004026 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004027
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004028 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004029 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004031 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004032
4033 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4034 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004036 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004037
4038 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4039 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004041 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004042
4043 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4044 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004046 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004047
4048 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4049 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004051 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004052
4053 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4054 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004056 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004057
4058 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
4059 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004060 goto xdr_error;
Trond Myklebust3201f3d2010-10-23 15:43:10 -04004061 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04004062 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04004063 fattr->valid |= status;
4064 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004065
Bryan Schumakerae42c702010-10-21 16:33:17 -04004066xdr_error:
4067 dprintk("%s: xdr returned %d\n", __func__, -status);
4068 return status;
4069}
4070
4071static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4072 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4073{
4074 __be32 *savep;
4075 uint32_t attrlen,
4076 bitmap[2] = {0};
4077 int status;
4078
4079 status = decode_op_hdr(xdr, OP_GETATTR);
4080 if (status < 0)
4081 goto xdr_error;
4082
4083 status = decode_attr_bitmap(xdr, bitmap);
4084 if (status < 0)
4085 goto xdr_error;
4086
4087 status = decode_attr_length(xdr, &attrlen, &savep);
4088 if (status < 0)
4089 goto xdr_error;
4090
4091 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4092 if (status < 0)
4093 goto xdr_error;
4094
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004095 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004097 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 return status;
4099}
4100
Bryan Schumakerae42c702010-10-21 16:33:17 -04004101static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4102 const struct nfs_server *server, int may_sleep)
4103{
4104 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4105}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106
Andy Adamson504913f2010-10-20 00:17:57 -04004107/*
4108 * Decode potentially multiple layout types. Currently we only support
4109 * one layout driver per file system.
4110 */
4111static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4112 uint32_t *layouttype)
4113{
4114 uint32_t *p;
4115 int num;
4116
4117 p = xdr_inline_decode(xdr, 4);
4118 if (unlikely(!p))
4119 goto out_overflow;
4120 num = be32_to_cpup(p);
4121
4122 /* pNFS is not supported by the underlying file system */
4123 if (num == 0) {
4124 *layouttype = 0;
4125 return 0;
4126 }
4127 if (num > 1)
4128 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4129 "per filesystem not supported\n", __func__);
4130
4131 /* Decode and set first layout type, move xdr->p past unused types */
4132 p = xdr_inline_decode(xdr, num * 4);
4133 if (unlikely(!p))
4134 goto out_overflow;
4135 *layouttype = be32_to_cpup(p);
4136 return 0;
4137out_overflow:
4138 print_overflow_msg(__func__, xdr);
4139 return -EIO;
4140}
4141
4142/*
4143 * The type of file system exported.
4144 * Note we must ensure that layouttype is set in any non-error case.
4145 */
4146static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4147 uint32_t *layouttype)
4148{
4149 int status = 0;
4150
4151 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4152 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4153 return -EIO;
4154 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4155 status = decode_first_pnfs_layout_type(xdr, layouttype);
4156 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4157 } else
4158 *layouttype = 0;
4159 return status;
4160}
4161
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4163{
Al Viro8687b632006-10-19 23:28:48 -07004164 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004165 uint32_t attrlen, bitmap[2];
4166 int status;
4167
4168 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4169 goto xdr_error;
4170 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4171 goto xdr_error;
4172 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4173 goto xdr_error;
4174
4175 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4176
4177 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4178 goto xdr_error;
4179 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4180 goto xdr_error;
4181 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4182 goto xdr_error;
4183 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4184 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4185 goto xdr_error;
4186 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004187 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4188 if (status != 0)
4189 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004190 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4191 if (status != 0)
4192 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193
4194 status = verify_attr_len(xdr, savep, attrlen);
4195xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004196 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197 return status;
4198}
4199
4200static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4201{
Al Viro8687b632006-10-19 23:28:48 -07004202 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203 uint32_t len;
4204 int status;
4205
Trond Myklebust99367812007-07-17 21:52:41 -04004206 /* Zero handle first to allow comparisons */
4207 memset(fh, 0, sizeof(*fh));
4208
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 status = decode_op_hdr(xdr, OP_GETFH);
4210 if (status)
4211 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212
Benny Halevyc0eae662009-08-14 17:20:14 +03004213 p = xdr_inline_decode(xdr, 4);
4214 if (unlikely(!p))
4215 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004216 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 if (len > NFS4_FHSIZE)
4218 return -EIO;
4219 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004220 p = xdr_inline_decode(xdr, len);
4221 if (unlikely(!p))
4222 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004223 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004225out_overflow:
4226 print_overflow_msg(__func__, xdr);
4227 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228}
4229
4230static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4231{
4232 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004233
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 status = decode_op_hdr(xdr, OP_LINK);
4235 if (status)
4236 return status;
4237 return decode_change_info(xdr, cinfo);
4238}
4239
4240/*
4241 * We create the owner, so we know a proper owner.id length is 4.
4242 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004243static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004244{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004245 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004246 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004247 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004249 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004250 if (unlikely(!p))
4251 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004252 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004253 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004254 type = be32_to_cpup(p++); /* 4 byte read */
4255 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004256 fl->fl_start = (loff_t)offset;
4257 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4258 if (length == ~(uint64_t)0)
4259 fl->fl_end = OFFSET_MAX;
4260 fl->fl_type = F_WRLCK;
4261 if (type & 1)
4262 fl->fl_type = F_RDLCK;
4263 fl->fl_pid = 0;
4264 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004265 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4266 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4267 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004268 if (likely(p))
4269 return -NFS4ERR_DENIED;
4270out_overflow:
4271 print_overflow_msg(__func__, xdr);
4272 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273}
4274
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004275static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277 int status;
4278
4279 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004280 if (status == -EIO)
4281 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004283 status = decode_stateid(xdr, &res->stateid);
4284 if (unlikely(status))
4285 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004287 status = decode_lock_denied(xdr, NULL);
4288 if (res->open_seqid != NULL)
4289 nfs_increment_open_seqid(status, res->open_seqid);
4290 nfs_increment_lock_seqid(status, res->lock_seqid);
4291out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 return status;
4293}
4294
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004295static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296{
4297 int status;
4298 status = decode_op_hdr(xdr, OP_LOCKT);
4299 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004300 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301 return status;
4302}
4303
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004304static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 int status;
4307
4308 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004309 if (status != -EIO)
4310 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004311 if (status == 0)
4312 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004313 return status;
4314}
4315
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004316static int decode_release_lockowner(struct xdr_stream *xdr)
4317{
4318 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4319}
4320
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321static int decode_lookup(struct xdr_stream *xdr)
4322{
4323 return decode_op_hdr(xdr, OP_LOOKUP);
4324}
4325
4326/* This is too sick! */
4327static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4328{
Andy Adamson05d564f2008-12-23 16:06:15 -05004329 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330 uint32_t limit_type, nblocks, blocksize;
4331
Benny Halevyc0eae662009-08-14 17:20:14 +03004332 p = xdr_inline_decode(xdr, 12);
4333 if (unlikely(!p))
4334 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004335 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004337 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004338 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004339 break;
4340 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004341 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004342 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004343 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004344 }
4345 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004346out_overflow:
4347 print_overflow_msg(__func__, xdr);
4348 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349}
4350
4351static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4352{
Andy Adamson05d564f2008-12-23 16:06:15 -05004353 __be32 *p;
4354 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004355 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356
Benny Halevyc0eae662009-08-14 17:20:14 +03004357 p = xdr_inline_decode(xdr, 4);
4358 if (unlikely(!p))
4359 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004360 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4362 res->delegation_type = 0;
4363 return 0;
4364 }
Benny Halevy07d30432009-08-14 17:19:52 +03004365 status = decode_stateid(xdr, &res->delegation);
4366 if (unlikely(status))
4367 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004368 p = xdr_inline_decode(xdr, 4);
4369 if (unlikely(!p))
4370 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004371 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004372
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004374 case NFS4_OPEN_DELEGATE_READ:
4375 res->delegation_type = FMODE_READ;
4376 break;
4377 case NFS4_OPEN_DELEGATE_WRITE:
4378 res->delegation_type = FMODE_WRITE|FMODE_READ;
4379 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380 return -EIO;
4381 }
David Howells7539bba2006-08-22 20:06:09 -04004382 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004383out_overflow:
4384 print_overflow_msg(__func__, xdr);
4385 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386}
4387
4388static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4389{
Andy Adamson05d564f2008-12-23 16:06:15 -05004390 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004391 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004392 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393
Andy Adamson05d564f2008-12-23 16:06:15 -05004394 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004395 if (status != -EIO)
4396 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004397 if (!status)
4398 status = decode_stateid(xdr, &res->stateid);
4399 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004400 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401
Andy Adamson05d564f2008-12-23 16:06:15 -05004402 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004403
Benny Halevyc0eae662009-08-14 17:20:14 +03004404 p = xdr_inline_decode(xdr, 8);
4405 if (unlikely(!p))
4406 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004407 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004408 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004409 if (bmlen > 10)
4410 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411
Benny Halevyc0eae662009-08-14 17:20:14 +03004412 p = xdr_inline_decode(xdr, bmlen << 2);
4413 if (unlikely(!p))
4414 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004415 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4416 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004417 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004418 for (; i < NFS4_BITMAP_SIZE; i++)
4419 res->attrset[i] = 0;
4420
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 return decode_delegation(xdr, res);
4422xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004423 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004424 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004425out_overflow:
4426 print_overflow_msg(__func__, xdr);
4427 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428}
4429
4430static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4431{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004432 int status;
4433
Andy Adamson05d564f2008-12-23 16:06:15 -05004434 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004435 if (status != -EIO)
4436 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004437 if (!status)
4438 status = decode_stateid(xdr, &res->stateid);
4439 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440}
4441
4442static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4443{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444 int status;
4445
4446 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004447 if (status != -EIO)
4448 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004449 if (!status)
4450 status = decode_stateid(xdr, &res->stateid);
4451 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004452}
4453
4454static int decode_putfh(struct xdr_stream *xdr)
4455{
4456 return decode_op_hdr(xdr, OP_PUTFH);
4457}
4458
4459static int decode_putrootfh(struct xdr_stream *xdr)
4460{
4461 return decode_op_hdr(xdr, OP_PUTROOTFH);
4462}
4463
4464static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4465{
4466 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004467 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 uint32_t count, eof, recvd, hdrlen;
4469 int status;
4470
4471 status = decode_op_hdr(xdr, OP_READ);
4472 if (status)
4473 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004474 p = xdr_inline_decode(xdr, 8);
4475 if (unlikely(!p))
4476 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004477 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004478 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004479 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480 recvd = req->rq_rcv_buf.len - hdrlen;
4481 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004482 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483 "count %u > recvd %u\n", count, recvd);
4484 count = recvd;
4485 eof = 0;
4486 }
4487 xdr_read_pages(xdr, count);
4488 res->eof = eof;
4489 res->count = count;
4490 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004491out_overflow:
4492 print_overflow_msg(__func__, xdr);
4493 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004494}
4495
4496static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4497{
4498 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004500 size_t hdrlen;
4501 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004502 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503
4504 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004505 if (!status)
4506 status = decode_verifier(xdr, readdir->verifier.data);
4507 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004509 dprintk("%s: verifier = %08x:%08x\n",
4510 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004511 ((u32 *)readdir->verifier.data)[0],
4512 ((u32 *)readdir->verifier.data)[1]);
4513
Linus Torvalds1da177e2005-04-16 15:20:36 -07004514
Benny Halevydb942bb2009-08-14 17:19:56 +03004515 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516 recvd = rcvbuf->len - hdrlen;
4517 if (pglen > recvd)
4518 pglen = recvd;
4519 xdr_read_pages(xdr, pglen);
4520
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004521
Trond Myklebustac396122010-11-15 20:26:22 -05004522 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523}
4524
4525static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4526{
4527 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4528 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004529 size_t hdrlen;
4530 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004531 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532 int status;
4533
4534 status = decode_op_hdr(xdr, OP_READLINK);
4535 if (status)
4536 return status;
4537
4538 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004539 p = xdr_inline_decode(xdr, 4);
4540 if (unlikely(!p))
4541 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004542 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004544 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545 return -ENAMETOOLONG;
4546 }
4547 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4548 recvd = req->rq_rcv_buf.len - hdrlen;
4549 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004550 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551 "count %u > recvd %u\n", len, recvd);
4552 return -EIO;
4553 }
4554 xdr_read_pages(xdr, len);
4555 /*
4556 * The XDR encode routine has set things up so that
4557 * the link text will be copied directly into the
4558 * buffer. We just have to do overflow-checking,
4559 * and and null-terminate the text (the VFS expects
4560 * null-termination).
4561 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004562 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004564out_overflow:
4565 print_overflow_msg(__func__, xdr);
4566 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004567}
4568
4569static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4570{
4571 int status;
4572
4573 status = decode_op_hdr(xdr, OP_REMOVE);
4574 if (status)
4575 goto out;
4576 status = decode_change_info(xdr, cinfo);
4577out:
4578 return status;
4579}
4580
4581static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4582 struct nfs4_change_info *new_cinfo)
4583{
4584 int status;
4585
4586 status = decode_op_hdr(xdr, OP_RENAME);
4587 if (status)
4588 goto out;
4589 if ((status = decode_change_info(xdr, old_cinfo)))
4590 goto out;
4591 status = decode_change_info(xdr, new_cinfo);
4592out:
4593 return status;
4594}
4595
4596static int decode_renew(struct xdr_stream *xdr)
4597{
4598 return decode_op_hdr(xdr, OP_RENEW);
4599}
4600
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004601static int
4602decode_restorefh(struct xdr_stream *xdr)
4603{
4604 return decode_op_hdr(xdr, OP_RESTOREFH);
4605}
4606
J. Bruce Fields029d1052005-06-22 17:16:22 +00004607static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4608 size_t *acl_len)
4609{
Al Viro8687b632006-10-19 23:28:48 -07004610 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004611 uint32_t attrlen,
4612 bitmap[2] = {0};
4613 struct kvec *iov = req->rq_rcv_buf.head;
4614 int status;
4615
4616 *acl_len = 0;
4617 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4618 goto out;
4619 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4620 goto out;
4621 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4622 goto out;
4623
4624 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4625 return -EIO;
4626 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004627 size_t hdrlen;
4628 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004629
4630 /* We ignore &savep and don't do consistency checks on
4631 * the attr length. Let userspace figure it out.... */
4632 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4633 recvd = req->rq_rcv_buf.len - hdrlen;
4634 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004635 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004636 " acl reply: attrlen %u > recvd %u\n",
4637 attrlen, recvd);
4638 return -EINVAL;
4639 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004640 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004641 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004642 } else
4643 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004644
4645out:
4646 return status;
4647}
4648
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649static int
4650decode_savefh(struct xdr_stream *xdr)
4651{
4652 return decode_op_hdr(xdr, OP_SAVEFH);
4653}
4654
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004655static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656{
Al Viro8687b632006-10-19 23:28:48 -07004657 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658 uint32_t bmlen;
4659 int status;
4660
Linus Torvalds1da177e2005-04-16 15:20:36 -07004661 status = decode_op_hdr(xdr, OP_SETATTR);
4662 if (status)
4663 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004664 p = xdr_inline_decode(xdr, 4);
4665 if (unlikely(!p))
4666 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004667 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004668 p = xdr_inline_decode(xdr, bmlen << 2);
4669 if (likely(p))
4670 return 0;
4671out_overflow:
4672 print_overflow_msg(__func__, xdr);
4673 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674}
4675
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004676static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004677{
Al Viro8687b632006-10-19 23:28:48 -07004678 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004679 uint32_t opnum;
4680 int32_t nfserr;
4681
Benny Halevyc0eae662009-08-14 17:20:14 +03004682 p = xdr_inline_decode(xdr, 8);
4683 if (unlikely(!p))
4684 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004685 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004687 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004688 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004689 return -EIO;
4690 }
Benny Halevycccddf42009-08-14 17:20:19 +03004691 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004692 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004693 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4694 if (unlikely(!p))
4695 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004696 p = xdr_decode_hyper(p, &res->clientid);
4697 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698 } else if (nfserr == NFSERR_CLID_INUSE) {
4699 uint32_t len;
4700
4701 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004702 p = xdr_inline_decode(xdr, 4);
4703 if (unlikely(!p))
4704 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004705 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004706 p = xdr_inline_decode(xdr, len);
4707 if (unlikely(!p))
4708 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709
4710 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004711 p = xdr_inline_decode(xdr, 4);
4712 if (unlikely(!p))
4713 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004714 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004715 p = xdr_inline_decode(xdr, len);
4716 if (unlikely(!p))
4717 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718 return -NFSERR_CLID_INUSE;
4719 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004720 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721
4722 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004723out_overflow:
4724 print_overflow_msg(__func__, xdr);
4725 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726}
4727
4728static int decode_setclientid_confirm(struct xdr_stream *xdr)
4729{
4730 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4731}
4732
4733static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4734{
Al Viro8687b632006-10-19 23:28:48 -07004735 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736 int status;
4737
4738 status = decode_op_hdr(xdr, OP_WRITE);
4739 if (status)
4740 return status;
4741
Benny Halevyc0eae662009-08-14 17:20:14 +03004742 p = xdr_inline_decode(xdr, 16);
4743 if (unlikely(!p))
4744 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004745 res->count = be32_to_cpup(p++);
4746 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004747 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004749out_overflow:
4750 print_overflow_msg(__func__, xdr);
4751 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752}
4753
4754static int decode_delegreturn(struct xdr_stream *xdr)
4755{
4756 return decode_op_hdr(xdr, OP_DELEGRETURN);
4757}
4758
Benny Halevy99fe60d2009-04-01 09:22:29 -04004759#if defined(CONFIG_NFS_V4_1)
4760static int decode_exchange_id(struct xdr_stream *xdr,
4761 struct nfs41_exchange_id_res *res)
4762{
4763 __be32 *p;
4764 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004765 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004766 int status;
4767 struct nfs_client *clp = res->client;
4768
4769 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4770 if (status)
4771 return status;
4772
Benny Halevyc0eae662009-08-14 17:20:14 +03004773 p = xdr_inline_decode(xdr, 8);
4774 if (unlikely(!p))
4775 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05004776 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004777 p = xdr_inline_decode(xdr, 12);
4778 if (unlikely(!p))
4779 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004780 clp->cl_seqid = be32_to_cpup(p++);
4781 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004782
4783 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004784 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004785 if (dummy != SP4_NONE)
4786 return -EIO;
4787
4788 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004789 p = xdr_inline_decode(xdr, 8);
4790 if (unlikely(!p))
4791 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004792
4793 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004794 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4795 if (unlikely(status))
4796 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004797
4798 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004799 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4800 if (unlikely(status))
4801 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004802
4803 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004804 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4805 if (unlikely(status))
4806 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004807
4808 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004809out_overflow:
4810 print_overflow_msg(__func__, xdr);
4811 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004812}
Andy Adamsonfc931582009-04-01 09:22:31 -04004813
4814static int decode_chan_attrs(struct xdr_stream *xdr,
4815 struct nfs4_channel_attrs *attrs)
4816{
4817 __be32 *p;
4818 u32 nr_attrs;
4819
Benny Halevyc0eae662009-08-14 17:20:14 +03004820 p = xdr_inline_decode(xdr, 28);
4821 if (unlikely(!p))
4822 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004823 attrs->headerpadsz = be32_to_cpup(p++);
4824 attrs->max_rqst_sz = be32_to_cpup(p++);
4825 attrs->max_resp_sz = be32_to_cpup(p++);
4826 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4827 attrs->max_ops = be32_to_cpup(p++);
4828 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004829 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004830 if (unlikely(nr_attrs > 1)) {
4831 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4832 __func__, nr_attrs);
4833 return -EINVAL;
4834 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004835 if (nr_attrs == 1) {
4836 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4837 if (unlikely(!p))
4838 goto out_overflow;
4839 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004840 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004841out_overflow:
4842 print_overflow_msg(__func__, xdr);
4843 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004844}
4845
Benny Halevye78291e2009-08-14 17:20:00 +03004846static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4847{
4848 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004849}
4850
4851static int decode_create_session(struct xdr_stream *xdr,
4852 struct nfs41_create_session_res *res)
4853{
4854 __be32 *p;
4855 int status;
4856 struct nfs_client *clp = res->client;
4857 struct nfs4_session *session = clp->cl_session;
4858
4859 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004860 if (!status)
4861 status = decode_sessionid(xdr, &session->sess_id);
4862 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004863 return status;
4864
Andy Adamsonfc931582009-04-01 09:22:31 -04004865 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004866 p = xdr_inline_decode(xdr, 8);
4867 if (unlikely(!p))
4868 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004869 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004870 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004871
4872 /* Channel attributes */
4873 status = decode_chan_attrs(xdr, &session->fc_attrs);
4874 if (!status)
4875 status = decode_chan_attrs(xdr, &session->bc_attrs);
4876 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004877out_overflow:
4878 print_overflow_msg(__func__, xdr);
4879 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004880}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004881
4882static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4883{
4884 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4885}
Ricardo Labiaga180197532009-12-05 16:08:40 -05004886
4887static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
4888{
4889 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
4890}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004891#endif /* CONFIG_NFS_V4_1 */
4892
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004893static int decode_sequence(struct xdr_stream *xdr,
4894 struct nfs4_sequence_res *res,
4895 struct rpc_rqst *rqstp)
4896{
4897#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004898 struct nfs4_sessionid id;
4899 u32 dummy;
4900 int status;
4901 __be32 *p;
4902
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004903 if (!res->sr_session)
4904 return 0;
4905
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004906 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03004907 if (!status)
4908 status = decode_sessionid(xdr, &id);
4909 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004910 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004911
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004912 /*
4913 * If the server returns different values for sessionID, slotID or
4914 * sequence number, the server is looney tunes.
4915 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05004916 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004917
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004918 if (memcmp(id.data, res->sr_session->sess_id.data,
4919 NFS4_MAX_SESSIONID_LEN)) {
4920 dprintk("%s Invalid session id\n", __func__);
4921 goto out_err;
4922 }
Benny Halevye78291e2009-08-14 17:20:00 +03004923
Benny Halevyc0eae662009-08-14 17:20:14 +03004924 p = xdr_inline_decode(xdr, 20);
4925 if (unlikely(!p))
4926 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03004927
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004928 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03004929 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004930 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004931 dprintk("%s Invalid sequence number\n", __func__);
4932 goto out_err;
4933 }
4934 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03004935 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004936 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004937 dprintk("%s Invalid slot id\n", __func__);
4938 goto out_err;
4939 }
4940 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004941 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004942 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004943 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05004944 /* result flags */
4945 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004946 status = 0;
4947out_err:
4948 res->sr_status = status;
4949 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004950out_overflow:
4951 print_overflow_msg(__func__, xdr);
4952 status = -EIO;
4953 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004954#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004955 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004956#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004957}
4958
Andy Adamsonb1f69b72010-10-20 00:18:03 -04004959#if defined(CONFIG_NFS_V4_1)
4960
4961static int decode_getdeviceinfo(struct xdr_stream *xdr,
4962 struct pnfs_device *pdev)
4963{
4964 __be32 *p;
4965 uint32_t len, type;
4966 int status;
4967
4968 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
4969 if (status) {
4970 if (status == -ETOOSMALL) {
4971 p = xdr_inline_decode(xdr, 4);
4972 if (unlikely(!p))
4973 goto out_overflow;
4974 pdev->mincount = be32_to_cpup(p);
4975 dprintk("%s: Min count too small. mincnt = %u\n",
4976 __func__, pdev->mincount);
4977 }
4978 return status;
4979 }
4980
4981 p = xdr_inline_decode(xdr, 8);
4982 if (unlikely(!p))
4983 goto out_overflow;
4984 type = be32_to_cpup(p++);
4985 if (type != pdev->layout_type) {
4986 dprintk("%s: layout mismatch req: %u pdev: %u\n",
4987 __func__, pdev->layout_type, type);
4988 return -EINVAL;
4989 }
4990 /*
4991 * Get the length of the opaque device_addr4. xdr_read_pages places
4992 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
4993 * and places the remaining xdr data in xdr_buf->tail
4994 */
4995 pdev->mincount = be32_to_cpup(p);
4996 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
4997
4998 /* Parse notification bitmap, verifying that it is zero. */
4999 p = xdr_inline_decode(xdr, 4);
5000 if (unlikely(!p))
5001 goto out_overflow;
5002 len = be32_to_cpup(p);
5003 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005004 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005005
5006 p = xdr_inline_decode(xdr, 4 * len);
5007 if (unlikely(!p))
5008 goto out_overflow;
5009 for (i = 0; i < len; i++, p++) {
5010 if (be32_to_cpup(p)) {
5011 dprintk("%s: notifications not supported\n",
5012 __func__);
5013 return -EIO;
5014 }
5015 }
5016 }
5017 return 0;
5018out_overflow:
5019 print_overflow_msg(__func__, xdr);
5020 return -EIO;
5021}
5022
5023static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5024 struct nfs4_layoutget_res *res)
5025{
5026 __be32 *p;
5027 int status;
5028 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005029 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5030 struct kvec *iov = rcvbuf->head;
5031 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005032
5033 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5034 if (status)
5035 return status;
5036 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5037 if (unlikely(!p))
5038 goto out_overflow;
5039 res->return_on_close = be32_to_cpup(p++);
5040 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5041 layout_count = be32_to_cpup(p);
5042 if (!layout_count) {
5043 dprintk("%s: server responded with empty layout array\n",
5044 __func__);
5045 return -EINVAL;
5046 }
5047
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005048 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005049 if (unlikely(!p))
5050 goto out_overflow;
5051 p = xdr_decode_hyper(p, &res->range.offset);
5052 p = xdr_decode_hyper(p, &res->range.length);
5053 res->range.iomode = be32_to_cpup(p++);
5054 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005055 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005056
5057 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5058 __func__,
5059 (unsigned long)res->range.offset,
5060 (unsigned long)res->range.length,
5061 res->range.iomode,
5062 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005063 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005064
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005065 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5066 recvd = req->rq_rcv_buf.len - hdrlen;
5067 if (res->layoutp->len > recvd) {
5068 dprintk("NFS: server cheating in layoutget reply: "
5069 "layout len %u > recvd %u\n",
5070 res->layoutp->len, recvd);
5071 return -EINVAL;
5072 }
5073
5074 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005075
5076 if (layout_count > 1) {
5077 /* We only handle a length one array at the moment. Any
5078 * further entries are just ignored. Note that this means
5079 * the client may see a response that is less than the
5080 * minimum it requested.
5081 */
5082 dprintk("%s: server responded with %d layouts, dropping tail\n",
5083 __func__, layout_count);
5084 }
5085
5086 return 0;
5087out_overflow:
5088 print_overflow_msg(__func__, xdr);
5089 return -EIO;
5090}
Andy Adamson863a3c62011-03-23 13:27:54 +00005091
5092static int decode_layoutcommit(struct xdr_stream *xdr,
5093 struct rpc_rqst *req,
5094 struct nfs4_layoutcommit_res *res)
5095{
5096 __be32 *p;
5097 __u32 sizechanged;
5098 int status;
5099
5100 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5101 if (status)
5102 return status;
5103
5104 p = xdr_inline_decode(xdr, 4);
5105 if (unlikely(!p))
5106 goto out_overflow;
5107 sizechanged = be32_to_cpup(p);
5108
5109 if (sizechanged) {
5110 /* throw away new size */
5111 p = xdr_inline_decode(xdr, 8);
5112 if (unlikely(!p))
5113 goto out_overflow;
5114 }
5115 return 0;
5116out_overflow:
5117 print_overflow_msg(__func__, xdr);
5118 return -EIO;
5119}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005120#endif /* CONFIG_NFS_V4_1 */
5121
Linus Torvalds1da177e2005-04-16 15:20:36 -07005122/*
Benny Halevy49c25592008-12-23 16:06:16 -05005123 * END OF "GENERIC" DECODE ROUTINES.
5124 */
5125
5126/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127 * Decode OPEN_DOWNGRADE response
5128 */
Chuck Leverbf269552010-12-14 14:59:29 +00005129static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5130 struct xdr_stream *xdr,
5131 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132{
Andy Adamson05d564f2008-12-23 16:06:15 -05005133 struct compound_hdr hdr;
5134 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005135
Chuck Leverbf269552010-12-14 14:59:29 +00005136 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005137 if (status)
5138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005139 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005140 if (status)
5141 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005142 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005143 if (status)
5144 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005145 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005146 if (status != 0)
5147 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005148 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005149 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005150out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005151 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152}
5153
5154/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155 * Decode ACCESS response
5156 */
Chuck Leverbf269552010-12-14 14:59:29 +00005157static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5158 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005159{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005160 struct compound_hdr hdr;
5161 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005162
Chuck Leverbf269552010-12-14 14:59:29 +00005163 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005164 if (status)
5165 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005166 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005167 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005169 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005170 if (status != 0)
5171 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005172 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005173 if (status != 0)
5174 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005175 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005176 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177out:
5178 return status;
5179}
5180
5181/*
5182 * Decode LOOKUP response
5183 */
Chuck Leverbf269552010-12-14 14:59:29 +00005184static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5185 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005186{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005187 struct compound_hdr hdr;
5188 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005189
Chuck Leverbf269552010-12-14 14:59:29 +00005190 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005191 if (status)
5192 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005193 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005194 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005195 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005196 status = decode_putfh(xdr);
5197 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005198 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005199 status = decode_lookup(xdr);
5200 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005201 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005202 status = decode_getfh(xdr, res->fh);
5203 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005204 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005205 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005206 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207out:
5208 return status;
5209}
5210
5211/*
5212 * Decode LOOKUP_ROOT response
5213 */
Chuck Leverbf269552010-12-14 14:59:29 +00005214static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5215 struct xdr_stream *xdr,
5216 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005217{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218 struct compound_hdr hdr;
5219 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005220
Chuck Leverbf269552010-12-14 14:59:29 +00005221 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005222 if (status)
5223 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005224 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005225 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005226 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005227 status = decode_putrootfh(xdr);
5228 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005229 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005230 status = decode_getfh(xdr, res->fh);
5231 if (status == 0)
5232 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005233 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234out:
5235 return status;
5236}
5237
5238/*
5239 * Decode REMOVE response
5240 */
Chuck Leverbf269552010-12-14 14:59:29 +00005241static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5242 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005243{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005244 struct compound_hdr hdr;
5245 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005246
Chuck Leverbf269552010-12-14 14:59:29 +00005247 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005248 if (status)
5249 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005250 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005251 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005253 status = decode_putfh(xdr);
5254 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005255 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005256 status = decode_remove(xdr, &res->cinfo);
5257 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005258 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005259 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005260 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005261out:
5262 return status;
5263}
5264
5265/*
5266 * Decode RENAME response
5267 */
Chuck Leverbf269552010-12-14 14:59:29 +00005268static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5269 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005270{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271 struct compound_hdr hdr;
5272 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005273
Chuck Leverbf269552010-12-14 14:59:29 +00005274 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005275 if (status)
5276 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005277 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005278 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005279 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005280 status = decode_putfh(xdr);
5281 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005283 status = decode_savefh(xdr);
5284 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005285 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005286 status = decode_putfh(xdr);
5287 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005288 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005289 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5290 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005291 goto out;
5292 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005293 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005294 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005295 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005296 status = decode_restorefh(xdr);
5297 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005298 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005299 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005300 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005301out:
5302 return status;
5303}
5304
5305/*
5306 * Decode LINK response
5307 */
Chuck Leverbf269552010-12-14 14:59:29 +00005308static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5309 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005310{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005311 struct compound_hdr hdr;
5312 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005313
Chuck Leverbf269552010-12-14 14:59:29 +00005314 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005315 if (status)
5316 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005317 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005318 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005320 status = decode_putfh(xdr);
5321 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005322 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005323 status = decode_savefh(xdr);
5324 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005326 status = decode_putfh(xdr);
5327 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005328 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005329 status = decode_link(xdr, &res->cinfo);
5330 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005331 goto out;
5332 /*
5333 * Note order: OP_LINK leaves the directory as the current
5334 * filehandle.
5335 */
Chuck Leverbf269552010-12-14 14:59:29 +00005336 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005337 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005338 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005339 status = decode_restorefh(xdr);
5340 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005341 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005342 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005343 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005344out:
5345 return status;
5346}
5347
5348/*
5349 * Decode CREATE response
5350 */
Chuck Leverbf269552010-12-14 14:59:29 +00005351static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5352 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005353{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005354 struct compound_hdr hdr;
5355 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005356
Chuck Leverbf269552010-12-14 14:59:29 +00005357 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005358 if (status)
5359 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005360 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005361 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005362 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005363 status = decode_putfh(xdr);
5364 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005365 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005366 status = decode_savefh(xdr);
5367 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005368 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005369 status = decode_create(xdr, &res->dir_cinfo);
5370 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005371 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005372 status = decode_getfh(xdr, res->fh);
5373 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005374 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005375 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005376 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005377 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005378 status = decode_restorefh(xdr);
5379 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005380 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005381 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005382 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005383out:
5384 return status;
5385}
5386
5387/*
5388 * Decode SYMLINK response
5389 */
Chuck Leverbf269552010-12-14 14:59:29 +00005390static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5391 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005392{
Chuck Leverbf269552010-12-14 14:59:29 +00005393 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394}
5395
5396/*
5397 * Decode GETATTR response
5398 */
Chuck Leverbf269552010-12-14 14:59:29 +00005399static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5400 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005401{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005402 struct compound_hdr hdr;
5403 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005404
Chuck Leverbf269552010-12-14 14:59:29 +00005405 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406 if (status)
5407 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005408 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005409 if (status)
5410 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005411 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005412 if (status)
5413 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005414 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005415 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005416out:
5417 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005418}
5419
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005420/*
5421 * Encode an SETACL request
5422 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005423static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5424 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005425{
Andy Adamson05d564f2008-12-23 16:06:15 -05005426 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005427 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005428 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005429
Chuck Lever9f06c712010-12-14 14:59:18 +00005430 encode_compound_hdr(xdr, req, &hdr);
5431 encode_sequence(xdr, &args->seq_args, &hdr);
5432 encode_putfh(xdr, args->fh, &hdr);
5433 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005434 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005435}
Andy Adamson05d564f2008-12-23 16:06:15 -05005436
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005437/*
5438 * Decode SETACL response
5439 */
5440static int
Chuck Leverbf269552010-12-14 14:59:29 +00005441nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005442 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005443{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005444 struct compound_hdr hdr;
5445 int status;
5446
Chuck Leverbf269552010-12-14 14:59:29 +00005447 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005448 if (status)
5449 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005450 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005451 if (status)
5452 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005453 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005454 if (status)
5455 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005456 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005457out:
5458 return status;
5459}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005460
5461/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005462 * Decode GETACL response
5463 */
5464static int
Chuck Leverbf269552010-12-14 14:59:29 +00005465nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005466 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005467{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005468 struct compound_hdr hdr;
5469 int status;
5470
Chuck Leverbf269552010-12-14 14:59:29 +00005471 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005472 if (status)
5473 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005474 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005475 if (status)
5476 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005477 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005478 if (status)
5479 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005480 status = decode_getacl(xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005481
5482out:
5483 return status;
5484}
5485
5486/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005487 * Decode CLOSE response
5488 */
Chuck Leverbf269552010-12-14 14:59:29 +00005489static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5490 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005491{
Andy Adamson05d564f2008-12-23 16:06:15 -05005492 struct compound_hdr hdr;
5493 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005494
Chuck Leverbf269552010-12-14 14:59:29 +00005495 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005496 if (status)
5497 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005498 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005499 if (status)
5500 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005501 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005502 if (status)
5503 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005504 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005505 if (status != 0)
5506 goto out;
5507 /*
5508 * Note: Server may do delete on close for this file
5509 * in which case the getattr call will fail with
5510 * an ESTALE error. Shouldn't be a problem,
5511 * though, since fattr->valid will remain unset.
5512 */
Chuck Leverbf269552010-12-14 14:59:29 +00005513 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005514 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005515out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005516 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005517}
5518
5519/*
5520 * Decode OPEN response
5521 */
Chuck Leverbf269552010-12-14 14:59:29 +00005522static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5523 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524{
Andy Adamson05d564f2008-12-23 16:06:15 -05005525 struct compound_hdr hdr;
5526 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005527
Chuck Leverbf269552010-12-14 14:59:29 +00005528 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005529 if (status)
5530 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005531 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005532 if (status)
5533 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005534 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005535 if (status)
5536 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005537 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005538 if (status)
5539 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005540 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005541 if (status)
5542 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005543 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005544 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005545 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005546 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005547 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005548 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005549 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005550 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005551 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005552out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005553 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005554}
5555
5556/*
5557 * Decode OPEN_CONFIRM response
5558 */
Chuck Leverbf269552010-12-14 14:59:29 +00005559static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5560 struct xdr_stream *xdr,
5561 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005562{
Andy Adamson05d564f2008-12-23 16:06:15 -05005563 struct compound_hdr hdr;
5564 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005565
Chuck Leverbf269552010-12-14 14:59:29 +00005566 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005567 if (status)
5568 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005569 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005570 if (status)
5571 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005572 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005573out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005574 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005575}
5576
5577/*
5578 * Decode OPEN response
5579 */
Chuck Leverbf269552010-12-14 14:59:29 +00005580static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5581 struct xdr_stream *xdr,
5582 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005583{
Andy Adamson05d564f2008-12-23 16:06:15 -05005584 struct compound_hdr hdr;
5585 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005586
Chuck Leverbf269552010-12-14 14:59:29 +00005587 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005588 if (status)
5589 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005590 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005591 if (status)
5592 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005593 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005594 if (status)
5595 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005596 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005597 if (status)
5598 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005599 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005600 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005601out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005602 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005603}
5604
5605/*
5606 * Decode SETATTR response
5607 */
Chuck Leverbf269552010-12-14 14:59:29 +00005608static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5609 struct xdr_stream *xdr,
5610 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005611{
Andy Adamson05d564f2008-12-23 16:06:15 -05005612 struct compound_hdr hdr;
5613 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005614
Chuck Leverbf269552010-12-14 14:59:29 +00005615 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005616 if (status)
5617 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005618 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005619 if (status)
5620 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005621 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005622 if (status)
5623 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005624 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005625 if (status)
5626 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005627 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005628 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005629out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005630 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005631}
5632
5633/*
5634 * Decode LOCK response
5635 */
Chuck Leverbf269552010-12-14 14:59:29 +00005636static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5637 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005638{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005639 struct compound_hdr hdr;
5640 int status;
5641
Chuck Leverbf269552010-12-14 14:59:29 +00005642 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005643 if (status)
5644 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005645 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005646 if (status)
5647 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005648 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005649 if (status)
5650 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005651 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005652out:
5653 return status;
5654}
5655
5656/*
5657 * Decode LOCKT response
5658 */
Chuck Leverbf269552010-12-14 14:59:29 +00005659static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5660 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005661{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005662 struct compound_hdr hdr;
5663 int status;
5664
Chuck Leverbf269552010-12-14 14:59:29 +00005665 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005666 if (status)
5667 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005668 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005669 if (status)
5670 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005671 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005672 if (status)
5673 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005674 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005675out:
5676 return status;
5677}
5678
5679/*
5680 * Decode LOCKU response
5681 */
Chuck Leverbf269552010-12-14 14:59:29 +00005682static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5683 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005684{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005685 struct compound_hdr hdr;
5686 int status;
5687
Chuck Leverbf269552010-12-14 14:59:29 +00005688 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005689 if (status)
5690 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005691 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005692 if (status)
5693 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005694 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005695 if (status)
5696 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005697 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005698out:
5699 return status;
5700}
5701
Chuck Leverbf269552010-12-14 14:59:29 +00005702static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5703 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005704{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005705 struct compound_hdr hdr;
5706 int status;
5707
Chuck Leverbf269552010-12-14 14:59:29 +00005708 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005709 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005710 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005711 return status;
5712}
5713
Linus Torvalds1da177e2005-04-16 15:20:36 -07005714/*
5715 * Decode READLINK response
5716 */
Chuck Leverbf269552010-12-14 14:59:29 +00005717static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5718 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04005719 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005720{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005721 struct compound_hdr hdr;
5722 int status;
5723
Chuck Leverbf269552010-12-14 14:59:29 +00005724 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005725 if (status)
5726 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005727 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005728 if (status)
5729 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005730 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005731 if (status)
5732 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005733 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005734out:
5735 return status;
5736}
5737
5738/*
5739 * Decode READDIR response
5740 */
Chuck Leverbf269552010-12-14 14:59:29 +00005741static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5742 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005743{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005744 struct compound_hdr hdr;
5745 int status;
5746
Chuck Leverbf269552010-12-14 14:59:29 +00005747 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005748 if (status)
5749 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005750 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005751 if (status)
5752 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005753 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005754 if (status)
5755 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005756 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005757out:
5758 return status;
5759}
5760
5761/*
5762 * Decode Read response
5763 */
Chuck Leverbf269552010-12-14 14:59:29 +00005764static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5765 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005766{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767 struct compound_hdr hdr;
5768 int status;
5769
Chuck Leverbf269552010-12-14 14:59:29 +00005770 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005771 if (status)
5772 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005773 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005774 if (status)
5775 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005776 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005777 if (status)
5778 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005779 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005780 if (!status)
5781 status = res->count;
5782out:
5783 return status;
5784}
5785
5786/*
5787 * Decode WRITE response
5788 */
Chuck Leverbf269552010-12-14 14:59:29 +00005789static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5790 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005791{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005792 struct compound_hdr hdr;
5793 int status;
5794
Chuck Leverbf269552010-12-14 14:59:29 +00005795 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005796 if (status)
5797 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005798 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005799 if (status)
5800 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005801 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005802 if (status)
5803 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005804 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005805 if (status)
5806 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00005807 if (res->fattr)
5808 decode_getfattr(xdr, res->fattr, res->server,
5809 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005810 if (!status)
5811 status = res->count;
5812out:
5813 return status;
5814}
5815
5816/*
5817 * Decode COMMIT response
5818 */
Chuck Leverbf269552010-12-14 14:59:29 +00005819static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5820 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005821{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005822 struct compound_hdr hdr;
5823 int status;
5824
Chuck Leverbf269552010-12-14 14:59:29 +00005825 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005826 if (status)
5827 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005828 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005829 if (status)
5830 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005831 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005832 if (status)
5833 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005834 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005835 if (status)
5836 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00005837 if (res->fattr)
5838 decode_getfattr(xdr, res->fattr, res->server,
5839 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005840out:
5841 return status;
5842}
5843
5844/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005845 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005846 */
Chuck Leverbf269552010-12-14 14:59:29 +00005847static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04005848 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005849{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 struct compound_hdr hdr;
5851 int status;
5852
Chuck Leverbf269552010-12-14 14:59:29 +00005853 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005855 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005856 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005857 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005858 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005859 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005860 return status;
5861}
5862
5863/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005864 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005865 */
Chuck Leverbf269552010-12-14 14:59:29 +00005866static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04005867 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005869 struct compound_hdr hdr;
5870 int status;
5871
Chuck Leverbf269552010-12-14 14:59:29 +00005872 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005873 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005874 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005875 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005876 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005878 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005879 return status;
5880}
5881
5882/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005883 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005884 */
Chuck Leverbf269552010-12-14 14:59:29 +00005885static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04005886 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005887{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005888 struct compound_hdr hdr;
5889 int status;
5890
Chuck Leverbf269552010-12-14 14:59:29 +00005891 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005893 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005894 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005895 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005896 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005897 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005898 return status;
5899}
5900
5901/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005902 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005903 */
Chuck Leverbf269552010-12-14 14:59:29 +00005904static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
5905 struct xdr_stream *xdr,
5906 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005907{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005908 struct compound_hdr hdr;
5909 int status;
5910
Chuck Leverbf269552010-12-14 14:59:29 +00005911 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005912 if (status)
5913 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005914 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005915 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005916 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005917 status = decode_putfh(xdr);
5918 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005919 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005920 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005921out:
5922 return status;
5923}
5924
5925/*
5926 * Decode RENEW response
5927 */
Chuck Leverbf269552010-12-14 14:59:29 +00005928static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5929 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005930{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931 struct compound_hdr hdr;
5932 int status;
5933
Chuck Leverbf269552010-12-14 14:59:29 +00005934 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005935 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005936 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005937 return status;
5938}
5939
5940/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005941 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005942 */
Chuck Leverbf269552010-12-14 14:59:29 +00005943static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
5944 struct xdr_stream *xdr,
5945 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005946{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005947 struct compound_hdr hdr;
5948 int status;
5949
Chuck Leverbf269552010-12-14 14:59:29 +00005950 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005951 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005952 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005953 return status;
5954}
5955
5956/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005957 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005958 */
Chuck Leverbf269552010-12-14 14:59:29 +00005959static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
5960 struct xdr_stream *xdr,
5961 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005962{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963 struct compound_hdr hdr;
5964 int status;
5965
Chuck Leverbf269552010-12-14 14:59:29 +00005966 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005967 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005968 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005970 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005971 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005972 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005973 return status;
5974}
5975
5976/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005977 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005978 */
Chuck Leverbf269552010-12-14 14:59:29 +00005979static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
5980 struct xdr_stream *xdr,
5981 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005982{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005983 struct compound_hdr hdr;
5984 int status;
5985
Chuck Leverbf269552010-12-14 14:59:29 +00005986 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005987 if (status)
5988 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005989 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005990 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005991 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005992 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01005993 if (status != 0)
5994 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005995 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04005996 if (status != 0)
5997 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005998 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005999 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01006000out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006001 return status;
6002}
6003
Trond Myklebust683b57b2006-06-09 09:34:22 -04006004/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006005 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006006 */
Chuck Leverbf269552010-12-14 14:59:29 +00006007static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6008 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006009 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006010{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006011 struct compound_hdr hdr;
6012 int status;
6013
Chuck Leverbf269552010-12-14 14:59:29 +00006014 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006015 if (status)
6016 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006017 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006018 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006019 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006020 status = decode_putfh(xdr);
6021 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006022 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006023 status = decode_lookup(xdr);
6024 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006025 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006026 xdr_enter_page(xdr, PAGE_SIZE);
6027 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006028 res->fs_locations->server,
6029 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04006030out:
6031 return status;
6032}
6033
Benny Halevy99fe60d2009-04-01 09:22:29 -04006034#if defined(CONFIG_NFS_V4_1)
6035/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006036 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006037 */
Chuck Leverbf269552010-12-14 14:59:29 +00006038static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6039 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006040 void *res)
6041{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006042 struct compound_hdr hdr;
6043 int status;
6044
Chuck Leverbf269552010-12-14 14:59:29 +00006045 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006046 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006047 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006048 return status;
6049}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006050
6051/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006052 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006053 */
Chuck Leverbf269552010-12-14 14:59:29 +00006054static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6055 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006056 struct nfs41_create_session_res *res)
6057{
Andy Adamsonfc931582009-04-01 09:22:31 -04006058 struct compound_hdr hdr;
6059 int status;
6060
Chuck Leverbf269552010-12-14 14:59:29 +00006061 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006062 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006063 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006064 return status;
6065}
6066
6067/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006068 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006069 */
Chuck Leverbf269552010-12-14 14:59:29 +00006070static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6071 struct xdr_stream *xdr,
6072 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006073{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006074 struct compound_hdr hdr;
6075 int status;
6076
Chuck Leverbf269552010-12-14 14:59:29 +00006077 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006078 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006079 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006080 return status;
6081}
6082
6083/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006084 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006085 */
Chuck Leverbf269552010-12-14 14:59:29 +00006086static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6087 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006088 struct nfs4_sequence_res *res)
6089{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006090 struct compound_hdr hdr;
6091 int status;
6092
Chuck Leverbf269552010-12-14 14:59:29 +00006093 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006094 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006095 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006096 return status;
6097}
6098
6099/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006100 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006101 */
Chuck Leverbf269552010-12-14 14:59:29 +00006102static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6103 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006104 struct nfs4_get_lease_time_res *res)
6105{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006106 struct compound_hdr hdr;
6107 int status;
6108
Chuck Leverbf269552010-12-14 14:59:29 +00006109 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006110 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006111 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006112 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006113 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006114 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006115 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006116 return status;
6117}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006118
6119/*
6120 * Decode RECLAIM_COMPLETE response
6121 */
Chuck Leverbf269552010-12-14 14:59:29 +00006122static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6123 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006124 struct nfs41_reclaim_complete_res *res)
6125{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006126 struct compound_hdr hdr;
6127 int status;
6128
Chuck Leverbf269552010-12-14 14:59:29 +00006129 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006130 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006131 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006132 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006133 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006134 return status;
6135}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006136
6137/*
6138 * Decode GETDEVINFO response
6139 */
Chuck Leverbf269552010-12-14 14:59:29 +00006140static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6141 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006142 struct nfs4_getdeviceinfo_res *res)
6143{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006144 struct compound_hdr hdr;
6145 int status;
6146
Chuck Leverbf269552010-12-14 14:59:29 +00006147 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006148 if (status != 0)
6149 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006150 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006151 if (status != 0)
6152 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006154out:
6155 return status;
6156}
6157
6158/*
6159 * Decode LAYOUTGET response
6160 */
Chuck Leverbf269552010-12-14 14:59:29 +00006161static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6162 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006163 struct nfs4_layoutget_res *res)
6164{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006165 struct compound_hdr hdr;
6166 int status;
6167
Chuck Leverbf269552010-12-14 14:59:29 +00006168 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006169 if (status)
6170 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006171 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006172 if (status)
6173 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006174 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006175 if (status)
6176 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006177 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006178out:
6179 return status;
6180}
Andy Adamson863a3c62011-03-23 13:27:54 +00006181
6182/*
6183 * Decode LAYOUTCOMMIT response
6184 */
6185static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6186 struct xdr_stream *xdr,
6187 struct nfs4_layoutcommit_res *res)
6188{
6189 struct compound_hdr hdr;
6190 int status;
6191
6192 status = decode_compound_hdr(xdr, &hdr);
6193 if (status)
6194 goto out;
6195 status = decode_sequence(xdr, &res->seq_res, rqstp);
6196 if (status)
6197 goto out;
6198 status = decode_putfh(xdr);
6199 if (status)
6200 goto out;
6201 status = decode_layoutcommit(xdr, rqstp, res);
6202 if (status)
6203 goto out;
6204 decode_getfattr(xdr, res->fattr, res->server,
6205 !RPC_IS_ASYNC(rqstp->rq_task));
6206out:
6207 return status;
6208}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006209#endif /* CONFIG_NFS_V4_1 */
6210
Chuck Lever573c4e12010-12-14 14:58:11 +00006211/**
6212 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6213 * the local page cache.
6214 * @xdr: XDR stream where entry resides
6215 * @entry: buffer to fill in with entry data
6216 * @plus: boolean indicating whether this should be a readdirplus entry
6217 *
6218 * Returns zero if successful, otherwise a negative errno value is
6219 * returned.
6220 *
6221 * This function is not invoked during READDIR reply decoding, but
6222 * rather whenever an application invokes the getdents(2) system call
6223 * on a directory already in our cache.
6224 */
6225int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6226 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227{
6228 uint32_t bitmap[2] = {0};
6229 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006230 __be32 *p = xdr_inline_decode(xdr, 4);
6231 if (unlikely(!p))
6232 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006233 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006234 p = xdr_inline_decode(xdr, 4);
6235 if (unlikely(!p))
6236 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006237 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006238 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006240 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006241 }
6242
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006243 p = xdr_inline_decode(xdr, 12);
6244 if (unlikely(!p))
6245 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246 entry->prev_cookie = entry->cookie;
6247 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006248 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006249
Trond Myklebust9af8c222010-10-24 11:52:55 -04006250 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006251 if (unlikely(!p))
6252 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006253 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006254
6255 /*
6256 * In case the server doesn't return an inode number,
6257 * we fake one here. (We don't use inode number 0,
6258 * since glibc seems to choke on it...)
6259 */
6260 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006261 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262
Trond Myklebust9af8c222010-10-24 11:52:55 -04006263 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006264 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006265
6266 if (decode_attr_length(xdr, &len, &p) < 0)
6267 goto out_overflow;
6268
Chuck Lever573c4e12010-12-14 14:58:11 +00006269 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6270 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006271 goto out_overflow;
6272 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6273 entry->ino = entry->fattr->fileid;
6274
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006275 entry->d_type = DT_UNKNOWN;
6276 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6277 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6278
Chuck Lever573c4e12010-12-14 14:58:11 +00006279 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006280
6281out_overflow:
6282 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006283 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006284}
6285
6286/*
6287 * We need to translate between nfs status return values and
6288 * the local errno values which may not be the same.
6289 */
6290static struct {
6291 int stat;
6292 int errno;
6293} nfs_errtbl[] = {
6294 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006295 { NFS4ERR_PERM, -EPERM },
6296 { NFS4ERR_NOENT, -ENOENT },
6297 { NFS4ERR_IO, -errno_NFSERR_IO},
6298 { NFS4ERR_NXIO, -ENXIO },
6299 { NFS4ERR_ACCESS, -EACCES },
6300 { NFS4ERR_EXIST, -EEXIST },
6301 { NFS4ERR_XDEV, -EXDEV },
6302 { NFS4ERR_NOTDIR, -ENOTDIR },
6303 { NFS4ERR_ISDIR, -EISDIR },
6304 { NFS4ERR_INVAL, -EINVAL },
6305 { NFS4ERR_FBIG, -EFBIG },
6306 { NFS4ERR_NOSPC, -ENOSPC },
6307 { NFS4ERR_ROFS, -EROFS },
6308 { NFS4ERR_MLINK, -EMLINK },
6309 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6310 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6311 { NFS4ERR_DQUOT, -EDQUOT },
6312 { NFS4ERR_STALE, -ESTALE },
6313 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006314 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6315 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6316 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006317 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006318 { NFS4ERR_BADTYPE, -EBADTYPE },
6319 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006320 { NFS4ERR_SYMLINK, -ELOOP },
6321 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6322 { NFS4ERR_DEADLOCK, -EDEADLK },
6323 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324 * to be handled by a
6325 * middle-layer.
6326 */
Benny Halevy856dff32008-03-31 17:39:06 +03006327 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006328};
6329
6330/*
6331 * Convert an NFS error code to a local one.
6332 * This one is used jointly by NFSv2 and NFSv3.
6333 */
6334static int
David Howells0a8ea432006-08-22 20:06:08 -04006335nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006336{
6337 int i;
6338 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6339 if (nfs_errtbl[i].stat == stat)
6340 return nfs_errtbl[i].errno;
6341 }
6342 if (stat <= 10000 || stat > 10100) {
6343 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006344 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 }
6346 /* If we cannot translate the error, the recovery routines should
6347 * handle it.
6348 * Note: remaining NFSv4 error codes have values > 10000, so should
6349 * not conflict with native Linux error codes.
6350 */
Benny Halevy856dff32008-03-31 17:39:06 +03006351 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352}
6353
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354#define PROC(proc, argtype, restype) \
6355[NFSPROC4_CLNT_##proc] = { \
6356 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006357 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006358 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006359 .p_arglen = NFS4_##argtype##_sz, \
6360 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006361 .p_statidx = NFSPROC4_CLNT_##proc, \
6362 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006363}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364
6365struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006366 PROC(READ, enc_read, dec_read),
6367 PROC(WRITE, enc_write, dec_write),
6368 PROC(COMMIT, enc_commit, dec_commit),
6369 PROC(OPEN, enc_open, dec_open),
6370 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6371 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6372 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6373 PROC(CLOSE, enc_close, dec_close),
6374 PROC(SETATTR, enc_setattr, dec_setattr),
6375 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6376 PROC(RENEW, enc_renew, dec_renew),
6377 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6378 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6379 PROC(LOCK, enc_lock, dec_lock),
6380 PROC(LOCKT, enc_lockt, dec_lockt),
6381 PROC(LOCKU, enc_locku, dec_locku),
6382 PROC(ACCESS, enc_access, dec_access),
6383 PROC(GETATTR, enc_getattr, dec_getattr),
6384 PROC(LOOKUP, enc_lookup, dec_lookup),
6385 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6386 PROC(REMOVE, enc_remove, dec_remove),
6387 PROC(RENAME, enc_rename, dec_rename),
6388 PROC(LINK, enc_link, dec_link),
6389 PROC(SYMLINK, enc_symlink, dec_symlink),
6390 PROC(CREATE, enc_create, dec_create),
6391 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6392 PROC(STATFS, enc_statfs, dec_statfs),
6393 PROC(READLINK, enc_readlink, dec_readlink),
6394 PROC(READDIR, enc_readdir, dec_readdir),
6395 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6396 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6397 PROC(GETACL, enc_getacl, dec_getacl),
6398 PROC(SETACL, enc_setacl, dec_setacl),
6399 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6400 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006401#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00006402 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6403 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6404 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6405 PROC(SEQUENCE, enc_sequence, dec_sequence),
6406 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6407 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6408 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6409 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00006410 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006411#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006412};
6413
6414struct rpc_version nfs_version4 = {
6415 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08006416 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07006417 .procs = nfs4_procedures
6418};
6419
6420/*
6421 * Local variables:
6422 * c-basic-offset: 8
6423 * End:
6424 */