blob: c3ccd2c468344fab9076214fec8d99fc1eee9036 [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 Labiaga18019752009-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 Labiaga18019752009-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{
Trond Myklebust28331a42011-04-27 13:47:52 -04001455 uint32_t attrs[2] = {
1456 FATTR4_WORD0_RDATTR_ERROR,
1457 FATTR4_WORD1_MOUNTED_ON_FILEID,
1458 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001459 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001460 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001462 if (readdir->plus) {
1463 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001464 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001465 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1466 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1467 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1468 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001469 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001470 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001471 /* Use mounted_on_fileid only if the server supports it */
1472 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1473 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001474
Benny Halevy13c65ce2009-08-14 17:19:25 +03001475 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001476 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001477 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001478 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001479 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001480 *p++ = cpu_to_be32(readdir->count);
1481 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001482
Benny Halevye75bc1c2009-08-14 17:18:54 +03001483 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001484 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001485 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001486 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001487 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1488 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001489 (unsigned long long)readdir->cookie,
1490 ((u32 *)readdir->verifier.data)[0],
1491 ((u32 *)readdir->verifier.data)[1],
1492 attrs[0] & readdir->bitmask[0],
1493 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494}
1495
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001496static 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 -07001497{
Al Viro8687b632006-10-19 23:28:48 -07001498 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
Benny Halevy13c65ce2009-08-14 17:19:25 +03001500 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001501 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001502 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001503 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504}
1505
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001506static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507{
Al Viro8687b632006-10-19 23:28:48 -07001508 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
Benny Halevy13c65ce2009-08-14 17:19:25 +03001510 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001511 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001512 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001513 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001514 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515}
1516
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001517static 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 -07001518{
Al Viro8687b632006-10-19 23:28:48 -07001519 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Benny Halevy811652b2009-08-14 17:19:34 +03001521 p = reserve_space(xdr, 4);
1522 *p = cpu_to_be32(OP_RENAME);
1523 encode_string(xdr, oldname->len, oldname->name);
1524 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001525 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001526 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527}
1528
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001529static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530{
Al Viro8687b632006-10-19 23:28:48 -07001531 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Benny Halevy13c65ce2009-08-14 17:19:25 +03001533 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001534 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001535 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001536 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001537 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538}
1539
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001540static void
Andy Adamsond0179312008-12-23 16:06:17 -05001541encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001542{
Al Viro8687b632006-10-19 23:28:48 -07001543 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001544
Benny Halevy13c65ce2009-08-14 17:19:25 +03001545 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001546 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001547 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001548 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001549}
1550
Chuck Lever9f06c712010-12-14 14:59:18 +00001551static void
Andy Adamsond0179312008-12-23 16:06:17 -05001552encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001553{
Al Viro8687b632006-10-19 23:28:48 -07001554 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001555
Benny Halevy13c65ce2009-08-14 17:19:25 +03001556 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001557 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001558 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001559 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001560 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001561 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001562 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001563 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001564 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001565 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001566 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001567 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001568}
1569
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001570static void
Andy Adamsond0179312008-12-23 16:06:17 -05001571encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572{
Al Viro8687b632006-10-19 23:28:48 -07001573 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Benny Halevy13c65ce2009-08-14 17:19:25 +03001575 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001576 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001577 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001578 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579}
1580
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001581static 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 -07001582{
Al Viro8687b632006-10-19 23:28:48 -07001583 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001584
Benny Halevy13c65ce2009-08-14 17:19:25 +03001585 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001586 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001587 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001588 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001589 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001590 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591}
1592
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001593static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594{
Al Viro8687b632006-10-19 23:28:48 -07001595 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
Benny Halevy13c65ce2009-08-14 17:19:25 +03001597 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001598 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001599 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
1601 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001602 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001603 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1605 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001606 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001607 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001608 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001609 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610}
1611
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001612static 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 -07001613{
Andy Adamson05d564f2008-12-23 16:06:15 -05001614 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
Benny Halevy13c65ce2009-08-14 17:19:25 +03001616 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001617 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001618 p = xdr_encode_hyper(p, arg->clientid);
1619 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001620 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001621 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622}
1623
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001624static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625{
Al Viro8687b632006-10-19 23:28:48 -07001626 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
Benny Halevy13c65ce2009-08-14 17:19:25 +03001628 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001629 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
Andy Adamson89d1ea62011-03-01 01:34:09 +00001631 encode_stateid(xdr, args->context, args->lock_context,
1632 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
Benny Halevy13c65ce2009-08-14 17:19:25 +03001634 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001635 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001636 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001637 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
1639 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001640 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001641 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642}
1643
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001644static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645{
Al Viro8687b632006-10-19 23:28:48 -07001646 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
Benny Halevy13c65ce2009-08-14 17:19:25 +03001648 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
Benny Halevye75bc1c2009-08-14 17:18:54 +03001650 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001651 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001652 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001653 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001655
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001656static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1657{
1658 int len = name->len;
1659 __be32 *p;
1660
1661 p = reserve_space(xdr, 8 + len);
1662 *p++ = cpu_to_be32(OP_SECINFO);
1663 xdr_encode_opaque(p, name->name, len);
1664 hdr->nops++;
1665 hdr->replen += decode_secinfo_maxsz;
1666}
1667
Benny Halevy99fe60d2009-04-01 09:22:29 -04001668#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001669/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001670static void encode_exchange_id(struct xdr_stream *xdr,
1671 struct nfs41_exchange_id_args *args,
1672 struct compound_hdr *hdr)
1673{
1674 __be32 *p;
1675
Benny Halevy13c65ce2009-08-14 17:19:25 +03001676 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001677 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001678 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001679
1680 encode_string(xdr, args->id_len, args->id);
1681
Benny Halevy13c65ce2009-08-14 17:19:25 +03001682 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001683 *p++ = cpu_to_be32(args->flags);
1684 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001685 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001686 hdr->nops++;
1687 hdr->replen += decode_exchange_id_maxsz;
1688}
Andy Adamsonfc931582009-04-01 09:22:31 -04001689
1690static void encode_create_session(struct xdr_stream *xdr,
1691 struct nfs41_create_session_args *args,
1692 struct compound_hdr *hdr)
1693{
1694 __be32 *p;
1695 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1696 uint32_t len;
1697 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001698 u32 max_resp_sz_cached;
1699
1700 /*
1701 * Assumes OPEN is the biggest non-idempotent compound.
1702 * 2 is the verifier.
1703 */
1704 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1705 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001706
Andy Adamsonfc931582009-04-01 09:22:31 -04001707 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1708 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001709
Benny Halevy13c65ce2009-08-14 17:19:25 +03001710 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001711 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001712 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001713 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1714 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001715
Andy Adamsonfc931582009-04-01 09:22:31 -04001716 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001717 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1718 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1719 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001720 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001721 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1722 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1723 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001724
1725 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001726 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1727 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1728 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1729 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1730 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1731 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1732 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001733
Benny Halevye75bc1c2009-08-14 17:18:54 +03001734 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001735 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001736 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001737
1738 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001739 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001740 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001741 *p++ = cpu_to_be32(0); /* UID */
1742 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001743 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001744 hdr->nops++;
1745 hdr->replen += decode_create_session_maxsz;
1746}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001747
1748static void encode_destroy_session(struct xdr_stream *xdr,
1749 struct nfs4_session *session,
1750 struct compound_hdr *hdr)
1751{
1752 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001753 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001754 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001755 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001756 hdr->nops++;
1757 hdr->replen += decode_destroy_session_maxsz;
1758}
Ricardo Labiaga18019752009-12-05 16:08:40 -05001759
1760static void encode_reclaim_complete(struct xdr_stream *xdr,
1761 struct nfs41_reclaim_complete_args *args,
1762 struct compound_hdr *hdr)
1763{
1764 __be32 *p;
1765
1766 p = reserve_space(xdr, 8);
1767 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1768 *p++ = cpu_to_be32(args->one_fs);
1769 hdr->nops++;
1770 hdr->replen += decode_reclaim_complete_maxsz;
1771}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001772#endif /* CONFIG_NFS_V4_1 */
1773
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001774static void encode_sequence(struct xdr_stream *xdr,
1775 const struct nfs4_sequence_args *args,
1776 struct compound_hdr *hdr)
1777{
1778#if defined(CONFIG_NFS_V4_1)
1779 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001780 struct nfs4_slot_table *tp;
1781 struct nfs4_slot *slot;
1782 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001783
1784 if (!session)
1785 return;
1786
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001787 tp = &session->fc_slot_table;
1788
1789 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1790 slot = tp->slots + args->sa_slotid;
1791
Benny Halevy13c65ce2009-08-14 17:19:25 +03001792 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001793 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001794
1795 /*
1796 * Sessionid + seqid + slotid + max slotid + cache_this
1797 */
1798 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1799 "max_slotid=%d cache_this=%d\n",
1800 __func__,
1801 ((u32 *)session->sess_id.data)[0],
1802 ((u32 *)session->sess_id.data)[1],
1803 ((u32 *)session->sess_id.data)[2],
1804 ((u32 *)session->sess_id.data)[3],
1805 slot->seq_nr, args->sa_slotid,
1806 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001807 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001808 *p++ = cpu_to_be32(slot->seq_nr);
1809 *p++ = cpu_to_be32(args->sa_slotid);
1810 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001811 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001812 hdr->nops++;
1813 hdr->replen += decode_sequence_maxsz;
1814#endif /* CONFIG_NFS_V4_1 */
1815}
1816
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001817#ifdef CONFIG_NFS_V4_1
1818static void
1819encode_getdeviceinfo(struct xdr_stream *xdr,
1820 const struct nfs4_getdeviceinfo_args *args,
1821 struct compound_hdr *hdr)
1822{
1823 __be32 *p;
1824
1825 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1826 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1827 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1828 NFS4_DEVICEID4_SIZE);
1829 *p++ = cpu_to_be32(args->pdev->layout_type);
1830 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1831 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1832 hdr->nops++;
1833 hdr->replen += decode_getdeviceinfo_maxsz;
1834}
1835
1836static void
1837encode_layoutget(struct xdr_stream *xdr,
1838 const struct nfs4_layoutget_args *args,
1839 struct compound_hdr *hdr)
1840{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001841 __be32 *p;
1842
1843 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1844 *p++ = cpu_to_be32(OP_LAYOUTGET);
1845 *p++ = cpu_to_be32(0); /* Signal layout available */
1846 *p++ = cpu_to_be32(args->type);
1847 *p++ = cpu_to_be32(args->range.iomode);
1848 p = xdr_encode_hyper(p, args->range.offset);
1849 p = xdr_encode_hyper(p, args->range.length);
1850 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00001851 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001852 *p = cpu_to_be32(args->maxcount);
1853
1854 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1855 __func__,
1856 args->type,
1857 args->range.iomode,
1858 (unsigned long)args->range.offset,
1859 (unsigned long)args->range.length,
1860 args->maxcount);
1861 hdr->nops++;
1862 hdr->replen += decode_layoutget_maxsz;
1863}
Andy Adamson863a3c62011-03-23 13:27:54 +00001864
1865static int
1866encode_layoutcommit(struct xdr_stream *xdr,
1867 const struct nfs4_layoutcommit_args *args,
1868 struct compound_hdr *hdr)
1869{
1870 __be32 *p;
1871
1872 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1873 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1874
1875 p = reserve_space(xdr, 48 + NFS4_STATEID_SIZE);
1876 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1877 /* Only whole file layouts */
1878 p = xdr_encode_hyper(p, 0); /* offset */
1879 p = xdr_encode_hyper(p, NFS4_MAX_UINT64); /* length */
1880 *p++ = cpu_to_be32(0); /* reclaim */
1881 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1882 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1883 p = xdr_encode_hyper(p, args->lastbytewritten);
1884 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1885 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1886 *p++ = cpu_to_be32(0); /* no file layout payload */
1887
1888 hdr->nops++;
1889 hdr->replen += decode_layoutcommit_maxsz;
1890 return 0;
1891}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001892#endif /* CONFIG_NFS_V4_1 */
1893
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894/*
1895 * END OF "GENERIC" ENCODE ROUTINES.
1896 */
1897
Benny Halevy66cc0422009-04-01 09:22:10 -04001898static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1899{
1900#if defined(CONFIG_NFS_V4_1)
1901 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001902 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001903#endif /* CONFIG_NFS_V4_1 */
1904 return 0;
1905}
1906
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907/*
1908 * Encode an ACCESS request
1909 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001910static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1911 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001914 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916
Chuck Lever9f06c712010-12-14 14:59:18 +00001917 encode_compound_hdr(xdr, req, &hdr);
1918 encode_sequence(xdr, &args->seq_args, &hdr);
1919 encode_putfh(xdr, args->fh, &hdr);
1920 encode_access(xdr, args->access, &hdr);
1921 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001922 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923}
1924
1925/*
1926 * Encode LOOKUP request
1927 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001928static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1929 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001932 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934
Chuck Lever9f06c712010-12-14 14:59:18 +00001935 encode_compound_hdr(xdr, req, &hdr);
1936 encode_sequence(xdr, &args->seq_args, &hdr);
1937 encode_putfh(xdr, args->dir_fh, &hdr);
1938 encode_lookup(xdr, args->name, &hdr);
1939 encode_getfh(xdr, &hdr);
1940 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001941 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942}
1943
1944/*
1945 * Encode LOOKUP_ROOT request
1946 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001947static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
1948 struct xdr_stream *xdr,
1949 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001952 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954
Chuck Lever9f06c712010-12-14 14:59:18 +00001955 encode_compound_hdr(xdr, req, &hdr);
1956 encode_sequence(xdr, &args->seq_args, &hdr);
1957 encode_putrootfh(xdr, &hdr);
1958 encode_getfh(xdr, &hdr);
1959 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001960 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961}
1962
1963/*
1964 * Encode REMOVE request
1965 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001966static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
1967 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001970 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
Chuck Lever9f06c712010-12-14 14:59:18 +00001973 encode_compound_hdr(xdr, req, &hdr);
1974 encode_sequence(xdr, &args->seq_args, &hdr);
1975 encode_putfh(xdr, args->fh, &hdr);
1976 encode_remove(xdr, &args->name, &hdr);
1977 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001978 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979}
1980
1981/*
1982 * Encode RENAME request
1983 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001984static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
1985 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001988 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
Chuck Lever9f06c712010-12-14 14:59:18 +00001991 encode_compound_hdr(xdr, req, &hdr);
1992 encode_sequence(xdr, &args->seq_args, &hdr);
1993 encode_putfh(xdr, args->old_dir, &hdr);
1994 encode_savefh(xdr, &hdr);
1995 encode_putfh(xdr, args->new_dir, &hdr);
1996 encode_rename(xdr, args->old_name, args->new_name, &hdr);
1997 encode_getfattr(xdr, args->bitmask, &hdr);
1998 encode_restorefh(xdr, &hdr);
1999 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002000 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001}
2002
2003/*
2004 * Encode LINK request
2005 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002006static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2007 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002010 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012
Chuck Lever9f06c712010-12-14 14:59:18 +00002013 encode_compound_hdr(xdr, req, &hdr);
2014 encode_sequence(xdr, &args->seq_args, &hdr);
2015 encode_putfh(xdr, args->fh, &hdr);
2016 encode_savefh(xdr, &hdr);
2017 encode_putfh(xdr, args->dir_fh, &hdr);
2018 encode_link(xdr, args->name, &hdr);
2019 encode_getfattr(xdr, args->bitmask, &hdr);
2020 encode_restorefh(xdr, &hdr);
2021 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002022 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023}
2024
2025/*
2026 * Encode CREATE request
2027 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002028static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2029 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002032 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
Chuck Lever9f06c712010-12-14 14:59:18 +00002035 encode_compound_hdr(xdr, req, &hdr);
2036 encode_sequence(xdr, &args->seq_args, &hdr);
2037 encode_putfh(xdr, args->dir_fh, &hdr);
2038 encode_savefh(xdr, &hdr);
2039 encode_create(xdr, args, &hdr);
2040 encode_getfh(xdr, &hdr);
2041 encode_getfattr(xdr, args->bitmask, &hdr);
2042 encode_restorefh(xdr, &hdr);
2043 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002044 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045}
2046
2047/*
2048 * Encode SYMLINK request
2049 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002050static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2051 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052{
Chuck Lever9f06c712010-12-14 14:59:18 +00002053 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054}
2055
2056/*
2057 * Encode GETATTR request
2058 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002059static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2060 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002063 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
Chuck Lever9f06c712010-12-14 14:59:18 +00002066 encode_compound_hdr(xdr, req, &hdr);
2067 encode_sequence(xdr, &args->seq_args, &hdr);
2068 encode_putfh(xdr, args->fh, &hdr);
2069 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002070 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071}
2072
2073/*
2074 * Encode a CLOSE request
2075 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002076static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2077 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078{
Andy Adamson05d564f2008-12-23 16:06:15 -05002079 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002080 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002081 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
Chuck Lever9f06c712010-12-14 14:59:18 +00002083 encode_compound_hdr(xdr, req, &hdr);
2084 encode_sequence(xdr, &args->seq_args, &hdr);
2085 encode_putfh(xdr, args->fh, &hdr);
2086 encode_close(xdr, args, &hdr);
2087 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002088 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089}
2090
2091/*
2092 * Encode an OPEN request
2093 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002094static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2095 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002098 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Chuck Lever9f06c712010-12-14 14:59:18 +00002101 encode_compound_hdr(xdr, req, &hdr);
2102 encode_sequence(xdr, &args->seq_args, &hdr);
2103 encode_putfh(xdr, args->fh, &hdr);
2104 encode_savefh(xdr, &hdr);
2105 encode_open(xdr, args, &hdr);
2106 encode_getfh(xdr, &hdr);
2107 encode_getfattr(xdr, args->bitmask, &hdr);
2108 encode_restorefh(xdr, &hdr);
2109 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002110 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111}
2112
2113/*
2114 * Encode an OPEN_CONFIRM request
2115 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002116static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2117 struct xdr_stream *xdr,
2118 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002121 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Chuck Lever9f06c712010-12-14 14:59:18 +00002124 encode_compound_hdr(xdr, req, &hdr);
2125 encode_putfh(xdr, args->fh, &hdr);
2126 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002127 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128}
2129
2130/*
2131 * Encode an OPEN request with no attributes.
2132 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002133static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2134 struct xdr_stream *xdr,
2135 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002138 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
Chuck Lever9f06c712010-12-14 14:59:18 +00002141 encode_compound_hdr(xdr, req, &hdr);
2142 encode_sequence(xdr, &args->seq_args, &hdr);
2143 encode_putfh(xdr, args->fh, &hdr);
2144 encode_open(xdr, args, &hdr);
2145 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002146 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147}
2148
2149/*
2150 * Encode an OPEN_DOWNGRADE request
2151 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002152static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2153 struct xdr_stream *xdr,
2154 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002157 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159
Chuck Lever9f06c712010-12-14 14:59:18 +00002160 encode_compound_hdr(xdr, req, &hdr);
2161 encode_sequence(xdr, &args->seq_args, &hdr);
2162 encode_putfh(xdr, args->fh, &hdr);
2163 encode_open_downgrade(xdr, args, &hdr);
2164 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002165 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166}
2167
2168/*
2169 * Encode a LOCK request
2170 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002171static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2172 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002175 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177
Chuck Lever9f06c712010-12-14 14:59:18 +00002178 encode_compound_hdr(xdr, req, &hdr);
2179 encode_sequence(xdr, &args->seq_args, &hdr);
2180 encode_putfh(xdr, args->fh, &hdr);
2181 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002182 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183}
2184
2185/*
2186 * Encode a LOCKT request
2187 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002188static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2189 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002192 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
Chuck Lever9f06c712010-12-14 14:59:18 +00002195 encode_compound_hdr(xdr, req, &hdr);
2196 encode_sequence(xdr, &args->seq_args, &hdr);
2197 encode_putfh(xdr, args->fh, &hdr);
2198 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002199 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200}
2201
2202/*
2203 * Encode a LOCKU request
2204 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002205static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2206 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002209 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
Chuck Lever9f06c712010-12-14 14:59:18 +00002212 encode_compound_hdr(xdr, req, &hdr);
2213 encode_sequence(xdr, &args->seq_args, &hdr);
2214 encode_putfh(xdr, args->fh, &hdr);
2215 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002216 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217}
2218
Chuck Lever9f06c712010-12-14 14:59:18 +00002219static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2220 struct xdr_stream *xdr,
2221 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002222{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002223 struct compound_hdr hdr = {
2224 .minorversion = 0,
2225 };
2226
Chuck Lever9f06c712010-12-14 14:59:18 +00002227 encode_compound_hdr(xdr, req, &hdr);
2228 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002229 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002230}
2231
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232/*
2233 * Encode a READLINK request
2234 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002235static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2236 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002239 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
Chuck Lever9f06c712010-12-14 14:59:18 +00002242 encode_compound_hdr(xdr, req, &hdr);
2243 encode_sequence(xdr, &args->seq_args, &hdr);
2244 encode_putfh(xdr, args->fh, &hdr);
2245 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002246
Benny Halevy28f56692009-04-01 09:22:09 -04002247 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002248 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002249 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250}
2251
2252/*
2253 * Encode a READDIR request
2254 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002255static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2256 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002259 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
Chuck Lever9f06c712010-12-14 14:59:18 +00002262 encode_compound_hdr(xdr, req, &hdr);
2263 encode_sequence(xdr, &args->seq_args, &hdr);
2264 encode_putfh(xdr, args->fh, &hdr);
2265 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002266
Benny Halevy28f56692009-04-01 09:22:09 -04002267 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002268 args->pgbase, args->count);
2269 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002270 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002271 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002272 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273}
2274
2275/*
2276 * Encode a READ request
2277 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002278static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2279 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002282 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284
Chuck Lever9f06c712010-12-14 14:59:18 +00002285 encode_compound_hdr(xdr, req, &hdr);
2286 encode_sequence(xdr, &args->seq_args, &hdr);
2287 encode_putfh(xdr, args->fh, &hdr);
2288 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
Benny Halevy28f56692009-04-01 09:22:09 -04002290 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002292 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002293 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294}
2295
2296/*
2297 * Encode an SETATTR request
2298 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002299static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2300 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301{
Andy Adamson05d564f2008-12-23 16:06:15 -05002302 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002303 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002304 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305
Chuck Lever9f06c712010-12-14 14:59:18 +00002306 encode_compound_hdr(xdr, req, &hdr);
2307 encode_sequence(xdr, &args->seq_args, &hdr);
2308 encode_putfh(xdr, args->fh, &hdr);
2309 encode_setattr(xdr, args, args->server, &hdr);
2310 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002311 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312}
2313
2314/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002315 * Encode a GETACL request
2316 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002317static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2318 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002319{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002320 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002321 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002322 };
Benny Halevy28f56692009-04-01 09:22:09 -04002323 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002324
Chuck Lever9f06c712010-12-14 14:59:18 +00002325 encode_compound_hdr(xdr, req, &hdr);
2326 encode_sequence(xdr, &args->seq_args, &hdr);
2327 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002328 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002329 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002330
Benny Halevy28f56692009-04-01 09:22:09 -04002331 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002332 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002333 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002334}
2335
2336/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 * Encode a WRITE request
2338 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002339static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2340 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002343 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
Chuck Lever9f06c712010-12-14 14:59:18 +00002346 encode_compound_hdr(xdr, req, &hdr);
2347 encode_sequence(xdr, &args->seq_args, &hdr);
2348 encode_putfh(xdr, args->fh, &hdr);
2349 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002350 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002351 if (args->bitmask)
2352 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002353 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354}
2355
2356/*
2357 * a COMMIT request
2358 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002359static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2360 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002363 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365
Chuck Lever9f06c712010-12-14 14:59:18 +00002366 encode_compound_hdr(xdr, req, &hdr);
2367 encode_sequence(xdr, &args->seq_args, &hdr);
2368 encode_putfh(xdr, args->fh, &hdr);
2369 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002370 if (args->bitmask)
2371 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002372 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373}
2374
2375/*
2376 * FSINFO request
2377 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002378static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2379 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002382 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384
Chuck Lever9f06c712010-12-14 14:59:18 +00002385 encode_compound_hdr(xdr, req, &hdr);
2386 encode_sequence(xdr, &args->seq_args, &hdr);
2387 encode_putfh(xdr, args->fh, &hdr);
2388 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002389 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390}
2391
2392/*
2393 * a PATHCONF request
2394 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002395static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2396 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002399 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
Chuck Lever9f06c712010-12-14 14:59:18 +00002402 encode_compound_hdr(xdr, req, &hdr);
2403 encode_sequence(xdr, &args->seq_args, &hdr);
2404 encode_putfh(xdr, args->fh, &hdr);
2405 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002406 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002407 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408}
2409
2410/*
2411 * a STATFS request
2412 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002413static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2414 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002417 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
Chuck Lever9f06c712010-12-14 14:59:18 +00002420 encode_compound_hdr(xdr, req, &hdr);
2421 encode_sequence(xdr, &args->seq_args, &hdr);
2422 encode_putfh(xdr, args->fh, &hdr);
2423 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002424 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002425 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426}
2427
2428/*
2429 * GETATTR_BITMAP request
2430 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002431static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2432 struct xdr_stream *xdr,
2433 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002436 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438
Chuck Lever9f06c712010-12-14 14:59:18 +00002439 encode_compound_hdr(xdr, req, &hdr);
2440 encode_sequence(xdr, &args->seq_args, &hdr);
2441 encode_putfh(xdr, args->fhandle, &hdr);
2442 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002443 FATTR4_WORD0_LINK_SUPPORT|
2444 FATTR4_WORD0_SYMLINK_SUPPORT|
2445 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002446 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447}
2448
2449/*
2450 * a RENEW request
2451 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002452static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2453 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002456 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 };
2458
Chuck Lever9f06c712010-12-14 14:59:18 +00002459 encode_compound_hdr(xdr, req, &hdr);
2460 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002461 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462}
2463
2464/*
2465 * a SETCLIENTID request
2466 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002467static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2468 struct xdr_stream *xdr,
2469 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002472 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 };
2474
Chuck Lever9f06c712010-12-14 14:59:18 +00002475 encode_compound_hdr(xdr, req, &hdr);
2476 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002477 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478}
2479
2480/*
2481 * a SETCLIENTID_CONFIRM request
2482 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002483static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2484 struct xdr_stream *xdr,
2485 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002488 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 };
2490 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491
Chuck Lever9f06c712010-12-14 14:59:18 +00002492 encode_compound_hdr(xdr, req, &hdr);
2493 encode_setclientid_confirm(xdr, arg, &hdr);
2494 encode_putrootfh(xdr, &hdr);
2495 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002496 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497}
2498
2499/*
2500 * DELEGRETURN request
2501 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002502static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2503 struct xdr_stream *xdr,
2504 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002507 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509
Chuck Lever9f06c712010-12-14 14:59:18 +00002510 encode_compound_hdr(xdr, req, &hdr);
2511 encode_sequence(xdr, &args->seq_args, &hdr);
2512 encode_putfh(xdr, args->fhandle, &hdr);
2513 encode_delegreturn(xdr, args->stateid, &hdr);
2514 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002515 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516}
2517
2518/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002519 * Encode FS_LOCATIONS request
2520 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002521static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2522 struct xdr_stream *xdr,
2523 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002524{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002525 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002526 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002527 };
Benny Halevy28f56692009-04-01 09:22:09 -04002528 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002529
Chuck Lever9f06c712010-12-14 14:59:18 +00002530 encode_compound_hdr(xdr, req, &hdr);
2531 encode_sequence(xdr, &args->seq_args, &hdr);
2532 encode_putfh(xdr, args->dir_fh, &hdr);
2533 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002534 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002535 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002536
Benny Halevy28f56692009-04-01 09:22:09 -04002537 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002538 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002539 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002540}
2541
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002542/*
2543 * Encode SECINFO request
2544 */
2545static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2546 struct xdr_stream *xdr,
2547 struct nfs4_secinfo_arg *args)
2548{
2549 struct compound_hdr hdr = {
2550 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2551 };
2552
2553 encode_compound_hdr(xdr, req, &hdr);
2554 encode_sequence(xdr, &args->seq_args, &hdr);
2555 encode_putfh(xdr, args->dir_fh, &hdr);
2556 encode_secinfo(xdr, args->name, &hdr);
2557 encode_nops(&hdr);
2558}
2559
Benny Halevy99fe60d2009-04-01 09:22:29 -04002560#if defined(CONFIG_NFS_V4_1)
2561/*
2562 * EXCHANGE_ID request
2563 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002564static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2565 struct xdr_stream *xdr,
2566 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002567{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002568 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002569 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002570 };
2571
Chuck Lever9f06c712010-12-14 14:59:18 +00002572 encode_compound_hdr(xdr, req, &hdr);
2573 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002574 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002575}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002576
2577/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002578 * a CREATE_SESSION request
2579 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002580static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2581 struct xdr_stream *xdr,
2582 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002583{
Andy Adamsonfc931582009-04-01 09:22:31 -04002584 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002585 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002586 };
2587
Chuck Lever9f06c712010-12-14 14:59:18 +00002588 encode_compound_hdr(xdr, req, &hdr);
2589 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002590 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002591}
2592
2593/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002594 * a DESTROY_SESSION request
2595 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002596static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2597 struct xdr_stream *xdr,
2598 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002599{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002600 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002601 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002602 };
2603
Chuck Lever9f06c712010-12-14 14:59:18 +00002604 encode_compound_hdr(xdr, req, &hdr);
2605 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002606 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002607}
2608
2609/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002610 * a SEQUENCE request
2611 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002612static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2613 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002614{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002615 struct compound_hdr hdr = {
2616 .minorversion = nfs4_xdr_minorversion(args),
2617 };
2618
Chuck Lever9f06c712010-12-14 14:59:18 +00002619 encode_compound_hdr(xdr, req, &hdr);
2620 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002621 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002622}
2623
2624/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002625 * a GET_LEASE_TIME request
2626 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002627static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2628 struct xdr_stream *xdr,
2629 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002630{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002631 struct compound_hdr hdr = {
2632 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2633 };
2634 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2635
Chuck Lever9f06c712010-12-14 14:59:18 +00002636 encode_compound_hdr(xdr, req, &hdr);
2637 encode_sequence(xdr, &args->la_seq_args, &hdr);
2638 encode_putrootfh(xdr, &hdr);
2639 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002640 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002641}
Ricardo Labiaga18019752009-12-05 16:08:40 -05002642
2643/*
2644 * a RECLAIM_COMPLETE request
2645 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002646static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2647 struct xdr_stream *xdr,
2648 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga18019752009-12-05 16:08:40 -05002649{
Ricardo Labiaga18019752009-12-05 16:08:40 -05002650 struct compound_hdr hdr = {
2651 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2652 };
2653
Chuck Lever9f06c712010-12-14 14:59:18 +00002654 encode_compound_hdr(xdr, req, &hdr);
2655 encode_sequence(xdr, &args->seq_args, &hdr);
2656 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05002657 encode_nops(&hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05002658}
2659
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002660/*
2661 * Encode GETDEVICEINFO request
2662 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002663static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2664 struct xdr_stream *xdr,
2665 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002666{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002667 struct compound_hdr hdr = {
2668 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2669 };
2670
Chuck Lever9f06c712010-12-14 14:59:18 +00002671 encode_compound_hdr(xdr, req, &hdr);
2672 encode_sequence(xdr, &args->seq_args, &hdr);
2673 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002674
2675 /* set up reply kvec. Subtract notification bitmap max size (2)
2676 * so that notification bitmap is put in xdr_buf tail */
2677 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2678 args->pdev->pages, args->pdev->pgbase,
2679 args->pdev->pglen);
2680
2681 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002682}
2683
2684/*
2685 * Encode LAYOUTGET request
2686 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002687static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2688 struct xdr_stream *xdr,
2689 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002690{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002691 struct compound_hdr hdr = {
2692 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2693 };
2694
Chuck Lever9f06c712010-12-14 14:59:18 +00002695 encode_compound_hdr(xdr, req, &hdr);
2696 encode_sequence(xdr, &args->seq_args, &hdr);
2697 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2698 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002699
2700 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2701 args->layout.pages, 0, args->layout.pglen);
2702
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002703 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002704}
Andy Adamson863a3c62011-03-23 13:27:54 +00002705
2706/*
2707 * Encode LAYOUTCOMMIT request
2708 */
2709static int nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2710 struct xdr_stream *xdr,
2711 struct nfs4_layoutcommit_args *args)
2712{
2713 struct compound_hdr hdr = {
2714 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2715 };
2716
2717 encode_compound_hdr(xdr, req, &hdr);
2718 encode_sequence(xdr, &args->seq_args, &hdr);
2719 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2720 encode_layoutcommit(xdr, args, &hdr);
2721 encode_getfattr(xdr, args->bitmask, &hdr);
2722 encode_nops(&hdr);
2723 return 0;
2724}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002725#endif /* CONFIG_NFS_V4_1 */
2726
Benny Halevy686841b2009-08-14 17:19:48 +03002727static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2728{
2729 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2730 "Remaining buffer length is %tu words.\n",
2731 func, xdr->end - xdr->p);
2732}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733
Trond Myklebust683b57b2006-06-09 09:34:22 -04002734static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735{
Al Viro8687b632006-10-19 23:28:48 -07002736 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737
Benny Halevyc0eae662009-08-14 17:20:14 +03002738 p = xdr_inline_decode(xdr, 4);
2739 if (unlikely(!p))
2740 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002741 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002742 p = xdr_inline_decode(xdr, *len);
2743 if (unlikely(!p))
2744 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 *string = (char *)p;
2746 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002747out_overflow:
2748 print_overflow_msg(__func__, xdr);
2749 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750}
2751
2752static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2753{
Al Viro8687b632006-10-19 23:28:48 -07002754 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755
Benny Halevyc0eae662009-08-14 17:20:14 +03002756 p = xdr_inline_decode(xdr, 8);
2757 if (unlikely(!p))
2758 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002759 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002760 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002761
Benny Halevyc0eae662009-08-14 17:20:14 +03002762 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2763 if (unlikely(!p))
2764 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 hdr->tag = (char *)p;
2766 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002767 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002768 if (unlikely(hdr->nops < 1))
2769 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002771out_overflow:
2772 print_overflow_msg(__func__, xdr);
2773 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774}
2775
2776static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2777{
Al Viro8687b632006-10-19 23:28:48 -07002778 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 uint32_t opnum;
2780 int32_t nfserr;
2781
Benny Halevyc0eae662009-08-14 17:20:14 +03002782 p = xdr_inline_decode(xdr, 8);
2783 if (unlikely(!p))
2784 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002785 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002787 dprintk("nfs: Server returned operation"
2788 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 opnum, expected);
2790 return -EIO;
2791 }
Benny Halevycccddf42009-08-14 17:20:19 +03002792 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002794 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002796out_overflow:
2797 print_overflow_msg(__func__, xdr);
2798 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799}
2800
2801/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002802static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803{
Al Viro8687b632006-10-19 23:28:48 -07002804 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002805 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 char *str;
2807
Benny Halevyc0eae662009-08-14 17:20:14 +03002808 p = xdr_inline_decode(xdr, 12);
2809 if (likely(p))
2810 return decode_opaque_inline(xdr, &strlen, &str);
2811 print_overflow_msg(__func__, xdr);
2812 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813}
2814
2815static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2816{
Al Viro8687b632006-10-19 23:28:48 -07002817 uint32_t bmlen;
2818 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819
Benny Halevyc0eae662009-08-14 17:20:14 +03002820 p = xdr_inline_decode(xdr, 4);
2821 if (unlikely(!p))
2822 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002823 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824
2825 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002826 p = xdr_inline_decode(xdr, (bmlen << 2));
2827 if (unlikely(!p))
2828 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002830 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002832 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 }
2834 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002835out_overflow:
2836 print_overflow_msg(__func__, xdr);
2837 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838}
2839
Al Viro8687b632006-10-19 23:28:48 -07002840static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841{
Al Viro8687b632006-10-19 23:28:48 -07002842 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843
Benny Halevyc0eae662009-08-14 17:20:14 +03002844 p = xdr_inline_decode(xdr, 4);
2845 if (unlikely(!p))
2846 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002847 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 *savep = xdr->p;
2849 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002850out_overflow:
2851 print_overflow_msg(__func__, xdr);
2852 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853}
2854
2855static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2856{
2857 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04002858 int ret;
2859 ret = decode_attr_bitmap(xdr, bitmask);
2860 if (unlikely(ret < 0))
2861 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2863 } else
2864 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002865 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 return 0;
2867}
2868
2869static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2870{
Al Viro8687b632006-10-19 23:28:48 -07002871 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002872 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873
2874 *type = 0;
2875 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2876 return -EIO;
2877 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002878 p = xdr_inline_decode(xdr, 4);
2879 if (unlikely(!p))
2880 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002881 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002883 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 return -EIO;
2885 }
2886 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002887 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002889 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002890 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002891out_overflow:
2892 print_overflow_msg(__func__, xdr);
2893 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894}
2895
2896static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2897{
Al Viro8687b632006-10-19 23:28:48 -07002898 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002899 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900
2901 *change = 0;
2902 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2903 return -EIO;
2904 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002905 p = xdr_inline_decode(xdr, 8);
2906 if (unlikely(!p))
2907 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002908 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002910 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002912 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002914 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002915out_overflow:
2916 print_overflow_msg(__func__, xdr);
2917 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918}
2919
2920static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2921{
Al Viro8687b632006-10-19 23:28:48 -07002922 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002923 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924
2925 *size = 0;
2926 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2927 return -EIO;
2928 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002929 p = xdr_inline_decode(xdr, 8);
2930 if (unlikely(!p))
2931 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002932 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002934 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002936 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002937 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002938out_overflow:
2939 print_overflow_msg(__func__, xdr);
2940 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941}
2942
2943static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2944{
Al Viro8687b632006-10-19 23:28:48 -07002945 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946
2947 *res = 0;
2948 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2949 return -EIO;
2950 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002951 p = xdr_inline_decode(xdr, 4);
2952 if (unlikely(!p))
2953 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002954 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2956 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002957 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002959out_overflow:
2960 print_overflow_msg(__func__, xdr);
2961 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962}
2963
2964static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2965{
Al Viro8687b632006-10-19 23:28:48 -07002966 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
2968 *res = 0;
2969 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2970 return -EIO;
2971 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002972 p = xdr_inline_decode(xdr, 4);
2973 if (unlikely(!p))
2974 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002975 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2977 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002978 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002980out_overflow:
2981 print_overflow_msg(__func__, xdr);
2982 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983}
2984
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002985static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986{
Al Viro8687b632006-10-19 23:28:48 -07002987 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002988 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989
2990 fsid->major = 0;
2991 fsid->minor = 0;
2992 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2993 return -EIO;
2994 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002995 p = xdr_inline_decode(xdr, 16);
2996 if (unlikely(!p))
2997 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03002998 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03002999 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003001 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003003 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 (unsigned long long)fsid->major,
3005 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003006 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003007out_overflow:
3008 print_overflow_msg(__func__, xdr);
3009 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010}
3011
3012static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3013{
Al Viro8687b632006-10-19 23:28:48 -07003014 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015
3016 *res = 60;
3017 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3018 return -EIO;
3019 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003020 p = xdr_inline_decode(xdr, 4);
3021 if (unlikely(!p))
3022 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003023 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3025 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003026 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003028out_overflow:
3029 print_overflow_msg(__func__, xdr);
3030 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031}
3032
Bryan Schumakerae42c702010-10-21 16:33:17 -04003033static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
3034{
3035 __be32 *p;
3036
3037 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3038 return -EIO;
3039 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3040 p = xdr_inline_decode(xdr, 4);
3041 if (unlikely(!p))
3042 goto out_overflow;
3043 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Bryan Schumaker7ebb9312011-03-24 17:12:30 +00003044 return -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003045 }
3046 return 0;
3047out_overflow:
3048 print_overflow_msg(__func__, xdr);
3049 return -EIO;
3050}
3051
3052static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3053{
3054 __be32 *p;
3055 int len;
3056
Trond Myklebust7ad07352010-10-23 15:34:20 -04003057 if (fh != NULL)
3058 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003059
3060 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3061 return -EIO;
3062 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3063 p = xdr_inline_decode(xdr, 4);
3064 if (unlikely(!p))
3065 goto out_overflow;
3066 len = be32_to_cpup(p);
3067 if (len > NFS4_FHSIZE)
3068 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003069 p = xdr_inline_decode(xdr, len);
3070 if (unlikely(!p))
3071 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003072 if (fh != NULL) {
3073 memcpy(fh->data, p, len);
3074 fh->size = len;
3075 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003076 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3077 }
3078 return 0;
3079out_overflow:
3080 print_overflow_msg(__func__, xdr);
3081 return -EIO;
3082}
3083
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3085{
Al Viro8687b632006-10-19 23:28:48 -07003086 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087
3088 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3089 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3090 return -EIO;
3091 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003092 p = xdr_inline_decode(xdr, 4);
3093 if (unlikely(!p))
3094 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003095 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3097 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003098 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003100out_overflow:
3101 print_overflow_msg(__func__, xdr);
3102 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103}
3104
3105static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3106{
Al Viro8687b632006-10-19 23:28:48 -07003107 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003108 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109
3110 *fileid = 0;
3111 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3112 return -EIO;
3113 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003114 p = xdr_inline_decode(xdr, 8);
3115 if (unlikely(!p))
3116 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003117 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003119 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003121 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003122 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003123out_overflow:
3124 print_overflow_msg(__func__, xdr);
3125 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126}
3127
Manoj Naik99baf622006-06-09 09:34:24 -04003128static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3129{
Al Viro8687b632006-10-19 23:28:48 -07003130 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003131 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003132
3133 *fileid = 0;
3134 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3135 return -EIO;
3136 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003137 p = xdr_inline_decode(xdr, 8);
3138 if (unlikely(!p))
3139 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003140 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003141 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003142 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003143 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003144 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003145 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003146out_overflow:
3147 print_overflow_msg(__func__, xdr);
3148 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003149}
3150
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3152{
Al Viro8687b632006-10-19 23:28:48 -07003153 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 int status = 0;
3155
3156 *res = 0;
3157 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3158 return -EIO;
3159 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003160 p = xdr_inline_decode(xdr, 8);
3161 if (unlikely(!p))
3162 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003163 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3165 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003166 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003168out_overflow:
3169 print_overflow_msg(__func__, xdr);
3170 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171}
3172
3173static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3174{
Al Viro8687b632006-10-19 23:28:48 -07003175 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 int status = 0;
3177
3178 *res = 0;
3179 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3180 return -EIO;
3181 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003182 p = xdr_inline_decode(xdr, 8);
3183 if (unlikely(!p))
3184 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003185 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3187 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003188 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003190out_overflow:
3191 print_overflow_msg(__func__, xdr);
3192 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193}
3194
3195static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3196{
Al Viro8687b632006-10-19 23:28:48 -07003197 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 int status = 0;
3199
3200 *res = 0;
3201 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3202 return -EIO;
3203 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003204 p = xdr_inline_decode(xdr, 8);
3205 if (unlikely(!p))
3206 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003207 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3209 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003210 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003212out_overflow:
3213 print_overflow_msg(__func__, xdr);
3214 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215}
3216
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003217static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3218{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003219 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003220 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003221 int status = 0;
3222
Benny Halevyc0eae662009-08-14 17:20:14 +03003223 p = xdr_inline_decode(xdr, 4);
3224 if (unlikely(!p))
3225 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003226 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003227 if (n == 0)
3228 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003229 dprintk("path ");
3230 path->ncomponents = 0;
3231 while (path->ncomponents < n) {
3232 struct nfs4_string *component = &path->components[path->ncomponents];
3233 status = decode_opaque_inline(xdr, &component->len, &component->data);
3234 if (unlikely(status != 0))
3235 goto out_eio;
3236 if (path->ncomponents != n)
3237 dprintk("/");
3238 dprintk("%s", component->data);
3239 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3240 path->ncomponents++;
3241 else {
3242 dprintk("cannot parse %d components in path\n", n);
3243 goto out_eio;
3244 }
3245 }
3246out:
3247 dprintk("\n");
3248 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003249root_path:
3250/* a root pathname is sent as a zero component4 */
3251 path->ncomponents = 1;
3252 path->components[0].len=0;
3253 path->components[0].data=NULL;
3254 dprintk("path /\n");
3255 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003256out_eio:
3257 dprintk(" status %d", status);
3258 status = -EIO;
3259 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003260out_overflow:
3261 print_overflow_msg(__func__, xdr);
3262 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003263}
3264
3265static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003266{
3267 int n;
Al Viro8687b632006-10-19 23:28:48 -07003268 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003269 int status = -EIO;
3270
3271 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3272 goto out;
3273 status = 0;
3274 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3275 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003276 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003277 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003278 if (unlikely(status != 0))
3279 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003280 p = xdr_inline_decode(xdr, 4);
3281 if (unlikely(!p))
3282 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003283 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003284 if (n <= 0)
3285 goto out_eio;
3286 res->nlocations = 0;
3287 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003288 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003289 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003290
Benny Halevyc0eae662009-08-14 17:20:14 +03003291 p = xdr_inline_decode(xdr, 4);
3292 if (unlikely(!p))
3293 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003294 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003295
3296 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003297 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003298 while (loc->nservers < m) {
3299 struct nfs4_string *server = &loc->servers[loc->nservers];
3300 status = decode_opaque_inline(xdr, &server->len, &server->data);
3301 if (unlikely(status != 0))
3302 goto out_eio;
3303 dprintk("%s ", server->data);
3304 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3305 loc->nservers++;
3306 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003307 unsigned int i;
3308 dprintk("%s: using first %u of %u servers "
3309 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003310 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003311 NFS4_FS_LOCATION_MAXSERVERS,
3312 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003313 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003314 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003315 char *data;
3316 status = decode_opaque_inline(xdr, &len, &data);
3317 if (unlikely(status != 0))
3318 goto out_eio;
3319 }
3320 }
3321 }
3322 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003323 if (unlikely(status != 0))
3324 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003325 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003326 res->nlocations++;
3327 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003328 if (res->nlocations != 0)
3329 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003330out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003331 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003332 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003333out_overflow:
3334 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003335out_eio:
3336 status = -EIO;
3337 goto out;
3338}
3339
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3341{
Al Viro8687b632006-10-19 23:28:48 -07003342 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 int status = 0;
3344
3345 *res = 0;
3346 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3347 return -EIO;
3348 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003349 p = xdr_inline_decode(xdr, 8);
3350 if (unlikely(!p))
3351 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003352 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3354 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003355 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003357out_overflow:
3358 print_overflow_msg(__func__, xdr);
3359 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360}
3361
3362static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3363{
Al Viro8687b632006-10-19 23:28:48 -07003364 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 int status = 0;
3366
3367 *maxlink = 1;
3368 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3369 return -EIO;
3370 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003371 p = xdr_inline_decode(xdr, 4);
3372 if (unlikely(!p))
3373 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003374 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3376 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003377 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003379out_overflow:
3380 print_overflow_msg(__func__, xdr);
3381 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382}
3383
3384static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3385{
Al Viro8687b632006-10-19 23:28:48 -07003386 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 int status = 0;
3388
3389 *maxname = 1024;
3390 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3391 return -EIO;
3392 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003393 p = xdr_inline_decode(xdr, 4);
3394 if (unlikely(!p))
3395 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003396 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3398 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003399 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003401out_overflow:
3402 print_overflow_msg(__func__, xdr);
3403 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404}
3405
3406static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3407{
Al Viro8687b632006-10-19 23:28:48 -07003408 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 int status = 0;
3410
3411 *res = 1024;
3412 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3413 return -EIO;
3414 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3415 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003416 p = xdr_inline_decode(xdr, 8);
3417 if (unlikely(!p))
3418 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003419 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 if (maxread > 0x7FFFFFFF)
3421 maxread = 0x7FFFFFFF;
3422 *res = (uint32_t)maxread;
3423 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3424 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003425 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003427out_overflow:
3428 print_overflow_msg(__func__, xdr);
3429 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430}
3431
3432static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3433{
Al Viro8687b632006-10-19 23:28:48 -07003434 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 int status = 0;
3436
3437 *res = 1024;
3438 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3439 return -EIO;
3440 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3441 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003442 p = xdr_inline_decode(xdr, 8);
3443 if (unlikely(!p))
3444 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003445 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 if (maxwrite > 0x7FFFFFFF)
3447 maxwrite = 0x7FFFFFFF;
3448 *res = (uint32_t)maxwrite;
3449 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3450 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003451 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003453out_overflow:
3454 print_overflow_msg(__func__, xdr);
3455 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456}
3457
Trond Myklebustbca79472009-03-11 14:10:26 -04003458static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459{
Trond Myklebustbca79472009-03-11 14:10:26 -04003460 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003461 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003462 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463
3464 *mode = 0;
3465 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3466 return -EIO;
3467 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003468 p = xdr_inline_decode(xdr, 4);
3469 if (unlikely(!p))
3470 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003471 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003472 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003474 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003476 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003477 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003478out_overflow:
3479 print_overflow_msg(__func__, xdr);
3480 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481}
3482
3483static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3484{
Al Viro8687b632006-10-19 23:28:48 -07003485 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003486 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487
3488 *nlink = 1;
3489 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3490 return -EIO;
3491 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003492 p = xdr_inline_decode(xdr, 4);
3493 if (unlikely(!p))
3494 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003495 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003497 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003499 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003500 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003501out_overflow:
3502 print_overflow_msg(__func__, xdr);
3503 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504}
3505
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003506static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003507 const struct nfs_server *server, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508{
Al Viro8687b632006-10-19 23:28:48 -07003509 uint32_t len;
3510 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003511 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512
3513 *uid = -2;
3514 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3515 return -EIO;
3516 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003517 p = xdr_inline_decode(xdr, 4);
3518 if (unlikely(!p))
3519 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003520 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003521 p = xdr_inline_decode(xdr, len);
3522 if (unlikely(!p))
3523 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003524 if (!may_sleep) {
3525 /* do nothing */
3526 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003527 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003528 ret = NFS_ATTR_FATTR_OWNER;
3529 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003531 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003533 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003534 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3536 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003537 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003538 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003539out_overflow:
3540 print_overflow_msg(__func__, xdr);
3541 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542}
3543
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003544static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003545 const struct nfs_server *server, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546{
Al Viro8687b632006-10-19 23:28:48 -07003547 uint32_t len;
3548 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003549 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550
3551 *gid = -2;
3552 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3553 return -EIO;
3554 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003555 p = xdr_inline_decode(xdr, 4);
3556 if (unlikely(!p))
3557 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003558 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003559 p = xdr_inline_decode(xdr, len);
3560 if (unlikely(!p))
3561 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003562 if (!may_sleep) {
3563 /* do nothing */
3564 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003565 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003566 ret = NFS_ATTR_FATTR_GROUP;
3567 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003569 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003571 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003572 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3574 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003575 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003576 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003577out_overflow:
3578 print_overflow_msg(__func__, xdr);
3579 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580}
3581
3582static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3583{
Al Viro8687b632006-10-19 23:28:48 -07003584 uint32_t major = 0, minor = 0;
3585 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003586 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587
3588 *rdev = MKDEV(0,0);
3589 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3590 return -EIO;
3591 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3592 dev_t tmp;
3593
Benny Halevyc0eae662009-08-14 17:20:14 +03003594 p = xdr_inline_decode(xdr, 8);
3595 if (unlikely(!p))
3596 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003597 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003598 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599 tmp = MKDEV(major, minor);
3600 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3601 *rdev = tmp;
3602 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003603 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003605 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003606 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003607out_overflow:
3608 print_overflow_msg(__func__, xdr);
3609 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610}
3611
3612static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3613{
Al Viro8687b632006-10-19 23:28:48 -07003614 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 int status = 0;
3616
3617 *res = 0;
3618 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3619 return -EIO;
3620 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003621 p = xdr_inline_decode(xdr, 8);
3622 if (unlikely(!p))
3623 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003624 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3626 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003627 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003629out_overflow:
3630 print_overflow_msg(__func__, xdr);
3631 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632}
3633
3634static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3635{
Al Viro8687b632006-10-19 23:28:48 -07003636 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 int status = 0;
3638
3639 *res = 0;
3640 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3641 return -EIO;
3642 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003643 p = xdr_inline_decode(xdr, 8);
3644 if (unlikely(!p))
3645 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003646 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3648 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003649 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003651out_overflow:
3652 print_overflow_msg(__func__, xdr);
3653 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654}
3655
3656static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3657{
Al Viro8687b632006-10-19 23:28:48 -07003658 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 int status = 0;
3660
3661 *res = 0;
3662 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3663 return -EIO;
3664 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003665 p = xdr_inline_decode(xdr, 8);
3666 if (unlikely(!p))
3667 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003668 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3670 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003671 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003673out_overflow:
3674 print_overflow_msg(__func__, xdr);
3675 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676}
3677
3678static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3679{
Al Viro8687b632006-10-19 23:28:48 -07003680 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003681 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682
3683 *used = 0;
3684 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3685 return -EIO;
3686 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003687 p = xdr_inline_decode(xdr, 8);
3688 if (unlikely(!p))
3689 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003690 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003692 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003694 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003696 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003697out_overflow:
3698 print_overflow_msg(__func__, xdr);
3699 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700}
3701
3702static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3703{
Al Viro8687b632006-10-19 23:28:48 -07003704 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 uint64_t sec;
3706 uint32_t nsec;
3707
Benny Halevyc0eae662009-08-14 17:20:14 +03003708 p = xdr_inline_decode(xdr, 12);
3709 if (unlikely(!p))
3710 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003711 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003712 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 time->tv_sec = (time_t)sec;
3714 time->tv_nsec = (long)nsec;
3715 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003716out_overflow:
3717 print_overflow_msg(__func__, xdr);
3718 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719}
3720
3721static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3722{
3723 int status = 0;
3724
3725 time->tv_sec = 0;
3726 time->tv_nsec = 0;
3727 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3728 return -EIO;
3729 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3730 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003731 if (status == 0)
3732 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3734 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003735 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 return status;
3737}
3738
3739static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3740{
3741 int status = 0;
3742
3743 time->tv_sec = 0;
3744 time->tv_nsec = 0;
3745 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3746 return -EIO;
3747 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3748 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003749 if (status == 0)
3750 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3752 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003753 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 return status;
3755}
3756
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003757static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3758 struct timespec *time)
3759{
3760 int status = 0;
3761
3762 time->tv_sec = 0;
3763 time->tv_nsec = 0;
3764 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3765 return -EIO;
3766 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3767 status = decode_attr_time(xdr, time);
3768 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3769 }
3770 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3771 (long)time->tv_nsec);
3772 return status;
3773}
3774
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3776{
3777 int status = 0;
3778
3779 time->tv_sec = 0;
3780 time->tv_nsec = 0;
3781 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3782 return -EIO;
3783 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3784 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003785 if (status == 0)
3786 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3788 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003789 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 return status;
3791}
3792
Al Viro8687b632006-10-19 23:28:48 -07003793static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794{
3795 unsigned int attrwords = XDR_QUADLEN(attrlen);
3796 unsigned int nwords = xdr->p - savep;
3797
3798 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003799 dprintk("%s: server returned incorrect attribute length: "
3800 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003801 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 attrwords << 2,
3803 (attrwords < nwords) ? '<' : '>',
3804 nwords << 2);
3805 return -EIO;
3806 }
3807 return 0;
3808}
3809
3810static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3811{
Al Viro8687b632006-10-19 23:28:48 -07003812 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813
Benny Halevyc0eae662009-08-14 17:20:14 +03003814 p = xdr_inline_decode(xdr, 20);
3815 if (unlikely(!p))
3816 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003817 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003818 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003819 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003821out_overflow:
3822 print_overflow_msg(__func__, xdr);
3823 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824}
3825
3826static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3827{
Al Viro8687b632006-10-19 23:28:48 -07003828 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 uint32_t supp, acc;
3830 int status;
3831
3832 status = decode_op_hdr(xdr, OP_ACCESS);
3833 if (status)
3834 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003835 p = xdr_inline_decode(xdr, 8);
3836 if (unlikely(!p))
3837 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003838 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003839 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 access->supported = supp;
3841 access->access = acc;
3842 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003843out_overflow:
3844 print_overflow_msg(__func__, xdr);
3845 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846}
3847
Benny Halevy07d30432009-08-14 17:19:52 +03003848static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849{
Al Viro8687b632006-10-19 23:28:48 -07003850 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003851
3852 p = xdr_inline_decode(xdr, len);
3853 if (likely(p)) {
3854 memcpy(buf, p, len);
3855 return 0;
3856 }
3857 print_overflow_msg(__func__, xdr);
3858 return -EIO;
3859}
3860
3861static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3862{
3863 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864}
3865
3866static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3867{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 int status;
3869
3870 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003871 if (status != -EIO)
3872 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003873 if (!status)
3874 status = decode_stateid(xdr, &res->stateid);
3875 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876}
3877
Benny Halevydb942bb2009-08-14 17:19:56 +03003878static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3879{
3880 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881}
3882
3883static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3884{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 int status;
3886
3887 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003888 if (!status)
3889 status = decode_verifier(xdr, res->verf->verifier);
3890 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891}
3892
3893static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3894{
Al Viro8687b632006-10-19 23:28:48 -07003895 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 uint32_t bmlen;
3897 int status;
3898
3899 status = decode_op_hdr(xdr, OP_CREATE);
3900 if (status)
3901 return status;
3902 if ((status = decode_change_info(xdr, cinfo)))
3903 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003904 p = xdr_inline_decode(xdr, 4);
3905 if (unlikely(!p))
3906 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003907 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003908 p = xdr_inline_decode(xdr, bmlen << 2);
3909 if (likely(p))
3910 return 0;
3911out_overflow:
3912 print_overflow_msg(__func__, xdr);
3913 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914}
3915
3916static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3917{
Al Viro8687b632006-10-19 23:28:48 -07003918 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003919 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920 int status;
3921
3922 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3923 goto xdr_error;
3924 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3925 goto xdr_error;
3926 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3927 goto xdr_error;
3928 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3929 goto xdr_error;
3930 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3931 goto xdr_error;
3932 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3933 goto xdr_error;
3934 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3935 goto xdr_error;
3936 status = verify_attr_len(xdr, savep, attrlen);
3937xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003938 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 return status;
3940}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003941
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3943{
Al Viro8687b632006-10-19 23:28:48 -07003944 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003945 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003947
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3949 goto xdr_error;
3950 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3951 goto xdr_error;
3952 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3953 goto xdr_error;
3954
3955 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3956 goto xdr_error;
3957 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3958 goto xdr_error;
3959 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3960 goto xdr_error;
3961 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3962 goto xdr_error;
3963 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3964 goto xdr_error;
3965 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3966 goto xdr_error;
3967
3968 status = verify_attr_len(xdr, savep, attrlen);
3969xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003970 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 return status;
3972}
3973
3974static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3975{
Al Viro8687b632006-10-19 23:28:48 -07003976 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003977 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003979
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3981 goto xdr_error;
3982 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3983 goto xdr_error;
3984 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3985 goto xdr_error;
3986
3987 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3988 goto xdr_error;
3989 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3990 goto xdr_error;
3991
3992 status = verify_attr_len(xdr, savep, attrlen);
3993xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003994 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 return status;
3996}
3997
Bryan Schumakerae42c702010-10-21 16:33:17 -04003998static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
3999 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004000 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001{
Trond Myklebustbca79472009-03-11 14:10:26 -04004002 int status;
4003 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004004 uint32_t type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004006 status = decode_attr_type(xdr, bitmap, &type);
4007 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004009 fattr->mode = 0;
4010 if (status != 0) {
4011 fattr->mode |= nfs_type2fmt[type];
4012 fattr->valid |= status;
4013 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004015 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4016 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004018 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004019
4020 status = decode_attr_size(xdr, bitmap, &fattr->size);
4021 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004023 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004024
4025 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4026 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004028 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004029
Bryan Schumakerae42c702010-10-21 16:33:17 -04004030 status = decode_attr_error(xdr, bitmap);
Bryan Schumaker7ebb9312011-03-24 17:12:30 +00004031 if (status == -NFS4ERR_WRONGSEC) {
4032 nfs_fixup_secinfo_attributes(fattr, fh);
4033 status = 0;
4034 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04004035 if (status < 0)
4036 goto xdr_error;
4037
4038 status = decode_attr_filehandle(xdr, bitmap, fh);
4039 if (status < 0)
4040 goto xdr_error;
4041
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004042 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4043 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004045 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004046
4047 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04004048 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004049 fattr));
4050 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004051 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004052 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004053
4054 status = decode_attr_mode(xdr, bitmap, &fmode);
4055 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004057 if (status != 0) {
4058 fattr->mode |= fmode;
4059 fattr->valid |= status;
4060 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004061
4062 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4063 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004065 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004066
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004067 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004068 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004070 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004071
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004072 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004073 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004075 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004076
4077 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4078 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004080 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004081
4082 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4083 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004085 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004086
4087 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4088 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004090 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004091
4092 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4093 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004095 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004096
4097 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4098 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004100 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004101
Trond Myklebust28331a42011-04-27 13:47:52 -04004102 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004103 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004104 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004105 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004106
Bryan Schumakerae42c702010-10-21 16:33:17 -04004107xdr_error:
4108 dprintk("%s: xdr returned %d\n", __func__, -status);
4109 return status;
4110}
4111
4112static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4113 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4114{
4115 __be32 *savep;
4116 uint32_t attrlen,
4117 bitmap[2] = {0};
4118 int status;
4119
4120 status = decode_op_hdr(xdr, OP_GETATTR);
4121 if (status < 0)
4122 goto xdr_error;
4123
4124 status = decode_attr_bitmap(xdr, bitmap);
4125 if (status < 0)
4126 goto xdr_error;
4127
4128 status = decode_attr_length(xdr, &attrlen, &savep);
4129 if (status < 0)
4130 goto xdr_error;
4131
4132 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4133 if (status < 0)
4134 goto xdr_error;
4135
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004136 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004138 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139 return status;
4140}
4141
Bryan Schumakerae42c702010-10-21 16:33:17 -04004142static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4143 const struct nfs_server *server, int may_sleep)
4144{
4145 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4146}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147
Andy Adamson504913f2010-10-20 00:17:57 -04004148/*
4149 * Decode potentially multiple layout types. Currently we only support
4150 * one layout driver per file system.
4151 */
4152static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4153 uint32_t *layouttype)
4154{
4155 uint32_t *p;
4156 int num;
4157
4158 p = xdr_inline_decode(xdr, 4);
4159 if (unlikely(!p))
4160 goto out_overflow;
4161 num = be32_to_cpup(p);
4162
4163 /* pNFS is not supported by the underlying file system */
4164 if (num == 0) {
4165 *layouttype = 0;
4166 return 0;
4167 }
4168 if (num > 1)
4169 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4170 "per filesystem not supported\n", __func__);
4171
4172 /* Decode and set first layout type, move xdr->p past unused types */
4173 p = xdr_inline_decode(xdr, num * 4);
4174 if (unlikely(!p))
4175 goto out_overflow;
4176 *layouttype = be32_to_cpup(p);
4177 return 0;
4178out_overflow:
4179 print_overflow_msg(__func__, xdr);
4180 return -EIO;
4181}
4182
4183/*
4184 * The type of file system exported.
4185 * Note we must ensure that layouttype is set in any non-error case.
4186 */
4187static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4188 uint32_t *layouttype)
4189{
4190 int status = 0;
4191
4192 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4193 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4194 return -EIO;
4195 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4196 status = decode_first_pnfs_layout_type(xdr, layouttype);
4197 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4198 } else
4199 *layouttype = 0;
4200 return status;
4201}
4202
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4204{
Al Viro8687b632006-10-19 23:28:48 -07004205 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206 uint32_t attrlen, bitmap[2];
4207 int status;
4208
4209 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4210 goto xdr_error;
4211 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4212 goto xdr_error;
4213 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4214 goto xdr_error;
4215
4216 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4217
4218 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4219 goto xdr_error;
4220 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4221 goto xdr_error;
4222 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4223 goto xdr_error;
4224 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4225 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4226 goto xdr_error;
4227 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004228 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4229 if (status != 0)
4230 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004231 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4232 if (status != 0)
4233 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234
4235 status = verify_attr_len(xdr, savep, attrlen);
4236xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004237 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238 return status;
4239}
4240
4241static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4242{
Al Viro8687b632006-10-19 23:28:48 -07004243 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004244 uint32_t len;
4245 int status;
4246
Trond Myklebust99367812007-07-17 21:52:41 -04004247 /* Zero handle first to allow comparisons */
4248 memset(fh, 0, sizeof(*fh));
4249
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250 status = decode_op_hdr(xdr, OP_GETFH);
4251 if (status)
4252 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253
Benny Halevyc0eae662009-08-14 17:20:14 +03004254 p = xdr_inline_decode(xdr, 4);
4255 if (unlikely(!p))
4256 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004257 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258 if (len > NFS4_FHSIZE)
4259 return -EIO;
4260 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004261 p = xdr_inline_decode(xdr, len);
4262 if (unlikely(!p))
4263 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004264 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004266out_overflow:
4267 print_overflow_msg(__func__, xdr);
4268 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269}
4270
4271static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4272{
4273 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004274
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275 status = decode_op_hdr(xdr, OP_LINK);
4276 if (status)
4277 return status;
4278 return decode_change_info(xdr, cinfo);
4279}
4280
4281/*
4282 * We create the owner, so we know a proper owner.id length is 4.
4283 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004284static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004286 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004287 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004288 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004290 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004291 if (unlikely(!p))
4292 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004293 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004294 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004295 type = be32_to_cpup(p++); /* 4 byte read */
4296 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004297 fl->fl_start = (loff_t)offset;
4298 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4299 if (length == ~(uint64_t)0)
4300 fl->fl_end = OFFSET_MAX;
4301 fl->fl_type = F_WRLCK;
4302 if (type & 1)
4303 fl->fl_type = F_RDLCK;
4304 fl->fl_pid = 0;
4305 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004306 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4307 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4308 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004309 if (likely(p))
4310 return -NFS4ERR_DENIED;
4311out_overflow:
4312 print_overflow_msg(__func__, xdr);
4313 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314}
4315
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004316static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 int status;
4319
4320 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004321 if (status == -EIO)
4322 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004324 status = decode_stateid(xdr, &res->stateid);
4325 if (unlikely(status))
4326 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004328 status = decode_lock_denied(xdr, NULL);
4329 if (res->open_seqid != NULL)
4330 nfs_increment_open_seqid(status, res->open_seqid);
4331 nfs_increment_lock_seqid(status, res->lock_seqid);
4332out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333 return status;
4334}
4335
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004336static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337{
4338 int status;
4339 status = decode_op_hdr(xdr, OP_LOCKT);
4340 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004341 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342 return status;
4343}
4344
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004345static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347 int status;
4348
4349 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004350 if (status != -EIO)
4351 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004352 if (status == 0)
4353 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354 return status;
4355}
4356
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004357static int decode_release_lockowner(struct xdr_stream *xdr)
4358{
4359 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4360}
4361
Linus Torvalds1da177e2005-04-16 15:20:36 -07004362static int decode_lookup(struct xdr_stream *xdr)
4363{
4364 return decode_op_hdr(xdr, OP_LOOKUP);
4365}
4366
4367/* This is too sick! */
4368static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4369{
Andy Adamson05d564f2008-12-23 16:06:15 -05004370 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371 uint32_t limit_type, nblocks, blocksize;
4372
Benny Halevyc0eae662009-08-14 17:20:14 +03004373 p = xdr_inline_decode(xdr, 12);
4374 if (unlikely(!p))
4375 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004376 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004378 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004379 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004380 break;
4381 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004382 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004383 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004384 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385 }
4386 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004387out_overflow:
4388 print_overflow_msg(__func__, xdr);
4389 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390}
4391
4392static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4393{
Andy Adamson05d564f2008-12-23 16:06:15 -05004394 __be32 *p;
4395 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004396 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397
Benny Halevyc0eae662009-08-14 17:20:14 +03004398 p = xdr_inline_decode(xdr, 4);
4399 if (unlikely(!p))
4400 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004401 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4403 res->delegation_type = 0;
4404 return 0;
4405 }
Benny Halevy07d30432009-08-14 17:19:52 +03004406 status = decode_stateid(xdr, &res->delegation);
4407 if (unlikely(status))
4408 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004409 p = xdr_inline_decode(xdr, 4);
4410 if (unlikely(!p))
4411 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004412 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004413
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004415 case NFS4_OPEN_DELEGATE_READ:
4416 res->delegation_type = FMODE_READ;
4417 break;
4418 case NFS4_OPEN_DELEGATE_WRITE:
4419 res->delegation_type = FMODE_WRITE|FMODE_READ;
4420 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 return -EIO;
4422 }
David Howells7539bba2006-08-22 20:06:09 -04004423 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004424out_overflow:
4425 print_overflow_msg(__func__, xdr);
4426 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427}
4428
4429static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4430{
Andy Adamson05d564f2008-12-23 16:06:15 -05004431 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004432 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004433 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004434
Andy Adamson05d564f2008-12-23 16:06:15 -05004435 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004436 if (status != -EIO)
4437 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004438 if (!status)
4439 status = decode_stateid(xdr, &res->stateid);
4440 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004441 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442
Andy Adamson05d564f2008-12-23 16:06:15 -05004443 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444
Benny Halevyc0eae662009-08-14 17:20:14 +03004445 p = xdr_inline_decode(xdr, 8);
4446 if (unlikely(!p))
4447 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004448 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004449 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004450 if (bmlen > 10)
4451 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004452
Benny Halevyc0eae662009-08-14 17:20:14 +03004453 p = xdr_inline_decode(xdr, bmlen << 2);
4454 if (unlikely(!p))
4455 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004456 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4457 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004458 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004459 for (; i < NFS4_BITMAP_SIZE; i++)
4460 res->attrset[i] = 0;
4461
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462 return decode_delegation(xdr, res);
4463xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004464 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004466out_overflow:
4467 print_overflow_msg(__func__, xdr);
4468 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469}
4470
4471static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4472{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473 int status;
4474
Andy Adamson05d564f2008-12-23 16:06:15 -05004475 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004476 if (status != -EIO)
4477 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004478 if (!status)
4479 status = decode_stateid(xdr, &res->stateid);
4480 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481}
4482
4483static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4484{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004485 int status;
4486
4487 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004488 if (status != -EIO)
4489 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004490 if (!status)
4491 status = decode_stateid(xdr, &res->stateid);
4492 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004493}
4494
4495static int decode_putfh(struct xdr_stream *xdr)
4496{
4497 return decode_op_hdr(xdr, OP_PUTFH);
4498}
4499
4500static int decode_putrootfh(struct xdr_stream *xdr)
4501{
4502 return decode_op_hdr(xdr, OP_PUTROOTFH);
4503}
4504
4505static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4506{
4507 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004508 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004509 uint32_t count, eof, recvd, hdrlen;
4510 int status;
4511
4512 status = decode_op_hdr(xdr, OP_READ);
4513 if (status)
4514 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004515 p = xdr_inline_decode(xdr, 8);
4516 if (unlikely(!p))
4517 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004518 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004519 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004520 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521 recvd = req->rq_rcv_buf.len - hdrlen;
4522 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004523 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004524 "count %u > recvd %u\n", count, recvd);
4525 count = recvd;
4526 eof = 0;
4527 }
4528 xdr_read_pages(xdr, count);
4529 res->eof = eof;
4530 res->count = count;
4531 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004532out_overflow:
4533 print_overflow_msg(__func__, xdr);
4534 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004535}
4536
4537static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4538{
4539 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004540 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004541 size_t hdrlen;
4542 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004543 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004544
4545 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004546 if (!status)
4547 status = decode_verifier(xdr, readdir->verifier.data);
4548 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004550 dprintk("%s: verifier = %08x:%08x\n",
4551 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004552 ((u32 *)readdir->verifier.data)[0],
4553 ((u32 *)readdir->verifier.data)[1]);
4554
Linus Torvalds1da177e2005-04-16 15:20:36 -07004555
Benny Halevydb942bb2009-08-14 17:19:56 +03004556 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 recvd = rcvbuf->len - hdrlen;
4558 if (pglen > recvd)
4559 pglen = recvd;
4560 xdr_read_pages(xdr, pglen);
4561
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004562
Trond Myklebustac396122010-11-15 20:26:22 -05004563 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004564}
4565
4566static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4567{
4568 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4569 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004570 size_t hdrlen;
4571 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004572 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573 int status;
4574
4575 status = decode_op_hdr(xdr, OP_READLINK);
4576 if (status)
4577 return status;
4578
4579 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004580 p = xdr_inline_decode(xdr, 4);
4581 if (unlikely(!p))
4582 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004583 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004584 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004585 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586 return -ENAMETOOLONG;
4587 }
4588 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4589 recvd = req->rq_rcv_buf.len - hdrlen;
4590 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004591 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 "count %u > recvd %u\n", len, recvd);
4593 return -EIO;
4594 }
4595 xdr_read_pages(xdr, len);
4596 /*
4597 * The XDR encode routine has set things up so that
4598 * the link text will be copied directly into the
4599 * buffer. We just have to do overflow-checking,
4600 * and and null-terminate the text (the VFS expects
4601 * null-termination).
4602 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004603 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004604 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004605out_overflow:
4606 print_overflow_msg(__func__, xdr);
4607 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608}
4609
4610static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4611{
4612 int status;
4613
4614 status = decode_op_hdr(xdr, OP_REMOVE);
4615 if (status)
4616 goto out;
4617 status = decode_change_info(xdr, cinfo);
4618out:
4619 return status;
4620}
4621
4622static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4623 struct nfs4_change_info *new_cinfo)
4624{
4625 int status;
4626
4627 status = decode_op_hdr(xdr, OP_RENAME);
4628 if (status)
4629 goto out;
4630 if ((status = decode_change_info(xdr, old_cinfo)))
4631 goto out;
4632 status = decode_change_info(xdr, new_cinfo);
4633out:
4634 return status;
4635}
4636
4637static int decode_renew(struct xdr_stream *xdr)
4638{
4639 return decode_op_hdr(xdr, OP_RENEW);
4640}
4641
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004642static int
4643decode_restorefh(struct xdr_stream *xdr)
4644{
4645 return decode_op_hdr(xdr, OP_RESTOREFH);
4646}
4647
J. Bruce Fields029d1052005-06-22 17:16:22 +00004648static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4649 size_t *acl_len)
4650{
Al Viro8687b632006-10-19 23:28:48 -07004651 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004652 uint32_t attrlen,
4653 bitmap[2] = {0};
4654 struct kvec *iov = req->rq_rcv_buf.head;
4655 int status;
4656
4657 *acl_len = 0;
4658 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4659 goto out;
4660 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4661 goto out;
4662 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4663 goto out;
4664
4665 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4666 return -EIO;
4667 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004668 size_t hdrlen;
4669 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004670
4671 /* We ignore &savep and don't do consistency checks on
4672 * the attr length. Let userspace figure it out.... */
4673 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4674 recvd = req->rq_rcv_buf.len - hdrlen;
4675 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004676 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004677 " acl reply: attrlen %u > recvd %u\n",
4678 attrlen, recvd);
4679 return -EINVAL;
4680 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004681 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004682 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004683 } else
4684 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004685
4686out:
4687 return status;
4688}
4689
Linus Torvalds1da177e2005-04-16 15:20:36 -07004690static int
4691decode_savefh(struct xdr_stream *xdr)
4692{
4693 return decode_op_hdr(xdr, OP_SAVEFH);
4694}
4695
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004696static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004697{
Al Viro8687b632006-10-19 23:28:48 -07004698 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004699 uint32_t bmlen;
4700 int status;
4701
Linus Torvalds1da177e2005-04-16 15:20:36 -07004702 status = decode_op_hdr(xdr, OP_SETATTR);
4703 if (status)
4704 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004705 p = xdr_inline_decode(xdr, 4);
4706 if (unlikely(!p))
4707 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004708 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004709 p = xdr_inline_decode(xdr, bmlen << 2);
4710 if (likely(p))
4711 return 0;
4712out_overflow:
4713 print_overflow_msg(__func__, xdr);
4714 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715}
4716
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004717static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718{
Al Viro8687b632006-10-19 23:28:48 -07004719 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720 uint32_t opnum;
4721 int32_t nfserr;
4722
Benny Halevyc0eae662009-08-14 17:20:14 +03004723 p = xdr_inline_decode(xdr, 8);
4724 if (unlikely(!p))
4725 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004726 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004727 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004728 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004729 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730 return -EIO;
4731 }
Benny Halevycccddf42009-08-14 17:20:19 +03004732 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004733 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004734 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4735 if (unlikely(!p))
4736 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004737 p = xdr_decode_hyper(p, &res->clientid);
4738 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739 } else if (nfserr == NFSERR_CLID_INUSE) {
4740 uint32_t len;
4741
4742 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004743 p = xdr_inline_decode(xdr, 4);
4744 if (unlikely(!p))
4745 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004746 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004747 p = xdr_inline_decode(xdr, len);
4748 if (unlikely(!p))
4749 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750
4751 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004752 p = xdr_inline_decode(xdr, 4);
4753 if (unlikely(!p))
4754 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004755 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004756 p = xdr_inline_decode(xdr, len);
4757 if (unlikely(!p))
4758 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759 return -NFSERR_CLID_INUSE;
4760 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004761 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762
4763 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004764out_overflow:
4765 print_overflow_msg(__func__, xdr);
4766 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767}
4768
4769static int decode_setclientid_confirm(struct xdr_stream *xdr)
4770{
4771 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4772}
4773
4774static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4775{
Al Viro8687b632006-10-19 23:28:48 -07004776 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777 int status;
4778
4779 status = decode_op_hdr(xdr, OP_WRITE);
4780 if (status)
4781 return status;
4782
Benny Halevyc0eae662009-08-14 17:20:14 +03004783 p = xdr_inline_decode(xdr, 16);
4784 if (unlikely(!p))
4785 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004786 res->count = be32_to_cpup(p++);
4787 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004788 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004790out_overflow:
4791 print_overflow_msg(__func__, xdr);
4792 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793}
4794
4795static int decode_delegreturn(struct xdr_stream *xdr)
4796{
4797 return decode_op_hdr(xdr, OP_DELEGRETURN);
4798}
4799
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004800static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
4801{
4802 __be32 *p;
4803
4804 p = xdr_inline_decode(xdr, 4);
4805 if (unlikely(!p))
4806 goto out_overflow;
4807 flavor->gss.sec_oid4.len = be32_to_cpup(p);
4808 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
4809 goto out_err;
4810
4811 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
4812 if (unlikely(!p))
4813 goto out_overflow;
4814 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
4815
4816 p = xdr_inline_decode(xdr, 8);
4817 if (unlikely(!p))
4818 goto out_overflow;
4819 flavor->gss.qop4 = be32_to_cpup(p++);
4820 flavor->gss.service = be32_to_cpup(p);
4821
4822 return 0;
4823
4824out_overflow:
4825 print_overflow_msg(__func__, xdr);
4826 return -EIO;
4827out_err:
4828 return -EINVAL;
4829}
4830
4831static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
4832{
4833 struct nfs4_secinfo_flavor *sec_flavor;
4834 int status;
4835 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004836 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004837
4838 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04004839 if (status)
4840 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004841 p = xdr_inline_decode(xdr, 4);
4842 if (unlikely(!p))
4843 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004844
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004845 res->flavors->num_flavors = 0;
4846 num_flavors = be32_to_cpup(p);
4847
4848 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004849 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004850 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004851 break;
4852
4853 p = xdr_inline_decode(xdr, 4);
4854 if (unlikely(!p))
4855 goto out_overflow;
4856 sec_flavor->flavor = be32_to_cpup(p);
4857
4858 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04004859 status = decode_secinfo_gss(xdr, sec_flavor);
4860 if (status)
4861 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004862 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004863 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004864 }
4865
Bryan Schumaker613e9012011-04-27 15:28:44 -04004866out:
4867 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004868out_overflow:
4869 print_overflow_msg(__func__, xdr);
4870 return -EIO;
4871}
4872
Benny Halevy99fe60d2009-04-01 09:22:29 -04004873#if defined(CONFIG_NFS_V4_1)
4874static int decode_exchange_id(struct xdr_stream *xdr,
4875 struct nfs41_exchange_id_res *res)
4876{
4877 __be32 *p;
4878 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004879 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004880 int status;
4881 struct nfs_client *clp = res->client;
4882
4883 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4884 if (status)
4885 return status;
4886
Benny Halevyc0eae662009-08-14 17:20:14 +03004887 p = xdr_inline_decode(xdr, 8);
4888 if (unlikely(!p))
4889 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05004890 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004891 p = xdr_inline_decode(xdr, 12);
4892 if (unlikely(!p))
4893 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004894 clp->cl_seqid = be32_to_cpup(p++);
4895 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004896
4897 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004898 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004899 if (dummy != SP4_NONE)
4900 return -EIO;
4901
4902 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004903 p = xdr_inline_decode(xdr, 8);
4904 if (unlikely(!p))
4905 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004906
4907 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004908 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4909 if (unlikely(status))
4910 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004911
4912 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004913 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4914 if (unlikely(status))
4915 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004916
4917 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004918 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4919 if (unlikely(status))
4920 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004921
4922 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004923out_overflow:
4924 print_overflow_msg(__func__, xdr);
4925 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004926}
Andy Adamsonfc931582009-04-01 09:22:31 -04004927
4928static int decode_chan_attrs(struct xdr_stream *xdr,
4929 struct nfs4_channel_attrs *attrs)
4930{
4931 __be32 *p;
4932 u32 nr_attrs;
4933
Benny Halevyc0eae662009-08-14 17:20:14 +03004934 p = xdr_inline_decode(xdr, 28);
4935 if (unlikely(!p))
4936 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004937 attrs->headerpadsz = be32_to_cpup(p++);
4938 attrs->max_rqst_sz = be32_to_cpup(p++);
4939 attrs->max_resp_sz = be32_to_cpup(p++);
4940 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4941 attrs->max_ops = be32_to_cpup(p++);
4942 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004943 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004944 if (unlikely(nr_attrs > 1)) {
4945 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4946 __func__, nr_attrs);
4947 return -EINVAL;
4948 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004949 if (nr_attrs == 1) {
4950 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4951 if (unlikely(!p))
4952 goto out_overflow;
4953 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004954 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004955out_overflow:
4956 print_overflow_msg(__func__, xdr);
4957 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004958}
4959
Benny Halevye78291e2009-08-14 17:20:00 +03004960static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4961{
4962 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004963}
4964
4965static int decode_create_session(struct xdr_stream *xdr,
4966 struct nfs41_create_session_res *res)
4967{
4968 __be32 *p;
4969 int status;
4970 struct nfs_client *clp = res->client;
4971 struct nfs4_session *session = clp->cl_session;
4972
4973 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004974 if (!status)
4975 status = decode_sessionid(xdr, &session->sess_id);
4976 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004977 return status;
4978
Andy Adamsonfc931582009-04-01 09:22:31 -04004979 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004980 p = xdr_inline_decode(xdr, 8);
4981 if (unlikely(!p))
4982 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004983 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004984 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004985
4986 /* Channel attributes */
4987 status = decode_chan_attrs(xdr, &session->fc_attrs);
4988 if (!status)
4989 status = decode_chan_attrs(xdr, &session->bc_attrs);
4990 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004991out_overflow:
4992 print_overflow_msg(__func__, xdr);
4993 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004994}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004995
4996static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4997{
4998 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4999}
Ricardo Labiaga18019752009-12-05 16:08:40 -05005000
5001static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5002{
5003 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5004}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005005#endif /* CONFIG_NFS_V4_1 */
5006
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005007static int decode_sequence(struct xdr_stream *xdr,
5008 struct nfs4_sequence_res *res,
5009 struct rpc_rqst *rqstp)
5010{
5011#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005012 struct nfs4_sessionid id;
5013 u32 dummy;
5014 int status;
5015 __be32 *p;
5016
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005017 if (!res->sr_session)
5018 return 0;
5019
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005020 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005021 if (!status)
5022 status = decode_sessionid(xdr, &id);
5023 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005024 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005025
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005026 /*
5027 * If the server returns different values for sessionID, slotID or
5028 * sequence number, the server is looney tunes.
5029 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005030 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005031
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005032 if (memcmp(id.data, res->sr_session->sess_id.data,
5033 NFS4_MAX_SESSIONID_LEN)) {
5034 dprintk("%s Invalid session id\n", __func__);
5035 goto out_err;
5036 }
Benny Halevye78291e2009-08-14 17:20:00 +03005037
Benny Halevyc0eae662009-08-14 17:20:14 +03005038 p = xdr_inline_decode(xdr, 20);
5039 if (unlikely(!p))
5040 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005041
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005042 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005043 dummy = be32_to_cpup(p++);
Benny Halevydfb4f302010-09-24 09:17:01 -04005044 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005045 dprintk("%s Invalid sequence number\n", __func__);
5046 goto out_err;
5047 }
5048 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005049 dummy = be32_to_cpup(p++);
Benny Halevydfb4f302010-09-24 09:17:01 -04005050 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005051 dprintk("%s Invalid slot id\n", __func__);
5052 goto out_err;
5053 }
5054 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005055 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005056 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005057 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005058 /* result flags */
5059 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005060 status = 0;
5061out_err:
5062 res->sr_status = status;
5063 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005064out_overflow:
5065 print_overflow_msg(__func__, xdr);
5066 status = -EIO;
5067 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005068#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005069 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005070#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005071}
5072
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005073#if defined(CONFIG_NFS_V4_1)
5074
5075static int decode_getdeviceinfo(struct xdr_stream *xdr,
5076 struct pnfs_device *pdev)
5077{
5078 __be32 *p;
5079 uint32_t len, type;
5080 int status;
5081
5082 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5083 if (status) {
5084 if (status == -ETOOSMALL) {
5085 p = xdr_inline_decode(xdr, 4);
5086 if (unlikely(!p))
5087 goto out_overflow;
5088 pdev->mincount = be32_to_cpup(p);
5089 dprintk("%s: Min count too small. mincnt = %u\n",
5090 __func__, pdev->mincount);
5091 }
5092 return status;
5093 }
5094
5095 p = xdr_inline_decode(xdr, 8);
5096 if (unlikely(!p))
5097 goto out_overflow;
5098 type = be32_to_cpup(p++);
5099 if (type != pdev->layout_type) {
5100 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5101 __func__, pdev->layout_type, type);
5102 return -EINVAL;
5103 }
5104 /*
5105 * Get the length of the opaque device_addr4. xdr_read_pages places
5106 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5107 * and places the remaining xdr data in xdr_buf->tail
5108 */
5109 pdev->mincount = be32_to_cpup(p);
5110 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5111
5112 /* Parse notification bitmap, verifying that it is zero. */
5113 p = xdr_inline_decode(xdr, 4);
5114 if (unlikely(!p))
5115 goto out_overflow;
5116 len = be32_to_cpup(p);
5117 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005118 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005119
5120 p = xdr_inline_decode(xdr, 4 * len);
5121 if (unlikely(!p))
5122 goto out_overflow;
5123 for (i = 0; i < len; i++, p++) {
5124 if (be32_to_cpup(p)) {
5125 dprintk("%s: notifications not supported\n",
5126 __func__);
5127 return -EIO;
5128 }
5129 }
5130 }
5131 return 0;
5132out_overflow:
5133 print_overflow_msg(__func__, xdr);
5134 return -EIO;
5135}
5136
5137static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5138 struct nfs4_layoutget_res *res)
5139{
5140 __be32 *p;
5141 int status;
5142 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005143 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5144 struct kvec *iov = rcvbuf->head;
5145 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005146
5147 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5148 if (status)
5149 return status;
5150 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5151 if (unlikely(!p))
5152 goto out_overflow;
5153 res->return_on_close = be32_to_cpup(p++);
5154 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5155 layout_count = be32_to_cpup(p);
5156 if (!layout_count) {
5157 dprintk("%s: server responded with empty layout array\n",
5158 __func__);
5159 return -EINVAL;
5160 }
5161
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005162 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005163 if (unlikely(!p))
5164 goto out_overflow;
5165 p = xdr_decode_hyper(p, &res->range.offset);
5166 p = xdr_decode_hyper(p, &res->range.length);
5167 res->range.iomode = be32_to_cpup(p++);
5168 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005169 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005170
5171 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5172 __func__,
5173 (unsigned long)res->range.offset,
5174 (unsigned long)res->range.length,
5175 res->range.iomode,
5176 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005177 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005178
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005179 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5180 recvd = req->rq_rcv_buf.len - hdrlen;
5181 if (res->layoutp->len > recvd) {
5182 dprintk("NFS: server cheating in layoutget reply: "
5183 "layout len %u > recvd %u\n",
5184 res->layoutp->len, recvd);
5185 return -EINVAL;
5186 }
5187
5188 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005189
5190 if (layout_count > 1) {
5191 /* We only handle a length one array at the moment. Any
5192 * further entries are just ignored. Note that this means
5193 * the client may see a response that is less than the
5194 * minimum it requested.
5195 */
5196 dprintk("%s: server responded with %d layouts, dropping tail\n",
5197 __func__, layout_count);
5198 }
5199
5200 return 0;
5201out_overflow:
5202 print_overflow_msg(__func__, xdr);
5203 return -EIO;
5204}
Andy Adamson863a3c62011-03-23 13:27:54 +00005205
5206static int decode_layoutcommit(struct xdr_stream *xdr,
5207 struct rpc_rqst *req,
5208 struct nfs4_layoutcommit_res *res)
5209{
5210 __be32 *p;
5211 __u32 sizechanged;
5212 int status;
5213
5214 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5215 if (status)
5216 return status;
5217
5218 p = xdr_inline_decode(xdr, 4);
5219 if (unlikely(!p))
5220 goto out_overflow;
5221 sizechanged = be32_to_cpup(p);
5222
5223 if (sizechanged) {
5224 /* throw away new size */
5225 p = xdr_inline_decode(xdr, 8);
5226 if (unlikely(!p))
5227 goto out_overflow;
5228 }
5229 return 0;
5230out_overflow:
5231 print_overflow_msg(__func__, xdr);
5232 return -EIO;
5233}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005234#endif /* CONFIG_NFS_V4_1 */
5235
Linus Torvalds1da177e2005-04-16 15:20:36 -07005236/*
Benny Halevy49c25592008-12-23 16:06:16 -05005237 * END OF "GENERIC" DECODE ROUTINES.
5238 */
5239
5240/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005241 * Decode OPEN_DOWNGRADE response
5242 */
Chuck Leverbf269552010-12-14 14:59:29 +00005243static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5244 struct xdr_stream *xdr,
5245 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005246{
Andy Adamson05d564f2008-12-23 16:06:15 -05005247 struct compound_hdr hdr;
5248 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249
Chuck Leverbf269552010-12-14 14:59:29 +00005250 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005251 if (status)
5252 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005253 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005254 if (status)
5255 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005256 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005257 if (status)
5258 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005259 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005260 if (status != 0)
5261 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005262 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005263 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005264out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005265 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266}
5267
5268/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269 * Decode ACCESS response
5270 */
Chuck Leverbf269552010-12-14 14:59:29 +00005271static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5272 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005273{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274 struct compound_hdr hdr;
5275 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005276
Chuck Leverbf269552010-12-14 14:59:29 +00005277 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005278 if (status)
5279 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005280 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005281 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005283 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005284 if (status != 0)
5285 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005286 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005287 if (status != 0)
5288 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005289 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005290 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005291out:
5292 return status;
5293}
5294
5295/*
5296 * Decode LOOKUP response
5297 */
Chuck Leverbf269552010-12-14 14:59:29 +00005298static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5299 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005300{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005301 struct compound_hdr hdr;
5302 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005303
Chuck Leverbf269552010-12-14 14:59:29 +00005304 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005305 if (status)
5306 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005307 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005308 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005309 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005310 status = decode_putfh(xdr);
5311 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005312 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005313 status = decode_lookup(xdr);
5314 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005315 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005316 status = decode_getfh(xdr, res->fh);
5317 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005318 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005319 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005320 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005321out:
5322 return status;
5323}
5324
5325/*
5326 * Decode LOOKUP_ROOT response
5327 */
Chuck Leverbf269552010-12-14 14:59:29 +00005328static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5329 struct xdr_stream *xdr,
5330 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005331{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005332 struct compound_hdr hdr;
5333 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005334
Chuck Leverbf269552010-12-14 14:59:29 +00005335 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005336 if (status)
5337 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005338 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005339 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005340 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005341 status = decode_putrootfh(xdr);
5342 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005343 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005344 status = decode_getfh(xdr, res->fh);
5345 if (status == 0)
5346 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005347 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005348out:
5349 return status;
5350}
5351
5352/*
5353 * Decode REMOVE response
5354 */
Chuck Leverbf269552010-12-14 14:59:29 +00005355static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5356 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005357{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005358 struct compound_hdr hdr;
5359 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005360
Chuck Leverbf269552010-12-14 14:59:29 +00005361 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005362 if (status)
5363 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005364 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005365 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005366 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005367 status = decode_putfh(xdr);
5368 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005369 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005370 status = decode_remove(xdr, &res->cinfo);
5371 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005372 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005373 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005374 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005375out:
5376 return status;
5377}
5378
5379/*
5380 * Decode RENAME response
5381 */
Chuck Leverbf269552010-12-14 14:59:29 +00005382static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5383 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005384{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005385 struct compound_hdr hdr;
5386 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005387
Chuck Leverbf269552010-12-14 14:59:29 +00005388 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005389 if (status)
5390 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005391 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005392 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005393 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005394 status = decode_putfh(xdr);
5395 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005396 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005397 status = decode_savefh(xdr);
5398 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005399 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005400 status = decode_putfh(xdr);
5401 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005402 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005403 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5404 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005405 goto out;
5406 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005407 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005408 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005409 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005410 status = decode_restorefh(xdr);
5411 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005412 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005413 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005414 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005415out:
5416 return status;
5417}
5418
5419/*
5420 * Decode LINK response
5421 */
Chuck Leverbf269552010-12-14 14:59:29 +00005422static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5423 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005424{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005425 struct compound_hdr hdr;
5426 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005427
Chuck Leverbf269552010-12-14 14:59:29 +00005428 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005429 if (status)
5430 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005431 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005432 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005433 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005434 status = decode_putfh(xdr);
5435 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005436 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005437 status = decode_savefh(xdr);
5438 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005439 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005440 status = decode_putfh(xdr);
5441 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005442 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005443 status = decode_link(xdr, &res->cinfo);
5444 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005445 goto out;
5446 /*
5447 * Note order: OP_LINK leaves the directory as the current
5448 * filehandle.
5449 */
Chuck Leverbf269552010-12-14 14:59:29 +00005450 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005451 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005452 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005453 status = decode_restorefh(xdr);
5454 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005455 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005456 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005457 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005458out:
5459 return status;
5460}
5461
5462/*
5463 * Decode CREATE response
5464 */
Chuck Leverbf269552010-12-14 14:59:29 +00005465static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5466 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005467{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005468 struct compound_hdr hdr;
5469 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005470
Chuck Leverbf269552010-12-14 14:59:29 +00005471 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005472 if (status)
5473 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005474 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005475 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005476 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005477 status = decode_putfh(xdr);
5478 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005479 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005480 status = decode_savefh(xdr);
5481 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005482 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005483 status = decode_create(xdr, &res->dir_cinfo);
5484 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005485 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005486 status = decode_getfh(xdr, res->fh);
5487 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005488 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005489 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005490 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005491 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005492 status = decode_restorefh(xdr);
5493 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005494 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005495 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005496 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005497out:
5498 return status;
5499}
5500
5501/*
5502 * Decode SYMLINK response
5503 */
Chuck Leverbf269552010-12-14 14:59:29 +00005504static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5505 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005506{
Chuck Leverbf269552010-12-14 14:59:29 +00005507 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005508}
5509
5510/*
5511 * Decode GETATTR response
5512 */
Chuck Leverbf269552010-12-14 14:59:29 +00005513static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5514 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005515{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005516 struct compound_hdr hdr;
5517 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005518
Chuck Leverbf269552010-12-14 14:59:29 +00005519 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005520 if (status)
5521 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005522 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005523 if (status)
5524 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005525 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005526 if (status)
5527 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005528 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005529 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005530out:
5531 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532}
5533
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005534/*
5535 * Encode an SETACL request
5536 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005537static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5538 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005539{
Andy Adamson05d564f2008-12-23 16:06:15 -05005540 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005541 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005542 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005543
Chuck Lever9f06c712010-12-14 14:59:18 +00005544 encode_compound_hdr(xdr, req, &hdr);
5545 encode_sequence(xdr, &args->seq_args, &hdr);
5546 encode_putfh(xdr, args->fh, &hdr);
5547 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005548 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005549}
Andy Adamson05d564f2008-12-23 16:06:15 -05005550
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005551/*
5552 * Decode SETACL response
5553 */
5554static int
Chuck Leverbf269552010-12-14 14:59:29 +00005555nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005556 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005557{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005558 struct compound_hdr hdr;
5559 int status;
5560
Chuck Leverbf269552010-12-14 14:59:29 +00005561 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005562 if (status)
5563 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005564 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005565 if (status)
5566 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005567 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005568 if (status)
5569 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005570 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005571out:
5572 return status;
5573}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005574
5575/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005576 * Decode GETACL response
5577 */
5578static int
Chuck Leverbf269552010-12-14 14:59:29 +00005579nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005580 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005581{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005582 struct compound_hdr hdr;
5583 int status;
5584
Chuck Leverbf269552010-12-14 14:59:29 +00005585 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005586 if (status)
5587 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005588 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005589 if (status)
5590 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005591 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005592 if (status)
5593 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005594 status = decode_getacl(xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005595
5596out:
5597 return status;
5598}
5599
5600/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005601 * Decode CLOSE response
5602 */
Chuck Leverbf269552010-12-14 14:59:29 +00005603static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5604 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005605{
Andy Adamson05d564f2008-12-23 16:06:15 -05005606 struct compound_hdr hdr;
5607 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005608
Chuck Leverbf269552010-12-14 14:59:29 +00005609 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005610 if (status)
5611 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005612 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005613 if (status)
5614 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005615 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005616 if (status)
5617 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005618 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005619 if (status != 0)
5620 goto out;
5621 /*
5622 * Note: Server may do delete on close for this file
5623 * in which case the getattr call will fail with
5624 * an ESTALE error. Shouldn't be a problem,
5625 * though, since fattr->valid will remain unset.
5626 */
Chuck Leverbf269552010-12-14 14:59:29 +00005627 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005628 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005629out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005630 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005631}
5632
5633/*
5634 * Decode OPEN response
5635 */
Chuck Leverbf269552010-12-14 14:59:29 +00005636static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5637 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005638{
Andy Adamson05d564f2008-12-23 16:06:15 -05005639 struct compound_hdr hdr;
5640 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005641
Chuck Leverbf269552010-12-14 14:59:29 +00005642 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005643 if (status)
5644 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005645 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005646 if (status)
5647 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005648 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005649 if (status)
5650 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005651 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005652 if (status)
5653 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005654 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005655 if (status)
5656 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005657 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005658 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005659 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005660 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005661 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005662 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005663 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005664 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005665 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005666out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005667 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005668}
5669
5670/*
5671 * Decode OPEN_CONFIRM response
5672 */
Chuck Leverbf269552010-12-14 14:59:29 +00005673static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5674 struct xdr_stream *xdr,
5675 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005676{
Andy Adamson05d564f2008-12-23 16:06:15 -05005677 struct compound_hdr hdr;
5678 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005679
Chuck Leverbf269552010-12-14 14:59:29 +00005680 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005681 if (status)
5682 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005683 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005684 if (status)
5685 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005686 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005687out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005688 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005689}
5690
5691/*
5692 * Decode OPEN response
5693 */
Chuck Leverbf269552010-12-14 14:59:29 +00005694static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5695 struct xdr_stream *xdr,
5696 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005697{
Andy Adamson05d564f2008-12-23 16:06:15 -05005698 struct compound_hdr hdr;
5699 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005700
Chuck Leverbf269552010-12-14 14:59:29 +00005701 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005702 if (status)
5703 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005704 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005705 if (status)
5706 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005707 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005708 if (status)
5709 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005710 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005711 if (status)
5712 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005713 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005714 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005715out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005716 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005717}
5718
5719/*
5720 * Decode SETATTR response
5721 */
Chuck Leverbf269552010-12-14 14:59:29 +00005722static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5723 struct xdr_stream *xdr,
5724 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005725{
Andy Adamson05d564f2008-12-23 16:06:15 -05005726 struct compound_hdr hdr;
5727 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005728
Chuck Leverbf269552010-12-14 14:59:29 +00005729 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005730 if (status)
5731 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005732 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005733 if (status)
5734 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005735 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005736 if (status)
5737 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005738 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005739 if (status)
5740 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005741 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005742 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005743out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005744 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745}
5746
5747/*
5748 * Decode LOCK response
5749 */
Chuck Leverbf269552010-12-14 14:59:29 +00005750static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5751 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005752{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005753 struct compound_hdr hdr;
5754 int status;
5755
Chuck Leverbf269552010-12-14 14:59:29 +00005756 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005757 if (status)
5758 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005759 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005760 if (status)
5761 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005762 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005763 if (status)
5764 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005765 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005766out:
5767 return status;
5768}
5769
5770/*
5771 * Decode LOCKT response
5772 */
Chuck Leverbf269552010-12-14 14:59:29 +00005773static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5774 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005775{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005776 struct compound_hdr hdr;
5777 int status;
5778
Chuck Leverbf269552010-12-14 14:59:29 +00005779 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005780 if (status)
5781 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005782 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005783 if (status)
5784 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005785 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005786 if (status)
5787 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005788 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005789out:
5790 return status;
5791}
5792
5793/*
5794 * Decode LOCKU response
5795 */
Chuck Leverbf269552010-12-14 14:59:29 +00005796static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5797 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005798{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799 struct compound_hdr hdr;
5800 int status;
5801
Chuck Leverbf269552010-12-14 14:59:29 +00005802 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005803 if (status)
5804 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005805 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005806 if (status)
5807 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005808 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005809 if (status)
5810 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005811 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005812out:
5813 return status;
5814}
5815
Chuck Leverbf269552010-12-14 14:59:29 +00005816static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5817 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005818{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005819 struct compound_hdr hdr;
5820 int status;
5821
Chuck Leverbf269552010-12-14 14:59:29 +00005822 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005823 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005824 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005825 return status;
5826}
5827
Linus Torvalds1da177e2005-04-16 15:20:36 -07005828/*
5829 * Decode READLINK response
5830 */
Chuck Leverbf269552010-12-14 14:59:29 +00005831static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5832 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04005833 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005834{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005835 struct compound_hdr hdr;
5836 int status;
5837
Chuck Leverbf269552010-12-14 14:59:29 +00005838 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005839 if (status)
5840 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005841 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005842 if (status)
5843 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005844 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845 if (status)
5846 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005847 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005848out:
5849 return status;
5850}
5851
5852/*
5853 * Decode READDIR response
5854 */
Chuck Leverbf269552010-12-14 14:59:29 +00005855static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5856 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005858 struct compound_hdr hdr;
5859 int status;
5860
Chuck Leverbf269552010-12-14 14:59:29 +00005861 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862 if (status)
5863 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005864 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005865 if (status)
5866 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005867 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868 if (status)
5869 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005870 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005871out:
5872 return status;
5873}
5874
5875/*
5876 * Decode Read response
5877 */
Chuck Leverbf269552010-12-14 14:59:29 +00005878static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5879 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005880{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005881 struct compound_hdr hdr;
5882 int status;
5883
Chuck Leverbf269552010-12-14 14:59:29 +00005884 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005885 if (status)
5886 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005887 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005888 if (status)
5889 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005890 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005891 if (status)
5892 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005893 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005894 if (!status)
5895 status = res->count;
5896out:
5897 return status;
5898}
5899
5900/*
5901 * Decode WRITE response
5902 */
Chuck Leverbf269552010-12-14 14:59:29 +00005903static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5904 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005905{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005906 struct compound_hdr hdr;
5907 int status;
5908
Chuck Leverbf269552010-12-14 14:59:29 +00005909 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005910 if (status)
5911 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005912 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005913 if (status)
5914 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005915 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005916 if (status)
5917 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005918 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005919 if (status)
5920 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00005921 if (res->fattr)
5922 decode_getfattr(xdr, res->fattr, res->server,
5923 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005924 if (!status)
5925 status = res->count;
5926out:
5927 return status;
5928}
5929
5930/*
5931 * Decode COMMIT response
5932 */
Chuck Leverbf269552010-12-14 14:59:29 +00005933static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5934 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005935{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005936 struct compound_hdr hdr;
5937 int status;
5938
Chuck Leverbf269552010-12-14 14:59:29 +00005939 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940 if (status)
5941 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005942 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005943 if (status)
5944 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005945 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005946 if (status)
5947 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005948 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005949 if (status)
5950 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00005951 if (res->fattr)
5952 decode_getfattr(xdr, res->fattr, res->server,
5953 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954out:
5955 return status;
5956}
5957
5958/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005959 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005960 */
Chuck Leverbf269552010-12-14 14:59:29 +00005961static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04005962 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005964 struct compound_hdr hdr;
5965 int status;
5966
Chuck Leverbf269552010-12-14 14:59:29 +00005967 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005968 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005969 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005970 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005971 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005973 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005974 return status;
5975}
5976
5977/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005978 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979 */
Chuck Leverbf269552010-12-14 14:59:29 +00005980static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04005981 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005982{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005983 struct compound_hdr hdr;
5984 int status;
5985
Chuck Leverbf269552010-12-14 14:59:29 +00005986 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005987 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005988 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005989 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005990 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005991 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005992 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005993 return status;
5994}
5995
5996/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005997 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005998 */
Chuck Leverbf269552010-12-14 14:59:29 +00005999static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006000 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006001{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006002 struct compound_hdr hdr;
6003 int status;
6004
Chuck Leverbf269552010-12-14 14:59:29 +00006005 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006006 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006007 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006008 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006009 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006011 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012 return status;
6013}
6014
6015/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006016 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006017 */
Chuck Leverbf269552010-12-14 14:59:29 +00006018static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6019 struct xdr_stream *xdr,
6020 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006021{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006022 struct compound_hdr hdr;
6023 int status;
6024
Chuck Leverbf269552010-12-14 14:59:29 +00006025 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006026 if (status)
6027 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006028 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006029 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006031 status = decode_putfh(xdr);
6032 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006033 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006034 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006035out:
6036 return status;
6037}
6038
6039/*
6040 * Decode RENEW response
6041 */
Chuck Leverbf269552010-12-14 14:59:29 +00006042static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6043 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006044{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006045 struct compound_hdr hdr;
6046 int status;
6047
Chuck Leverbf269552010-12-14 14:59:29 +00006048 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006049 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006050 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006051 return status;
6052}
6053
6054/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006055 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056 */
Chuck Leverbf269552010-12-14 14:59:29 +00006057static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6058 struct xdr_stream *xdr,
6059 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006060{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061 struct compound_hdr hdr;
6062 int status;
6063
Chuck Leverbf269552010-12-14 14:59:29 +00006064 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006065 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006066 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067 return status;
6068}
6069
6070/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006071 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006072 */
Chuck Leverbf269552010-12-14 14:59:29 +00006073static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6074 struct xdr_stream *xdr,
6075 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006076{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077 struct compound_hdr hdr;
6078 int status;
6079
Chuck Leverbf269552010-12-14 14:59:29 +00006080 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006082 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006084 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006085 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006086 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006087 return status;
6088}
6089
6090/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006091 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092 */
Chuck Leverbf269552010-12-14 14:59:29 +00006093static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6094 struct xdr_stream *xdr,
6095 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097 struct compound_hdr hdr;
6098 int status;
6099
Chuck Leverbf269552010-12-14 14:59:29 +00006100 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006101 if (status)
6102 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006103 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006104 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006105 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006106 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006107 if (status != 0)
6108 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006109 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006110 if (status != 0)
6111 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006112 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006113 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01006114out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006115 return status;
6116}
6117
Trond Myklebust683b57b2006-06-09 09:34:22 -04006118/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006119 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006120 */
Chuck Leverbf269552010-12-14 14:59:29 +00006121static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6122 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006123 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006124{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006125 struct compound_hdr hdr;
6126 int status;
6127
Chuck Leverbf269552010-12-14 14:59:29 +00006128 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006129 if (status)
6130 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006131 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006132 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006133 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006134 status = decode_putfh(xdr);
6135 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006136 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006137 status = decode_lookup(xdr);
6138 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006139 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006140 xdr_enter_page(xdr, PAGE_SIZE);
6141 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006142 res->fs_locations->server,
6143 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04006144out:
6145 return status;
6146}
6147
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006148/*
6149 * Decode SECINFO response
6150 */
6151static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6152 struct xdr_stream *xdr,
6153 struct nfs4_secinfo_res *res)
6154{
6155 struct compound_hdr hdr;
6156 int status;
6157
6158 status = decode_compound_hdr(xdr, &hdr);
6159 if (status)
6160 goto out;
6161 status = decode_sequence(xdr, &res->seq_res, rqstp);
6162 if (status)
6163 goto out;
6164 status = decode_putfh(xdr);
6165 if (status)
6166 goto out;
6167 status = decode_secinfo(xdr, res);
6168 if (status)
6169 goto out;
6170out:
6171 return status;
6172}
6173
Benny Halevy99fe60d2009-04-01 09:22:29 -04006174#if defined(CONFIG_NFS_V4_1)
6175/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006176 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006177 */
Chuck Leverbf269552010-12-14 14:59:29 +00006178static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6179 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006180 void *res)
6181{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006182 struct compound_hdr hdr;
6183 int status;
6184
Chuck Leverbf269552010-12-14 14:59:29 +00006185 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006186 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006187 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006188 return status;
6189}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006190
6191/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006192 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006193 */
Chuck Leverbf269552010-12-14 14:59:29 +00006194static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6195 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006196 struct nfs41_create_session_res *res)
6197{
Andy Adamsonfc931582009-04-01 09:22:31 -04006198 struct compound_hdr hdr;
6199 int status;
6200
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006202 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006203 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006204 return status;
6205}
6206
6207/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006208 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006209 */
Chuck Leverbf269552010-12-14 14:59:29 +00006210static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6211 struct xdr_stream *xdr,
6212 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006213{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006214 struct compound_hdr hdr;
6215 int status;
6216
Chuck Leverbf269552010-12-14 14:59:29 +00006217 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006218 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006219 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006220 return status;
6221}
6222
6223/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006224 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006225 */
Chuck Leverbf269552010-12-14 14:59:29 +00006226static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6227 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006228 struct nfs4_sequence_res *res)
6229{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006230 struct compound_hdr hdr;
6231 int status;
6232
Chuck Leverbf269552010-12-14 14:59:29 +00006233 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006234 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006235 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006236 return status;
6237}
6238
6239/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006240 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006241 */
Chuck Leverbf269552010-12-14 14:59:29 +00006242static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6243 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006244 struct nfs4_get_lease_time_res *res)
6245{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006246 struct compound_hdr hdr;
6247 int status;
6248
Chuck Leverbf269552010-12-14 14:59:29 +00006249 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006250 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006251 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006252 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006253 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006254 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006256 return status;
6257}
Ricardo Labiaga18019752009-12-05 16:08:40 -05006258
6259/*
6260 * Decode RECLAIM_COMPLETE response
6261 */
Chuck Leverbf269552010-12-14 14:59:29 +00006262static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6263 struct xdr_stream *xdr,
Ricardo Labiaga18019752009-12-05 16:08:40 -05006264 struct nfs41_reclaim_complete_res *res)
6265{
Ricardo Labiaga18019752009-12-05 16:08:40 -05006266 struct compound_hdr hdr;
6267 int status;
6268
Chuck Leverbf269552010-12-14 14:59:29 +00006269 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006270 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006271 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006272 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006273 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006274 return status;
6275}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006276
6277/*
6278 * Decode GETDEVINFO response
6279 */
Chuck Leverbf269552010-12-14 14:59:29 +00006280static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6281 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006282 struct nfs4_getdeviceinfo_res *res)
6283{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006284 struct compound_hdr hdr;
6285 int status;
6286
Chuck Leverbf269552010-12-14 14:59:29 +00006287 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006288 if (status != 0)
6289 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006290 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006291 if (status != 0)
6292 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006293 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006294out:
6295 return status;
6296}
6297
6298/*
6299 * Decode LAYOUTGET response
6300 */
Chuck Leverbf269552010-12-14 14:59:29 +00006301static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6302 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006303 struct nfs4_layoutget_res *res)
6304{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006305 struct compound_hdr hdr;
6306 int status;
6307
Chuck Leverbf269552010-12-14 14:59:29 +00006308 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006309 if (status)
6310 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006311 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006312 if (status)
6313 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006314 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006315 if (status)
6316 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006317 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006318out:
6319 return status;
6320}
Andy Adamson863a3c62011-03-23 13:27:54 +00006321
6322/*
6323 * Decode LAYOUTCOMMIT response
6324 */
6325static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6326 struct xdr_stream *xdr,
6327 struct nfs4_layoutcommit_res *res)
6328{
6329 struct compound_hdr hdr;
6330 int status;
6331
6332 status = decode_compound_hdr(xdr, &hdr);
6333 if (status)
6334 goto out;
6335 status = decode_sequence(xdr, &res->seq_res, rqstp);
6336 if (status)
6337 goto out;
6338 status = decode_putfh(xdr);
6339 if (status)
6340 goto out;
6341 status = decode_layoutcommit(xdr, rqstp, res);
6342 if (status)
6343 goto out;
6344 decode_getfattr(xdr, res->fattr, res->server,
6345 !RPC_IS_ASYNC(rqstp->rq_task));
6346out:
6347 return status;
6348}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006349#endif /* CONFIG_NFS_V4_1 */
6350
Chuck Lever573c4e12010-12-14 14:58:11 +00006351/**
6352 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6353 * the local page cache.
6354 * @xdr: XDR stream where entry resides
6355 * @entry: buffer to fill in with entry data
6356 * @plus: boolean indicating whether this should be a readdirplus entry
6357 *
6358 * Returns zero if successful, otherwise a negative errno value is
6359 * returned.
6360 *
6361 * This function is not invoked during READDIR reply decoding, but
6362 * rather whenever an application invokes the getdents(2) system call
6363 * on a directory already in our cache.
6364 */
6365int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6366 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006367{
6368 uint32_t bitmap[2] = {0};
6369 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006370 __be32 *p = xdr_inline_decode(xdr, 4);
6371 if (unlikely(!p))
6372 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006373 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006374 p = xdr_inline_decode(xdr, 4);
6375 if (unlikely(!p))
6376 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006377 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006378 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006379 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006380 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381 }
6382
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006383 p = xdr_inline_decode(xdr, 12);
6384 if (unlikely(!p))
6385 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006386 entry->prev_cookie = entry->cookie;
6387 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006388 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006389
Trond Myklebust9af8c222010-10-24 11:52:55 -04006390 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006391 if (unlikely(!p))
6392 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006393 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006394
6395 /*
6396 * In case the server doesn't return an inode number,
6397 * we fake one here. (We don't use inode number 0,
6398 * since glibc seems to choke on it...)
6399 */
6400 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006401 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006402
Trond Myklebust9af8c222010-10-24 11:52:55 -04006403 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006404 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006405
6406 if (decode_attr_length(xdr, &len, &p) < 0)
6407 goto out_overflow;
6408
Chuck Lever573c4e12010-12-14 14:58:11 +00006409 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6410 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006411 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006412 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6413 entry->ino = entry->fattr->mounted_on_fileid;
6414 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006415 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 */