blob: 6870bc61ceec4083f80818c4a31f934dab3227b1 [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)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400258#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400259
260#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400261#define NFS4_MAX_MACHINE_NAME_LEN (64)
262
Benny Halevy99fe60d2009-04-01 09:22:29 -0400263#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
264 encode_verifier_maxsz + \
265 1 /* co_ownerid.len */ + \
266 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
267 1 /* flags */ + \
268 1 /* spa_how */ + \
269 0 /* SP4_NONE (for now) */ + \
270 1 /* zero implemetation id array */)
271#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
272 2 /* eir_clientid */ + \
273 1 /* eir_sequenceid */ + \
274 1 /* eir_flags */ + \
275 1 /* spr_how */ + \
276 0 /* SP4_NONE (for now) */ + \
277 2 /* eir_server_owner.so_minor_id */ + \
278 /* eir_server_owner.so_major_id<> */ \
279 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
280 /* eir_server_scope<> */ \
281 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
282 1 /* eir_server_impl_id array length */ + \
283 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400284#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
285#define decode_channel_attrs_maxsz (6 + \
286 1 /* ca_rdma_ird.len */ + \
287 1 /* ca_rdma_ird */)
288#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
289 2 /* csa_clientid */ + \
290 1 /* csa_sequence */ + \
291 1 /* csa_flags */ + \
292 encode_channel_attrs_maxsz + \
293 encode_channel_attrs_maxsz + \
294 1 /* csa_cb_program */ + \
295 1 /* csa_sec_parms.len (1) */ + \
296 1 /* cb_secflavor (AUTH_SYS) */ + \
297 1 /* stamp */ + \
298 1 /* machinename.len */ + \
299 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
300 1 /* uid */ + \
301 1 /* gid */ + \
302 1 /* gids.len (0) */)
303#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
304 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
305 1 /* csr_sequence */ + \
306 1 /* csr_flags */ + \
307 decode_channel_attrs_maxsz + \
308 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400309#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
310#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400311#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
312 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
313#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
314 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500315#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
316#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400317#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
318 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
319#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
320 1 /* layout type */ + \
321 1 /* opaque devaddr4 length */ + \
322 /* devaddr4 payload is read into page */ \
323 1 /* notification bitmap length */ + \
324 1 /* notification bitmap */)
325#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
326 encode_stateid_maxsz)
327#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
328 decode_stateid_maxsz + \
329 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000330#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
331 2 /* offset */ + \
332 2 /* length */ + \
333 1 /* reclaim */ + \
334 encode_stateid_maxsz + \
335 1 /* new offset (true) */ + \
336 2 /* last byte written */ + \
337 1 /* nt_timechanged (false) */ + \
338 1 /* layoutupdate4 layout type */ + \
339 1 /* NULL filelayout layoutupdate4 payload */)
340#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300341#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
342 encode_stateid_maxsz + \
343 1 /* FIXME: opaque lrf_body always empty at the moment */)
344#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
345 1 + decode_stateid_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400346#else /* CONFIG_NFS_V4_1 */
347#define encode_sequence_maxsz 0
348#define decode_sequence_maxsz 0
349#endif /* CONFIG_NFS_V4_1 */
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
352#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
353#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400354 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400356 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400358 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400360 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400362 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400364 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400366 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400368 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400370 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400372 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400374 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400376 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400378 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400380 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400381 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400383 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400385 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400386 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400388 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400390 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400391 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400393 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400395 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400396 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400398 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400399 encode_putfh_maxsz + \
400 encode_savefh_maxsz + \
401 encode_open_maxsz + \
402 encode_getfh_maxsz + \
403 encode_getattr_maxsz + \
404 encode_restorefh_maxsz + \
405 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400407 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400408 decode_putfh_maxsz + \
409 decode_savefh_maxsz + \
410 decode_open_maxsz + \
411 decode_getfh_maxsz + \
412 decode_getattr_maxsz + \
413 decode_restorefh_maxsz + \
414 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400415#define NFS4_enc_open_confirm_sz \
416 (compound_encode_hdr_maxsz + \
417 encode_putfh_maxsz + \
418 encode_open_confirm_maxsz)
419#define NFS4_dec_open_confirm_sz \
420 (compound_decode_hdr_maxsz + \
421 decode_putfh_maxsz + \
422 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400424 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400426 encode_open_maxsz + \
427 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400429 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400431 decode_open_maxsz + \
432 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define NFS4_enc_open_downgrade_sz \
434 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400435 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400436 encode_putfh_maxsz + \
437 encode_open_downgrade_maxsz + \
438 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#define NFS4_dec_open_downgrade_sz \
440 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400441 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400442 decode_putfh_maxsz + \
443 decode_open_downgrade_maxsz + \
444 decode_getattr_maxsz)
445#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400446 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400447 encode_putfh_maxsz + \
448 encode_close_maxsz + \
449 encode_getattr_maxsz)
450#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400451 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400452 decode_putfh_maxsz + \
453 decode_close_maxsz + \
454 decode_getattr_maxsz)
455#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400456 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400457 encode_putfh_maxsz + \
458 encode_setattr_maxsz + \
459 encode_getattr_maxsz)
460#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400461 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400462 decode_putfh_maxsz + \
463 decode_setattr_maxsz + \
464 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400466 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 encode_putfh_maxsz + \
468 encode_fsinfo_maxsz)
469#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400470 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 decode_putfh_maxsz + \
472 decode_fsinfo_maxsz)
473#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
474 encode_renew_maxsz)
475#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
476 decode_renew_maxsz)
477#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
478 encode_setclientid_maxsz)
479#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
480 decode_setclientid_maxsz)
481#define NFS4_enc_setclientid_confirm_sz \
482 (compound_encode_hdr_maxsz + \
483 encode_setclientid_confirm_maxsz + \
484 encode_putrootfh_maxsz + \
485 encode_fsinfo_maxsz)
486#define NFS4_dec_setclientid_confirm_sz \
487 (compound_decode_hdr_maxsz + \
488 decode_setclientid_confirm_maxsz + \
489 decode_putrootfh_maxsz + \
490 decode_fsinfo_maxsz)
491#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400494 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400498 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400500 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400502 encode_lockt_maxsz)
503#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400504 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400505 decode_putfh_maxsz + \
506 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400508 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400510 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400512 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400514 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400515#define NFS4_enc_release_lockowner_sz \
516 (compound_encode_hdr_maxsz + \
517 encode_lockowner_maxsz)
518#define NFS4_dec_release_lockowner_sz \
519 (compound_decode_hdr_maxsz + \
520 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400522 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400524 encode_access_maxsz + \
525 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400527 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400529 decode_access_maxsz + \
530 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400532 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 encode_putfh_maxsz + \
534 encode_getattr_maxsz)
535#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400536 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 decode_putfh_maxsz + \
538 decode_getattr_maxsz)
539#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400540 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 encode_putfh_maxsz + \
542 encode_lookup_maxsz + \
543 encode_getattr_maxsz + \
544 encode_getfh_maxsz)
545#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400548 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 decode_getattr_maxsz + \
550 decode_getfh_maxsz)
551#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400552 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 encode_putrootfh_maxsz + \
554 encode_getattr_maxsz + \
555 encode_getfh_maxsz)
556#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400557 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 decode_putrootfh_maxsz + \
559 decode_getattr_maxsz + \
560 decode_getfh_maxsz)
561#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400564 encode_remove_maxsz + \
565 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400567 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400569 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400570 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 encode_putfh_maxsz + \
574 encode_savefh_maxsz + \
575 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400576 encode_rename_maxsz + \
577 encode_getattr_maxsz + \
578 encode_restorefh_maxsz + \
579 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400581 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 decode_putfh_maxsz + \
583 decode_savefh_maxsz + \
584 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400585 decode_rename_maxsz + \
586 decode_getattr_maxsz + \
587 decode_restorefh_maxsz + \
588 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 encode_putfh_maxsz + \
592 encode_savefh_maxsz + \
593 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400594 encode_link_maxsz + \
595 decode_getattr_maxsz + \
596 encode_restorefh_maxsz + \
597 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400599 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 decode_putfh_maxsz + \
601 decode_savefh_maxsz + \
602 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400603 decode_link_maxsz + \
604 decode_getattr_maxsz + \
605 decode_restorefh_maxsz + \
606 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400608 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 encode_putfh_maxsz + \
610 encode_symlink_maxsz + \
611 encode_getattr_maxsz + \
612 encode_getfh_maxsz)
613#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400614 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 decode_putfh_maxsz + \
616 decode_symlink_maxsz + \
617 decode_getattr_maxsz + \
618 decode_getfh_maxsz)
619#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400620 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400622 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400624 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400626 encode_restorefh_maxsz + \
627 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400629 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400631 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400633 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400635 decode_restorefh_maxsz + \
636 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400638 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 encode_putfh_maxsz + \
640 encode_getattr_maxsz)
641#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 decode_putfh_maxsz + \
644 decode_getattr_maxsz)
645#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400646 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400648 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400652 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800655 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 encode_getattr_maxsz)
657#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400658 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800659 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 decode_getattr_maxsz)
661#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400662 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100664 encode_delegreturn_maxsz + \
665 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400667 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100668 decode_delegreturn_maxsz + \
669 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000670#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400671 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000672 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400673 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000674#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400675 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000676 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400677 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000678#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400679 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000680 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400681 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000682#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400683 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000684 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400685 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400686#define NFS4_enc_fs_locations_sz \
687 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400689 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400690 encode_lookup_maxsz + \
691 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400692#define NFS4_dec_fs_locations_sz \
693 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400694 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400695 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400696 decode_lookup_maxsz + \
697 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000698#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
699 encode_sequence_maxsz + \
700 encode_putfh_maxsz + \
701 encode_secinfo_maxsz)
702#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
703 decode_sequence_maxsz + \
704 decode_putfh_maxsz + \
705 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400706#if defined(CONFIG_NFS_V4_1)
707#define NFS4_enc_exchange_id_sz \
708 (compound_encode_hdr_maxsz + \
709 encode_exchange_id_maxsz)
710#define NFS4_dec_exchange_id_sz \
711 (compound_decode_hdr_maxsz + \
712 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400713#define NFS4_enc_create_session_sz \
714 (compound_encode_hdr_maxsz + \
715 encode_create_session_maxsz)
716#define NFS4_dec_create_session_sz \
717 (compound_decode_hdr_maxsz + \
718 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400719#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
720 encode_destroy_session_maxsz)
721#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
722 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400723#define NFS4_enc_sequence_sz \
724 (compound_decode_hdr_maxsz + \
725 encode_sequence_maxsz)
726#define NFS4_dec_sequence_sz \
727 (compound_decode_hdr_maxsz + \
728 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400729#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
730 encode_sequence_maxsz + \
731 encode_putrootfh_maxsz + \
732 encode_fsinfo_maxsz)
733#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
734 decode_sequence_maxsz + \
735 decode_putrootfh_maxsz + \
736 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500737#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
738 encode_sequence_maxsz + \
739 encode_reclaim_complete_maxsz)
740#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
741 decode_sequence_maxsz + \
742 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400743#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
744 encode_sequence_maxsz +\
745 encode_getdeviceinfo_maxsz)
746#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
747 decode_sequence_maxsz + \
748 decode_getdeviceinfo_maxsz)
749#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
750 encode_sequence_maxsz + \
751 encode_putfh_maxsz + \
752 encode_layoutget_maxsz)
753#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
754 decode_sequence_maxsz + \
755 decode_putfh_maxsz + \
756 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000757#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
758 encode_sequence_maxsz +\
759 encode_putfh_maxsz + \
760 encode_layoutcommit_maxsz + \
761 encode_getattr_maxsz)
762#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
763 decode_sequence_maxsz + \
764 decode_putfh_maxsz + \
765 decode_layoutcommit_maxsz + \
766 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300767#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
768 encode_sequence_maxsz + \
769 encode_putfh_maxsz + \
770 encode_layoutreturn_maxsz)
771#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
772 decode_sequence_maxsz + \
773 decode_putfh_maxsz + \
774 decode_layoutreturn_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500775
776const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
777 compound_encode_hdr_maxsz +
778 encode_sequence_maxsz +
779 encode_putfh_maxsz +
780 encode_getattr_maxsz) *
781 XDR_UNIT);
782
783const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
784 compound_decode_hdr_maxsz +
785 decode_sequence_maxsz +
786 decode_putfh_maxsz) *
787 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400788#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
Trond Myklebustbca79472009-03-11 14:10:26 -0400790static const umode_t nfs_type2fmt[] = {
791 [NF4BAD] = 0,
792 [NF4REG] = S_IFREG,
793 [NF4DIR] = S_IFDIR,
794 [NF4BLK] = S_IFBLK,
795 [NF4CHR] = S_IFCHR,
796 [NF4LNK] = S_IFLNK,
797 [NF4SOCK] = S_IFSOCK,
798 [NF4FIFO] = S_IFIFO,
799 [NF4ATTRDIR] = 0,
800 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801};
802
803struct compound_hdr {
804 int32_t status;
805 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500806 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 uint32_t taglen;
808 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400809 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400810 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811};
812
Benny Halevy13c65ce2009-08-14 17:19:25 +0300813static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
814{
815 __be32 *p = xdr_reserve_space(xdr, nbytes);
816 BUG_ON(!p);
817 return p;
818}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
820static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
821{
Al Viro8687b632006-10-19 23:28:48 -0700822 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
824 p = xdr_reserve_space(xdr, 4 + len);
825 BUG_ON(p == NULL);
826 xdr_encode_opaque(p, str, len);
827}
828
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400829static void encode_compound_hdr(struct xdr_stream *xdr,
830 struct rpc_rqst *req,
831 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832{
Al Viro8687b632006-10-19 23:28:48 -0700833 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400834 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400835
836 /* initialize running count of expected bytes in reply.
837 * NOTE: the replied tag SHOULD be the same is the one sent,
838 * but this is not required as a MUST for the server to do so. */
839 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
841 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
842 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300843 p = reserve_space(xdr, 4 + hdr->taglen + 8);
844 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300845 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500846 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300847 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500848}
849
850static void encode_nops(struct compound_hdr *hdr)
851{
Andy Adamsonfc931582009-04-01 09:22:31 -0400852 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500853 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854}
855
856static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
857{
Al Viro8687b632006-10-19 23:28:48 -0700858 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
860 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
861 BUG_ON(p == NULL);
862 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
863}
864
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500865static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866{
867 char owner_name[IDMAP_NAMESZ];
868 char owner_group[IDMAP_NAMESZ];
869 int owner_namelen = 0;
870 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700871 __be32 *p;
872 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 int len;
874 uint32_t bmval0 = 0;
875 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
877 /*
878 * We reserve enough space to write the entire attribute buffer at once.
879 * In the worst-case, this would be
880 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
881 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000882 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 */
884 len = 16;
885
886 /* Sigh */
887 if (iap->ia_valid & ATTR_SIZE)
888 len += 8;
889 if (iap->ia_valid & ATTR_MODE)
890 len += 4;
891 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800892 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400894 dprintk("nfs: couldn't resolve uid %d to string\n",
895 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 /* XXX */
897 strcpy(owner_name, "nobody");
898 owner_namelen = sizeof("nobody") - 1;
899 /* goto out; */
900 }
901 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
902 }
903 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800904 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400906 dprintk("nfs: couldn't resolve gid %d to string\n",
907 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 strcpy(owner_group, "nobody");
909 owner_grouplen = sizeof("nobody") - 1;
910 /* goto out; */
911 }
912 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
913 }
914 if (iap->ia_valid & ATTR_ATIME_SET)
915 len += 16;
916 else if (iap->ia_valid & ATTR_ATIME)
917 len += 4;
918 if (iap->ia_valid & ATTR_MTIME_SET)
919 len += 16;
920 else if (iap->ia_valid & ATTR_MTIME)
921 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300922 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 /*
925 * We write the bitmap length now, but leave the bitmap and the attribute
926 * buffer length to be backfilled at the end of this routine.
927 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300928 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 q = p;
930 p += 3;
931
932 if (iap->ia_valid & ATTR_SIZE) {
933 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300934 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 }
936 if (iap->ia_valid & ATTR_MODE) {
937 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300938 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 }
940 if (iap->ia_valid & ATTR_UID) {
941 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300942 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 }
944 if (iap->ia_valid & ATTR_GID) {
945 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300946 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 }
948 if (iap->ia_valid & ATTR_ATIME_SET) {
949 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300950 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
951 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -0400952 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
953 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 }
955 else if (iap->ia_valid & ATTR_ATIME) {
956 bmval1 |= FATTR4_WORD1_TIME_ACCESS_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 }
959 if (iap->ia_valid & ATTR_MTIME_SET) {
960 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300961 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
962 *p++ = cpu_to_be32(0);
963 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
964 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 }
966 else if (iap->ia_valid & ATTR_MTIME) {
967 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300968 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500970
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 /*
972 * Now we backfill the bitmap and the attribute buffer length.
973 */
974 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400975 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 len, ((char *)p - (char *)q) + 4);
977 BUG();
978 }
979 len = (char *)p - (char *)q - 12;
980 *q++ = htonl(bmval0);
981 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300982 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985}
986
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500987static void encode_access(struct xdr_stream *xdr, u32 access, 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);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300992 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +0300993 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500994 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400995 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996}
997
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500998static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999{
Al Viro8687b632006-10-19 23:28:48 -07001000 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
Benny Halevy13c65ce2009-08-14 17:19:25 +03001002 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001003 *p++ = cpu_to_be32(OP_CLOSE);
1004 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +03001005 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001006 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001007 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008}
1009
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001010static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011{
Al Viro8687b632006-10-19 23:28:48 -07001012 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001013
Benny Halevy13c65ce2009-08-14 17:19:25 +03001014 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001015 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001016 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001017 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001018 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001019 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020}
1021
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001022static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023{
Al Viro8687b632006-10-19 23:28:48 -07001024 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001025
Benny Halevy13c65ce2009-08-14 17:19:25 +03001026 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001027 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001028 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
1030 switch (create->ftype) {
1031 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001032 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001033 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001034 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 break;
1036
1037 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001038 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001039 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001040 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 break;
1042
1043 default:
1044 break;
1045 }
1046
Benny Halevy811652b2009-08-14 17:19:34 +03001047 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001048 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001049 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001051 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052}
1053
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001054static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055{
Andy Adamson05d564f2008-12-23 16:06:15 -05001056 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Benny Halevy13c65ce2009-08-14 17:19:25 +03001058 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001059 *p++ = cpu_to_be32(OP_GETATTR);
1060 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001061 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001062 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001063 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064}
1065
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001066static 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 -07001067{
Andy Adamson05d564f2008-12-23 16:06:15 -05001068 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Benny Halevy13c65ce2009-08-14 17:19:25 +03001070 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001071 *p++ = cpu_to_be32(OP_GETATTR);
1072 *p++ = cpu_to_be32(2);
1073 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001074 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001075 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001076 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077}
1078
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001079static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001081 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1082 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083}
1084
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001085static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001087 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1088 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089}
1090
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001091static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001092{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001093 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1094 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001095}
1096
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001097static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098{
Al Viro8687b632006-10-19 23:28:48 -07001099 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Benny Halevy13c65ce2009-08-14 17:19:25 +03001101 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001102 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001103 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001104 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105}
1106
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001107static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108{
Al Viro8687b632006-10-19 23:28:48 -07001109 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
Benny Halevy13c65ce2009-08-14 17:19:25 +03001111 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001112 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001113 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001114 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001115 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001118static inline int nfs4_lock_type(struct file_lock *fl, int block)
1119{
1120 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1121 return block ? NFS4_READW_LT : NFS4_READ_LT;
1122 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1123}
1124
1125static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1126{
1127 if (fl->fl_end == OFFSET_MAX)
1128 return ~(uint64_t)0;
1129 return fl->fl_end - fl->fl_start + 1;
1130}
1131
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001132static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1133{
1134 __be32 *p;
1135
Trond Myklebustd035c362010-12-21 10:45:27 -05001136 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001137 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001138 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001139 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001140 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001141 xdr_encode_hyper(p, lowner->id);
1142}
1143
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144/*
1145 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1146 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1147 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001148static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149{
Al Viro8687b632006-10-19 23:28:48 -07001150 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Benny Halevy13c65ce2009-08-14 17:19:25 +03001152 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001153 *p++ = cpu_to_be32(OP_LOCK);
1154 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1155 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001156 p = xdr_encode_hyper(p, args->fl->fl_start);
1157 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001158 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001159 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001160 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001161 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001162 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001163 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001164 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
1166 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001167 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001168 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001169 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 }
Andy Adamsond0179312008-12-23 16:06:17 -05001171 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001172 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173}
1174
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001175static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176{
Al Viro8687b632006-10-19 23:28:48 -07001177 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001179 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001180 *p++ = cpu_to_be32(OP_LOCKT);
1181 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001182 p = xdr_encode_hyper(p, args->fl->fl_start);
1183 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001184 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001185 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001186 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187}
1188
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001189static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190{
Al Viro8687b632006-10-19 23:28:48 -07001191 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Benny Halevy13c65ce2009-08-14 17:19:25 +03001193 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001194 *p++ = cpu_to_be32(OP_LOCKU);
1195 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1196 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001197 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001198 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001199 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001200 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001201 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202}
1203
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001204static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1205{
1206 __be32 *p;
1207
1208 p = reserve_space(xdr, 4);
1209 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1210 encode_lockowner(xdr, lowner);
1211 hdr->nops++;
1212 hdr->replen += decode_release_lockowner_maxsz;
1213}
1214
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001215static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216{
1217 int len = name->len;
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 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001221 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001222 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001223 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001224 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225}
1226
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001227static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228{
Al Viro8687b632006-10-19 23:28:48 -07001229 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Benny Halevy13c65ce2009-08-14 17:19:25 +03001231 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001232 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001233 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001234 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001235 break;
1236 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001237 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001238 break;
1239 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001240 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001241 break;
1242 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001243 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 }
Benny Halevy34558512009-08-14 17:19:30 +03001245 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246}
1247
1248static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1249{
Al Viro8687b632006-10-19 23:28:48 -07001250 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 /*
1252 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1253 * owner 4 = 32
1254 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001255 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001256 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001257 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001258 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001259 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001260 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001261 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001262 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001263 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001264 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265}
1266
1267static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1268{
Al Viro8687b632006-10-19 23:28:48 -07001269 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001270 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Benny Halevy13c65ce2009-08-14 17:19:25 +03001272 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001274 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001275 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001276 encode_attrs(xdr, arg->u.attrs, arg->server);
1277 break;
1278 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001279 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001280 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001281 if (nfs4_has_persistent_session(clp)) {
1282 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1283 encode_attrs(xdr, arg->u.attrs, arg->server);
1284 } else {
1285 struct iattr dummy;
1286
1287 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1288 encode_nfs4_verifier(xdr, &arg->u.verifier);
1289 dummy.ia_valid = 0;
1290 encode_attrs(xdr, &dummy, arg->server);
1291 }
1292 } else {
1293 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1294 encode_nfs4_verifier(xdr, &arg->u.verifier);
1295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 }
1297}
1298
1299static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1300{
Al Viro8687b632006-10-19 23:28:48 -07001301 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
Benny Halevy13c65ce2009-08-14 17:19:25 +03001303 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001305 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001306 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001307 break;
1308 default:
1309 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001310 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001311 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 }
1313}
1314
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001315static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316{
Al Viro8687b632006-10-19 23:28:48 -07001317 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Benny Halevy13c65ce2009-08-14 17:19:25 +03001319 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001321 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001322 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001323 break;
1324 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001325 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001326 break;
1327 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001328 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001329 break;
1330 default:
1331 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 }
1333}
1334
1335static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1336{
Al Viro8687b632006-10-19 23:28:48 -07001337 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Benny Halevy13c65ce2009-08-14 17:19:25 +03001339 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001340 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 encode_string(xdr, name->len, name->name);
1342}
1343
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001344static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345{
Al Viro8687b632006-10-19 23:28:48 -07001346 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Benny Halevy13c65ce2009-08-14 17:19:25 +03001348 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001349 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 encode_delegation_type(xdr, type);
1351}
1352
1353static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1354{
Al Viro8687b632006-10-19 23:28:48 -07001355 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
Benny Halevy13c65ce2009-08-14 17:19:25 +03001357 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001358 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001359 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 encode_string(xdr, name->len, name->name);
1361}
1362
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001363static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364{
1365 encode_openhdr(xdr, arg);
1366 encode_opentype(xdr, arg);
1367 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001368 case NFS4_OPEN_CLAIM_NULL:
1369 encode_claim_null(xdr, arg->name);
1370 break;
1371 case NFS4_OPEN_CLAIM_PREVIOUS:
1372 encode_claim_previous(xdr, arg->u.delegation_type);
1373 break;
1374 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1375 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1376 break;
1377 default:
1378 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 }
Andy Adamsond0179312008-12-23 16:06:17 -05001380 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001381 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382}
1383
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001384static 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 -07001385{
Al Viro8687b632006-10-19 23:28:48 -07001386 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Benny Halevy13c65ce2009-08-14 17:19:25 +03001388 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001389 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001390 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001391 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001392 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001393 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394}
1395
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001396static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397{
Al Viro8687b632006-10-19 23:28:48 -07001398 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Benny Halevy13c65ce2009-08-14 17:19:25 +03001400 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001401 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001402 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001403 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001404 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001405 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001406 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407}
1408
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001409static void
Andy Adamsond0179312008-12-23 16:06:17 -05001410encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411{
1412 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001413 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Benny Halevy13c65ce2009-08-14 17:19:25 +03001415 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001416 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001417 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001418 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001419 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420}
1421
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001422static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423{
Andy Adamson05d564f2008-12-23 16:06:15 -05001424 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001425
Benny Halevy13c65ce2009-08-14 17:19:25 +03001426 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001427 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001428 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001429 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430}
1431
Andy Adamson89d1ea62011-03-01 01:34:09 +00001432static 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 -07001433{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001435 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Benny Halevy13c65ce2009-08-14 17:19:25 +03001437 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001439 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001440 if (zero_seqid)
1441 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001442 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 } else
Benny Halevy34558512009-08-14 17:19:30 +03001444 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445}
1446
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001447static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448{
Al Viro8687b632006-10-19 23:28:48 -07001449 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Benny Halevy13c65ce2009-08-14 17:19:25 +03001451 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001452 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
Andy Adamson89d1ea62011-03-01 01:34:09 +00001454 encode_stateid(xdr, args->context, args->lock_context,
1455 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
Benny Halevy13c65ce2009-08-14 17:19:25 +03001457 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001458 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001459 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001460 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001461 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462}
1463
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001464static 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 -07001465{
Trond Myklebust28331a42011-04-27 13:47:52 -04001466 uint32_t attrs[2] = {
1467 FATTR4_WORD0_RDATTR_ERROR,
1468 FATTR4_WORD1_MOUNTED_ON_FILEID,
1469 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001470 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001471 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001473 if (readdir->plus) {
1474 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001475 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001476 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1477 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1478 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1479 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001480 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001481 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001482 /* Use mounted_on_fileid only if the server supports it */
1483 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1484 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001485
Benny Halevy13c65ce2009-08-14 17:19:25 +03001486 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001487 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001488 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001489 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001490 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001491 *p++ = cpu_to_be32(readdir->count);
1492 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001493
Benny Halevye75bc1c2009-08-14 17:18:54 +03001494 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001495 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001496 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001497 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001498 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1499 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001500 (unsigned long long)readdir->cookie,
1501 ((u32 *)readdir->verifier.data)[0],
1502 ((u32 *)readdir->verifier.data)[1],
1503 attrs[0] & readdir->bitmask[0],
1504 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505}
1506
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001507static 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 -07001508{
Al Viro8687b632006-10-19 23:28:48 -07001509 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Benny Halevy13c65ce2009-08-14 17:19:25 +03001511 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001512 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001513 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001514 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515}
1516
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001517static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, 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 Halevy13c65ce2009-08-14 17:19:25 +03001521 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001522 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001523 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001524 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001525 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526}
1527
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001528static 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 -07001529{
Al Viro8687b632006-10-19 23:28:48 -07001530 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Benny Halevy811652b2009-08-14 17:19:34 +03001532 p = reserve_space(xdr, 4);
1533 *p = cpu_to_be32(OP_RENAME);
1534 encode_string(xdr, oldname->len, oldname->name);
1535 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001536 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001537 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538}
1539
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001540static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541{
Al Viro8687b632006-10-19 23:28:48 -07001542 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
Benny Halevy13c65ce2009-08-14 17:19:25 +03001544 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001545 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001546 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001547 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001548 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549}
1550
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001551static void
Andy Adamsond0179312008-12-23 16:06:17 -05001552encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001553{
Al Viro8687b632006-10-19 23:28:48 -07001554 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001555
Benny Halevy13c65ce2009-08-14 17:19:25 +03001556 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001557 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001558 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001559 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001560}
1561
Chuck Lever9f06c712010-12-14 14:59:18 +00001562static void
Andy Adamsond0179312008-12-23 16:06:17 -05001563encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001564{
Al Viro8687b632006-10-19 23:28:48 -07001565 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001566
Benny Halevy13c65ce2009-08-14 17:19:25 +03001567 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001568 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001569 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001570 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001571 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001572 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001573 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001574 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001575 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001576 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001577 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001578 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001579}
1580
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001581static void
Andy Adamsond0179312008-12-23 16:06:17 -05001582encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583{
Al Viro8687b632006-10-19 23:28:48 -07001584 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
Benny Halevy13c65ce2009-08-14 17:19:25 +03001586 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001587 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001588 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001589 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590}
1591
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001592static 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 -07001593{
Al Viro8687b632006-10-19 23:28:48 -07001594 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001595
Benny Halevy13c65ce2009-08-14 17:19:25 +03001596 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001597 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001598 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001599 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001600 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001601 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602}
1603
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001604static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605{
Al Viro8687b632006-10-19 23:28:48 -07001606 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
Benny Halevy13c65ce2009-08-14 17:19:25 +03001608 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001609 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001610 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001613 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001614 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1616 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001617 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001618 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001619 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001620 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621}
1622
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001623static 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 -07001624{
Andy Adamson05d564f2008-12-23 16:06:15 -05001625 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
Benny Halevy13c65ce2009-08-14 17:19:25 +03001627 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001628 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001629 p = xdr_encode_hyper(p, arg->clientid);
1630 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001631 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001632 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633}
1634
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001635static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636{
Al Viro8687b632006-10-19 23:28:48 -07001637 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
Benny Halevy13c65ce2009-08-14 17:19:25 +03001639 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001640 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
Andy Adamson89d1ea62011-03-01 01:34:09 +00001642 encode_stateid(xdr, args->context, args->lock_context,
1643 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
Benny Halevy13c65ce2009-08-14 17:19:25 +03001645 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001646 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001647 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001648 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
1650 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001651 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001652 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653}
1654
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001655static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656{
Al Viro8687b632006-10-19 23:28:48 -07001657 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
Benny Halevy13c65ce2009-08-14 17:19:25 +03001659 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
Benny Halevye75bc1c2009-08-14 17:18:54 +03001661 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001662 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001663 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001664 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001666
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001667static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1668{
1669 int len = name->len;
1670 __be32 *p;
1671
1672 p = reserve_space(xdr, 8 + len);
1673 *p++ = cpu_to_be32(OP_SECINFO);
1674 xdr_encode_opaque(p, name->name, len);
1675 hdr->nops++;
1676 hdr->replen += decode_secinfo_maxsz;
1677}
1678
Benny Halevy99fe60d2009-04-01 09:22:29 -04001679#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001680/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001681static void encode_exchange_id(struct xdr_stream *xdr,
1682 struct nfs41_exchange_id_args *args,
1683 struct compound_hdr *hdr)
1684{
1685 __be32 *p;
1686
Benny Halevy13c65ce2009-08-14 17:19:25 +03001687 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001688 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001689 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001690
1691 encode_string(xdr, args->id_len, args->id);
1692
Benny Halevy13c65ce2009-08-14 17:19:25 +03001693 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001694 *p++ = cpu_to_be32(args->flags);
1695 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001696 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001697 hdr->nops++;
1698 hdr->replen += decode_exchange_id_maxsz;
1699}
Andy Adamsonfc931582009-04-01 09:22:31 -04001700
1701static void encode_create_session(struct xdr_stream *xdr,
1702 struct nfs41_create_session_args *args,
1703 struct compound_hdr *hdr)
1704{
1705 __be32 *p;
1706 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1707 uint32_t len;
1708 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001709 u32 max_resp_sz_cached;
1710
1711 /*
1712 * Assumes OPEN is the biggest non-idempotent compound.
1713 * 2 is the verifier.
1714 */
1715 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1716 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001717
Andy Adamsonfc931582009-04-01 09:22:31 -04001718 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1719 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001720
Benny Halevy13c65ce2009-08-14 17:19:25 +03001721 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001722 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001723 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001724 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1725 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001726
Andy Adamsonfc931582009-04-01 09:22:31 -04001727 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001728 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001729 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1730 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001731 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001732 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1733 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1734 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001735
1736 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001737 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001738 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1739 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1740 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1741 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1742 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1743 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001744
Benny Halevye75bc1c2009-08-14 17:18:54 +03001745 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001746 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001747 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001748
1749 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001750 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001751 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001752 *p++ = cpu_to_be32(0); /* UID */
1753 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001754 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001755 hdr->nops++;
1756 hdr->replen += decode_create_session_maxsz;
1757}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001758
1759static void encode_destroy_session(struct xdr_stream *xdr,
1760 struct nfs4_session *session,
1761 struct compound_hdr *hdr)
1762{
1763 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001764 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001765 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001766 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001767 hdr->nops++;
1768 hdr->replen += decode_destroy_session_maxsz;
1769}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001770
1771static void encode_reclaim_complete(struct xdr_stream *xdr,
1772 struct nfs41_reclaim_complete_args *args,
1773 struct compound_hdr *hdr)
1774{
1775 __be32 *p;
1776
1777 p = reserve_space(xdr, 8);
1778 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1779 *p++ = cpu_to_be32(args->one_fs);
1780 hdr->nops++;
1781 hdr->replen += decode_reclaim_complete_maxsz;
1782}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001783#endif /* CONFIG_NFS_V4_1 */
1784
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001785static void encode_sequence(struct xdr_stream *xdr,
1786 const struct nfs4_sequence_args *args,
1787 struct compound_hdr *hdr)
1788{
1789#if defined(CONFIG_NFS_V4_1)
1790 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001791 struct nfs4_slot_table *tp;
1792 struct nfs4_slot *slot;
1793 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001794
1795 if (!session)
1796 return;
1797
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001798 tp = &session->fc_slot_table;
1799
1800 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1801 slot = tp->slots + args->sa_slotid;
1802
Benny Halevy13c65ce2009-08-14 17:19:25 +03001803 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001804 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001805
1806 /*
1807 * Sessionid + seqid + slotid + max slotid + cache_this
1808 */
1809 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1810 "max_slotid=%d cache_this=%d\n",
1811 __func__,
1812 ((u32 *)session->sess_id.data)[0],
1813 ((u32 *)session->sess_id.data)[1],
1814 ((u32 *)session->sess_id.data)[2],
1815 ((u32 *)session->sess_id.data)[3],
1816 slot->seq_nr, args->sa_slotid,
1817 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001818 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001819 *p++ = cpu_to_be32(slot->seq_nr);
1820 *p++ = cpu_to_be32(args->sa_slotid);
1821 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001822 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001823 hdr->nops++;
1824 hdr->replen += decode_sequence_maxsz;
1825#endif /* CONFIG_NFS_V4_1 */
1826}
1827
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001828#ifdef CONFIG_NFS_V4_1
1829static void
1830encode_getdeviceinfo(struct xdr_stream *xdr,
1831 const struct nfs4_getdeviceinfo_args *args,
1832 struct compound_hdr *hdr)
1833{
1834 __be32 *p;
1835
1836 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1837 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1838 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1839 NFS4_DEVICEID4_SIZE);
1840 *p++ = cpu_to_be32(args->pdev->layout_type);
1841 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1842 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1843 hdr->nops++;
1844 hdr->replen += decode_getdeviceinfo_maxsz;
1845}
1846
1847static void
1848encode_layoutget(struct xdr_stream *xdr,
1849 const struct nfs4_layoutget_args *args,
1850 struct compound_hdr *hdr)
1851{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001852 __be32 *p;
1853
1854 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1855 *p++ = cpu_to_be32(OP_LAYOUTGET);
1856 *p++ = cpu_to_be32(0); /* Signal layout available */
1857 *p++ = cpu_to_be32(args->type);
1858 *p++ = cpu_to_be32(args->range.iomode);
1859 p = xdr_encode_hyper(p, args->range.offset);
1860 p = xdr_encode_hyper(p, args->range.length);
1861 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00001862 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001863 *p = cpu_to_be32(args->maxcount);
1864
1865 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1866 __func__,
1867 args->type,
1868 args->range.iomode,
1869 (unsigned long)args->range.offset,
1870 (unsigned long)args->range.length,
1871 args->maxcount);
1872 hdr->nops++;
1873 hdr->replen += decode_layoutget_maxsz;
1874}
Andy Adamson863a3c62011-03-23 13:27:54 +00001875
1876static int
1877encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001878 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001879 const struct nfs4_layoutcommit_args *args,
1880 struct compound_hdr *hdr)
1881{
1882 __be32 *p;
1883
1884 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1885 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1886
Benny Halevyac7db722011-05-22 19:53:48 +03001887 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
Andy Adamson863a3c62011-03-23 13:27:54 +00001888 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1889 /* Only whole file layouts */
1890 p = xdr_encode_hyper(p, 0); /* offset */
1891 p = xdr_encode_hyper(p, NFS4_MAX_UINT64); /* length */
1892 *p++ = cpu_to_be32(0); /* reclaim */
1893 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1894 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1895 p = xdr_encode_hyper(p, args->lastbytewritten);
1896 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1897 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001898
1899 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1900 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1901 NFS_I(inode)->layout, xdr, args);
1902 else {
1903 p = reserve_space(xdr, 4);
1904 *p = cpu_to_be32(0); /* no layout-type payload */
1905 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001906
1907 hdr->nops++;
1908 hdr->replen += decode_layoutcommit_maxsz;
1909 return 0;
1910}
Benny Halevycbe82602011-05-22 19:52:37 +03001911
1912static void
1913encode_layoutreturn(struct xdr_stream *xdr,
1914 const struct nfs4_layoutreturn_args *args,
1915 struct compound_hdr *hdr)
1916{
1917 __be32 *p;
1918
1919 p = reserve_space(xdr, 20);
1920 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
1921 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1922 *p++ = cpu_to_be32(args->layout_type);
1923 *p++ = cpu_to_be32(IOMODE_ANY);
1924 *p = cpu_to_be32(RETURN_FILE);
1925 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
1926 p = xdr_encode_hyper(p, 0);
1927 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1928 spin_lock(&args->inode->i_lock);
1929 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1930 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001931 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1932 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1933 NFS_I(args->inode)->layout, xdr, args);
1934 } else {
1935 p = reserve_space(xdr, 4);
1936 *p = cpu_to_be32(0);
1937 }
Benny Halevycbe82602011-05-22 19:52:37 +03001938 hdr->nops++;
1939 hdr->replen += decode_layoutreturn_maxsz;
1940}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001941#endif /* CONFIG_NFS_V4_1 */
1942
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943/*
1944 * END OF "GENERIC" ENCODE ROUTINES.
1945 */
1946
Benny Halevy66cc0422009-04-01 09:22:10 -04001947static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1948{
1949#if defined(CONFIG_NFS_V4_1)
1950 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001951 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001952#endif /* CONFIG_NFS_V4_1 */
1953 return 0;
1954}
1955
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956/*
1957 * Encode an ACCESS request
1958 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001959static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1960 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001963 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965
Chuck Lever9f06c712010-12-14 14:59:18 +00001966 encode_compound_hdr(xdr, req, &hdr);
1967 encode_sequence(xdr, &args->seq_args, &hdr);
1968 encode_putfh(xdr, args->fh, &hdr);
1969 encode_access(xdr, args->access, &hdr);
1970 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001971 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972}
1973
1974/*
1975 * Encode LOOKUP request
1976 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001977static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1978 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001981 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983
Chuck Lever9f06c712010-12-14 14:59:18 +00001984 encode_compound_hdr(xdr, req, &hdr);
1985 encode_sequence(xdr, &args->seq_args, &hdr);
1986 encode_putfh(xdr, args->dir_fh, &hdr);
1987 encode_lookup(xdr, args->name, &hdr);
1988 encode_getfh(xdr, &hdr);
1989 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001990 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991}
1992
1993/*
1994 * Encode LOOKUP_ROOT request
1995 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001996static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
1997 struct xdr_stream *xdr,
1998 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002001 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
Chuck Lever9f06c712010-12-14 14:59:18 +00002004 encode_compound_hdr(xdr, req, &hdr);
2005 encode_sequence(xdr, &args->seq_args, &hdr);
2006 encode_putrootfh(xdr, &hdr);
2007 encode_getfh(xdr, &hdr);
2008 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002009 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010}
2011
2012/*
2013 * Encode REMOVE request
2014 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002015static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2016 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002019 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021
Chuck Lever9f06c712010-12-14 14:59:18 +00002022 encode_compound_hdr(xdr, req, &hdr);
2023 encode_sequence(xdr, &args->seq_args, &hdr);
2024 encode_putfh(xdr, args->fh, &hdr);
2025 encode_remove(xdr, &args->name, &hdr);
2026 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002027 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028}
2029
2030/*
2031 * Encode RENAME request
2032 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002033static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2034 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002037 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039
Chuck Lever9f06c712010-12-14 14:59:18 +00002040 encode_compound_hdr(xdr, req, &hdr);
2041 encode_sequence(xdr, &args->seq_args, &hdr);
2042 encode_putfh(xdr, args->old_dir, &hdr);
2043 encode_savefh(xdr, &hdr);
2044 encode_putfh(xdr, args->new_dir, &hdr);
2045 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2046 encode_getfattr(xdr, args->bitmask, &hdr);
2047 encode_restorefh(xdr, &hdr);
2048 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002049 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050}
2051
2052/*
2053 * Encode LINK request
2054 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002055static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2056 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002059 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
Chuck Lever9f06c712010-12-14 14:59:18 +00002062 encode_compound_hdr(xdr, req, &hdr);
2063 encode_sequence(xdr, &args->seq_args, &hdr);
2064 encode_putfh(xdr, args->fh, &hdr);
2065 encode_savefh(xdr, &hdr);
2066 encode_putfh(xdr, args->dir_fh, &hdr);
2067 encode_link(xdr, args->name, &hdr);
2068 encode_getfattr(xdr, args->bitmask, &hdr);
2069 encode_restorefh(xdr, &hdr);
2070 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002071 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072}
2073
2074/*
2075 * Encode CREATE request
2076 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002077static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2078 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002081 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
Chuck Lever9f06c712010-12-14 14:59:18 +00002084 encode_compound_hdr(xdr, req, &hdr);
2085 encode_sequence(xdr, &args->seq_args, &hdr);
2086 encode_putfh(xdr, args->dir_fh, &hdr);
2087 encode_savefh(xdr, &hdr);
2088 encode_create(xdr, args, &hdr);
2089 encode_getfh(xdr, &hdr);
2090 encode_getfattr(xdr, args->bitmask, &hdr);
2091 encode_restorefh(xdr, &hdr);
2092 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002093 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094}
2095
2096/*
2097 * Encode SYMLINK request
2098 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002099static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2100 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101{
Chuck Lever9f06c712010-12-14 14:59:18 +00002102 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103}
2104
2105/*
2106 * Encode GETATTR request
2107 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002108static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2109 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002112 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114
Chuck Lever9f06c712010-12-14 14:59:18 +00002115 encode_compound_hdr(xdr, req, &hdr);
2116 encode_sequence(xdr, &args->seq_args, &hdr);
2117 encode_putfh(xdr, args->fh, &hdr);
2118 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002119 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120}
2121
2122/*
2123 * Encode a CLOSE request
2124 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002125static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2126 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127{
Andy Adamson05d564f2008-12-23 16:06:15 -05002128 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002129 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002130 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131
Chuck Lever9f06c712010-12-14 14:59:18 +00002132 encode_compound_hdr(xdr, req, &hdr);
2133 encode_sequence(xdr, &args->seq_args, &hdr);
2134 encode_putfh(xdr, args->fh, &hdr);
2135 encode_close(xdr, args, &hdr);
2136 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002137 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138}
2139
2140/*
2141 * Encode an OPEN request
2142 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002143static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2144 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002147 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
Chuck Lever9f06c712010-12-14 14:59:18 +00002150 encode_compound_hdr(xdr, req, &hdr);
2151 encode_sequence(xdr, &args->seq_args, &hdr);
2152 encode_putfh(xdr, args->fh, &hdr);
2153 encode_savefh(xdr, &hdr);
2154 encode_open(xdr, args, &hdr);
2155 encode_getfh(xdr, &hdr);
2156 encode_getfattr(xdr, args->bitmask, &hdr);
2157 encode_restorefh(xdr, &hdr);
2158 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002159 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160}
2161
2162/*
2163 * Encode an OPEN_CONFIRM request
2164 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002165static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2166 struct xdr_stream *xdr,
2167 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002170 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
Chuck Lever9f06c712010-12-14 14:59:18 +00002173 encode_compound_hdr(xdr, req, &hdr);
2174 encode_putfh(xdr, args->fh, &hdr);
2175 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002176 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177}
2178
2179/*
2180 * Encode an OPEN request with no attributes.
2181 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002182static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2183 struct xdr_stream *xdr,
2184 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002187 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189
Chuck Lever9f06c712010-12-14 14:59:18 +00002190 encode_compound_hdr(xdr, req, &hdr);
2191 encode_sequence(xdr, &args->seq_args, &hdr);
2192 encode_putfh(xdr, args->fh, &hdr);
2193 encode_open(xdr, args, &hdr);
2194 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002195 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196}
2197
2198/*
2199 * Encode an OPEN_DOWNGRADE request
2200 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002201static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2202 struct xdr_stream *xdr,
2203 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002206 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208
Chuck Lever9f06c712010-12-14 14:59:18 +00002209 encode_compound_hdr(xdr, req, &hdr);
2210 encode_sequence(xdr, &args->seq_args, &hdr);
2211 encode_putfh(xdr, args->fh, &hdr);
2212 encode_open_downgrade(xdr, args, &hdr);
2213 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002214 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215}
2216
2217/*
2218 * Encode a LOCK request
2219 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002220static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2221 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002224 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
Chuck Lever9f06c712010-12-14 14:59:18 +00002227 encode_compound_hdr(xdr, req, &hdr);
2228 encode_sequence(xdr, &args->seq_args, &hdr);
2229 encode_putfh(xdr, args->fh, &hdr);
2230 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002231 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232}
2233
2234/*
2235 * Encode a LOCKT request
2236 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002237static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2238 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002241 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
Chuck Lever9f06c712010-12-14 14:59:18 +00002244 encode_compound_hdr(xdr, req, &hdr);
2245 encode_sequence(xdr, &args->seq_args, &hdr);
2246 encode_putfh(xdr, args->fh, &hdr);
2247 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002248 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249}
2250
2251/*
2252 * Encode a LOCKU request
2253 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002254static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2255 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002258 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260
Chuck Lever9f06c712010-12-14 14:59:18 +00002261 encode_compound_hdr(xdr, req, &hdr);
2262 encode_sequence(xdr, &args->seq_args, &hdr);
2263 encode_putfh(xdr, args->fh, &hdr);
2264 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002265 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266}
2267
Chuck Lever9f06c712010-12-14 14:59:18 +00002268static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2269 struct xdr_stream *xdr,
2270 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002271{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002272 struct compound_hdr hdr = {
2273 .minorversion = 0,
2274 };
2275
Chuck Lever9f06c712010-12-14 14:59:18 +00002276 encode_compound_hdr(xdr, req, &hdr);
2277 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002278 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002279}
2280
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281/*
2282 * Encode a READLINK request
2283 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002284static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2285 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002288 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290
Chuck Lever9f06c712010-12-14 14:59:18 +00002291 encode_compound_hdr(xdr, req, &hdr);
2292 encode_sequence(xdr, &args->seq_args, &hdr);
2293 encode_putfh(xdr, args->fh, &hdr);
2294 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002295
Benny Halevy28f56692009-04-01 09:22:09 -04002296 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002297 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002298 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299}
2300
2301/*
2302 * Encode a READDIR request
2303 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002304static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2305 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002308 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
Chuck Lever9f06c712010-12-14 14:59:18 +00002311 encode_compound_hdr(xdr, req, &hdr);
2312 encode_sequence(xdr, &args->seq_args, &hdr);
2313 encode_putfh(xdr, args->fh, &hdr);
2314 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002315
Benny Halevy28f56692009-04-01 09:22:09 -04002316 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002317 args->pgbase, args->count);
2318 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002319 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002320 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002321 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322}
2323
2324/*
2325 * Encode a READ request
2326 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002327static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2328 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002331 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
Chuck Lever9f06c712010-12-14 14:59:18 +00002334 encode_compound_hdr(xdr, req, &hdr);
2335 encode_sequence(xdr, &args->seq_args, &hdr);
2336 encode_putfh(xdr, args->fh, &hdr);
2337 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
Benny Halevy28f56692009-04-01 09:22:09 -04002339 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002341 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002342 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343}
2344
2345/*
2346 * Encode an SETATTR request
2347 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002348static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2349 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350{
Andy Adamson05d564f2008-12-23 16:06:15 -05002351 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002352 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002353 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
Chuck Lever9f06c712010-12-14 14:59:18 +00002355 encode_compound_hdr(xdr, req, &hdr);
2356 encode_sequence(xdr, &args->seq_args, &hdr);
2357 encode_putfh(xdr, args->fh, &hdr);
2358 encode_setattr(xdr, args, args->server, &hdr);
2359 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002360 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361}
2362
2363/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002364 * Encode a GETACL request
2365 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002366static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2367 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002368{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002369 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002370 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002371 };
Benny Halevy28f56692009-04-01 09:22:09 -04002372 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002373
Chuck Lever9f06c712010-12-14 14:59:18 +00002374 encode_compound_hdr(xdr, req, &hdr);
2375 encode_sequence(xdr, &args->seq_args, &hdr);
2376 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002377 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002378 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002379
Benny Halevy28f56692009-04-01 09:22:09 -04002380 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002381 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002382 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002383}
2384
2385/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 * Encode a WRITE request
2387 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002388static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2389 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002392 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
Chuck Lever9f06c712010-12-14 14:59:18 +00002395 encode_compound_hdr(xdr, req, &hdr);
2396 encode_sequence(xdr, &args->seq_args, &hdr);
2397 encode_putfh(xdr, args->fh, &hdr);
2398 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002399 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002400 if (args->bitmask)
2401 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002402 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403}
2404
2405/*
2406 * a COMMIT request
2407 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002408static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2409 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002412 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414
Chuck Lever9f06c712010-12-14 14:59:18 +00002415 encode_compound_hdr(xdr, req, &hdr);
2416 encode_sequence(xdr, &args->seq_args, &hdr);
2417 encode_putfh(xdr, args->fh, &hdr);
2418 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002419 if (args->bitmask)
2420 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002421 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422}
2423
2424/*
2425 * FSINFO request
2426 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002427static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2428 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002431 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433
Chuck Lever9f06c712010-12-14 14:59:18 +00002434 encode_compound_hdr(xdr, req, &hdr);
2435 encode_sequence(xdr, &args->seq_args, &hdr);
2436 encode_putfh(xdr, args->fh, &hdr);
2437 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002438 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439}
2440
2441/*
2442 * a PATHCONF request
2443 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002444static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2445 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002448 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
Chuck Lever9f06c712010-12-14 14:59:18 +00002451 encode_compound_hdr(xdr, req, &hdr);
2452 encode_sequence(xdr, &args->seq_args, &hdr);
2453 encode_putfh(xdr, args->fh, &hdr);
2454 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002455 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002456 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457}
2458
2459/*
2460 * a STATFS request
2461 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002462static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2463 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002466 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468
Chuck Lever9f06c712010-12-14 14:59:18 +00002469 encode_compound_hdr(xdr, req, &hdr);
2470 encode_sequence(xdr, &args->seq_args, &hdr);
2471 encode_putfh(xdr, args->fh, &hdr);
2472 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002473 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002474 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475}
2476
2477/*
2478 * GETATTR_BITMAP request
2479 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002480static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2481 struct xdr_stream *xdr,
2482 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002485 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
Chuck Lever9f06c712010-12-14 14:59:18 +00002488 encode_compound_hdr(xdr, req, &hdr);
2489 encode_sequence(xdr, &args->seq_args, &hdr);
2490 encode_putfh(xdr, args->fhandle, &hdr);
2491 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002492 FATTR4_WORD0_LINK_SUPPORT|
2493 FATTR4_WORD0_SYMLINK_SUPPORT|
2494 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002495 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496}
2497
2498/*
2499 * a RENEW request
2500 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002501static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2502 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002505 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 };
2507
Chuck Lever9f06c712010-12-14 14:59:18 +00002508 encode_compound_hdr(xdr, req, &hdr);
2509 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002510 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511}
2512
2513/*
2514 * a SETCLIENTID request
2515 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002516static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2517 struct xdr_stream *xdr,
2518 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002521 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 };
2523
Chuck Lever9f06c712010-12-14 14:59:18 +00002524 encode_compound_hdr(xdr, req, &hdr);
2525 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002526 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527}
2528
2529/*
2530 * a SETCLIENTID_CONFIRM request
2531 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002532static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2533 struct xdr_stream *xdr,
2534 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002537 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 };
2539 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540
Chuck Lever9f06c712010-12-14 14:59:18 +00002541 encode_compound_hdr(xdr, req, &hdr);
2542 encode_setclientid_confirm(xdr, arg, &hdr);
2543 encode_putrootfh(xdr, &hdr);
2544 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002545 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546}
2547
2548/*
2549 * DELEGRETURN request
2550 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002551static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2552 struct xdr_stream *xdr,
2553 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002556 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558
Chuck Lever9f06c712010-12-14 14:59:18 +00002559 encode_compound_hdr(xdr, req, &hdr);
2560 encode_sequence(xdr, &args->seq_args, &hdr);
2561 encode_putfh(xdr, args->fhandle, &hdr);
2562 encode_delegreturn(xdr, args->stateid, &hdr);
2563 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002564 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565}
2566
2567/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002568 * Encode FS_LOCATIONS request
2569 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002570static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2571 struct xdr_stream *xdr,
2572 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002573{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002574 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002575 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002576 };
Benny Halevy28f56692009-04-01 09:22:09 -04002577 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002578
Chuck Lever9f06c712010-12-14 14:59:18 +00002579 encode_compound_hdr(xdr, req, &hdr);
2580 encode_sequence(xdr, &args->seq_args, &hdr);
2581 encode_putfh(xdr, args->dir_fh, &hdr);
2582 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002583 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002584 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002585
Benny Halevy28f56692009-04-01 09:22:09 -04002586 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002587 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002588 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002589}
2590
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002591/*
2592 * Encode SECINFO request
2593 */
2594static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2595 struct xdr_stream *xdr,
2596 struct nfs4_secinfo_arg *args)
2597{
2598 struct compound_hdr hdr = {
2599 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2600 };
2601
2602 encode_compound_hdr(xdr, req, &hdr);
2603 encode_sequence(xdr, &args->seq_args, &hdr);
2604 encode_putfh(xdr, args->dir_fh, &hdr);
2605 encode_secinfo(xdr, args->name, &hdr);
2606 encode_nops(&hdr);
2607}
2608
Benny Halevy99fe60d2009-04-01 09:22:29 -04002609#if defined(CONFIG_NFS_V4_1)
2610/*
2611 * EXCHANGE_ID request
2612 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002613static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2614 struct xdr_stream *xdr,
2615 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002616{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002617 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002618 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002619 };
2620
Chuck Lever9f06c712010-12-14 14:59:18 +00002621 encode_compound_hdr(xdr, req, &hdr);
2622 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002623 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002624}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002625
2626/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002627 * a CREATE_SESSION request
2628 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002629static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2630 struct xdr_stream *xdr,
2631 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002632{
Andy Adamsonfc931582009-04-01 09:22:31 -04002633 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002634 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002635 };
2636
Chuck Lever9f06c712010-12-14 14:59:18 +00002637 encode_compound_hdr(xdr, req, &hdr);
2638 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002639 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002640}
2641
2642/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002643 * a DESTROY_SESSION request
2644 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002645static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2646 struct xdr_stream *xdr,
2647 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002648{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002649 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002650 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002651 };
2652
Chuck Lever9f06c712010-12-14 14:59:18 +00002653 encode_compound_hdr(xdr, req, &hdr);
2654 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002655 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002656}
2657
2658/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002659 * a SEQUENCE request
2660 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002661static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2662 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002663{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002664 struct compound_hdr hdr = {
2665 .minorversion = nfs4_xdr_minorversion(args),
2666 };
2667
Chuck Lever9f06c712010-12-14 14:59:18 +00002668 encode_compound_hdr(xdr, req, &hdr);
2669 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002670 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002671}
2672
2673/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002674 * a GET_LEASE_TIME request
2675 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002676static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2677 struct xdr_stream *xdr,
2678 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002679{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002680 struct compound_hdr hdr = {
2681 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2682 };
2683 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2684
Chuck Lever9f06c712010-12-14 14:59:18 +00002685 encode_compound_hdr(xdr, req, &hdr);
2686 encode_sequence(xdr, &args->la_seq_args, &hdr);
2687 encode_putrootfh(xdr, &hdr);
2688 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002689 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002690}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002691
2692/*
2693 * a RECLAIM_COMPLETE request
2694 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002695static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2696 struct xdr_stream *xdr,
2697 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002698{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002699 struct compound_hdr hdr = {
2700 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2701 };
2702
Chuck Lever9f06c712010-12-14 14:59:18 +00002703 encode_compound_hdr(xdr, req, &hdr);
2704 encode_sequence(xdr, &args->seq_args, &hdr);
2705 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002706 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002707}
2708
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002709/*
2710 * Encode GETDEVICEINFO request
2711 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002712static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2713 struct xdr_stream *xdr,
2714 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002715{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002716 struct compound_hdr hdr = {
2717 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2718 };
2719
Chuck Lever9f06c712010-12-14 14:59:18 +00002720 encode_compound_hdr(xdr, req, &hdr);
2721 encode_sequence(xdr, &args->seq_args, &hdr);
2722 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002723
2724 /* set up reply kvec. Subtract notification bitmap max size (2)
2725 * so that notification bitmap is put in xdr_buf tail */
2726 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2727 args->pdev->pages, args->pdev->pgbase,
2728 args->pdev->pglen);
2729
2730 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002731}
2732
2733/*
2734 * Encode LAYOUTGET request
2735 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002736static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2737 struct xdr_stream *xdr,
2738 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002739{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002740 struct compound_hdr hdr = {
2741 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2742 };
2743
Chuck Lever9f06c712010-12-14 14:59:18 +00002744 encode_compound_hdr(xdr, req, &hdr);
2745 encode_sequence(xdr, &args->seq_args, &hdr);
2746 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2747 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002748
2749 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2750 args->layout.pages, 0, args->layout.pglen);
2751
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002752 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002753}
Andy Adamson863a3c62011-03-23 13:27:54 +00002754
2755/*
2756 * Encode LAYOUTCOMMIT request
2757 */
Benny Halevycbe82602011-05-22 19:52:37 +03002758static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2759 struct xdr_stream *xdr,
2760 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002761{
Benny Halevyac7db722011-05-22 19:53:48 +03002762 struct nfs4_layoutcommit_data *data =
2763 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002764 struct compound_hdr hdr = {
2765 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2766 };
2767
2768 encode_compound_hdr(xdr, req, &hdr);
2769 encode_sequence(xdr, &args->seq_args, &hdr);
2770 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002771 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002772 encode_getfattr(xdr, args->bitmask, &hdr);
2773 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002774}
2775
2776/*
2777 * Encode LAYOUTRETURN request
2778 */
2779static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2780 struct xdr_stream *xdr,
2781 struct nfs4_layoutreturn_args *args)
2782{
2783 struct compound_hdr hdr = {
2784 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2785 };
2786
2787 encode_compound_hdr(xdr, req, &hdr);
2788 encode_sequence(xdr, &args->seq_args, &hdr);
2789 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2790 encode_layoutreturn(xdr, args, &hdr);
2791 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002792}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002793#endif /* CONFIG_NFS_V4_1 */
2794
Benny Halevy686841b2009-08-14 17:19:48 +03002795static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2796{
2797 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2798 "Remaining buffer length is %tu words.\n",
2799 func, xdr->end - xdr->p);
2800}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801
Trond Myklebust683b57b2006-06-09 09:34:22 -04002802static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803{
Al Viro8687b632006-10-19 23:28:48 -07002804 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
Benny Halevyc0eae662009-08-14 17:20:14 +03002806 p = xdr_inline_decode(xdr, 4);
2807 if (unlikely(!p))
2808 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002809 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002810 p = xdr_inline_decode(xdr, *len);
2811 if (unlikely(!p))
2812 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 *string = (char *)p;
2814 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002815out_overflow:
2816 print_overflow_msg(__func__, xdr);
2817 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818}
2819
2820static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2821{
Al Viro8687b632006-10-19 23:28:48 -07002822 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823
Benny Halevyc0eae662009-08-14 17:20:14 +03002824 p = xdr_inline_decode(xdr, 8);
2825 if (unlikely(!p))
2826 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002827 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002828 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002829
Benny Halevyc0eae662009-08-14 17:20:14 +03002830 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2831 if (unlikely(!p))
2832 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 hdr->tag = (char *)p;
2834 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002835 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002836 if (unlikely(hdr->nops < 1))
2837 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002839out_overflow:
2840 print_overflow_msg(__func__, xdr);
2841 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842}
2843
2844static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2845{
Al Viro8687b632006-10-19 23:28:48 -07002846 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 uint32_t opnum;
2848 int32_t nfserr;
2849
Benny Halevyc0eae662009-08-14 17:20:14 +03002850 p = xdr_inline_decode(xdr, 8);
2851 if (unlikely(!p))
2852 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002853 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002855 dprintk("nfs: Server returned operation"
2856 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 opnum, expected);
2858 return -EIO;
2859 }
Benny Halevycccddf42009-08-14 17:20:19 +03002860 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002862 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002864out_overflow:
2865 print_overflow_msg(__func__, xdr);
2866 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867}
2868
2869/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002870static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871{
Al Viro8687b632006-10-19 23:28:48 -07002872 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002873 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 char *str;
2875
Benny Halevyc0eae662009-08-14 17:20:14 +03002876 p = xdr_inline_decode(xdr, 12);
2877 if (likely(p))
2878 return decode_opaque_inline(xdr, &strlen, &str);
2879 print_overflow_msg(__func__, xdr);
2880 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881}
2882
2883static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2884{
Al Viro8687b632006-10-19 23:28:48 -07002885 uint32_t bmlen;
2886 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887
Benny Halevyc0eae662009-08-14 17:20:14 +03002888 p = xdr_inline_decode(xdr, 4);
2889 if (unlikely(!p))
2890 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002891 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892
2893 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002894 p = xdr_inline_decode(xdr, (bmlen << 2));
2895 if (unlikely(!p))
2896 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002898 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002900 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 }
2902 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002903out_overflow:
2904 print_overflow_msg(__func__, xdr);
2905 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906}
2907
Al Viro8687b632006-10-19 23:28:48 -07002908static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909{
Al Viro8687b632006-10-19 23:28:48 -07002910 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911
Benny Halevyc0eae662009-08-14 17:20:14 +03002912 p = xdr_inline_decode(xdr, 4);
2913 if (unlikely(!p))
2914 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002915 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 *savep = xdr->p;
2917 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002918out_overflow:
2919 print_overflow_msg(__func__, xdr);
2920 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921}
2922
2923static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2924{
2925 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04002926 int ret;
2927 ret = decode_attr_bitmap(xdr, bitmask);
2928 if (unlikely(ret < 0))
2929 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2931 } else
2932 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002933 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 return 0;
2935}
2936
2937static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2938{
Al Viro8687b632006-10-19 23:28:48 -07002939 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002940 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941
2942 *type = 0;
2943 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2944 return -EIO;
2945 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002946 p = xdr_inline_decode(xdr, 4);
2947 if (unlikely(!p))
2948 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002949 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002951 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 return -EIO;
2953 }
2954 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002955 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002957 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002958 return ret;
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_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2965{
Al Viro8687b632006-10-19 23:28:48 -07002966 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002967 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968
2969 *change = 0;
2970 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2971 return -EIO;
2972 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002973 p = xdr_inline_decode(xdr, 8);
2974 if (unlikely(!p))
2975 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002976 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002978 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002980 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002982 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002983out_overflow:
2984 print_overflow_msg(__func__, xdr);
2985 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986}
2987
2988static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2989{
Al Viro8687b632006-10-19 23:28:48 -07002990 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002991 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992
2993 *size = 0;
2994 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2995 return -EIO;
2996 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002997 p = xdr_inline_decode(xdr, 8);
2998 if (unlikely(!p))
2999 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003000 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003002 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003004 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003005 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003006out_overflow:
3007 print_overflow_msg(__func__, xdr);
3008 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009}
3010
3011static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3012{
Al Viro8687b632006-10-19 23:28:48 -07003013 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014
3015 *res = 0;
3016 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3017 return -EIO;
3018 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003019 p = xdr_inline_decode(xdr, 4);
3020 if (unlikely(!p))
3021 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003022 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3024 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003025 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003027out_overflow:
3028 print_overflow_msg(__func__, xdr);
3029 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030}
3031
3032static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3033{
Al Viro8687b632006-10-19 23:28:48 -07003034 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035
3036 *res = 0;
3037 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3038 return -EIO;
3039 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003040 p = xdr_inline_decode(xdr, 4);
3041 if (unlikely(!p))
3042 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003043 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3045 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003046 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003048out_overflow:
3049 print_overflow_msg(__func__, xdr);
3050 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051}
3052
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003053static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054{
Al Viro8687b632006-10-19 23:28:48 -07003055 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003056 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057
3058 fsid->major = 0;
3059 fsid->minor = 0;
3060 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3061 return -EIO;
3062 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003063 p = xdr_inline_decode(xdr, 16);
3064 if (unlikely(!p))
3065 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003066 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003067 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003069 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003071 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 (unsigned long long)fsid->major,
3073 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003074 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003075out_overflow:
3076 print_overflow_msg(__func__, xdr);
3077 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078}
3079
3080static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3081{
Al Viro8687b632006-10-19 23:28:48 -07003082 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083
3084 *res = 60;
3085 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3086 return -EIO;
3087 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003088 p = xdr_inline_decode(xdr, 4);
3089 if (unlikely(!p))
3090 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003091 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3093 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003094 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003096out_overflow:
3097 print_overflow_msg(__func__, xdr);
3098 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099}
3100
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003101static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003102{
3103 __be32 *p;
3104
3105 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3106 return -EIO;
3107 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3108 p = xdr_inline_decode(xdr, 4);
3109 if (unlikely(!p))
3110 goto out_overflow;
3111 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003112 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003113 }
3114 return 0;
3115out_overflow:
3116 print_overflow_msg(__func__, xdr);
3117 return -EIO;
3118}
3119
3120static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3121{
3122 __be32 *p;
3123 int len;
3124
Trond Myklebust7ad07352010-10-23 15:34:20 -04003125 if (fh != NULL)
3126 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003127
3128 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3129 return -EIO;
3130 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3131 p = xdr_inline_decode(xdr, 4);
3132 if (unlikely(!p))
3133 goto out_overflow;
3134 len = be32_to_cpup(p);
3135 if (len > NFS4_FHSIZE)
3136 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003137 p = xdr_inline_decode(xdr, len);
3138 if (unlikely(!p))
3139 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003140 if (fh != NULL) {
3141 memcpy(fh->data, p, len);
3142 fh->size = len;
3143 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003144 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3145 }
3146 return 0;
3147out_overflow:
3148 print_overflow_msg(__func__, xdr);
3149 return -EIO;
3150}
3151
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3153{
Al Viro8687b632006-10-19 23:28:48 -07003154 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155
3156 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3157 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3158 return -EIO;
3159 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003160 p = xdr_inline_decode(xdr, 4);
3161 if (unlikely(!p))
3162 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003163 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3165 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003166 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 return 0;
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_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3174{
Al Viro8687b632006-10-19 23:28:48 -07003175 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003176 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177
3178 *fileid = 0;
3179 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3180 return -EIO;
3181 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
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, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003187 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003189 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003190 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003191out_overflow:
3192 print_overflow_msg(__func__, xdr);
3193 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194}
3195
Manoj Naik99baf622006-06-09 09:34:24 -04003196static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3197{
Al Viro8687b632006-10-19 23:28:48 -07003198 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003199 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003200
3201 *fileid = 0;
3202 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3203 return -EIO;
3204 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003205 p = xdr_inline_decode(xdr, 8);
3206 if (unlikely(!p))
3207 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003208 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003209 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003210 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003211 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003212 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003213 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003214out_overflow:
3215 print_overflow_msg(__func__, xdr);
3216 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003217}
3218
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3220{
Al Viro8687b632006-10-19 23:28:48 -07003221 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 int status = 0;
3223
3224 *res = 0;
3225 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3226 return -EIO;
3227 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003228 p = xdr_inline_decode(xdr, 8);
3229 if (unlikely(!p))
3230 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003231 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3233 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003234 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003236out_overflow:
3237 print_overflow_msg(__func__, xdr);
3238 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239}
3240
3241static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3242{
Al Viro8687b632006-10-19 23:28:48 -07003243 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 int status = 0;
3245
3246 *res = 0;
3247 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3248 return -EIO;
3249 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003250 p = xdr_inline_decode(xdr, 8);
3251 if (unlikely(!p))
3252 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003253 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3255 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003256 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003258out_overflow:
3259 print_overflow_msg(__func__, xdr);
3260 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261}
3262
3263static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3264{
Al Viro8687b632006-10-19 23:28:48 -07003265 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 int status = 0;
3267
3268 *res = 0;
3269 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3270 return -EIO;
3271 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003272 p = xdr_inline_decode(xdr, 8);
3273 if (unlikely(!p))
3274 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003275 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3277 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003278 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003280out_overflow:
3281 print_overflow_msg(__func__, xdr);
3282 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283}
3284
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003285static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3286{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003287 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003288 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003289 int status = 0;
3290
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 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003295 if (n == 0)
3296 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003297 dprintk("path ");
3298 path->ncomponents = 0;
3299 while (path->ncomponents < n) {
3300 struct nfs4_string *component = &path->components[path->ncomponents];
3301 status = decode_opaque_inline(xdr, &component->len, &component->data);
3302 if (unlikely(status != 0))
3303 goto out_eio;
3304 if (path->ncomponents != n)
3305 dprintk("/");
3306 dprintk("%s", component->data);
3307 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3308 path->ncomponents++;
3309 else {
3310 dprintk("cannot parse %d components in path\n", n);
3311 goto out_eio;
3312 }
3313 }
3314out:
3315 dprintk("\n");
3316 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003317root_path:
3318/* a root pathname is sent as a zero component4 */
3319 path->ncomponents = 1;
3320 path->components[0].len=0;
3321 path->components[0].data=NULL;
3322 dprintk("path /\n");
3323 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003324out_eio:
3325 dprintk(" status %d", status);
3326 status = -EIO;
3327 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003328out_overflow:
3329 print_overflow_msg(__func__, xdr);
3330 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003331}
3332
3333static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003334{
3335 int n;
Al Viro8687b632006-10-19 23:28:48 -07003336 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003337 int status = -EIO;
3338
3339 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3340 goto out;
3341 status = 0;
3342 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3343 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003344 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003345 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003346 if (unlikely(status != 0))
3347 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003348 p = xdr_inline_decode(xdr, 4);
3349 if (unlikely(!p))
3350 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003351 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003352 if (n <= 0)
3353 goto out_eio;
3354 res->nlocations = 0;
3355 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003356 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003357 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003358
Benny Halevyc0eae662009-08-14 17:20:14 +03003359 p = xdr_inline_decode(xdr, 4);
3360 if (unlikely(!p))
3361 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003362 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003363
3364 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003365 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003366 while (loc->nservers < m) {
3367 struct nfs4_string *server = &loc->servers[loc->nservers];
3368 status = decode_opaque_inline(xdr, &server->len, &server->data);
3369 if (unlikely(status != 0))
3370 goto out_eio;
3371 dprintk("%s ", server->data);
3372 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3373 loc->nservers++;
3374 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003375 unsigned int i;
3376 dprintk("%s: using first %u of %u servers "
3377 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003378 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003379 NFS4_FS_LOCATION_MAXSERVERS,
3380 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003381 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003382 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003383 char *data;
3384 status = decode_opaque_inline(xdr, &len, &data);
3385 if (unlikely(status != 0))
3386 goto out_eio;
3387 }
3388 }
3389 }
3390 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003391 if (unlikely(status != 0))
3392 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003393 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003394 res->nlocations++;
3395 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003396 if (res->nlocations != 0)
3397 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003398out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003399 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003400 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003401out_overflow:
3402 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003403out_eio:
3404 status = -EIO;
3405 goto out;
3406}
3407
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3409{
Al Viro8687b632006-10-19 23:28:48 -07003410 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 int status = 0;
3412
3413 *res = 0;
3414 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3415 return -EIO;
3416 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003417 p = xdr_inline_decode(xdr, 8);
3418 if (unlikely(!p))
3419 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003420 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3422 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003423 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003425out_overflow:
3426 print_overflow_msg(__func__, xdr);
3427 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428}
3429
3430static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3431{
Al Viro8687b632006-10-19 23:28:48 -07003432 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 int status = 0;
3434
3435 *maxlink = 1;
3436 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3437 return -EIO;
3438 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003439 p = xdr_inline_decode(xdr, 4);
3440 if (unlikely(!p))
3441 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003442 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3444 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003445 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003447out_overflow:
3448 print_overflow_msg(__func__, xdr);
3449 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450}
3451
3452static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3453{
Al Viro8687b632006-10-19 23:28:48 -07003454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 int status = 0;
3456
3457 *maxname = 1024;
3458 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3459 return -EIO;
3460 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003461 p = xdr_inline_decode(xdr, 4);
3462 if (unlikely(!p))
3463 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003464 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3466 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003467 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003469out_overflow:
3470 print_overflow_msg(__func__, xdr);
3471 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472}
3473
3474static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3475{
Al Viro8687b632006-10-19 23:28:48 -07003476 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 int status = 0;
3478
3479 *res = 1024;
3480 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3481 return -EIO;
3482 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3483 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003484 p = xdr_inline_decode(xdr, 8);
3485 if (unlikely(!p))
3486 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003487 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 if (maxread > 0x7FFFFFFF)
3489 maxread = 0x7FFFFFFF;
3490 *res = (uint32_t)maxread;
3491 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3492 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003493 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003495out_overflow:
3496 print_overflow_msg(__func__, xdr);
3497 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498}
3499
3500static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3501{
Al Viro8687b632006-10-19 23:28:48 -07003502 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 int status = 0;
3504
3505 *res = 1024;
3506 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3507 return -EIO;
3508 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3509 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003510 p = xdr_inline_decode(xdr, 8);
3511 if (unlikely(!p))
3512 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003513 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 if (maxwrite > 0x7FFFFFFF)
3515 maxwrite = 0x7FFFFFFF;
3516 *res = (uint32_t)maxwrite;
3517 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3518 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003519 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003521out_overflow:
3522 print_overflow_msg(__func__, xdr);
3523 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524}
3525
Trond Myklebustbca79472009-03-11 14:10:26 -04003526static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527{
Trond Myklebustbca79472009-03-11 14:10:26 -04003528 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003529 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003530 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531
3532 *mode = 0;
3533 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3534 return -EIO;
3535 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003536 p = xdr_inline_decode(xdr, 4);
3537 if (unlikely(!p))
3538 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003539 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003540 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003542 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003544 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003545 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003546out_overflow:
3547 print_overflow_msg(__func__, xdr);
3548 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549}
3550
3551static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3552{
Al Viro8687b632006-10-19 23:28:48 -07003553 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003554 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555
3556 *nlink = 1;
3557 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3558 return -EIO;
3559 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003560 p = xdr_inline_decode(xdr, 4);
3561 if (unlikely(!p))
3562 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003563 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003565 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003567 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003568 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003569out_overflow:
3570 print_overflow_msg(__func__, xdr);
3571 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572}
3573
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003574static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003575 const struct nfs_server *server, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576{
Al Viro8687b632006-10-19 23:28:48 -07003577 uint32_t len;
3578 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003579 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580
3581 *uid = -2;
3582 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3583 return -EIO;
3584 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003585 p = xdr_inline_decode(xdr, 4);
3586 if (unlikely(!p))
3587 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003588 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003589 p = xdr_inline_decode(xdr, len);
3590 if (unlikely(!p))
3591 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003592 if (!may_sleep) {
3593 /* do nothing */
3594 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003595 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003596 ret = NFS_ATTR_FATTR_OWNER;
3597 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003599 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003601 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003602 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3604 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003605 dprintk("%s: uid=%d\n", __func__, (int)*uid);
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
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003612static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003613 const struct nfs_server *server, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614{
Al Viro8687b632006-10-19 23:28:48 -07003615 uint32_t len;
3616 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003617 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618
3619 *gid = -2;
3620 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3621 return -EIO;
3622 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003623 p = xdr_inline_decode(xdr, 4);
3624 if (unlikely(!p))
3625 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003626 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003627 p = xdr_inline_decode(xdr, len);
3628 if (unlikely(!p))
3629 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003630 if (!may_sleep) {
3631 /* do nothing */
3632 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003633 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003634 ret = NFS_ATTR_FATTR_GROUP;
3635 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003637 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003639 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003640 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3642 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003643 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003644 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003645out_overflow:
3646 print_overflow_msg(__func__, xdr);
3647 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648}
3649
3650static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3651{
Al Viro8687b632006-10-19 23:28:48 -07003652 uint32_t major = 0, minor = 0;
3653 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003654 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655
3656 *rdev = MKDEV(0,0);
3657 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3658 return -EIO;
3659 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3660 dev_t tmp;
3661
Benny Halevyc0eae662009-08-14 17:20:14 +03003662 p = xdr_inline_decode(xdr, 8);
3663 if (unlikely(!p))
3664 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003665 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003666 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667 tmp = MKDEV(major, minor);
3668 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3669 *rdev = tmp;
3670 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003671 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003673 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003674 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003675out_overflow:
3676 print_overflow_msg(__func__, xdr);
3677 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678}
3679
3680static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3681{
Al Viro8687b632006-10-19 23:28:48 -07003682 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 int status = 0;
3684
3685 *res = 0;
3686 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3687 return -EIO;
3688 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003689 p = xdr_inline_decode(xdr, 8);
3690 if (unlikely(!p))
3691 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003692 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3694 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003695 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 return status;
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_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3703{
Al Viro8687b632006-10-19 23:28:48 -07003704 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 int status = 0;
3706
3707 *res = 0;
3708 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3709 return -EIO;
3710 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003711 p = xdr_inline_decode(xdr, 8);
3712 if (unlikely(!p))
3713 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003714 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3716 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003717 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003719out_overflow:
3720 print_overflow_msg(__func__, xdr);
3721 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722}
3723
3724static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3725{
Al Viro8687b632006-10-19 23:28:48 -07003726 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727 int status = 0;
3728
3729 *res = 0;
3730 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3731 return -EIO;
3732 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003733 p = xdr_inline_decode(xdr, 8);
3734 if (unlikely(!p))
3735 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003736 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3738 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003739 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003741out_overflow:
3742 print_overflow_msg(__func__, xdr);
3743 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744}
3745
3746static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3747{
Al Viro8687b632006-10-19 23:28:48 -07003748 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003749 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750
3751 *used = 0;
3752 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3753 return -EIO;
3754 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003755 p = xdr_inline_decode(xdr, 8);
3756 if (unlikely(!p))
3757 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003758 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003760 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003762 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003764 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003765out_overflow:
3766 print_overflow_msg(__func__, xdr);
3767 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768}
3769
3770static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3771{
Al Viro8687b632006-10-19 23:28:48 -07003772 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773 uint64_t sec;
3774 uint32_t nsec;
3775
Benny Halevyc0eae662009-08-14 17:20:14 +03003776 p = xdr_inline_decode(xdr, 12);
3777 if (unlikely(!p))
3778 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003779 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003780 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 time->tv_sec = (time_t)sec;
3782 time->tv_nsec = (long)nsec;
3783 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003784out_overflow:
3785 print_overflow_msg(__func__, xdr);
3786 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787}
3788
3789static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3790{
3791 int status = 0;
3792
3793 time->tv_sec = 0;
3794 time->tv_nsec = 0;
3795 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3796 return -EIO;
3797 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3798 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003799 if (status == 0)
3800 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3802 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003803 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 return status;
3805}
3806
3807static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3808{
3809 int status = 0;
3810
3811 time->tv_sec = 0;
3812 time->tv_nsec = 0;
3813 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3814 return -EIO;
3815 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3816 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003817 if (status == 0)
3818 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3820 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003821 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 return status;
3823}
3824
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003825static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3826 struct timespec *time)
3827{
3828 int status = 0;
3829
3830 time->tv_sec = 0;
3831 time->tv_nsec = 0;
3832 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3833 return -EIO;
3834 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3835 status = decode_attr_time(xdr, time);
3836 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3837 }
3838 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3839 (long)time->tv_nsec);
3840 return status;
3841}
3842
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3844{
3845 int status = 0;
3846
3847 time->tv_sec = 0;
3848 time->tv_nsec = 0;
3849 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3850 return -EIO;
3851 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3852 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003853 if (status == 0)
3854 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3856 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003857 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 return status;
3859}
3860
Al Viro8687b632006-10-19 23:28:48 -07003861static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862{
3863 unsigned int attrwords = XDR_QUADLEN(attrlen);
3864 unsigned int nwords = xdr->p - savep;
3865
3866 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003867 dprintk("%s: server returned incorrect attribute length: "
3868 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003869 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 attrwords << 2,
3871 (attrwords < nwords) ? '<' : '>',
3872 nwords << 2);
3873 return -EIO;
3874 }
3875 return 0;
3876}
3877
3878static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3879{
Al Viro8687b632006-10-19 23:28:48 -07003880 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881
Benny Halevyc0eae662009-08-14 17:20:14 +03003882 p = xdr_inline_decode(xdr, 20);
3883 if (unlikely(!p))
3884 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003885 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003886 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003887 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003889out_overflow:
3890 print_overflow_msg(__func__, xdr);
3891 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892}
3893
3894static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3895{
Al Viro8687b632006-10-19 23:28:48 -07003896 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 uint32_t supp, acc;
3898 int status;
3899
3900 status = decode_op_hdr(xdr, OP_ACCESS);
3901 if (status)
3902 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003903 p = xdr_inline_decode(xdr, 8);
3904 if (unlikely(!p))
3905 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003906 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003907 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 access->supported = supp;
3909 access->access = acc;
3910 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003911out_overflow:
3912 print_overflow_msg(__func__, xdr);
3913 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914}
3915
Benny Halevy07d30432009-08-14 17:19:52 +03003916static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917{
Al Viro8687b632006-10-19 23:28:48 -07003918 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003919
3920 p = xdr_inline_decode(xdr, len);
3921 if (likely(p)) {
3922 memcpy(buf, p, len);
3923 return 0;
3924 }
3925 print_overflow_msg(__func__, xdr);
3926 return -EIO;
3927}
3928
3929static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3930{
3931 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932}
3933
3934static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3935{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 int status;
3937
3938 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003939 if (status != -EIO)
3940 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003941 if (!status)
3942 status = decode_stateid(xdr, &res->stateid);
3943 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944}
3945
Benny Halevydb942bb2009-08-14 17:19:56 +03003946static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3947{
3948 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949}
3950
3951static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3952{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 int status;
3954
3955 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003956 if (!status)
3957 status = decode_verifier(xdr, res->verf->verifier);
3958 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959}
3960
3961static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3962{
Al Viro8687b632006-10-19 23:28:48 -07003963 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 uint32_t bmlen;
3965 int status;
3966
3967 status = decode_op_hdr(xdr, OP_CREATE);
3968 if (status)
3969 return status;
3970 if ((status = decode_change_info(xdr, cinfo)))
3971 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003972 p = xdr_inline_decode(xdr, 4);
3973 if (unlikely(!p))
3974 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003975 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003976 p = xdr_inline_decode(xdr, bmlen << 2);
3977 if (likely(p))
3978 return 0;
3979out_overflow:
3980 print_overflow_msg(__func__, xdr);
3981 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982}
3983
3984static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3985{
Al Viro8687b632006-10-19 23:28:48 -07003986 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003987 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 int status;
3989
3990 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3991 goto xdr_error;
3992 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3993 goto xdr_error;
3994 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3995 goto xdr_error;
3996 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3997 goto xdr_error;
3998 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3999 goto xdr_error;
4000 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4001 goto xdr_error;
4002 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4003 goto xdr_error;
4004 status = verify_attr_len(xdr, savep, attrlen);
4005xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004006 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007 return status;
4008}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004009
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4011{
Al Viro8687b632006-10-19 23:28:48 -07004012 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004013 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004015
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4017 goto xdr_error;
4018 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4019 goto xdr_error;
4020 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4021 goto xdr_error;
4022
4023 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4024 goto xdr_error;
4025 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4026 goto xdr_error;
4027 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4028 goto xdr_error;
4029 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4030 goto xdr_error;
4031 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4032 goto xdr_error;
4033 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4034 goto xdr_error;
4035
4036 status = verify_attr_len(xdr, savep, attrlen);
4037xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004038 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039 return status;
4040}
4041
4042static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4043{
Al Viro8687b632006-10-19 23:28:48 -07004044 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004045 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004047
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4049 goto xdr_error;
4050 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4051 goto xdr_error;
4052 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4053 goto xdr_error;
4054
4055 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4056 goto xdr_error;
4057 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4058 goto xdr_error;
4059
4060 status = verify_attr_len(xdr, savep, attrlen);
4061xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004062 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063 return status;
4064}
4065
Bryan Schumakerae42c702010-10-21 16:33:17 -04004066static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4067 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004068 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069{
Trond Myklebustbca79472009-03-11 14:10:26 -04004070 int status;
4071 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004072 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004073 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004075 status = decode_attr_type(xdr, bitmap, &type);
4076 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004078 fattr->mode = 0;
4079 if (status != 0) {
4080 fattr->mode |= nfs_type2fmt[type];
4081 fattr->valid |= status;
4082 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004084 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4085 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004087 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004088
4089 status = decode_attr_size(xdr, bitmap, &fattr->size);
4090 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004092 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004093
4094 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4095 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004097 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004098
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004099 err = 0;
4100 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004101 if (status < 0)
4102 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004103 if (err == -NFS4ERR_WRONGSEC)
4104 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004105
4106 status = decode_attr_filehandle(xdr, bitmap, fh);
4107 if (status < 0)
4108 goto xdr_error;
4109
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004110 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4111 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004113 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004114
4115 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04004116 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004117 fattr));
4118 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004119 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004120 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004121
4122 status = decode_attr_mode(xdr, bitmap, &fmode);
4123 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004125 if (status != 0) {
4126 fattr->mode |= fmode;
4127 fattr->valid |= status;
4128 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004129
4130 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4131 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004133 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004134
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004135 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004136 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004138 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004139
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004140 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004141 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004143 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004144
4145 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4146 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004148 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004149
4150 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4151 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004153 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004154
4155 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4156 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004158 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004159
4160 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4161 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004163 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004164
4165 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4166 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004168 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004169
Trond Myklebust28331a42011-04-27 13:47:52 -04004170 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004171 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004172 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004173 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004174
Bryan Schumakerae42c702010-10-21 16:33:17 -04004175xdr_error:
4176 dprintk("%s: xdr returned %d\n", __func__, -status);
4177 return status;
4178}
4179
4180static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4181 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4182{
4183 __be32 *savep;
4184 uint32_t attrlen,
4185 bitmap[2] = {0};
4186 int status;
4187
4188 status = decode_op_hdr(xdr, OP_GETATTR);
4189 if (status < 0)
4190 goto xdr_error;
4191
4192 status = decode_attr_bitmap(xdr, bitmap);
4193 if (status < 0)
4194 goto xdr_error;
4195
4196 status = decode_attr_length(xdr, &attrlen, &savep);
4197 if (status < 0)
4198 goto xdr_error;
4199
4200 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4201 if (status < 0)
4202 goto xdr_error;
4203
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004204 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004206 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 return status;
4208}
4209
Bryan Schumakerae42c702010-10-21 16:33:17 -04004210static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4211 const struct nfs_server *server, int may_sleep)
4212{
4213 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4214}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215
Andy Adamson504913f2010-10-20 00:17:57 -04004216/*
4217 * Decode potentially multiple layout types. Currently we only support
4218 * one layout driver per file system.
4219 */
4220static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4221 uint32_t *layouttype)
4222{
4223 uint32_t *p;
4224 int num;
4225
4226 p = xdr_inline_decode(xdr, 4);
4227 if (unlikely(!p))
4228 goto out_overflow;
4229 num = be32_to_cpup(p);
4230
4231 /* pNFS is not supported by the underlying file system */
4232 if (num == 0) {
4233 *layouttype = 0;
4234 return 0;
4235 }
4236 if (num > 1)
4237 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4238 "per filesystem not supported\n", __func__);
4239
4240 /* Decode and set first layout type, move xdr->p past unused types */
4241 p = xdr_inline_decode(xdr, num * 4);
4242 if (unlikely(!p))
4243 goto out_overflow;
4244 *layouttype = be32_to_cpup(p);
4245 return 0;
4246out_overflow:
4247 print_overflow_msg(__func__, xdr);
4248 return -EIO;
4249}
4250
4251/*
4252 * The type of file system exported.
4253 * Note we must ensure that layouttype is set in any non-error case.
4254 */
4255static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4256 uint32_t *layouttype)
4257{
4258 int status = 0;
4259
4260 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4261 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4262 return -EIO;
4263 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4264 status = decode_first_pnfs_layout_type(xdr, layouttype);
4265 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4266 } else
4267 *layouttype = 0;
4268 return status;
4269}
4270
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4272{
Al Viro8687b632006-10-19 23:28:48 -07004273 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274 uint32_t attrlen, bitmap[2];
4275 int status;
4276
4277 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4278 goto xdr_error;
4279 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4280 goto xdr_error;
4281 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4282 goto xdr_error;
4283
4284 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4285
4286 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4287 goto xdr_error;
4288 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4289 goto xdr_error;
4290 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4291 goto xdr_error;
4292 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4293 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4294 goto xdr_error;
4295 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004296 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4297 if (status != 0)
4298 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004299 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4300 if (status != 0)
4301 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302
4303 status = verify_attr_len(xdr, savep, attrlen);
4304xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004305 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 return status;
4307}
4308
4309static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4310{
Al Viro8687b632006-10-19 23:28:48 -07004311 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312 uint32_t len;
4313 int status;
4314
Trond Myklebust99367812007-07-17 21:52:41 -04004315 /* Zero handle first to allow comparisons */
4316 memset(fh, 0, sizeof(*fh));
4317
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 status = decode_op_hdr(xdr, OP_GETFH);
4319 if (status)
4320 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321
Benny Halevyc0eae662009-08-14 17:20:14 +03004322 p = xdr_inline_decode(xdr, 4);
4323 if (unlikely(!p))
4324 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004325 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 if (len > NFS4_FHSIZE)
4327 return -EIO;
4328 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004329 p = xdr_inline_decode(xdr, len);
4330 if (unlikely(!p))
4331 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004332 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004334out_overflow:
4335 print_overflow_msg(__func__, xdr);
4336 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337}
4338
4339static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4340{
4341 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004342
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 status = decode_op_hdr(xdr, OP_LINK);
4344 if (status)
4345 return status;
4346 return decode_change_info(xdr, cinfo);
4347}
4348
4349/*
4350 * We create the owner, so we know a proper owner.id length is 4.
4351 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004352static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004354 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004355 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004356 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004358 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004359 if (unlikely(!p))
4360 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004361 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004362 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004363 type = be32_to_cpup(p++); /* 4 byte read */
4364 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004365 fl->fl_start = (loff_t)offset;
4366 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4367 if (length == ~(uint64_t)0)
4368 fl->fl_end = OFFSET_MAX;
4369 fl->fl_type = F_WRLCK;
4370 if (type & 1)
4371 fl->fl_type = F_RDLCK;
4372 fl->fl_pid = 0;
4373 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004374 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4375 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4376 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004377 if (likely(p))
4378 return -NFS4ERR_DENIED;
4379out_overflow:
4380 print_overflow_msg(__func__, xdr);
4381 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382}
4383
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004384static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386 int status;
4387
4388 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004389 if (status == -EIO)
4390 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004391 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004392 status = decode_stateid(xdr, &res->stateid);
4393 if (unlikely(status))
4394 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004396 status = decode_lock_denied(xdr, NULL);
4397 if (res->open_seqid != NULL)
4398 nfs_increment_open_seqid(status, res->open_seqid);
4399 nfs_increment_lock_seqid(status, res->lock_seqid);
4400out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 return status;
4402}
4403
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004404static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405{
4406 int status;
4407 status = decode_op_hdr(xdr, OP_LOCKT);
4408 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004409 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410 return status;
4411}
4412
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004413static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415 int status;
4416
4417 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004418 if (status != -EIO)
4419 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004420 if (status == 0)
4421 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422 return status;
4423}
4424
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004425static int decode_release_lockowner(struct xdr_stream *xdr)
4426{
4427 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4428}
4429
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430static int decode_lookup(struct xdr_stream *xdr)
4431{
4432 return decode_op_hdr(xdr, OP_LOOKUP);
4433}
4434
4435/* This is too sick! */
4436static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4437{
Andy Adamson05d564f2008-12-23 16:06:15 -05004438 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004439 uint32_t limit_type, nblocks, blocksize;
4440
Benny Halevyc0eae662009-08-14 17:20:14 +03004441 p = xdr_inline_decode(xdr, 12);
4442 if (unlikely(!p))
4443 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004444 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004446 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004447 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004448 break;
4449 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004450 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004451 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004452 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 }
4454 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004455out_overflow:
4456 print_overflow_msg(__func__, xdr);
4457 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458}
4459
4460static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4461{
Andy Adamson05d564f2008-12-23 16:06:15 -05004462 __be32 *p;
4463 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004464 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465
Benny Halevyc0eae662009-08-14 17:20:14 +03004466 p = xdr_inline_decode(xdr, 4);
4467 if (unlikely(!p))
4468 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004469 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4471 res->delegation_type = 0;
4472 return 0;
4473 }
Benny Halevy07d30432009-08-14 17:19:52 +03004474 status = decode_stateid(xdr, &res->delegation);
4475 if (unlikely(status))
4476 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004477 p = xdr_inline_decode(xdr, 4);
4478 if (unlikely(!p))
4479 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004480 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004481
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004483 case NFS4_OPEN_DELEGATE_READ:
4484 res->delegation_type = FMODE_READ;
4485 break;
4486 case NFS4_OPEN_DELEGATE_WRITE:
4487 res->delegation_type = FMODE_WRITE|FMODE_READ;
4488 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 return -EIO;
4490 }
David Howells7539bba2006-08-22 20:06:09 -04004491 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004492out_overflow:
4493 print_overflow_msg(__func__, xdr);
4494 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495}
4496
4497static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4498{
Andy Adamson05d564f2008-12-23 16:06:15 -05004499 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004500 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004501 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502
Andy Adamson05d564f2008-12-23 16:06:15 -05004503 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004504 if (status != -EIO)
4505 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004506 if (!status)
4507 status = decode_stateid(xdr, &res->stateid);
4508 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004509 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510
Andy Adamson05d564f2008-12-23 16:06:15 -05004511 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004512
Benny Halevyc0eae662009-08-14 17:20:14 +03004513 p = xdr_inline_decode(xdr, 8);
4514 if (unlikely(!p))
4515 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004516 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004517 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004518 if (bmlen > 10)
4519 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004520
Benny Halevyc0eae662009-08-14 17:20:14 +03004521 p = xdr_inline_decode(xdr, bmlen << 2);
4522 if (unlikely(!p))
4523 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004524 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4525 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004526 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004527 for (; i < NFS4_BITMAP_SIZE; i++)
4528 res->attrset[i] = 0;
4529
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530 return decode_delegation(xdr, res);
4531xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004532 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004534out_overflow:
4535 print_overflow_msg(__func__, xdr);
4536 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004537}
4538
4539static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4540{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004541 int status;
4542
Andy Adamson05d564f2008-12-23 16:06:15 -05004543 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004544 if (status != -EIO)
4545 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004546 if (!status)
4547 status = decode_stateid(xdr, &res->stateid);
4548 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549}
4550
4551static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4552{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553 int status;
4554
4555 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004556 if (status != -EIO)
4557 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004558 if (!status)
4559 status = decode_stateid(xdr, &res->stateid);
4560 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561}
4562
4563static int decode_putfh(struct xdr_stream *xdr)
4564{
4565 return decode_op_hdr(xdr, OP_PUTFH);
4566}
4567
4568static int decode_putrootfh(struct xdr_stream *xdr)
4569{
4570 return decode_op_hdr(xdr, OP_PUTROOTFH);
4571}
4572
4573static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4574{
4575 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004576 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577 uint32_t count, eof, recvd, hdrlen;
4578 int status;
4579
4580 status = decode_op_hdr(xdr, OP_READ);
4581 if (status)
4582 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004583 p = xdr_inline_decode(xdr, 8);
4584 if (unlikely(!p))
4585 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004586 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004587 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004588 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004589 recvd = req->rq_rcv_buf.len - hdrlen;
4590 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004591 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 "count %u > recvd %u\n", count, recvd);
4593 count = recvd;
4594 eof = 0;
4595 }
4596 xdr_read_pages(xdr, count);
4597 res->eof = eof;
4598 res->count = count;
4599 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004600out_overflow:
4601 print_overflow_msg(__func__, xdr);
4602 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603}
4604
4605static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4606{
4607 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004609 size_t hdrlen;
4610 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004611 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004612
4613 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004614 if (!status)
4615 status = decode_verifier(xdr, readdir->verifier.data);
4616 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004618 dprintk("%s: verifier = %08x:%08x\n",
4619 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004620 ((u32 *)readdir->verifier.data)[0],
4621 ((u32 *)readdir->verifier.data)[1]);
4622
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623
Benny Halevydb942bb2009-08-14 17:19:56 +03004624 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625 recvd = rcvbuf->len - hdrlen;
4626 if (pglen > recvd)
4627 pglen = recvd;
4628 xdr_read_pages(xdr, pglen);
4629
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004630
Trond Myklebustac396122010-11-15 20:26:22 -05004631 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632}
4633
4634static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4635{
4636 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4637 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004638 size_t hdrlen;
4639 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004640 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641 int status;
4642
4643 status = decode_op_hdr(xdr, OP_READLINK);
4644 if (status)
4645 return status;
4646
4647 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004648 p = xdr_inline_decode(xdr, 4);
4649 if (unlikely(!p))
4650 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004651 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004653 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654 return -ENAMETOOLONG;
4655 }
4656 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4657 recvd = req->rq_rcv_buf.len - hdrlen;
4658 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004659 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 "count %u > recvd %u\n", len, recvd);
4661 return -EIO;
4662 }
4663 xdr_read_pages(xdr, len);
4664 /*
4665 * The XDR encode routine has set things up so that
4666 * the link text will be copied directly into the
4667 * buffer. We just have to do overflow-checking,
4668 * and and null-terminate the text (the VFS expects
4669 * null-termination).
4670 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004671 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004672 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004673out_overflow:
4674 print_overflow_msg(__func__, xdr);
4675 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004676}
4677
4678static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4679{
4680 int status;
4681
4682 status = decode_op_hdr(xdr, OP_REMOVE);
4683 if (status)
4684 goto out;
4685 status = decode_change_info(xdr, cinfo);
4686out:
4687 return status;
4688}
4689
4690static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4691 struct nfs4_change_info *new_cinfo)
4692{
4693 int status;
4694
4695 status = decode_op_hdr(xdr, OP_RENAME);
4696 if (status)
4697 goto out;
4698 if ((status = decode_change_info(xdr, old_cinfo)))
4699 goto out;
4700 status = decode_change_info(xdr, new_cinfo);
4701out:
4702 return status;
4703}
4704
4705static int decode_renew(struct xdr_stream *xdr)
4706{
4707 return decode_op_hdr(xdr, OP_RENEW);
4708}
4709
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004710static int
4711decode_restorefh(struct xdr_stream *xdr)
4712{
4713 return decode_op_hdr(xdr, OP_RESTOREFH);
4714}
4715
J. Bruce Fields029d1052005-06-22 17:16:22 +00004716static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4717 size_t *acl_len)
4718{
Al Viro8687b632006-10-19 23:28:48 -07004719 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004720 uint32_t attrlen,
4721 bitmap[2] = {0};
4722 struct kvec *iov = req->rq_rcv_buf.head;
4723 int status;
4724
4725 *acl_len = 0;
4726 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4727 goto out;
4728 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4729 goto out;
4730 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4731 goto out;
4732
4733 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4734 return -EIO;
4735 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004736 size_t hdrlen;
4737 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004738
4739 /* We ignore &savep and don't do consistency checks on
4740 * the attr length. Let userspace figure it out.... */
4741 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4742 recvd = req->rq_rcv_buf.len - hdrlen;
4743 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004744 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004745 " acl reply: attrlen %u > recvd %u\n",
4746 attrlen, recvd);
4747 return -EINVAL;
4748 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004749 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004750 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004751 } else
4752 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004753
4754out:
4755 return status;
4756}
4757
Linus Torvalds1da177e2005-04-16 15:20:36 -07004758static int
4759decode_savefh(struct xdr_stream *xdr)
4760{
4761 return decode_op_hdr(xdr, OP_SAVEFH);
4762}
4763
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004764static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765{
Al Viro8687b632006-10-19 23:28:48 -07004766 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 uint32_t bmlen;
4768 int status;
4769
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 status = decode_op_hdr(xdr, OP_SETATTR);
4771 if (status)
4772 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004773 p = xdr_inline_decode(xdr, 4);
4774 if (unlikely(!p))
4775 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004776 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004777 p = xdr_inline_decode(xdr, bmlen << 2);
4778 if (likely(p))
4779 return 0;
4780out_overflow:
4781 print_overflow_msg(__func__, xdr);
4782 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783}
4784
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004785static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786{
Al Viro8687b632006-10-19 23:28:48 -07004787 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788 uint32_t opnum;
4789 int32_t nfserr;
4790
Benny Halevyc0eae662009-08-14 17:20:14 +03004791 p = xdr_inline_decode(xdr, 8);
4792 if (unlikely(!p))
4793 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004794 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004796 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004797 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798 return -EIO;
4799 }
Benny Halevycccddf42009-08-14 17:20:19 +03004800 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004802 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4803 if (unlikely(!p))
4804 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004805 p = xdr_decode_hyper(p, &res->clientid);
4806 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807 } else if (nfserr == NFSERR_CLID_INUSE) {
4808 uint32_t len;
4809
4810 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004811 p = xdr_inline_decode(xdr, 4);
4812 if (unlikely(!p))
4813 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004814 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004815 p = xdr_inline_decode(xdr, len);
4816 if (unlikely(!p))
4817 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818
4819 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004820 p = xdr_inline_decode(xdr, 4);
4821 if (unlikely(!p))
4822 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004823 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004824 p = xdr_inline_decode(xdr, len);
4825 if (unlikely(!p))
4826 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827 return -NFSERR_CLID_INUSE;
4828 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004829 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830
4831 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004832out_overflow:
4833 print_overflow_msg(__func__, xdr);
4834 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835}
4836
4837static int decode_setclientid_confirm(struct xdr_stream *xdr)
4838{
4839 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4840}
4841
4842static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4843{
Al Viro8687b632006-10-19 23:28:48 -07004844 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845 int status;
4846
4847 status = decode_op_hdr(xdr, OP_WRITE);
4848 if (status)
4849 return status;
4850
Benny Halevyc0eae662009-08-14 17:20:14 +03004851 p = xdr_inline_decode(xdr, 16);
4852 if (unlikely(!p))
4853 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004854 res->count = be32_to_cpup(p++);
4855 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004856 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004858out_overflow:
4859 print_overflow_msg(__func__, xdr);
4860 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861}
4862
4863static int decode_delegreturn(struct xdr_stream *xdr)
4864{
4865 return decode_op_hdr(xdr, OP_DELEGRETURN);
4866}
4867
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004868static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
4869{
4870 __be32 *p;
4871
4872 p = xdr_inline_decode(xdr, 4);
4873 if (unlikely(!p))
4874 goto out_overflow;
4875 flavor->gss.sec_oid4.len = be32_to_cpup(p);
4876 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
4877 goto out_err;
4878
4879 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
4880 if (unlikely(!p))
4881 goto out_overflow;
4882 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
4883
4884 p = xdr_inline_decode(xdr, 8);
4885 if (unlikely(!p))
4886 goto out_overflow;
4887 flavor->gss.qop4 = be32_to_cpup(p++);
4888 flavor->gss.service = be32_to_cpup(p);
4889
4890 return 0;
4891
4892out_overflow:
4893 print_overflow_msg(__func__, xdr);
4894 return -EIO;
4895out_err:
4896 return -EINVAL;
4897}
4898
4899static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
4900{
4901 struct nfs4_secinfo_flavor *sec_flavor;
4902 int status;
4903 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004904 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004905
4906 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04004907 if (status)
4908 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004909 p = xdr_inline_decode(xdr, 4);
4910 if (unlikely(!p))
4911 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004912
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004913 res->flavors->num_flavors = 0;
4914 num_flavors = be32_to_cpup(p);
4915
4916 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004917 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004918 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004919 break;
4920
4921 p = xdr_inline_decode(xdr, 4);
4922 if (unlikely(!p))
4923 goto out_overflow;
4924 sec_flavor->flavor = be32_to_cpup(p);
4925
4926 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04004927 status = decode_secinfo_gss(xdr, sec_flavor);
4928 if (status)
4929 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004930 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004931 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004932 }
4933
Bryan Schumaker613e9012011-04-27 15:28:44 -04004934out:
4935 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004936out_overflow:
4937 print_overflow_msg(__func__, xdr);
4938 return -EIO;
4939}
4940
Benny Halevy99fe60d2009-04-01 09:22:29 -04004941#if defined(CONFIG_NFS_V4_1)
4942static int decode_exchange_id(struct xdr_stream *xdr,
4943 struct nfs41_exchange_id_res *res)
4944{
4945 __be32 *p;
4946 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004947 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004948 int status;
4949 struct nfs_client *clp = res->client;
4950
4951 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4952 if (status)
4953 return status;
4954
Benny Halevyc0eae662009-08-14 17:20:14 +03004955 p = xdr_inline_decode(xdr, 8);
4956 if (unlikely(!p))
4957 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05004958 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004959 p = xdr_inline_decode(xdr, 12);
4960 if (unlikely(!p))
4961 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004962 clp->cl_seqid = be32_to_cpup(p++);
4963 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004964
4965 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004966 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004967 if (dummy != SP4_NONE)
4968 return -EIO;
4969
4970 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004971 p = xdr_inline_decode(xdr, 8);
4972 if (unlikely(!p))
4973 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004974
4975 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004976 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4977 if (unlikely(status))
4978 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004979
4980 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004981 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4982 if (unlikely(status))
4983 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004984
4985 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004986 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4987 if (unlikely(status))
4988 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004989
4990 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004991out_overflow:
4992 print_overflow_msg(__func__, xdr);
4993 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004994}
Andy Adamsonfc931582009-04-01 09:22:31 -04004995
4996static int decode_chan_attrs(struct xdr_stream *xdr,
4997 struct nfs4_channel_attrs *attrs)
4998{
4999 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005000 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005001
Benny Halevyc0eae662009-08-14 17:20:14 +03005002 p = xdr_inline_decode(xdr, 28);
5003 if (unlikely(!p))
5004 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005005 val = be32_to_cpup(p++); /* headerpadsz */
5006 if (val)
5007 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005008 attrs->max_rqst_sz = be32_to_cpup(p++);
5009 attrs->max_resp_sz = be32_to_cpup(p++);
5010 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5011 attrs->max_ops = be32_to_cpup(p++);
5012 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005013 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005014 if (unlikely(nr_attrs > 1)) {
5015 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
5016 __func__, nr_attrs);
5017 return -EINVAL;
5018 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005019 if (nr_attrs == 1) {
5020 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5021 if (unlikely(!p))
5022 goto out_overflow;
5023 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005024 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005025out_overflow:
5026 print_overflow_msg(__func__, xdr);
5027 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005028}
5029
Benny Halevye78291e2009-08-14 17:20:00 +03005030static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5031{
5032 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005033}
5034
5035static int decode_create_session(struct xdr_stream *xdr,
5036 struct nfs41_create_session_res *res)
5037{
5038 __be32 *p;
5039 int status;
5040 struct nfs_client *clp = res->client;
5041 struct nfs4_session *session = clp->cl_session;
5042
5043 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005044 if (!status)
5045 status = decode_sessionid(xdr, &session->sess_id);
5046 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005047 return status;
5048
Andy Adamsonfc931582009-04-01 09:22:31 -04005049 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005050 p = xdr_inline_decode(xdr, 8);
5051 if (unlikely(!p))
5052 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005053 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005054 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005055
5056 /* Channel attributes */
5057 status = decode_chan_attrs(xdr, &session->fc_attrs);
5058 if (!status)
5059 status = decode_chan_attrs(xdr, &session->bc_attrs);
5060 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005061out_overflow:
5062 print_overflow_msg(__func__, xdr);
5063 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005064}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005065
5066static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5067{
5068 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5069}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005070
5071static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5072{
5073 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5074}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005075#endif /* CONFIG_NFS_V4_1 */
5076
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005077static int decode_sequence(struct xdr_stream *xdr,
5078 struct nfs4_sequence_res *res,
5079 struct rpc_rqst *rqstp)
5080{
5081#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005082 struct nfs4_sessionid id;
5083 u32 dummy;
5084 int status;
5085 __be32 *p;
5086
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005087 if (!res->sr_session)
5088 return 0;
5089
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005090 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005091 if (!status)
5092 status = decode_sessionid(xdr, &id);
5093 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005094 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005095
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005096 /*
5097 * If the server returns different values for sessionID, slotID or
5098 * sequence number, the server is looney tunes.
5099 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005100 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005101
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005102 if (memcmp(id.data, res->sr_session->sess_id.data,
5103 NFS4_MAX_SESSIONID_LEN)) {
5104 dprintk("%s Invalid session id\n", __func__);
5105 goto out_err;
5106 }
Benny Halevye78291e2009-08-14 17:20:00 +03005107
Benny Halevyc0eae662009-08-14 17:20:14 +03005108 p = xdr_inline_decode(xdr, 20);
5109 if (unlikely(!p))
5110 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005111
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005112 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005113 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005114 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005115 dprintk("%s Invalid sequence number\n", __func__);
5116 goto out_err;
5117 }
5118 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005119 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005120 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005121 dprintk("%s Invalid slot id\n", __func__);
5122 goto out_err;
5123 }
5124 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005125 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005126 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005127 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005128 /* result flags */
5129 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005130 status = 0;
5131out_err:
5132 res->sr_status = status;
5133 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005134out_overflow:
5135 print_overflow_msg(__func__, xdr);
5136 status = -EIO;
5137 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005138#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005139 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005140#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005141}
5142
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005143#if defined(CONFIG_NFS_V4_1)
5144
5145static int decode_getdeviceinfo(struct xdr_stream *xdr,
5146 struct pnfs_device *pdev)
5147{
5148 __be32 *p;
5149 uint32_t len, type;
5150 int status;
5151
5152 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5153 if (status) {
5154 if (status == -ETOOSMALL) {
5155 p = xdr_inline_decode(xdr, 4);
5156 if (unlikely(!p))
5157 goto out_overflow;
5158 pdev->mincount = be32_to_cpup(p);
5159 dprintk("%s: Min count too small. mincnt = %u\n",
5160 __func__, pdev->mincount);
5161 }
5162 return status;
5163 }
5164
5165 p = xdr_inline_decode(xdr, 8);
5166 if (unlikely(!p))
5167 goto out_overflow;
5168 type = be32_to_cpup(p++);
5169 if (type != pdev->layout_type) {
5170 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5171 __func__, pdev->layout_type, type);
5172 return -EINVAL;
5173 }
5174 /*
5175 * Get the length of the opaque device_addr4. xdr_read_pages places
5176 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5177 * and places the remaining xdr data in xdr_buf->tail
5178 */
5179 pdev->mincount = be32_to_cpup(p);
5180 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5181
5182 /* Parse notification bitmap, verifying that it is zero. */
5183 p = xdr_inline_decode(xdr, 4);
5184 if (unlikely(!p))
5185 goto out_overflow;
5186 len = be32_to_cpup(p);
5187 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005188 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005189
5190 p = xdr_inline_decode(xdr, 4 * len);
5191 if (unlikely(!p))
5192 goto out_overflow;
5193 for (i = 0; i < len; i++, p++) {
5194 if (be32_to_cpup(p)) {
5195 dprintk("%s: notifications not supported\n",
5196 __func__);
5197 return -EIO;
5198 }
5199 }
5200 }
5201 return 0;
5202out_overflow:
5203 print_overflow_msg(__func__, xdr);
5204 return -EIO;
5205}
5206
5207static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5208 struct nfs4_layoutget_res *res)
5209{
5210 __be32 *p;
5211 int status;
5212 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005213 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5214 struct kvec *iov = rcvbuf->head;
5215 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005216
5217 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5218 if (status)
5219 return status;
5220 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5221 if (unlikely(!p))
5222 goto out_overflow;
5223 res->return_on_close = be32_to_cpup(p++);
5224 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5225 layout_count = be32_to_cpup(p);
5226 if (!layout_count) {
5227 dprintk("%s: server responded with empty layout array\n",
5228 __func__);
5229 return -EINVAL;
5230 }
5231
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005232 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005233 if (unlikely(!p))
5234 goto out_overflow;
5235 p = xdr_decode_hyper(p, &res->range.offset);
5236 p = xdr_decode_hyper(p, &res->range.length);
5237 res->range.iomode = be32_to_cpup(p++);
5238 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005239 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005240
5241 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5242 __func__,
5243 (unsigned long)res->range.offset,
5244 (unsigned long)res->range.length,
5245 res->range.iomode,
5246 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005247 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005248
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005249 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5250 recvd = req->rq_rcv_buf.len - hdrlen;
5251 if (res->layoutp->len > recvd) {
5252 dprintk("NFS: server cheating in layoutget reply: "
5253 "layout len %u > recvd %u\n",
5254 res->layoutp->len, recvd);
5255 return -EINVAL;
5256 }
5257
5258 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005259
5260 if (layout_count > 1) {
5261 /* We only handle a length one array at the moment. Any
5262 * further entries are just ignored. Note that this means
5263 * the client may see a response that is less than the
5264 * minimum it requested.
5265 */
5266 dprintk("%s: server responded with %d layouts, dropping tail\n",
5267 __func__, layout_count);
5268 }
5269
5270 return 0;
5271out_overflow:
5272 print_overflow_msg(__func__, xdr);
5273 return -EIO;
5274}
Andy Adamson863a3c62011-03-23 13:27:54 +00005275
Benny Halevycbe82602011-05-22 19:52:37 +03005276static int decode_layoutreturn(struct xdr_stream *xdr,
5277 struct nfs4_layoutreturn_res *res)
5278{
5279 __be32 *p;
5280 int status;
5281
5282 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5283 if (status)
5284 return status;
5285 p = xdr_inline_decode(xdr, 4);
5286 if (unlikely(!p))
5287 goto out_overflow;
5288 res->lrs_present = be32_to_cpup(p);
5289 if (res->lrs_present)
5290 status = decode_stateid(xdr, &res->stateid);
5291 return status;
5292out_overflow:
5293 print_overflow_msg(__func__, xdr);
5294 return -EIO;
5295}
5296
Andy Adamson863a3c62011-03-23 13:27:54 +00005297static int decode_layoutcommit(struct xdr_stream *xdr,
5298 struct rpc_rqst *req,
5299 struct nfs4_layoutcommit_res *res)
5300{
5301 __be32 *p;
5302 __u32 sizechanged;
5303 int status;
5304
5305 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5306 if (status)
5307 return status;
5308
5309 p = xdr_inline_decode(xdr, 4);
5310 if (unlikely(!p))
5311 goto out_overflow;
5312 sizechanged = be32_to_cpup(p);
5313
5314 if (sizechanged) {
5315 /* throw away new size */
5316 p = xdr_inline_decode(xdr, 8);
5317 if (unlikely(!p))
5318 goto out_overflow;
5319 }
5320 return 0;
5321out_overflow:
5322 print_overflow_msg(__func__, xdr);
5323 return -EIO;
5324}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005325#endif /* CONFIG_NFS_V4_1 */
5326
Linus Torvalds1da177e2005-04-16 15:20:36 -07005327/*
Benny Halevy49c25592008-12-23 16:06:16 -05005328 * END OF "GENERIC" DECODE ROUTINES.
5329 */
5330
5331/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005332 * Decode OPEN_DOWNGRADE response
5333 */
Chuck Leverbf269552010-12-14 14:59:29 +00005334static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5335 struct xdr_stream *xdr,
5336 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005337{
Andy Adamson05d564f2008-12-23 16:06:15 -05005338 struct compound_hdr hdr;
5339 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005340
Chuck Leverbf269552010-12-14 14:59:29 +00005341 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005342 if (status)
5343 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005344 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005345 if (status)
5346 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005347 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005348 if (status)
5349 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005350 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005351 if (status != 0)
5352 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005353 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005354 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005355out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005356 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005357}
5358
5359/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005360 * Decode ACCESS response
5361 */
Chuck Leverbf269552010-12-14 14:59:29 +00005362static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5363 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005364{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005365 struct compound_hdr hdr;
5366 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005367
Chuck Leverbf269552010-12-14 14:59:29 +00005368 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005369 if (status)
5370 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005371 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005372 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005373 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005374 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005375 if (status != 0)
5376 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005377 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005378 if (status != 0)
5379 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005380 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005381 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005382out:
5383 return status;
5384}
5385
5386/*
5387 * Decode LOOKUP response
5388 */
Chuck Leverbf269552010-12-14 14:59:29 +00005389static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5390 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005391{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005392 struct compound_hdr hdr;
5393 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005394
Chuck Leverbf269552010-12-14 14:59:29 +00005395 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005396 if (status)
5397 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005398 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005399 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005400 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005401 status = decode_putfh(xdr);
5402 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005403 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005404 status = decode_lookup(xdr);
5405 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005407 status = decode_getfh(xdr, res->fh);
5408 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005409 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005410 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005411 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005412out:
5413 return status;
5414}
5415
5416/*
5417 * Decode LOOKUP_ROOT response
5418 */
Chuck Leverbf269552010-12-14 14:59:29 +00005419static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5420 struct xdr_stream *xdr,
5421 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005422{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005423 struct compound_hdr hdr;
5424 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005425
Chuck Leverbf269552010-12-14 14:59:29 +00005426 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005427 if (status)
5428 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005429 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005430 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005431 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005432 status = decode_putrootfh(xdr);
5433 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005434 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005435 status = decode_getfh(xdr, res->fh);
5436 if (status == 0)
5437 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005438 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005439out:
5440 return status;
5441}
5442
5443/*
5444 * Decode REMOVE response
5445 */
Chuck Leverbf269552010-12-14 14:59:29 +00005446static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5447 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005448{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005449 struct compound_hdr hdr;
5450 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005451
Chuck Leverbf269552010-12-14 14:59:29 +00005452 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005453 if (status)
5454 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005455 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005456 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005457 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005458 status = decode_putfh(xdr);
5459 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005460 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005461 status = decode_remove(xdr, &res->cinfo);
5462 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005463 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005464 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005465 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005466out:
5467 return status;
5468}
5469
5470/*
5471 * Decode RENAME response
5472 */
Chuck Leverbf269552010-12-14 14:59:29 +00005473static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5474 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005475{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005476 struct compound_hdr hdr;
5477 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005478
Chuck Leverbf269552010-12-14 14:59:29 +00005479 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005480 if (status)
5481 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005482 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005483 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005484 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005485 status = decode_putfh(xdr);
5486 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005487 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005488 status = decode_savefh(xdr);
5489 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005490 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005491 status = decode_putfh(xdr);
5492 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005493 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005494 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5495 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005496 goto out;
5497 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005498 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005499 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005500 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005501 status = decode_restorefh(xdr);
5502 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005503 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005504 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005505 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005506out:
5507 return status;
5508}
5509
5510/*
5511 * Decode LINK response
5512 */
Chuck Leverbf269552010-12-14 14:59:29 +00005513static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5514 struct nfs4_link_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);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005520 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)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005525 status = decode_putfh(xdr);
5526 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005527 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005528 status = decode_savefh(xdr);
5529 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005530 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005531 status = decode_putfh(xdr);
5532 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005533 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005534 status = decode_link(xdr, &res->cinfo);
5535 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005536 goto out;
5537 /*
5538 * Note order: OP_LINK leaves the directory as the current
5539 * filehandle.
5540 */
Chuck Leverbf269552010-12-14 14:59:29 +00005541 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005542 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005543 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005544 status = decode_restorefh(xdr);
5545 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005546 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005547 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005548 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005549out:
5550 return status;
5551}
5552
5553/*
5554 * Decode CREATE response
5555 */
Chuck Leverbf269552010-12-14 14:59:29 +00005556static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5557 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005558{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005559 struct compound_hdr hdr;
5560 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005561
Chuck Leverbf269552010-12-14 14:59:29 +00005562 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005563 if (status)
5564 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005565 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005566 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005567 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005568 status = decode_putfh(xdr);
5569 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005570 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005571 status = decode_savefh(xdr);
5572 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005573 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005574 status = decode_create(xdr, &res->dir_cinfo);
5575 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005576 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005577 status = decode_getfh(xdr, res->fh);
5578 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005579 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005580 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005581 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005582 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005583 status = decode_restorefh(xdr);
5584 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005585 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005586 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005587 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005588out:
5589 return status;
5590}
5591
5592/*
5593 * Decode SYMLINK response
5594 */
Chuck Leverbf269552010-12-14 14:59:29 +00005595static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5596 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005597{
Chuck Leverbf269552010-12-14 14:59:29 +00005598 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005599}
5600
5601/*
5602 * Decode GETATTR response
5603 */
Chuck Leverbf269552010-12-14 14:59:29 +00005604static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5605 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005606{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005607 struct compound_hdr hdr;
5608 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005609
Chuck Leverbf269552010-12-14 14:59:29 +00005610 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005611 if (status)
5612 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005613 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005614 if (status)
5615 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005616 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005617 if (status)
5618 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005619 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005620 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005621out:
5622 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005623}
5624
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005625/*
5626 * Encode an SETACL request
5627 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005628static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5629 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005630{
Andy Adamson05d564f2008-12-23 16:06:15 -05005631 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005632 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005633 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005634
Chuck Lever9f06c712010-12-14 14:59:18 +00005635 encode_compound_hdr(xdr, req, &hdr);
5636 encode_sequence(xdr, &args->seq_args, &hdr);
5637 encode_putfh(xdr, args->fh, &hdr);
5638 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005639 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005640}
Andy Adamson05d564f2008-12-23 16:06:15 -05005641
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005642/*
5643 * Decode SETACL response
5644 */
5645static int
Chuck Leverbf269552010-12-14 14:59:29 +00005646nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005647 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005648{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005649 struct compound_hdr hdr;
5650 int status;
5651
Chuck Leverbf269552010-12-14 14:59:29 +00005652 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005653 if (status)
5654 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005655 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005656 if (status)
5657 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005658 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005659 if (status)
5660 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005661 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005662out:
5663 return status;
5664}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005665
5666/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005667 * Decode GETACL response
5668 */
5669static int
Chuck Leverbf269552010-12-14 14:59:29 +00005670nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005671 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005672{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005673 struct compound_hdr hdr;
5674 int status;
5675
Chuck Leverbf269552010-12-14 14:59:29 +00005676 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005677 if (status)
5678 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005679 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005680 if (status)
5681 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005682 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005683 if (status)
5684 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005685 status = decode_getacl(xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005686
5687out:
5688 return status;
5689}
5690
5691/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005692 * Decode CLOSE response
5693 */
Chuck Leverbf269552010-12-14 14:59:29 +00005694static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5695 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005696{
Andy Adamson05d564f2008-12-23 16:06:15 -05005697 struct compound_hdr hdr;
5698 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005699
Chuck Leverbf269552010-12-14 14:59:29 +00005700 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005701 if (status)
5702 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005703 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005704 if (status)
5705 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005706 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005707 if (status)
5708 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005709 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005710 if (status != 0)
5711 goto out;
5712 /*
5713 * Note: Server may do delete on close for this file
5714 * in which case the getattr call will fail with
5715 * an ESTALE error. Shouldn't be a problem,
5716 * though, since fattr->valid will remain unset.
5717 */
Chuck Leverbf269552010-12-14 14:59:29 +00005718 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005719 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005720out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005721 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005722}
5723
5724/*
5725 * Decode OPEN response
5726 */
Chuck Leverbf269552010-12-14 14:59:29 +00005727static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5728 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005729{
Andy Adamson05d564f2008-12-23 16:06:15 -05005730 struct compound_hdr hdr;
5731 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005732
Chuck Leverbf269552010-12-14 14:59:29 +00005733 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005734 if (status)
5735 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005736 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005737 if (status)
5738 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005739 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005740 if (status)
5741 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005742 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005743 if (status)
5744 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005745 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005746 if (status)
5747 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005748 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005749 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005750 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005751 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005752 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005753 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005754 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005755 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005756 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005757out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005758 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005759}
5760
5761/*
5762 * Decode OPEN_CONFIRM response
5763 */
Chuck Leverbf269552010-12-14 14:59:29 +00005764static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5765 struct xdr_stream *xdr,
5766 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767{
Andy Adamson05d564f2008-12-23 16:06:15 -05005768 struct compound_hdr hdr;
5769 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005770
Chuck Leverbf269552010-12-14 14:59:29 +00005771 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005772 if (status)
5773 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005774 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005775 if (status)
5776 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005777 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005778out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005779 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005780}
5781
5782/*
5783 * Decode OPEN response
5784 */
Chuck Leverbf269552010-12-14 14:59:29 +00005785static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5786 struct xdr_stream *xdr,
5787 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788{
Andy Adamson05d564f2008-12-23 16:06:15 -05005789 struct compound_hdr hdr;
5790 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005791
Chuck Leverbf269552010-12-14 14:59:29 +00005792 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005793 if (status)
5794 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005795 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005796 if (status)
5797 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005798 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005799 if (status)
5800 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005801 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005802 if (status)
5803 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005804 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005805 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005806out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005807 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005808}
5809
5810/*
5811 * Decode SETATTR response
5812 */
Chuck Leverbf269552010-12-14 14:59:29 +00005813static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5814 struct xdr_stream *xdr,
5815 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005816{
Andy Adamson05d564f2008-12-23 16:06:15 -05005817 struct compound_hdr hdr;
5818 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005819
Chuck Leverbf269552010-12-14 14:59:29 +00005820 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005821 if (status)
5822 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005823 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005824 if (status)
5825 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005826 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005827 if (status)
5828 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005829 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005830 if (status)
5831 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005832 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005833 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005834out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005835 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836}
5837
5838/*
5839 * Decode LOCK response
5840 */
Chuck Leverbf269552010-12-14 14:59:29 +00005841static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5842 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005843{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844 struct compound_hdr hdr;
5845 int status;
5846
Chuck Leverbf269552010-12-14 14:59:29 +00005847 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005848 if (status)
5849 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005850 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005851 if (status)
5852 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005853 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854 if (status)
5855 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005856 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857out:
5858 return status;
5859}
5860
5861/*
5862 * Decode LOCKT response
5863 */
Chuck Leverbf269552010-12-14 14:59:29 +00005864static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5865 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005866{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867 struct compound_hdr hdr;
5868 int status;
5869
Chuck Leverbf269552010-12-14 14:59:29 +00005870 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005871 if (status)
5872 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005873 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005874 if (status)
5875 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005876 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877 if (status)
5878 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005879 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005880out:
5881 return status;
5882}
5883
5884/*
5885 * Decode LOCKU response
5886 */
Chuck Leverbf269552010-12-14 14:59:29 +00005887static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5888 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005889{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005890 struct compound_hdr hdr;
5891 int status;
5892
Chuck Leverbf269552010-12-14 14:59:29 +00005893 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005894 if (status)
5895 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005896 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005897 if (status)
5898 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005899 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005900 if (status)
5901 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005902 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005903out:
5904 return status;
5905}
5906
Chuck Leverbf269552010-12-14 14:59:29 +00005907static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5908 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005909{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005910 struct compound_hdr hdr;
5911 int status;
5912
Chuck Leverbf269552010-12-14 14:59:29 +00005913 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005914 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005915 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005916 return status;
5917}
5918
Linus Torvalds1da177e2005-04-16 15:20:36 -07005919/*
5920 * Decode READLINK response
5921 */
Chuck Leverbf269552010-12-14 14:59:29 +00005922static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5923 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04005924 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005925{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005926 struct compound_hdr hdr;
5927 int status;
5928
Chuck Leverbf269552010-12-14 14:59:29 +00005929 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005930 if (status)
5931 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005932 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005933 if (status)
5934 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005935 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005936 if (status)
5937 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005938 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005939out:
5940 return status;
5941}
5942
5943/*
5944 * Decode READDIR response
5945 */
Chuck Leverbf269552010-12-14 14:59:29 +00005946static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5947 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005948{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005949 struct compound_hdr hdr;
5950 int status;
5951
Chuck Leverbf269552010-12-14 14:59:29 +00005952 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005953 if (status)
5954 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005955 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005956 if (status)
5957 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005958 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005959 if (status)
5960 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005961 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005962out:
5963 return status;
5964}
5965
5966/*
5967 * Decode Read response
5968 */
Chuck Leverbf269552010-12-14 14:59:29 +00005969static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5970 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005971{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972 struct compound_hdr hdr;
5973 int status;
5974
Chuck Leverbf269552010-12-14 14:59:29 +00005975 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005976 if (status)
5977 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005978 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005979 if (status)
5980 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005981 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005982 if (status)
5983 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005984 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005985 if (!status)
5986 status = res->count;
5987out:
5988 return status;
5989}
5990
5991/*
5992 * Decode WRITE response
5993 */
Chuck Leverbf269552010-12-14 14:59:29 +00005994static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5995 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005996{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997 struct compound_hdr hdr;
5998 int status;
5999
Chuck Leverbf269552010-12-14 14:59:29 +00006000 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006001 if (status)
6002 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006003 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006004 if (status)
6005 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006006 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006007 if (status)
6008 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006009 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006010 if (status)
6011 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006012 if (res->fattr)
6013 decode_getfattr(xdr, res->fattr, res->server,
6014 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006015 if (!status)
6016 status = res->count;
6017out:
6018 return status;
6019}
6020
6021/*
6022 * Decode COMMIT response
6023 */
Chuck Leverbf269552010-12-14 14:59:29 +00006024static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6025 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006026{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006027 struct compound_hdr hdr;
6028 int status;
6029
Chuck Leverbf269552010-12-14 14:59:29 +00006030 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006031 if (status)
6032 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006033 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006034 if (status)
6035 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006036 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006037 if (status)
6038 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006039 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006040 if (status)
6041 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006042 if (res->fattr)
6043 decode_getfattr(xdr, res->fattr, res->server,
6044 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006045out:
6046 return status;
6047}
6048
6049/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006050 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006051 */
Chuck Leverbf269552010-12-14 14:59:29 +00006052static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006053 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006054{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006055 struct compound_hdr hdr;
6056 int status;
6057
Chuck Leverbf269552010-12-14 14:59:29 +00006058 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006059 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006060 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006061 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006062 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006063 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006064 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006065 return status;
6066}
6067
6068/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006069 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006070 */
Chuck Leverbf269552010-12-14 14:59:29 +00006071static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006072 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006073{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006074 struct compound_hdr hdr;
6075 int status;
6076
Chuck Leverbf269552010-12-14 14:59:29 +00006077 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006079 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006080 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006081 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006082 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006083 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006084 return status;
6085}
6086
6087/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006088 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089 */
Chuck Leverbf269552010-12-14 14:59:29 +00006090static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006091 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006093 struct compound_hdr hdr;
6094 int status;
6095
Chuck Leverbf269552010-12-14 14:59:29 +00006096 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006098 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006099 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006100 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006102 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103 return status;
6104}
6105
6106/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006107 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006108 */
Chuck Leverbf269552010-12-14 14:59:29 +00006109static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6110 struct xdr_stream *xdr,
6111 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006112{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113 struct compound_hdr hdr;
6114 int status;
6115
Chuck Leverbf269552010-12-14 14:59:29 +00006116 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006117 if (status)
6118 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006119 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006120 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006121 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006122 status = decode_putfh(xdr);
6123 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006124 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006125 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006126out:
6127 return status;
6128}
6129
6130/*
6131 * Decode RENEW response
6132 */
Chuck Leverbf269552010-12-14 14:59:29 +00006133static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6134 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006135{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006136 struct compound_hdr hdr;
6137 int status;
6138
Chuck Leverbf269552010-12-14 14:59:29 +00006139 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006140 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006141 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006142 return status;
6143}
6144
6145/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006146 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006147 */
Chuck Leverbf269552010-12-14 14:59:29 +00006148static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6149 struct xdr_stream *xdr,
6150 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006151{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152 struct compound_hdr hdr;
6153 int status;
6154
Chuck Leverbf269552010-12-14 14:59:29 +00006155 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006156 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006157 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006158 return status;
6159}
6160
6161/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006162 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006163 */
Chuck Leverbf269552010-12-14 14:59:29 +00006164static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6165 struct xdr_stream *xdr,
6166 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006167{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006168 struct compound_hdr hdr;
6169 int status;
6170
Chuck Leverbf269552010-12-14 14:59:29 +00006171 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006173 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006174 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006175 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006176 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006177 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006178 return status;
6179}
6180
6181/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006182 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183 */
Chuck Leverbf269552010-12-14 14:59:29 +00006184static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6185 struct xdr_stream *xdr,
6186 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188 struct compound_hdr hdr;
6189 int status;
6190
Chuck Leverbf269552010-12-14 14:59:29 +00006191 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006192 if (status)
6193 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006194 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006195 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006196 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006197 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006198 if (status != 0)
6199 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006200 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006201 if (status != 0)
6202 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006203 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006204 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01006205out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206 return status;
6207}
6208
Trond Myklebust683b57b2006-06-09 09:34:22 -04006209/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006210 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006211 */
Chuck Leverbf269552010-12-14 14:59:29 +00006212static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6213 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006214 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006215{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006216 struct compound_hdr hdr;
6217 int status;
6218
Chuck Leverbf269552010-12-14 14:59:29 +00006219 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006220 if (status)
6221 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006222 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006223 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006224 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006225 status = decode_putfh(xdr);
6226 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006227 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006228 status = decode_lookup(xdr);
6229 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006230 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006231 xdr_enter_page(xdr, PAGE_SIZE);
6232 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006233 res->fs_locations->server,
6234 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04006235out:
6236 return status;
6237}
6238
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006239/*
6240 * Decode SECINFO response
6241 */
6242static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6243 struct xdr_stream *xdr,
6244 struct nfs4_secinfo_res *res)
6245{
6246 struct compound_hdr hdr;
6247 int status;
6248
6249 status = decode_compound_hdr(xdr, &hdr);
6250 if (status)
6251 goto out;
6252 status = decode_sequence(xdr, &res->seq_res, rqstp);
6253 if (status)
6254 goto out;
6255 status = decode_putfh(xdr);
6256 if (status)
6257 goto out;
6258 status = decode_secinfo(xdr, res);
6259 if (status)
6260 goto out;
6261out:
6262 return status;
6263}
6264
Benny Halevy99fe60d2009-04-01 09:22:29 -04006265#if defined(CONFIG_NFS_V4_1)
6266/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006267 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006268 */
Chuck Leverbf269552010-12-14 14:59:29 +00006269static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6270 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006271 void *res)
6272{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006273 struct compound_hdr hdr;
6274 int status;
6275
Chuck Leverbf269552010-12-14 14:59:29 +00006276 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006277 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006278 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006279 return status;
6280}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006281
6282/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006283 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006284 */
Chuck Leverbf269552010-12-14 14:59:29 +00006285static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6286 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006287 struct nfs41_create_session_res *res)
6288{
Andy Adamsonfc931582009-04-01 09:22:31 -04006289 struct compound_hdr hdr;
6290 int status;
6291
Chuck Leverbf269552010-12-14 14:59:29 +00006292 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006293 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006294 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006295 return status;
6296}
6297
6298/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006299 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006300 */
Chuck Leverbf269552010-12-14 14:59:29 +00006301static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6302 struct xdr_stream *xdr,
6303 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006304{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006305 struct compound_hdr hdr;
6306 int status;
6307
Chuck Leverbf269552010-12-14 14:59:29 +00006308 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006309 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006311 return status;
6312}
6313
6314/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006315 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006316 */
Chuck Leverbf269552010-12-14 14:59:29 +00006317static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6318 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006319 struct nfs4_sequence_res *res)
6320{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006321 struct compound_hdr hdr;
6322 int status;
6323
Chuck Leverbf269552010-12-14 14:59:29 +00006324 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006325 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006326 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006327 return status;
6328}
6329
6330/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006331 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006332 */
Chuck Leverbf269552010-12-14 14:59:29 +00006333static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6334 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006335 struct nfs4_get_lease_time_res *res)
6336{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006337 struct compound_hdr hdr;
6338 int status;
6339
Chuck Leverbf269552010-12-14 14:59:29 +00006340 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006341 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006342 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006343 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006344 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006345 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006346 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006347 return status;
6348}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006349
6350/*
6351 * Decode RECLAIM_COMPLETE response
6352 */
Chuck Leverbf269552010-12-14 14:59:29 +00006353static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6354 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006355 struct nfs41_reclaim_complete_res *res)
6356{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006357 struct compound_hdr hdr;
6358 int status;
6359
Chuck Leverbf269552010-12-14 14:59:29 +00006360 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006361 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006362 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006363 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006365 return status;
6366}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006367
6368/*
6369 * Decode GETDEVINFO response
6370 */
Chuck Leverbf269552010-12-14 14:59:29 +00006371static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6372 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006373 struct nfs4_getdeviceinfo_res *res)
6374{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006375 struct compound_hdr hdr;
6376 int status;
6377
Chuck Leverbf269552010-12-14 14:59:29 +00006378 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006379 if (status != 0)
6380 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006381 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006382 if (status != 0)
6383 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006384 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006385out:
6386 return status;
6387}
6388
6389/*
6390 * Decode LAYOUTGET response
6391 */
Chuck Leverbf269552010-12-14 14:59:29 +00006392static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6393 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006394 struct nfs4_layoutget_res *res)
6395{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006396 struct compound_hdr hdr;
6397 int status;
6398
Chuck Leverbf269552010-12-14 14:59:29 +00006399 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006400 if (status)
6401 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006402 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006403 if (status)
6404 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006405 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006406 if (status)
6407 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006408 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006409out:
6410 return status;
6411}
Andy Adamson863a3c62011-03-23 13:27:54 +00006412
6413/*
Benny Halevycbe82602011-05-22 19:52:37 +03006414 * Decode LAYOUTRETURN response
6415 */
6416static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6417 struct xdr_stream *xdr,
6418 struct nfs4_layoutreturn_res *res)
6419{
6420 struct compound_hdr hdr;
6421 int status;
6422
6423 status = decode_compound_hdr(xdr, &hdr);
6424 if (status)
6425 goto out;
6426 status = decode_sequence(xdr, &res->seq_res, rqstp);
6427 if (status)
6428 goto out;
6429 status = decode_putfh(xdr);
6430 if (status)
6431 goto out;
6432 status = decode_layoutreturn(xdr, res);
6433out:
6434 return status;
6435}
6436
6437/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006438 * Decode LAYOUTCOMMIT response
6439 */
6440static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6441 struct xdr_stream *xdr,
6442 struct nfs4_layoutcommit_res *res)
6443{
6444 struct compound_hdr hdr;
6445 int status;
6446
6447 status = decode_compound_hdr(xdr, &hdr);
6448 if (status)
6449 goto out;
6450 status = decode_sequence(xdr, &res->seq_res, rqstp);
6451 if (status)
6452 goto out;
6453 status = decode_putfh(xdr);
6454 if (status)
6455 goto out;
6456 status = decode_layoutcommit(xdr, rqstp, res);
6457 if (status)
6458 goto out;
6459 decode_getfattr(xdr, res->fattr, res->server,
6460 !RPC_IS_ASYNC(rqstp->rq_task));
6461out:
6462 return status;
6463}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006464#endif /* CONFIG_NFS_V4_1 */
6465
Chuck Lever573c4e12010-12-14 14:58:11 +00006466/**
6467 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6468 * the local page cache.
6469 * @xdr: XDR stream where entry resides
6470 * @entry: buffer to fill in with entry data
6471 * @plus: boolean indicating whether this should be a readdirplus entry
6472 *
6473 * Returns zero if successful, otherwise a negative errno value is
6474 * returned.
6475 *
6476 * This function is not invoked during READDIR reply decoding, but
6477 * rather whenever an application invokes the getdents(2) system call
6478 * on a directory already in our cache.
6479 */
6480int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6481 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482{
6483 uint32_t bitmap[2] = {0};
6484 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006485 __be32 *p = xdr_inline_decode(xdr, 4);
6486 if (unlikely(!p))
6487 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006488 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006489 p = xdr_inline_decode(xdr, 4);
6490 if (unlikely(!p))
6491 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006492 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006493 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006494 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006495 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006496 }
6497
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006498 p = xdr_inline_decode(xdr, 12);
6499 if (unlikely(!p))
6500 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006501 entry->prev_cookie = entry->cookie;
6502 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006503 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006504
Trond Myklebust9af8c222010-10-24 11:52:55 -04006505 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006506 if (unlikely(!p))
6507 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006509
6510 /*
6511 * In case the server doesn't return an inode number,
6512 * we fake one here. (We don't use inode number 0,
6513 * since glibc seems to choke on it...)
6514 */
6515 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006516 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006517
Trond Myklebust9af8c222010-10-24 11:52:55 -04006518 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006519 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006520
6521 if (decode_attr_length(xdr, &len, &p) < 0)
6522 goto out_overflow;
6523
Chuck Lever573c4e12010-12-14 14:58:11 +00006524 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6525 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006526 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006527 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6528 entry->ino = entry->fattr->mounted_on_fileid;
6529 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006530 entry->ino = entry->fattr->fileid;
6531
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006532 entry->d_type = DT_UNKNOWN;
6533 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6534 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6535
Chuck Lever573c4e12010-12-14 14:58:11 +00006536 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006537
6538out_overflow:
6539 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006540 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541}
6542
6543/*
6544 * We need to translate between nfs status return values and
6545 * the local errno values which may not be the same.
6546 */
6547static struct {
6548 int stat;
6549 int errno;
6550} nfs_errtbl[] = {
6551 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006552 { NFS4ERR_PERM, -EPERM },
6553 { NFS4ERR_NOENT, -ENOENT },
6554 { NFS4ERR_IO, -errno_NFSERR_IO},
6555 { NFS4ERR_NXIO, -ENXIO },
6556 { NFS4ERR_ACCESS, -EACCES },
6557 { NFS4ERR_EXIST, -EEXIST },
6558 { NFS4ERR_XDEV, -EXDEV },
6559 { NFS4ERR_NOTDIR, -ENOTDIR },
6560 { NFS4ERR_ISDIR, -EISDIR },
6561 { NFS4ERR_INVAL, -EINVAL },
6562 { NFS4ERR_FBIG, -EFBIG },
6563 { NFS4ERR_NOSPC, -ENOSPC },
6564 { NFS4ERR_ROFS, -EROFS },
6565 { NFS4ERR_MLINK, -EMLINK },
6566 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6567 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6568 { NFS4ERR_DQUOT, -EDQUOT },
6569 { NFS4ERR_STALE, -ESTALE },
6570 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006571 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6572 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6573 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006574 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006575 { NFS4ERR_BADTYPE, -EBADTYPE },
6576 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006577 { NFS4ERR_SYMLINK, -ELOOP },
6578 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6579 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006580 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006581};
6582
6583/*
6584 * Convert an NFS error code to a local one.
6585 * This one is used jointly by NFSv2 and NFSv3.
6586 */
6587static int
David Howells0a8ea432006-08-22 20:06:08 -04006588nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006589{
6590 int i;
6591 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6592 if (nfs_errtbl[i].stat == stat)
6593 return nfs_errtbl[i].errno;
6594 }
6595 if (stat <= 10000 || stat > 10100) {
6596 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006597 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006598 }
6599 /* If we cannot translate the error, the recovery routines should
6600 * handle it.
6601 * Note: remaining NFSv4 error codes have values > 10000, so should
6602 * not conflict with native Linux error codes.
6603 */
Benny Halevy856dff32008-03-31 17:39:06 +03006604 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006605}
6606
Linus Torvalds1da177e2005-04-16 15:20:36 -07006607#define PROC(proc, argtype, restype) \
6608[NFSPROC4_CLNT_##proc] = { \
6609 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006610 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006611 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006612 .p_arglen = NFS4_##argtype##_sz, \
6613 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006614 .p_statidx = NFSPROC4_CLNT_##proc, \
6615 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006616}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617
6618struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006619 PROC(READ, enc_read, dec_read),
6620 PROC(WRITE, enc_write, dec_write),
6621 PROC(COMMIT, enc_commit, dec_commit),
6622 PROC(OPEN, enc_open, dec_open),
6623 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6624 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6625 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6626 PROC(CLOSE, enc_close, dec_close),
6627 PROC(SETATTR, enc_setattr, dec_setattr),
6628 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6629 PROC(RENEW, enc_renew, dec_renew),
6630 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6631 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6632 PROC(LOCK, enc_lock, dec_lock),
6633 PROC(LOCKT, enc_lockt, dec_lockt),
6634 PROC(LOCKU, enc_locku, dec_locku),
6635 PROC(ACCESS, enc_access, dec_access),
6636 PROC(GETATTR, enc_getattr, dec_getattr),
6637 PROC(LOOKUP, enc_lookup, dec_lookup),
6638 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6639 PROC(REMOVE, enc_remove, dec_remove),
6640 PROC(RENAME, enc_rename, dec_rename),
6641 PROC(LINK, enc_link, dec_link),
6642 PROC(SYMLINK, enc_symlink, dec_symlink),
6643 PROC(CREATE, enc_create, dec_create),
6644 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6645 PROC(STATFS, enc_statfs, dec_statfs),
6646 PROC(READLINK, enc_readlink, dec_readlink),
6647 PROC(READDIR, enc_readdir, dec_readdir),
6648 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6649 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6650 PROC(GETACL, enc_getacl, dec_getacl),
6651 PROC(SETACL, enc_setacl, dec_setacl),
6652 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6653 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006654 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006655#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00006656 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6657 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6658 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6659 PROC(SEQUENCE, enc_sequence, dec_sequence),
6660 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6661 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6662 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6663 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00006664 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03006665 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006666#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006667};
6668
6669struct rpc_version nfs_version4 = {
6670 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08006671 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672 .procs = nfs4_procedures
6673};
6674
6675/*
6676 * Local variables:
6677 * c-basic-offset: 8
6678 * End:
6679 */