blob: 0f2dcfb41f296822f2168c6a9997bf4d27b8d094 [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 Adamson9b7b9fc2009-04-01 09:22:11 -0400327#else /* CONFIG_NFS_V4_1 */
328#define encode_sequence_maxsz 0
329#define decode_sequence_maxsz 0
330#endif /* CONFIG_NFS_V4_1 */
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
333#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
334#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400335 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400337 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400339 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400341 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400343 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400345 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400347 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400349 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400351 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400353 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400355 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400357 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400359 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400361 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400362 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400364 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400366 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400367 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400369 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400371 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400372 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400374 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400376 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400377 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400379 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400380 encode_putfh_maxsz + \
381 encode_savefh_maxsz + \
382 encode_open_maxsz + \
383 encode_getfh_maxsz + \
384 encode_getattr_maxsz + \
385 encode_restorefh_maxsz + \
386 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400388 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400389 decode_putfh_maxsz + \
390 decode_savefh_maxsz + \
391 decode_open_maxsz + \
392 decode_getfh_maxsz + \
393 decode_getattr_maxsz + \
394 decode_restorefh_maxsz + \
395 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400396#define NFS4_enc_open_confirm_sz \
397 (compound_encode_hdr_maxsz + \
398 encode_putfh_maxsz + \
399 encode_open_confirm_maxsz)
400#define NFS4_dec_open_confirm_sz \
401 (compound_decode_hdr_maxsz + \
402 decode_putfh_maxsz + \
403 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400405 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400407 encode_open_maxsz + \
408 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400410 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400412 decode_open_maxsz + \
413 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414#define NFS4_enc_open_downgrade_sz \
415 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400416 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400417 encode_putfh_maxsz + \
418 encode_open_downgrade_maxsz + \
419 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420#define NFS4_dec_open_downgrade_sz \
421 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400423 decode_putfh_maxsz + \
424 decode_open_downgrade_maxsz + \
425 decode_getattr_maxsz)
426#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400428 encode_putfh_maxsz + \
429 encode_close_maxsz + \
430 encode_getattr_maxsz)
431#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400433 decode_putfh_maxsz + \
434 decode_close_maxsz + \
435 decode_getattr_maxsz)
436#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400438 encode_putfh_maxsz + \
439 encode_setattr_maxsz + \
440 encode_getattr_maxsz)
441#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400443 decode_putfh_maxsz + \
444 decode_setattr_maxsz + \
445 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400447 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 encode_putfh_maxsz + \
449 encode_fsinfo_maxsz)
450#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400451 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 decode_putfh_maxsz + \
453 decode_fsinfo_maxsz)
454#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
455 encode_renew_maxsz)
456#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
457 decode_renew_maxsz)
458#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
459 encode_setclientid_maxsz)
460#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
461 decode_setclientid_maxsz)
462#define NFS4_enc_setclientid_confirm_sz \
463 (compound_encode_hdr_maxsz + \
464 encode_setclientid_confirm_maxsz + \
465 encode_putrootfh_maxsz + \
466 encode_fsinfo_maxsz)
467#define NFS4_dec_setclientid_confirm_sz \
468 (compound_decode_hdr_maxsz + \
469 decode_setclientid_confirm_maxsz + \
470 decode_putrootfh_maxsz + \
471 decode_fsinfo_maxsz)
472#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400473 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400475 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400477 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400479 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400481 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400483 encode_lockt_maxsz)
484#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400486 decode_putfh_maxsz + \
487 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400489 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400491 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400493 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400495 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400496#define NFS4_enc_release_lockowner_sz \
497 (compound_encode_hdr_maxsz + \
498 encode_lockowner_maxsz)
499#define NFS4_dec_release_lockowner_sz \
500 (compound_decode_hdr_maxsz + \
501 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400503 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400505 encode_access_maxsz + \
506 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400508 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400510 decode_access_maxsz + \
511 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400513 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 encode_putfh_maxsz + \
515 encode_getattr_maxsz)
516#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400517 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 decode_putfh_maxsz + \
519 decode_getattr_maxsz)
520#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400521 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 encode_putfh_maxsz + \
523 encode_lookup_maxsz + \
524 encode_getattr_maxsz + \
525 encode_getfh_maxsz)
526#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400527 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400529 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 decode_getattr_maxsz + \
531 decode_getfh_maxsz)
532#define NFS4_enc_lookup_root_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_putrootfh_maxsz + \
535 encode_getattr_maxsz + \
536 encode_getfh_maxsz)
537#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 decode_putrootfh_maxsz + \
540 decode_getattr_maxsz + \
541 decode_getfh_maxsz)
542#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400543 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400545 encode_remove_maxsz + \
546 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400548 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400550 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400551 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400553 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 encode_putfh_maxsz + \
555 encode_savefh_maxsz + \
556 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400557 encode_rename_maxsz + \
558 encode_getattr_maxsz + \
559 encode_restorefh_maxsz + \
560 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 decode_putfh_maxsz + \
564 decode_savefh_maxsz + \
565 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400566 decode_rename_maxsz + \
567 decode_getattr_maxsz + \
568 decode_restorefh_maxsz + \
569 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400571 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 encode_putfh_maxsz + \
573 encode_savefh_maxsz + \
574 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400575 encode_link_maxsz + \
576 decode_getattr_maxsz + \
577 encode_restorefh_maxsz + \
578 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putfh_maxsz + \
582 decode_savefh_maxsz + \
583 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400584 decode_link_maxsz + \
585 decode_getattr_maxsz + \
586 decode_restorefh_maxsz + \
587 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400589 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 encode_putfh_maxsz + \
591 encode_symlink_maxsz + \
592 encode_getattr_maxsz + \
593 encode_getfh_maxsz)
594#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400595 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 decode_putfh_maxsz + \
597 decode_symlink_maxsz + \
598 decode_getattr_maxsz + \
599 decode_getfh_maxsz)
600#define NFS4_enc_create_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 + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400603 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400605 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400607 encode_restorefh_maxsz + \
608 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400610 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400612 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400614 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400616 decode_restorefh_maxsz + \
617 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400619 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 encode_putfh_maxsz + \
621 encode_getattr_maxsz)
622#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400623 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 decode_putfh_maxsz + \
625 decode_getattr_maxsz)
626#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400627 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400629 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400631 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400633 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400635 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800636 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 encode_getattr_maxsz)
638#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400639 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800640 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 decode_getattr_maxsz)
642#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400643 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100645 encode_delegreturn_maxsz + \
646 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100649 decode_delegreturn_maxsz + \
650 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000651#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400652 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000653 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400654 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000655#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400656 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000657 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400658 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000659#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400660 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000661 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400662 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000663#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400664 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000665 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400666 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400667#define NFS4_enc_fs_locations_sz \
668 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400669 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400670 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400671 encode_lookup_maxsz + \
672 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400673#define NFS4_dec_fs_locations_sz \
674 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400675 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400676 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400677 decode_lookup_maxsz + \
678 decode_fs_locations_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400679#if defined(CONFIG_NFS_V4_1)
680#define NFS4_enc_exchange_id_sz \
681 (compound_encode_hdr_maxsz + \
682 encode_exchange_id_maxsz)
683#define NFS4_dec_exchange_id_sz \
684 (compound_decode_hdr_maxsz + \
685 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400686#define NFS4_enc_create_session_sz \
687 (compound_encode_hdr_maxsz + \
688 encode_create_session_maxsz)
689#define NFS4_dec_create_session_sz \
690 (compound_decode_hdr_maxsz + \
691 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400692#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
693 encode_destroy_session_maxsz)
694#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
695 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400696#define NFS4_enc_sequence_sz \
697 (compound_decode_hdr_maxsz + \
698 encode_sequence_maxsz)
699#define NFS4_dec_sequence_sz \
700 (compound_decode_hdr_maxsz + \
701 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400702#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
703 encode_sequence_maxsz + \
704 encode_putrootfh_maxsz + \
705 encode_fsinfo_maxsz)
706#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
707 decode_sequence_maxsz + \
708 decode_putrootfh_maxsz + \
709 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500710#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
711 encode_sequence_maxsz + \
712 encode_reclaim_complete_maxsz)
713#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
714 decode_sequence_maxsz + \
715 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400716#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
717 encode_sequence_maxsz +\
718 encode_getdeviceinfo_maxsz)
719#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
720 decode_sequence_maxsz + \
721 decode_getdeviceinfo_maxsz)
722#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
723 encode_sequence_maxsz + \
724 encode_putfh_maxsz + \
725 encode_layoutget_maxsz)
726#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
727 decode_sequence_maxsz + \
728 decode_putfh_maxsz + \
729 decode_layoutget_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500730
731const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
732 compound_encode_hdr_maxsz +
733 encode_sequence_maxsz +
734 encode_putfh_maxsz +
735 encode_getattr_maxsz) *
736 XDR_UNIT);
737
738const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
739 compound_decode_hdr_maxsz +
740 decode_sequence_maxsz +
741 decode_putfh_maxsz) *
742 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400743#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Trond Myklebustbca79472009-03-11 14:10:26 -0400745static const umode_t nfs_type2fmt[] = {
746 [NF4BAD] = 0,
747 [NF4REG] = S_IFREG,
748 [NF4DIR] = S_IFDIR,
749 [NF4BLK] = S_IFBLK,
750 [NF4CHR] = S_IFCHR,
751 [NF4LNK] = S_IFLNK,
752 [NF4SOCK] = S_IFSOCK,
753 [NF4FIFO] = S_IFIFO,
754 [NF4ATTRDIR] = 0,
755 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756};
757
758struct compound_hdr {
759 int32_t status;
760 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500761 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 uint32_t taglen;
763 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400764 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400765 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766};
767
Benny Halevy13c65ce2009-08-14 17:19:25 +0300768static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
769{
770 __be32 *p = xdr_reserve_space(xdr, nbytes);
771 BUG_ON(!p);
772 return p;
773}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
775static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
776{
Al Viro8687b632006-10-19 23:28:48 -0700777 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779 p = xdr_reserve_space(xdr, 4 + len);
780 BUG_ON(p == NULL);
781 xdr_encode_opaque(p, str, len);
782}
783
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400784static void encode_compound_hdr(struct xdr_stream *xdr,
785 struct rpc_rqst *req,
786 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787{
Al Viro8687b632006-10-19 23:28:48 -0700788 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400789 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400790
791 /* initialize running count of expected bytes in reply.
792 * NOTE: the replied tag SHOULD be the same is the one sent,
793 * but this is not required as a MUST for the server to do so. */
794 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
796 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
797 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300798 p = reserve_space(xdr, 4 + hdr->taglen + 8);
799 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300800 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500801 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300802 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500803}
804
805static void encode_nops(struct compound_hdr *hdr)
806{
Andy Adamsonfc931582009-04-01 09:22:31 -0400807 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500808 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809}
810
811static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
812{
Al Viro8687b632006-10-19 23:28:48 -0700813 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
816 BUG_ON(p == NULL);
817 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
818}
819
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500820static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
822 char owner_name[IDMAP_NAMESZ];
823 char owner_group[IDMAP_NAMESZ];
824 int owner_namelen = 0;
825 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700826 __be32 *p;
827 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 int len;
829 uint32_t bmval0 = 0;
830 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832 /*
833 * We reserve enough space to write the entire attribute buffer at once.
834 * In the worst-case, this would be
835 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
836 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000837 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 */
839 len = 16;
840
841 /* Sigh */
842 if (iap->ia_valid & ATTR_SIZE)
843 len += 8;
844 if (iap->ia_valid & ATTR_MODE)
845 len += 4;
846 if (iap->ia_valid & ATTR_UID) {
Bryan Schumaker955a8572010-09-29 15:41:49 -0400847 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400849 dprintk("nfs: couldn't resolve uid %d to string\n",
850 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 /* XXX */
852 strcpy(owner_name, "nobody");
853 owner_namelen = sizeof("nobody") - 1;
854 /* goto out; */
855 }
856 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
857 }
858 if (iap->ia_valid & ATTR_GID) {
Bryan Schumaker955a8572010-09-29 15:41:49 -0400859 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400861 dprintk("nfs: couldn't resolve gid %d to string\n",
862 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 strcpy(owner_group, "nobody");
864 owner_grouplen = sizeof("nobody") - 1;
865 /* goto out; */
866 }
867 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
868 }
869 if (iap->ia_valid & ATTR_ATIME_SET)
870 len += 16;
871 else if (iap->ia_valid & ATTR_ATIME)
872 len += 4;
873 if (iap->ia_valid & ATTR_MTIME_SET)
874 len += 16;
875 else if (iap->ia_valid & ATTR_MTIME)
876 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300877 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
879 /*
880 * We write the bitmap length now, but leave the bitmap and the attribute
881 * buffer length to be backfilled at the end of this routine.
882 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300883 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 q = p;
885 p += 3;
886
887 if (iap->ia_valid & ATTR_SIZE) {
888 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300889 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 }
891 if (iap->ia_valid & ATTR_MODE) {
892 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300893 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 }
895 if (iap->ia_valid & ATTR_UID) {
896 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300897 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 }
899 if (iap->ia_valid & ATTR_GID) {
900 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300901 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 }
903 if (iap->ia_valid & ATTR_ATIME_SET) {
904 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300905 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
906 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -0400907 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
908 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 }
910 else if (iap->ia_valid & ATTR_ATIME) {
911 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300912 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 }
914 if (iap->ia_valid & ATTR_MTIME_SET) {
915 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300916 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
917 *p++ = cpu_to_be32(0);
918 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
919 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 }
921 else if (iap->ia_valid & ATTR_MTIME) {
922 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300923 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 /*
927 * Now we backfill the bitmap and the attribute buffer length.
928 */
929 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400930 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 len, ((char *)p - (char *)q) + 4);
932 BUG();
933 }
934 len = (char *)p - (char *)q - 12;
935 *q++ = htonl(bmval0);
936 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300937 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940}
941
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500942static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943{
Al Viro8687b632006-10-19 23:28:48 -0700944 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
Benny Halevy13c65ce2009-08-14 17:19:25 +0300946 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300947 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +0300948 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500949 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400950 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951}
952
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500953static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
Al Viro8687b632006-10-19 23:28:48 -0700955 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Benny Halevy13c65ce2009-08-14 17:19:25 +0300957 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300958 *p++ = cpu_to_be32(OP_CLOSE);
959 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +0300960 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500961 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400962 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963}
964
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500965static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
Al Viro8687b632006-10-19 23:28:48 -0700967 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500968
Benny Halevy13c65ce2009-08-14 17:19:25 +0300969 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300970 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +0300971 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +0300972 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500973 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400974 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975}
976
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500977static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978{
Al Viro8687b632006-10-19 23:28:48 -0700979 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500980
Benny Halevy13c65ce2009-08-14 17:19:25 +0300981 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300982 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +0300983 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
985 switch (create->ftype) {
986 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300987 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +0300988 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -0400989 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 break;
991
992 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300993 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300994 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +0300995 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 break;
997
998 default:
999 break;
1000 }
1001
Benny Halevy811652b2009-08-14 17:19:34 +03001002 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001003 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001004 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001006 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007}
1008
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001009static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010{
Andy Adamson05d564f2008-12-23 16:06:15 -05001011 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Benny Halevy13c65ce2009-08-14 17:19:25 +03001013 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001014 *p++ = cpu_to_be32(OP_GETATTR);
1015 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001016 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001017 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001018 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019}
1020
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001021static 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 -07001022{
Andy Adamson05d564f2008-12-23 16:06:15 -05001023 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
Benny Halevy13c65ce2009-08-14 17:19:25 +03001025 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001026 *p++ = cpu_to_be32(OP_GETATTR);
1027 *p++ = cpu_to_be32(2);
1028 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001029 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001030 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001031 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032}
1033
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001034static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001036 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1037 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038}
1039
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001040static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001042 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1043 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044}
1045
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001046static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001047{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001048 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1049 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001050}
1051
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001052static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053{
Al Viro8687b632006-10-19 23:28:48 -07001054 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Benny Halevy13c65ce2009-08-14 17:19:25 +03001056 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001057 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001058 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001059 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060}
1061
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001062static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063{
Al Viro8687b632006-10-19 23:28:48 -07001064 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Benny Halevy13c65ce2009-08-14 17:19:25 +03001066 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001067 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001068 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001069 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001070 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001073static inline int nfs4_lock_type(struct file_lock *fl, int block)
1074{
1075 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1076 return block ? NFS4_READW_LT : NFS4_READ_LT;
1077 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1078}
1079
1080static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1081{
1082 if (fl->fl_end == OFFSET_MAX)
1083 return ~(uint64_t)0;
1084 return fl->fl_end - fl->fl_start + 1;
1085}
1086
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001087static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1088{
1089 __be32 *p;
1090
Trond Myklebustd035c362010-12-21 10:45:27 -05001091 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001092 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001093 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001094 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001095 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001096 xdr_encode_hyper(p, lowner->id);
1097}
1098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099/*
1100 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1101 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1102 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001103static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104{
Al Viro8687b632006-10-19 23:28:48 -07001105 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
Benny Halevy13c65ce2009-08-14 17:19:25 +03001107 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001108 *p++ = cpu_to_be32(OP_LOCK);
1109 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1110 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001111 p = xdr_encode_hyper(p, args->fl->fl_start);
1112 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001113 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001114 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001115 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001116 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001117 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001118 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001119 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 }
1121 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001122 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001123 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001124 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 }
Andy Adamsond0179312008-12-23 16:06:17 -05001126 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001127 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128}
1129
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001130static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131{
Al Viro8687b632006-10-19 23:28:48 -07001132 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001134 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001135 *p++ = cpu_to_be32(OP_LOCKT);
1136 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001137 p = xdr_encode_hyper(p, args->fl->fl_start);
1138 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001139 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001140 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001141 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
1143
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001144static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
Al Viro8687b632006-10-19 23:28:48 -07001146 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Benny Halevy13c65ce2009-08-14 17:19:25 +03001148 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001149 *p++ = cpu_to_be32(OP_LOCKU);
1150 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1151 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001152 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001153 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001154 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001155 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001156 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157}
1158
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001159static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1160{
1161 __be32 *p;
1162
1163 p = reserve_space(xdr, 4);
1164 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1165 encode_lockowner(xdr, lowner);
1166 hdr->nops++;
1167 hdr->replen += decode_release_lockowner_maxsz;
1168}
1169
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001170static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171{
1172 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001173 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Benny Halevy13c65ce2009-08-14 17:19:25 +03001175 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001176 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001177 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001178 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001179 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180}
1181
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001182static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183{
Al Viro8687b632006-10-19 23:28:48 -07001184 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185
Benny Halevy13c65ce2009-08-14 17:19:25 +03001186 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001187 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001188 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001189 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001190 break;
1191 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001192 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001193 break;
1194 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001195 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001196 break;
1197 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001198 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 }
Benny Halevy34558512009-08-14 17:19:30 +03001200 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201}
1202
1203static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1204{
Al Viro8687b632006-10-19 23:28:48 -07001205 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 /*
1207 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1208 * owner 4 = 32
1209 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001210 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001211 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001212 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001213 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001214 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001215 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001216 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001217 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001218 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001219 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220}
1221
1222static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1223{
Al Viro8687b632006-10-19 23:28:48 -07001224 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001225 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
Benny Halevy13c65ce2009-08-14 17:19:25 +03001227 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001229 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001230 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001231 encode_attrs(xdr, arg->u.attrs, arg->server);
1232 break;
1233 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001234 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001235 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001236 if (nfs4_has_persistent_session(clp)) {
1237 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1238 encode_attrs(xdr, arg->u.attrs, arg->server);
1239 } else {
1240 struct iattr dummy;
1241
1242 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1243 encode_nfs4_verifier(xdr, &arg->u.verifier);
1244 dummy.ia_valid = 0;
1245 encode_attrs(xdr, &dummy, arg->server);
1246 }
1247 } else {
1248 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1249 encode_nfs4_verifier(xdr, &arg->u.verifier);
1250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 }
1252}
1253
1254static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1255{
Al Viro8687b632006-10-19 23:28:48 -07001256 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Benny Halevy13c65ce2009-08-14 17:19:25 +03001258 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001260 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001261 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001262 break;
1263 default:
1264 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001265 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001266 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 }
1268}
1269
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001270static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271{
Al Viro8687b632006-10-19 23:28:48 -07001272 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
Benny Halevy13c65ce2009-08-14 17:19:25 +03001274 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001276 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001277 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001278 break;
1279 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001280 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001281 break;
1282 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001283 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001284 break;
1285 default:
1286 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 }
1288}
1289
1290static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1291{
Al Viro8687b632006-10-19 23:28:48 -07001292 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Benny Halevy13c65ce2009-08-14 17:19:25 +03001294 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001295 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 encode_string(xdr, name->len, name->name);
1297}
1298
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001299static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300{
Al Viro8687b632006-10-19 23:28:48 -07001301 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
Benny Halevy13c65ce2009-08-14 17:19:25 +03001303 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001304 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 encode_delegation_type(xdr, type);
1306}
1307
1308static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1309{
Al Viro8687b632006-10-19 23:28:48 -07001310 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Benny Halevy13c65ce2009-08-14 17:19:25 +03001312 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001313 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001314 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 encode_string(xdr, name->len, name->name);
1316}
1317
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001318static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319{
1320 encode_openhdr(xdr, arg);
1321 encode_opentype(xdr, arg);
1322 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001323 case NFS4_OPEN_CLAIM_NULL:
1324 encode_claim_null(xdr, arg->name);
1325 break;
1326 case NFS4_OPEN_CLAIM_PREVIOUS:
1327 encode_claim_previous(xdr, arg->u.delegation_type);
1328 break;
1329 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1330 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1331 break;
1332 default:
1333 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 }
Andy Adamsond0179312008-12-23 16:06:17 -05001335 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001336 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337}
1338
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001339static 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 -07001340{
Al Viro8687b632006-10-19 23:28:48 -07001341 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Benny Halevy13c65ce2009-08-14 17:19:25 +03001343 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001344 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001345 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001346 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001347 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001348 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349}
1350
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001351static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352{
Al Viro8687b632006-10-19 23:28:48 -07001353 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Benny Halevy13c65ce2009-08-14 17:19:25 +03001355 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001356 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001357 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001358 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001359 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001360 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001361 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362}
1363
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001364static void
Andy Adamsond0179312008-12-23 16:06:17 -05001365encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366{
1367 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001368 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Benny Halevy13c65ce2009-08-14 17:19:25 +03001370 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001371 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001372 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001373 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001374 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375}
1376
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001377static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
Andy Adamson05d564f2008-12-23 16:06:15 -05001379 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001380
Benny Halevy13c65ce2009-08-14 17:19:25 +03001381 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001382 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001383 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001384 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385}
1386
Andy Adamson89d1ea62011-03-01 01:34:09 +00001387static 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 -07001388{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001390 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
Benny Halevy13c65ce2009-08-14 17:19:25 +03001392 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001394 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001395 if (zero_seqid)
1396 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001397 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 } else
Benny Halevy34558512009-08-14 17:19:30 +03001399 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400}
1401
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001402static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403{
Al Viro8687b632006-10-19 23:28:48 -07001404 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Benny Halevy13c65ce2009-08-14 17:19:25 +03001406 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001407 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Andy Adamson89d1ea62011-03-01 01:34:09 +00001409 encode_stateid(xdr, args->context, args->lock_context,
1410 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
Benny Halevy13c65ce2009-08-14 17:19:25 +03001412 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001413 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001414 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001415 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001416 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417}
1418
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001419static 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 -07001420{
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001421 uint32_t attrs[2] = {0, 0};
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001422 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001423 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001425 if (readdir->plus) {
1426 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1427 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE;
1428 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1429 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1430 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1431 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001432 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001433 }
1434 attrs[0] |= FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID;
1435 attrs[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001436 /* Switch to mounted_on_fileid if the server supports it */
1437 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1438 attrs[0] &= ~FATTR4_WORD0_FILEID;
1439 else
1440 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001441
Benny Halevy13c65ce2009-08-14 17:19:25 +03001442 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001443 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001444 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001445 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001446 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001447 *p++ = cpu_to_be32(readdir->count);
1448 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001449
Benny Halevye75bc1c2009-08-14 17:18:54 +03001450 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001451 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001452 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001453 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001454 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1455 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001456 (unsigned long long)readdir->cookie,
1457 ((u32 *)readdir->verifier.data)[0],
1458 ((u32 *)readdir->verifier.data)[1],
1459 attrs[0] & readdir->bitmask[0],
1460 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461}
1462
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001463static 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 -07001464{
Al Viro8687b632006-10-19 23:28:48 -07001465 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Benny Halevy13c65ce2009-08-14 17:19:25 +03001467 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001468 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001469 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001470 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471}
1472
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001473static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474{
Al Viro8687b632006-10-19 23:28:48 -07001475 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Benny Halevy13c65ce2009-08-14 17:19:25 +03001477 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001478 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001479 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001480 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001481 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482}
1483
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001484static 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 -07001485{
Al Viro8687b632006-10-19 23:28:48 -07001486 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Benny Halevy811652b2009-08-14 17:19:34 +03001488 p = reserve_space(xdr, 4);
1489 *p = cpu_to_be32(OP_RENAME);
1490 encode_string(xdr, oldname->len, oldname->name);
1491 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001492 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001493 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494}
1495
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001496static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, 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, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001501 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001502 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001503 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001504 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505}
1506
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001507static void
Andy Adamsond0179312008-12-23 16:06:17 -05001508encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001509{
Al Viro8687b632006-10-19 23:28:48 -07001510 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001511
Benny Halevy13c65ce2009-08-14 17:19:25 +03001512 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001513 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001514 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001515 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001516}
1517
Chuck Lever9f06c712010-12-14 14:59:18 +00001518static void
Andy Adamsond0179312008-12-23 16:06:17 -05001519encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001520{
Al Viro8687b632006-10-19 23:28:48 -07001521 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001522
Benny Halevy13c65ce2009-08-14 17:19:25 +03001523 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001524 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001525 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001526 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001527 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001528 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001529 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001530 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001531 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001532 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001533 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001534 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001535}
1536
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001537static void
Andy Adamsond0179312008-12-23 16:06:17 -05001538encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539{
Al Viro8687b632006-10-19 23:28:48 -07001540 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
Benny Halevy13c65ce2009-08-14 17:19:25 +03001542 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001543 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001544 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001545 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546}
1547
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001548static 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 -07001549{
Al Viro8687b632006-10-19 23:28:48 -07001550 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001551
Benny Halevy13c65ce2009-08-14 17:19:25 +03001552 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001553 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001554 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001555 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001556 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001557 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558}
1559
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001560static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
Al Viro8687b632006-10-19 23:28:48 -07001562 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
Benny Halevy13c65ce2009-08-14 17:19:25 +03001564 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001565 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001566 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
1568 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001569 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001570 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1572 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001573 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001574 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001575 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001576 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577}
1578
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001579static 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 -07001580{
Andy Adamson05d564f2008-12-23 16:06:15 -05001581 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
Benny Halevy13c65ce2009-08-14 17:19:25 +03001583 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001584 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001585 p = xdr_encode_hyper(p, arg->clientid);
1586 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001587 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001588 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589}
1590
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001591static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592{
Al Viro8687b632006-10-19 23:28:48 -07001593 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594
Benny Halevy13c65ce2009-08-14 17:19:25 +03001595 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001596 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
Andy Adamson89d1ea62011-03-01 01:34:09 +00001598 encode_stateid(xdr, args->context, args->lock_context,
1599 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
Benny Halevy13c65ce2009-08-14 17:19:25 +03001601 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001602 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001603 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001604 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
1606 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001607 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001608 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609}
1610
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001611static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612{
Al Viro8687b632006-10-19 23:28:48 -07001613 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
Benny Halevy13c65ce2009-08-14 17:19:25 +03001615 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
Benny Halevye75bc1c2009-08-14 17:18:54 +03001617 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001618 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001619 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001620 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001622
Benny Halevy99fe60d2009-04-01 09:22:29 -04001623#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001624/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001625static void encode_exchange_id(struct xdr_stream *xdr,
1626 struct nfs41_exchange_id_args *args,
1627 struct compound_hdr *hdr)
1628{
1629 __be32 *p;
1630
Benny Halevy13c65ce2009-08-14 17:19:25 +03001631 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001632 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001633 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001634
1635 encode_string(xdr, args->id_len, args->id);
1636
Benny Halevy13c65ce2009-08-14 17:19:25 +03001637 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001638 *p++ = cpu_to_be32(args->flags);
1639 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001640 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001641 hdr->nops++;
1642 hdr->replen += decode_exchange_id_maxsz;
1643}
Andy Adamsonfc931582009-04-01 09:22:31 -04001644
1645static void encode_create_session(struct xdr_stream *xdr,
1646 struct nfs41_create_session_args *args,
1647 struct compound_hdr *hdr)
1648{
1649 __be32 *p;
1650 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1651 uint32_t len;
1652 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001653 u32 max_resp_sz_cached;
1654
1655 /*
1656 * Assumes OPEN is the biggest non-idempotent compound.
1657 * 2 is the verifier.
1658 */
1659 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1660 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001661
Andy Adamsonfc931582009-04-01 09:22:31 -04001662 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1663 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001664
Benny Halevy13c65ce2009-08-14 17:19:25 +03001665 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001666 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001667 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001668 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1669 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001670
Andy Adamsonfc931582009-04-01 09:22:31 -04001671 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001672 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1673 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1674 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001675 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001676 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1677 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1678 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001679
1680 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001681 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1682 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1683 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1684 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1685 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1686 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1687 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001688
Benny Halevye75bc1c2009-08-14 17:18:54 +03001689 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001690 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001691 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001692
1693 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001694 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001695 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001696 *p++ = cpu_to_be32(0); /* UID */
1697 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001698 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001699 hdr->nops++;
1700 hdr->replen += decode_create_session_maxsz;
1701}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001702
1703static void encode_destroy_session(struct xdr_stream *xdr,
1704 struct nfs4_session *session,
1705 struct compound_hdr *hdr)
1706{
1707 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001708 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001709 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001710 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001711 hdr->nops++;
1712 hdr->replen += decode_destroy_session_maxsz;
1713}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001714
1715static void encode_reclaim_complete(struct xdr_stream *xdr,
1716 struct nfs41_reclaim_complete_args *args,
1717 struct compound_hdr *hdr)
1718{
1719 __be32 *p;
1720
1721 p = reserve_space(xdr, 8);
1722 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1723 *p++ = cpu_to_be32(args->one_fs);
1724 hdr->nops++;
1725 hdr->replen += decode_reclaim_complete_maxsz;
1726}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001727#endif /* CONFIG_NFS_V4_1 */
1728
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001729static void encode_sequence(struct xdr_stream *xdr,
1730 const struct nfs4_sequence_args *args,
1731 struct compound_hdr *hdr)
1732{
1733#if defined(CONFIG_NFS_V4_1)
1734 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001735 struct nfs4_slot_table *tp;
1736 struct nfs4_slot *slot;
1737 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001738
1739 if (!session)
1740 return;
1741
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001742 tp = &session->fc_slot_table;
1743
1744 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1745 slot = tp->slots + args->sa_slotid;
1746
Benny Halevy13c65ce2009-08-14 17:19:25 +03001747 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001748 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001749
1750 /*
1751 * Sessionid + seqid + slotid + max slotid + cache_this
1752 */
1753 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1754 "max_slotid=%d cache_this=%d\n",
1755 __func__,
1756 ((u32 *)session->sess_id.data)[0],
1757 ((u32 *)session->sess_id.data)[1],
1758 ((u32 *)session->sess_id.data)[2],
1759 ((u32 *)session->sess_id.data)[3],
1760 slot->seq_nr, args->sa_slotid,
1761 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001762 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001763 *p++ = cpu_to_be32(slot->seq_nr);
1764 *p++ = cpu_to_be32(args->sa_slotid);
1765 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001766 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001767 hdr->nops++;
1768 hdr->replen += decode_sequence_maxsz;
1769#endif /* CONFIG_NFS_V4_1 */
1770}
1771
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001772#ifdef CONFIG_NFS_V4_1
1773static void
1774encode_getdeviceinfo(struct xdr_stream *xdr,
1775 const struct nfs4_getdeviceinfo_args *args,
1776 struct compound_hdr *hdr)
1777{
1778 __be32 *p;
1779
1780 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1781 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1782 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1783 NFS4_DEVICEID4_SIZE);
1784 *p++ = cpu_to_be32(args->pdev->layout_type);
1785 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1786 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1787 hdr->nops++;
1788 hdr->replen += decode_getdeviceinfo_maxsz;
1789}
1790
1791static void
1792encode_layoutget(struct xdr_stream *xdr,
1793 const struct nfs4_layoutget_args *args,
1794 struct compound_hdr *hdr)
1795{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001796 __be32 *p;
1797
1798 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1799 *p++ = cpu_to_be32(OP_LAYOUTGET);
1800 *p++ = cpu_to_be32(0); /* Signal layout available */
1801 *p++ = cpu_to_be32(args->type);
1802 *p++ = cpu_to_be32(args->range.iomode);
1803 p = xdr_encode_hyper(p, args->range.offset);
1804 p = xdr_encode_hyper(p, args->range.length);
1805 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00001806 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001807 *p = cpu_to_be32(args->maxcount);
1808
1809 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1810 __func__,
1811 args->type,
1812 args->range.iomode,
1813 (unsigned long)args->range.offset,
1814 (unsigned long)args->range.length,
1815 args->maxcount);
1816 hdr->nops++;
1817 hdr->replen += decode_layoutget_maxsz;
1818}
1819#endif /* CONFIG_NFS_V4_1 */
1820
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821/*
1822 * END OF "GENERIC" ENCODE ROUTINES.
1823 */
1824
Benny Halevy66cc0422009-04-01 09:22:10 -04001825static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1826{
1827#if defined(CONFIG_NFS_V4_1)
1828 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001829 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001830#endif /* CONFIG_NFS_V4_1 */
1831 return 0;
1832}
1833
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834/*
1835 * Encode an ACCESS request
1836 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001837static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1838 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001841 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
Chuck Lever9f06c712010-12-14 14:59:18 +00001844 encode_compound_hdr(xdr, req, &hdr);
1845 encode_sequence(xdr, &args->seq_args, &hdr);
1846 encode_putfh(xdr, args->fh, &hdr);
1847 encode_access(xdr, args->access, &hdr);
1848 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001849 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850}
1851
1852/*
1853 * Encode LOOKUP request
1854 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001855static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1856 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001859 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861
Chuck Lever9f06c712010-12-14 14:59:18 +00001862 encode_compound_hdr(xdr, req, &hdr);
1863 encode_sequence(xdr, &args->seq_args, &hdr);
1864 encode_putfh(xdr, args->dir_fh, &hdr);
1865 encode_lookup(xdr, args->name, &hdr);
1866 encode_getfh(xdr, &hdr);
1867 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001868 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869}
1870
1871/*
1872 * Encode LOOKUP_ROOT request
1873 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001874static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
1875 struct xdr_stream *xdr,
1876 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001879 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881
Chuck Lever9f06c712010-12-14 14:59:18 +00001882 encode_compound_hdr(xdr, req, &hdr);
1883 encode_sequence(xdr, &args->seq_args, &hdr);
1884 encode_putrootfh(xdr, &hdr);
1885 encode_getfh(xdr, &hdr);
1886 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001887 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888}
1889
1890/*
1891 * Encode REMOVE request
1892 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001893static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
1894 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001897 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899
Chuck Lever9f06c712010-12-14 14:59:18 +00001900 encode_compound_hdr(xdr, req, &hdr);
1901 encode_sequence(xdr, &args->seq_args, &hdr);
1902 encode_putfh(xdr, args->fh, &hdr);
1903 encode_remove(xdr, &args->name, &hdr);
1904 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001905 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906}
1907
1908/*
1909 * Encode RENAME request
1910 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001911static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
1912 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001915 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
Chuck Lever9f06c712010-12-14 14:59:18 +00001918 encode_compound_hdr(xdr, req, &hdr);
1919 encode_sequence(xdr, &args->seq_args, &hdr);
1920 encode_putfh(xdr, args->old_dir, &hdr);
1921 encode_savefh(xdr, &hdr);
1922 encode_putfh(xdr, args->new_dir, &hdr);
1923 encode_rename(xdr, args->old_name, args->new_name, &hdr);
1924 encode_getfattr(xdr, args->bitmask, &hdr);
1925 encode_restorefh(xdr, &hdr);
1926 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001927 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928}
1929
1930/*
1931 * Encode LINK request
1932 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001933static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
1934 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001937 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939
Chuck Lever9f06c712010-12-14 14:59:18 +00001940 encode_compound_hdr(xdr, req, &hdr);
1941 encode_sequence(xdr, &args->seq_args, &hdr);
1942 encode_putfh(xdr, args->fh, &hdr);
1943 encode_savefh(xdr, &hdr);
1944 encode_putfh(xdr, args->dir_fh, &hdr);
1945 encode_link(xdr, args->name, &hdr);
1946 encode_getfattr(xdr, args->bitmask, &hdr);
1947 encode_restorefh(xdr, &hdr);
1948 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001949 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950}
1951
1952/*
1953 * Encode CREATE request
1954 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001955static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
1956 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001959 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
Chuck Lever9f06c712010-12-14 14:59:18 +00001962 encode_compound_hdr(xdr, req, &hdr);
1963 encode_sequence(xdr, &args->seq_args, &hdr);
1964 encode_putfh(xdr, args->dir_fh, &hdr);
1965 encode_savefh(xdr, &hdr);
1966 encode_create(xdr, args, &hdr);
1967 encode_getfh(xdr, &hdr);
1968 encode_getfattr(xdr, args->bitmask, &hdr);
1969 encode_restorefh(xdr, &hdr);
1970 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001971 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972}
1973
1974/*
1975 * Encode SYMLINK request
1976 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001977static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
1978 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979{
Chuck Lever9f06c712010-12-14 14:59:18 +00001980 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981}
1982
1983/*
1984 * Encode GETATTR request
1985 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001986static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
1987 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001990 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992
Chuck Lever9f06c712010-12-14 14:59:18 +00001993 encode_compound_hdr(xdr, req, &hdr);
1994 encode_sequence(xdr, &args->seq_args, &hdr);
1995 encode_putfh(xdr, args->fh, &hdr);
1996 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001997 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998}
1999
2000/*
2001 * Encode a CLOSE request
2002 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002003static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2004 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005{
Andy Adamson05d564f2008-12-23 16:06:15 -05002006 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002007 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002008 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009
Chuck Lever9f06c712010-12-14 14:59:18 +00002010 encode_compound_hdr(xdr, req, &hdr);
2011 encode_sequence(xdr, &args->seq_args, &hdr);
2012 encode_putfh(xdr, args->fh, &hdr);
2013 encode_close(xdr, args, &hdr);
2014 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002015 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016}
2017
2018/*
2019 * Encode an OPEN request
2020 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002021static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2022 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002025 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027
Chuck Lever9f06c712010-12-14 14:59:18 +00002028 encode_compound_hdr(xdr, req, &hdr);
2029 encode_sequence(xdr, &args->seq_args, &hdr);
2030 encode_putfh(xdr, args->fh, &hdr);
2031 encode_savefh(xdr, &hdr);
2032 encode_open(xdr, args, &hdr);
2033 encode_getfh(xdr, &hdr);
2034 encode_getfattr(xdr, args->bitmask, &hdr);
2035 encode_restorefh(xdr, &hdr);
2036 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002037 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038}
2039
2040/*
2041 * Encode an OPEN_CONFIRM request
2042 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002043static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2044 struct xdr_stream *xdr,
2045 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002048 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
Chuck Lever9f06c712010-12-14 14:59:18 +00002051 encode_compound_hdr(xdr, req, &hdr);
2052 encode_putfh(xdr, args->fh, &hdr);
2053 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002054 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055}
2056
2057/*
2058 * Encode an OPEN request with no attributes.
2059 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002060static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2061 struct xdr_stream *xdr,
2062 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002065 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067
Chuck Lever9f06c712010-12-14 14:59:18 +00002068 encode_compound_hdr(xdr, req, &hdr);
2069 encode_sequence(xdr, &args->seq_args, &hdr);
2070 encode_putfh(xdr, args->fh, &hdr);
2071 encode_open(xdr, args, &hdr);
2072 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002073 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074}
2075
2076/*
2077 * Encode an OPEN_DOWNGRADE request
2078 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002079static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2080 struct xdr_stream *xdr,
2081 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002084 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086
Chuck Lever9f06c712010-12-14 14:59:18 +00002087 encode_compound_hdr(xdr, req, &hdr);
2088 encode_sequence(xdr, &args->seq_args, &hdr);
2089 encode_putfh(xdr, args->fh, &hdr);
2090 encode_open_downgrade(xdr, args, &hdr);
2091 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002092 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093}
2094
2095/*
2096 * Encode a LOCK request
2097 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002098static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2099 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002102 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
Chuck Lever9f06c712010-12-14 14:59:18 +00002105 encode_compound_hdr(xdr, req, &hdr);
2106 encode_sequence(xdr, &args->seq_args, &hdr);
2107 encode_putfh(xdr, args->fh, &hdr);
2108 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002109 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110}
2111
2112/*
2113 * Encode a LOCKT request
2114 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002115static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2116 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002119 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121
Chuck Lever9f06c712010-12-14 14:59:18 +00002122 encode_compound_hdr(xdr, req, &hdr);
2123 encode_sequence(xdr, &args->seq_args, &hdr);
2124 encode_putfh(xdr, args->fh, &hdr);
2125 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002126 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127}
2128
2129/*
2130 * Encode a LOCKU request
2131 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002132static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2133 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002136 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
Chuck Lever9f06c712010-12-14 14:59:18 +00002139 encode_compound_hdr(xdr, req, &hdr);
2140 encode_sequence(xdr, &args->seq_args, &hdr);
2141 encode_putfh(xdr, args->fh, &hdr);
2142 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002143 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144}
2145
Chuck Lever9f06c712010-12-14 14:59:18 +00002146static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2147 struct xdr_stream *xdr,
2148 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002149{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002150 struct compound_hdr hdr = {
2151 .minorversion = 0,
2152 };
2153
Chuck Lever9f06c712010-12-14 14:59:18 +00002154 encode_compound_hdr(xdr, req, &hdr);
2155 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002156 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002157}
2158
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159/*
2160 * Encode a READLINK request
2161 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002162static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2163 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002166 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
Chuck Lever9f06c712010-12-14 14:59:18 +00002169 encode_compound_hdr(xdr, req, &hdr);
2170 encode_sequence(xdr, &args->seq_args, &hdr);
2171 encode_putfh(xdr, args->fh, &hdr);
2172 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002173
Benny Halevy28f56692009-04-01 09:22:09 -04002174 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002175 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002176 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177}
2178
2179/*
2180 * Encode a READDIR request
2181 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002182static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2183 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002186 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
Chuck Lever9f06c712010-12-14 14:59:18 +00002189 encode_compound_hdr(xdr, req, &hdr);
2190 encode_sequence(xdr, &args->seq_args, &hdr);
2191 encode_putfh(xdr, args->fh, &hdr);
2192 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002193
Benny Halevy28f56692009-04-01 09:22:09 -04002194 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002195 args->pgbase, args->count);
2196 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002197 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002198 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002199 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200}
2201
2202/*
2203 * Encode a READ request
2204 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002205static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2206 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002209 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
Chuck Lever9f06c712010-12-14 14:59:18 +00002212 encode_compound_hdr(xdr, req, &hdr);
2213 encode_sequence(xdr, &args->seq_args, &hdr);
2214 encode_putfh(xdr, args->fh, &hdr);
2215 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
Benny Halevy28f56692009-04-01 09:22:09 -04002217 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002219 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002220 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221}
2222
2223/*
2224 * Encode an SETATTR request
2225 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002226static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2227 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228{
Andy Adamson05d564f2008-12-23 16:06:15 -05002229 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002230 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002231 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
Chuck Lever9f06c712010-12-14 14:59:18 +00002233 encode_compound_hdr(xdr, req, &hdr);
2234 encode_sequence(xdr, &args->seq_args, &hdr);
2235 encode_putfh(xdr, args->fh, &hdr);
2236 encode_setattr(xdr, args, args->server, &hdr);
2237 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002238 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239}
2240
2241/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002242 * Encode a GETACL request
2243 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002244static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2245 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002246{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002247 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002248 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002249 };
Benny Halevy28f56692009-04-01 09:22:09 -04002250 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002251
Chuck Lever9f06c712010-12-14 14:59:18 +00002252 encode_compound_hdr(xdr, req, &hdr);
2253 encode_sequence(xdr, &args->seq_args, &hdr);
2254 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002255 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002256 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002257
Benny Halevy28f56692009-04-01 09:22:09 -04002258 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002259 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002260 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002261}
2262
2263/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 * Encode a WRITE request
2265 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002266static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2267 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002270 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272
Chuck Lever9f06c712010-12-14 14:59:18 +00002273 encode_compound_hdr(xdr, req, &hdr);
2274 encode_sequence(xdr, &args->seq_args, &hdr);
2275 encode_putfh(xdr, args->fh, &hdr);
2276 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002277 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002278 if (args->bitmask)
2279 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002280 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281}
2282
2283/*
2284 * a COMMIT request
2285 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002286static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2287 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002290 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
Chuck Lever9f06c712010-12-14 14:59:18 +00002293 encode_compound_hdr(xdr, req, &hdr);
2294 encode_sequence(xdr, &args->seq_args, &hdr);
2295 encode_putfh(xdr, args->fh, &hdr);
2296 encode_commit(xdr, args, &hdr);
2297 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002298 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299}
2300
2301/*
2302 * FSINFO request
2303 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002304static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2305 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002308 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
Chuck Lever9f06c712010-12-14 14:59:18 +00002311 encode_compound_hdr(xdr, req, &hdr);
2312 encode_sequence(xdr, &args->seq_args, &hdr);
2313 encode_putfh(xdr, args->fh, &hdr);
2314 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002315 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316}
2317
2318/*
2319 * a PATHCONF request
2320 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002321static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2322 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002325 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
Chuck Lever9f06c712010-12-14 14:59:18 +00002328 encode_compound_hdr(xdr, req, &hdr);
2329 encode_sequence(xdr, &args->seq_args, &hdr);
2330 encode_putfh(xdr, args->fh, &hdr);
2331 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002332 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002333 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334}
2335
2336/*
2337 * a STATFS request
2338 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002339static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2340 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002343 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
Chuck Lever9f06c712010-12-14 14:59:18 +00002346 encode_compound_hdr(xdr, req, &hdr);
2347 encode_sequence(xdr, &args->seq_args, &hdr);
2348 encode_putfh(xdr, args->fh, &hdr);
2349 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002350 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002351 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352}
2353
2354/*
2355 * GETATTR_BITMAP request
2356 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002357static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2358 struct xdr_stream *xdr,
2359 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002362 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
Chuck Lever9f06c712010-12-14 14:59:18 +00002365 encode_compound_hdr(xdr, req, &hdr);
2366 encode_sequence(xdr, &args->seq_args, &hdr);
2367 encode_putfh(xdr, args->fhandle, &hdr);
2368 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002369 FATTR4_WORD0_LINK_SUPPORT|
2370 FATTR4_WORD0_SYMLINK_SUPPORT|
2371 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002372 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373}
2374
2375/*
2376 * a RENEW request
2377 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002378static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2379 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002382 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 };
2384
Chuck Lever9f06c712010-12-14 14:59:18 +00002385 encode_compound_hdr(xdr, req, &hdr);
2386 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002387 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388}
2389
2390/*
2391 * a SETCLIENTID request
2392 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002393static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2394 struct xdr_stream *xdr,
2395 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002398 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 };
2400
Chuck Lever9f06c712010-12-14 14:59:18 +00002401 encode_compound_hdr(xdr, req, &hdr);
2402 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002403 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404}
2405
2406/*
2407 * a SETCLIENTID_CONFIRM request
2408 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002409static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2410 struct xdr_stream *xdr,
2411 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002414 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 };
2416 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
Chuck Lever9f06c712010-12-14 14:59:18 +00002418 encode_compound_hdr(xdr, req, &hdr);
2419 encode_setclientid_confirm(xdr, arg, &hdr);
2420 encode_putrootfh(xdr, &hdr);
2421 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002422 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423}
2424
2425/*
2426 * DELEGRETURN request
2427 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002428static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2429 struct xdr_stream *xdr,
2430 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002433 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
Chuck Lever9f06c712010-12-14 14:59:18 +00002436 encode_compound_hdr(xdr, req, &hdr);
2437 encode_sequence(xdr, &args->seq_args, &hdr);
2438 encode_putfh(xdr, args->fhandle, &hdr);
2439 encode_delegreturn(xdr, args->stateid, &hdr);
2440 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002441 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442}
2443
2444/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002445 * Encode FS_LOCATIONS request
2446 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002447static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2448 struct xdr_stream *xdr,
2449 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002450{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002451 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002452 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002453 };
Benny Halevy28f56692009-04-01 09:22:09 -04002454 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002455
Chuck Lever9f06c712010-12-14 14:59:18 +00002456 encode_compound_hdr(xdr, req, &hdr);
2457 encode_sequence(xdr, &args->seq_args, &hdr);
2458 encode_putfh(xdr, args->dir_fh, &hdr);
2459 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002460 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002461 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002462
Benny Halevy28f56692009-04-01 09:22:09 -04002463 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002464 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002465 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002466}
2467
Benny Halevy99fe60d2009-04-01 09:22:29 -04002468#if defined(CONFIG_NFS_V4_1)
2469/*
2470 * EXCHANGE_ID request
2471 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002472static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2473 struct xdr_stream *xdr,
2474 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002475{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002476 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002477 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002478 };
2479
Chuck Lever9f06c712010-12-14 14:59:18 +00002480 encode_compound_hdr(xdr, req, &hdr);
2481 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002482 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002483}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002484
2485/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002486 * a CREATE_SESSION request
2487 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002488static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2489 struct xdr_stream *xdr,
2490 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002491{
Andy Adamsonfc931582009-04-01 09:22:31 -04002492 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002493 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002494 };
2495
Chuck Lever9f06c712010-12-14 14:59:18 +00002496 encode_compound_hdr(xdr, req, &hdr);
2497 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002498 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002499}
2500
2501/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002502 * a DESTROY_SESSION request
2503 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002504static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2505 struct xdr_stream *xdr,
2506 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002507{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002508 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002509 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002510 };
2511
Chuck Lever9f06c712010-12-14 14:59:18 +00002512 encode_compound_hdr(xdr, req, &hdr);
2513 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002514 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002515}
2516
2517/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002518 * a SEQUENCE request
2519 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002520static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2521 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002522{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002523 struct compound_hdr hdr = {
2524 .minorversion = nfs4_xdr_minorversion(args),
2525 };
2526
Chuck Lever9f06c712010-12-14 14:59:18 +00002527 encode_compound_hdr(xdr, req, &hdr);
2528 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002529 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002530}
2531
2532/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002533 * a GET_LEASE_TIME request
2534 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002535static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2536 struct xdr_stream *xdr,
2537 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002538{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002539 struct compound_hdr hdr = {
2540 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2541 };
2542 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2543
Chuck Lever9f06c712010-12-14 14:59:18 +00002544 encode_compound_hdr(xdr, req, &hdr);
2545 encode_sequence(xdr, &args->la_seq_args, &hdr);
2546 encode_putrootfh(xdr, &hdr);
2547 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002548 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002549}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002550
2551/*
2552 * a RECLAIM_COMPLETE request
2553 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002554static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2555 struct xdr_stream *xdr,
2556 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002557{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002558 struct compound_hdr hdr = {
2559 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2560 };
2561
Chuck Lever9f06c712010-12-14 14:59:18 +00002562 encode_compound_hdr(xdr, req, &hdr);
2563 encode_sequence(xdr, &args->seq_args, &hdr);
2564 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002565 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002566}
2567
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002568/*
2569 * Encode GETDEVICEINFO request
2570 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002571static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2572 struct xdr_stream *xdr,
2573 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002574{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002575 struct compound_hdr hdr = {
2576 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2577 };
2578
Chuck Lever9f06c712010-12-14 14:59:18 +00002579 encode_compound_hdr(xdr, req, &hdr);
2580 encode_sequence(xdr, &args->seq_args, &hdr);
2581 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002582
2583 /* set up reply kvec. Subtract notification bitmap max size (2)
2584 * so that notification bitmap is put in xdr_buf tail */
2585 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2586 args->pdev->pages, args->pdev->pgbase,
2587 args->pdev->pglen);
2588
2589 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002590}
2591
2592/*
2593 * Encode LAYOUTGET request
2594 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002595static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2596 struct xdr_stream *xdr,
2597 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002598{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002599 struct compound_hdr hdr = {
2600 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2601 };
2602
Chuck Lever9f06c712010-12-14 14:59:18 +00002603 encode_compound_hdr(xdr, req, &hdr);
2604 encode_sequence(xdr, &args->seq_args, &hdr);
2605 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2606 encode_layoutget(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002607 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002608}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002609#endif /* CONFIG_NFS_V4_1 */
2610
Benny Halevy686841b2009-08-14 17:19:48 +03002611static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2612{
2613 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2614 "Remaining buffer length is %tu words.\n",
2615 func, xdr->end - xdr->p);
2616}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617
Trond Myklebust683b57b2006-06-09 09:34:22 -04002618static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619{
Al Viro8687b632006-10-19 23:28:48 -07002620 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621
Benny Halevyc0eae662009-08-14 17:20:14 +03002622 p = xdr_inline_decode(xdr, 4);
2623 if (unlikely(!p))
2624 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002625 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002626 p = xdr_inline_decode(xdr, *len);
2627 if (unlikely(!p))
2628 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 *string = (char *)p;
2630 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002631out_overflow:
2632 print_overflow_msg(__func__, xdr);
2633 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634}
2635
2636static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2637{
Al Viro8687b632006-10-19 23:28:48 -07002638 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639
Benny Halevyc0eae662009-08-14 17:20:14 +03002640 p = xdr_inline_decode(xdr, 8);
2641 if (unlikely(!p))
2642 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002643 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002644 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002645
Benny Halevyc0eae662009-08-14 17:20:14 +03002646 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2647 if (unlikely(!p))
2648 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 hdr->tag = (char *)p;
2650 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002651 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002652 if (unlikely(hdr->nops < 1))
2653 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002655out_overflow:
2656 print_overflow_msg(__func__, xdr);
2657 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658}
2659
2660static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2661{
Al Viro8687b632006-10-19 23:28:48 -07002662 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 uint32_t opnum;
2664 int32_t nfserr;
2665
Benny Halevyc0eae662009-08-14 17:20:14 +03002666 p = xdr_inline_decode(xdr, 8);
2667 if (unlikely(!p))
2668 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002669 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002671 dprintk("nfs: Server returned operation"
2672 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 opnum, expected);
2674 return -EIO;
2675 }
Benny Halevycccddf42009-08-14 17:20:19 +03002676 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002678 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002680out_overflow:
2681 print_overflow_msg(__func__, xdr);
2682 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683}
2684
2685/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002686static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687{
Al Viro8687b632006-10-19 23:28:48 -07002688 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002689 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 char *str;
2691
Benny Halevyc0eae662009-08-14 17:20:14 +03002692 p = xdr_inline_decode(xdr, 12);
2693 if (likely(p))
2694 return decode_opaque_inline(xdr, &strlen, &str);
2695 print_overflow_msg(__func__, xdr);
2696 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697}
2698
2699static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2700{
Al Viro8687b632006-10-19 23:28:48 -07002701 uint32_t bmlen;
2702 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703
Benny Halevyc0eae662009-08-14 17:20:14 +03002704 p = xdr_inline_decode(xdr, 4);
2705 if (unlikely(!p))
2706 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002707 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708
2709 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002710 p = xdr_inline_decode(xdr, (bmlen << 2));
2711 if (unlikely(!p))
2712 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002714 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002716 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 }
2718 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002719out_overflow:
2720 print_overflow_msg(__func__, xdr);
2721 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722}
2723
Al Viro8687b632006-10-19 23:28:48 -07002724static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725{
Al Viro8687b632006-10-19 23:28:48 -07002726 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727
Benny Halevyc0eae662009-08-14 17:20:14 +03002728 p = xdr_inline_decode(xdr, 4);
2729 if (unlikely(!p))
2730 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002731 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 *savep = xdr->p;
2733 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002734out_overflow:
2735 print_overflow_msg(__func__, xdr);
2736 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737}
2738
2739static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2740{
2741 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04002742 int ret;
2743 ret = decode_attr_bitmap(xdr, bitmask);
2744 if (unlikely(ret < 0))
2745 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2747 } else
2748 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002749 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 return 0;
2751}
2752
2753static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2754{
Al Viro8687b632006-10-19 23:28:48 -07002755 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002756 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757
2758 *type = 0;
2759 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2760 return -EIO;
2761 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002762 p = xdr_inline_decode(xdr, 4);
2763 if (unlikely(!p))
2764 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002765 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002767 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 return -EIO;
2769 }
2770 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002771 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002773 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002774 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002775out_overflow:
2776 print_overflow_msg(__func__, xdr);
2777 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778}
2779
2780static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2781{
Al Viro8687b632006-10-19 23:28:48 -07002782 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002783 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784
2785 *change = 0;
2786 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2787 return -EIO;
2788 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002789 p = xdr_inline_decode(xdr, 8);
2790 if (unlikely(!p))
2791 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002792 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002794 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002796 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002798 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002799out_overflow:
2800 print_overflow_msg(__func__, xdr);
2801 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802}
2803
2804static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2805{
Al Viro8687b632006-10-19 23:28:48 -07002806 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002807 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808
2809 *size = 0;
2810 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2811 return -EIO;
2812 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002813 p = xdr_inline_decode(xdr, 8);
2814 if (unlikely(!p))
2815 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002816 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002818 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002820 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002821 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002822out_overflow:
2823 print_overflow_msg(__func__, xdr);
2824 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825}
2826
2827static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2828{
Al Viro8687b632006-10-19 23:28:48 -07002829 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830
2831 *res = 0;
2832 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2833 return -EIO;
2834 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002835 p = xdr_inline_decode(xdr, 4);
2836 if (unlikely(!p))
2837 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002838 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2840 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002841 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002843out_overflow:
2844 print_overflow_msg(__func__, xdr);
2845 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846}
2847
2848static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2849{
Al Viro8687b632006-10-19 23:28:48 -07002850 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851
2852 *res = 0;
2853 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2854 return -EIO;
2855 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002856 p = xdr_inline_decode(xdr, 4);
2857 if (unlikely(!p))
2858 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002859 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2861 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002862 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002864out_overflow:
2865 print_overflow_msg(__func__, xdr);
2866 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867}
2868
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002869static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870{
Al Viro8687b632006-10-19 23:28:48 -07002871 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002872 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873
2874 fsid->major = 0;
2875 fsid->minor = 0;
2876 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2877 return -EIO;
2878 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002879 p = xdr_inline_decode(xdr, 16);
2880 if (unlikely(!p))
2881 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03002882 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03002883 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002885 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002887 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 (unsigned long long)fsid->major,
2889 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002890 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002891out_overflow:
2892 print_overflow_msg(__func__, xdr);
2893 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894}
2895
2896static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2897{
Al Viro8687b632006-10-19 23:28:48 -07002898 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899
2900 *res = 60;
2901 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2902 return -EIO;
2903 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002904 p = xdr_inline_decode(xdr, 4);
2905 if (unlikely(!p))
2906 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002907 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2909 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002910 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002912out_overflow:
2913 print_overflow_msg(__func__, xdr);
2914 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915}
2916
Bryan Schumakerae42c702010-10-21 16:33:17 -04002917static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
2918{
2919 __be32 *p;
2920
2921 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
2922 return -EIO;
2923 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
2924 p = xdr_inline_decode(xdr, 4);
2925 if (unlikely(!p))
2926 goto out_overflow;
2927 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
2928 }
2929 return 0;
2930out_overflow:
2931 print_overflow_msg(__func__, xdr);
2932 return -EIO;
2933}
2934
2935static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
2936{
2937 __be32 *p;
2938 int len;
2939
Trond Myklebust7ad07352010-10-23 15:34:20 -04002940 if (fh != NULL)
2941 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04002942
2943 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
2944 return -EIO;
2945 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
2946 p = xdr_inline_decode(xdr, 4);
2947 if (unlikely(!p))
2948 goto out_overflow;
2949 len = be32_to_cpup(p);
2950 if (len > NFS4_FHSIZE)
2951 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04002952 p = xdr_inline_decode(xdr, len);
2953 if (unlikely(!p))
2954 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04002955 if (fh != NULL) {
2956 memcpy(fh->data, p, len);
2957 fh->size = len;
2958 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04002959 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
2960 }
2961 return 0;
2962out_overflow:
2963 print_overflow_msg(__func__, xdr);
2964 return -EIO;
2965}
2966
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2968{
Al Viro8687b632006-10-19 23:28:48 -07002969 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970
2971 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2972 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2973 return -EIO;
2974 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002975 p = xdr_inline_decode(xdr, 4);
2976 if (unlikely(!p))
2977 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002978 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2980 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002981 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002983out_overflow:
2984 print_overflow_msg(__func__, xdr);
2985 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986}
2987
2988static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2989{
Al Viro8687b632006-10-19 23:28:48 -07002990 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002991 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992
2993 *fileid = 0;
2994 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2995 return -EIO;
2996 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002997 p = xdr_inline_decode(xdr, 8);
2998 if (unlikely(!p))
2999 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003000 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003002 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003004 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003005 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003006out_overflow:
3007 print_overflow_msg(__func__, xdr);
3008 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009}
3010
Manoj Naik99baf622006-06-09 09:34:24 -04003011static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3012{
Al Viro8687b632006-10-19 23:28:48 -07003013 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003014 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003015
3016 *fileid = 0;
3017 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3018 return -EIO;
3019 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003020 p = xdr_inline_decode(xdr, 8);
3021 if (unlikely(!p))
3022 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003023 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003024 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003025 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003026 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003027 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003028 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003029out_overflow:
3030 print_overflow_msg(__func__, xdr);
3031 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003032}
3033
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3035{
Al Viro8687b632006-10-19 23:28:48 -07003036 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 int status = 0;
3038
3039 *res = 0;
3040 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3041 return -EIO;
3042 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003043 p = xdr_inline_decode(xdr, 8);
3044 if (unlikely(!p))
3045 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003046 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3048 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003049 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003051out_overflow:
3052 print_overflow_msg(__func__, xdr);
3053 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054}
3055
3056static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3057{
Al Viro8687b632006-10-19 23:28:48 -07003058 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 int status = 0;
3060
3061 *res = 0;
3062 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3063 return -EIO;
3064 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003065 p = xdr_inline_decode(xdr, 8);
3066 if (unlikely(!p))
3067 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003068 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3070 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003071 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003073out_overflow:
3074 print_overflow_msg(__func__, xdr);
3075 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076}
3077
3078static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3079{
Al Viro8687b632006-10-19 23:28:48 -07003080 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 int status = 0;
3082
3083 *res = 0;
3084 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3085 return -EIO;
3086 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003087 p = xdr_inline_decode(xdr, 8);
3088 if (unlikely(!p))
3089 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003090 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3092 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003093 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003095out_overflow:
3096 print_overflow_msg(__func__, xdr);
3097 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098}
3099
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003100static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3101{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003102 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003103 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003104 int status = 0;
3105
Benny Halevyc0eae662009-08-14 17:20:14 +03003106 p = xdr_inline_decode(xdr, 4);
3107 if (unlikely(!p))
3108 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003109 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003110 if (n == 0)
3111 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003112 dprintk("path ");
3113 path->ncomponents = 0;
3114 while (path->ncomponents < n) {
3115 struct nfs4_string *component = &path->components[path->ncomponents];
3116 status = decode_opaque_inline(xdr, &component->len, &component->data);
3117 if (unlikely(status != 0))
3118 goto out_eio;
3119 if (path->ncomponents != n)
3120 dprintk("/");
3121 dprintk("%s", component->data);
3122 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3123 path->ncomponents++;
3124 else {
3125 dprintk("cannot parse %d components in path\n", n);
3126 goto out_eio;
3127 }
3128 }
3129out:
3130 dprintk("\n");
3131 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003132root_path:
3133/* a root pathname is sent as a zero component4 */
3134 path->ncomponents = 1;
3135 path->components[0].len=0;
3136 path->components[0].data=NULL;
3137 dprintk("path /\n");
3138 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003139out_eio:
3140 dprintk(" status %d", status);
3141 status = -EIO;
3142 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003143out_overflow:
3144 print_overflow_msg(__func__, xdr);
3145 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003146}
3147
3148static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003149{
3150 int n;
Al Viro8687b632006-10-19 23:28:48 -07003151 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003152 int status = -EIO;
3153
3154 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3155 goto out;
3156 status = 0;
3157 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3158 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003159 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003160 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003161 if (unlikely(status != 0))
3162 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003163 p = xdr_inline_decode(xdr, 4);
3164 if (unlikely(!p))
3165 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003166 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003167 if (n <= 0)
3168 goto out_eio;
3169 res->nlocations = 0;
3170 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003171 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003172 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003173
Benny Halevyc0eae662009-08-14 17:20:14 +03003174 p = xdr_inline_decode(xdr, 4);
3175 if (unlikely(!p))
3176 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003177 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003178
3179 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003180 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003181 while (loc->nservers < m) {
3182 struct nfs4_string *server = &loc->servers[loc->nservers];
3183 status = decode_opaque_inline(xdr, &server->len, &server->data);
3184 if (unlikely(status != 0))
3185 goto out_eio;
3186 dprintk("%s ", server->data);
3187 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3188 loc->nservers++;
3189 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003190 unsigned int i;
3191 dprintk("%s: using first %u of %u servers "
3192 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003193 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003194 NFS4_FS_LOCATION_MAXSERVERS,
3195 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003196 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003197 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003198 char *data;
3199 status = decode_opaque_inline(xdr, &len, &data);
3200 if (unlikely(status != 0))
3201 goto out_eio;
3202 }
3203 }
3204 }
3205 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003206 if (unlikely(status != 0))
3207 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003208 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003209 res->nlocations++;
3210 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003211 if (res->nlocations != 0)
3212 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003213out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003214 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003215 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003216out_overflow:
3217 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003218out_eio:
3219 status = -EIO;
3220 goto out;
3221}
3222
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3224{
Al Viro8687b632006-10-19 23:28:48 -07003225 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 int status = 0;
3227
3228 *res = 0;
3229 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3230 return -EIO;
3231 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003232 p = xdr_inline_decode(xdr, 8);
3233 if (unlikely(!p))
3234 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003235 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3237 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003238 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003240out_overflow:
3241 print_overflow_msg(__func__, xdr);
3242 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243}
3244
3245static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3246{
Al Viro8687b632006-10-19 23:28:48 -07003247 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 int status = 0;
3249
3250 *maxlink = 1;
3251 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3252 return -EIO;
3253 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003254 p = xdr_inline_decode(xdr, 4);
3255 if (unlikely(!p))
3256 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003257 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3259 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003260 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003262out_overflow:
3263 print_overflow_msg(__func__, xdr);
3264 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265}
3266
3267static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3268{
Al Viro8687b632006-10-19 23:28:48 -07003269 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 int status = 0;
3271
3272 *maxname = 1024;
3273 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3274 return -EIO;
3275 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003276 p = xdr_inline_decode(xdr, 4);
3277 if (unlikely(!p))
3278 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003279 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3281 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003282 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003284out_overflow:
3285 print_overflow_msg(__func__, xdr);
3286 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287}
3288
3289static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3290{
Al Viro8687b632006-10-19 23:28:48 -07003291 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 int status = 0;
3293
3294 *res = 1024;
3295 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3296 return -EIO;
3297 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3298 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003299 p = xdr_inline_decode(xdr, 8);
3300 if (unlikely(!p))
3301 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003302 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 if (maxread > 0x7FFFFFFF)
3304 maxread = 0x7FFFFFFF;
3305 *res = (uint32_t)maxread;
3306 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3307 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003308 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003310out_overflow:
3311 print_overflow_msg(__func__, xdr);
3312 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313}
3314
3315static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3316{
Al Viro8687b632006-10-19 23:28:48 -07003317 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 int status = 0;
3319
3320 *res = 1024;
3321 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3322 return -EIO;
3323 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3324 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003325 p = xdr_inline_decode(xdr, 8);
3326 if (unlikely(!p))
3327 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003328 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 if (maxwrite > 0x7FFFFFFF)
3330 maxwrite = 0x7FFFFFFF;
3331 *res = (uint32_t)maxwrite;
3332 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3333 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003334 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003336out_overflow:
3337 print_overflow_msg(__func__, xdr);
3338 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339}
3340
Trond Myklebustbca79472009-03-11 14:10:26 -04003341static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342{
Trond Myklebustbca79472009-03-11 14:10:26 -04003343 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003344 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003345 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346
3347 *mode = 0;
3348 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3349 return -EIO;
3350 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003351 p = xdr_inline_decode(xdr, 4);
3352 if (unlikely(!p))
3353 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003354 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003355 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003357 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003359 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003360 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003361out_overflow:
3362 print_overflow_msg(__func__, xdr);
3363 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364}
3365
3366static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3367{
Al Viro8687b632006-10-19 23:28:48 -07003368 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003369 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370
3371 *nlink = 1;
3372 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3373 return -EIO;
3374 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003375 p = xdr_inline_decode(xdr, 4);
3376 if (unlikely(!p))
3377 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003378 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003380 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003382 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003383 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003384out_overflow:
3385 print_overflow_msg(__func__, xdr);
3386 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387}
3388
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003389static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3390 struct nfs_client *clp, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391{
Al Viro8687b632006-10-19 23:28:48 -07003392 uint32_t len;
3393 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003394 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395
3396 *uid = -2;
3397 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3398 return -EIO;
3399 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003400 p = xdr_inline_decode(xdr, 4);
3401 if (unlikely(!p))
3402 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003403 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003404 p = xdr_inline_decode(xdr, len);
3405 if (unlikely(!p))
3406 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003407 if (!may_sleep) {
3408 /* do nothing */
3409 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003410 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3411 ret = NFS_ATTR_FATTR_OWNER;
3412 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003414 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003416 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003417 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3419 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003420 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003421 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003422out_overflow:
3423 print_overflow_msg(__func__, xdr);
3424 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425}
3426
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003427static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3428 struct nfs_client *clp, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429{
Al Viro8687b632006-10-19 23:28:48 -07003430 uint32_t len;
3431 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003432 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433
3434 *gid = -2;
3435 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3436 return -EIO;
3437 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003438 p = xdr_inline_decode(xdr, 4);
3439 if (unlikely(!p))
3440 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003441 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003442 p = xdr_inline_decode(xdr, len);
3443 if (unlikely(!p))
3444 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003445 if (!may_sleep) {
3446 /* do nothing */
3447 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003448 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3449 ret = NFS_ATTR_FATTR_GROUP;
3450 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003452 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003454 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003455 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3457 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003458 dprintk("%s: gid=%d\n", __func__, (int)*gid);
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
3465static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3466{
Al Viro8687b632006-10-19 23:28:48 -07003467 uint32_t major = 0, minor = 0;
3468 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003469 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470
3471 *rdev = MKDEV(0,0);
3472 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3473 return -EIO;
3474 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3475 dev_t tmp;
3476
Benny Halevyc0eae662009-08-14 17:20:14 +03003477 p = xdr_inline_decode(xdr, 8);
3478 if (unlikely(!p))
3479 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003480 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003481 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 tmp = MKDEV(major, minor);
3483 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3484 *rdev = tmp;
3485 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003486 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003488 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003489 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003490out_overflow:
3491 print_overflow_msg(__func__, xdr);
3492 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493}
3494
3495static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3496{
Al Viro8687b632006-10-19 23:28:48 -07003497 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 int status = 0;
3499
3500 *res = 0;
3501 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3502 return -EIO;
3503 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003504 p = xdr_inline_decode(xdr, 8);
3505 if (unlikely(!p))
3506 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003507 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3509 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003510 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003512out_overflow:
3513 print_overflow_msg(__func__, xdr);
3514 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515}
3516
3517static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3518{
Al Viro8687b632006-10-19 23:28:48 -07003519 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 int status = 0;
3521
3522 *res = 0;
3523 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3524 return -EIO;
3525 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003526 p = xdr_inline_decode(xdr, 8);
3527 if (unlikely(!p))
3528 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003529 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3531 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003532 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003534out_overflow:
3535 print_overflow_msg(__func__, xdr);
3536 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537}
3538
3539static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3540{
Al Viro8687b632006-10-19 23:28:48 -07003541 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 int status = 0;
3543
3544 *res = 0;
3545 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3546 return -EIO;
3547 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003548 p = xdr_inline_decode(xdr, 8);
3549 if (unlikely(!p))
3550 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003551 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3553 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003554 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003556out_overflow:
3557 print_overflow_msg(__func__, xdr);
3558 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559}
3560
3561static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3562{
Al Viro8687b632006-10-19 23:28:48 -07003563 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003564 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565
3566 *used = 0;
3567 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3568 return -EIO;
3569 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003570 p = xdr_inline_decode(xdr, 8);
3571 if (unlikely(!p))
3572 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003573 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003575 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003577 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003579 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003580out_overflow:
3581 print_overflow_msg(__func__, xdr);
3582 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583}
3584
3585static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3586{
Al Viro8687b632006-10-19 23:28:48 -07003587 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 uint64_t sec;
3589 uint32_t nsec;
3590
Benny Halevyc0eae662009-08-14 17:20:14 +03003591 p = xdr_inline_decode(xdr, 12);
3592 if (unlikely(!p))
3593 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003594 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003595 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596 time->tv_sec = (time_t)sec;
3597 time->tv_nsec = (long)nsec;
3598 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003599out_overflow:
3600 print_overflow_msg(__func__, xdr);
3601 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602}
3603
3604static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3605{
3606 int status = 0;
3607
3608 time->tv_sec = 0;
3609 time->tv_nsec = 0;
3610 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3611 return -EIO;
3612 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3613 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003614 if (status == 0)
3615 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003616 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3617 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003618 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619 return status;
3620}
3621
3622static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3623{
3624 int status = 0;
3625
3626 time->tv_sec = 0;
3627 time->tv_nsec = 0;
3628 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3629 return -EIO;
3630 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3631 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003632 if (status == 0)
3633 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3635 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003636 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 return status;
3638}
3639
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003640static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3641 struct timespec *time)
3642{
3643 int status = 0;
3644
3645 time->tv_sec = 0;
3646 time->tv_nsec = 0;
3647 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3648 return -EIO;
3649 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3650 status = decode_attr_time(xdr, time);
3651 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3652 }
3653 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3654 (long)time->tv_nsec);
3655 return status;
3656}
3657
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3659{
3660 int status = 0;
3661
3662 time->tv_sec = 0;
3663 time->tv_nsec = 0;
3664 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3665 return -EIO;
3666 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3667 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003668 if (status == 0)
3669 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3671 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003672 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 return status;
3674}
3675
Al Viro8687b632006-10-19 23:28:48 -07003676static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677{
3678 unsigned int attrwords = XDR_QUADLEN(attrlen);
3679 unsigned int nwords = xdr->p - savep;
3680
3681 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003682 dprintk("%s: server returned incorrect attribute length: "
3683 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003684 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 attrwords << 2,
3686 (attrwords < nwords) ? '<' : '>',
3687 nwords << 2);
3688 return -EIO;
3689 }
3690 return 0;
3691}
3692
3693static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3694{
Al Viro8687b632006-10-19 23:28:48 -07003695 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696
Benny Halevyc0eae662009-08-14 17:20:14 +03003697 p = xdr_inline_decode(xdr, 20);
3698 if (unlikely(!p))
3699 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003700 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003701 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003702 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003704out_overflow:
3705 print_overflow_msg(__func__, xdr);
3706 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707}
3708
3709static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3710{
Al Viro8687b632006-10-19 23:28:48 -07003711 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 uint32_t supp, acc;
3713 int status;
3714
3715 status = decode_op_hdr(xdr, OP_ACCESS);
3716 if (status)
3717 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003718 p = xdr_inline_decode(xdr, 8);
3719 if (unlikely(!p))
3720 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003721 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003722 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 access->supported = supp;
3724 access->access = acc;
3725 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003726out_overflow:
3727 print_overflow_msg(__func__, xdr);
3728 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729}
3730
Benny Halevy07d30432009-08-14 17:19:52 +03003731static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732{
Al Viro8687b632006-10-19 23:28:48 -07003733 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003734
3735 p = xdr_inline_decode(xdr, len);
3736 if (likely(p)) {
3737 memcpy(buf, p, len);
3738 return 0;
3739 }
3740 print_overflow_msg(__func__, xdr);
3741 return -EIO;
3742}
3743
3744static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3745{
3746 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747}
3748
3749static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3750{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751 int status;
3752
3753 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003754 if (status != -EIO)
3755 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003756 if (!status)
3757 status = decode_stateid(xdr, &res->stateid);
3758 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759}
3760
Benny Halevydb942bb2009-08-14 17:19:56 +03003761static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3762{
3763 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764}
3765
3766static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3767{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 int status;
3769
3770 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003771 if (!status)
3772 status = decode_verifier(xdr, res->verf->verifier);
3773 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774}
3775
3776static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3777{
Al Viro8687b632006-10-19 23:28:48 -07003778 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 uint32_t bmlen;
3780 int status;
3781
3782 status = decode_op_hdr(xdr, OP_CREATE);
3783 if (status)
3784 return status;
3785 if ((status = decode_change_info(xdr, cinfo)))
3786 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003787 p = xdr_inline_decode(xdr, 4);
3788 if (unlikely(!p))
3789 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003790 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003791 p = xdr_inline_decode(xdr, bmlen << 2);
3792 if (likely(p))
3793 return 0;
3794out_overflow:
3795 print_overflow_msg(__func__, xdr);
3796 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797}
3798
3799static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3800{
Al Viro8687b632006-10-19 23:28:48 -07003801 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003802 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 int status;
3804
3805 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3806 goto xdr_error;
3807 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3808 goto xdr_error;
3809 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3810 goto xdr_error;
3811 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3812 goto xdr_error;
3813 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3814 goto xdr_error;
3815 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3816 goto xdr_error;
3817 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3818 goto xdr_error;
3819 status = verify_attr_len(xdr, savep, attrlen);
3820xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003821 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 return status;
3823}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003824
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3826{
Al Viro8687b632006-10-19 23:28:48 -07003827 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003828 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003830
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3832 goto xdr_error;
3833 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3834 goto xdr_error;
3835 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3836 goto xdr_error;
3837
3838 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3839 goto xdr_error;
3840 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3841 goto xdr_error;
3842 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3843 goto xdr_error;
3844 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3845 goto xdr_error;
3846 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3847 goto xdr_error;
3848 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3849 goto xdr_error;
3850
3851 status = verify_attr_len(xdr, savep, attrlen);
3852xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003853 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 return status;
3855}
3856
3857static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3858{
Al Viro8687b632006-10-19 23:28:48 -07003859 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003860 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003862
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3864 goto xdr_error;
3865 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3866 goto xdr_error;
3867 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3868 goto xdr_error;
3869
3870 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3871 goto xdr_error;
3872 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3873 goto xdr_error;
3874
3875 status = verify_attr_len(xdr, savep, attrlen);
3876xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003877 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878 return status;
3879}
3880
Bryan Schumakerae42c702010-10-21 16:33:17 -04003881static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
3882 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003883 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884{
Trond Myklebustbca79472009-03-11 14:10:26 -04003885 int status;
3886 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003887 uint64_t fileid;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003888 uint32_t type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003890 status = decode_attr_type(xdr, bitmap, &type);
3891 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003893 fattr->mode = 0;
3894 if (status != 0) {
3895 fattr->mode |= nfs_type2fmt[type];
3896 fattr->valid |= status;
3897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003899 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3900 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003902 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003903
3904 status = decode_attr_size(xdr, bitmap, &fattr->size);
3905 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003907 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003908
3909 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3910 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003912 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003913
Bryan Schumakerae42c702010-10-21 16:33:17 -04003914 status = decode_attr_error(xdr, bitmap);
3915 if (status < 0)
3916 goto xdr_error;
3917
3918 status = decode_attr_filehandle(xdr, bitmap, fh);
3919 if (status < 0)
3920 goto xdr_error;
3921
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003922 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3923 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003925 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003926
3927 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003928 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003929 fattr));
3930 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003931 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003932 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003933
3934 status = decode_attr_mode(xdr, bitmap, &fmode);
3935 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003937 if (status != 0) {
3938 fattr->mode |= fmode;
3939 fattr->valid |= status;
3940 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003941
3942 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3943 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003945 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003946
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003947 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3948 &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003949 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003951 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003952
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003953 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3954 &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003955 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003957 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003958
3959 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3960 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003962 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003963
3964 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3965 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003967 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003968
3969 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3970 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003972 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003973
3974 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3975 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003977 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003978
3979 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3980 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003982 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003983
3984 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3985 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003986 goto xdr_error;
Trond Myklebust3201f3d2010-10-23 15:43:10 -04003987 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003988 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003989 fattr->valid |= status;
3990 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003991
Bryan Schumakerae42c702010-10-21 16:33:17 -04003992xdr_error:
3993 dprintk("%s: xdr returned %d\n", __func__, -status);
3994 return status;
3995}
3996
3997static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3998 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
3999{
4000 __be32 *savep;
4001 uint32_t attrlen,
4002 bitmap[2] = {0};
4003 int status;
4004
4005 status = decode_op_hdr(xdr, OP_GETATTR);
4006 if (status < 0)
4007 goto xdr_error;
4008
4009 status = decode_attr_bitmap(xdr, bitmap);
4010 if (status < 0)
4011 goto xdr_error;
4012
4013 status = decode_attr_length(xdr, &attrlen, &savep);
4014 if (status < 0)
4015 goto xdr_error;
4016
4017 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4018 if (status < 0)
4019 goto xdr_error;
4020
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004021 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004023 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 return status;
4025}
4026
Bryan Schumakerae42c702010-10-21 16:33:17 -04004027static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4028 const struct nfs_server *server, int may_sleep)
4029{
4030 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4031}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032
Andy Adamson504913f2010-10-20 00:17:57 -04004033/*
4034 * Decode potentially multiple layout types. Currently we only support
4035 * one layout driver per file system.
4036 */
4037static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4038 uint32_t *layouttype)
4039{
4040 uint32_t *p;
4041 int num;
4042
4043 p = xdr_inline_decode(xdr, 4);
4044 if (unlikely(!p))
4045 goto out_overflow;
4046 num = be32_to_cpup(p);
4047
4048 /* pNFS is not supported by the underlying file system */
4049 if (num == 0) {
4050 *layouttype = 0;
4051 return 0;
4052 }
4053 if (num > 1)
4054 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4055 "per filesystem not supported\n", __func__);
4056
4057 /* Decode and set first layout type, move xdr->p past unused types */
4058 p = xdr_inline_decode(xdr, num * 4);
4059 if (unlikely(!p))
4060 goto out_overflow;
4061 *layouttype = be32_to_cpup(p);
4062 return 0;
4063out_overflow:
4064 print_overflow_msg(__func__, xdr);
4065 return -EIO;
4066}
4067
4068/*
4069 * The type of file system exported.
4070 * Note we must ensure that layouttype is set in any non-error case.
4071 */
4072static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4073 uint32_t *layouttype)
4074{
4075 int status = 0;
4076
4077 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4078 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4079 return -EIO;
4080 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4081 status = decode_first_pnfs_layout_type(xdr, layouttype);
4082 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4083 } else
4084 *layouttype = 0;
4085 return status;
4086}
4087
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4089{
Al Viro8687b632006-10-19 23:28:48 -07004090 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 uint32_t attrlen, bitmap[2];
4092 int status;
4093
4094 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4095 goto xdr_error;
4096 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4097 goto xdr_error;
4098 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4099 goto xdr_error;
4100
4101 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4102
4103 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4104 goto xdr_error;
4105 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4106 goto xdr_error;
4107 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4108 goto xdr_error;
4109 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4110 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4111 goto xdr_error;
4112 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004113 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4114 if (status != 0)
4115 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004116 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4117 if (status != 0)
4118 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119
4120 status = verify_attr_len(xdr, savep, attrlen);
4121xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004122 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123 return status;
4124}
4125
4126static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4127{
Al Viro8687b632006-10-19 23:28:48 -07004128 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 uint32_t len;
4130 int status;
4131
Trond Myklebust99367812007-07-17 21:52:41 -04004132 /* Zero handle first to allow comparisons */
4133 memset(fh, 0, sizeof(*fh));
4134
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135 status = decode_op_hdr(xdr, OP_GETFH);
4136 if (status)
4137 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138
Benny Halevyc0eae662009-08-14 17:20:14 +03004139 p = xdr_inline_decode(xdr, 4);
4140 if (unlikely(!p))
4141 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004142 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 if (len > NFS4_FHSIZE)
4144 return -EIO;
4145 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004146 p = xdr_inline_decode(xdr, len);
4147 if (unlikely(!p))
4148 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004149 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004151out_overflow:
4152 print_overflow_msg(__func__, xdr);
4153 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154}
4155
4156static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4157{
4158 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004159
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 status = decode_op_hdr(xdr, OP_LINK);
4161 if (status)
4162 return status;
4163 return decode_change_info(xdr, cinfo);
4164}
4165
4166/*
4167 * We create the owner, so we know a proper owner.id length is 4.
4168 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004169static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004171 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004172 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004173 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004175 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004176 if (unlikely(!p))
4177 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004178 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004179 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004180 type = be32_to_cpup(p++); /* 4 byte read */
4181 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004182 fl->fl_start = (loff_t)offset;
4183 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4184 if (length == ~(uint64_t)0)
4185 fl->fl_end = OFFSET_MAX;
4186 fl->fl_type = F_WRLCK;
4187 if (type & 1)
4188 fl->fl_type = F_RDLCK;
4189 fl->fl_pid = 0;
4190 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004191 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4192 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4193 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004194 if (likely(p))
4195 return -NFS4ERR_DENIED;
4196out_overflow:
4197 print_overflow_msg(__func__, xdr);
4198 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199}
4200
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004201static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203 int status;
4204
4205 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004206 if (status == -EIO)
4207 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004209 status = decode_stateid(xdr, &res->stateid);
4210 if (unlikely(status))
4211 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004213 status = decode_lock_denied(xdr, NULL);
4214 if (res->open_seqid != NULL)
4215 nfs_increment_open_seqid(status, res->open_seqid);
4216 nfs_increment_lock_seqid(status, res->lock_seqid);
4217out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218 return status;
4219}
4220
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004221static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222{
4223 int status;
4224 status = decode_op_hdr(xdr, OP_LOCKT);
4225 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004226 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227 return status;
4228}
4229
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004230static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232 int status;
4233
4234 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004235 if (status != -EIO)
4236 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004237 if (status == 0)
4238 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004239 return status;
4240}
4241
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004242static int decode_release_lockowner(struct xdr_stream *xdr)
4243{
4244 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4245}
4246
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247static int decode_lookup(struct xdr_stream *xdr)
4248{
4249 return decode_op_hdr(xdr, OP_LOOKUP);
4250}
4251
4252/* This is too sick! */
4253static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4254{
Andy Adamson05d564f2008-12-23 16:06:15 -05004255 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256 uint32_t limit_type, nblocks, blocksize;
4257
Benny Halevyc0eae662009-08-14 17:20:14 +03004258 p = xdr_inline_decode(xdr, 12);
4259 if (unlikely(!p))
4260 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004261 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004263 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004264 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004265 break;
4266 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004267 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004268 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004269 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270 }
4271 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004272out_overflow:
4273 print_overflow_msg(__func__, xdr);
4274 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275}
4276
4277static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4278{
Andy Adamson05d564f2008-12-23 16:06:15 -05004279 __be32 *p;
4280 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004281 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282
Benny Halevyc0eae662009-08-14 17:20:14 +03004283 p = xdr_inline_decode(xdr, 4);
4284 if (unlikely(!p))
4285 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004286 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4288 res->delegation_type = 0;
4289 return 0;
4290 }
Benny Halevy07d30432009-08-14 17:19:52 +03004291 status = decode_stateid(xdr, &res->delegation);
4292 if (unlikely(status))
4293 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004294 p = xdr_inline_decode(xdr, 4);
4295 if (unlikely(!p))
4296 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004297 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004298
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004300 case NFS4_OPEN_DELEGATE_READ:
4301 res->delegation_type = FMODE_READ;
4302 break;
4303 case NFS4_OPEN_DELEGATE_WRITE:
4304 res->delegation_type = FMODE_WRITE|FMODE_READ;
4305 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 return -EIO;
4307 }
David Howells7539bba2006-08-22 20:06:09 -04004308 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004309out_overflow:
4310 print_overflow_msg(__func__, xdr);
4311 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312}
4313
4314static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4315{
Andy Adamson05d564f2008-12-23 16:06:15 -05004316 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004317 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004318 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319
Andy Adamson05d564f2008-12-23 16:06:15 -05004320 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004321 if (status != -EIO)
4322 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004323 if (!status)
4324 status = decode_stateid(xdr, &res->stateid);
4325 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004326 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327
Andy Adamson05d564f2008-12-23 16:06:15 -05004328 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004329
Benny Halevyc0eae662009-08-14 17:20:14 +03004330 p = xdr_inline_decode(xdr, 8);
4331 if (unlikely(!p))
4332 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004333 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004334 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004335 if (bmlen > 10)
4336 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337
Benny Halevyc0eae662009-08-14 17:20:14 +03004338 p = xdr_inline_decode(xdr, bmlen << 2);
4339 if (unlikely(!p))
4340 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004341 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4342 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004343 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004344 for (; i < NFS4_BITMAP_SIZE; i++)
4345 res->attrset[i] = 0;
4346
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347 return decode_delegation(xdr, res);
4348xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004349 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004351out_overflow:
4352 print_overflow_msg(__func__, xdr);
4353 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354}
4355
4356static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4357{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358 int status;
4359
Andy Adamson05d564f2008-12-23 16:06:15 -05004360 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004361 if (status != -EIO)
4362 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004363 if (!status)
4364 status = decode_stateid(xdr, &res->stateid);
4365 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366}
4367
4368static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4369{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004370 int status;
4371
4372 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004373 if (status != -EIO)
4374 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004375 if (!status)
4376 status = decode_stateid(xdr, &res->stateid);
4377 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378}
4379
4380static int decode_putfh(struct xdr_stream *xdr)
4381{
4382 return decode_op_hdr(xdr, OP_PUTFH);
4383}
4384
4385static int decode_putrootfh(struct xdr_stream *xdr)
4386{
4387 return decode_op_hdr(xdr, OP_PUTROOTFH);
4388}
4389
4390static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4391{
4392 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004393 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 uint32_t count, eof, recvd, hdrlen;
4395 int status;
4396
4397 status = decode_op_hdr(xdr, OP_READ);
4398 if (status)
4399 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004400 p = xdr_inline_decode(xdr, 8);
4401 if (unlikely(!p))
4402 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004403 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004404 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004405 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406 recvd = req->rq_rcv_buf.len - hdrlen;
4407 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004408 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409 "count %u > recvd %u\n", count, recvd);
4410 count = recvd;
4411 eof = 0;
4412 }
4413 xdr_read_pages(xdr, count);
4414 res->eof = eof;
4415 res->count = count;
4416 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004417out_overflow:
4418 print_overflow_msg(__func__, xdr);
4419 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420}
4421
4422static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4423{
4424 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004426 size_t hdrlen;
4427 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004428 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429
4430 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004431 if (!status)
4432 status = decode_verifier(xdr, readdir->verifier.data);
4433 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004434 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004435 dprintk("%s: verifier = %08x:%08x\n",
4436 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004437 ((u32 *)readdir->verifier.data)[0],
4438 ((u32 *)readdir->verifier.data)[1]);
4439
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440
Benny Halevydb942bb2009-08-14 17:19:56 +03004441 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 recvd = rcvbuf->len - hdrlen;
4443 if (pglen > recvd)
4444 pglen = recvd;
4445 xdr_read_pages(xdr, pglen);
4446
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004447
Trond Myklebustac396122010-11-15 20:26:22 -05004448 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449}
4450
4451static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4452{
4453 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4454 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004455 size_t hdrlen;
4456 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004457 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458 int status;
4459
4460 status = decode_op_hdr(xdr, OP_READLINK);
4461 if (status)
4462 return status;
4463
4464 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004465 p = xdr_inline_decode(xdr, 4);
4466 if (unlikely(!p))
4467 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004468 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004470 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004471 return -ENAMETOOLONG;
4472 }
4473 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4474 recvd = req->rq_rcv_buf.len - hdrlen;
4475 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004476 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004477 "count %u > recvd %u\n", len, recvd);
4478 return -EIO;
4479 }
4480 xdr_read_pages(xdr, len);
4481 /*
4482 * The XDR encode routine has set things up so that
4483 * the link text will be copied directly into the
4484 * buffer. We just have to do overflow-checking,
4485 * and and null-terminate the text (the VFS expects
4486 * null-termination).
4487 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004488 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004490out_overflow:
4491 print_overflow_msg(__func__, xdr);
4492 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004493}
4494
4495static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4496{
4497 int status;
4498
4499 status = decode_op_hdr(xdr, OP_REMOVE);
4500 if (status)
4501 goto out;
4502 status = decode_change_info(xdr, cinfo);
4503out:
4504 return status;
4505}
4506
4507static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4508 struct nfs4_change_info *new_cinfo)
4509{
4510 int status;
4511
4512 status = decode_op_hdr(xdr, OP_RENAME);
4513 if (status)
4514 goto out;
4515 if ((status = decode_change_info(xdr, old_cinfo)))
4516 goto out;
4517 status = decode_change_info(xdr, new_cinfo);
4518out:
4519 return status;
4520}
4521
4522static int decode_renew(struct xdr_stream *xdr)
4523{
4524 return decode_op_hdr(xdr, OP_RENEW);
4525}
4526
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004527static int
4528decode_restorefh(struct xdr_stream *xdr)
4529{
4530 return decode_op_hdr(xdr, OP_RESTOREFH);
4531}
4532
J. Bruce Fields029d1052005-06-22 17:16:22 +00004533static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4534 size_t *acl_len)
4535{
Al Viro8687b632006-10-19 23:28:48 -07004536 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004537 uint32_t attrlen,
4538 bitmap[2] = {0};
4539 struct kvec *iov = req->rq_rcv_buf.head;
4540 int status;
4541
4542 *acl_len = 0;
4543 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4544 goto out;
4545 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4546 goto out;
4547 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4548 goto out;
4549
4550 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4551 return -EIO;
4552 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004553 size_t hdrlen;
4554 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004555
4556 /* We ignore &savep and don't do consistency checks on
4557 * the attr length. Let userspace figure it out.... */
4558 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4559 recvd = req->rq_rcv_buf.len - hdrlen;
4560 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004561 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004562 " acl reply: attrlen %u > recvd %u\n",
4563 attrlen, recvd);
4564 return -EINVAL;
4565 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004566 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004567 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004568 } else
4569 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004570
4571out:
4572 return status;
4573}
4574
Linus Torvalds1da177e2005-04-16 15:20:36 -07004575static int
4576decode_savefh(struct xdr_stream *xdr)
4577{
4578 return decode_op_hdr(xdr, OP_SAVEFH);
4579}
4580
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004581static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582{
Al Viro8687b632006-10-19 23:28:48 -07004583 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004584 uint32_t bmlen;
4585 int status;
4586
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587 status = decode_op_hdr(xdr, OP_SETATTR);
4588 if (status)
4589 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004590 p = xdr_inline_decode(xdr, 4);
4591 if (unlikely(!p))
4592 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004593 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004594 p = xdr_inline_decode(xdr, bmlen << 2);
4595 if (likely(p))
4596 return 0;
4597out_overflow:
4598 print_overflow_msg(__func__, xdr);
4599 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600}
4601
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004602static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603{
Al Viro8687b632006-10-19 23:28:48 -07004604 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605 uint32_t opnum;
4606 int32_t nfserr;
4607
Benny Halevyc0eae662009-08-14 17:20:14 +03004608 p = xdr_inline_decode(xdr, 8);
4609 if (unlikely(!p))
4610 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004611 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004612 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004613 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004614 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004615 return -EIO;
4616 }
Benny Halevycccddf42009-08-14 17:20:19 +03004617 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004618 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004619 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4620 if (unlikely(!p))
4621 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004622 p = xdr_decode_hyper(p, &res->clientid);
4623 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624 } else if (nfserr == NFSERR_CLID_INUSE) {
4625 uint32_t len;
4626
4627 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004628 p = xdr_inline_decode(xdr, 4);
4629 if (unlikely(!p))
4630 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004631 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004632 p = xdr_inline_decode(xdr, len);
4633 if (unlikely(!p))
4634 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004635
4636 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004637 p = xdr_inline_decode(xdr, 4);
4638 if (unlikely(!p))
4639 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004640 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004641 p = xdr_inline_decode(xdr, len);
4642 if (unlikely(!p))
4643 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644 return -NFSERR_CLID_INUSE;
4645 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004646 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647
4648 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004649out_overflow:
4650 print_overflow_msg(__func__, xdr);
4651 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652}
4653
4654static int decode_setclientid_confirm(struct xdr_stream *xdr)
4655{
4656 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4657}
4658
4659static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4660{
Al Viro8687b632006-10-19 23:28:48 -07004661 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 int status;
4663
4664 status = decode_op_hdr(xdr, OP_WRITE);
4665 if (status)
4666 return status;
4667
Benny Halevyc0eae662009-08-14 17:20:14 +03004668 p = xdr_inline_decode(xdr, 16);
4669 if (unlikely(!p))
4670 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004671 res->count = be32_to_cpup(p++);
4672 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004673 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004675out_overflow:
4676 print_overflow_msg(__func__, xdr);
4677 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678}
4679
4680static int decode_delegreturn(struct xdr_stream *xdr)
4681{
4682 return decode_op_hdr(xdr, OP_DELEGRETURN);
4683}
4684
Benny Halevy99fe60d2009-04-01 09:22:29 -04004685#if defined(CONFIG_NFS_V4_1)
4686static int decode_exchange_id(struct xdr_stream *xdr,
4687 struct nfs41_exchange_id_res *res)
4688{
4689 __be32 *p;
4690 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004691 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004692 int status;
4693 struct nfs_client *clp = res->client;
4694
4695 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4696 if (status)
4697 return status;
4698
Benny Halevyc0eae662009-08-14 17:20:14 +03004699 p = xdr_inline_decode(xdr, 8);
4700 if (unlikely(!p))
4701 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05004702 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004703 p = xdr_inline_decode(xdr, 12);
4704 if (unlikely(!p))
4705 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004706 clp->cl_seqid = be32_to_cpup(p++);
4707 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004708
4709 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004710 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004711 if (dummy != SP4_NONE)
4712 return -EIO;
4713
4714 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004715 p = xdr_inline_decode(xdr, 8);
4716 if (unlikely(!p))
4717 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004718
4719 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004720 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4721 if (unlikely(status))
4722 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004723
4724 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004725 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4726 if (unlikely(status))
4727 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004728
4729 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004730 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4731 if (unlikely(status))
4732 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004733
4734 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004735out_overflow:
4736 print_overflow_msg(__func__, xdr);
4737 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004738}
Andy Adamsonfc931582009-04-01 09:22:31 -04004739
4740static int decode_chan_attrs(struct xdr_stream *xdr,
4741 struct nfs4_channel_attrs *attrs)
4742{
4743 __be32 *p;
4744 u32 nr_attrs;
4745
Benny Halevyc0eae662009-08-14 17:20:14 +03004746 p = xdr_inline_decode(xdr, 28);
4747 if (unlikely(!p))
4748 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004749 attrs->headerpadsz = be32_to_cpup(p++);
4750 attrs->max_rqst_sz = be32_to_cpup(p++);
4751 attrs->max_resp_sz = be32_to_cpup(p++);
4752 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4753 attrs->max_ops = be32_to_cpup(p++);
4754 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004755 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004756 if (unlikely(nr_attrs > 1)) {
4757 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4758 __func__, nr_attrs);
4759 return -EINVAL;
4760 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004761 if (nr_attrs == 1) {
4762 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4763 if (unlikely(!p))
4764 goto out_overflow;
4765 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004766 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004767out_overflow:
4768 print_overflow_msg(__func__, xdr);
4769 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004770}
4771
Benny Halevye78291e2009-08-14 17:20:00 +03004772static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4773{
4774 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004775}
4776
4777static int decode_create_session(struct xdr_stream *xdr,
4778 struct nfs41_create_session_res *res)
4779{
4780 __be32 *p;
4781 int status;
4782 struct nfs_client *clp = res->client;
4783 struct nfs4_session *session = clp->cl_session;
4784
4785 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004786 if (!status)
4787 status = decode_sessionid(xdr, &session->sess_id);
4788 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004789 return status;
4790
Andy Adamsonfc931582009-04-01 09:22:31 -04004791 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004792 p = xdr_inline_decode(xdr, 8);
4793 if (unlikely(!p))
4794 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004795 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004796 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004797
4798 /* Channel attributes */
4799 status = decode_chan_attrs(xdr, &session->fc_attrs);
4800 if (!status)
4801 status = decode_chan_attrs(xdr, &session->bc_attrs);
4802 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004803out_overflow:
4804 print_overflow_msg(__func__, xdr);
4805 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004806}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004807
4808static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4809{
4810 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4811}
Ricardo Labiaga180197532009-12-05 16:08:40 -05004812
4813static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
4814{
4815 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
4816}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004817#endif /* CONFIG_NFS_V4_1 */
4818
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004819static int decode_sequence(struct xdr_stream *xdr,
4820 struct nfs4_sequence_res *res,
4821 struct rpc_rqst *rqstp)
4822{
4823#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004824 struct nfs4_sessionid id;
4825 u32 dummy;
4826 int status;
4827 __be32 *p;
4828
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004829 if (!res->sr_session)
4830 return 0;
4831
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004832 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03004833 if (!status)
4834 status = decode_sessionid(xdr, &id);
4835 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004836 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004837
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004838 /*
4839 * If the server returns different values for sessionID, slotID or
4840 * sequence number, the server is looney tunes.
4841 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05004842 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004843
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004844 if (memcmp(id.data, res->sr_session->sess_id.data,
4845 NFS4_MAX_SESSIONID_LEN)) {
4846 dprintk("%s Invalid session id\n", __func__);
4847 goto out_err;
4848 }
Benny Halevye78291e2009-08-14 17:20:00 +03004849
Benny Halevyc0eae662009-08-14 17:20:14 +03004850 p = xdr_inline_decode(xdr, 20);
4851 if (unlikely(!p))
4852 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03004853
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004854 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03004855 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004856 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004857 dprintk("%s Invalid sequence number\n", __func__);
4858 goto out_err;
4859 }
4860 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03004861 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004862 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004863 dprintk("%s Invalid slot id\n", __func__);
4864 goto out_err;
4865 }
4866 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004867 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004868 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004869 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05004870 /* result flags */
4871 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004872 status = 0;
4873out_err:
4874 res->sr_status = status;
4875 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004876out_overflow:
4877 print_overflow_msg(__func__, xdr);
4878 status = -EIO;
4879 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004880#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004881 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004882#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004883}
4884
Andy Adamsonb1f69b72010-10-20 00:18:03 -04004885#if defined(CONFIG_NFS_V4_1)
4886
4887static int decode_getdeviceinfo(struct xdr_stream *xdr,
4888 struct pnfs_device *pdev)
4889{
4890 __be32 *p;
4891 uint32_t len, type;
4892 int status;
4893
4894 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
4895 if (status) {
4896 if (status == -ETOOSMALL) {
4897 p = xdr_inline_decode(xdr, 4);
4898 if (unlikely(!p))
4899 goto out_overflow;
4900 pdev->mincount = be32_to_cpup(p);
4901 dprintk("%s: Min count too small. mincnt = %u\n",
4902 __func__, pdev->mincount);
4903 }
4904 return status;
4905 }
4906
4907 p = xdr_inline_decode(xdr, 8);
4908 if (unlikely(!p))
4909 goto out_overflow;
4910 type = be32_to_cpup(p++);
4911 if (type != pdev->layout_type) {
4912 dprintk("%s: layout mismatch req: %u pdev: %u\n",
4913 __func__, pdev->layout_type, type);
4914 return -EINVAL;
4915 }
4916 /*
4917 * Get the length of the opaque device_addr4. xdr_read_pages places
4918 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
4919 * and places the remaining xdr data in xdr_buf->tail
4920 */
4921 pdev->mincount = be32_to_cpup(p);
4922 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
4923
4924 /* Parse notification bitmap, verifying that it is zero. */
4925 p = xdr_inline_decode(xdr, 4);
4926 if (unlikely(!p))
4927 goto out_overflow;
4928 len = be32_to_cpup(p);
4929 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00004930 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04004931
4932 p = xdr_inline_decode(xdr, 4 * len);
4933 if (unlikely(!p))
4934 goto out_overflow;
4935 for (i = 0; i < len; i++, p++) {
4936 if (be32_to_cpup(p)) {
4937 dprintk("%s: notifications not supported\n",
4938 __func__);
4939 return -EIO;
4940 }
4941 }
4942 }
4943 return 0;
4944out_overflow:
4945 print_overflow_msg(__func__, xdr);
4946 return -EIO;
4947}
4948
4949static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
4950 struct nfs4_layoutget_res *res)
4951{
4952 __be32 *p;
4953 int status;
4954 u32 layout_count;
4955
4956 status = decode_op_hdr(xdr, OP_LAYOUTGET);
4957 if (status)
4958 return status;
4959 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
4960 if (unlikely(!p))
4961 goto out_overflow;
4962 res->return_on_close = be32_to_cpup(p++);
4963 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
4964 layout_count = be32_to_cpup(p);
4965 if (!layout_count) {
4966 dprintk("%s: server responded with empty layout array\n",
4967 __func__);
4968 return -EINVAL;
4969 }
4970
4971 p = xdr_inline_decode(xdr, 24);
4972 if (unlikely(!p))
4973 goto out_overflow;
4974 p = xdr_decode_hyper(p, &res->range.offset);
4975 p = xdr_decode_hyper(p, &res->range.length);
4976 res->range.iomode = be32_to_cpup(p++);
4977 res->type = be32_to_cpup(p++);
4978
4979 status = decode_opaque_inline(xdr, &res->layout.len, (char **)&p);
4980 if (unlikely(status))
4981 return status;
4982
4983 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
4984 __func__,
4985 (unsigned long)res->range.offset,
4986 (unsigned long)res->range.length,
4987 res->range.iomode,
4988 res->type,
4989 res->layout.len);
4990
4991 /* nfs4_proc_layoutget allocated a single page */
4992 if (res->layout.len > PAGE_SIZE)
4993 return -ENOMEM;
4994 memcpy(res->layout.buf, p, res->layout.len);
4995
4996 if (layout_count > 1) {
4997 /* We only handle a length one array at the moment. Any
4998 * further entries are just ignored. Note that this means
4999 * the client may see a response that is less than the
5000 * minimum it requested.
5001 */
5002 dprintk("%s: server responded with %d layouts, dropping tail\n",
5003 __func__, layout_count);
5004 }
5005
5006 return 0;
5007out_overflow:
5008 print_overflow_msg(__func__, xdr);
5009 return -EIO;
5010}
5011#endif /* CONFIG_NFS_V4_1 */
5012
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013/*
Benny Halevy49c25592008-12-23 16:06:16 -05005014 * END OF "GENERIC" DECODE ROUTINES.
5015 */
5016
5017/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018 * Decode OPEN_DOWNGRADE response
5019 */
Chuck Leverbf269552010-12-14 14:59:29 +00005020static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5021 struct xdr_stream *xdr,
5022 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023{
Andy Adamson05d564f2008-12-23 16:06:15 -05005024 struct compound_hdr hdr;
5025 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026
Chuck Leverbf269552010-12-14 14:59:29 +00005027 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005028 if (status)
5029 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005030 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005031 if (status)
5032 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005033 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005034 if (status)
5035 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005036 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005037 if (status != 0)
5038 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005039 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005040 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005042 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005043}
5044
5045/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046 * Decode ACCESS response
5047 */
Chuck Leverbf269552010-12-14 14:59:29 +00005048static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5049 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005051 struct compound_hdr hdr;
5052 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005053
Chuck Leverbf269552010-12-14 14:59:29 +00005054 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005055 if (status)
5056 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005057 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005058 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005059 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005060 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005061 if (status != 0)
5062 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005063 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005064 if (status != 0)
5065 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005066 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005067 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068out:
5069 return status;
5070}
5071
5072/*
5073 * Decode LOOKUP response
5074 */
Chuck Leverbf269552010-12-14 14:59:29 +00005075static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5076 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078 struct compound_hdr hdr;
5079 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005080
Chuck Leverbf269552010-12-14 14:59:29 +00005081 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005082 if (status)
5083 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005084 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005085 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005087 status = decode_putfh(xdr);
5088 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005089 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005090 status = decode_lookup(xdr);
5091 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005092 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005093 status = decode_getfh(xdr, res->fh);
5094 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005095 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005096 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005097 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005098out:
5099 return status;
5100}
5101
5102/*
5103 * Decode LOOKUP_ROOT response
5104 */
Chuck Leverbf269552010-12-14 14:59:29 +00005105static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5106 struct xdr_stream *xdr,
5107 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005108{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109 struct compound_hdr hdr;
5110 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005111
Chuck Leverbf269552010-12-14 14:59:29 +00005112 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005113 if (status)
5114 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005115 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005116 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005118 status = decode_putrootfh(xdr);
5119 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005121 status = decode_getfh(xdr, res->fh);
5122 if (status == 0)
5123 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005124 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005125out:
5126 return status;
5127}
5128
5129/*
5130 * Decode REMOVE response
5131 */
Chuck Leverbf269552010-12-14 14:59:29 +00005132static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5133 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005134{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005135 struct compound_hdr hdr;
5136 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005137
Chuck Leverbf269552010-12-14 14:59:29 +00005138 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005139 if (status)
5140 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005141 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005142 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005144 status = decode_putfh(xdr);
5145 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005146 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005147 status = decode_remove(xdr, &res->cinfo);
5148 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005149 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005150 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005151 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152out:
5153 return status;
5154}
5155
5156/*
5157 * Decode RENAME response
5158 */
Chuck Leverbf269552010-12-14 14:59:29 +00005159static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5160 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005161{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162 struct compound_hdr hdr;
5163 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005164
Chuck Leverbf269552010-12-14 14:59:29 +00005165 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005166 if (status)
5167 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005168 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005169 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005171 status = decode_putfh(xdr);
5172 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005174 status = decode_savefh(xdr);
5175 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005176 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005177 status = decode_putfh(xdr);
5178 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005179 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005180 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5181 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005182 goto out;
5183 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005184 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005185 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005186 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005187 status = decode_restorefh(xdr);
5188 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005189 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005190 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005191 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005192out:
5193 return status;
5194}
5195
5196/*
5197 * Decode LINK response
5198 */
Chuck Leverbf269552010-12-14 14:59:29 +00005199static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5200 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005201{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005202 struct compound_hdr hdr;
5203 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005204
Chuck Leverbf269552010-12-14 14:59:29 +00005205 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005206 if (status)
5207 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005208 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005209 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005210 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005211 status = decode_putfh(xdr);
5212 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005213 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005214 status = decode_savefh(xdr);
5215 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005216 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005217 status = decode_putfh(xdr);
5218 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005219 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005220 status = decode_link(xdr, &res->cinfo);
5221 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005222 goto out;
5223 /*
5224 * Note order: OP_LINK leaves the directory as the current
5225 * filehandle.
5226 */
Chuck Leverbf269552010-12-14 14:59:29 +00005227 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005228 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005229 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005230 status = decode_restorefh(xdr);
5231 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005232 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005233 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005234 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005235out:
5236 return status;
5237}
5238
5239/*
5240 * Decode CREATE response
5241 */
Chuck Leverbf269552010-12-14 14:59:29 +00005242static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5243 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005244{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245 struct compound_hdr hdr;
5246 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005247
Chuck Leverbf269552010-12-14 14:59:29 +00005248 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005249 if (status)
5250 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005251 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005252 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005253 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005254 status = decode_putfh(xdr);
5255 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005256 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005257 status = decode_savefh(xdr);
5258 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005259 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005260 status = decode_create(xdr, &res->dir_cinfo);
5261 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005263 status = decode_getfh(xdr, res->fh);
5264 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005265 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005266 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005267 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005268 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005269 status = decode_restorefh(xdr);
5270 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005271 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005272 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005273 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274out:
5275 return status;
5276}
5277
5278/*
5279 * Decode SYMLINK response
5280 */
Chuck Leverbf269552010-12-14 14:59:29 +00005281static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5282 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005283{
Chuck Leverbf269552010-12-14 14:59:29 +00005284 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005285}
5286
5287/*
5288 * Decode GETATTR response
5289 */
Chuck Leverbf269552010-12-14 14:59:29 +00005290static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5291 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005292{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005293 struct compound_hdr hdr;
5294 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005295
Chuck Leverbf269552010-12-14 14:59:29 +00005296 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005297 if (status)
5298 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005299 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005300 if (status)
5301 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005302 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005303 if (status)
5304 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005305 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005306 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005307out:
5308 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005309}
5310
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005311/*
5312 * Encode an SETACL request
5313 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005314static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5315 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005316{
Andy Adamson05d564f2008-12-23 16:06:15 -05005317 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005318 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005319 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005320
Chuck Lever9f06c712010-12-14 14:59:18 +00005321 encode_compound_hdr(xdr, req, &hdr);
5322 encode_sequence(xdr, &args->seq_args, &hdr);
5323 encode_putfh(xdr, args->fh, &hdr);
5324 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005325 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005326}
Andy Adamson05d564f2008-12-23 16:06:15 -05005327
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005328/*
5329 * Decode SETACL response
5330 */
5331static int
Chuck Leverbf269552010-12-14 14:59:29 +00005332nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005333 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005334{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005335 struct compound_hdr hdr;
5336 int status;
5337
Chuck Leverbf269552010-12-14 14:59:29 +00005338 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005339 if (status)
5340 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005341 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005342 if (status)
5343 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005344 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005345 if (status)
5346 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005347 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005348out:
5349 return status;
5350}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005351
5352/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005353 * Decode GETACL response
5354 */
5355static int
Chuck Leverbf269552010-12-14 14:59:29 +00005356nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005357 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005358{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005359 struct compound_hdr hdr;
5360 int status;
5361
Chuck Leverbf269552010-12-14 14:59:29 +00005362 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005363 if (status)
5364 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005365 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005366 if (status)
5367 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005368 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005369 if (status)
5370 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005371 status = decode_getacl(xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005372
5373out:
5374 return status;
5375}
5376
5377/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378 * Decode CLOSE response
5379 */
Chuck Leverbf269552010-12-14 14:59:29 +00005380static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5381 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005382{
Andy Adamson05d564f2008-12-23 16:06:15 -05005383 struct compound_hdr hdr;
5384 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005385
Chuck Leverbf269552010-12-14 14:59:29 +00005386 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005387 if (status)
5388 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005389 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005390 if (status)
5391 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005392 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005393 if (status)
5394 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005395 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005396 if (status != 0)
5397 goto out;
5398 /*
5399 * Note: Server may do delete on close for this file
5400 * in which case the getattr call will fail with
5401 * an ESTALE error. Shouldn't be a problem,
5402 * though, since fattr->valid will remain unset.
5403 */
Chuck Leverbf269552010-12-14 14:59:29 +00005404 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005405 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005407 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408}
5409
5410/*
5411 * Decode OPEN response
5412 */
Chuck Leverbf269552010-12-14 14:59:29 +00005413static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5414 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005415{
Andy Adamson05d564f2008-12-23 16:06:15 -05005416 struct compound_hdr hdr;
5417 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005418
Chuck Leverbf269552010-12-14 14:59:29 +00005419 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005420 if (status)
5421 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005422 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005423 if (status)
5424 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005425 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005426 if (status)
5427 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005428 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005429 if (status)
5430 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005431 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005432 if (status)
5433 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005434 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005435 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005436 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005437 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005438 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005439 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005440 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005441 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005442 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005443out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005444 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005445}
5446
5447/*
5448 * Decode OPEN_CONFIRM response
5449 */
Chuck Leverbf269552010-12-14 14:59:29 +00005450static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5451 struct xdr_stream *xdr,
5452 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005453{
Andy Adamson05d564f2008-12-23 16:06:15 -05005454 struct compound_hdr hdr;
5455 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005456
Chuck Leverbf269552010-12-14 14:59:29 +00005457 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005458 if (status)
5459 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005460 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005461 if (status)
5462 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005463 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005464out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005465 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005466}
5467
5468/*
5469 * Decode OPEN response
5470 */
Chuck Leverbf269552010-12-14 14:59:29 +00005471static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5472 struct xdr_stream *xdr,
5473 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005474{
Andy Adamson05d564f2008-12-23 16:06:15 -05005475 struct compound_hdr hdr;
5476 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005477
Chuck Leverbf269552010-12-14 14:59:29 +00005478 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005479 if (status)
5480 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005481 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005482 if (status)
5483 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005484 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005485 if (status)
5486 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005487 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005488 if (status)
5489 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005490 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005491 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005492out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005493 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005494}
5495
5496/*
5497 * Decode SETATTR response
5498 */
Chuck Leverbf269552010-12-14 14:59:29 +00005499static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5500 struct xdr_stream *xdr,
5501 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005502{
Andy Adamson05d564f2008-12-23 16:06:15 -05005503 struct compound_hdr hdr;
5504 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005505
Chuck Leverbf269552010-12-14 14:59:29 +00005506 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005507 if (status)
5508 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005509 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005510 if (status)
5511 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005512 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005513 if (status)
5514 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005515 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005516 if (status)
5517 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005518 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005519 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005520out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005521 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005522}
5523
5524/*
5525 * Decode LOCK response
5526 */
Chuck Leverbf269552010-12-14 14:59:29 +00005527static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5528 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005529{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005530 struct compound_hdr hdr;
5531 int status;
5532
Chuck Leverbf269552010-12-14 14:59:29 +00005533 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005534 if (status)
5535 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005536 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005537 if (status)
5538 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005539 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005540 if (status)
5541 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005542 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005543out:
5544 return status;
5545}
5546
5547/*
5548 * Decode LOCKT response
5549 */
Chuck Leverbf269552010-12-14 14:59:29 +00005550static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5551 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005552{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005553 struct compound_hdr hdr;
5554 int status;
5555
Chuck Leverbf269552010-12-14 14:59:29 +00005556 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005557 if (status)
5558 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005559 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005560 if (status)
5561 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005562 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005563 if (status)
5564 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005565 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005566out:
5567 return status;
5568}
5569
5570/*
5571 * Decode LOCKU response
5572 */
Chuck Leverbf269552010-12-14 14:59:29 +00005573static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5574 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005575{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005576 struct compound_hdr hdr;
5577 int status;
5578
Chuck Leverbf269552010-12-14 14:59:29 +00005579 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005580 if (status)
5581 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005582 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005583 if (status)
5584 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005585 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005586 if (status)
5587 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005588 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005589out:
5590 return status;
5591}
5592
Chuck Leverbf269552010-12-14 14:59:29 +00005593static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5594 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005595{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005596 struct compound_hdr hdr;
5597 int status;
5598
Chuck Leverbf269552010-12-14 14:59:29 +00005599 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005600 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005601 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005602 return status;
5603}
5604
Linus Torvalds1da177e2005-04-16 15:20:36 -07005605/*
5606 * Decode READLINK response
5607 */
Chuck Leverbf269552010-12-14 14:59:29 +00005608static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5609 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04005610 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005611{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005612 struct compound_hdr hdr;
5613 int status;
5614
Chuck Leverbf269552010-12-14 14:59:29 +00005615 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005616 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005622 if (status)
5623 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005624 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005625out:
5626 return status;
5627}
5628
5629/*
5630 * Decode READDIR response
5631 */
Chuck Leverbf269552010-12-14 14:59:29 +00005632static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5633 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005634{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005635 struct compound_hdr hdr;
5636 int status;
5637
Chuck Leverbf269552010-12-14 14:59:29 +00005638 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005639 if (status)
5640 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005641 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005642 if (status)
5643 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005644 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005645 if (status)
5646 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005647 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005648out:
5649 return status;
5650}
5651
5652/*
5653 * Decode Read response
5654 */
Chuck Leverbf269552010-12-14 14:59:29 +00005655static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5656 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005657{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005658 struct compound_hdr hdr;
5659 int status;
5660
Chuck Leverbf269552010-12-14 14:59:29 +00005661 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005662 if (status)
5663 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005664 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005665 if (status)
5666 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005667 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005668 if (status)
5669 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005670 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005671 if (!status)
5672 status = res->count;
5673out:
5674 return status;
5675}
5676
5677/*
5678 * Decode WRITE response
5679 */
Chuck Leverbf269552010-12-14 14:59:29 +00005680static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5681 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005682{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005683 struct compound_hdr hdr;
5684 int status;
5685
Chuck Leverbf269552010-12-14 14:59:29 +00005686 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005687 if (status)
5688 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005689 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005690 if (status)
5691 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005692 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005693 if (status)
5694 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005695 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005696 if (status)
5697 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00005698 if (res->fattr)
5699 decode_getfattr(xdr, res->fattr, res->server,
5700 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005701 if (!status)
5702 status = res->count;
5703out:
5704 return status;
5705}
5706
5707/*
5708 * Decode COMMIT response
5709 */
Chuck Leverbf269552010-12-14 14:59:29 +00005710static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5711 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005712{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005713 struct compound_hdr hdr;
5714 int status;
5715
Chuck Leverbf269552010-12-14 14:59:29 +00005716 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005717 if (status)
5718 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005719 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005720 if (status)
5721 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005722 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005723 if (status)
5724 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005725 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005726 if (status)
5727 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005728 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005729 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005730out:
5731 return status;
5732}
5733
5734/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005735 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005736 */
Chuck Leverbf269552010-12-14 14:59:29 +00005737static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04005738 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005739{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005740 struct compound_hdr hdr;
5741 int status;
5742
Chuck Leverbf269552010-12-14 14:59:29 +00005743 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005744 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005745 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005746 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005747 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005748 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005749 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005750 return status;
5751}
5752
5753/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005754 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755 */
Chuck Leverbf269552010-12-14 14:59:29 +00005756static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04005757 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005759 struct compound_hdr hdr;
5760 int status;
5761
Chuck Leverbf269552010-12-14 14:59:29 +00005762 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005763 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005764 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005765 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005766 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005768 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005769 return status;
5770}
5771
5772/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005773 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005774 */
Chuck Leverbf269552010-12-14 14:59:29 +00005775static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04005776 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005777{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005778 struct compound_hdr hdr;
5779 int status;
5780
Chuck Leverbf269552010-12-14 14:59:29 +00005781 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005782 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005783 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005784 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005785 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005786 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005787 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788 return status;
5789}
5790
5791/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005792 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005793 */
Chuck Leverbf269552010-12-14 14:59:29 +00005794static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
5795 struct xdr_stream *xdr,
5796 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005797{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005798 struct compound_hdr hdr;
5799 int status;
5800
Chuck Leverbf269552010-12-14 14:59:29 +00005801 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005802 if (status)
5803 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005804 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005805 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005806 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005807 status = decode_putfh(xdr);
5808 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005809 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005810 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005811out:
5812 return status;
5813}
5814
5815/*
5816 * Decode RENEW response
5817 */
Chuck Leverbf269552010-12-14 14:59:29 +00005818static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5819 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005820{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005821 struct compound_hdr hdr;
5822 int status;
5823
Chuck Leverbf269552010-12-14 14:59:29 +00005824 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005825 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005826 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005827 return status;
5828}
5829
5830/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005831 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005832 */
Chuck Leverbf269552010-12-14 14:59:29 +00005833static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
5834 struct xdr_stream *xdr,
5835 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005837 struct compound_hdr hdr;
5838 int status;
5839
Chuck Leverbf269552010-12-14 14:59:29 +00005840 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005841 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005842 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005843 return status;
5844}
5845
5846/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005847 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005848 */
Chuck Leverbf269552010-12-14 14:59:29 +00005849static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
5850 struct xdr_stream *xdr,
5851 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005852{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005853 struct compound_hdr hdr;
5854 int status;
5855
Chuck Leverbf269552010-12-14 14:59:29 +00005856 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005858 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005859 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005860 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005861 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005862 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005863 return status;
5864}
5865
5866/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005867 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868 */
Chuck Leverbf269552010-12-14 14:59:29 +00005869static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
5870 struct xdr_stream *xdr,
5871 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005872{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005873 struct compound_hdr hdr;
5874 int status;
5875
Chuck Leverbf269552010-12-14 14:59:29 +00005876 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005877 if (status)
5878 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005879 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005880 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005881 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005882 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01005883 if (status != 0)
5884 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005885 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04005886 if (status != 0)
5887 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005888 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005889 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01005890out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005891 return status;
5892}
5893
Trond Myklebust683b57b2006-06-09 09:34:22 -04005894/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005895 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04005896 */
Chuck Leverbf269552010-12-14 14:59:29 +00005897static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
5898 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04005899 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005900{
Trond Myklebust683b57b2006-06-09 09:34:22 -04005901 struct compound_hdr hdr;
5902 int status;
5903
Chuck Leverbf269552010-12-14 14:59:29 +00005904 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005905 if (status)
5906 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005907 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005908 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005909 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005910 status = decode_putfh(xdr);
5911 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005912 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005913 status = decode_lookup(xdr);
5914 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005915 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005916 xdr_enter_page(xdr, PAGE_SIZE);
5917 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005918 res->fs_locations->server,
5919 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04005920out:
5921 return status;
5922}
5923
Benny Halevy99fe60d2009-04-01 09:22:29 -04005924#if defined(CONFIG_NFS_V4_1)
5925/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005926 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04005927 */
Chuck Leverbf269552010-12-14 14:59:29 +00005928static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
5929 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04005930 void *res)
5931{
Benny Halevy99fe60d2009-04-01 09:22:29 -04005932 struct compound_hdr hdr;
5933 int status;
5934
Chuck Leverbf269552010-12-14 14:59:29 +00005935 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005936 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005937 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005938 return status;
5939}
Andy Adamson2050f0c2009-04-01 09:22:30 -04005940
5941/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005942 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04005943 */
Chuck Leverbf269552010-12-14 14:59:29 +00005944static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
5945 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04005946 struct nfs41_create_session_res *res)
5947{
Andy Adamsonfc931582009-04-01 09:22:31 -04005948 struct compound_hdr hdr;
5949 int status;
5950
Chuck Leverbf269552010-12-14 14:59:29 +00005951 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04005952 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005953 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04005954 return status;
5955}
5956
5957/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005958 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005959 */
Chuck Leverbf269552010-12-14 14:59:29 +00005960static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
5961 struct xdr_stream *xdr,
5962 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005963{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005964 struct compound_hdr hdr;
5965 int status;
5966
Chuck Leverbf269552010-12-14 14:59:29 +00005967 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005968 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005969 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005970 return status;
5971}
5972
5973/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005974 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005975 */
Chuck Leverbf269552010-12-14 14:59:29 +00005976static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
5977 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005978 struct nfs4_sequence_res *res)
5979{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005980 struct compound_hdr hdr;
5981 int status;
5982
Chuck Leverbf269552010-12-14 14:59:29 +00005983 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005984 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005985 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005986 return status;
5987}
5988
5989/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005990 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04005991 */
Chuck Leverbf269552010-12-14 14:59:29 +00005992static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
5993 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04005994 struct nfs4_get_lease_time_res *res)
5995{
Andy Adamson2050f0c2009-04-01 09:22:30 -04005996 struct compound_hdr hdr;
5997 int status;
5998
Chuck Leverbf269552010-12-14 14:59:29 +00005999 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006000 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006001 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006002 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006003 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006004 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006005 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006006 return status;
6007}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006008
6009/*
6010 * Decode RECLAIM_COMPLETE response
6011 */
Chuck Leverbf269552010-12-14 14:59:29 +00006012static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6013 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006014 struct nfs41_reclaim_complete_res *res)
6015{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006016 struct compound_hdr hdr;
6017 int status;
6018
Chuck Leverbf269552010-12-14 14:59:29 +00006019 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006020 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006021 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006022 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006023 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006024 return status;
6025}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006026
6027/*
6028 * Decode GETDEVINFO response
6029 */
Chuck Leverbf269552010-12-14 14:59:29 +00006030static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6031 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006032 struct nfs4_getdeviceinfo_res *res)
6033{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006034 struct compound_hdr hdr;
6035 int status;
6036
Chuck Leverbf269552010-12-14 14:59:29 +00006037 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006038 if (status != 0)
6039 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006040 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006041 if (status != 0)
6042 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006043 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006044out:
6045 return status;
6046}
6047
6048/*
6049 * Decode LAYOUTGET response
6050 */
Chuck Leverbf269552010-12-14 14:59:29 +00006051static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6052 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006053 struct nfs4_layoutget_res *res)
6054{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006055 struct compound_hdr hdr;
6056 int status;
6057
Chuck Leverbf269552010-12-14 14:59:29 +00006058 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006059 if (status)
6060 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006061 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006062 if (status)
6063 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006064 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006065 if (status)
6066 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006067 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006068out:
6069 return status;
6070}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006071#endif /* CONFIG_NFS_V4_1 */
6072
Chuck Lever573c4e12010-12-14 14:58:11 +00006073/**
6074 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6075 * the local page cache.
6076 * @xdr: XDR stream where entry resides
6077 * @entry: buffer to fill in with entry data
6078 * @plus: boolean indicating whether this should be a readdirplus entry
6079 *
6080 * Returns zero if successful, otherwise a negative errno value is
6081 * returned.
6082 *
6083 * This function is not invoked during READDIR reply decoding, but
6084 * rather whenever an application invokes the getdents(2) system call
6085 * on a directory already in our cache.
6086 */
6087int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6088 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089{
6090 uint32_t bitmap[2] = {0};
6091 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006092 __be32 *p = xdr_inline_decode(xdr, 4);
6093 if (unlikely(!p))
6094 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006095 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006096 p = xdr_inline_decode(xdr, 4);
6097 if (unlikely(!p))
6098 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006099 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006100 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006102 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103 }
6104
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006105 p = xdr_inline_decode(xdr, 12);
6106 if (unlikely(!p))
6107 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006108 entry->prev_cookie = entry->cookie;
6109 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006110 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006111
Trond Myklebust9af8c222010-10-24 11:52:55 -04006112 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006113 if (unlikely(!p))
6114 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006115 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006116
6117 /*
6118 * In case the server doesn't return an inode number,
6119 * we fake one here. (We don't use inode number 0,
6120 * since glibc seems to choke on it...)
6121 */
6122 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006123 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006124
Trond Myklebust9af8c222010-10-24 11:52:55 -04006125 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006126 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006127
6128 if (decode_attr_length(xdr, &len, &p) < 0)
6129 goto out_overflow;
6130
Chuck Lever573c4e12010-12-14 14:58:11 +00006131 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6132 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006133 goto out_overflow;
6134 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6135 entry->ino = entry->fattr->fileid;
6136
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006137 entry->d_type = DT_UNKNOWN;
6138 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6139 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6140
Chuck Lever573c4e12010-12-14 14:58:11 +00006141 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006142
6143out_overflow:
6144 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006145 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146}
6147
6148/*
6149 * We need to translate between nfs status return values and
6150 * the local errno values which may not be the same.
6151 */
6152static struct {
6153 int stat;
6154 int errno;
6155} nfs_errtbl[] = {
6156 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006157 { NFS4ERR_PERM, -EPERM },
6158 { NFS4ERR_NOENT, -ENOENT },
6159 { NFS4ERR_IO, -errno_NFSERR_IO},
6160 { NFS4ERR_NXIO, -ENXIO },
6161 { NFS4ERR_ACCESS, -EACCES },
6162 { NFS4ERR_EXIST, -EEXIST },
6163 { NFS4ERR_XDEV, -EXDEV },
6164 { NFS4ERR_NOTDIR, -ENOTDIR },
6165 { NFS4ERR_ISDIR, -EISDIR },
6166 { NFS4ERR_INVAL, -EINVAL },
6167 { NFS4ERR_FBIG, -EFBIG },
6168 { NFS4ERR_NOSPC, -ENOSPC },
6169 { NFS4ERR_ROFS, -EROFS },
6170 { NFS4ERR_MLINK, -EMLINK },
6171 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6172 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6173 { NFS4ERR_DQUOT, -EDQUOT },
6174 { NFS4ERR_STALE, -ESTALE },
6175 { NFS4ERR_BADHANDLE, -EBADHANDLE },
6176 { NFS4ERR_BADOWNER, -EINVAL },
6177 { NFS4ERR_BADNAME, -EINVAL },
6178 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6179 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6180 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006181 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006182 { NFS4ERR_BADTYPE, -EBADTYPE },
6183 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006184 { NFS4ERR_SYMLINK, -ELOOP },
6185 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6186 { NFS4ERR_DEADLOCK, -EDEADLK },
6187 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188 * to be handled by a
6189 * middle-layer.
6190 */
Benny Halevy856dff32008-03-31 17:39:06 +03006191 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192};
6193
6194/*
6195 * Convert an NFS error code to a local one.
6196 * This one is used jointly by NFSv2 and NFSv3.
6197 */
6198static int
David Howells0a8ea432006-08-22 20:06:08 -04006199nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200{
6201 int i;
6202 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6203 if (nfs_errtbl[i].stat == stat)
6204 return nfs_errtbl[i].errno;
6205 }
6206 if (stat <= 10000 || stat > 10100) {
6207 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006208 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209 }
6210 /* If we cannot translate the error, the recovery routines should
6211 * handle it.
6212 * Note: remaining NFSv4 error codes have values > 10000, so should
6213 * not conflict with native Linux error codes.
6214 */
Benny Halevy856dff32008-03-31 17:39:06 +03006215 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216}
6217
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218#define PROC(proc, argtype, restype) \
6219[NFSPROC4_CLNT_##proc] = { \
6220 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006221 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006222 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006223 .p_arglen = NFS4_##argtype##_sz, \
6224 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006225 .p_statidx = NFSPROC4_CLNT_##proc, \
6226 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006227}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228
6229struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006230 PROC(READ, enc_read, dec_read),
6231 PROC(WRITE, enc_write, dec_write),
6232 PROC(COMMIT, enc_commit, dec_commit),
6233 PROC(OPEN, enc_open, dec_open),
6234 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6235 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6236 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6237 PROC(CLOSE, enc_close, dec_close),
6238 PROC(SETATTR, enc_setattr, dec_setattr),
6239 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6240 PROC(RENEW, enc_renew, dec_renew),
6241 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6242 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6243 PROC(LOCK, enc_lock, dec_lock),
6244 PROC(LOCKT, enc_lockt, dec_lockt),
6245 PROC(LOCKU, enc_locku, dec_locku),
6246 PROC(ACCESS, enc_access, dec_access),
6247 PROC(GETATTR, enc_getattr, dec_getattr),
6248 PROC(LOOKUP, enc_lookup, dec_lookup),
6249 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6250 PROC(REMOVE, enc_remove, dec_remove),
6251 PROC(RENAME, enc_rename, dec_rename),
6252 PROC(LINK, enc_link, dec_link),
6253 PROC(SYMLINK, enc_symlink, dec_symlink),
6254 PROC(CREATE, enc_create, dec_create),
6255 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6256 PROC(STATFS, enc_statfs, dec_statfs),
6257 PROC(READLINK, enc_readlink, dec_readlink),
6258 PROC(READDIR, enc_readdir, dec_readdir),
6259 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6260 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6261 PROC(GETACL, enc_getacl, dec_getacl),
6262 PROC(SETACL, enc_setacl, dec_setacl),
6263 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6264 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006265#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00006266 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6267 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6268 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6269 PROC(SEQUENCE, enc_sequence, dec_sequence),
6270 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6271 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6272 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6273 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006274#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006275};
6276
6277struct rpc_version nfs_version4 = {
6278 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08006279 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07006280 .procs = nfs4_procedures
6281};
6282
6283/*
6284 * Local variables:
6285 * c-basic-offset: 8
6286 * End:
6287 */