blob: ba952bdc4d624db46ede8b0cf2821f4e9ef9452e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
47#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050048#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000049#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/nfs.h>
51#include <linux/nfs4.h>
52#include <linux/nfs_fs.h>
53#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000054#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050055#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040056#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58#define NFSDBG_FACILITY NFSDBG_XDR
59
60/* Mapping from NFS error code to "errno" error code. */
61#define errno_NFSERR_IO EIO
62
David Howells0a8ea432006-08-22 20:06:08 -040063static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
66#ifdef DEBUG
67#define NFS4_MAXTAGLEN 20
68#else
69#define NFS4_MAXTAGLEN 0
70#endif
71
Andy Adamson6c0195a2008-12-23 16:06:15 -050072/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040073 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 */
Trond Myklebustd035c362010-12-21 10:45:27 -050075#define open_owner_id_maxsz (1 + 1 + 4)
76#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040077#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
80#define op_encode_hdr_maxsz (1)
81#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040082#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
84#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
85#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
87 (NFS4_FHSIZE >> 2))
88#define decode_putfh_maxsz (op_decode_hdr_maxsz)
89#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
90#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
91#define encode_getfh_maxsz (op_encode_hdr_maxsz)
92#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
93 ((3+NFS4_FHSIZE) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000094#define nfs4_fattr_bitmap_maxsz 3
95#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
97#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040098#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
99#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000100/* This is based on getfattr, which uses the most attributes: */
101#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400102 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000103#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
104 nfs4_fattr_value_maxsz)
105#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400106#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
107 1 + 2 + 1 + \
108 nfs4_owner_maxsz + \
109 nfs4_group_maxsz + \
110 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define encode_savefh_maxsz (op_encode_hdr_maxsz)
112#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400113#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
114#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200115#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Bryan Schumaker7ebb9312011-03-24 17:12:30 +0000116#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 15)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
118#define decode_renew_maxsz (op_decode_hdr_maxsz)
119#define encode_setclientid_maxsz \
120 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500121 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
122 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
123 1 /* sc_prog */ + \
124 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
125 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
126 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define decode_setclientid_maxsz \
128 (op_decode_hdr_maxsz + \
129 2 + \
130 1024) /* large value for CLID_INUSE */
131#define encode_setclientid_confirm_maxsz \
132 (op_encode_hdr_maxsz + \
133 3 + (NFS4_VERIFIER_SIZE >> 2))
134#define decode_setclientid_confirm_maxsz \
135 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400136#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
137#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400138#define encode_share_access_maxsz \
139 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500140#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400141#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
142#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
143#define encode_open_maxsz (op_encode_hdr_maxsz + \
144 2 + encode_share_access_maxsz + 2 + \
145 open_owner_id_maxsz + \
146 encode_opentype_maxsz + \
147 encode_claim_null_maxsz)
148#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400149#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400150 decode_ace_maxsz)
151#define decode_change_info_maxsz (5)
152#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400153 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400154 decode_change_info_maxsz + 1 + \
155 nfs4_fattr_bitmap_maxsz + \
156 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400157#define encode_open_confirm_maxsz \
158 (op_encode_hdr_maxsz + \
159 encode_stateid_maxsz + 1)
160#define decode_open_confirm_maxsz \
161 (op_decode_hdr_maxsz + \
162 decode_stateid_maxsz)
163#define encode_open_downgrade_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1 + \
166 encode_share_access_maxsz)
167#define decode_open_downgrade_maxsz \
168 (op_decode_hdr_maxsz + \
169 decode_stateid_maxsz)
170#define encode_close_maxsz (op_encode_hdr_maxsz + \
171 1 + encode_stateid_maxsz)
172#define decode_close_maxsz (op_decode_hdr_maxsz + \
173 decode_stateid_maxsz)
174#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
175 encode_stateid_maxsz + \
176 encode_attrs_maxsz)
177#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
178 nfs4_fattr_bitmap_maxsz)
179#define encode_read_maxsz (op_encode_hdr_maxsz + \
180 encode_stateid_maxsz + 3)
181#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
182#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
183 2 + encode_verifier_maxsz + 5)
184#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
185 decode_verifier_maxsz)
186#define encode_readlink_maxsz (op_encode_hdr_maxsz)
187#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
188#define encode_write_maxsz (op_encode_hdr_maxsz + \
189 encode_stateid_maxsz + 4)
190#define decode_write_maxsz (op_decode_hdr_maxsz + \
191 2 + decode_verifier_maxsz)
192#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
193#define decode_commit_maxsz (op_decode_hdr_maxsz + \
194 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195#define encode_remove_maxsz (op_encode_hdr_maxsz + \
196 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400197#define decode_remove_maxsz (op_decode_hdr_maxsz + \
198 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199#define encode_rename_maxsz (op_encode_hdr_maxsz + \
200 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400201#define decode_rename_maxsz (op_decode_hdr_maxsz + \
202 decode_change_info_maxsz + \
203 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204#define encode_link_maxsz (op_encode_hdr_maxsz + \
205 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400206#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400207#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400208#define encode_lock_maxsz (op_encode_hdr_maxsz + \
209 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400210 1 + encode_stateid_maxsz + 1 + \
211 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400212#define decode_lock_denied_maxsz \
213 (8 + decode_lockowner_maxsz)
214#define decode_lock_maxsz (op_decode_hdr_maxsz + \
215 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400216#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
217 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400218#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
219 decode_lock_denied_maxsz)
220#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
221 encode_stateid_maxsz + \
222 4)
223#define decode_locku_maxsz (op_decode_hdr_maxsz + \
224 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400225#define encode_release_lockowner_maxsz \
226 (op_encode_hdr_maxsz + \
227 encode_lockowner_maxsz)
228#define decode_release_lockowner_maxsz \
229 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400230#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
231#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
233 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400234 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000235 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
237#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400238 1 + 2 + nfs4_name_maxsz + \
239 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400240#define decode_create_maxsz (op_decode_hdr_maxsz + \
241 decode_change_info_maxsz + \
242 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400243#define encode_statfs_maxsz (encode_getattr_maxsz)
244#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
246#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400247#define encode_getacl_maxsz (encode_getattr_maxsz)
248#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
249 nfs4_fattr_bitmap_maxsz + 1)
250#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
251 encode_stateid_maxsz + 3)
252#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400253#define encode_fs_locations_maxsz \
254 (encode_getattr_maxsz)
255#define decode_fs_locations_maxsz \
256 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000257#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
258#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 4 + (NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400259
260#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400261#define NFS4_MAX_MACHINE_NAME_LEN (64)
262
Benny Halevy99fe60d2009-04-01 09:22:29 -0400263#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
264 encode_verifier_maxsz + \
265 1 /* co_ownerid.len */ + \
266 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
267 1 /* flags */ + \
268 1 /* spa_how */ + \
269 0 /* SP4_NONE (for now) */ + \
270 1 /* zero implemetation id array */)
271#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
272 2 /* eir_clientid */ + \
273 1 /* eir_sequenceid */ + \
274 1 /* eir_flags */ + \
275 1 /* spr_how */ + \
276 0 /* SP4_NONE (for now) */ + \
277 2 /* eir_server_owner.so_minor_id */ + \
278 /* eir_server_owner.so_major_id<> */ \
279 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
280 /* eir_server_scope<> */ \
281 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
282 1 /* eir_server_impl_id array length */ + \
283 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400284#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
285#define decode_channel_attrs_maxsz (6 + \
286 1 /* ca_rdma_ird.len */ + \
287 1 /* ca_rdma_ird */)
288#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
289 2 /* csa_clientid */ + \
290 1 /* csa_sequence */ + \
291 1 /* csa_flags */ + \
292 encode_channel_attrs_maxsz + \
293 encode_channel_attrs_maxsz + \
294 1 /* csa_cb_program */ + \
295 1 /* csa_sec_parms.len (1) */ + \
296 1 /* cb_secflavor (AUTH_SYS) */ + \
297 1 /* stamp */ + \
298 1 /* machinename.len */ + \
299 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
300 1 /* uid */ + \
301 1 /* gid */ + \
302 1 /* gids.len (0) */)
303#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
304 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
305 1 /* csr_sequence */ + \
306 1 /* csr_flags */ + \
307 decode_channel_attrs_maxsz + \
308 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400309#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
310#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400311#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
312 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
313#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
314 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500315#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
316#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400317#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
318 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
319#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
320 1 /* layout type */ + \
321 1 /* opaque devaddr4 length */ + \
322 /* devaddr4 payload is read into page */ \
323 1 /* notification bitmap length */ + \
324 1 /* notification bitmap */)
325#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
326 encode_stateid_maxsz)
327#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
328 decode_stateid_maxsz + \
329 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000330#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
331 2 /* offset */ + \
332 2 /* length */ + \
333 1 /* reclaim */ + \
334 encode_stateid_maxsz + \
335 1 /* new offset (true) */ + \
336 2 /* last byte written */ + \
337 1 /* nt_timechanged (false) */ + \
338 1 /* layoutupdate4 layout type */ + \
339 1 /* NULL filelayout layoutupdate4 payload */)
340#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
341
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400342#else /* CONFIG_NFS_V4_1 */
343#define encode_sequence_maxsz 0
344#define decode_sequence_maxsz 0
345#endif /* CONFIG_NFS_V4_1 */
346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
348#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
349#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400350 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400352 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400354 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400356 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400358 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400360 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400362 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400364 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400366 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400368 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400370 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400372 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400374 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400376 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400377 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400379 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400381 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400382 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400384 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400386 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400387 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400389 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400391 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400392 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400394 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400395 encode_putfh_maxsz + \
396 encode_savefh_maxsz + \
397 encode_open_maxsz + \
398 encode_getfh_maxsz + \
399 encode_getattr_maxsz + \
400 encode_restorefh_maxsz + \
401 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400403 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400404 decode_putfh_maxsz + \
405 decode_savefh_maxsz + \
406 decode_open_maxsz + \
407 decode_getfh_maxsz + \
408 decode_getattr_maxsz + \
409 decode_restorefh_maxsz + \
410 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400411#define NFS4_enc_open_confirm_sz \
412 (compound_encode_hdr_maxsz + \
413 encode_putfh_maxsz + \
414 encode_open_confirm_maxsz)
415#define NFS4_dec_open_confirm_sz \
416 (compound_decode_hdr_maxsz + \
417 decode_putfh_maxsz + \
418 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400420 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400422 encode_open_maxsz + \
423 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400425 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400427 decode_open_maxsz + \
428 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define NFS4_enc_open_downgrade_sz \
430 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400431 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400432 encode_putfh_maxsz + \
433 encode_open_downgrade_maxsz + \
434 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435#define NFS4_dec_open_downgrade_sz \
436 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400438 decode_putfh_maxsz + \
439 decode_open_downgrade_maxsz + \
440 decode_getattr_maxsz)
441#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400443 encode_putfh_maxsz + \
444 encode_close_maxsz + \
445 encode_getattr_maxsz)
446#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400447 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400448 decode_putfh_maxsz + \
449 decode_close_maxsz + \
450 decode_getattr_maxsz)
451#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400452 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400453 encode_putfh_maxsz + \
454 encode_setattr_maxsz + \
455 encode_getattr_maxsz)
456#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400457 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400458 decode_putfh_maxsz + \
459 decode_setattr_maxsz + \
460 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400462 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 encode_putfh_maxsz + \
464 encode_fsinfo_maxsz)
465#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400466 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 decode_putfh_maxsz + \
468 decode_fsinfo_maxsz)
469#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
470 encode_renew_maxsz)
471#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
472 decode_renew_maxsz)
473#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
474 encode_setclientid_maxsz)
475#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
476 decode_setclientid_maxsz)
477#define NFS4_enc_setclientid_confirm_sz \
478 (compound_encode_hdr_maxsz + \
479 encode_setclientid_confirm_maxsz + \
480 encode_putrootfh_maxsz + \
481 encode_fsinfo_maxsz)
482#define NFS4_dec_setclientid_confirm_sz \
483 (compound_decode_hdr_maxsz + \
484 decode_setclientid_confirm_maxsz + \
485 decode_putrootfh_maxsz + \
486 decode_fsinfo_maxsz)
487#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400488 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400490 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400494 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400498 encode_lockt_maxsz)
499#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400500 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400501 decode_putfh_maxsz + \
502 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400504 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400506 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#define NFS4_dec_locku_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 Myklebust9104a552007-07-17 21:52:42 -0400510 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400511#define NFS4_enc_release_lockowner_sz \
512 (compound_encode_hdr_maxsz + \
513 encode_lockowner_maxsz)
514#define NFS4_dec_release_lockowner_sz \
515 (compound_decode_hdr_maxsz + \
516 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400518 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400520 encode_access_maxsz + \
521 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400523 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400525 decode_access_maxsz + \
526 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400528 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 encode_putfh_maxsz + \
530 encode_getattr_maxsz)
531#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400532 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 decode_putfh_maxsz + \
534 decode_getattr_maxsz)
535#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400536 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 encode_putfh_maxsz + \
538 encode_lookup_maxsz + \
539 encode_getattr_maxsz + \
540 encode_getfh_maxsz)
541#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400544 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 decode_getattr_maxsz + \
546 decode_getfh_maxsz)
547#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400548 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 encode_putrootfh_maxsz + \
550 encode_getattr_maxsz + \
551 encode_getfh_maxsz)
552#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400553 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 decode_putrootfh_maxsz + \
555 decode_getattr_maxsz + \
556 decode_getfh_maxsz)
557#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400558 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400560 encode_remove_maxsz + \
561 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400563 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400565 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400566 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 encode_putfh_maxsz + \
570 encode_savefh_maxsz + \
571 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400572 encode_rename_maxsz + \
573 encode_getattr_maxsz + \
574 encode_restorefh_maxsz + \
575 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400577 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 decode_putfh_maxsz + \
579 decode_savefh_maxsz + \
580 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400581 decode_rename_maxsz + \
582 decode_getattr_maxsz + \
583 decode_restorefh_maxsz + \
584 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 encode_putfh_maxsz + \
588 encode_savefh_maxsz + \
589 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400590 encode_link_maxsz + \
591 decode_getattr_maxsz + \
592 encode_restorefh_maxsz + \
593 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594#define NFS4_dec_link_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_savefh_maxsz + \
598 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400599 decode_link_maxsz + \
600 decode_getattr_maxsz + \
601 decode_restorefh_maxsz + \
602 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400604 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 encode_putfh_maxsz + \
606 encode_symlink_maxsz + \
607 encode_getattr_maxsz + \
608 encode_getfh_maxsz)
609#define NFS4_dec_symlink_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 + \
612 decode_symlink_maxsz + \
613 decode_getattr_maxsz + \
614 decode_getfh_maxsz)
615#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400616 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400618 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400620 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400622 encode_restorefh_maxsz + \
623 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400625 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400627 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400629 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400631 decode_restorefh_maxsz + \
632 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400634 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 encode_putfh_maxsz + \
636 encode_getattr_maxsz)
637#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400638 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 decode_putfh_maxsz + \
640 decode_getattr_maxsz)
641#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400644 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400646 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400648 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800651 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 encode_getattr_maxsz)
653#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800655 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 decode_getattr_maxsz)
657#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400658 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100660 encode_delegreturn_maxsz + \
661 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400663 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100664 decode_delegreturn_maxsz + \
665 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000666#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400667 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000668 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400669 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000670#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400671 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000672 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400673 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000674#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400675 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000676 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400677 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000678#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400679 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000680 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400681 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400682#define NFS4_enc_fs_locations_sz \
683 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400685 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400686 encode_lookup_maxsz + \
687 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400688#define NFS4_dec_fs_locations_sz \
689 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400690 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400691 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400692 decode_lookup_maxsz + \
693 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000694#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
695 encode_sequence_maxsz + \
696 encode_putfh_maxsz + \
697 encode_secinfo_maxsz)
698#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
699 decode_sequence_maxsz + \
700 decode_putfh_maxsz + \
701 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400702#if defined(CONFIG_NFS_V4_1)
703#define NFS4_enc_exchange_id_sz \
704 (compound_encode_hdr_maxsz + \
705 encode_exchange_id_maxsz)
706#define NFS4_dec_exchange_id_sz \
707 (compound_decode_hdr_maxsz + \
708 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400709#define NFS4_enc_create_session_sz \
710 (compound_encode_hdr_maxsz + \
711 encode_create_session_maxsz)
712#define NFS4_dec_create_session_sz \
713 (compound_decode_hdr_maxsz + \
714 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400715#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
716 encode_destroy_session_maxsz)
717#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
718 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400719#define NFS4_enc_sequence_sz \
720 (compound_decode_hdr_maxsz + \
721 encode_sequence_maxsz)
722#define NFS4_dec_sequence_sz \
723 (compound_decode_hdr_maxsz + \
724 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400725#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
726 encode_sequence_maxsz + \
727 encode_putrootfh_maxsz + \
728 encode_fsinfo_maxsz)
729#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
730 decode_sequence_maxsz + \
731 decode_putrootfh_maxsz + \
732 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500733#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
734 encode_sequence_maxsz + \
735 encode_reclaim_complete_maxsz)
736#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
737 decode_sequence_maxsz + \
738 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400739#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
740 encode_sequence_maxsz +\
741 encode_getdeviceinfo_maxsz)
742#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
743 decode_sequence_maxsz + \
744 decode_getdeviceinfo_maxsz)
745#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
746 encode_sequence_maxsz + \
747 encode_putfh_maxsz + \
748 encode_layoutget_maxsz)
749#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
750 decode_sequence_maxsz + \
751 decode_putfh_maxsz + \
752 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000753#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
754 encode_sequence_maxsz +\
755 encode_putfh_maxsz + \
756 encode_layoutcommit_maxsz + \
757 encode_getattr_maxsz)
758#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
759 decode_sequence_maxsz + \
760 decode_putfh_maxsz + \
761 decode_layoutcommit_maxsz + \
762 decode_getattr_maxsz)
763
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500764
765const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
766 compound_encode_hdr_maxsz +
767 encode_sequence_maxsz +
768 encode_putfh_maxsz +
769 encode_getattr_maxsz) *
770 XDR_UNIT);
771
772const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
773 compound_decode_hdr_maxsz +
774 decode_sequence_maxsz +
775 decode_putfh_maxsz) *
776 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400777#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Trond Myklebustbca79472009-03-11 14:10:26 -0400779static const umode_t nfs_type2fmt[] = {
780 [NF4BAD] = 0,
781 [NF4REG] = S_IFREG,
782 [NF4DIR] = S_IFDIR,
783 [NF4BLK] = S_IFBLK,
784 [NF4CHR] = S_IFCHR,
785 [NF4LNK] = S_IFLNK,
786 [NF4SOCK] = S_IFSOCK,
787 [NF4FIFO] = S_IFIFO,
788 [NF4ATTRDIR] = 0,
789 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790};
791
792struct compound_hdr {
793 int32_t status;
794 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500795 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 uint32_t taglen;
797 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400798 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400799 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800};
801
Benny Halevy13c65ce2009-08-14 17:19:25 +0300802static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
803{
804 __be32 *p = xdr_reserve_space(xdr, nbytes);
805 BUG_ON(!p);
806 return p;
807}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
810{
Al Viro8687b632006-10-19 23:28:48 -0700811 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 p = xdr_reserve_space(xdr, 4 + len);
814 BUG_ON(p == NULL);
815 xdr_encode_opaque(p, str, len);
816}
817
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400818static void encode_compound_hdr(struct xdr_stream *xdr,
819 struct rpc_rqst *req,
820 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
Al Viro8687b632006-10-19 23:28:48 -0700822 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400823 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400824
825 /* initialize running count of expected bytes in reply.
826 * NOTE: the replied tag SHOULD be the same is the one sent,
827 * but this is not required as a MUST for the server to do so. */
828 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
831 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300832 p = reserve_space(xdr, 4 + hdr->taglen + 8);
833 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300834 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500835 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300836 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500837}
838
839static void encode_nops(struct compound_hdr *hdr)
840{
Andy Adamsonfc931582009-04-01 09:22:31 -0400841 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500842 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843}
844
845static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
846{
Al Viro8687b632006-10-19 23:28:48 -0700847 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
849 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
850 BUG_ON(p == NULL);
851 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
852}
853
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500854static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855{
856 char owner_name[IDMAP_NAMESZ];
857 char owner_group[IDMAP_NAMESZ];
858 int owner_namelen = 0;
859 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700860 __be32 *p;
861 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 int len;
863 uint32_t bmval0 = 0;
864 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
866 /*
867 * We reserve enough space to write the entire attribute buffer at once.
868 * In the worst-case, this would be
869 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
870 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000871 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 */
873 len = 16;
874
875 /* Sigh */
876 if (iap->ia_valid & ATTR_SIZE)
877 len += 8;
878 if (iap->ia_valid & ATTR_MODE)
879 len += 4;
880 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800881 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400883 dprintk("nfs: couldn't resolve uid %d to string\n",
884 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 /* XXX */
886 strcpy(owner_name, "nobody");
887 owner_namelen = sizeof("nobody") - 1;
888 /* goto out; */
889 }
890 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
891 }
892 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800893 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400895 dprintk("nfs: couldn't resolve gid %d to string\n",
896 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 strcpy(owner_group, "nobody");
898 owner_grouplen = sizeof("nobody") - 1;
899 /* goto out; */
900 }
901 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
902 }
903 if (iap->ia_valid & ATTR_ATIME_SET)
904 len += 16;
905 else if (iap->ia_valid & ATTR_ATIME)
906 len += 4;
907 if (iap->ia_valid & ATTR_MTIME_SET)
908 len += 16;
909 else if (iap->ia_valid & ATTR_MTIME)
910 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300911 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
913 /*
914 * We write the bitmap length now, but leave the bitmap and the attribute
915 * buffer length to be backfilled at the end of this routine.
916 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300917 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 q = p;
919 p += 3;
920
921 if (iap->ia_valid & ATTR_SIZE) {
922 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300923 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 }
925 if (iap->ia_valid & ATTR_MODE) {
926 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300927 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 }
929 if (iap->ia_valid & ATTR_UID) {
930 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300931 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 }
933 if (iap->ia_valid & ATTR_GID) {
934 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300935 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 }
937 if (iap->ia_valid & ATTR_ATIME_SET) {
938 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300939 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
940 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -0400941 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
942 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 }
944 else if (iap->ia_valid & ATTR_ATIME) {
945 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300946 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 }
948 if (iap->ia_valid & ATTR_MTIME_SET) {
949 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300950 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
951 *p++ = cpu_to_be32(0);
952 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
953 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 }
955 else if (iap->ia_valid & ATTR_MTIME) {
956 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300957 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 /*
961 * Now we backfill the bitmap and the attribute buffer length.
962 */
963 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400964 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 len, ((char *)p - (char *)q) + 4);
966 BUG();
967 }
968 len = (char *)p - (char *)q - 12;
969 *q++ = htonl(bmval0);
970 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300971 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974}
975
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500976static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977{
Al Viro8687b632006-10-19 23:28:48 -0700978 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
Benny Halevy13c65ce2009-08-14 17:19:25 +0300980 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300981 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +0300982 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500983 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400984 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985}
986
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500987static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988{
Al Viro8687b632006-10-19 23:28:48 -0700989 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
Benny Halevy13c65ce2009-08-14 17:19:25 +0300991 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300992 *p++ = cpu_to_be32(OP_CLOSE);
993 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +0300994 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500995 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400996 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997}
998
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500999static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000{
Al Viro8687b632006-10-19 23:28:48 -07001001 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001002
Benny Halevy13c65ce2009-08-14 17:19:25 +03001003 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001004 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001005 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001006 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001007 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001008 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009}
1010
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001011static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012{
Al Viro8687b632006-10-19 23:28:48 -07001013 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001014
Benny Halevy13c65ce2009-08-14 17:19:25 +03001015 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001016 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001017 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
1019 switch (create->ftype) {
1020 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001021 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001022 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001023 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 break;
1025
1026 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001027 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001028 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001029 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 break;
1031
1032 default:
1033 break;
1034 }
1035
Benny Halevy811652b2009-08-14 17:19:34 +03001036 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001037 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001038 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001040 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041}
1042
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001043static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044{
Andy Adamson05d564f2008-12-23 16:06:15 -05001045 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
Benny Halevy13c65ce2009-08-14 17:19:25 +03001047 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001048 *p++ = cpu_to_be32(OP_GETATTR);
1049 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001050 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001051 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001052 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053}
1054
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001055static 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 -07001056{
Andy Adamson05d564f2008-12-23 16:06:15 -05001057 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
Benny Halevy13c65ce2009-08-14 17:19:25 +03001059 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001060 *p++ = cpu_to_be32(OP_GETATTR);
1061 *p++ = cpu_to_be32(2);
1062 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001063 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001064 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001065 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066}
1067
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001068static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001070 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1071 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072}
1073
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001074static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001076 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1077 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078}
1079
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001080static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001081{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001082 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1083 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001084}
1085
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001086static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087{
Al Viro8687b632006-10-19 23:28:48 -07001088 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
Benny Halevy13c65ce2009-08-14 17:19:25 +03001090 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001091 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001092 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001093 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094}
1095
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001096static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097{
Al Viro8687b632006-10-19 23:28:48 -07001098 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
Benny Halevy13c65ce2009-08-14 17:19:25 +03001100 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001101 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001102 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001103 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001104 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105}
1106
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001107static inline int nfs4_lock_type(struct file_lock *fl, int block)
1108{
1109 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1110 return block ? NFS4_READW_LT : NFS4_READ_LT;
1111 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1112}
1113
1114static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1115{
1116 if (fl->fl_end == OFFSET_MAX)
1117 return ~(uint64_t)0;
1118 return fl->fl_end - fl->fl_start + 1;
1119}
1120
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001121static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1122{
1123 __be32 *p;
1124
Trond Myklebustd035c362010-12-21 10:45:27 -05001125 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001126 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001127 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001128 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001129 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001130 xdr_encode_hyper(p, lowner->id);
1131}
1132
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133/*
1134 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1135 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1136 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001137static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138{
Al Viro8687b632006-10-19 23:28:48 -07001139 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
Benny Halevy13c65ce2009-08-14 17:19:25 +03001141 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001142 *p++ = cpu_to_be32(OP_LOCK);
1143 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1144 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001145 p = xdr_encode_hyper(p, args->fl->fl_start);
1146 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001147 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001148 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001149 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001150 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001151 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001152 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001153 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 }
1155 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001156 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001157 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001158 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 }
Andy Adamsond0179312008-12-23 16:06:17 -05001160 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001161 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162}
1163
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001164static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165{
Al Viro8687b632006-10-19 23:28:48 -07001166 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001168 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001169 *p++ = cpu_to_be32(OP_LOCKT);
1170 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001171 p = xdr_encode_hyper(p, args->fl->fl_start);
1172 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001173 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001174 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001175 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176}
1177
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001178static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179{
Al Viro8687b632006-10-19 23:28:48 -07001180 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
Benny Halevy13c65ce2009-08-14 17:19:25 +03001182 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001183 *p++ = cpu_to_be32(OP_LOCKU);
1184 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1185 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001186 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001187 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001188 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001189 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001190 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191}
1192
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001193static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1194{
1195 __be32 *p;
1196
1197 p = reserve_space(xdr, 4);
1198 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1199 encode_lockowner(xdr, lowner);
1200 hdr->nops++;
1201 hdr->replen += decode_release_lockowner_maxsz;
1202}
1203
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001204static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205{
1206 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001207 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
Benny Halevy13c65ce2009-08-14 17:19:25 +03001209 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001210 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001211 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001212 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001213 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214}
1215
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001216static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217{
Al Viro8687b632006-10-19 23:28:48 -07001218 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
Benny Halevy13c65ce2009-08-14 17:19:25 +03001220 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001221 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001222 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001223 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001224 break;
1225 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001226 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001227 break;
1228 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001229 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001230 break;
1231 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001232 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 }
Benny Halevy34558512009-08-14 17:19:30 +03001234 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235}
1236
1237static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1238{
Al Viro8687b632006-10-19 23:28:48 -07001239 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 /*
1241 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1242 * owner 4 = 32
1243 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001244 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001245 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001246 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001247 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001248 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001249 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001250 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001251 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001252 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001253 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254}
1255
1256static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1257{
Al Viro8687b632006-10-19 23:28:48 -07001258 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001259 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
Benny Halevy13c65ce2009-08-14 17:19:25 +03001261 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001263 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001264 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001265 encode_attrs(xdr, arg->u.attrs, arg->server);
1266 break;
1267 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001268 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001269 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001270 if (nfs4_has_persistent_session(clp)) {
1271 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1272 encode_attrs(xdr, arg->u.attrs, arg->server);
1273 } else {
1274 struct iattr dummy;
1275
1276 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1277 encode_nfs4_verifier(xdr, &arg->u.verifier);
1278 dummy.ia_valid = 0;
1279 encode_attrs(xdr, &dummy, arg->server);
1280 }
1281 } else {
1282 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1283 encode_nfs4_verifier(xdr, &arg->u.verifier);
1284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 }
1286}
1287
1288static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1289{
Al Viro8687b632006-10-19 23:28:48 -07001290 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Benny Halevy13c65ce2009-08-14 17:19:25 +03001292 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001294 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001295 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001296 break;
1297 default:
1298 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001299 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001300 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 }
1302}
1303
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001304static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305{
Al Viro8687b632006-10-19 23:28:48 -07001306 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
Benny Halevy13c65ce2009-08-14 17:19:25 +03001308 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001310 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001311 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001312 break;
1313 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001314 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001315 break;
1316 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001317 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001318 break;
1319 default:
1320 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 }
1322}
1323
1324static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1325{
Al Viro8687b632006-10-19 23:28:48 -07001326 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Benny Halevy13c65ce2009-08-14 17:19:25 +03001328 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001329 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 encode_string(xdr, name->len, name->name);
1331}
1332
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001333static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334{
Al Viro8687b632006-10-19 23:28:48 -07001335 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Benny Halevy13c65ce2009-08-14 17:19:25 +03001337 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001338 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 encode_delegation_type(xdr, type);
1340}
1341
1342static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1343{
Al Viro8687b632006-10-19 23:28:48 -07001344 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Benny Halevy13c65ce2009-08-14 17:19:25 +03001346 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001347 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001348 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 encode_string(xdr, name->len, name->name);
1350}
1351
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001352static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353{
1354 encode_openhdr(xdr, arg);
1355 encode_opentype(xdr, arg);
1356 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001357 case NFS4_OPEN_CLAIM_NULL:
1358 encode_claim_null(xdr, arg->name);
1359 break;
1360 case NFS4_OPEN_CLAIM_PREVIOUS:
1361 encode_claim_previous(xdr, arg->u.delegation_type);
1362 break;
1363 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1364 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1365 break;
1366 default:
1367 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 }
Andy Adamsond0179312008-12-23 16:06:17 -05001369 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001370 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371}
1372
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001373static 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 -07001374{
Al Viro8687b632006-10-19 23:28:48 -07001375 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376
Benny Halevy13c65ce2009-08-14 17:19:25 +03001377 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001378 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001379 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001380 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001381 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001382 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383}
1384
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001385static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386{
Al Viro8687b632006-10-19 23:28:48 -07001387 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
Benny Halevy13c65ce2009-08-14 17:19:25 +03001389 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001390 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001391 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001392 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001393 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001394 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001395 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396}
1397
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001398static void
Andy Adamsond0179312008-12-23 16:06:17 -05001399encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400{
1401 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001402 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Benny Halevy13c65ce2009-08-14 17:19:25 +03001404 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001405 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001406 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001407 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001408 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409}
1410
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001411static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412{
Andy Adamson05d564f2008-12-23 16:06:15 -05001413 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001414
Benny Halevy13c65ce2009-08-14 17:19:25 +03001415 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001416 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001417 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001418 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419}
1420
Andy Adamson89d1ea62011-03-01 01:34:09 +00001421static 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 -07001422{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001424 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
Benny Halevy13c65ce2009-08-14 17:19:25 +03001426 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001428 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001429 if (zero_seqid)
1430 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001431 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 } else
Benny Halevy34558512009-08-14 17:19:30 +03001433 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434}
1435
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001436static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437{
Al Viro8687b632006-10-19 23:28:48 -07001438 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Benny Halevy13c65ce2009-08-14 17:19:25 +03001440 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001441 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
Andy Adamson89d1ea62011-03-01 01:34:09 +00001443 encode_stateid(xdr, args->context, args->lock_context,
1444 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
Benny Halevy13c65ce2009-08-14 17:19:25 +03001446 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001447 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001448 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001449 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001450 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451}
1452
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001453static 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 -07001454{
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001455 uint32_t attrs[2] = {0, 0};
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001456 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001457 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001459 if (readdir->plus) {
1460 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1461 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE;
1462 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1463 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1464 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1465 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001466 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001467 }
1468 attrs[0] |= FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID;
1469 attrs[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001470 /* Switch to mounted_on_fileid if the server supports it */
1471 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1472 attrs[0] &= ~FATTR4_WORD0_FILEID;
1473 else
1474 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001475
Benny Halevy13c65ce2009-08-14 17:19:25 +03001476 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001477 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001478 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001479 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001480 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001481 *p++ = cpu_to_be32(readdir->count);
1482 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001483
Benny Halevye75bc1c2009-08-14 17:18:54 +03001484 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001485 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001486 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001487 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001488 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1489 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001490 (unsigned long long)readdir->cookie,
1491 ((u32 *)readdir->verifier.data)[0],
1492 ((u32 *)readdir->verifier.data)[1],
1493 attrs[0] & readdir->bitmask[0],
1494 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495}
1496
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001497static 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 -07001498{
Al Viro8687b632006-10-19 23:28:48 -07001499 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
Benny Halevy13c65ce2009-08-14 17:19:25 +03001501 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001502 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001503 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001504 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505}
1506
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001507static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
Al Viro8687b632006-10-19 23:28:48 -07001509 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Benny Halevy13c65ce2009-08-14 17:19:25 +03001511 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001512 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001513 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001514 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001515 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516}
1517
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001518static 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 -07001519{
Al Viro8687b632006-10-19 23:28:48 -07001520 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
Benny Halevy811652b2009-08-14 17:19:34 +03001522 p = reserve_space(xdr, 4);
1523 *p = cpu_to_be32(OP_RENAME);
1524 encode_string(xdr, oldname->len, oldname->name);
1525 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001526 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001527 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528}
1529
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001530static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531{
Al Viro8687b632006-10-19 23:28:48 -07001532 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
Benny Halevy13c65ce2009-08-14 17:19:25 +03001534 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001535 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001536 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001537 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001538 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539}
1540
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001541static void
Andy Adamsond0179312008-12-23 16:06:17 -05001542encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001543{
Al Viro8687b632006-10-19 23:28:48 -07001544 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001545
Benny Halevy13c65ce2009-08-14 17:19:25 +03001546 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001547 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001548 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001549 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001550}
1551
Chuck Lever9f06c712010-12-14 14:59:18 +00001552static void
Andy Adamsond0179312008-12-23 16:06:17 -05001553encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001554{
Al Viro8687b632006-10-19 23:28:48 -07001555 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001556
Benny Halevy13c65ce2009-08-14 17:19:25 +03001557 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001558 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001559 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001560 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001561 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001562 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001563 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001564 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001565 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001566 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001567 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001568 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001569}
1570
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001571static void
Andy Adamsond0179312008-12-23 16:06:17 -05001572encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573{
Al Viro8687b632006-10-19 23:28:48 -07001574 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575
Benny Halevy13c65ce2009-08-14 17:19:25 +03001576 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001577 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001578 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001579 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580}
1581
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001582static 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 -07001583{
Al Viro8687b632006-10-19 23:28:48 -07001584 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001585
Benny Halevy13c65ce2009-08-14 17:19:25 +03001586 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001587 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001588 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001589 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001590 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001591 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592}
1593
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001594static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595{
Al Viro8687b632006-10-19 23:28:48 -07001596 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
Benny Halevy13c65ce2009-08-14 17:19:25 +03001598 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001599 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001600 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
1602 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001603 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001604 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1606 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001607 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001608 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001609 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001610 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611}
1612
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001613static 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 -07001614{
Andy Adamson05d564f2008-12-23 16:06:15 -05001615 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
Benny Halevy13c65ce2009-08-14 17:19:25 +03001617 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001618 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001619 p = xdr_encode_hyper(p, arg->clientid);
1620 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001621 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001622 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623}
1624
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001625static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626{
Al Viro8687b632006-10-19 23:28:48 -07001627 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628
Benny Halevy13c65ce2009-08-14 17:19:25 +03001629 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001630 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
Andy Adamson89d1ea62011-03-01 01:34:09 +00001632 encode_stateid(xdr, args->context, args->lock_context,
1633 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
Benny Halevy13c65ce2009-08-14 17:19:25 +03001635 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001636 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001637 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001638 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
1640 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001641 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001642 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643}
1644
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001645static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646{
Al Viro8687b632006-10-19 23:28:48 -07001647 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
Benny Halevy13c65ce2009-08-14 17:19:25 +03001649 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
Benny Halevye75bc1c2009-08-14 17:18:54 +03001651 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001652 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001653 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001654 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001656
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001657static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1658{
1659 int len = name->len;
1660 __be32 *p;
1661
1662 p = reserve_space(xdr, 8 + len);
1663 *p++ = cpu_to_be32(OP_SECINFO);
1664 xdr_encode_opaque(p, name->name, len);
1665 hdr->nops++;
1666 hdr->replen += decode_secinfo_maxsz;
1667}
1668
Benny Halevy99fe60d2009-04-01 09:22:29 -04001669#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001670/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001671static void encode_exchange_id(struct xdr_stream *xdr,
1672 struct nfs41_exchange_id_args *args,
1673 struct compound_hdr *hdr)
1674{
1675 __be32 *p;
1676
Benny Halevy13c65ce2009-08-14 17:19:25 +03001677 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001678 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001679 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001680
1681 encode_string(xdr, args->id_len, args->id);
1682
Benny Halevy13c65ce2009-08-14 17:19:25 +03001683 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001684 *p++ = cpu_to_be32(args->flags);
1685 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001686 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001687 hdr->nops++;
1688 hdr->replen += decode_exchange_id_maxsz;
1689}
Andy Adamsonfc931582009-04-01 09:22:31 -04001690
1691static void encode_create_session(struct xdr_stream *xdr,
1692 struct nfs41_create_session_args *args,
1693 struct compound_hdr *hdr)
1694{
1695 __be32 *p;
1696 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1697 uint32_t len;
1698 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001699 u32 max_resp_sz_cached;
1700
1701 /*
1702 * Assumes OPEN is the biggest non-idempotent compound.
1703 * 2 is the verifier.
1704 */
1705 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1706 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001707
Andy Adamsonfc931582009-04-01 09:22:31 -04001708 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1709 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001710
Benny Halevy13c65ce2009-08-14 17:19:25 +03001711 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001712 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001713 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001714 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1715 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001716
Andy Adamsonfc931582009-04-01 09:22:31 -04001717 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001718 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1719 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1720 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001721 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001722 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1723 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1724 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001725
1726 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001727 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1728 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1729 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1730 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1731 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1732 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1733 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001734
Benny Halevye75bc1c2009-08-14 17:18:54 +03001735 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001736 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001737 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001738
1739 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001740 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001741 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001742 *p++ = cpu_to_be32(0); /* UID */
1743 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001744 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001745 hdr->nops++;
1746 hdr->replen += decode_create_session_maxsz;
1747}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001748
1749static void encode_destroy_session(struct xdr_stream *xdr,
1750 struct nfs4_session *session,
1751 struct compound_hdr *hdr)
1752{
1753 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001754 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001755 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001756 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001757 hdr->nops++;
1758 hdr->replen += decode_destroy_session_maxsz;
1759}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001760
1761static void encode_reclaim_complete(struct xdr_stream *xdr,
1762 struct nfs41_reclaim_complete_args *args,
1763 struct compound_hdr *hdr)
1764{
1765 __be32 *p;
1766
1767 p = reserve_space(xdr, 8);
1768 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1769 *p++ = cpu_to_be32(args->one_fs);
1770 hdr->nops++;
1771 hdr->replen += decode_reclaim_complete_maxsz;
1772}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001773#endif /* CONFIG_NFS_V4_1 */
1774
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001775static void encode_sequence(struct xdr_stream *xdr,
1776 const struct nfs4_sequence_args *args,
1777 struct compound_hdr *hdr)
1778{
1779#if defined(CONFIG_NFS_V4_1)
1780 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001781 struct nfs4_slot_table *tp;
1782 struct nfs4_slot *slot;
1783 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001784
1785 if (!session)
1786 return;
1787
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001788 tp = &session->fc_slot_table;
1789
1790 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1791 slot = tp->slots + args->sa_slotid;
1792
Benny Halevy13c65ce2009-08-14 17:19:25 +03001793 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001794 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001795
1796 /*
1797 * Sessionid + seqid + slotid + max slotid + cache_this
1798 */
1799 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1800 "max_slotid=%d cache_this=%d\n",
1801 __func__,
1802 ((u32 *)session->sess_id.data)[0],
1803 ((u32 *)session->sess_id.data)[1],
1804 ((u32 *)session->sess_id.data)[2],
1805 ((u32 *)session->sess_id.data)[3],
1806 slot->seq_nr, args->sa_slotid,
1807 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001808 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001809 *p++ = cpu_to_be32(slot->seq_nr);
1810 *p++ = cpu_to_be32(args->sa_slotid);
1811 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001812 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001813 hdr->nops++;
1814 hdr->replen += decode_sequence_maxsz;
1815#endif /* CONFIG_NFS_V4_1 */
1816}
1817
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001818#ifdef CONFIG_NFS_V4_1
1819static void
1820encode_getdeviceinfo(struct xdr_stream *xdr,
1821 const struct nfs4_getdeviceinfo_args *args,
1822 struct compound_hdr *hdr)
1823{
1824 __be32 *p;
1825
1826 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1827 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1828 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1829 NFS4_DEVICEID4_SIZE);
1830 *p++ = cpu_to_be32(args->pdev->layout_type);
1831 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1832 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1833 hdr->nops++;
1834 hdr->replen += decode_getdeviceinfo_maxsz;
1835}
1836
1837static void
1838encode_layoutget(struct xdr_stream *xdr,
1839 const struct nfs4_layoutget_args *args,
1840 struct compound_hdr *hdr)
1841{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001842 __be32 *p;
1843
1844 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1845 *p++ = cpu_to_be32(OP_LAYOUTGET);
1846 *p++ = cpu_to_be32(0); /* Signal layout available */
1847 *p++ = cpu_to_be32(args->type);
1848 *p++ = cpu_to_be32(args->range.iomode);
1849 p = xdr_encode_hyper(p, args->range.offset);
1850 p = xdr_encode_hyper(p, args->range.length);
1851 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00001852 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001853 *p = cpu_to_be32(args->maxcount);
1854
1855 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1856 __func__,
1857 args->type,
1858 args->range.iomode,
1859 (unsigned long)args->range.offset,
1860 (unsigned long)args->range.length,
1861 args->maxcount);
1862 hdr->nops++;
1863 hdr->replen += decode_layoutget_maxsz;
1864}
Andy Adamson863a3c62011-03-23 13:27:54 +00001865
1866static int
1867encode_layoutcommit(struct xdr_stream *xdr,
1868 const struct nfs4_layoutcommit_args *args,
1869 struct compound_hdr *hdr)
1870{
1871 __be32 *p;
1872
1873 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1874 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1875
1876 p = reserve_space(xdr, 48 + NFS4_STATEID_SIZE);
1877 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1878 /* Only whole file layouts */
1879 p = xdr_encode_hyper(p, 0); /* offset */
1880 p = xdr_encode_hyper(p, NFS4_MAX_UINT64); /* length */
1881 *p++ = cpu_to_be32(0); /* reclaim */
1882 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1883 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1884 p = xdr_encode_hyper(p, args->lastbytewritten);
1885 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1886 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1887 *p++ = cpu_to_be32(0); /* no file layout payload */
1888
1889 hdr->nops++;
1890 hdr->replen += decode_layoutcommit_maxsz;
1891 return 0;
1892}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001893#endif /* CONFIG_NFS_V4_1 */
1894
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895/*
1896 * END OF "GENERIC" ENCODE ROUTINES.
1897 */
1898
Benny Halevy66cc0422009-04-01 09:22:10 -04001899static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1900{
1901#if defined(CONFIG_NFS_V4_1)
1902 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001903 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001904#endif /* CONFIG_NFS_V4_1 */
1905 return 0;
1906}
1907
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908/*
1909 * Encode an ACCESS request
1910 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001911static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1912 const struct nfs4_accessargs *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->fh, &hdr);
1921 encode_access(xdr, args->access, &hdr);
1922 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001923 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924}
1925
1926/*
1927 * Encode LOOKUP request
1928 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001929static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1930 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001933 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935
Chuck Lever9f06c712010-12-14 14:59:18 +00001936 encode_compound_hdr(xdr, req, &hdr);
1937 encode_sequence(xdr, &args->seq_args, &hdr);
1938 encode_putfh(xdr, args->dir_fh, &hdr);
1939 encode_lookup(xdr, args->name, &hdr);
1940 encode_getfh(xdr, &hdr);
1941 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001942 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943}
1944
1945/*
1946 * Encode LOOKUP_ROOT request
1947 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001948static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
1949 struct xdr_stream *xdr,
1950 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001953 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
Chuck Lever9f06c712010-12-14 14:59:18 +00001956 encode_compound_hdr(xdr, req, &hdr);
1957 encode_sequence(xdr, &args->seq_args, &hdr);
1958 encode_putrootfh(xdr, &hdr);
1959 encode_getfh(xdr, &hdr);
1960 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001961 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962}
1963
1964/*
1965 * Encode REMOVE request
1966 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001967static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
1968 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001971 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
Chuck Lever9f06c712010-12-14 14:59:18 +00001974 encode_compound_hdr(xdr, req, &hdr);
1975 encode_sequence(xdr, &args->seq_args, &hdr);
1976 encode_putfh(xdr, args->fh, &hdr);
1977 encode_remove(xdr, &args->name, &hdr);
1978 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001979 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980}
1981
1982/*
1983 * Encode RENAME request
1984 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001985static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
1986 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001989 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
Chuck Lever9f06c712010-12-14 14:59:18 +00001992 encode_compound_hdr(xdr, req, &hdr);
1993 encode_sequence(xdr, &args->seq_args, &hdr);
1994 encode_putfh(xdr, args->old_dir, &hdr);
1995 encode_savefh(xdr, &hdr);
1996 encode_putfh(xdr, args->new_dir, &hdr);
1997 encode_rename(xdr, args->old_name, args->new_name, &hdr);
1998 encode_getfattr(xdr, args->bitmask, &hdr);
1999 encode_restorefh(xdr, &hdr);
2000 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002001 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002}
2003
2004/*
2005 * Encode LINK request
2006 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002007static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2008 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002011 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
Chuck Lever9f06c712010-12-14 14:59:18 +00002014 encode_compound_hdr(xdr, req, &hdr);
2015 encode_sequence(xdr, &args->seq_args, &hdr);
2016 encode_putfh(xdr, args->fh, &hdr);
2017 encode_savefh(xdr, &hdr);
2018 encode_putfh(xdr, args->dir_fh, &hdr);
2019 encode_link(xdr, args->name, &hdr);
2020 encode_getfattr(xdr, args->bitmask, &hdr);
2021 encode_restorefh(xdr, &hdr);
2022 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002023 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024}
2025
2026/*
2027 * Encode CREATE request
2028 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002029static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2030 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002033 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
Chuck Lever9f06c712010-12-14 14:59:18 +00002036 encode_compound_hdr(xdr, req, &hdr);
2037 encode_sequence(xdr, &args->seq_args, &hdr);
2038 encode_putfh(xdr, args->dir_fh, &hdr);
2039 encode_savefh(xdr, &hdr);
2040 encode_create(xdr, args, &hdr);
2041 encode_getfh(xdr, &hdr);
2042 encode_getfattr(xdr, args->bitmask, &hdr);
2043 encode_restorefh(xdr, &hdr);
2044 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002045 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046}
2047
2048/*
2049 * Encode SYMLINK request
2050 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002051static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2052 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053{
Chuck Lever9f06c712010-12-14 14:59:18 +00002054 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055}
2056
2057/*
2058 * Encode GETATTR request
2059 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002060static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2061 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002064 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066
Chuck Lever9f06c712010-12-14 14:59:18 +00002067 encode_compound_hdr(xdr, req, &hdr);
2068 encode_sequence(xdr, &args->seq_args, &hdr);
2069 encode_putfh(xdr, args->fh, &hdr);
2070 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002071 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072}
2073
2074/*
2075 * Encode a CLOSE request
2076 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002077static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2078 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079{
Andy Adamson05d564f2008-12-23 16:06:15 -05002080 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002081 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002082 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
Chuck Lever9f06c712010-12-14 14:59:18 +00002084 encode_compound_hdr(xdr, req, &hdr);
2085 encode_sequence(xdr, &args->seq_args, &hdr);
2086 encode_putfh(xdr, args->fh, &hdr);
2087 encode_close(xdr, args, &hdr);
2088 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002089 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090}
2091
2092/*
2093 * Encode an OPEN request
2094 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002095static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2096 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002099 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
Chuck Lever9f06c712010-12-14 14:59:18 +00002102 encode_compound_hdr(xdr, req, &hdr);
2103 encode_sequence(xdr, &args->seq_args, &hdr);
2104 encode_putfh(xdr, args->fh, &hdr);
2105 encode_savefh(xdr, &hdr);
2106 encode_open(xdr, args, &hdr);
2107 encode_getfh(xdr, &hdr);
2108 encode_getfattr(xdr, args->bitmask, &hdr);
2109 encode_restorefh(xdr, &hdr);
2110 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002111 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112}
2113
2114/*
2115 * Encode an OPEN_CONFIRM request
2116 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002117static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2118 struct xdr_stream *xdr,
2119 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002122 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
Chuck Lever9f06c712010-12-14 14:59:18 +00002125 encode_compound_hdr(xdr, req, &hdr);
2126 encode_putfh(xdr, args->fh, &hdr);
2127 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002128 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129}
2130
2131/*
2132 * Encode an OPEN request with no attributes.
2133 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002134static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2135 struct xdr_stream *xdr,
2136 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002139 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
Chuck Lever9f06c712010-12-14 14:59:18 +00002142 encode_compound_hdr(xdr, req, &hdr);
2143 encode_sequence(xdr, &args->seq_args, &hdr);
2144 encode_putfh(xdr, args->fh, &hdr);
2145 encode_open(xdr, args, &hdr);
2146 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002147 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148}
2149
2150/*
2151 * Encode an OPEN_DOWNGRADE request
2152 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002153static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2154 struct xdr_stream *xdr,
2155 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002158 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
Chuck Lever9f06c712010-12-14 14:59:18 +00002161 encode_compound_hdr(xdr, req, &hdr);
2162 encode_sequence(xdr, &args->seq_args, &hdr);
2163 encode_putfh(xdr, args->fh, &hdr);
2164 encode_open_downgrade(xdr, args, &hdr);
2165 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002166 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167}
2168
2169/*
2170 * Encode a LOCK request
2171 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002172static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2173 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002176 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Chuck Lever9f06c712010-12-14 14:59:18 +00002179 encode_compound_hdr(xdr, req, &hdr);
2180 encode_sequence(xdr, &args->seq_args, &hdr);
2181 encode_putfh(xdr, args->fh, &hdr);
2182 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002183 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184}
2185
2186/*
2187 * Encode a LOCKT request
2188 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002189static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2190 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002193 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
Chuck Lever9f06c712010-12-14 14:59:18 +00002196 encode_compound_hdr(xdr, req, &hdr);
2197 encode_sequence(xdr, &args->seq_args, &hdr);
2198 encode_putfh(xdr, args->fh, &hdr);
2199 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002200 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201}
2202
2203/*
2204 * Encode a LOCKU request
2205 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002206static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2207 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002210 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
Chuck Lever9f06c712010-12-14 14:59:18 +00002213 encode_compound_hdr(xdr, req, &hdr);
2214 encode_sequence(xdr, &args->seq_args, &hdr);
2215 encode_putfh(xdr, args->fh, &hdr);
2216 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002217 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218}
2219
Chuck Lever9f06c712010-12-14 14:59:18 +00002220static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2221 struct xdr_stream *xdr,
2222 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002223{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002224 struct compound_hdr hdr = {
2225 .minorversion = 0,
2226 };
2227
Chuck Lever9f06c712010-12-14 14:59:18 +00002228 encode_compound_hdr(xdr, req, &hdr);
2229 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002230 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002231}
2232
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233/*
2234 * Encode a READLINK request
2235 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002236static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2237 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002240 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
Chuck Lever9f06c712010-12-14 14:59:18 +00002243 encode_compound_hdr(xdr, req, &hdr);
2244 encode_sequence(xdr, &args->seq_args, &hdr);
2245 encode_putfh(xdr, args->fh, &hdr);
2246 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002247
Benny Halevy28f56692009-04-01 09:22:09 -04002248 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002249 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002250 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251}
2252
2253/*
2254 * Encode a READDIR request
2255 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002256static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2257 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002260 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
Chuck Lever9f06c712010-12-14 14:59:18 +00002263 encode_compound_hdr(xdr, req, &hdr);
2264 encode_sequence(xdr, &args->seq_args, &hdr);
2265 encode_putfh(xdr, args->fh, &hdr);
2266 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002267
Benny Halevy28f56692009-04-01 09:22:09 -04002268 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002269 args->pgbase, args->count);
2270 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002271 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002272 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002273 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274}
2275
2276/*
2277 * Encode a READ request
2278 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002279static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2280 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002283 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
Chuck Lever9f06c712010-12-14 14:59:18 +00002286 encode_compound_hdr(xdr, req, &hdr);
2287 encode_sequence(xdr, &args->seq_args, &hdr);
2288 encode_putfh(xdr, args->fh, &hdr);
2289 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290
Benny Halevy28f56692009-04-01 09:22:09 -04002291 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002293 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002294 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295}
2296
2297/*
2298 * Encode an SETATTR request
2299 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002300static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2301 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302{
Andy Adamson05d564f2008-12-23 16:06:15 -05002303 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002304 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002305 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306
Chuck Lever9f06c712010-12-14 14:59:18 +00002307 encode_compound_hdr(xdr, req, &hdr);
2308 encode_sequence(xdr, &args->seq_args, &hdr);
2309 encode_putfh(xdr, args->fh, &hdr);
2310 encode_setattr(xdr, args, args->server, &hdr);
2311 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002312 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313}
2314
2315/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002316 * Encode a GETACL request
2317 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002318static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2319 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002320{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002321 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002322 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002323 };
Benny Halevy28f56692009-04-01 09:22:09 -04002324 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002325
Chuck Lever9f06c712010-12-14 14:59:18 +00002326 encode_compound_hdr(xdr, req, &hdr);
2327 encode_sequence(xdr, &args->seq_args, &hdr);
2328 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002329 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002330 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002331
Benny Halevy28f56692009-04-01 09:22:09 -04002332 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002333 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002334 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002335}
2336
2337/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 * Encode a WRITE request
2339 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002340static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2341 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002344 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346
Chuck Lever9f06c712010-12-14 14:59:18 +00002347 encode_compound_hdr(xdr, req, &hdr);
2348 encode_sequence(xdr, &args->seq_args, &hdr);
2349 encode_putfh(xdr, args->fh, &hdr);
2350 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002351 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002352 if (args->bitmask)
2353 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002354 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355}
2356
2357/*
2358 * a COMMIT request
2359 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002360static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2361 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002364 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
Chuck Lever9f06c712010-12-14 14:59:18 +00002367 encode_compound_hdr(xdr, req, &hdr);
2368 encode_sequence(xdr, &args->seq_args, &hdr);
2369 encode_putfh(xdr, args->fh, &hdr);
2370 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002371 if (args->bitmask)
2372 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002373 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374}
2375
2376/*
2377 * FSINFO request
2378 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002379static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2380 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002383 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385
Chuck Lever9f06c712010-12-14 14:59:18 +00002386 encode_compound_hdr(xdr, req, &hdr);
2387 encode_sequence(xdr, &args->seq_args, &hdr);
2388 encode_putfh(xdr, args->fh, &hdr);
2389 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002390 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391}
2392
2393/*
2394 * a PATHCONF request
2395 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002396static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2397 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002400 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
Chuck Lever9f06c712010-12-14 14:59:18 +00002403 encode_compound_hdr(xdr, req, &hdr);
2404 encode_sequence(xdr, &args->seq_args, &hdr);
2405 encode_putfh(xdr, args->fh, &hdr);
2406 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002407 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002408 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409}
2410
2411/*
2412 * a STATFS request
2413 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002414static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2415 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002418 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
Chuck Lever9f06c712010-12-14 14:59:18 +00002421 encode_compound_hdr(xdr, req, &hdr);
2422 encode_sequence(xdr, &args->seq_args, &hdr);
2423 encode_putfh(xdr, args->fh, &hdr);
2424 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002425 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002426 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427}
2428
2429/*
2430 * GETATTR_BITMAP request
2431 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002432static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2433 struct xdr_stream *xdr,
2434 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002437 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439
Chuck Lever9f06c712010-12-14 14:59:18 +00002440 encode_compound_hdr(xdr, req, &hdr);
2441 encode_sequence(xdr, &args->seq_args, &hdr);
2442 encode_putfh(xdr, args->fhandle, &hdr);
2443 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002444 FATTR4_WORD0_LINK_SUPPORT|
2445 FATTR4_WORD0_SYMLINK_SUPPORT|
2446 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002447 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448}
2449
2450/*
2451 * a RENEW request
2452 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002453static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2454 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002457 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 };
2459
Chuck Lever9f06c712010-12-14 14:59:18 +00002460 encode_compound_hdr(xdr, req, &hdr);
2461 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002462 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463}
2464
2465/*
2466 * a SETCLIENTID request
2467 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002468static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2469 struct xdr_stream *xdr,
2470 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002473 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 };
2475
Chuck Lever9f06c712010-12-14 14:59:18 +00002476 encode_compound_hdr(xdr, req, &hdr);
2477 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002478 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479}
2480
2481/*
2482 * a SETCLIENTID_CONFIRM request
2483 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002484static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2485 struct xdr_stream *xdr,
2486 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002489 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 };
2491 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492
Chuck Lever9f06c712010-12-14 14:59:18 +00002493 encode_compound_hdr(xdr, req, &hdr);
2494 encode_setclientid_confirm(xdr, arg, &hdr);
2495 encode_putrootfh(xdr, &hdr);
2496 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002497 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498}
2499
2500/*
2501 * DELEGRETURN request
2502 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002503static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2504 struct xdr_stream *xdr,
2505 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002508 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510
Chuck Lever9f06c712010-12-14 14:59:18 +00002511 encode_compound_hdr(xdr, req, &hdr);
2512 encode_sequence(xdr, &args->seq_args, &hdr);
2513 encode_putfh(xdr, args->fhandle, &hdr);
2514 encode_delegreturn(xdr, args->stateid, &hdr);
2515 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002516 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517}
2518
2519/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002520 * Encode FS_LOCATIONS request
2521 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002522static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2523 struct xdr_stream *xdr,
2524 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002525{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002526 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002527 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002528 };
Benny Halevy28f56692009-04-01 09:22:09 -04002529 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002530
Chuck Lever9f06c712010-12-14 14:59:18 +00002531 encode_compound_hdr(xdr, req, &hdr);
2532 encode_sequence(xdr, &args->seq_args, &hdr);
2533 encode_putfh(xdr, args->dir_fh, &hdr);
2534 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002535 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002536 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002537
Benny Halevy28f56692009-04-01 09:22:09 -04002538 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002539 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002540 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002541}
2542
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002543/*
2544 * Encode SECINFO request
2545 */
2546static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2547 struct xdr_stream *xdr,
2548 struct nfs4_secinfo_arg *args)
2549{
2550 struct compound_hdr hdr = {
2551 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2552 };
2553
2554 encode_compound_hdr(xdr, req, &hdr);
2555 encode_sequence(xdr, &args->seq_args, &hdr);
2556 encode_putfh(xdr, args->dir_fh, &hdr);
2557 encode_secinfo(xdr, args->name, &hdr);
2558 encode_nops(&hdr);
2559}
2560
Benny Halevy99fe60d2009-04-01 09:22:29 -04002561#if defined(CONFIG_NFS_V4_1)
2562/*
2563 * EXCHANGE_ID request
2564 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002565static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2566 struct xdr_stream *xdr,
2567 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002568{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002569 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002570 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002571 };
2572
Chuck Lever9f06c712010-12-14 14:59:18 +00002573 encode_compound_hdr(xdr, req, &hdr);
2574 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002575 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002576}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002577
2578/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002579 * a CREATE_SESSION request
2580 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002581static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2582 struct xdr_stream *xdr,
2583 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002584{
Andy Adamsonfc931582009-04-01 09:22:31 -04002585 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002586 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002587 };
2588
Chuck Lever9f06c712010-12-14 14:59:18 +00002589 encode_compound_hdr(xdr, req, &hdr);
2590 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002591 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002592}
2593
2594/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002595 * a DESTROY_SESSION request
2596 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002597static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2598 struct xdr_stream *xdr,
2599 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002600{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002601 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002602 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002603 };
2604
Chuck Lever9f06c712010-12-14 14:59:18 +00002605 encode_compound_hdr(xdr, req, &hdr);
2606 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002607 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002608}
2609
2610/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002611 * a SEQUENCE request
2612 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002613static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2614 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002615{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002616 struct compound_hdr hdr = {
2617 .minorversion = nfs4_xdr_minorversion(args),
2618 };
2619
Chuck Lever9f06c712010-12-14 14:59:18 +00002620 encode_compound_hdr(xdr, req, &hdr);
2621 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002622 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002623}
2624
2625/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002626 * a GET_LEASE_TIME request
2627 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002628static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2629 struct xdr_stream *xdr,
2630 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002631{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002632 struct compound_hdr hdr = {
2633 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2634 };
2635 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2636
Chuck Lever9f06c712010-12-14 14:59:18 +00002637 encode_compound_hdr(xdr, req, &hdr);
2638 encode_sequence(xdr, &args->la_seq_args, &hdr);
2639 encode_putrootfh(xdr, &hdr);
2640 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002641 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002642}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002643
2644/*
2645 * a RECLAIM_COMPLETE request
2646 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002647static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2648 struct xdr_stream *xdr,
2649 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002650{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002651 struct compound_hdr hdr = {
2652 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2653 };
2654
Chuck Lever9f06c712010-12-14 14:59:18 +00002655 encode_compound_hdr(xdr, req, &hdr);
2656 encode_sequence(xdr, &args->seq_args, &hdr);
2657 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002658 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002659}
2660
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002661/*
2662 * Encode GETDEVICEINFO request
2663 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002664static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2665 struct xdr_stream *xdr,
2666 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002667{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002668 struct compound_hdr hdr = {
2669 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2670 };
2671
Chuck Lever9f06c712010-12-14 14:59:18 +00002672 encode_compound_hdr(xdr, req, &hdr);
2673 encode_sequence(xdr, &args->seq_args, &hdr);
2674 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002675
2676 /* set up reply kvec. Subtract notification bitmap max size (2)
2677 * so that notification bitmap is put in xdr_buf tail */
2678 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2679 args->pdev->pages, args->pdev->pgbase,
2680 args->pdev->pglen);
2681
2682 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002683}
2684
2685/*
2686 * Encode LAYOUTGET request
2687 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002688static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2689 struct xdr_stream *xdr,
2690 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002691{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002692 struct compound_hdr hdr = {
2693 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2694 };
2695
Chuck Lever9f06c712010-12-14 14:59:18 +00002696 encode_compound_hdr(xdr, req, &hdr);
2697 encode_sequence(xdr, &args->seq_args, &hdr);
2698 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2699 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002700
2701 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2702 args->layout.pages, 0, args->layout.pglen);
2703
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002704 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002705}
Andy Adamson863a3c62011-03-23 13:27:54 +00002706
2707/*
2708 * Encode LAYOUTCOMMIT request
2709 */
2710static int nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2711 struct xdr_stream *xdr,
2712 struct nfs4_layoutcommit_args *args)
2713{
2714 struct compound_hdr hdr = {
2715 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2716 };
2717
2718 encode_compound_hdr(xdr, req, &hdr);
2719 encode_sequence(xdr, &args->seq_args, &hdr);
2720 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2721 encode_layoutcommit(xdr, args, &hdr);
2722 encode_getfattr(xdr, args->bitmask, &hdr);
2723 encode_nops(&hdr);
2724 return 0;
2725}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002726#endif /* CONFIG_NFS_V4_1 */
2727
Benny Halevy686841b2009-08-14 17:19:48 +03002728static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2729{
2730 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2731 "Remaining buffer length is %tu words.\n",
2732 func, xdr->end - xdr->p);
2733}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734
Trond Myklebust683b57b2006-06-09 09:34:22 -04002735static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736{
Al Viro8687b632006-10-19 23:28:48 -07002737 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738
Benny Halevyc0eae662009-08-14 17:20:14 +03002739 p = xdr_inline_decode(xdr, 4);
2740 if (unlikely(!p))
2741 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002742 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002743 p = xdr_inline_decode(xdr, *len);
2744 if (unlikely(!p))
2745 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 *string = (char *)p;
2747 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002748out_overflow:
2749 print_overflow_msg(__func__, xdr);
2750 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751}
2752
2753static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2754{
Al Viro8687b632006-10-19 23:28:48 -07002755 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756
Benny Halevyc0eae662009-08-14 17:20:14 +03002757 p = xdr_inline_decode(xdr, 8);
2758 if (unlikely(!p))
2759 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002760 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002761 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002762
Benny Halevyc0eae662009-08-14 17:20:14 +03002763 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2764 if (unlikely(!p))
2765 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 hdr->tag = (char *)p;
2767 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002768 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002769 if (unlikely(hdr->nops < 1))
2770 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002772out_overflow:
2773 print_overflow_msg(__func__, xdr);
2774 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775}
2776
2777static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2778{
Al Viro8687b632006-10-19 23:28:48 -07002779 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 uint32_t opnum;
2781 int32_t nfserr;
2782
Benny Halevyc0eae662009-08-14 17:20:14 +03002783 p = xdr_inline_decode(xdr, 8);
2784 if (unlikely(!p))
2785 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002786 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002788 dprintk("nfs: Server returned operation"
2789 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 opnum, expected);
2791 return -EIO;
2792 }
Benny Halevycccddf42009-08-14 17:20:19 +03002793 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002795 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002797out_overflow:
2798 print_overflow_msg(__func__, xdr);
2799 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800}
2801
2802/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002803static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804{
Al Viro8687b632006-10-19 23:28:48 -07002805 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002806 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 char *str;
2808
Benny Halevyc0eae662009-08-14 17:20:14 +03002809 p = xdr_inline_decode(xdr, 12);
2810 if (likely(p))
2811 return decode_opaque_inline(xdr, &strlen, &str);
2812 print_overflow_msg(__func__, xdr);
2813 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814}
2815
2816static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2817{
Al Viro8687b632006-10-19 23:28:48 -07002818 uint32_t bmlen;
2819 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820
Benny Halevyc0eae662009-08-14 17:20:14 +03002821 p = xdr_inline_decode(xdr, 4);
2822 if (unlikely(!p))
2823 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002824 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825
2826 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002827 p = xdr_inline_decode(xdr, (bmlen << 2));
2828 if (unlikely(!p))
2829 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002831 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002833 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 }
2835 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002836out_overflow:
2837 print_overflow_msg(__func__, xdr);
2838 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839}
2840
Al Viro8687b632006-10-19 23:28:48 -07002841static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842{
Al Viro8687b632006-10-19 23:28:48 -07002843 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844
Benny Halevyc0eae662009-08-14 17:20:14 +03002845 p = xdr_inline_decode(xdr, 4);
2846 if (unlikely(!p))
2847 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002848 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 *savep = xdr->p;
2850 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002851out_overflow:
2852 print_overflow_msg(__func__, xdr);
2853 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854}
2855
2856static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2857{
2858 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04002859 int ret;
2860 ret = decode_attr_bitmap(xdr, bitmask);
2861 if (unlikely(ret < 0))
2862 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2864 } else
2865 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002866 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 return 0;
2868}
2869
2870static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2871{
Al Viro8687b632006-10-19 23:28:48 -07002872 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002873 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874
2875 *type = 0;
2876 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2877 return -EIO;
2878 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002879 p = xdr_inline_decode(xdr, 4);
2880 if (unlikely(!p))
2881 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002882 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002884 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 return -EIO;
2886 }
2887 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002888 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002890 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002891 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002892out_overflow:
2893 print_overflow_msg(__func__, xdr);
2894 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895}
2896
2897static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2898{
Al Viro8687b632006-10-19 23:28:48 -07002899 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002900 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901
2902 *change = 0;
2903 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2904 return -EIO;
2905 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002906 p = xdr_inline_decode(xdr, 8);
2907 if (unlikely(!p))
2908 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002909 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002911 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002913 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002915 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002916out_overflow:
2917 print_overflow_msg(__func__, xdr);
2918 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919}
2920
2921static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2922{
Al Viro8687b632006-10-19 23:28:48 -07002923 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002924 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925
2926 *size = 0;
2927 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2928 return -EIO;
2929 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002930 p = xdr_inline_decode(xdr, 8);
2931 if (unlikely(!p))
2932 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002933 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002935 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002937 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002938 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002939out_overflow:
2940 print_overflow_msg(__func__, xdr);
2941 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942}
2943
2944static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2945{
Al Viro8687b632006-10-19 23:28:48 -07002946 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947
2948 *res = 0;
2949 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2950 return -EIO;
2951 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002952 p = xdr_inline_decode(xdr, 4);
2953 if (unlikely(!p))
2954 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002955 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2957 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002958 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002960out_overflow:
2961 print_overflow_msg(__func__, xdr);
2962 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963}
2964
2965static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2966{
Al Viro8687b632006-10-19 23:28:48 -07002967 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968
2969 *res = 0;
2970 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2971 return -EIO;
2972 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002973 p = xdr_inline_decode(xdr, 4);
2974 if (unlikely(!p))
2975 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002976 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2978 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002979 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002981out_overflow:
2982 print_overflow_msg(__func__, xdr);
2983 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984}
2985
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002986static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987{
Al Viro8687b632006-10-19 23:28:48 -07002988 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002989 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990
2991 fsid->major = 0;
2992 fsid->minor = 0;
2993 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2994 return -EIO;
2995 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002996 p = xdr_inline_decode(xdr, 16);
2997 if (unlikely(!p))
2998 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03002999 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003000 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003002 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003004 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 (unsigned long long)fsid->major,
3006 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003007 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003008out_overflow:
3009 print_overflow_msg(__func__, xdr);
3010 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011}
3012
3013static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3014{
Al Viro8687b632006-10-19 23:28:48 -07003015 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016
3017 *res = 60;
3018 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3019 return -EIO;
3020 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003021 p = xdr_inline_decode(xdr, 4);
3022 if (unlikely(!p))
3023 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003024 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3026 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003027 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003029out_overflow:
3030 print_overflow_msg(__func__, xdr);
3031 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032}
3033
Bryan Schumakerae42c702010-10-21 16:33:17 -04003034static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
3035{
3036 __be32 *p;
3037
3038 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3039 return -EIO;
3040 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3041 p = xdr_inline_decode(xdr, 4);
3042 if (unlikely(!p))
3043 goto out_overflow;
3044 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Bryan Schumaker7ebb9312011-03-24 17:12:30 +00003045 return -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003046 }
3047 return 0;
3048out_overflow:
3049 print_overflow_msg(__func__, xdr);
3050 return -EIO;
3051}
3052
3053static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3054{
3055 __be32 *p;
3056 int len;
3057
Trond Myklebust7ad07352010-10-23 15:34:20 -04003058 if (fh != NULL)
3059 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003060
3061 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3062 return -EIO;
3063 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3064 p = xdr_inline_decode(xdr, 4);
3065 if (unlikely(!p))
3066 goto out_overflow;
3067 len = be32_to_cpup(p);
3068 if (len > NFS4_FHSIZE)
3069 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003070 p = xdr_inline_decode(xdr, len);
3071 if (unlikely(!p))
3072 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003073 if (fh != NULL) {
3074 memcpy(fh->data, p, len);
3075 fh->size = len;
3076 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003077 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3078 }
3079 return 0;
3080out_overflow:
3081 print_overflow_msg(__func__, xdr);
3082 return -EIO;
3083}
3084
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3086{
Al Viro8687b632006-10-19 23:28:48 -07003087 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088
3089 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3090 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3091 return -EIO;
3092 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003093 p = xdr_inline_decode(xdr, 4);
3094 if (unlikely(!p))
3095 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003096 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3098 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003099 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003101out_overflow:
3102 print_overflow_msg(__func__, xdr);
3103 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104}
3105
3106static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3107{
Al Viro8687b632006-10-19 23:28:48 -07003108 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003109 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110
3111 *fileid = 0;
3112 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3113 return -EIO;
3114 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003115 p = xdr_inline_decode(xdr, 8);
3116 if (unlikely(!p))
3117 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003118 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003120 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003122 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003123 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003124out_overflow:
3125 print_overflow_msg(__func__, xdr);
3126 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127}
3128
Manoj Naik99baf622006-06-09 09:34:24 -04003129static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3130{
Al Viro8687b632006-10-19 23:28:48 -07003131 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003132 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003133
3134 *fileid = 0;
3135 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3136 return -EIO;
3137 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003138 p = xdr_inline_decode(xdr, 8);
3139 if (unlikely(!p))
3140 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003141 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003142 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003143 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003144 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003145 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003146 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003147out_overflow:
3148 print_overflow_msg(__func__, xdr);
3149 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003150}
3151
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3153{
Al Viro8687b632006-10-19 23:28:48 -07003154 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 int status = 0;
3156
3157 *res = 0;
3158 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3159 return -EIO;
3160 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003161 p = xdr_inline_decode(xdr, 8);
3162 if (unlikely(!p))
3163 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003164 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3166 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003167 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003169out_overflow:
3170 print_overflow_msg(__func__, xdr);
3171 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172}
3173
3174static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3175{
Al Viro8687b632006-10-19 23:28:48 -07003176 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 int status = 0;
3178
3179 *res = 0;
3180 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3181 return -EIO;
3182 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003183 p = xdr_inline_decode(xdr, 8);
3184 if (unlikely(!p))
3185 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003186 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3188 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003189 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003191out_overflow:
3192 print_overflow_msg(__func__, xdr);
3193 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194}
3195
3196static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3197{
Al Viro8687b632006-10-19 23:28:48 -07003198 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 int status = 0;
3200
3201 *res = 0;
3202 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3203 return -EIO;
3204 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003205 p = xdr_inline_decode(xdr, 8);
3206 if (unlikely(!p))
3207 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003208 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3210 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003211 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003213out_overflow:
3214 print_overflow_msg(__func__, xdr);
3215 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216}
3217
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003218static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3219{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003220 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003221 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003222 int status = 0;
3223
Benny Halevyc0eae662009-08-14 17:20:14 +03003224 p = xdr_inline_decode(xdr, 4);
3225 if (unlikely(!p))
3226 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003227 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003228 if (n == 0)
3229 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003230 dprintk("path ");
3231 path->ncomponents = 0;
3232 while (path->ncomponents < n) {
3233 struct nfs4_string *component = &path->components[path->ncomponents];
3234 status = decode_opaque_inline(xdr, &component->len, &component->data);
3235 if (unlikely(status != 0))
3236 goto out_eio;
3237 if (path->ncomponents != n)
3238 dprintk("/");
3239 dprintk("%s", component->data);
3240 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3241 path->ncomponents++;
3242 else {
3243 dprintk("cannot parse %d components in path\n", n);
3244 goto out_eio;
3245 }
3246 }
3247out:
3248 dprintk("\n");
3249 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003250root_path:
3251/* a root pathname is sent as a zero component4 */
3252 path->ncomponents = 1;
3253 path->components[0].len=0;
3254 path->components[0].data=NULL;
3255 dprintk("path /\n");
3256 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003257out_eio:
3258 dprintk(" status %d", status);
3259 status = -EIO;
3260 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003261out_overflow:
3262 print_overflow_msg(__func__, xdr);
3263 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003264}
3265
3266static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003267{
3268 int n;
Al Viro8687b632006-10-19 23:28:48 -07003269 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003270 int status = -EIO;
3271
3272 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3273 goto out;
3274 status = 0;
3275 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3276 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003277 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003278 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003279 if (unlikely(status != 0))
3280 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003281 p = xdr_inline_decode(xdr, 4);
3282 if (unlikely(!p))
3283 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003284 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003285 if (n <= 0)
3286 goto out_eio;
3287 res->nlocations = 0;
3288 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003289 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003290 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003291
Benny Halevyc0eae662009-08-14 17:20:14 +03003292 p = xdr_inline_decode(xdr, 4);
3293 if (unlikely(!p))
3294 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003295 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003296
3297 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003298 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003299 while (loc->nservers < m) {
3300 struct nfs4_string *server = &loc->servers[loc->nservers];
3301 status = decode_opaque_inline(xdr, &server->len, &server->data);
3302 if (unlikely(status != 0))
3303 goto out_eio;
3304 dprintk("%s ", server->data);
3305 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3306 loc->nservers++;
3307 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003308 unsigned int i;
3309 dprintk("%s: using first %u of %u servers "
3310 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003311 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003312 NFS4_FS_LOCATION_MAXSERVERS,
3313 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003314 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003315 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003316 char *data;
3317 status = decode_opaque_inline(xdr, &len, &data);
3318 if (unlikely(status != 0))
3319 goto out_eio;
3320 }
3321 }
3322 }
3323 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003324 if (unlikely(status != 0))
3325 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003326 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003327 res->nlocations++;
3328 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003329 if (res->nlocations != 0)
3330 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003331out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003332 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003333 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003334out_overflow:
3335 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003336out_eio:
3337 status = -EIO;
3338 goto out;
3339}
3340
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3342{
Al Viro8687b632006-10-19 23:28:48 -07003343 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 int status = 0;
3345
3346 *res = 0;
3347 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3348 return -EIO;
3349 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003350 p = xdr_inline_decode(xdr, 8);
3351 if (unlikely(!p))
3352 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003353 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3355 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003356 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003358out_overflow:
3359 print_overflow_msg(__func__, xdr);
3360 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361}
3362
3363static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3364{
Al Viro8687b632006-10-19 23:28:48 -07003365 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 int status = 0;
3367
3368 *maxlink = 1;
3369 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3370 return -EIO;
3371 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003372 p = xdr_inline_decode(xdr, 4);
3373 if (unlikely(!p))
3374 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003375 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3377 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003378 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003380out_overflow:
3381 print_overflow_msg(__func__, xdr);
3382 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383}
3384
3385static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3386{
Al Viro8687b632006-10-19 23:28:48 -07003387 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 int status = 0;
3389
3390 *maxname = 1024;
3391 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3392 return -EIO;
3393 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003394 p = xdr_inline_decode(xdr, 4);
3395 if (unlikely(!p))
3396 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003397 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3399 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003400 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003402out_overflow:
3403 print_overflow_msg(__func__, xdr);
3404 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405}
3406
3407static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3408{
Al Viro8687b632006-10-19 23:28:48 -07003409 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 int status = 0;
3411
3412 *res = 1024;
3413 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3414 return -EIO;
3415 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3416 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003417 p = xdr_inline_decode(xdr, 8);
3418 if (unlikely(!p))
3419 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003420 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421 if (maxread > 0x7FFFFFFF)
3422 maxread = 0x7FFFFFFF;
3423 *res = (uint32_t)maxread;
3424 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3425 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003426 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003428out_overflow:
3429 print_overflow_msg(__func__, xdr);
3430 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431}
3432
3433static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3434{
Al Viro8687b632006-10-19 23:28:48 -07003435 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 int status = 0;
3437
3438 *res = 1024;
3439 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3440 return -EIO;
3441 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3442 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003443 p = xdr_inline_decode(xdr, 8);
3444 if (unlikely(!p))
3445 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003446 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447 if (maxwrite > 0x7FFFFFFF)
3448 maxwrite = 0x7FFFFFFF;
3449 *res = (uint32_t)maxwrite;
3450 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3451 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003452 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003454out_overflow:
3455 print_overflow_msg(__func__, xdr);
3456 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457}
3458
Trond Myklebustbca79472009-03-11 14:10:26 -04003459static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460{
Trond Myklebustbca79472009-03-11 14:10:26 -04003461 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003462 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003463 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464
3465 *mode = 0;
3466 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3467 return -EIO;
3468 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003469 p = xdr_inline_decode(xdr, 4);
3470 if (unlikely(!p))
3471 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003472 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003473 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003475 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003477 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003478 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003479out_overflow:
3480 print_overflow_msg(__func__, xdr);
3481 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482}
3483
3484static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3485{
Al Viro8687b632006-10-19 23:28:48 -07003486 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003487 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488
3489 *nlink = 1;
3490 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3491 return -EIO;
3492 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003493 p = xdr_inline_decode(xdr, 4);
3494 if (unlikely(!p))
3495 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003496 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003498 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003500 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003501 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003502out_overflow:
3503 print_overflow_msg(__func__, xdr);
3504 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505}
3506
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003507static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003508 const struct nfs_server *server, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509{
Al Viro8687b632006-10-19 23:28:48 -07003510 uint32_t len;
3511 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003512 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513
3514 *uid = -2;
3515 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3516 return -EIO;
3517 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003518 p = xdr_inline_decode(xdr, 4);
3519 if (unlikely(!p))
3520 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003521 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003522 p = xdr_inline_decode(xdr, len);
3523 if (unlikely(!p))
3524 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003525 if (!may_sleep) {
3526 /* do nothing */
3527 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003528 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003529 ret = NFS_ATTR_FATTR_OWNER;
3530 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003532 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003534 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003535 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3537 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003538 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003539 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003540out_overflow:
3541 print_overflow_msg(__func__, xdr);
3542 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543}
3544
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003545static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003546 const struct nfs_server *server, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547{
Al Viro8687b632006-10-19 23:28:48 -07003548 uint32_t len;
3549 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003550 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551
3552 *gid = -2;
3553 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3554 return -EIO;
3555 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003556 p = xdr_inline_decode(xdr, 4);
3557 if (unlikely(!p))
3558 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003559 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003560 p = xdr_inline_decode(xdr, len);
3561 if (unlikely(!p))
3562 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003563 if (!may_sleep) {
3564 /* do nothing */
3565 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003566 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003567 ret = NFS_ATTR_FATTR_GROUP;
3568 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003570 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003572 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003573 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3575 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003576 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003577 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003578out_overflow:
3579 print_overflow_msg(__func__, xdr);
3580 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581}
3582
3583static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3584{
Al Viro8687b632006-10-19 23:28:48 -07003585 uint32_t major = 0, minor = 0;
3586 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003587 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588
3589 *rdev = MKDEV(0,0);
3590 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3591 return -EIO;
3592 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3593 dev_t tmp;
3594
Benny Halevyc0eae662009-08-14 17:20:14 +03003595 p = xdr_inline_decode(xdr, 8);
3596 if (unlikely(!p))
3597 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003598 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003599 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 tmp = MKDEV(major, minor);
3601 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3602 *rdev = tmp;
3603 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003604 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003606 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003607 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003608out_overflow:
3609 print_overflow_msg(__func__, xdr);
3610 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611}
3612
3613static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3614{
Al Viro8687b632006-10-19 23:28:48 -07003615 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003616 int status = 0;
3617
3618 *res = 0;
3619 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3620 return -EIO;
3621 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003622 p = xdr_inline_decode(xdr, 8);
3623 if (unlikely(!p))
3624 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003625 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3627 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003628 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003630out_overflow:
3631 print_overflow_msg(__func__, xdr);
3632 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633}
3634
3635static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3636{
Al Viro8687b632006-10-19 23:28:48 -07003637 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638 int status = 0;
3639
3640 *res = 0;
3641 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3642 return -EIO;
3643 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003644 p = xdr_inline_decode(xdr, 8);
3645 if (unlikely(!p))
3646 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003647 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3649 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003650 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003652out_overflow:
3653 print_overflow_msg(__func__, xdr);
3654 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655}
3656
3657static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3658{
Al Viro8687b632006-10-19 23:28:48 -07003659 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660 int status = 0;
3661
3662 *res = 0;
3663 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3664 return -EIO;
3665 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003666 p = xdr_inline_decode(xdr, 8);
3667 if (unlikely(!p))
3668 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003669 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3671 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003672 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003674out_overflow:
3675 print_overflow_msg(__func__, xdr);
3676 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677}
3678
3679static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3680{
Al Viro8687b632006-10-19 23:28:48 -07003681 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003682 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683
3684 *used = 0;
3685 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3686 return -EIO;
3687 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003688 p = xdr_inline_decode(xdr, 8);
3689 if (unlikely(!p))
3690 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003691 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003693 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003695 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003697 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003698out_overflow:
3699 print_overflow_msg(__func__, xdr);
3700 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701}
3702
3703static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3704{
Al Viro8687b632006-10-19 23:28:48 -07003705 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706 uint64_t sec;
3707 uint32_t nsec;
3708
Benny Halevyc0eae662009-08-14 17:20:14 +03003709 p = xdr_inline_decode(xdr, 12);
3710 if (unlikely(!p))
3711 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003712 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003713 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 time->tv_sec = (time_t)sec;
3715 time->tv_nsec = (long)nsec;
3716 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003717out_overflow:
3718 print_overflow_msg(__func__, xdr);
3719 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720}
3721
3722static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3723{
3724 int status = 0;
3725
3726 time->tv_sec = 0;
3727 time->tv_nsec = 0;
3728 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3729 return -EIO;
3730 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3731 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003732 if (status == 0)
3733 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3735 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003736 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 return status;
3738}
3739
3740static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3741{
3742 int status = 0;
3743
3744 time->tv_sec = 0;
3745 time->tv_nsec = 0;
3746 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3747 return -EIO;
3748 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3749 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003750 if (status == 0)
3751 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3753 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003754 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 return status;
3756}
3757
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003758static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3759 struct timespec *time)
3760{
3761 int status = 0;
3762
3763 time->tv_sec = 0;
3764 time->tv_nsec = 0;
3765 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3766 return -EIO;
3767 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3768 status = decode_attr_time(xdr, time);
3769 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3770 }
3771 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3772 (long)time->tv_nsec);
3773 return status;
3774}
3775
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3777{
3778 int status = 0;
3779
3780 time->tv_sec = 0;
3781 time->tv_nsec = 0;
3782 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3783 return -EIO;
3784 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3785 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003786 if (status == 0)
3787 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3789 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003790 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791 return status;
3792}
3793
Al Viro8687b632006-10-19 23:28:48 -07003794static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795{
3796 unsigned int attrwords = XDR_QUADLEN(attrlen);
3797 unsigned int nwords = xdr->p - savep;
3798
3799 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003800 dprintk("%s: server returned incorrect attribute length: "
3801 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003802 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 attrwords << 2,
3804 (attrwords < nwords) ? '<' : '>',
3805 nwords << 2);
3806 return -EIO;
3807 }
3808 return 0;
3809}
3810
3811static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3812{
Al Viro8687b632006-10-19 23:28:48 -07003813 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814
Benny Halevyc0eae662009-08-14 17:20:14 +03003815 p = xdr_inline_decode(xdr, 20);
3816 if (unlikely(!p))
3817 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003818 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003819 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003820 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003822out_overflow:
3823 print_overflow_msg(__func__, xdr);
3824 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825}
3826
3827static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3828{
Al Viro8687b632006-10-19 23:28:48 -07003829 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 uint32_t supp, acc;
3831 int status;
3832
3833 status = decode_op_hdr(xdr, OP_ACCESS);
3834 if (status)
3835 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003836 p = xdr_inline_decode(xdr, 8);
3837 if (unlikely(!p))
3838 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003839 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003840 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 access->supported = supp;
3842 access->access = acc;
3843 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003844out_overflow:
3845 print_overflow_msg(__func__, xdr);
3846 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847}
3848
Benny Halevy07d30432009-08-14 17:19:52 +03003849static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850{
Al Viro8687b632006-10-19 23:28:48 -07003851 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003852
3853 p = xdr_inline_decode(xdr, len);
3854 if (likely(p)) {
3855 memcpy(buf, p, len);
3856 return 0;
3857 }
3858 print_overflow_msg(__func__, xdr);
3859 return -EIO;
3860}
3861
3862static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3863{
3864 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865}
3866
3867static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3868{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 int status;
3870
3871 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003872 if (status != -EIO)
3873 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003874 if (!status)
3875 status = decode_stateid(xdr, &res->stateid);
3876 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877}
3878
Benny Halevydb942bb2009-08-14 17:19:56 +03003879static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3880{
3881 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882}
3883
3884static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3885{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886 int status;
3887
3888 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003889 if (!status)
3890 status = decode_verifier(xdr, res->verf->verifier);
3891 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892}
3893
3894static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3895{
Al Viro8687b632006-10-19 23:28:48 -07003896 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 uint32_t bmlen;
3898 int status;
3899
3900 status = decode_op_hdr(xdr, OP_CREATE);
3901 if (status)
3902 return status;
3903 if ((status = decode_change_info(xdr, cinfo)))
3904 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003905 p = xdr_inline_decode(xdr, 4);
3906 if (unlikely(!p))
3907 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003908 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003909 p = xdr_inline_decode(xdr, bmlen << 2);
3910 if (likely(p))
3911 return 0;
3912out_overflow:
3913 print_overflow_msg(__func__, xdr);
3914 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915}
3916
3917static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3918{
Al Viro8687b632006-10-19 23:28:48 -07003919 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003920 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 int status;
3922
3923 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3924 goto xdr_error;
3925 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3926 goto xdr_error;
3927 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3928 goto xdr_error;
3929 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3930 goto xdr_error;
3931 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3932 goto xdr_error;
3933 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3934 goto xdr_error;
3935 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3936 goto xdr_error;
3937 status = verify_attr_len(xdr, savep, attrlen);
3938xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003939 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940 return status;
3941}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003942
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3944{
Al Viro8687b632006-10-19 23:28:48 -07003945 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003946 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003948
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3950 goto xdr_error;
3951 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3952 goto xdr_error;
3953 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3954 goto xdr_error;
3955
3956 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3957 goto xdr_error;
3958 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3959 goto xdr_error;
3960 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3961 goto xdr_error;
3962 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3963 goto xdr_error;
3964 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3965 goto xdr_error;
3966 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3967 goto xdr_error;
3968
3969 status = verify_attr_len(xdr, savep, attrlen);
3970xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003971 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 return status;
3973}
3974
3975static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3976{
Al Viro8687b632006-10-19 23:28:48 -07003977 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003978 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003980
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3982 goto xdr_error;
3983 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3984 goto xdr_error;
3985 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3986 goto xdr_error;
3987
3988 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3989 goto xdr_error;
3990 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3991 goto xdr_error;
3992
3993 status = verify_attr_len(xdr, savep, attrlen);
3994xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003995 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 return status;
3997}
3998
Bryan Schumakerae42c702010-10-21 16:33:17 -04003999static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4000 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004001 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002{
Trond Myklebustbca79472009-03-11 14:10:26 -04004003 int status;
4004 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04004005 uint64_t fileid;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004006 uint32_t type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004008 status = decode_attr_type(xdr, bitmap, &type);
4009 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004011 fattr->mode = 0;
4012 if (status != 0) {
4013 fattr->mode |= nfs_type2fmt[type];
4014 fattr->valid |= status;
4015 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004017 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4018 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004020 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004021
4022 status = decode_attr_size(xdr, bitmap, &fattr->size);
4023 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004025 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004026
4027 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4028 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004030 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004031
Bryan Schumakerae42c702010-10-21 16:33:17 -04004032 status = decode_attr_error(xdr, bitmap);
Bryan Schumaker7ebb9312011-03-24 17:12:30 +00004033 if (status == -NFS4ERR_WRONGSEC) {
4034 nfs_fixup_secinfo_attributes(fattr, fh);
4035 status = 0;
4036 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04004037 if (status < 0)
4038 goto xdr_error;
4039
4040 status = decode_attr_filehandle(xdr, bitmap, fh);
4041 if (status < 0)
4042 goto xdr_error;
4043
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004044 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4045 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004047 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004048
4049 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04004050 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004051 fattr));
4052 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004053 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004054 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004055
4056 status = decode_attr_mode(xdr, bitmap, &fmode);
4057 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004059 if (status != 0) {
4060 fattr->mode |= fmode;
4061 fattr->valid |= status;
4062 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004063
4064 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4065 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004067 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004068
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004069 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004070 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004072 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004073
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004074 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004075 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004077 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004078
4079 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4080 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004082 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004083
4084 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4085 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004087 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004088
4089 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4090 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004092 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004093
4094 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4095 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004097 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004098
4099 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4100 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004102 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004103
4104 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
4105 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004106 goto xdr_error;
Trond Myklebust3201f3d2010-10-23 15:43:10 -04004107 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04004108 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04004109 fattr->valid |= status;
4110 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004111
Bryan Schumakerae42c702010-10-21 16:33:17 -04004112xdr_error:
4113 dprintk("%s: xdr returned %d\n", __func__, -status);
4114 return status;
4115}
4116
4117static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4118 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4119{
4120 __be32 *savep;
4121 uint32_t attrlen,
4122 bitmap[2] = {0};
4123 int status;
4124
4125 status = decode_op_hdr(xdr, OP_GETATTR);
4126 if (status < 0)
4127 goto xdr_error;
4128
4129 status = decode_attr_bitmap(xdr, bitmap);
4130 if (status < 0)
4131 goto xdr_error;
4132
4133 status = decode_attr_length(xdr, &attrlen, &savep);
4134 if (status < 0)
4135 goto xdr_error;
4136
4137 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4138 if (status < 0)
4139 goto xdr_error;
4140
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004141 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004143 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144 return status;
4145}
4146
Bryan Schumakerae42c702010-10-21 16:33:17 -04004147static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4148 const struct nfs_server *server, int may_sleep)
4149{
4150 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4151}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152
Andy Adamson504913f2010-10-20 00:17:57 -04004153/*
4154 * Decode potentially multiple layout types. Currently we only support
4155 * one layout driver per file system.
4156 */
4157static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4158 uint32_t *layouttype)
4159{
4160 uint32_t *p;
4161 int num;
4162
4163 p = xdr_inline_decode(xdr, 4);
4164 if (unlikely(!p))
4165 goto out_overflow;
4166 num = be32_to_cpup(p);
4167
4168 /* pNFS is not supported by the underlying file system */
4169 if (num == 0) {
4170 *layouttype = 0;
4171 return 0;
4172 }
4173 if (num > 1)
4174 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4175 "per filesystem not supported\n", __func__);
4176
4177 /* Decode and set first layout type, move xdr->p past unused types */
4178 p = xdr_inline_decode(xdr, num * 4);
4179 if (unlikely(!p))
4180 goto out_overflow;
4181 *layouttype = be32_to_cpup(p);
4182 return 0;
4183out_overflow:
4184 print_overflow_msg(__func__, xdr);
4185 return -EIO;
4186}
4187
4188/*
4189 * The type of file system exported.
4190 * Note we must ensure that layouttype is set in any non-error case.
4191 */
4192static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4193 uint32_t *layouttype)
4194{
4195 int status = 0;
4196
4197 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4198 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4199 return -EIO;
4200 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4201 status = decode_first_pnfs_layout_type(xdr, layouttype);
4202 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4203 } else
4204 *layouttype = 0;
4205 return status;
4206}
4207
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4209{
Al Viro8687b632006-10-19 23:28:48 -07004210 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211 uint32_t attrlen, bitmap[2];
4212 int status;
4213
4214 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4215 goto xdr_error;
4216 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4217 goto xdr_error;
4218 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4219 goto xdr_error;
4220
4221 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4222
4223 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4224 goto xdr_error;
4225 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4226 goto xdr_error;
4227 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4228 goto xdr_error;
4229 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4230 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4231 goto xdr_error;
4232 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004233 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4234 if (status != 0)
4235 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004236 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4237 if (status != 0)
4238 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004239
4240 status = verify_attr_len(xdr, savep, attrlen);
4241xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004242 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243 return status;
4244}
4245
4246static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4247{
Al Viro8687b632006-10-19 23:28:48 -07004248 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249 uint32_t len;
4250 int status;
4251
Trond Myklebust99367812007-07-17 21:52:41 -04004252 /* Zero handle first to allow comparisons */
4253 memset(fh, 0, sizeof(*fh));
4254
Linus Torvalds1da177e2005-04-16 15:20:36 -07004255 status = decode_op_hdr(xdr, OP_GETFH);
4256 if (status)
4257 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258
Benny Halevyc0eae662009-08-14 17:20:14 +03004259 p = xdr_inline_decode(xdr, 4);
4260 if (unlikely(!p))
4261 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004262 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 if (len > NFS4_FHSIZE)
4264 return -EIO;
4265 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004266 p = xdr_inline_decode(xdr, len);
4267 if (unlikely(!p))
4268 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004269 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004271out_overflow:
4272 print_overflow_msg(__func__, xdr);
4273 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274}
4275
4276static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4277{
4278 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004279
Linus Torvalds1da177e2005-04-16 15:20:36 -07004280 status = decode_op_hdr(xdr, OP_LINK);
4281 if (status)
4282 return status;
4283 return decode_change_info(xdr, cinfo);
4284}
4285
4286/*
4287 * We create the owner, so we know a proper owner.id length is 4.
4288 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004289static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004290{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004291 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004292 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004293 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004295 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004296 if (unlikely(!p))
4297 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004298 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004299 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004300 type = be32_to_cpup(p++); /* 4 byte read */
4301 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004302 fl->fl_start = (loff_t)offset;
4303 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4304 if (length == ~(uint64_t)0)
4305 fl->fl_end = OFFSET_MAX;
4306 fl->fl_type = F_WRLCK;
4307 if (type & 1)
4308 fl->fl_type = F_RDLCK;
4309 fl->fl_pid = 0;
4310 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004311 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4312 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4313 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004314 if (likely(p))
4315 return -NFS4ERR_DENIED;
4316out_overflow:
4317 print_overflow_msg(__func__, xdr);
4318 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319}
4320
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004321static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 int status;
4324
4325 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004326 if (status == -EIO)
4327 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004329 status = decode_stateid(xdr, &res->stateid);
4330 if (unlikely(status))
4331 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004333 status = decode_lock_denied(xdr, NULL);
4334 if (res->open_seqid != NULL)
4335 nfs_increment_open_seqid(status, res->open_seqid);
4336 nfs_increment_lock_seqid(status, res->lock_seqid);
4337out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338 return status;
4339}
4340
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004341static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342{
4343 int status;
4344 status = decode_op_hdr(xdr, OP_LOCKT);
4345 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004346 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347 return status;
4348}
4349
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004350static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 int status;
4353
4354 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004355 if (status != -EIO)
4356 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004357 if (status == 0)
4358 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359 return status;
4360}
4361
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004362static int decode_release_lockowner(struct xdr_stream *xdr)
4363{
4364 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4365}
4366
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367static int decode_lookup(struct xdr_stream *xdr)
4368{
4369 return decode_op_hdr(xdr, OP_LOOKUP);
4370}
4371
4372/* This is too sick! */
4373static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4374{
Andy Adamson05d564f2008-12-23 16:06:15 -05004375 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376 uint32_t limit_type, nblocks, blocksize;
4377
Benny Halevyc0eae662009-08-14 17:20:14 +03004378 p = xdr_inline_decode(xdr, 12);
4379 if (unlikely(!p))
4380 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004381 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004383 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004384 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004385 break;
4386 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004387 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004388 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004389 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390 }
4391 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004392out_overflow:
4393 print_overflow_msg(__func__, xdr);
4394 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395}
4396
4397static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4398{
Andy Adamson05d564f2008-12-23 16:06:15 -05004399 __be32 *p;
4400 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004401 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402
Benny Halevyc0eae662009-08-14 17:20:14 +03004403 p = xdr_inline_decode(xdr, 4);
4404 if (unlikely(!p))
4405 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004406 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4408 res->delegation_type = 0;
4409 return 0;
4410 }
Benny Halevy07d30432009-08-14 17:19:52 +03004411 status = decode_stateid(xdr, &res->delegation);
4412 if (unlikely(status))
4413 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004414 p = xdr_inline_decode(xdr, 4);
4415 if (unlikely(!p))
4416 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004417 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004418
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004420 case NFS4_OPEN_DELEGATE_READ:
4421 res->delegation_type = FMODE_READ;
4422 break;
4423 case NFS4_OPEN_DELEGATE_WRITE:
4424 res->delegation_type = FMODE_WRITE|FMODE_READ;
4425 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426 return -EIO;
4427 }
David Howells7539bba2006-08-22 20:06:09 -04004428 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004429out_overflow:
4430 print_overflow_msg(__func__, xdr);
4431 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004432}
4433
4434static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4435{
Andy Adamson05d564f2008-12-23 16:06:15 -05004436 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004437 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004438 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004439
Andy Adamson05d564f2008-12-23 16:06:15 -05004440 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004441 if (status != -EIO)
4442 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004443 if (!status)
4444 status = decode_stateid(xdr, &res->stateid);
4445 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004446 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004447
Andy Adamson05d564f2008-12-23 16:06:15 -05004448 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449
Benny Halevyc0eae662009-08-14 17:20:14 +03004450 p = xdr_inline_decode(xdr, 8);
4451 if (unlikely(!p))
4452 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004453 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004454 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004455 if (bmlen > 10)
4456 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004457
Benny Halevyc0eae662009-08-14 17:20:14 +03004458 p = xdr_inline_decode(xdr, bmlen << 2);
4459 if (unlikely(!p))
4460 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004461 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4462 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004463 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004464 for (; i < NFS4_BITMAP_SIZE; i++)
4465 res->attrset[i] = 0;
4466
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467 return decode_delegation(xdr, res);
4468xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004469 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004471out_overflow:
4472 print_overflow_msg(__func__, xdr);
4473 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004474}
4475
4476static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4477{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 int status;
4479
Andy Adamson05d564f2008-12-23 16:06:15 -05004480 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004481 if (status != -EIO)
4482 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004483 if (!status)
4484 status = decode_stateid(xdr, &res->stateid);
4485 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486}
4487
4488static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4489{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490 int status;
4491
4492 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004493 if (status != -EIO)
4494 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004495 if (!status)
4496 status = decode_stateid(xdr, &res->stateid);
4497 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004498}
4499
4500static int decode_putfh(struct xdr_stream *xdr)
4501{
4502 return decode_op_hdr(xdr, OP_PUTFH);
4503}
4504
4505static int decode_putrootfh(struct xdr_stream *xdr)
4506{
4507 return decode_op_hdr(xdr, OP_PUTROOTFH);
4508}
4509
4510static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4511{
4512 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004513 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004514 uint32_t count, eof, recvd, hdrlen;
4515 int status;
4516
4517 status = decode_op_hdr(xdr, OP_READ);
4518 if (status)
4519 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004520 p = xdr_inline_decode(xdr, 8);
4521 if (unlikely(!p))
4522 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004523 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004524 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004525 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004526 recvd = req->rq_rcv_buf.len - hdrlen;
4527 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004528 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529 "count %u > recvd %u\n", count, recvd);
4530 count = recvd;
4531 eof = 0;
4532 }
4533 xdr_read_pages(xdr, count);
4534 res->eof = eof;
4535 res->count = count;
4536 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004537out_overflow:
4538 print_overflow_msg(__func__, xdr);
4539 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004540}
4541
4542static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4543{
4544 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004546 size_t hdrlen;
4547 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004548 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549
4550 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004551 if (!status)
4552 status = decode_verifier(xdr, readdir->verifier.data);
4553 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004554 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004555 dprintk("%s: verifier = %08x:%08x\n",
4556 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004557 ((u32 *)readdir->verifier.data)[0],
4558 ((u32 *)readdir->verifier.data)[1]);
4559
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560
Benny Halevydb942bb2009-08-14 17:19:56 +03004561 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562 recvd = rcvbuf->len - hdrlen;
4563 if (pglen > recvd)
4564 pglen = recvd;
4565 xdr_read_pages(xdr, pglen);
4566
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004567
Trond Myklebustac396122010-11-15 20:26:22 -05004568 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004569}
4570
4571static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4572{
4573 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4574 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004575 size_t hdrlen;
4576 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004577 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004578 int status;
4579
4580 status = decode_op_hdr(xdr, OP_READLINK);
4581 if (status)
4582 return status;
4583
4584 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004585 p = xdr_inline_decode(xdr, 4);
4586 if (unlikely(!p))
4587 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004588 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004589 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004590 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591 return -ENAMETOOLONG;
4592 }
4593 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4594 recvd = req->rq_rcv_buf.len - hdrlen;
4595 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004596 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004597 "count %u > recvd %u\n", len, recvd);
4598 return -EIO;
4599 }
4600 xdr_read_pages(xdr, len);
4601 /*
4602 * The XDR encode routine has set things up so that
4603 * the link text will be copied directly into the
4604 * buffer. We just have to do overflow-checking,
4605 * and and null-terminate the text (the VFS expects
4606 * null-termination).
4607 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004608 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004609 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004610out_overflow:
4611 print_overflow_msg(__func__, xdr);
4612 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613}
4614
4615static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4616{
4617 int status;
4618
4619 status = decode_op_hdr(xdr, OP_REMOVE);
4620 if (status)
4621 goto out;
4622 status = decode_change_info(xdr, cinfo);
4623out:
4624 return status;
4625}
4626
4627static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4628 struct nfs4_change_info *new_cinfo)
4629{
4630 int status;
4631
4632 status = decode_op_hdr(xdr, OP_RENAME);
4633 if (status)
4634 goto out;
4635 if ((status = decode_change_info(xdr, old_cinfo)))
4636 goto out;
4637 status = decode_change_info(xdr, new_cinfo);
4638out:
4639 return status;
4640}
4641
4642static int decode_renew(struct xdr_stream *xdr)
4643{
4644 return decode_op_hdr(xdr, OP_RENEW);
4645}
4646
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004647static int
4648decode_restorefh(struct xdr_stream *xdr)
4649{
4650 return decode_op_hdr(xdr, OP_RESTOREFH);
4651}
4652
J. Bruce Fields029d1052005-06-22 17:16:22 +00004653static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4654 size_t *acl_len)
4655{
Al Viro8687b632006-10-19 23:28:48 -07004656 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004657 uint32_t attrlen,
4658 bitmap[2] = {0};
4659 struct kvec *iov = req->rq_rcv_buf.head;
4660 int status;
4661
4662 *acl_len = 0;
4663 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4664 goto out;
4665 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4666 goto out;
4667 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4668 goto out;
4669
4670 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4671 return -EIO;
4672 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004673 size_t hdrlen;
4674 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004675
4676 /* We ignore &savep and don't do consistency checks on
4677 * the attr length. Let userspace figure it out.... */
4678 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4679 recvd = req->rq_rcv_buf.len - hdrlen;
4680 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004681 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004682 " acl reply: attrlen %u > recvd %u\n",
4683 attrlen, recvd);
4684 return -EINVAL;
4685 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004686 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004687 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004688 } else
4689 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004690
4691out:
4692 return status;
4693}
4694
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695static int
4696decode_savefh(struct xdr_stream *xdr)
4697{
4698 return decode_op_hdr(xdr, OP_SAVEFH);
4699}
4700
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004701static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004702{
Al Viro8687b632006-10-19 23:28:48 -07004703 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004704 uint32_t bmlen;
4705 int status;
4706
Linus Torvalds1da177e2005-04-16 15:20:36 -07004707 status = decode_op_hdr(xdr, OP_SETATTR);
4708 if (status)
4709 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004710 p = xdr_inline_decode(xdr, 4);
4711 if (unlikely(!p))
4712 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004713 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004714 p = xdr_inline_decode(xdr, bmlen << 2);
4715 if (likely(p))
4716 return 0;
4717out_overflow:
4718 print_overflow_msg(__func__, xdr);
4719 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720}
4721
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004722static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723{
Al Viro8687b632006-10-19 23:28:48 -07004724 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725 uint32_t opnum;
4726 int32_t nfserr;
4727
Benny Halevyc0eae662009-08-14 17:20:14 +03004728 p = xdr_inline_decode(xdr, 8);
4729 if (unlikely(!p))
4730 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004731 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004733 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004734 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 return -EIO;
4736 }
Benny Halevycccddf42009-08-14 17:20:19 +03004737 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004738 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004739 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4740 if (unlikely(!p))
4741 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004742 p = xdr_decode_hyper(p, &res->clientid);
4743 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744 } else if (nfserr == NFSERR_CLID_INUSE) {
4745 uint32_t len;
4746
4747 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004748 p = xdr_inline_decode(xdr, 4);
4749 if (unlikely(!p))
4750 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004751 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004752 p = xdr_inline_decode(xdr, len);
4753 if (unlikely(!p))
4754 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755
4756 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004757 p = xdr_inline_decode(xdr, 4);
4758 if (unlikely(!p))
4759 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004760 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004761 p = xdr_inline_decode(xdr, len);
4762 if (unlikely(!p))
4763 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764 return -NFSERR_CLID_INUSE;
4765 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004766 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767
4768 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004769out_overflow:
4770 print_overflow_msg(__func__, xdr);
4771 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772}
4773
4774static int decode_setclientid_confirm(struct xdr_stream *xdr)
4775{
4776 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4777}
4778
4779static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4780{
Al Viro8687b632006-10-19 23:28:48 -07004781 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782 int status;
4783
4784 status = decode_op_hdr(xdr, OP_WRITE);
4785 if (status)
4786 return status;
4787
Benny Halevyc0eae662009-08-14 17:20:14 +03004788 p = xdr_inline_decode(xdr, 16);
4789 if (unlikely(!p))
4790 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004791 res->count = be32_to_cpup(p++);
4792 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004793 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004795out_overflow:
4796 print_overflow_msg(__func__, xdr);
4797 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798}
4799
4800static int decode_delegreturn(struct xdr_stream *xdr)
4801{
4802 return decode_op_hdr(xdr, OP_DELEGRETURN);
4803}
4804
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004805static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
4806{
4807 __be32 *p;
4808
4809 p = xdr_inline_decode(xdr, 4);
4810 if (unlikely(!p))
4811 goto out_overflow;
4812 flavor->gss.sec_oid4.len = be32_to_cpup(p);
4813 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
4814 goto out_err;
4815
4816 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
4817 if (unlikely(!p))
4818 goto out_overflow;
4819 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
4820
4821 p = xdr_inline_decode(xdr, 8);
4822 if (unlikely(!p))
4823 goto out_overflow;
4824 flavor->gss.qop4 = be32_to_cpup(p++);
4825 flavor->gss.service = be32_to_cpup(p);
4826
4827 return 0;
4828
4829out_overflow:
4830 print_overflow_msg(__func__, xdr);
4831 return -EIO;
4832out_err:
4833 return -EINVAL;
4834}
4835
4836static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
4837{
4838 struct nfs4_secinfo_flavor *sec_flavor;
4839 int status;
4840 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004841 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004842
4843 status = decode_op_hdr(xdr, OP_SECINFO);
4844 p = xdr_inline_decode(xdr, 4);
4845 if (unlikely(!p))
4846 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004847
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004848 res->flavors->num_flavors = 0;
4849 num_flavors = be32_to_cpup(p);
4850
4851 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004852 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004853 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004854 break;
4855
4856 p = xdr_inline_decode(xdr, 4);
4857 if (unlikely(!p))
4858 goto out_overflow;
4859 sec_flavor->flavor = be32_to_cpup(p);
4860
4861 if (sec_flavor->flavor == RPC_AUTH_GSS) {
4862 if (decode_secinfo_gss(xdr, sec_flavor))
4863 break;
4864 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004865 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004866 }
4867
4868 return 0;
4869
4870out_overflow:
4871 print_overflow_msg(__func__, xdr);
4872 return -EIO;
4873}
4874
Benny Halevy99fe60d2009-04-01 09:22:29 -04004875#if defined(CONFIG_NFS_V4_1)
4876static int decode_exchange_id(struct xdr_stream *xdr,
4877 struct nfs41_exchange_id_res *res)
4878{
4879 __be32 *p;
4880 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004881 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004882 int status;
4883 struct nfs_client *clp = res->client;
4884
4885 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4886 if (status)
4887 return status;
4888
Benny Halevyc0eae662009-08-14 17:20:14 +03004889 p = xdr_inline_decode(xdr, 8);
4890 if (unlikely(!p))
4891 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05004892 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004893 p = xdr_inline_decode(xdr, 12);
4894 if (unlikely(!p))
4895 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004896 clp->cl_seqid = be32_to_cpup(p++);
4897 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004898
4899 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004900 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004901 if (dummy != SP4_NONE)
4902 return -EIO;
4903
4904 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004905 p = xdr_inline_decode(xdr, 8);
4906 if (unlikely(!p))
4907 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004908
4909 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004910 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4911 if (unlikely(status))
4912 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004913
4914 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004915 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4916 if (unlikely(status))
4917 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004918
4919 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004920 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4921 if (unlikely(status))
4922 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004923
4924 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004925out_overflow:
4926 print_overflow_msg(__func__, xdr);
4927 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004928}
Andy Adamsonfc931582009-04-01 09:22:31 -04004929
4930static int decode_chan_attrs(struct xdr_stream *xdr,
4931 struct nfs4_channel_attrs *attrs)
4932{
4933 __be32 *p;
4934 u32 nr_attrs;
4935
Benny Halevyc0eae662009-08-14 17:20:14 +03004936 p = xdr_inline_decode(xdr, 28);
4937 if (unlikely(!p))
4938 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004939 attrs->headerpadsz = be32_to_cpup(p++);
4940 attrs->max_rqst_sz = be32_to_cpup(p++);
4941 attrs->max_resp_sz = be32_to_cpup(p++);
4942 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4943 attrs->max_ops = be32_to_cpup(p++);
4944 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004945 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004946 if (unlikely(nr_attrs > 1)) {
4947 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4948 __func__, nr_attrs);
4949 return -EINVAL;
4950 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004951 if (nr_attrs == 1) {
4952 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4953 if (unlikely(!p))
4954 goto out_overflow;
4955 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004956 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004957out_overflow:
4958 print_overflow_msg(__func__, xdr);
4959 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004960}
4961
Benny Halevye78291e2009-08-14 17:20:00 +03004962static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4963{
4964 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004965}
4966
4967static int decode_create_session(struct xdr_stream *xdr,
4968 struct nfs41_create_session_res *res)
4969{
4970 __be32 *p;
4971 int status;
4972 struct nfs_client *clp = res->client;
4973 struct nfs4_session *session = clp->cl_session;
4974
4975 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004976 if (!status)
4977 status = decode_sessionid(xdr, &session->sess_id);
4978 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004979 return status;
4980
Andy Adamsonfc931582009-04-01 09:22:31 -04004981 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004982 p = xdr_inline_decode(xdr, 8);
4983 if (unlikely(!p))
4984 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004985 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004986 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004987
4988 /* Channel attributes */
4989 status = decode_chan_attrs(xdr, &session->fc_attrs);
4990 if (!status)
4991 status = decode_chan_attrs(xdr, &session->bc_attrs);
4992 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004993out_overflow:
4994 print_overflow_msg(__func__, xdr);
4995 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004996}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004997
4998static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4999{
5000 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5001}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005002
5003static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5004{
5005 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5006}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005007#endif /* CONFIG_NFS_V4_1 */
5008
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005009static int decode_sequence(struct xdr_stream *xdr,
5010 struct nfs4_sequence_res *res,
5011 struct rpc_rqst *rqstp)
5012{
5013#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005014 struct nfs4_sessionid id;
5015 u32 dummy;
5016 int status;
5017 __be32 *p;
5018
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005019 if (!res->sr_session)
5020 return 0;
5021
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005022 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005023 if (!status)
5024 status = decode_sessionid(xdr, &id);
5025 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005026 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005027
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005028 /*
5029 * If the server returns different values for sessionID, slotID or
5030 * sequence number, the server is looney tunes.
5031 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005032 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005033
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005034 if (memcmp(id.data, res->sr_session->sess_id.data,
5035 NFS4_MAX_SESSIONID_LEN)) {
5036 dprintk("%s Invalid session id\n", __func__);
5037 goto out_err;
5038 }
Benny Halevye78291e2009-08-14 17:20:00 +03005039
Benny Halevyc0eae662009-08-14 17:20:14 +03005040 p = xdr_inline_decode(xdr, 20);
5041 if (unlikely(!p))
5042 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005043
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005044 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005045 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005046 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005047 dprintk("%s Invalid sequence number\n", __func__);
5048 goto out_err;
5049 }
5050 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005051 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005052 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005053 dprintk("%s Invalid slot id\n", __func__);
5054 goto out_err;
5055 }
5056 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005057 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005058 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005059 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005060 /* result flags */
5061 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005062 status = 0;
5063out_err:
5064 res->sr_status = status;
5065 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005066out_overflow:
5067 print_overflow_msg(__func__, xdr);
5068 status = -EIO;
5069 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005070#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005071 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005072#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005073}
5074
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005075#if defined(CONFIG_NFS_V4_1)
5076
5077static int decode_getdeviceinfo(struct xdr_stream *xdr,
5078 struct pnfs_device *pdev)
5079{
5080 __be32 *p;
5081 uint32_t len, type;
5082 int status;
5083
5084 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5085 if (status) {
5086 if (status == -ETOOSMALL) {
5087 p = xdr_inline_decode(xdr, 4);
5088 if (unlikely(!p))
5089 goto out_overflow;
5090 pdev->mincount = be32_to_cpup(p);
5091 dprintk("%s: Min count too small. mincnt = %u\n",
5092 __func__, pdev->mincount);
5093 }
5094 return status;
5095 }
5096
5097 p = xdr_inline_decode(xdr, 8);
5098 if (unlikely(!p))
5099 goto out_overflow;
5100 type = be32_to_cpup(p++);
5101 if (type != pdev->layout_type) {
5102 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5103 __func__, pdev->layout_type, type);
5104 return -EINVAL;
5105 }
5106 /*
5107 * Get the length of the opaque device_addr4. xdr_read_pages places
5108 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5109 * and places the remaining xdr data in xdr_buf->tail
5110 */
5111 pdev->mincount = be32_to_cpup(p);
5112 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5113
5114 /* Parse notification bitmap, verifying that it is zero. */
5115 p = xdr_inline_decode(xdr, 4);
5116 if (unlikely(!p))
5117 goto out_overflow;
5118 len = be32_to_cpup(p);
5119 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005120 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005121
5122 p = xdr_inline_decode(xdr, 4 * len);
5123 if (unlikely(!p))
5124 goto out_overflow;
5125 for (i = 0; i < len; i++, p++) {
5126 if (be32_to_cpup(p)) {
5127 dprintk("%s: notifications not supported\n",
5128 __func__);
5129 return -EIO;
5130 }
5131 }
5132 }
5133 return 0;
5134out_overflow:
5135 print_overflow_msg(__func__, xdr);
5136 return -EIO;
5137}
5138
5139static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5140 struct nfs4_layoutget_res *res)
5141{
5142 __be32 *p;
5143 int status;
5144 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005145 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5146 struct kvec *iov = rcvbuf->head;
5147 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005148
5149 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5150 if (status)
5151 return status;
5152 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5153 if (unlikely(!p))
5154 goto out_overflow;
5155 res->return_on_close = be32_to_cpup(p++);
5156 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5157 layout_count = be32_to_cpup(p);
5158 if (!layout_count) {
5159 dprintk("%s: server responded with empty layout array\n",
5160 __func__);
5161 return -EINVAL;
5162 }
5163
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005164 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005165 if (unlikely(!p))
5166 goto out_overflow;
5167 p = xdr_decode_hyper(p, &res->range.offset);
5168 p = xdr_decode_hyper(p, &res->range.length);
5169 res->range.iomode = be32_to_cpup(p++);
5170 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005171 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005172
5173 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5174 __func__,
5175 (unsigned long)res->range.offset,
5176 (unsigned long)res->range.length,
5177 res->range.iomode,
5178 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005179 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005180
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005181 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5182 recvd = req->rq_rcv_buf.len - hdrlen;
5183 if (res->layoutp->len > recvd) {
5184 dprintk("NFS: server cheating in layoutget reply: "
5185 "layout len %u > recvd %u\n",
5186 res->layoutp->len, recvd);
5187 return -EINVAL;
5188 }
5189
5190 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005191
5192 if (layout_count > 1) {
5193 /* We only handle a length one array at the moment. Any
5194 * further entries are just ignored. Note that this means
5195 * the client may see a response that is less than the
5196 * minimum it requested.
5197 */
5198 dprintk("%s: server responded with %d layouts, dropping tail\n",
5199 __func__, layout_count);
5200 }
5201
5202 return 0;
5203out_overflow:
5204 print_overflow_msg(__func__, xdr);
5205 return -EIO;
5206}
Andy Adamson863a3c62011-03-23 13:27:54 +00005207
5208static int decode_layoutcommit(struct xdr_stream *xdr,
5209 struct rpc_rqst *req,
5210 struct nfs4_layoutcommit_res *res)
5211{
5212 __be32 *p;
5213 __u32 sizechanged;
5214 int status;
5215
5216 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5217 if (status)
5218 return status;
5219
5220 p = xdr_inline_decode(xdr, 4);
5221 if (unlikely(!p))
5222 goto out_overflow;
5223 sizechanged = be32_to_cpup(p);
5224
5225 if (sizechanged) {
5226 /* throw away new size */
5227 p = xdr_inline_decode(xdr, 8);
5228 if (unlikely(!p))
5229 goto out_overflow;
5230 }
5231 return 0;
5232out_overflow:
5233 print_overflow_msg(__func__, xdr);
5234 return -EIO;
5235}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005236#endif /* CONFIG_NFS_V4_1 */
5237
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238/*
Benny Halevy49c25592008-12-23 16:06:16 -05005239 * END OF "GENERIC" DECODE ROUTINES.
5240 */
5241
5242/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005243 * Decode OPEN_DOWNGRADE response
5244 */
Chuck Leverbf269552010-12-14 14:59:29 +00005245static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5246 struct xdr_stream *xdr,
5247 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005248{
Andy Adamson05d564f2008-12-23 16:06:15 -05005249 struct compound_hdr hdr;
5250 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005251
Chuck Leverbf269552010-12-14 14:59:29 +00005252 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005253 if (status)
5254 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005255 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005256 if (status)
5257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005258 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005259 if (status)
5260 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005261 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005262 if (status != 0)
5263 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005264 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005265 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005267 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005268}
5269
5270/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271 * Decode ACCESS response
5272 */
Chuck Leverbf269552010-12-14 14:59:29 +00005273static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5274 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005275{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276 struct compound_hdr hdr;
5277 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005278
Chuck Leverbf269552010-12-14 14:59:29 +00005279 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005280 if (status)
5281 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005282 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005283 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005284 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005285 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005286 if (status != 0)
5287 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005288 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005289 if (status != 0)
5290 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005291 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005292 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005293out:
5294 return status;
5295}
5296
5297/*
5298 * Decode LOOKUP response
5299 */
Chuck Leverbf269552010-12-14 14:59:29 +00005300static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5301 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005303 struct compound_hdr hdr;
5304 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005305
Chuck Leverbf269552010-12-14 14:59:29 +00005306 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005307 if (status)
5308 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005309 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005310 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005311 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005312 status = decode_putfh(xdr);
5313 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005314 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005315 status = decode_lookup(xdr);
5316 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005317 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005318 status = decode_getfh(xdr, res->fh);
5319 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005320 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005321 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005322 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005323out:
5324 return status;
5325}
5326
5327/*
5328 * Decode LOOKUP_ROOT response
5329 */
Chuck Leverbf269552010-12-14 14:59:29 +00005330static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5331 struct xdr_stream *xdr,
5332 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005333{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005334 struct compound_hdr hdr;
5335 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005336
Chuck Leverbf269552010-12-14 14:59:29 +00005337 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005338 if (status)
5339 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005340 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005341 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005342 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005343 status = decode_putrootfh(xdr);
5344 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005345 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005346 status = decode_getfh(xdr, res->fh);
5347 if (status == 0)
5348 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005349 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005350out:
5351 return status;
5352}
5353
5354/*
5355 * Decode REMOVE response
5356 */
Chuck Leverbf269552010-12-14 14:59:29 +00005357static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5358 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005359{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005360 struct compound_hdr hdr;
5361 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005362
Chuck Leverbf269552010-12-14 14:59:29 +00005363 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005364 if (status)
5365 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005366 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005367 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005368 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005369 status = decode_putfh(xdr);
5370 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005371 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005372 status = decode_remove(xdr, &res->cinfo);
5373 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005374 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005375 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005376 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005377out:
5378 return status;
5379}
5380
5381/*
5382 * Decode RENAME response
5383 */
Chuck Leverbf269552010-12-14 14:59:29 +00005384static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5385 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005386{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005387 struct compound_hdr hdr;
5388 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005389
Chuck Leverbf269552010-12-14 14:59:29 +00005390 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005391 if (status)
5392 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005393 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005394 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005395 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005396 status = decode_putfh(xdr);
5397 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005398 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005399 status = decode_savefh(xdr);
5400 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005401 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005402 status = decode_putfh(xdr);
5403 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005404 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005405 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5406 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005407 goto out;
5408 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005409 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005410 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005411 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005412 status = decode_restorefh(xdr);
5413 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005414 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005415 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005416 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005417out:
5418 return status;
5419}
5420
5421/*
5422 * Decode LINK response
5423 */
Chuck Leverbf269552010-12-14 14:59:29 +00005424static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5425 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005426{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005427 struct compound_hdr hdr;
5428 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005429
Chuck Leverbf269552010-12-14 14:59:29 +00005430 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005431 if (status)
5432 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005433 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005434 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005435 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005436 status = decode_putfh(xdr);
5437 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005438 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005439 status = decode_savefh(xdr);
5440 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005441 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005442 status = decode_putfh(xdr);
5443 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005444 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005445 status = decode_link(xdr, &res->cinfo);
5446 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005447 goto out;
5448 /*
5449 * Note order: OP_LINK leaves the directory as the current
5450 * filehandle.
5451 */
Chuck Leverbf269552010-12-14 14:59:29 +00005452 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005453 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005454 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005455 status = decode_restorefh(xdr);
5456 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005457 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005458 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005459 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005460out:
5461 return status;
5462}
5463
5464/*
5465 * Decode CREATE response
5466 */
Chuck Leverbf269552010-12-14 14:59:29 +00005467static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5468 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005469{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005470 struct compound_hdr hdr;
5471 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005472
Chuck Leverbf269552010-12-14 14:59:29 +00005473 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005474 if (status)
5475 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005476 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005477 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005478 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005479 status = decode_putfh(xdr);
5480 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005481 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005482 status = decode_savefh(xdr);
5483 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005484 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005485 status = decode_create(xdr, &res->dir_cinfo);
5486 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005487 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005488 status = decode_getfh(xdr, res->fh);
5489 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005490 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005491 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005492 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005493 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005494 status = decode_restorefh(xdr);
5495 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005496 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005497 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005498 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005499out:
5500 return status;
5501}
5502
5503/*
5504 * Decode SYMLINK response
5505 */
Chuck Leverbf269552010-12-14 14:59:29 +00005506static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5507 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005508{
Chuck Leverbf269552010-12-14 14:59:29 +00005509 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005510}
5511
5512/*
5513 * Decode GETATTR response
5514 */
Chuck Leverbf269552010-12-14 14:59:29 +00005515static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5516 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005517{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005518 struct compound_hdr hdr;
5519 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005520
Chuck Leverbf269552010-12-14 14:59:29 +00005521 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005522 if (status)
5523 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005524 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005525 if (status)
5526 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005527 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005528 if (status)
5529 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005530 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005531 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532out:
5533 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005534}
5535
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005536/*
5537 * Encode an SETACL request
5538 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005539static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5540 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005541{
Andy Adamson05d564f2008-12-23 16:06:15 -05005542 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005543 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005544 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005545
Chuck Lever9f06c712010-12-14 14:59:18 +00005546 encode_compound_hdr(xdr, req, &hdr);
5547 encode_sequence(xdr, &args->seq_args, &hdr);
5548 encode_putfh(xdr, args->fh, &hdr);
5549 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005550 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005551}
Andy Adamson05d564f2008-12-23 16:06:15 -05005552
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005553/*
5554 * Decode SETACL response
5555 */
5556static int
Chuck Leverbf269552010-12-14 14:59:29 +00005557nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005558 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005559{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005560 struct compound_hdr hdr;
5561 int status;
5562
Chuck Leverbf269552010-12-14 14:59:29 +00005563 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005564 if (status)
5565 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005566 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005567 if (status)
5568 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005569 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005570 if (status)
5571 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005572 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005573out:
5574 return status;
5575}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005576
5577/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005578 * Decode GETACL response
5579 */
5580static int
Chuck Leverbf269552010-12-14 14:59:29 +00005581nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005582 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005583{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005584 struct compound_hdr hdr;
5585 int status;
5586
Chuck Leverbf269552010-12-14 14:59:29 +00005587 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005588 if (status)
5589 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005590 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005591 if (status)
5592 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005593 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005594 if (status)
5595 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005596 status = decode_getacl(xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005597
5598out:
5599 return status;
5600}
5601
5602/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005603 * Decode CLOSE response
5604 */
Chuck Leverbf269552010-12-14 14:59:29 +00005605static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5606 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005607{
Andy Adamson05d564f2008-12-23 16:06:15 -05005608 struct compound_hdr hdr;
5609 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005610
Chuck Leverbf269552010-12-14 14:59:29 +00005611 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005612 if (status)
5613 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005614 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005615 if (status)
5616 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005617 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005618 if (status)
5619 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005620 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005621 if (status != 0)
5622 goto out;
5623 /*
5624 * Note: Server may do delete on close for this file
5625 * in which case the getattr call will fail with
5626 * an ESTALE error. Shouldn't be a problem,
5627 * though, since fattr->valid will remain unset.
5628 */
Chuck Leverbf269552010-12-14 14:59:29 +00005629 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005630 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005631out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005632 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005633}
5634
5635/*
5636 * Decode OPEN response
5637 */
Chuck Leverbf269552010-12-14 14:59:29 +00005638static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5639 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005640{
Andy Adamson05d564f2008-12-23 16:06:15 -05005641 struct compound_hdr hdr;
5642 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005643
Chuck Leverbf269552010-12-14 14:59:29 +00005644 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005645 if (status)
5646 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005647 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005648 if (status)
5649 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005650 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005651 if (status)
5652 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005653 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005654 if (status)
5655 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005656 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005657 if (status)
5658 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005659 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005660 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005661 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005662 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005663 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005664 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005665 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005666 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005667 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005668out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005669 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005670}
5671
5672/*
5673 * Decode OPEN_CONFIRM response
5674 */
Chuck Leverbf269552010-12-14 14:59:29 +00005675static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5676 struct xdr_stream *xdr,
5677 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005678{
Andy Adamson05d564f2008-12-23 16:06:15 -05005679 struct compound_hdr hdr;
5680 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005681
Chuck Leverbf269552010-12-14 14:59:29 +00005682 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005683 if (status)
5684 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005685 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005686 if (status)
5687 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005688 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005689out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005690 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005691}
5692
5693/*
5694 * Decode OPEN response
5695 */
Chuck Leverbf269552010-12-14 14:59:29 +00005696static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5697 struct xdr_stream *xdr,
5698 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005699{
Andy Adamson05d564f2008-12-23 16:06:15 -05005700 struct compound_hdr hdr;
5701 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005702
Chuck Leverbf269552010-12-14 14:59:29 +00005703 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005704 if (status)
5705 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005706 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005707 if (status)
5708 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005709 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005710 if (status)
5711 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005712 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005713 if (status)
5714 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005715 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005716 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005717out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005718 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005719}
5720
5721/*
5722 * Decode SETATTR response
5723 */
Chuck Leverbf269552010-12-14 14:59:29 +00005724static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5725 struct xdr_stream *xdr,
5726 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005727{
Andy Adamson05d564f2008-12-23 16:06:15 -05005728 struct compound_hdr hdr;
5729 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005730
Chuck Leverbf269552010-12-14 14:59:29 +00005731 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005732 if (status)
5733 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005734 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005735 if (status)
5736 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005737 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005738 if (status)
5739 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005740 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005741 if (status)
5742 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005743 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005744 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005746 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005747}
5748
5749/*
5750 * Decode LOCK response
5751 */
Chuck Leverbf269552010-12-14 14:59:29 +00005752static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5753 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005754{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755 struct compound_hdr hdr;
5756 int status;
5757
Chuck Leverbf269552010-12-14 14:59:29 +00005758 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005759 if (status)
5760 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005761 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005762 if (status)
5763 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005764 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005765 if (status)
5766 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005767 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005768out:
5769 return status;
5770}
5771
5772/*
5773 * Decode LOCKT response
5774 */
Chuck Leverbf269552010-12-14 14:59:29 +00005775static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5776 struct nfs_lockt_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)
5783 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005784 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005785 if (status)
5786 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005787 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788 if (status)
5789 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005790 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005791out:
5792 return status;
5793}
5794
5795/*
5796 * Decode LOCKU response
5797 */
Chuck Leverbf269552010-12-14 14:59:29 +00005798static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5799 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005800{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005801 struct compound_hdr hdr;
5802 int status;
5803
Chuck Leverbf269552010-12-14 14:59:29 +00005804 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005805 if (status)
5806 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005807 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005808 if (status)
5809 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005810 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005811 if (status)
5812 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005813 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005814out:
5815 return status;
5816}
5817
Chuck Leverbf269552010-12-14 14:59:29 +00005818static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5819 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005820{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005821 struct compound_hdr hdr;
5822 int status;
5823
Chuck Leverbf269552010-12-14 14:59:29 +00005824 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005825 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005826 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005827 return status;
5828}
5829
Linus Torvalds1da177e2005-04-16 15:20:36 -07005830/*
5831 * Decode READLINK response
5832 */
Chuck Leverbf269552010-12-14 14:59:29 +00005833static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5834 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04005835 struct nfs4_readlink_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)
5842 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005843 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005844 if (status)
5845 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005846 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005847 if (status)
5848 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005849 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850out:
5851 return status;
5852}
5853
5854/*
5855 * Decode READDIR response
5856 */
Chuck Leverbf269552010-12-14 14:59:29 +00005857static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5858 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005859{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005860 struct compound_hdr hdr;
5861 int status;
5862
Chuck Leverbf269552010-12-14 14:59:29 +00005863 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005864 if (status)
5865 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005866 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005867 if (status)
5868 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005869 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005870 if (status)
5871 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005872 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005873out:
5874 return status;
5875}
5876
5877/*
5878 * Decode Read response
5879 */
Chuck Leverbf269552010-12-14 14:59:29 +00005880static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5881 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005882{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005883 struct compound_hdr hdr;
5884 int status;
5885
Chuck Leverbf269552010-12-14 14:59:29 +00005886 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005887 if (status)
5888 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005889 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005890 if (status)
5891 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005892 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005893 if (status)
5894 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005895 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005896 if (!status)
5897 status = res->count;
5898out:
5899 return status;
5900}
5901
5902/*
5903 * Decode WRITE response
5904 */
Chuck Leverbf269552010-12-14 14:59:29 +00005905static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5906 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005907{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005908 struct compound_hdr hdr;
5909 int status;
5910
Chuck Leverbf269552010-12-14 14:59:29 +00005911 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005912 if (status)
5913 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005914 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005915 if (status)
5916 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005917 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005918 if (status)
5919 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005920 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005921 if (status)
5922 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00005923 if (res->fattr)
5924 decode_getfattr(xdr, res->fattr, res->server,
5925 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005926 if (!status)
5927 status = res->count;
5928out:
5929 return status;
5930}
5931
5932/*
5933 * Decode COMMIT response
5934 */
Chuck Leverbf269552010-12-14 14:59:29 +00005935static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5936 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005937{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005938 struct compound_hdr hdr;
5939 int status;
5940
Chuck Leverbf269552010-12-14 14:59:29 +00005941 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005942 if (status)
5943 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005944 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005945 if (status)
5946 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005947 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005948 if (status)
5949 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005950 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005951 if (status)
5952 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00005953 if (res->fattr)
5954 decode_getfattr(xdr, res->fattr, res->server,
5955 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005956out:
5957 return status;
5958}
5959
5960/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005961 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005962 */
Chuck Leverbf269552010-12-14 14:59:29 +00005963static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04005964 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005965{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005966 struct compound_hdr hdr;
5967 int status;
5968
Chuck Leverbf269552010-12-14 14:59:29 +00005969 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005971 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005972 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005973 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005974 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005975 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005976 return status;
5977}
5978
5979/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005980 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005981 */
Chuck Leverbf269552010-12-14 14:59:29 +00005982static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04005983 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005985 struct compound_hdr hdr;
5986 int status;
5987
Chuck Leverbf269552010-12-14 14:59:29 +00005988 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005989 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005990 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005991 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005992 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005993 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005994 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005995 return status;
5996}
5997
5998/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005999 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006000 */
Chuck Leverbf269552010-12-14 14:59:29 +00006001static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006002 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006003{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006004 struct compound_hdr hdr;
6005 int status;
6006
Chuck Leverbf269552010-12-14 14:59:29 +00006007 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006009 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006010 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006011 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006013 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014 return status;
6015}
6016
6017/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006018 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006019 */
Chuck Leverbf269552010-12-14 14:59:29 +00006020static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6021 struct xdr_stream *xdr,
6022 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006023{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024 struct compound_hdr hdr;
6025 int status;
6026
Chuck Leverbf269552010-12-14 14:59:29 +00006027 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006028 if (status)
6029 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006030 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006031 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006032 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006033 status = decode_putfh(xdr);
6034 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006035 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006036 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006037out:
6038 return status;
6039}
6040
6041/*
6042 * Decode RENEW response
6043 */
Chuck Leverbf269552010-12-14 14:59:29 +00006044static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6045 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006046{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006047 struct compound_hdr hdr;
6048 int status;
6049
Chuck Leverbf269552010-12-14 14:59:29 +00006050 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006051 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006052 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006053 return status;
6054}
6055
6056/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006057 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006058 */
Chuck Leverbf269552010-12-14 14:59:29 +00006059static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6060 struct xdr_stream *xdr,
6061 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006062{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006063 struct compound_hdr hdr;
6064 int status;
6065
Chuck Leverbf269552010-12-14 14:59:29 +00006066 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006068 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006069 return status;
6070}
6071
6072/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006073 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006074 */
Chuck Leverbf269552010-12-14 14:59:29 +00006075static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6076 struct xdr_stream *xdr,
6077 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006079 struct compound_hdr hdr;
6080 int status;
6081
Chuck Leverbf269552010-12-14 14:59:29 +00006082 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006084 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006085 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006086 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006087 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006088 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089 return status;
6090}
6091
6092/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006093 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006094 */
Chuck Leverbf269552010-12-14 14:59:29 +00006095static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6096 struct xdr_stream *xdr,
6097 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006099 struct compound_hdr hdr;
6100 int status;
6101
Chuck Leverbf269552010-12-14 14:59:29 +00006102 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006103 if (status)
6104 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006105 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006106 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006107 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006108 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006109 if (status != 0)
6110 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006111 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006112 if (status != 0)
6113 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006114 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006115 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01006116out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117 return status;
6118}
6119
Trond Myklebust683b57b2006-06-09 09:34:22 -04006120/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006121 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006122 */
Chuck Leverbf269552010-12-14 14:59:29 +00006123static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6124 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006125 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006126{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006127 struct compound_hdr hdr;
6128 int status;
6129
Chuck Leverbf269552010-12-14 14:59:29 +00006130 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006131 if (status)
6132 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006133 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006134 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006135 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_putfh(xdr);
6137 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006139 status = decode_lookup(xdr);
6140 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006141 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006142 xdr_enter_page(xdr, PAGE_SIZE);
6143 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006144 res->fs_locations->server,
6145 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04006146out:
6147 return status;
6148}
6149
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006150/*
6151 * Decode SECINFO response
6152 */
6153static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6154 struct xdr_stream *xdr,
6155 struct nfs4_secinfo_res *res)
6156{
6157 struct compound_hdr hdr;
6158 int status;
6159
6160 status = decode_compound_hdr(xdr, &hdr);
6161 if (status)
6162 goto out;
6163 status = decode_sequence(xdr, &res->seq_res, rqstp);
6164 if (status)
6165 goto out;
6166 status = decode_putfh(xdr);
6167 if (status)
6168 goto out;
6169 status = decode_secinfo(xdr, res);
6170 if (status)
6171 goto out;
6172out:
6173 return status;
6174}
6175
Benny Halevy99fe60d2009-04-01 09:22:29 -04006176#if defined(CONFIG_NFS_V4_1)
6177/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006178 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006179 */
Chuck Leverbf269552010-12-14 14:59:29 +00006180static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6181 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006182 void *res)
6183{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006184 struct compound_hdr hdr;
6185 int status;
6186
Chuck Leverbf269552010-12-14 14:59:29 +00006187 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006188 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006189 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006190 return status;
6191}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006192
6193/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006194 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006195 */
Chuck Leverbf269552010-12-14 14:59:29 +00006196static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6197 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006198 struct nfs41_create_session_res *res)
6199{
Andy Adamsonfc931582009-04-01 09:22:31 -04006200 struct compound_hdr hdr;
6201 int status;
6202
Chuck Leverbf269552010-12-14 14:59:29 +00006203 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006204 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006205 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006206 return status;
6207}
6208
6209/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006210 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006211 */
Chuck Leverbf269552010-12-14 14:59:29 +00006212static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6213 struct xdr_stream *xdr,
6214 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006215{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006216 struct compound_hdr hdr;
6217 int status;
6218
Chuck Leverbf269552010-12-14 14:59:29 +00006219 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006220 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006221 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006222 return status;
6223}
6224
6225/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006226 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006227 */
Chuck Leverbf269552010-12-14 14:59:29 +00006228static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6229 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006230 struct nfs4_sequence_res *res)
6231{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006232 struct compound_hdr hdr;
6233 int status;
6234
Chuck Leverbf269552010-12-14 14:59:29 +00006235 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006236 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006237 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006238 return status;
6239}
6240
6241/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006242 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006243 */
Chuck Leverbf269552010-12-14 14:59:29 +00006244static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6245 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006246 struct nfs4_get_lease_time_res *res)
6247{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006248 struct compound_hdr hdr;
6249 int status;
6250
Chuck Leverbf269552010-12-14 14:59:29 +00006251 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006252 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006253 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006254 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006256 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006257 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006258 return status;
6259}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006260
6261/*
6262 * Decode RECLAIM_COMPLETE response
6263 */
Chuck Leverbf269552010-12-14 14:59:29 +00006264static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6265 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006266 struct nfs41_reclaim_complete_res *res)
6267{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006268 struct compound_hdr hdr;
6269 int status;
6270
Chuck Leverbf269552010-12-14 14:59:29 +00006271 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006272 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006273 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006274 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006275 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006276 return status;
6277}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006278
6279/*
6280 * Decode GETDEVINFO response
6281 */
Chuck Leverbf269552010-12-14 14:59:29 +00006282static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6283 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006284 struct nfs4_getdeviceinfo_res *res)
6285{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006286 struct compound_hdr hdr;
6287 int status;
6288
Chuck Leverbf269552010-12-14 14:59:29 +00006289 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006290 if (status != 0)
6291 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006292 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006293 if (status != 0)
6294 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006295 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006296out:
6297 return status;
6298}
6299
6300/*
6301 * Decode LAYOUTGET response
6302 */
Chuck Leverbf269552010-12-14 14:59:29 +00006303static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6304 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006305 struct nfs4_layoutget_res *res)
6306{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006307 struct compound_hdr hdr;
6308 int status;
6309
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006311 if (status)
6312 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006313 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006314 if (status)
6315 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006316 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006317 if (status)
6318 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006319 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006320out:
6321 return status;
6322}
Andy Adamson863a3c62011-03-23 13:27:54 +00006323
6324/*
6325 * Decode LAYOUTCOMMIT response
6326 */
6327static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6328 struct xdr_stream *xdr,
6329 struct nfs4_layoutcommit_res *res)
6330{
6331 struct compound_hdr hdr;
6332 int status;
6333
6334 status = decode_compound_hdr(xdr, &hdr);
6335 if (status)
6336 goto out;
6337 status = decode_sequence(xdr, &res->seq_res, rqstp);
6338 if (status)
6339 goto out;
6340 status = decode_putfh(xdr);
6341 if (status)
6342 goto out;
6343 status = decode_layoutcommit(xdr, rqstp, res);
6344 if (status)
6345 goto out;
6346 decode_getfattr(xdr, res->fattr, res->server,
6347 !RPC_IS_ASYNC(rqstp->rq_task));
6348out:
6349 return status;
6350}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006351#endif /* CONFIG_NFS_V4_1 */
6352
Chuck Lever573c4e12010-12-14 14:58:11 +00006353/**
6354 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6355 * the local page cache.
6356 * @xdr: XDR stream where entry resides
6357 * @entry: buffer to fill in with entry data
6358 * @plus: boolean indicating whether this should be a readdirplus entry
6359 *
6360 * Returns zero if successful, otherwise a negative errno value is
6361 * returned.
6362 *
6363 * This function is not invoked during READDIR reply decoding, but
6364 * rather whenever an application invokes the getdents(2) system call
6365 * on a directory already in our cache.
6366 */
6367int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6368 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006369{
6370 uint32_t bitmap[2] = {0};
6371 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006372 __be32 *p = xdr_inline_decode(xdr, 4);
6373 if (unlikely(!p))
6374 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006375 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006376 p = xdr_inline_decode(xdr, 4);
6377 if (unlikely(!p))
6378 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006379 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006380 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006382 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006383 }
6384
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006385 p = xdr_inline_decode(xdr, 12);
6386 if (unlikely(!p))
6387 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006388 entry->prev_cookie = entry->cookie;
6389 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006390 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006391
Trond Myklebust9af8c222010-10-24 11:52:55 -04006392 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006393 if (unlikely(!p))
6394 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006395 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396
6397 /*
6398 * In case the server doesn't return an inode number,
6399 * we fake one here. (We don't use inode number 0,
6400 * since glibc seems to choke on it...)
6401 */
6402 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006403 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006404
Trond Myklebust9af8c222010-10-24 11:52:55 -04006405 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006406 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006407
6408 if (decode_attr_length(xdr, &len, &p) < 0)
6409 goto out_overflow;
6410
Chuck Lever573c4e12010-12-14 14:58:11 +00006411 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6412 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006413 goto out_overflow;
6414 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6415 entry->ino = entry->fattr->fileid;
6416
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006417 entry->d_type = DT_UNKNOWN;
6418 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6419 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6420
Chuck Lever573c4e12010-12-14 14:58:11 +00006421 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006422
6423out_overflow:
6424 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006425 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426}
6427
6428/*
6429 * We need to translate between nfs status return values and
6430 * the local errno values which may not be the same.
6431 */
6432static struct {
6433 int stat;
6434 int errno;
6435} nfs_errtbl[] = {
6436 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006437 { NFS4ERR_PERM, -EPERM },
6438 { NFS4ERR_NOENT, -ENOENT },
6439 { NFS4ERR_IO, -errno_NFSERR_IO},
6440 { NFS4ERR_NXIO, -ENXIO },
6441 { NFS4ERR_ACCESS, -EACCES },
6442 { NFS4ERR_EXIST, -EEXIST },
6443 { NFS4ERR_XDEV, -EXDEV },
6444 { NFS4ERR_NOTDIR, -ENOTDIR },
6445 { NFS4ERR_ISDIR, -EISDIR },
6446 { NFS4ERR_INVAL, -EINVAL },
6447 { NFS4ERR_FBIG, -EFBIG },
6448 { NFS4ERR_NOSPC, -ENOSPC },
6449 { NFS4ERR_ROFS, -EROFS },
6450 { NFS4ERR_MLINK, -EMLINK },
6451 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6452 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6453 { NFS4ERR_DQUOT, -EDQUOT },
6454 { NFS4ERR_STALE, -ESTALE },
6455 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006456 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6457 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6458 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006459 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006460 { NFS4ERR_BADTYPE, -EBADTYPE },
6461 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006462 { NFS4ERR_SYMLINK, -ELOOP },
6463 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6464 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006465 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466};
6467
6468/*
6469 * Convert an NFS error code to a local one.
6470 * This one is used jointly by NFSv2 and NFSv3.
6471 */
6472static int
David Howells0a8ea432006-08-22 20:06:08 -04006473nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006474{
6475 int i;
6476 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6477 if (nfs_errtbl[i].stat == stat)
6478 return nfs_errtbl[i].errno;
6479 }
6480 if (stat <= 10000 || stat > 10100) {
6481 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006482 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006483 }
6484 /* If we cannot translate the error, the recovery routines should
6485 * handle it.
6486 * Note: remaining NFSv4 error codes have values > 10000, so should
6487 * not conflict with native Linux error codes.
6488 */
Benny Halevy856dff32008-03-31 17:39:06 +03006489 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490}
6491
Linus Torvalds1da177e2005-04-16 15:20:36 -07006492#define PROC(proc, argtype, restype) \
6493[NFSPROC4_CLNT_##proc] = { \
6494 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006495 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006496 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006497 .p_arglen = NFS4_##argtype##_sz, \
6498 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006499 .p_statidx = NFSPROC4_CLNT_##proc, \
6500 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006501}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502
6503struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006504 PROC(READ, enc_read, dec_read),
6505 PROC(WRITE, enc_write, dec_write),
6506 PROC(COMMIT, enc_commit, dec_commit),
6507 PROC(OPEN, enc_open, dec_open),
6508 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6509 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6510 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6511 PROC(CLOSE, enc_close, dec_close),
6512 PROC(SETATTR, enc_setattr, dec_setattr),
6513 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6514 PROC(RENEW, enc_renew, dec_renew),
6515 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6516 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6517 PROC(LOCK, enc_lock, dec_lock),
6518 PROC(LOCKT, enc_lockt, dec_lockt),
6519 PROC(LOCKU, enc_locku, dec_locku),
6520 PROC(ACCESS, enc_access, dec_access),
6521 PROC(GETATTR, enc_getattr, dec_getattr),
6522 PROC(LOOKUP, enc_lookup, dec_lookup),
6523 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6524 PROC(REMOVE, enc_remove, dec_remove),
6525 PROC(RENAME, enc_rename, dec_rename),
6526 PROC(LINK, enc_link, dec_link),
6527 PROC(SYMLINK, enc_symlink, dec_symlink),
6528 PROC(CREATE, enc_create, dec_create),
6529 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6530 PROC(STATFS, enc_statfs, dec_statfs),
6531 PROC(READLINK, enc_readlink, dec_readlink),
6532 PROC(READDIR, enc_readdir, dec_readdir),
6533 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6534 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6535 PROC(GETACL, enc_getacl, dec_getacl),
6536 PROC(SETACL, enc_setacl, dec_setacl),
6537 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6538 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006539 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006540#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00006541 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6542 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6543 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6544 PROC(SEQUENCE, enc_sequence, dec_sequence),
6545 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6546 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6547 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6548 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00006549 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006550#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551};
6552
6553struct rpc_version nfs_version4 = {
6554 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08006555 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556 .procs = nfs4_procedures
6557};
6558
6559/*
6560 * Local variables:
6561 * c-basic-offset: 8
6562 * End:
6563 */