blob: d464badc00673057898db1bba7cb345ea20555bd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
47#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050048#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000049#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/nfs.h>
51#include <linux/nfs4.h>
52#include <linux/nfs_fs.h>
53#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000054#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050055#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040056#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58#define NFSDBG_FACILITY NFSDBG_XDR
59
60/* Mapping from NFS error code to "errno" error code. */
61#define errno_NFSERR_IO EIO
62
David Howells0a8ea432006-08-22 20:06:08 -040063static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
66#ifdef DEBUG
67#define NFS4_MAXTAGLEN 20
68#else
69#define NFS4_MAXTAGLEN 0
70#endif
71
Andy Adamson6c0195a2008-12-23 16:06:15 -050072/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040073 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 */
Trond Myklebustd035c362010-12-21 10:45:27 -050075#define open_owner_id_maxsz (1 + 1 + 4)
76#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040077#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
80#define op_encode_hdr_maxsz (1)
81#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040082#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
84#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
85#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
87 (NFS4_FHSIZE >> 2))
88#define decode_putfh_maxsz (op_decode_hdr_maxsz)
89#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
90#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
91#define encode_getfh_maxsz (op_encode_hdr_maxsz)
92#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
93 ((3+NFS4_FHSIZE) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000094#define nfs4_fattr_bitmap_maxsz 3
95#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
97#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040098#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
99#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000100/* This is based on getfattr, which uses the most attributes: */
101#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400102 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000103#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
104 nfs4_fattr_value_maxsz)
105#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400106#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
107 1 + 2 + 1 + \
108 nfs4_owner_maxsz + \
109 nfs4_group_maxsz + \
110 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define encode_savefh_maxsz (op_encode_hdr_maxsz)
112#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400113#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
114#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200115#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Bryan Schumaker7ebb9312011-03-24 17:12:30 +0000116#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 15)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
118#define decode_renew_maxsz (op_decode_hdr_maxsz)
119#define encode_setclientid_maxsz \
120 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500121 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
122 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
123 1 /* sc_prog */ + \
124 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
125 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
126 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define decode_setclientid_maxsz \
128 (op_decode_hdr_maxsz + \
129 2 + \
130 1024) /* large value for CLID_INUSE */
131#define encode_setclientid_confirm_maxsz \
132 (op_encode_hdr_maxsz + \
133 3 + (NFS4_VERIFIER_SIZE >> 2))
134#define decode_setclientid_confirm_maxsz \
135 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400136#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
137#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400138#define encode_share_access_maxsz \
139 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500140#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400141#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
142#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
143#define encode_open_maxsz (op_encode_hdr_maxsz + \
144 2 + encode_share_access_maxsz + 2 + \
145 open_owner_id_maxsz + \
146 encode_opentype_maxsz + \
147 encode_claim_null_maxsz)
148#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400149#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400150 decode_ace_maxsz)
151#define decode_change_info_maxsz (5)
152#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400153 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400154 decode_change_info_maxsz + 1 + \
155 nfs4_fattr_bitmap_maxsz + \
156 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400157#define encode_open_confirm_maxsz \
158 (op_encode_hdr_maxsz + \
159 encode_stateid_maxsz + 1)
160#define decode_open_confirm_maxsz \
161 (op_decode_hdr_maxsz + \
162 decode_stateid_maxsz)
163#define encode_open_downgrade_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1 + \
166 encode_share_access_maxsz)
167#define decode_open_downgrade_maxsz \
168 (op_decode_hdr_maxsz + \
169 decode_stateid_maxsz)
170#define encode_close_maxsz (op_encode_hdr_maxsz + \
171 1 + encode_stateid_maxsz)
172#define decode_close_maxsz (op_decode_hdr_maxsz + \
173 decode_stateid_maxsz)
174#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
175 encode_stateid_maxsz + \
176 encode_attrs_maxsz)
177#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
178 nfs4_fattr_bitmap_maxsz)
179#define encode_read_maxsz (op_encode_hdr_maxsz + \
180 encode_stateid_maxsz + 3)
181#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
182#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
183 2 + encode_verifier_maxsz + 5)
184#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
185 decode_verifier_maxsz)
186#define encode_readlink_maxsz (op_encode_hdr_maxsz)
187#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
188#define encode_write_maxsz (op_encode_hdr_maxsz + \
189 encode_stateid_maxsz + 4)
190#define decode_write_maxsz (op_decode_hdr_maxsz + \
191 2 + decode_verifier_maxsz)
192#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
193#define decode_commit_maxsz (op_decode_hdr_maxsz + \
194 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195#define encode_remove_maxsz (op_encode_hdr_maxsz + \
196 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400197#define decode_remove_maxsz (op_decode_hdr_maxsz + \
198 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199#define encode_rename_maxsz (op_encode_hdr_maxsz + \
200 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400201#define decode_rename_maxsz (op_decode_hdr_maxsz + \
202 decode_change_info_maxsz + \
203 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204#define encode_link_maxsz (op_encode_hdr_maxsz + \
205 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400206#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400207#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400208#define encode_lock_maxsz (op_encode_hdr_maxsz + \
209 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400210 1 + encode_stateid_maxsz + 1 + \
211 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400212#define decode_lock_denied_maxsz \
213 (8 + decode_lockowner_maxsz)
214#define decode_lock_maxsz (op_decode_hdr_maxsz + \
215 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400216#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
217 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400218#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
219 decode_lock_denied_maxsz)
220#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
221 encode_stateid_maxsz + \
222 4)
223#define decode_locku_maxsz (op_decode_hdr_maxsz + \
224 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400225#define encode_release_lockowner_maxsz \
226 (op_encode_hdr_maxsz + \
227 encode_lockowner_maxsz)
228#define decode_release_lockowner_maxsz \
229 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400230#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
231#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
233 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400234 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000235 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
237#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400238 1 + 2 + nfs4_name_maxsz + \
239 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400240#define decode_create_maxsz (op_decode_hdr_maxsz + \
241 decode_change_info_maxsz + \
242 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400243#define encode_statfs_maxsz (encode_getattr_maxsz)
244#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
246#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400247#define encode_getacl_maxsz (encode_getattr_maxsz)
248#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
249 nfs4_fattr_bitmap_maxsz + 1)
250#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
251 encode_stateid_maxsz + 3)
252#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400253#define encode_fs_locations_maxsz \
254 (encode_getattr_maxsz)
255#define decode_fs_locations_maxsz \
256 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000257#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
258#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 4 + (NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400259
260#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400261#define NFS4_MAX_MACHINE_NAME_LEN (64)
262
Benny Halevy99fe60d2009-04-01 09:22:29 -0400263#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
264 encode_verifier_maxsz + \
265 1 /* co_ownerid.len */ + \
266 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
267 1 /* flags */ + \
268 1 /* spa_how */ + \
269 0 /* SP4_NONE (for now) */ + \
270 1 /* zero implemetation id array */)
271#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
272 2 /* eir_clientid */ + \
273 1 /* eir_sequenceid */ + \
274 1 /* eir_flags */ + \
275 1 /* spr_how */ + \
276 0 /* SP4_NONE (for now) */ + \
277 2 /* eir_server_owner.so_minor_id */ + \
278 /* eir_server_owner.so_major_id<> */ \
279 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
280 /* eir_server_scope<> */ \
281 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
282 1 /* eir_server_impl_id array length */ + \
283 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400284#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
285#define decode_channel_attrs_maxsz (6 + \
286 1 /* ca_rdma_ird.len */ + \
287 1 /* ca_rdma_ird */)
288#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
289 2 /* csa_clientid */ + \
290 1 /* csa_sequence */ + \
291 1 /* csa_flags */ + \
292 encode_channel_attrs_maxsz + \
293 encode_channel_attrs_maxsz + \
294 1 /* csa_cb_program */ + \
295 1 /* csa_sec_parms.len (1) */ + \
296 1 /* cb_secflavor (AUTH_SYS) */ + \
297 1 /* stamp */ + \
298 1 /* machinename.len */ + \
299 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
300 1 /* uid */ + \
301 1 /* gid */ + \
302 1 /* gids.len (0) */)
303#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
304 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
305 1 /* csr_sequence */ + \
306 1 /* csr_flags */ + \
307 decode_channel_attrs_maxsz + \
308 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400309#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
310#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400311#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
312 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
313#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
314 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga18019752009-12-05 16:08:40 -0500315#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
316#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400317#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
318 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
319#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
320 1 /* layout type */ + \
321 1 /* opaque devaddr4 length */ + \
322 /* devaddr4 payload is read into page */ \
323 1 /* notification bitmap length */ + \
324 1 /* notification bitmap */)
325#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
326 encode_stateid_maxsz)
327#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
328 decode_stateid_maxsz + \
329 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000330#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
331 2 /* offset */ + \
332 2 /* length */ + \
333 1 /* reclaim */ + \
334 encode_stateid_maxsz + \
335 1 /* new offset (true) */ + \
336 2 /* last byte written */ + \
337 1 /* nt_timechanged (false) */ + \
338 1 /* layoutupdate4 layout type */ + \
339 1 /* NULL filelayout layoutupdate4 payload */)
340#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
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 Labiaga18019752009-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 Halevye75bc1c2009-08-14 17:18:54 +03001728 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1729 *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 Halevye75bc1c2009-08-14 17:18:54 +03001737 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1738 *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 Labiaga18019752009-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,
1878 const struct nfs4_layoutcommit_args *args,
1879 struct compound_hdr *hdr)
1880{
1881 __be32 *p;
1882
1883 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1884 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1885
1886 p = reserve_space(xdr, 48 + NFS4_STATEID_SIZE);
1887 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1888 /* Only whole file layouts */
1889 p = xdr_encode_hyper(p, 0); /* offset */
1890 p = xdr_encode_hyper(p, NFS4_MAX_UINT64); /* length */
1891 *p++ = cpu_to_be32(0); /* reclaim */
1892 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1893 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1894 p = xdr_encode_hyper(p, args->lastbytewritten);
1895 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1896 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1897 *p++ = cpu_to_be32(0); /* no file layout payload */
1898
1899 hdr->nops++;
1900 hdr->replen += decode_layoutcommit_maxsz;
1901 return 0;
1902}
Benny Halevycbe82602011-05-22 19:52:37 +03001903
1904static void
1905encode_layoutreturn(struct xdr_stream *xdr,
1906 const struct nfs4_layoutreturn_args *args,
1907 struct compound_hdr *hdr)
1908{
1909 __be32 *p;
1910
1911 p = reserve_space(xdr, 20);
1912 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
1913 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1914 *p++ = cpu_to_be32(args->layout_type);
1915 *p++ = cpu_to_be32(IOMODE_ANY);
1916 *p = cpu_to_be32(RETURN_FILE);
1917 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
1918 p = xdr_encode_hyper(p, 0);
1919 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1920 spin_lock(&args->inode->i_lock);
1921 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1922 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001923 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1924 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1925 NFS_I(args->inode)->layout, xdr, args);
1926 } else {
1927 p = reserve_space(xdr, 4);
1928 *p = cpu_to_be32(0);
1929 }
Benny Halevycbe82602011-05-22 19:52:37 +03001930 hdr->nops++;
1931 hdr->replen += decode_layoutreturn_maxsz;
1932}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001933#endif /* CONFIG_NFS_V4_1 */
1934
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935/*
1936 * END OF "GENERIC" ENCODE ROUTINES.
1937 */
1938
Benny Halevy66cc0422009-04-01 09:22:10 -04001939static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1940{
1941#if defined(CONFIG_NFS_V4_1)
1942 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001943 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001944#endif /* CONFIG_NFS_V4_1 */
1945 return 0;
1946}
1947
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948/*
1949 * Encode an ACCESS request
1950 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001951static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1952 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001955 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957
Chuck Lever9f06c712010-12-14 14:59:18 +00001958 encode_compound_hdr(xdr, req, &hdr);
1959 encode_sequence(xdr, &args->seq_args, &hdr);
1960 encode_putfh(xdr, args->fh, &hdr);
1961 encode_access(xdr, args->access, &hdr);
1962 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001963 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964}
1965
1966/*
1967 * Encode LOOKUP request
1968 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001969static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1970 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001973 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975
Chuck Lever9f06c712010-12-14 14:59:18 +00001976 encode_compound_hdr(xdr, req, &hdr);
1977 encode_sequence(xdr, &args->seq_args, &hdr);
1978 encode_putfh(xdr, args->dir_fh, &hdr);
1979 encode_lookup(xdr, args->name, &hdr);
1980 encode_getfh(xdr, &hdr);
1981 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001982 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983}
1984
1985/*
1986 * Encode LOOKUP_ROOT request
1987 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001988static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
1989 struct xdr_stream *xdr,
1990 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001993 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
Chuck Lever9f06c712010-12-14 14:59:18 +00001996 encode_compound_hdr(xdr, req, &hdr);
1997 encode_sequence(xdr, &args->seq_args, &hdr);
1998 encode_putrootfh(xdr, &hdr);
1999 encode_getfh(xdr, &hdr);
2000 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002001 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002}
2003
2004/*
2005 * Encode REMOVE request
2006 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002007static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2008 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002011 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
Chuck Lever9f06c712010-12-14 14:59:18 +00002014 encode_compound_hdr(xdr, req, &hdr);
2015 encode_sequence(xdr, &args->seq_args, &hdr);
2016 encode_putfh(xdr, args->fh, &hdr);
2017 encode_remove(xdr, &args->name, &hdr);
2018 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002019 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020}
2021
2022/*
2023 * Encode RENAME request
2024 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002025static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2026 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002029 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
Chuck Lever9f06c712010-12-14 14:59:18 +00002032 encode_compound_hdr(xdr, req, &hdr);
2033 encode_sequence(xdr, &args->seq_args, &hdr);
2034 encode_putfh(xdr, args->old_dir, &hdr);
2035 encode_savefh(xdr, &hdr);
2036 encode_putfh(xdr, args->new_dir, &hdr);
2037 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2038 encode_getfattr(xdr, args->bitmask, &hdr);
2039 encode_restorefh(xdr, &hdr);
2040 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002041 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042}
2043
2044/*
2045 * Encode LINK request
2046 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002047static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2048 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002051 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
Chuck Lever9f06c712010-12-14 14:59:18 +00002054 encode_compound_hdr(xdr, req, &hdr);
2055 encode_sequence(xdr, &args->seq_args, &hdr);
2056 encode_putfh(xdr, args->fh, &hdr);
2057 encode_savefh(xdr, &hdr);
2058 encode_putfh(xdr, args->dir_fh, &hdr);
2059 encode_link(xdr, args->name, &hdr);
2060 encode_getfattr(xdr, args->bitmask, &hdr);
2061 encode_restorefh(xdr, &hdr);
2062 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002063 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064}
2065
2066/*
2067 * Encode CREATE request
2068 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002069static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2070 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002073 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075
Chuck Lever9f06c712010-12-14 14:59:18 +00002076 encode_compound_hdr(xdr, req, &hdr);
2077 encode_sequence(xdr, &args->seq_args, &hdr);
2078 encode_putfh(xdr, args->dir_fh, &hdr);
2079 encode_savefh(xdr, &hdr);
2080 encode_create(xdr, args, &hdr);
2081 encode_getfh(xdr, &hdr);
2082 encode_getfattr(xdr, args->bitmask, &hdr);
2083 encode_restorefh(xdr, &hdr);
2084 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002085 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086}
2087
2088/*
2089 * Encode SYMLINK request
2090 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002091static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2092 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093{
Chuck Lever9f06c712010-12-14 14:59:18 +00002094 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095}
2096
2097/*
2098 * Encode GETATTR request
2099 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002100static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2101 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002104 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106
Chuck Lever9f06c712010-12-14 14:59:18 +00002107 encode_compound_hdr(xdr, req, &hdr);
2108 encode_sequence(xdr, &args->seq_args, &hdr);
2109 encode_putfh(xdr, args->fh, &hdr);
2110 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002111 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112}
2113
2114/*
2115 * Encode a CLOSE request
2116 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002117static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2118 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119{
Andy Adamson05d564f2008-12-23 16:06:15 -05002120 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002121 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002122 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Chuck Lever9f06c712010-12-14 14:59:18 +00002124 encode_compound_hdr(xdr, req, &hdr);
2125 encode_sequence(xdr, &args->seq_args, &hdr);
2126 encode_putfh(xdr, args->fh, &hdr);
2127 encode_close(xdr, args, &hdr);
2128 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002129 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130}
2131
2132/*
2133 * Encode an OPEN request
2134 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002135static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2136 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002139 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
Chuck Lever9f06c712010-12-14 14:59:18 +00002142 encode_compound_hdr(xdr, req, &hdr);
2143 encode_sequence(xdr, &args->seq_args, &hdr);
2144 encode_putfh(xdr, args->fh, &hdr);
2145 encode_savefh(xdr, &hdr);
2146 encode_open(xdr, args, &hdr);
2147 encode_getfh(xdr, &hdr);
2148 encode_getfattr(xdr, args->bitmask, &hdr);
2149 encode_restorefh(xdr, &hdr);
2150 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002151 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152}
2153
2154/*
2155 * Encode an OPEN_CONFIRM request
2156 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002157static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2158 struct xdr_stream *xdr,
2159 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002162 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164
Chuck Lever9f06c712010-12-14 14:59:18 +00002165 encode_compound_hdr(xdr, req, &hdr);
2166 encode_putfh(xdr, args->fh, &hdr);
2167 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002168 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169}
2170
2171/*
2172 * Encode an OPEN request with no attributes.
2173 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002174static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2175 struct xdr_stream *xdr,
2176 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002179 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
Chuck Lever9f06c712010-12-14 14:59:18 +00002182 encode_compound_hdr(xdr, req, &hdr);
2183 encode_sequence(xdr, &args->seq_args, &hdr);
2184 encode_putfh(xdr, args->fh, &hdr);
2185 encode_open(xdr, args, &hdr);
2186 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002187 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188}
2189
2190/*
2191 * Encode an OPEN_DOWNGRADE request
2192 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002193static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2194 struct xdr_stream *xdr,
2195 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002198 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
Chuck Lever9f06c712010-12-14 14:59:18 +00002201 encode_compound_hdr(xdr, req, &hdr);
2202 encode_sequence(xdr, &args->seq_args, &hdr);
2203 encode_putfh(xdr, args->fh, &hdr);
2204 encode_open_downgrade(xdr, args, &hdr);
2205 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002206 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207}
2208
2209/*
2210 * Encode a LOCK request
2211 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002212static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2213 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002216 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218
Chuck Lever9f06c712010-12-14 14:59:18 +00002219 encode_compound_hdr(xdr, req, &hdr);
2220 encode_sequence(xdr, &args->seq_args, &hdr);
2221 encode_putfh(xdr, args->fh, &hdr);
2222 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002223 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224}
2225
2226/*
2227 * Encode a LOCKT request
2228 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002229static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2230 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002233 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235
Chuck Lever9f06c712010-12-14 14:59:18 +00002236 encode_compound_hdr(xdr, req, &hdr);
2237 encode_sequence(xdr, &args->seq_args, &hdr);
2238 encode_putfh(xdr, args->fh, &hdr);
2239 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002240 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241}
2242
2243/*
2244 * Encode a LOCKU request
2245 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002246static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2247 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002250 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252
Chuck Lever9f06c712010-12-14 14:59:18 +00002253 encode_compound_hdr(xdr, req, &hdr);
2254 encode_sequence(xdr, &args->seq_args, &hdr);
2255 encode_putfh(xdr, args->fh, &hdr);
2256 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002257 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258}
2259
Chuck Lever9f06c712010-12-14 14:59:18 +00002260static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2261 struct xdr_stream *xdr,
2262 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002263{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002264 struct compound_hdr hdr = {
2265 .minorversion = 0,
2266 };
2267
Chuck Lever9f06c712010-12-14 14:59:18 +00002268 encode_compound_hdr(xdr, req, &hdr);
2269 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002270 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002271}
2272
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273/*
2274 * Encode a READLINK request
2275 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002276static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2277 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002280 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282
Chuck Lever9f06c712010-12-14 14:59:18 +00002283 encode_compound_hdr(xdr, req, &hdr);
2284 encode_sequence(xdr, &args->seq_args, &hdr);
2285 encode_putfh(xdr, args->fh, &hdr);
2286 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002287
Benny Halevy28f56692009-04-01 09:22:09 -04002288 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002289 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002290 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291}
2292
2293/*
2294 * Encode a READDIR request
2295 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002296static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2297 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002300 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302
Chuck Lever9f06c712010-12-14 14:59:18 +00002303 encode_compound_hdr(xdr, req, &hdr);
2304 encode_sequence(xdr, &args->seq_args, &hdr);
2305 encode_putfh(xdr, args->fh, &hdr);
2306 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002307
Benny Halevy28f56692009-04-01 09:22:09 -04002308 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002309 args->pgbase, args->count);
2310 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002311 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002312 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002313 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314}
2315
2316/*
2317 * Encode a READ request
2318 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002319static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2320 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002323 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
Chuck Lever9f06c712010-12-14 14:59:18 +00002326 encode_compound_hdr(xdr, req, &hdr);
2327 encode_sequence(xdr, &args->seq_args, &hdr);
2328 encode_putfh(xdr, args->fh, &hdr);
2329 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
Benny Halevy28f56692009-04-01 09:22:09 -04002331 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002333 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002334 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335}
2336
2337/*
2338 * Encode an SETATTR request
2339 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002340static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2341 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342{
Andy Adamson05d564f2008-12-23 16:06:15 -05002343 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002344 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002345 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346
Chuck Lever9f06c712010-12-14 14:59:18 +00002347 encode_compound_hdr(xdr, req, &hdr);
2348 encode_sequence(xdr, &args->seq_args, &hdr);
2349 encode_putfh(xdr, args->fh, &hdr);
2350 encode_setattr(xdr, args, args->server, &hdr);
2351 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002352 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353}
2354
2355/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002356 * Encode a GETACL request
2357 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002358static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2359 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002360{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002361 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002362 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002363 };
Benny Halevy28f56692009-04-01 09:22:09 -04002364 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002365
Chuck Lever9f06c712010-12-14 14:59:18 +00002366 encode_compound_hdr(xdr, req, &hdr);
2367 encode_sequence(xdr, &args->seq_args, &hdr);
2368 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002369 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002370 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002371
Benny Halevy28f56692009-04-01 09:22:09 -04002372 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002373 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002374 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002375}
2376
2377/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 * Encode a WRITE request
2379 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002380static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2381 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002384 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386
Chuck Lever9f06c712010-12-14 14:59:18 +00002387 encode_compound_hdr(xdr, req, &hdr);
2388 encode_sequence(xdr, &args->seq_args, &hdr);
2389 encode_putfh(xdr, args->fh, &hdr);
2390 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002391 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002392 if (args->bitmask)
2393 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002394 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395}
2396
2397/*
2398 * a COMMIT request
2399 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002400static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2401 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002404 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
Chuck Lever9f06c712010-12-14 14:59:18 +00002407 encode_compound_hdr(xdr, req, &hdr);
2408 encode_sequence(xdr, &args->seq_args, &hdr);
2409 encode_putfh(xdr, args->fh, &hdr);
2410 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002411 if (args->bitmask)
2412 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002413 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414}
2415
2416/*
2417 * FSINFO request
2418 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002419static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2420 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002423 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425
Chuck Lever9f06c712010-12-14 14:59:18 +00002426 encode_compound_hdr(xdr, req, &hdr);
2427 encode_sequence(xdr, &args->seq_args, &hdr);
2428 encode_putfh(xdr, args->fh, &hdr);
2429 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002430 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431}
2432
2433/*
2434 * a PATHCONF request
2435 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002436static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2437 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002440 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442
Chuck Lever9f06c712010-12-14 14:59:18 +00002443 encode_compound_hdr(xdr, req, &hdr);
2444 encode_sequence(xdr, &args->seq_args, &hdr);
2445 encode_putfh(xdr, args->fh, &hdr);
2446 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002447 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002448 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449}
2450
2451/*
2452 * a STATFS request
2453 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002454static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2455 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002458 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460
Chuck Lever9f06c712010-12-14 14:59:18 +00002461 encode_compound_hdr(xdr, req, &hdr);
2462 encode_sequence(xdr, &args->seq_args, &hdr);
2463 encode_putfh(xdr, args->fh, &hdr);
2464 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002465 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002466 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467}
2468
2469/*
2470 * GETATTR_BITMAP request
2471 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002472static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2473 struct xdr_stream *xdr,
2474 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002477 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479
Chuck Lever9f06c712010-12-14 14:59:18 +00002480 encode_compound_hdr(xdr, req, &hdr);
2481 encode_sequence(xdr, &args->seq_args, &hdr);
2482 encode_putfh(xdr, args->fhandle, &hdr);
2483 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002484 FATTR4_WORD0_LINK_SUPPORT|
2485 FATTR4_WORD0_SYMLINK_SUPPORT|
2486 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002487 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488}
2489
2490/*
2491 * a RENEW request
2492 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002493static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2494 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002497 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 };
2499
Chuck Lever9f06c712010-12-14 14:59:18 +00002500 encode_compound_hdr(xdr, req, &hdr);
2501 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002502 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503}
2504
2505/*
2506 * a SETCLIENTID request
2507 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002508static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2509 struct xdr_stream *xdr,
2510 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002513 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 };
2515
Chuck Lever9f06c712010-12-14 14:59:18 +00002516 encode_compound_hdr(xdr, req, &hdr);
2517 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002518 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519}
2520
2521/*
2522 * a SETCLIENTID_CONFIRM request
2523 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002524static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2525 struct xdr_stream *xdr,
2526 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002529 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 };
2531 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
Chuck Lever9f06c712010-12-14 14:59:18 +00002533 encode_compound_hdr(xdr, req, &hdr);
2534 encode_setclientid_confirm(xdr, arg, &hdr);
2535 encode_putrootfh(xdr, &hdr);
2536 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002537 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538}
2539
2540/*
2541 * DELEGRETURN request
2542 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002543static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2544 struct xdr_stream *xdr,
2545 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002548 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550
Chuck Lever9f06c712010-12-14 14:59:18 +00002551 encode_compound_hdr(xdr, req, &hdr);
2552 encode_sequence(xdr, &args->seq_args, &hdr);
2553 encode_putfh(xdr, args->fhandle, &hdr);
2554 encode_delegreturn(xdr, args->stateid, &hdr);
2555 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002556 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557}
2558
2559/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002560 * Encode FS_LOCATIONS request
2561 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002562static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2563 struct xdr_stream *xdr,
2564 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002565{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002566 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002567 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002568 };
Benny Halevy28f56692009-04-01 09:22:09 -04002569 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002570
Chuck Lever9f06c712010-12-14 14:59:18 +00002571 encode_compound_hdr(xdr, req, &hdr);
2572 encode_sequence(xdr, &args->seq_args, &hdr);
2573 encode_putfh(xdr, args->dir_fh, &hdr);
2574 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002575 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002576 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002577
Benny Halevy28f56692009-04-01 09:22:09 -04002578 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002579 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002580 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002581}
2582
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002583/*
2584 * Encode SECINFO request
2585 */
2586static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2587 struct xdr_stream *xdr,
2588 struct nfs4_secinfo_arg *args)
2589{
2590 struct compound_hdr hdr = {
2591 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2592 };
2593
2594 encode_compound_hdr(xdr, req, &hdr);
2595 encode_sequence(xdr, &args->seq_args, &hdr);
2596 encode_putfh(xdr, args->dir_fh, &hdr);
2597 encode_secinfo(xdr, args->name, &hdr);
2598 encode_nops(&hdr);
2599}
2600
Benny Halevy99fe60d2009-04-01 09:22:29 -04002601#if defined(CONFIG_NFS_V4_1)
2602/*
2603 * EXCHANGE_ID request
2604 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002605static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2606 struct xdr_stream *xdr,
2607 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002608{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002609 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002610 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002611 };
2612
Chuck Lever9f06c712010-12-14 14:59:18 +00002613 encode_compound_hdr(xdr, req, &hdr);
2614 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002615 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002616}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002617
2618/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002619 * a CREATE_SESSION request
2620 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002621static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2622 struct xdr_stream *xdr,
2623 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002624{
Andy Adamsonfc931582009-04-01 09:22:31 -04002625 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002626 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002627 };
2628
Chuck Lever9f06c712010-12-14 14:59:18 +00002629 encode_compound_hdr(xdr, req, &hdr);
2630 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002631 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002632}
2633
2634/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002635 * a DESTROY_SESSION request
2636 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002637static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2638 struct xdr_stream *xdr,
2639 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002640{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002641 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002642 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002643 };
2644
Chuck Lever9f06c712010-12-14 14:59:18 +00002645 encode_compound_hdr(xdr, req, &hdr);
2646 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002647 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002648}
2649
2650/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002651 * a SEQUENCE request
2652 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002653static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2654 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002655{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002656 struct compound_hdr hdr = {
2657 .minorversion = nfs4_xdr_minorversion(args),
2658 };
2659
Chuck Lever9f06c712010-12-14 14:59:18 +00002660 encode_compound_hdr(xdr, req, &hdr);
2661 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002662 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002663}
2664
2665/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002666 * a GET_LEASE_TIME request
2667 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002668static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2669 struct xdr_stream *xdr,
2670 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002671{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002672 struct compound_hdr hdr = {
2673 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2674 };
2675 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2676
Chuck Lever9f06c712010-12-14 14:59:18 +00002677 encode_compound_hdr(xdr, req, &hdr);
2678 encode_sequence(xdr, &args->la_seq_args, &hdr);
2679 encode_putrootfh(xdr, &hdr);
2680 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002681 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002682}
Ricardo Labiaga18019752009-12-05 16:08:40 -05002683
2684/*
2685 * a RECLAIM_COMPLETE request
2686 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002687static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2688 struct xdr_stream *xdr,
2689 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga18019752009-12-05 16:08:40 -05002690{
Ricardo Labiaga18019752009-12-05 16:08:40 -05002691 struct compound_hdr hdr = {
2692 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2693 };
2694
Chuck Lever9f06c712010-12-14 14:59:18 +00002695 encode_compound_hdr(xdr, req, &hdr);
2696 encode_sequence(xdr, &args->seq_args, &hdr);
2697 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05002698 encode_nops(&hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05002699}
2700
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002701/*
2702 * Encode GETDEVICEINFO request
2703 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002704static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2705 struct xdr_stream *xdr,
2706 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002707{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002708 struct compound_hdr hdr = {
2709 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2710 };
2711
Chuck Lever9f06c712010-12-14 14:59:18 +00002712 encode_compound_hdr(xdr, req, &hdr);
2713 encode_sequence(xdr, &args->seq_args, &hdr);
2714 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002715
2716 /* set up reply kvec. Subtract notification bitmap max size (2)
2717 * so that notification bitmap is put in xdr_buf tail */
2718 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2719 args->pdev->pages, args->pdev->pgbase,
2720 args->pdev->pglen);
2721
2722 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002723}
2724
2725/*
2726 * Encode LAYOUTGET request
2727 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002728static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2729 struct xdr_stream *xdr,
2730 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002731{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002732 struct compound_hdr hdr = {
2733 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2734 };
2735
Chuck Lever9f06c712010-12-14 14:59:18 +00002736 encode_compound_hdr(xdr, req, &hdr);
2737 encode_sequence(xdr, &args->seq_args, &hdr);
2738 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2739 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002740
2741 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2742 args->layout.pages, 0, args->layout.pglen);
2743
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002744 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002745}
Andy Adamson863a3c62011-03-23 13:27:54 +00002746
2747/*
2748 * Encode LAYOUTCOMMIT request
2749 */
Benny Halevycbe82602011-05-22 19:52:37 +03002750static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2751 struct xdr_stream *xdr,
2752 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002753{
2754 struct compound_hdr hdr = {
2755 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2756 };
2757
2758 encode_compound_hdr(xdr, req, &hdr);
2759 encode_sequence(xdr, &args->seq_args, &hdr);
2760 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2761 encode_layoutcommit(xdr, args, &hdr);
2762 encode_getfattr(xdr, args->bitmask, &hdr);
2763 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002764}
2765
2766/*
2767 * Encode LAYOUTRETURN request
2768 */
2769static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2770 struct xdr_stream *xdr,
2771 struct nfs4_layoutreturn_args *args)
2772{
2773 struct compound_hdr hdr = {
2774 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2775 };
2776
2777 encode_compound_hdr(xdr, req, &hdr);
2778 encode_sequence(xdr, &args->seq_args, &hdr);
2779 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2780 encode_layoutreturn(xdr, args, &hdr);
2781 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002782}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002783#endif /* CONFIG_NFS_V4_1 */
2784
Benny Halevy686841b2009-08-14 17:19:48 +03002785static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2786{
2787 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2788 "Remaining buffer length is %tu words.\n",
2789 func, xdr->end - xdr->p);
2790}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791
Trond Myklebust683b57b2006-06-09 09:34:22 -04002792static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793{
Al Viro8687b632006-10-19 23:28:48 -07002794 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795
Benny Halevyc0eae662009-08-14 17:20:14 +03002796 p = xdr_inline_decode(xdr, 4);
2797 if (unlikely(!p))
2798 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002799 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002800 p = xdr_inline_decode(xdr, *len);
2801 if (unlikely(!p))
2802 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 *string = (char *)p;
2804 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002805out_overflow:
2806 print_overflow_msg(__func__, xdr);
2807 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808}
2809
2810static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2811{
Al Viro8687b632006-10-19 23:28:48 -07002812 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813
Benny Halevyc0eae662009-08-14 17:20:14 +03002814 p = xdr_inline_decode(xdr, 8);
2815 if (unlikely(!p))
2816 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002817 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002818 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002819
Benny Halevyc0eae662009-08-14 17:20:14 +03002820 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2821 if (unlikely(!p))
2822 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 hdr->tag = (char *)p;
2824 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002825 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002826 if (unlikely(hdr->nops < 1))
2827 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002829out_overflow:
2830 print_overflow_msg(__func__, xdr);
2831 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832}
2833
2834static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2835{
Al Viro8687b632006-10-19 23:28:48 -07002836 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 uint32_t opnum;
2838 int32_t nfserr;
2839
Benny Halevyc0eae662009-08-14 17:20:14 +03002840 p = xdr_inline_decode(xdr, 8);
2841 if (unlikely(!p))
2842 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002843 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002845 dprintk("nfs: Server returned operation"
2846 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 opnum, expected);
2848 return -EIO;
2849 }
Benny Halevycccddf42009-08-14 17:20:19 +03002850 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002852 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002854out_overflow:
2855 print_overflow_msg(__func__, xdr);
2856 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857}
2858
2859/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002860static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861{
Al Viro8687b632006-10-19 23:28:48 -07002862 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002863 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 char *str;
2865
Benny Halevyc0eae662009-08-14 17:20:14 +03002866 p = xdr_inline_decode(xdr, 12);
2867 if (likely(p))
2868 return decode_opaque_inline(xdr, &strlen, &str);
2869 print_overflow_msg(__func__, xdr);
2870 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871}
2872
2873static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2874{
Al Viro8687b632006-10-19 23:28:48 -07002875 uint32_t bmlen;
2876 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877
Benny Halevyc0eae662009-08-14 17:20:14 +03002878 p = xdr_inline_decode(xdr, 4);
2879 if (unlikely(!p))
2880 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002881 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882
2883 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002884 p = xdr_inline_decode(xdr, (bmlen << 2));
2885 if (unlikely(!p))
2886 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002888 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002890 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 }
2892 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002893out_overflow:
2894 print_overflow_msg(__func__, xdr);
2895 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896}
2897
Al Viro8687b632006-10-19 23:28:48 -07002898static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899{
Al Viro8687b632006-10-19 23:28:48 -07002900 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901
Benny Halevyc0eae662009-08-14 17:20:14 +03002902 p = xdr_inline_decode(xdr, 4);
2903 if (unlikely(!p))
2904 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002905 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 *savep = xdr->p;
2907 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002908out_overflow:
2909 print_overflow_msg(__func__, xdr);
2910 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911}
2912
2913static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2914{
2915 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04002916 int ret;
2917 ret = decode_attr_bitmap(xdr, bitmask);
2918 if (unlikely(ret < 0))
2919 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2921 } else
2922 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002923 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 return 0;
2925}
2926
2927static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2928{
Al Viro8687b632006-10-19 23:28:48 -07002929 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002930 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931
2932 *type = 0;
2933 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2934 return -EIO;
2935 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002936 p = xdr_inline_decode(xdr, 4);
2937 if (unlikely(!p))
2938 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002939 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002941 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 return -EIO;
2943 }
2944 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002945 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002947 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002948 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002949out_overflow:
2950 print_overflow_msg(__func__, xdr);
2951 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952}
2953
2954static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2955{
Al Viro8687b632006-10-19 23:28:48 -07002956 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002957 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958
2959 *change = 0;
2960 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2961 return -EIO;
2962 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002963 p = xdr_inline_decode(xdr, 8);
2964 if (unlikely(!p))
2965 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002966 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002968 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002970 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002972 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002973out_overflow:
2974 print_overflow_msg(__func__, xdr);
2975 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976}
2977
2978static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2979{
Al Viro8687b632006-10-19 23:28:48 -07002980 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002981 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982
2983 *size = 0;
2984 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2985 return -EIO;
2986 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002987 p = xdr_inline_decode(xdr, 8);
2988 if (unlikely(!p))
2989 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002990 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002992 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002994 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002995 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002996out_overflow:
2997 print_overflow_msg(__func__, xdr);
2998 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999}
3000
3001static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3002{
Al Viro8687b632006-10-19 23:28:48 -07003003 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004
3005 *res = 0;
3006 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3007 return -EIO;
3008 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003009 p = xdr_inline_decode(xdr, 4);
3010 if (unlikely(!p))
3011 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003012 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3014 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003015 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003017out_overflow:
3018 print_overflow_msg(__func__, xdr);
3019 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020}
3021
3022static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3023{
Al Viro8687b632006-10-19 23:28:48 -07003024 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025
3026 *res = 0;
3027 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3028 return -EIO;
3029 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003030 p = xdr_inline_decode(xdr, 4);
3031 if (unlikely(!p))
3032 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003033 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3035 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003036 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003038out_overflow:
3039 print_overflow_msg(__func__, xdr);
3040 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041}
3042
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003043static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044{
Al Viro8687b632006-10-19 23:28:48 -07003045 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003046 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047
3048 fsid->major = 0;
3049 fsid->minor = 0;
3050 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3051 return -EIO;
3052 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003053 p = xdr_inline_decode(xdr, 16);
3054 if (unlikely(!p))
3055 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003056 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003057 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003059 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003061 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 (unsigned long long)fsid->major,
3063 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003064 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003065out_overflow:
3066 print_overflow_msg(__func__, xdr);
3067 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068}
3069
3070static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3071{
Al Viro8687b632006-10-19 23:28:48 -07003072 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073
3074 *res = 60;
3075 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3076 return -EIO;
3077 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003078 p = xdr_inline_decode(xdr, 4);
3079 if (unlikely(!p))
3080 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003081 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3083 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003084 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003086out_overflow:
3087 print_overflow_msg(__func__, xdr);
3088 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089}
3090
Bryan Schumakerae42c702010-10-21 16:33:17 -04003091static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
3092{
3093 __be32 *p;
3094
3095 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3096 return -EIO;
3097 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3098 p = xdr_inline_decode(xdr, 4);
3099 if (unlikely(!p))
3100 goto out_overflow;
3101 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Bryan Schumaker7ebb9312011-03-24 17:12:30 +00003102 return -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003103 }
3104 return 0;
3105out_overflow:
3106 print_overflow_msg(__func__, xdr);
3107 return -EIO;
3108}
3109
3110static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3111{
3112 __be32 *p;
3113 int len;
3114
Trond Myklebust7ad07352010-10-23 15:34:20 -04003115 if (fh != NULL)
3116 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003117
3118 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3119 return -EIO;
3120 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3121 p = xdr_inline_decode(xdr, 4);
3122 if (unlikely(!p))
3123 goto out_overflow;
3124 len = be32_to_cpup(p);
3125 if (len > NFS4_FHSIZE)
3126 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003127 p = xdr_inline_decode(xdr, len);
3128 if (unlikely(!p))
3129 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003130 if (fh != NULL) {
3131 memcpy(fh->data, p, len);
3132 fh->size = len;
3133 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003134 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3135 }
3136 return 0;
3137out_overflow:
3138 print_overflow_msg(__func__, xdr);
3139 return -EIO;
3140}
3141
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3143{
Al Viro8687b632006-10-19 23:28:48 -07003144 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145
3146 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3147 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3148 return -EIO;
3149 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003150 p = xdr_inline_decode(xdr, 4);
3151 if (unlikely(!p))
3152 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003153 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3155 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003156 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003158out_overflow:
3159 print_overflow_msg(__func__, xdr);
3160 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161}
3162
3163static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3164{
Al Viro8687b632006-10-19 23:28:48 -07003165 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003166 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167
3168 *fileid = 0;
3169 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3170 return -EIO;
3171 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003172 p = xdr_inline_decode(xdr, 8);
3173 if (unlikely(!p))
3174 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003175 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003177 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003179 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003180 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003181out_overflow:
3182 print_overflow_msg(__func__, xdr);
3183 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184}
3185
Manoj Naik99baf622006-06-09 09:34:24 -04003186static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3187{
Al Viro8687b632006-10-19 23:28:48 -07003188 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003189 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003190
3191 *fileid = 0;
3192 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3193 return -EIO;
3194 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003195 p = xdr_inline_decode(xdr, 8);
3196 if (unlikely(!p))
3197 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003198 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003199 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003200 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003201 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003202 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003203 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003204out_overflow:
3205 print_overflow_msg(__func__, xdr);
3206 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003207}
3208
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3210{
Al Viro8687b632006-10-19 23:28:48 -07003211 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 int status = 0;
3213
3214 *res = 0;
3215 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3216 return -EIO;
3217 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003218 p = xdr_inline_decode(xdr, 8);
3219 if (unlikely(!p))
3220 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003221 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3223 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003224 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003226out_overflow:
3227 print_overflow_msg(__func__, xdr);
3228 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229}
3230
3231static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3232{
Al Viro8687b632006-10-19 23:28:48 -07003233 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 int status = 0;
3235
3236 *res = 0;
3237 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3238 return -EIO;
3239 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003240 p = xdr_inline_decode(xdr, 8);
3241 if (unlikely(!p))
3242 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003243 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3245 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003246 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003248out_overflow:
3249 print_overflow_msg(__func__, xdr);
3250 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251}
3252
3253static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3254{
Al Viro8687b632006-10-19 23:28:48 -07003255 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 int status = 0;
3257
3258 *res = 0;
3259 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3260 return -EIO;
3261 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003262 p = xdr_inline_decode(xdr, 8);
3263 if (unlikely(!p))
3264 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003265 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3267 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003268 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003270out_overflow:
3271 print_overflow_msg(__func__, xdr);
3272 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273}
3274
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003275static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3276{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003277 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003278 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003279 int status = 0;
3280
Benny Halevyc0eae662009-08-14 17:20:14 +03003281 p = xdr_inline_decode(xdr, 4);
3282 if (unlikely(!p))
3283 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003284 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003285 if (n == 0)
3286 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003287 dprintk("path ");
3288 path->ncomponents = 0;
3289 while (path->ncomponents < n) {
3290 struct nfs4_string *component = &path->components[path->ncomponents];
3291 status = decode_opaque_inline(xdr, &component->len, &component->data);
3292 if (unlikely(status != 0))
3293 goto out_eio;
3294 if (path->ncomponents != n)
3295 dprintk("/");
3296 dprintk("%s", component->data);
3297 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3298 path->ncomponents++;
3299 else {
3300 dprintk("cannot parse %d components in path\n", n);
3301 goto out_eio;
3302 }
3303 }
3304out:
3305 dprintk("\n");
3306 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003307root_path:
3308/* a root pathname is sent as a zero component4 */
3309 path->ncomponents = 1;
3310 path->components[0].len=0;
3311 path->components[0].data=NULL;
3312 dprintk("path /\n");
3313 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003314out_eio:
3315 dprintk(" status %d", status);
3316 status = -EIO;
3317 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003318out_overflow:
3319 print_overflow_msg(__func__, xdr);
3320 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003321}
3322
3323static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003324{
3325 int n;
Al Viro8687b632006-10-19 23:28:48 -07003326 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003327 int status = -EIO;
3328
3329 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3330 goto out;
3331 status = 0;
3332 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3333 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003334 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003335 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003336 if (unlikely(status != 0))
3337 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003338 p = xdr_inline_decode(xdr, 4);
3339 if (unlikely(!p))
3340 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003341 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003342 if (n <= 0)
3343 goto out_eio;
3344 res->nlocations = 0;
3345 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003346 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003347 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003348
Benny Halevyc0eae662009-08-14 17:20:14 +03003349 p = xdr_inline_decode(xdr, 4);
3350 if (unlikely(!p))
3351 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003352 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003353
3354 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003355 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003356 while (loc->nservers < m) {
3357 struct nfs4_string *server = &loc->servers[loc->nservers];
3358 status = decode_opaque_inline(xdr, &server->len, &server->data);
3359 if (unlikely(status != 0))
3360 goto out_eio;
3361 dprintk("%s ", server->data);
3362 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3363 loc->nservers++;
3364 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003365 unsigned int i;
3366 dprintk("%s: using first %u of %u servers "
3367 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003368 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003369 NFS4_FS_LOCATION_MAXSERVERS,
3370 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003371 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003372 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003373 char *data;
3374 status = decode_opaque_inline(xdr, &len, &data);
3375 if (unlikely(status != 0))
3376 goto out_eio;
3377 }
3378 }
3379 }
3380 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003381 if (unlikely(status != 0))
3382 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003383 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003384 res->nlocations++;
3385 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003386 if (res->nlocations != 0)
3387 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003388out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003389 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003390 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003391out_overflow:
3392 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003393out_eio:
3394 status = -EIO;
3395 goto out;
3396}
3397
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3399{
Al Viro8687b632006-10-19 23:28:48 -07003400 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 int status = 0;
3402
3403 *res = 0;
3404 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3405 return -EIO;
3406 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003407 p = xdr_inline_decode(xdr, 8);
3408 if (unlikely(!p))
3409 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003410 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3412 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003413 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003415out_overflow:
3416 print_overflow_msg(__func__, xdr);
3417 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418}
3419
3420static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3421{
Al Viro8687b632006-10-19 23:28:48 -07003422 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 int status = 0;
3424
3425 *maxlink = 1;
3426 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3427 return -EIO;
3428 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003429 p = xdr_inline_decode(xdr, 4);
3430 if (unlikely(!p))
3431 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003432 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3434 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003435 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003437out_overflow:
3438 print_overflow_msg(__func__, xdr);
3439 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440}
3441
3442static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3443{
Al Viro8687b632006-10-19 23:28:48 -07003444 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 int status = 0;
3446
3447 *maxname = 1024;
3448 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3449 return -EIO;
3450 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003451 p = xdr_inline_decode(xdr, 4);
3452 if (unlikely(!p))
3453 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003454 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3456 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003457 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003459out_overflow:
3460 print_overflow_msg(__func__, xdr);
3461 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462}
3463
3464static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3465{
Al Viro8687b632006-10-19 23:28:48 -07003466 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 int status = 0;
3468
3469 *res = 1024;
3470 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3471 return -EIO;
3472 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3473 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003474 p = xdr_inline_decode(xdr, 8);
3475 if (unlikely(!p))
3476 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003477 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478 if (maxread > 0x7FFFFFFF)
3479 maxread = 0x7FFFFFFF;
3480 *res = (uint32_t)maxread;
3481 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3482 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003483 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003485out_overflow:
3486 print_overflow_msg(__func__, xdr);
3487 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488}
3489
3490static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3491{
Al Viro8687b632006-10-19 23:28:48 -07003492 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493 int status = 0;
3494
3495 *res = 1024;
3496 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3497 return -EIO;
3498 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3499 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003500 p = xdr_inline_decode(xdr, 8);
3501 if (unlikely(!p))
3502 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003503 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 if (maxwrite > 0x7FFFFFFF)
3505 maxwrite = 0x7FFFFFFF;
3506 *res = (uint32_t)maxwrite;
3507 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3508 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003509 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003511out_overflow:
3512 print_overflow_msg(__func__, xdr);
3513 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514}
3515
Trond Myklebustbca79472009-03-11 14:10:26 -04003516static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517{
Trond Myklebustbca79472009-03-11 14:10:26 -04003518 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003519 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003520 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521
3522 *mode = 0;
3523 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3524 return -EIO;
3525 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003526 p = xdr_inline_decode(xdr, 4);
3527 if (unlikely(!p))
3528 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003529 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003530 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003532 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003534 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003535 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003536out_overflow:
3537 print_overflow_msg(__func__, xdr);
3538 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539}
3540
3541static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3542{
Al Viro8687b632006-10-19 23:28:48 -07003543 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003544 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545
3546 *nlink = 1;
3547 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3548 return -EIO;
3549 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003550 p = xdr_inline_decode(xdr, 4);
3551 if (unlikely(!p))
3552 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003553 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003555 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003557 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003558 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003559out_overflow:
3560 print_overflow_msg(__func__, xdr);
3561 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562}
3563
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003564static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003565 const struct nfs_server *server, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566{
Al Viro8687b632006-10-19 23:28:48 -07003567 uint32_t len;
3568 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003569 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570
3571 *uid = -2;
3572 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3573 return -EIO;
3574 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003575 p = xdr_inline_decode(xdr, 4);
3576 if (unlikely(!p))
3577 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003578 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003579 p = xdr_inline_decode(xdr, len);
3580 if (unlikely(!p))
3581 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003582 if (!may_sleep) {
3583 /* do nothing */
3584 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003585 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003586 ret = NFS_ATTR_FATTR_OWNER;
3587 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003589 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003591 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003592 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3594 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003595 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003596 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003597out_overflow:
3598 print_overflow_msg(__func__, xdr);
3599 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600}
3601
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003602static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003603 const struct nfs_server *server, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604{
Al Viro8687b632006-10-19 23:28:48 -07003605 uint32_t len;
3606 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003607 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608
3609 *gid = -2;
3610 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3611 return -EIO;
3612 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003613 p = xdr_inline_decode(xdr, 4);
3614 if (unlikely(!p))
3615 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003616 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003617 p = xdr_inline_decode(xdr, len);
3618 if (unlikely(!p))
3619 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003620 if (!may_sleep) {
3621 /* do nothing */
3622 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003623 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003624 ret = NFS_ATTR_FATTR_GROUP;
3625 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003627 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003629 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003630 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3632 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003633 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003634 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003635out_overflow:
3636 print_overflow_msg(__func__, xdr);
3637 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638}
3639
3640static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3641{
Al Viro8687b632006-10-19 23:28:48 -07003642 uint32_t major = 0, minor = 0;
3643 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003644 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645
3646 *rdev = MKDEV(0,0);
3647 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3648 return -EIO;
3649 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3650 dev_t tmp;
3651
Benny Halevyc0eae662009-08-14 17:20:14 +03003652 p = xdr_inline_decode(xdr, 8);
3653 if (unlikely(!p))
3654 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003655 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003656 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 tmp = MKDEV(major, minor);
3658 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3659 *rdev = tmp;
3660 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003661 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003663 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003664 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003665out_overflow:
3666 print_overflow_msg(__func__, xdr);
3667 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668}
3669
3670static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3671{
Al Viro8687b632006-10-19 23:28:48 -07003672 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 int status = 0;
3674
3675 *res = 0;
3676 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3677 return -EIO;
3678 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003679 p = xdr_inline_decode(xdr, 8);
3680 if (unlikely(!p))
3681 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003682 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3684 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003685 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003687out_overflow:
3688 print_overflow_msg(__func__, xdr);
3689 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690}
3691
3692static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3693{
Al Viro8687b632006-10-19 23:28:48 -07003694 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 int status = 0;
3696
3697 *res = 0;
3698 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3699 return -EIO;
3700 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003701 p = xdr_inline_decode(xdr, 8);
3702 if (unlikely(!p))
3703 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003704 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3706 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003707 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003709out_overflow:
3710 print_overflow_msg(__func__, xdr);
3711 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712}
3713
3714static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3715{
Al Viro8687b632006-10-19 23:28:48 -07003716 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717 int status = 0;
3718
3719 *res = 0;
3720 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3721 return -EIO;
3722 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003723 p = xdr_inline_decode(xdr, 8);
3724 if (unlikely(!p))
3725 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003726 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3728 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003729 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003731out_overflow:
3732 print_overflow_msg(__func__, xdr);
3733 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734}
3735
3736static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3737{
Al Viro8687b632006-10-19 23:28:48 -07003738 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003739 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740
3741 *used = 0;
3742 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3743 return -EIO;
3744 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003745 p = xdr_inline_decode(xdr, 8);
3746 if (unlikely(!p))
3747 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003748 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003750 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003752 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003754 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003755out_overflow:
3756 print_overflow_msg(__func__, xdr);
3757 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758}
3759
3760static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3761{
Al Viro8687b632006-10-19 23:28:48 -07003762 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763 uint64_t sec;
3764 uint32_t nsec;
3765
Benny Halevyc0eae662009-08-14 17:20:14 +03003766 p = xdr_inline_decode(xdr, 12);
3767 if (unlikely(!p))
3768 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003769 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003770 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 time->tv_sec = (time_t)sec;
3772 time->tv_nsec = (long)nsec;
3773 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003774out_overflow:
3775 print_overflow_msg(__func__, xdr);
3776 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777}
3778
3779static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3780{
3781 int status = 0;
3782
3783 time->tv_sec = 0;
3784 time->tv_nsec = 0;
3785 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3786 return -EIO;
3787 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3788 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003789 if (status == 0)
3790 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3792 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003793 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794 return status;
3795}
3796
3797static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3798{
3799 int status = 0;
3800
3801 time->tv_sec = 0;
3802 time->tv_nsec = 0;
3803 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3804 return -EIO;
3805 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3806 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003807 if (status == 0)
3808 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3810 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003811 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812 return status;
3813}
3814
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003815static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3816 struct timespec *time)
3817{
3818 int status = 0;
3819
3820 time->tv_sec = 0;
3821 time->tv_nsec = 0;
3822 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3823 return -EIO;
3824 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3825 status = decode_attr_time(xdr, time);
3826 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3827 }
3828 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3829 (long)time->tv_nsec);
3830 return status;
3831}
3832
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3834{
3835 int status = 0;
3836
3837 time->tv_sec = 0;
3838 time->tv_nsec = 0;
3839 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3840 return -EIO;
3841 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3842 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003843 if (status == 0)
3844 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3846 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003847 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 return status;
3849}
3850
Al Viro8687b632006-10-19 23:28:48 -07003851static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852{
3853 unsigned int attrwords = XDR_QUADLEN(attrlen);
3854 unsigned int nwords = xdr->p - savep;
3855
3856 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003857 dprintk("%s: server returned incorrect attribute length: "
3858 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003859 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 attrwords << 2,
3861 (attrwords < nwords) ? '<' : '>',
3862 nwords << 2);
3863 return -EIO;
3864 }
3865 return 0;
3866}
3867
3868static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3869{
Al Viro8687b632006-10-19 23:28:48 -07003870 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871
Benny Halevyc0eae662009-08-14 17:20:14 +03003872 p = xdr_inline_decode(xdr, 20);
3873 if (unlikely(!p))
3874 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003875 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003876 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003877 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003879out_overflow:
3880 print_overflow_msg(__func__, xdr);
3881 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882}
3883
3884static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3885{
Al Viro8687b632006-10-19 23:28:48 -07003886 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 uint32_t supp, acc;
3888 int status;
3889
3890 status = decode_op_hdr(xdr, OP_ACCESS);
3891 if (status)
3892 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003893 p = xdr_inline_decode(xdr, 8);
3894 if (unlikely(!p))
3895 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003896 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003897 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 access->supported = supp;
3899 access->access = acc;
3900 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003901out_overflow:
3902 print_overflow_msg(__func__, xdr);
3903 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904}
3905
Benny Halevy07d30432009-08-14 17:19:52 +03003906static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907{
Al Viro8687b632006-10-19 23:28:48 -07003908 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003909
3910 p = xdr_inline_decode(xdr, len);
3911 if (likely(p)) {
3912 memcpy(buf, p, len);
3913 return 0;
3914 }
3915 print_overflow_msg(__func__, xdr);
3916 return -EIO;
3917}
3918
3919static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3920{
3921 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922}
3923
3924static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3925{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 int status;
3927
3928 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003929 if (status != -EIO)
3930 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003931 if (!status)
3932 status = decode_stateid(xdr, &res->stateid);
3933 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934}
3935
Benny Halevydb942bb2009-08-14 17:19:56 +03003936static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3937{
3938 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939}
3940
3941static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3942{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 int status;
3944
3945 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003946 if (!status)
3947 status = decode_verifier(xdr, res->verf->verifier);
3948 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949}
3950
3951static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3952{
Al Viro8687b632006-10-19 23:28:48 -07003953 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 uint32_t bmlen;
3955 int status;
3956
3957 status = decode_op_hdr(xdr, OP_CREATE);
3958 if (status)
3959 return status;
3960 if ((status = decode_change_info(xdr, cinfo)))
3961 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003962 p = xdr_inline_decode(xdr, 4);
3963 if (unlikely(!p))
3964 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003965 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003966 p = xdr_inline_decode(xdr, bmlen << 2);
3967 if (likely(p))
3968 return 0;
3969out_overflow:
3970 print_overflow_msg(__func__, xdr);
3971 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972}
3973
3974static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3975{
Al Viro8687b632006-10-19 23:28:48 -07003976 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003977 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 int status;
3979
3980 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3981 goto xdr_error;
3982 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3983 goto xdr_error;
3984 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3985 goto xdr_error;
3986 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3987 goto xdr_error;
3988 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3989 goto xdr_error;
3990 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3991 goto xdr_error;
3992 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3993 goto xdr_error;
3994 status = verify_attr_len(xdr, savep, attrlen);
3995xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003996 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997 return status;
3998}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003999
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4001{
Al Viro8687b632006-10-19 23:28:48 -07004002 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004003 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004005
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4007 goto xdr_error;
4008 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4009 goto xdr_error;
4010 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4011 goto xdr_error;
4012
4013 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4014 goto xdr_error;
4015 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4016 goto xdr_error;
4017 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4018 goto xdr_error;
4019 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4020 goto xdr_error;
4021 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4022 goto xdr_error;
4023 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4024 goto xdr_error;
4025
4026 status = verify_attr_len(xdr, savep, attrlen);
4027xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004028 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029 return status;
4030}
4031
4032static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4033{
Al Viro8687b632006-10-19 23:28:48 -07004034 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004035 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004037
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4039 goto xdr_error;
4040 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4041 goto xdr_error;
4042 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4043 goto xdr_error;
4044
4045 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4046 goto xdr_error;
4047 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4048 goto xdr_error;
4049
4050 status = verify_attr_len(xdr, savep, attrlen);
4051xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004052 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053 return status;
4054}
4055
Bryan Schumakerae42c702010-10-21 16:33:17 -04004056static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4057 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004058 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059{
Trond Myklebustbca79472009-03-11 14:10:26 -04004060 int status;
4061 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004062 uint32_t type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004064 status = decode_attr_type(xdr, bitmap, &type);
4065 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004067 fattr->mode = 0;
4068 if (status != 0) {
4069 fattr->mode |= nfs_type2fmt[type];
4070 fattr->valid |= status;
4071 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004073 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4074 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004076 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004077
4078 status = decode_attr_size(xdr, bitmap, &fattr->size);
4079 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004081 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004082
4083 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4084 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004086 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004087
Bryan Schumakerae42c702010-10-21 16:33:17 -04004088 status = decode_attr_error(xdr, bitmap);
Bryan Schumaker7ebb9312011-03-24 17:12:30 +00004089 if (status == -NFS4ERR_WRONGSEC) {
4090 nfs_fixup_secinfo_attributes(fattr, fh);
4091 status = 0;
4092 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04004093 if (status < 0)
4094 goto xdr_error;
4095
4096 status = decode_attr_filehandle(xdr, bitmap, fh);
4097 if (status < 0)
4098 goto xdr_error;
4099
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004100 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4101 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004103 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004104
4105 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04004106 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004107 fattr));
4108 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004109 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004110 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004111
4112 status = decode_attr_mode(xdr, bitmap, &fmode);
4113 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004115 if (status != 0) {
4116 fattr->mode |= fmode;
4117 fattr->valid |= status;
4118 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004119
4120 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4121 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004123 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004124
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004125 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004126 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004128 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004129
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004130 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004131 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
4135 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4136 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
4140 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4141 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_time_access(xdr, bitmap, &fattr->atime);
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_time_metadata(xdr, bitmap, &fattr->ctime);
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_modify(xdr, bitmap, &fattr->mtime);
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
Trond Myklebust28331a42011-04-27 13:47:52 -04004160 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004161 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004162 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004163 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004164
Bryan Schumakerae42c702010-10-21 16:33:17 -04004165xdr_error:
4166 dprintk("%s: xdr returned %d\n", __func__, -status);
4167 return status;
4168}
4169
4170static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4171 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4172{
4173 __be32 *savep;
4174 uint32_t attrlen,
4175 bitmap[2] = {0};
4176 int status;
4177
4178 status = decode_op_hdr(xdr, OP_GETATTR);
4179 if (status < 0)
4180 goto xdr_error;
4181
4182 status = decode_attr_bitmap(xdr, bitmap);
4183 if (status < 0)
4184 goto xdr_error;
4185
4186 status = decode_attr_length(xdr, &attrlen, &savep);
4187 if (status < 0)
4188 goto xdr_error;
4189
4190 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4191 if (status < 0)
4192 goto xdr_error;
4193
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004194 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004196 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197 return status;
4198}
4199
Bryan Schumakerae42c702010-10-21 16:33:17 -04004200static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4201 const struct nfs_server *server, int may_sleep)
4202{
4203 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4204}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205
Andy Adamson504913f2010-10-20 00:17:57 -04004206/*
4207 * Decode potentially multiple layout types. Currently we only support
4208 * one layout driver per file system.
4209 */
4210static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4211 uint32_t *layouttype)
4212{
4213 uint32_t *p;
4214 int num;
4215
4216 p = xdr_inline_decode(xdr, 4);
4217 if (unlikely(!p))
4218 goto out_overflow;
4219 num = be32_to_cpup(p);
4220
4221 /* pNFS is not supported by the underlying file system */
4222 if (num == 0) {
4223 *layouttype = 0;
4224 return 0;
4225 }
4226 if (num > 1)
4227 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4228 "per filesystem not supported\n", __func__);
4229
4230 /* Decode and set first layout type, move xdr->p past unused types */
4231 p = xdr_inline_decode(xdr, num * 4);
4232 if (unlikely(!p))
4233 goto out_overflow;
4234 *layouttype = be32_to_cpup(p);
4235 return 0;
4236out_overflow:
4237 print_overflow_msg(__func__, xdr);
4238 return -EIO;
4239}
4240
4241/*
4242 * The type of file system exported.
4243 * Note we must ensure that layouttype is set in any non-error case.
4244 */
4245static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4246 uint32_t *layouttype)
4247{
4248 int status = 0;
4249
4250 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4251 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4252 return -EIO;
4253 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4254 status = decode_first_pnfs_layout_type(xdr, layouttype);
4255 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4256 } else
4257 *layouttype = 0;
4258 return status;
4259}
4260
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4262{
Al Viro8687b632006-10-19 23:28:48 -07004263 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264 uint32_t attrlen, bitmap[2];
4265 int status;
4266
4267 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4268 goto xdr_error;
4269 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4270 goto xdr_error;
4271 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4272 goto xdr_error;
4273
4274 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4275
4276 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4277 goto xdr_error;
4278 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4279 goto xdr_error;
4280 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4281 goto xdr_error;
4282 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4283 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4284 goto xdr_error;
4285 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004286 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4287 if (status != 0)
4288 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004289 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4290 if (status != 0)
4291 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292
4293 status = verify_attr_len(xdr, savep, attrlen);
4294xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004295 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296 return status;
4297}
4298
4299static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4300{
Al Viro8687b632006-10-19 23:28:48 -07004301 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 uint32_t len;
4303 int status;
4304
Trond Myklebust99367812007-07-17 21:52:41 -04004305 /* Zero handle first to allow comparisons */
4306 memset(fh, 0, sizeof(*fh));
4307
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308 status = decode_op_hdr(xdr, OP_GETFH);
4309 if (status)
4310 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311
Benny Halevyc0eae662009-08-14 17:20:14 +03004312 p = xdr_inline_decode(xdr, 4);
4313 if (unlikely(!p))
4314 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004315 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 if (len > NFS4_FHSIZE)
4317 return -EIO;
4318 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004319 p = xdr_inline_decode(xdr, len);
4320 if (unlikely(!p))
4321 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004322 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004324out_overflow:
4325 print_overflow_msg(__func__, xdr);
4326 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327}
4328
4329static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4330{
4331 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004332
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333 status = decode_op_hdr(xdr, OP_LINK);
4334 if (status)
4335 return status;
4336 return decode_change_info(xdr, cinfo);
4337}
4338
4339/*
4340 * We create the owner, so we know a proper owner.id length is 4.
4341 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004342static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004344 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004345 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004346 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004348 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004349 if (unlikely(!p))
4350 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004351 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004352 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004353 type = be32_to_cpup(p++); /* 4 byte read */
4354 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004355 fl->fl_start = (loff_t)offset;
4356 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4357 if (length == ~(uint64_t)0)
4358 fl->fl_end = OFFSET_MAX;
4359 fl->fl_type = F_WRLCK;
4360 if (type & 1)
4361 fl->fl_type = F_RDLCK;
4362 fl->fl_pid = 0;
4363 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004364 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4365 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4366 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004367 if (likely(p))
4368 return -NFS4ERR_DENIED;
4369out_overflow:
4370 print_overflow_msg(__func__, xdr);
4371 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004372}
4373
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004374static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004375{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376 int status;
4377
4378 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004379 if (status == -EIO)
4380 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004381 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004382 status = decode_stateid(xdr, &res->stateid);
4383 if (unlikely(status))
4384 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004386 status = decode_lock_denied(xdr, NULL);
4387 if (res->open_seqid != NULL)
4388 nfs_increment_open_seqid(status, res->open_seqid);
4389 nfs_increment_lock_seqid(status, res->lock_seqid);
4390out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004391 return status;
4392}
4393
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004394static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395{
4396 int status;
4397 status = decode_op_hdr(xdr, OP_LOCKT);
4398 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004399 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400 return status;
4401}
4402
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004403static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405 int status;
4406
4407 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004408 if (status != -EIO)
4409 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004410 if (status == 0)
4411 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004412 return status;
4413}
4414
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004415static int decode_release_lockowner(struct xdr_stream *xdr)
4416{
4417 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4418}
4419
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420static int decode_lookup(struct xdr_stream *xdr)
4421{
4422 return decode_op_hdr(xdr, OP_LOOKUP);
4423}
4424
4425/* This is too sick! */
4426static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4427{
Andy Adamson05d564f2008-12-23 16:06:15 -05004428 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429 uint32_t limit_type, nblocks, blocksize;
4430
Benny Halevyc0eae662009-08-14 17:20:14 +03004431 p = xdr_inline_decode(xdr, 12);
4432 if (unlikely(!p))
4433 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004434 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004436 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004437 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004438 break;
4439 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004440 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004441 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004442 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443 }
4444 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004445out_overflow:
4446 print_overflow_msg(__func__, xdr);
4447 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448}
4449
4450static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4451{
Andy Adamson05d564f2008-12-23 16:06:15 -05004452 __be32 *p;
4453 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004454 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455
Benny Halevyc0eae662009-08-14 17:20:14 +03004456 p = xdr_inline_decode(xdr, 4);
4457 if (unlikely(!p))
4458 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004459 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4461 res->delegation_type = 0;
4462 return 0;
4463 }
Benny Halevy07d30432009-08-14 17:19:52 +03004464 status = decode_stateid(xdr, &res->delegation);
4465 if (unlikely(status))
4466 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004467 p = xdr_inline_decode(xdr, 4);
4468 if (unlikely(!p))
4469 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004470 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004471
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004473 case NFS4_OPEN_DELEGATE_READ:
4474 res->delegation_type = FMODE_READ;
4475 break;
4476 case NFS4_OPEN_DELEGATE_WRITE:
4477 res->delegation_type = FMODE_WRITE|FMODE_READ;
4478 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004479 return -EIO;
4480 }
David Howells7539bba2006-08-22 20:06:09 -04004481 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004482out_overflow:
4483 print_overflow_msg(__func__, xdr);
4484 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004485}
4486
4487static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4488{
Andy Adamson05d564f2008-12-23 16:06:15 -05004489 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004490 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004491 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004492
Andy Adamson05d564f2008-12-23 16:06:15 -05004493 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004494 if (status != -EIO)
4495 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004496 if (!status)
4497 status = decode_stateid(xdr, &res->stateid);
4498 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004499 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004500
Andy Adamson05d564f2008-12-23 16:06:15 -05004501 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502
Benny Halevyc0eae662009-08-14 17:20:14 +03004503 p = xdr_inline_decode(xdr, 8);
4504 if (unlikely(!p))
4505 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004506 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004507 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004508 if (bmlen > 10)
4509 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510
Benny Halevyc0eae662009-08-14 17:20:14 +03004511 p = xdr_inline_decode(xdr, bmlen << 2);
4512 if (unlikely(!p))
4513 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004514 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4515 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004516 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004517 for (; i < NFS4_BITMAP_SIZE; i++)
4518 res->attrset[i] = 0;
4519
Linus Torvalds1da177e2005-04-16 15:20:36 -07004520 return decode_delegation(xdr, res);
4521xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004522 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004524out_overflow:
4525 print_overflow_msg(__func__, xdr);
4526 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527}
4528
4529static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4530{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004531 int status;
4532
Andy Adamson05d564f2008-12-23 16:06:15 -05004533 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004534 if (status != -EIO)
4535 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004536 if (!status)
4537 status = decode_stateid(xdr, &res->stateid);
4538 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004539}
4540
4541static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4542{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543 int status;
4544
4545 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004546 if (status != -EIO)
4547 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004548 if (!status)
4549 status = decode_stateid(xdr, &res->stateid);
4550 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551}
4552
4553static int decode_putfh(struct xdr_stream *xdr)
4554{
4555 return decode_op_hdr(xdr, OP_PUTFH);
4556}
4557
4558static int decode_putrootfh(struct xdr_stream *xdr)
4559{
4560 return decode_op_hdr(xdr, OP_PUTROOTFH);
4561}
4562
4563static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4564{
4565 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004566 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004567 uint32_t count, eof, recvd, hdrlen;
4568 int status;
4569
4570 status = decode_op_hdr(xdr, OP_READ);
4571 if (status)
4572 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004573 p = xdr_inline_decode(xdr, 8);
4574 if (unlikely(!p))
4575 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004576 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004577 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004578 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579 recvd = req->rq_rcv_buf.len - hdrlen;
4580 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004581 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582 "count %u > recvd %u\n", count, recvd);
4583 count = recvd;
4584 eof = 0;
4585 }
4586 xdr_read_pages(xdr, count);
4587 res->eof = eof;
4588 res->count = count;
4589 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004590out_overflow:
4591 print_overflow_msg(__func__, xdr);
4592 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593}
4594
4595static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4596{
4597 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004599 size_t hdrlen;
4600 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004601 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004602
4603 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004604 if (!status)
4605 status = decode_verifier(xdr, readdir->verifier.data);
4606 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004607 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004608 dprintk("%s: verifier = %08x:%08x\n",
4609 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004610 ((u32 *)readdir->verifier.data)[0],
4611 ((u32 *)readdir->verifier.data)[1]);
4612
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613
Benny Halevydb942bb2009-08-14 17:19:56 +03004614 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004615 recvd = rcvbuf->len - hdrlen;
4616 if (pglen > recvd)
4617 pglen = recvd;
4618 xdr_read_pages(xdr, pglen);
4619
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004620
Trond Myklebustac396122010-11-15 20:26:22 -05004621 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004622}
4623
4624static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4625{
4626 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4627 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004628 size_t hdrlen;
4629 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004630 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631 int status;
4632
4633 status = decode_op_hdr(xdr, OP_READLINK);
4634 if (status)
4635 return status;
4636
4637 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004638 p = xdr_inline_decode(xdr, 4);
4639 if (unlikely(!p))
4640 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004641 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004643 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644 return -ENAMETOOLONG;
4645 }
4646 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4647 recvd = req->rq_rcv_buf.len - hdrlen;
4648 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004649 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004650 "count %u > recvd %u\n", len, recvd);
4651 return -EIO;
4652 }
4653 xdr_read_pages(xdr, len);
4654 /*
4655 * The XDR encode routine has set things up so that
4656 * the link text will be copied directly into the
4657 * buffer. We just have to do overflow-checking,
4658 * and and null-terminate the text (the VFS expects
4659 * null-termination).
4660 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004661 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004663out_overflow:
4664 print_overflow_msg(__func__, xdr);
4665 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666}
4667
4668static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4669{
4670 int status;
4671
4672 status = decode_op_hdr(xdr, OP_REMOVE);
4673 if (status)
4674 goto out;
4675 status = decode_change_info(xdr, cinfo);
4676out:
4677 return status;
4678}
4679
4680static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4681 struct nfs4_change_info *new_cinfo)
4682{
4683 int status;
4684
4685 status = decode_op_hdr(xdr, OP_RENAME);
4686 if (status)
4687 goto out;
4688 if ((status = decode_change_info(xdr, old_cinfo)))
4689 goto out;
4690 status = decode_change_info(xdr, new_cinfo);
4691out:
4692 return status;
4693}
4694
4695static int decode_renew(struct xdr_stream *xdr)
4696{
4697 return decode_op_hdr(xdr, OP_RENEW);
4698}
4699
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004700static int
4701decode_restorefh(struct xdr_stream *xdr)
4702{
4703 return decode_op_hdr(xdr, OP_RESTOREFH);
4704}
4705
J. Bruce Fields029d1052005-06-22 17:16:22 +00004706static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4707 size_t *acl_len)
4708{
Al Viro8687b632006-10-19 23:28:48 -07004709 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004710 uint32_t attrlen,
4711 bitmap[2] = {0};
4712 struct kvec *iov = req->rq_rcv_buf.head;
4713 int status;
4714
4715 *acl_len = 0;
4716 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4717 goto out;
4718 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4719 goto out;
4720 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4721 goto out;
4722
4723 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4724 return -EIO;
4725 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004726 size_t hdrlen;
4727 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004728
4729 /* We ignore &savep and don't do consistency checks on
4730 * the attr length. Let userspace figure it out.... */
4731 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4732 recvd = req->rq_rcv_buf.len - hdrlen;
4733 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004734 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004735 " acl reply: attrlen %u > recvd %u\n",
4736 attrlen, recvd);
4737 return -EINVAL;
4738 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004739 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004740 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004741 } else
4742 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004743
4744out:
4745 return status;
4746}
4747
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748static int
4749decode_savefh(struct xdr_stream *xdr)
4750{
4751 return decode_op_hdr(xdr, OP_SAVEFH);
4752}
4753
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004754static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755{
Al Viro8687b632006-10-19 23:28:48 -07004756 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757 uint32_t bmlen;
4758 int status;
4759
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760 status = decode_op_hdr(xdr, OP_SETATTR);
4761 if (status)
4762 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004763 p = xdr_inline_decode(xdr, 4);
4764 if (unlikely(!p))
4765 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004766 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004767 p = xdr_inline_decode(xdr, bmlen << 2);
4768 if (likely(p))
4769 return 0;
4770out_overflow:
4771 print_overflow_msg(__func__, xdr);
4772 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773}
4774
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004775static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004776{
Al Viro8687b632006-10-19 23:28:48 -07004777 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 uint32_t opnum;
4779 int32_t nfserr;
4780
Benny Halevyc0eae662009-08-14 17:20:14 +03004781 p = xdr_inline_decode(xdr, 8);
4782 if (unlikely(!p))
4783 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004784 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004786 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004787 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788 return -EIO;
4789 }
Benny Halevycccddf42009-08-14 17:20:19 +03004790 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004791 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004792 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4793 if (unlikely(!p))
4794 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004795 p = xdr_decode_hyper(p, &res->clientid);
4796 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 } else if (nfserr == NFSERR_CLID_INUSE) {
4798 uint32_t len;
4799
4800 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004801 p = xdr_inline_decode(xdr, 4);
4802 if (unlikely(!p))
4803 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004804 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004805 p = xdr_inline_decode(xdr, len);
4806 if (unlikely(!p))
4807 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808
4809 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004810 p = xdr_inline_decode(xdr, 4);
4811 if (unlikely(!p))
4812 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004813 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004814 p = xdr_inline_decode(xdr, len);
4815 if (unlikely(!p))
4816 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817 return -NFSERR_CLID_INUSE;
4818 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004819 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820
4821 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004822out_overflow:
4823 print_overflow_msg(__func__, xdr);
4824 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825}
4826
4827static int decode_setclientid_confirm(struct xdr_stream *xdr)
4828{
4829 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4830}
4831
4832static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4833{
Al Viro8687b632006-10-19 23:28:48 -07004834 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835 int status;
4836
4837 status = decode_op_hdr(xdr, OP_WRITE);
4838 if (status)
4839 return status;
4840
Benny Halevyc0eae662009-08-14 17:20:14 +03004841 p = xdr_inline_decode(xdr, 16);
4842 if (unlikely(!p))
4843 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004844 res->count = be32_to_cpup(p++);
4845 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004846 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004848out_overflow:
4849 print_overflow_msg(__func__, xdr);
4850 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851}
4852
4853static int decode_delegreturn(struct xdr_stream *xdr)
4854{
4855 return decode_op_hdr(xdr, OP_DELEGRETURN);
4856}
4857
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004858static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
4859{
4860 __be32 *p;
4861
4862 p = xdr_inline_decode(xdr, 4);
4863 if (unlikely(!p))
4864 goto out_overflow;
4865 flavor->gss.sec_oid4.len = be32_to_cpup(p);
4866 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
4867 goto out_err;
4868
4869 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
4870 if (unlikely(!p))
4871 goto out_overflow;
4872 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
4873
4874 p = xdr_inline_decode(xdr, 8);
4875 if (unlikely(!p))
4876 goto out_overflow;
4877 flavor->gss.qop4 = be32_to_cpup(p++);
4878 flavor->gss.service = be32_to_cpup(p);
4879
4880 return 0;
4881
4882out_overflow:
4883 print_overflow_msg(__func__, xdr);
4884 return -EIO;
4885out_err:
4886 return -EINVAL;
4887}
4888
4889static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
4890{
4891 struct nfs4_secinfo_flavor *sec_flavor;
4892 int status;
4893 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004894 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004895
4896 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04004897 if (status)
4898 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004899 p = xdr_inline_decode(xdr, 4);
4900 if (unlikely(!p))
4901 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004902
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004903 res->flavors->num_flavors = 0;
4904 num_flavors = be32_to_cpup(p);
4905
4906 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004907 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004908 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004909 break;
4910
4911 p = xdr_inline_decode(xdr, 4);
4912 if (unlikely(!p))
4913 goto out_overflow;
4914 sec_flavor->flavor = be32_to_cpup(p);
4915
4916 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04004917 status = decode_secinfo_gss(xdr, sec_flavor);
4918 if (status)
4919 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004920 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004921 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004922 }
4923
Bryan Schumaker613e9012011-04-27 15:28:44 -04004924out:
4925 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004926out_overflow:
4927 print_overflow_msg(__func__, xdr);
4928 return -EIO;
4929}
4930
Benny Halevy99fe60d2009-04-01 09:22:29 -04004931#if defined(CONFIG_NFS_V4_1)
4932static int decode_exchange_id(struct xdr_stream *xdr,
4933 struct nfs41_exchange_id_res *res)
4934{
4935 __be32 *p;
4936 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004937 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004938 int status;
4939 struct nfs_client *clp = res->client;
4940
4941 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4942 if (status)
4943 return status;
4944
Benny Halevyc0eae662009-08-14 17:20:14 +03004945 p = xdr_inline_decode(xdr, 8);
4946 if (unlikely(!p))
4947 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05004948 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004949 p = xdr_inline_decode(xdr, 12);
4950 if (unlikely(!p))
4951 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004952 clp->cl_seqid = be32_to_cpup(p++);
4953 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004954
4955 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004956 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004957 if (dummy != SP4_NONE)
4958 return -EIO;
4959
4960 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004961 p = xdr_inline_decode(xdr, 8);
4962 if (unlikely(!p))
4963 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004964
4965 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004966 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4967 if (unlikely(status))
4968 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004969
4970 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004971 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4972 if (unlikely(status))
4973 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004974
4975 /* Throw away Implementation id array */
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 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004981out_overflow:
4982 print_overflow_msg(__func__, xdr);
4983 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004984}
Andy Adamsonfc931582009-04-01 09:22:31 -04004985
4986static int decode_chan_attrs(struct xdr_stream *xdr,
4987 struct nfs4_channel_attrs *attrs)
4988{
4989 __be32 *p;
4990 u32 nr_attrs;
4991
Benny Halevyc0eae662009-08-14 17:20:14 +03004992 p = xdr_inline_decode(xdr, 28);
4993 if (unlikely(!p))
4994 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004995 attrs->headerpadsz = be32_to_cpup(p++);
4996 attrs->max_rqst_sz = be32_to_cpup(p++);
4997 attrs->max_resp_sz = be32_to_cpup(p++);
4998 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4999 attrs->max_ops = be32_to_cpup(p++);
5000 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005001 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005002 if (unlikely(nr_attrs > 1)) {
5003 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
5004 __func__, nr_attrs);
5005 return -EINVAL;
5006 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005007 if (nr_attrs == 1) {
5008 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5009 if (unlikely(!p))
5010 goto out_overflow;
5011 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005012 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005013out_overflow:
5014 print_overflow_msg(__func__, xdr);
5015 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005016}
5017
Benny Halevye78291e2009-08-14 17:20:00 +03005018static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5019{
5020 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005021}
5022
5023static int decode_create_session(struct xdr_stream *xdr,
5024 struct nfs41_create_session_res *res)
5025{
5026 __be32 *p;
5027 int status;
5028 struct nfs_client *clp = res->client;
5029 struct nfs4_session *session = clp->cl_session;
5030
5031 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005032 if (!status)
5033 status = decode_sessionid(xdr, &session->sess_id);
5034 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005035 return status;
5036
Andy Adamsonfc931582009-04-01 09:22:31 -04005037 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005038 p = xdr_inline_decode(xdr, 8);
5039 if (unlikely(!p))
5040 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005041 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005042 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005043
5044 /* Channel attributes */
5045 status = decode_chan_attrs(xdr, &session->fc_attrs);
5046 if (!status)
5047 status = decode_chan_attrs(xdr, &session->bc_attrs);
5048 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005049out_overflow:
5050 print_overflow_msg(__func__, xdr);
5051 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005052}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005053
5054static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5055{
5056 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5057}
Ricardo Labiaga18019752009-12-05 16:08:40 -05005058
5059static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5060{
5061 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5062}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005063#endif /* CONFIG_NFS_V4_1 */
5064
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005065static int decode_sequence(struct xdr_stream *xdr,
5066 struct nfs4_sequence_res *res,
5067 struct rpc_rqst *rqstp)
5068{
5069#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005070 struct nfs4_sessionid id;
5071 u32 dummy;
5072 int status;
5073 __be32 *p;
5074
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005075 if (!res->sr_session)
5076 return 0;
5077
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005078 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005079 if (!status)
5080 status = decode_sessionid(xdr, &id);
5081 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005082 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005083
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005084 /*
5085 * If the server returns different values for sessionID, slotID or
5086 * sequence number, the server is looney tunes.
5087 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005088 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005089
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005090 if (memcmp(id.data, res->sr_session->sess_id.data,
5091 NFS4_MAX_SESSIONID_LEN)) {
5092 dprintk("%s Invalid session id\n", __func__);
5093 goto out_err;
5094 }
Benny Halevye78291e2009-08-14 17:20:00 +03005095
Benny Halevyc0eae662009-08-14 17:20:14 +03005096 p = xdr_inline_decode(xdr, 20);
5097 if (unlikely(!p))
5098 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005099
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005100 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005101 dummy = be32_to_cpup(p++);
Benny Halevydfb4f302010-09-24 09:17:01 -04005102 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005103 dprintk("%s Invalid sequence number\n", __func__);
5104 goto out_err;
5105 }
5106 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005107 dummy = be32_to_cpup(p++);
Benny Halevydfb4f302010-09-24 09:17:01 -04005108 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005109 dprintk("%s Invalid slot id\n", __func__);
5110 goto out_err;
5111 }
5112 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005113 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005114 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005115 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005116 /* result flags */
5117 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005118 status = 0;
5119out_err:
5120 res->sr_status = status;
5121 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005122out_overflow:
5123 print_overflow_msg(__func__, xdr);
5124 status = -EIO;
5125 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005126#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005127 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005128#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005129}
5130
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005131#if defined(CONFIG_NFS_V4_1)
5132
5133static int decode_getdeviceinfo(struct xdr_stream *xdr,
5134 struct pnfs_device *pdev)
5135{
5136 __be32 *p;
5137 uint32_t len, type;
5138 int status;
5139
5140 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5141 if (status) {
5142 if (status == -ETOOSMALL) {
5143 p = xdr_inline_decode(xdr, 4);
5144 if (unlikely(!p))
5145 goto out_overflow;
5146 pdev->mincount = be32_to_cpup(p);
5147 dprintk("%s: Min count too small. mincnt = %u\n",
5148 __func__, pdev->mincount);
5149 }
5150 return status;
5151 }
5152
5153 p = xdr_inline_decode(xdr, 8);
5154 if (unlikely(!p))
5155 goto out_overflow;
5156 type = be32_to_cpup(p++);
5157 if (type != pdev->layout_type) {
5158 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5159 __func__, pdev->layout_type, type);
5160 return -EINVAL;
5161 }
5162 /*
5163 * Get the length of the opaque device_addr4. xdr_read_pages places
5164 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5165 * and places the remaining xdr data in xdr_buf->tail
5166 */
5167 pdev->mincount = be32_to_cpup(p);
5168 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5169
5170 /* Parse notification bitmap, verifying that it is zero. */
5171 p = xdr_inline_decode(xdr, 4);
5172 if (unlikely(!p))
5173 goto out_overflow;
5174 len = be32_to_cpup(p);
5175 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005176 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005177
5178 p = xdr_inline_decode(xdr, 4 * len);
5179 if (unlikely(!p))
5180 goto out_overflow;
5181 for (i = 0; i < len; i++, p++) {
5182 if (be32_to_cpup(p)) {
5183 dprintk("%s: notifications not supported\n",
5184 __func__);
5185 return -EIO;
5186 }
5187 }
5188 }
5189 return 0;
5190out_overflow:
5191 print_overflow_msg(__func__, xdr);
5192 return -EIO;
5193}
5194
5195static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5196 struct nfs4_layoutget_res *res)
5197{
5198 __be32 *p;
5199 int status;
5200 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005201 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5202 struct kvec *iov = rcvbuf->head;
5203 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005204
5205 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5206 if (status)
5207 return status;
5208 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5209 if (unlikely(!p))
5210 goto out_overflow;
5211 res->return_on_close = be32_to_cpup(p++);
5212 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5213 layout_count = be32_to_cpup(p);
5214 if (!layout_count) {
5215 dprintk("%s: server responded with empty layout array\n",
5216 __func__);
5217 return -EINVAL;
5218 }
5219
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005220 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005221 if (unlikely(!p))
5222 goto out_overflow;
5223 p = xdr_decode_hyper(p, &res->range.offset);
5224 p = xdr_decode_hyper(p, &res->range.length);
5225 res->range.iomode = be32_to_cpup(p++);
5226 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005227 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005228
5229 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5230 __func__,
5231 (unsigned long)res->range.offset,
5232 (unsigned long)res->range.length,
5233 res->range.iomode,
5234 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005235 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005236
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005237 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5238 recvd = req->rq_rcv_buf.len - hdrlen;
5239 if (res->layoutp->len > recvd) {
5240 dprintk("NFS: server cheating in layoutget reply: "
5241 "layout len %u > recvd %u\n",
5242 res->layoutp->len, recvd);
5243 return -EINVAL;
5244 }
5245
5246 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005247
5248 if (layout_count > 1) {
5249 /* We only handle a length one array at the moment. Any
5250 * further entries are just ignored. Note that this means
5251 * the client may see a response that is less than the
5252 * minimum it requested.
5253 */
5254 dprintk("%s: server responded with %d layouts, dropping tail\n",
5255 __func__, layout_count);
5256 }
5257
5258 return 0;
5259out_overflow:
5260 print_overflow_msg(__func__, xdr);
5261 return -EIO;
5262}
Andy Adamson863a3c62011-03-23 13:27:54 +00005263
Benny Halevycbe82602011-05-22 19:52:37 +03005264static int decode_layoutreturn(struct xdr_stream *xdr,
5265 struct nfs4_layoutreturn_res *res)
5266{
5267 __be32 *p;
5268 int status;
5269
5270 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5271 if (status)
5272 return status;
5273 p = xdr_inline_decode(xdr, 4);
5274 if (unlikely(!p))
5275 goto out_overflow;
5276 res->lrs_present = be32_to_cpup(p);
5277 if (res->lrs_present)
5278 status = decode_stateid(xdr, &res->stateid);
5279 return status;
5280out_overflow:
5281 print_overflow_msg(__func__, xdr);
5282 return -EIO;
5283}
5284
Andy Adamson863a3c62011-03-23 13:27:54 +00005285static int decode_layoutcommit(struct xdr_stream *xdr,
5286 struct rpc_rqst *req,
5287 struct nfs4_layoutcommit_res *res)
5288{
5289 __be32 *p;
5290 __u32 sizechanged;
5291 int status;
5292
5293 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5294 if (status)
5295 return status;
5296
5297 p = xdr_inline_decode(xdr, 4);
5298 if (unlikely(!p))
5299 goto out_overflow;
5300 sizechanged = be32_to_cpup(p);
5301
5302 if (sizechanged) {
5303 /* throw away new size */
5304 p = xdr_inline_decode(xdr, 8);
5305 if (unlikely(!p))
5306 goto out_overflow;
5307 }
5308 return 0;
5309out_overflow:
5310 print_overflow_msg(__func__, xdr);
5311 return -EIO;
5312}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005313#endif /* CONFIG_NFS_V4_1 */
5314
Linus Torvalds1da177e2005-04-16 15:20:36 -07005315/*
Benny Halevy49c25592008-12-23 16:06:16 -05005316 * END OF "GENERIC" DECODE ROUTINES.
5317 */
5318
5319/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005320 * Decode OPEN_DOWNGRADE response
5321 */
Chuck Leverbf269552010-12-14 14:59:29 +00005322static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5323 struct xdr_stream *xdr,
5324 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325{
Andy Adamson05d564f2008-12-23 16:06:15 -05005326 struct compound_hdr hdr;
5327 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005328
Chuck Leverbf269552010-12-14 14:59:29 +00005329 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005330 if (status)
5331 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005332 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005333 if (status)
5334 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005335 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005336 if (status)
5337 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005338 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005339 if (status != 0)
5340 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005341 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005342 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005343out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005344 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005345}
5346
5347/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005348 * Decode ACCESS response
5349 */
Chuck Leverbf269552010-12-14 14:59:29 +00005350static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5351 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005352{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005353 struct compound_hdr hdr;
5354 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005355
Chuck Leverbf269552010-12-14 14:59:29 +00005356 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005357 if (status)
5358 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005359 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005360 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005361 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005362 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005363 if (status != 0)
5364 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005365 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005366 if (status != 0)
5367 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005368 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005369 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005370out:
5371 return status;
5372}
5373
5374/*
5375 * Decode LOOKUP response
5376 */
Chuck Leverbf269552010-12-14 14:59:29 +00005377static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5378 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005379{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005380 struct compound_hdr hdr;
5381 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005382
Chuck Leverbf269552010-12-14 14:59:29 +00005383 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005384 if (status)
5385 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005386 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005387 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005388 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005389 status = decode_putfh(xdr);
5390 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005391 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005392 status = decode_lookup(xdr);
5393 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005395 status = decode_getfh(xdr, res->fh);
5396 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005397 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005398 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005399 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005400out:
5401 return status;
5402}
5403
5404/*
5405 * Decode LOOKUP_ROOT response
5406 */
Chuck Leverbf269552010-12-14 14:59:29 +00005407static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5408 struct xdr_stream *xdr,
5409 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005410{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005411 struct compound_hdr hdr;
5412 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005413
Chuck Leverbf269552010-12-14 14:59:29 +00005414 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005415 if (status)
5416 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005417 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005418 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005419 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005420 status = decode_putrootfh(xdr);
5421 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005422 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005423 status = decode_getfh(xdr, res->fh);
5424 if (status == 0)
5425 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005426 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005427out:
5428 return status;
5429}
5430
5431/*
5432 * Decode REMOVE response
5433 */
Chuck Leverbf269552010-12-14 14:59:29 +00005434static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5435 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005436{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005437 struct compound_hdr hdr;
5438 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005439
Chuck Leverbf269552010-12-14 14:59:29 +00005440 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005441 if (status)
5442 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005443 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005444 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005445 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005446 status = decode_putfh(xdr);
5447 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005448 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005449 status = decode_remove(xdr, &res->cinfo);
5450 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005451 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005452 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005453 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005454out:
5455 return status;
5456}
5457
5458/*
5459 * Decode RENAME response
5460 */
Chuck Leverbf269552010-12-14 14:59:29 +00005461static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5462 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005463{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005464 struct compound_hdr hdr;
5465 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005466
Chuck Leverbf269552010-12-14 14:59:29 +00005467 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005468 if (status)
5469 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005470 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005471 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005472 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005473 status = decode_putfh(xdr);
5474 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005475 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005476 status = decode_savefh(xdr);
5477 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005478 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005479 status = decode_putfh(xdr);
5480 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005481 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005482 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5483 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005484 goto out;
5485 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005486 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005487 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005488 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005489 status = decode_restorefh(xdr);
5490 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005491 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005492 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005493 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005494out:
5495 return status;
5496}
5497
5498/*
5499 * Decode LINK response
5500 */
Chuck Leverbf269552010-12-14 14:59:29 +00005501static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5502 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005503{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005504 struct compound_hdr hdr;
5505 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005506
Chuck Leverbf269552010-12-14 14:59:29 +00005507 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005508 if (status)
5509 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005510 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005511 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005512 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005513 status = decode_putfh(xdr);
5514 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005515 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005516 status = decode_savefh(xdr);
5517 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005518 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005519 status = decode_putfh(xdr);
5520 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005521 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005522 status = decode_link(xdr, &res->cinfo);
5523 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005524 goto out;
5525 /*
5526 * Note order: OP_LINK leaves the directory as the current
5527 * filehandle.
5528 */
Chuck Leverbf269552010-12-14 14:59:29 +00005529 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005530 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005531 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005532 status = decode_restorefh(xdr);
5533 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005534 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005535 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005536 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005537out:
5538 return status;
5539}
5540
5541/*
5542 * Decode CREATE response
5543 */
Chuck Leverbf269552010-12-14 14:59:29 +00005544static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5545 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005546{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005547 struct compound_hdr hdr;
5548 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005549
Chuck Leverbf269552010-12-14 14:59:29 +00005550 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005551 if (status)
5552 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005553 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005554 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005555 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005556 status = decode_putfh(xdr);
5557 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005558 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005559 status = decode_savefh(xdr);
5560 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005561 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005562 status = decode_create(xdr, &res->dir_cinfo);
5563 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005564 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005565 status = decode_getfh(xdr, res->fh);
5566 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005567 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005568 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005569 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005570 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005571 status = decode_restorefh(xdr);
5572 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005573 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005574 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005575 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005576out:
5577 return status;
5578}
5579
5580/*
5581 * Decode SYMLINK response
5582 */
Chuck Leverbf269552010-12-14 14:59:29 +00005583static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5584 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005585{
Chuck Leverbf269552010-12-14 14:59:29 +00005586 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005587}
5588
5589/*
5590 * Decode GETATTR response
5591 */
Chuck Leverbf269552010-12-14 14:59:29 +00005592static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5593 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005594{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005595 struct compound_hdr hdr;
5596 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005597
Chuck Leverbf269552010-12-14 14:59:29 +00005598 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005599 if (status)
5600 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005601 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005602 if (status)
5603 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005604 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005605 if (status)
5606 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005607 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005608 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005609out:
5610 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005611}
5612
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005613/*
5614 * Encode an SETACL request
5615 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005616static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5617 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005618{
Andy Adamson05d564f2008-12-23 16:06:15 -05005619 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005620 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005621 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005622
Chuck Lever9f06c712010-12-14 14:59:18 +00005623 encode_compound_hdr(xdr, req, &hdr);
5624 encode_sequence(xdr, &args->seq_args, &hdr);
5625 encode_putfh(xdr, args->fh, &hdr);
5626 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005627 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005628}
Andy Adamson05d564f2008-12-23 16:06:15 -05005629
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005630/*
5631 * Decode SETACL response
5632 */
5633static int
Chuck Leverbf269552010-12-14 14:59:29 +00005634nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005635 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005636{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005637 struct compound_hdr hdr;
5638 int status;
5639
Chuck Leverbf269552010-12-14 14:59:29 +00005640 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005641 if (status)
5642 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005643 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005644 if (status)
5645 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005646 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005647 if (status)
5648 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005649 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005650out:
5651 return status;
5652}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005653
5654/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005655 * Decode GETACL response
5656 */
5657static int
Chuck Leverbf269552010-12-14 14:59:29 +00005658nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005659 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005660{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005661 struct compound_hdr hdr;
5662 int status;
5663
Chuck Leverbf269552010-12-14 14:59:29 +00005664 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005665 if (status)
5666 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005667 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005668 if (status)
5669 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005670 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005671 if (status)
5672 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005673 status = decode_getacl(xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005674
5675out:
5676 return status;
5677}
5678
5679/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005680 * Decode CLOSE response
5681 */
Chuck Leverbf269552010-12-14 14:59:29 +00005682static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5683 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005684{
Andy Adamson05d564f2008-12-23 16:06:15 -05005685 struct compound_hdr hdr;
5686 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005687
Chuck Leverbf269552010-12-14 14:59:29 +00005688 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005689 if (status)
5690 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005691 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005692 if (status)
5693 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005694 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005695 if (status)
5696 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005697 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005698 if (status != 0)
5699 goto out;
5700 /*
5701 * Note: Server may do delete on close for this file
5702 * in which case the getattr call will fail with
5703 * an ESTALE error. Shouldn't be a problem,
5704 * though, since fattr->valid will remain unset.
5705 */
Chuck Leverbf269552010-12-14 14:59:29 +00005706 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005707 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005708out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005709 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005710}
5711
5712/*
5713 * Decode OPEN response
5714 */
Chuck Leverbf269552010-12-14 14:59:29 +00005715static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5716 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005717{
Andy Adamson05d564f2008-12-23 16:06:15 -05005718 struct compound_hdr hdr;
5719 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005720
Chuck Leverbf269552010-12-14 14:59:29 +00005721 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005722 if (status)
5723 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005724 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005725 if (status)
5726 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005727 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005728 if (status)
5729 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005730 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005731 if (status)
5732 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005733 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005734 if (status)
5735 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005736 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005737 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005738 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005739 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005740 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005741 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005742 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005743 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005744 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005746 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005747}
5748
5749/*
5750 * Decode OPEN_CONFIRM response
5751 */
Chuck Leverbf269552010-12-14 14:59:29 +00005752static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5753 struct xdr_stream *xdr,
5754 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755{
Andy Adamson05d564f2008-12-23 16:06:15 -05005756 struct compound_hdr hdr;
5757 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758
Chuck Leverbf269552010-12-14 14:59:29 +00005759 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005760 if (status)
5761 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005762 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005763 if (status)
5764 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005765 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005766out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005767 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005768}
5769
5770/*
5771 * Decode OPEN response
5772 */
Chuck Leverbf269552010-12-14 14:59:29 +00005773static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5774 struct xdr_stream *xdr,
5775 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005776{
Andy Adamson05d564f2008-12-23 16:06:15 -05005777 struct compound_hdr hdr;
5778 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005779
Chuck Leverbf269552010-12-14 14:59:29 +00005780 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005781 if (status)
5782 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005783 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005784 if (status)
5785 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005786 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005787 if (status)
5788 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005789 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005790 if (status)
5791 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005792 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005793 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005794out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005795 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005796}
5797
5798/*
5799 * Decode SETATTR response
5800 */
Chuck Leverbf269552010-12-14 14:59:29 +00005801static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5802 struct xdr_stream *xdr,
5803 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005804{
Andy Adamson05d564f2008-12-23 16:06:15 -05005805 struct compound_hdr hdr;
5806 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005807
Chuck Leverbf269552010-12-14 14:59:29 +00005808 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005809 if (status)
5810 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005811 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005812 if (status)
5813 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005814 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005815 if (status)
5816 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005817 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005818 if (status)
5819 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005820 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005821 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005822out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005823 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005824}
5825
5826/*
5827 * Decode LOCK response
5828 */
Chuck Leverbf269552010-12-14 14:59:29 +00005829static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5830 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005831{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005832 struct compound_hdr hdr;
5833 int status;
5834
Chuck Leverbf269552010-12-14 14:59:29 +00005835 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836 if (status)
5837 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005838 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005839 if (status)
5840 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005841 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005842 if (status)
5843 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005844 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845out:
5846 return status;
5847}
5848
5849/*
5850 * Decode LOCKT response
5851 */
Chuck Leverbf269552010-12-14 14:59:29 +00005852static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5853 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005855 struct compound_hdr hdr;
5856 int status;
5857
Chuck Leverbf269552010-12-14 14:59:29 +00005858 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005859 if (status)
5860 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005861 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005862 if (status)
5863 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005864 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005865 if (status)
5866 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005867 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868out:
5869 return status;
5870}
5871
5872/*
5873 * Decode LOCKU response
5874 */
Chuck Leverbf269552010-12-14 14:59:29 +00005875static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5876 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005878 struct compound_hdr hdr;
5879 int status;
5880
Chuck Leverbf269552010-12-14 14:59:29 +00005881 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005882 if (status)
5883 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005884 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005885 if (status)
5886 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005887 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005888 if (status)
5889 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005890 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005891out:
5892 return status;
5893}
5894
Chuck Leverbf269552010-12-14 14:59:29 +00005895static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5896 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005897{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005898 struct compound_hdr hdr;
5899 int status;
5900
Chuck Leverbf269552010-12-14 14:59:29 +00005901 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005902 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005903 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005904 return status;
5905}
5906
Linus Torvalds1da177e2005-04-16 15:20:36 -07005907/*
5908 * Decode READLINK response
5909 */
Chuck Leverbf269552010-12-14 14:59:29 +00005910static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5911 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04005912 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005913{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005914 struct compound_hdr hdr;
5915 int status;
5916
Chuck Leverbf269552010-12-14 14:59:29 +00005917 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005918 if (status)
5919 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005920 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005921 if (status)
5922 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005923 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005924 if (status)
5925 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005926 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005927out:
5928 return status;
5929}
5930
5931/*
5932 * Decode READDIR response
5933 */
Chuck Leverbf269552010-12-14 14:59:29 +00005934static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5935 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005936{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005937 struct compound_hdr hdr;
5938 int status;
5939
Chuck Leverbf269552010-12-14 14:59:29 +00005940 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005941 if (status)
5942 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005943 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005944 if (status)
5945 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005946 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005947 if (status)
5948 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005949 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005950out:
5951 return status;
5952}
5953
5954/*
5955 * Decode Read response
5956 */
Chuck Leverbf269552010-12-14 14:59:29 +00005957static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5958 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005959{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005960 struct compound_hdr hdr;
5961 int status;
5962
Chuck Leverbf269552010-12-14 14:59:29 +00005963 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005964 if (status)
5965 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005966 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005967 if (status)
5968 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005969 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970 if (status)
5971 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005972 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005973 if (!status)
5974 status = res->count;
5975out:
5976 return status;
5977}
5978
5979/*
5980 * Decode WRITE response
5981 */
Chuck Leverbf269552010-12-14 14:59:29 +00005982static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5983 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005985 struct compound_hdr hdr;
5986 int status;
5987
Chuck Leverbf269552010-12-14 14:59:29 +00005988 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005989 if (status)
5990 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005991 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005992 if (status)
5993 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005994 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005995 if (status)
5996 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005997 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005998 if (status)
5999 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006000 if (res->fattr)
6001 decode_getfattr(xdr, res->fattr, res->server,
6002 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006003 if (!status)
6004 status = res->count;
6005out:
6006 return status;
6007}
6008
6009/*
6010 * Decode COMMIT response
6011 */
Chuck Leverbf269552010-12-14 14:59:29 +00006012static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6013 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006015 struct compound_hdr hdr;
6016 int status;
6017
Chuck Leverbf269552010-12-14 14:59:29 +00006018 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006019 if (status)
6020 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006021 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006022 if (status)
6023 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006024 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006025 if (status)
6026 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006027 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006028 if (status)
6029 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006030 if (res->fattr)
6031 decode_getfattr(xdr, res->fattr, res->server,
6032 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006033out:
6034 return status;
6035}
6036
6037/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006038 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006039 */
Chuck Leverbf269552010-12-14 14:59:29 +00006040static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006041 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006042{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006043 struct compound_hdr hdr;
6044 int status;
6045
Chuck Leverbf269552010-12-14 14:59:29 +00006046 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006047 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006048 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006049 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006050 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006051 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006052 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006053 return status;
6054}
6055
6056/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006057 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006058 */
Chuck Leverbf269552010-12-14 14:59:29 +00006059static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006060 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006062 struct compound_hdr hdr;
6063 int status;
6064
Chuck Leverbf269552010-12-14 14:59:29 +00006065 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006066 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006067 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006068 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006069 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006070 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006071 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006072 return status;
6073}
6074
6075/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006076 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077 */
Chuck Leverbf269552010-12-14 14:59:29 +00006078static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006079 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006080{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081 struct compound_hdr hdr;
6082 int status;
6083
Chuck Leverbf269552010-12-14 14:59:29 +00006084 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006085 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006086 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006087 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006088 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006090 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006091 return status;
6092}
6093
6094/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006095 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096 */
Chuck Leverbf269552010-12-14 14:59:29 +00006097static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6098 struct xdr_stream *xdr,
6099 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006100{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101 struct compound_hdr hdr;
6102 int status;
6103
Chuck Leverbf269552010-12-14 14:59:29 +00006104 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006105 if (status)
6106 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006107 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006108 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006110 status = decode_putfh(xdr);
6111 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006112 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006113 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114out:
6115 return status;
6116}
6117
6118/*
6119 * Decode RENEW response
6120 */
Chuck Leverbf269552010-12-14 14:59:29 +00006121static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6122 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006123{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006124 struct compound_hdr hdr;
6125 int status;
6126
Chuck Leverbf269552010-12-14 14:59:29 +00006127 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006128 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006129 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006130 return status;
6131}
6132
6133/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006134 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006135 */
Chuck Leverbf269552010-12-14 14:59:29 +00006136static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6137 struct xdr_stream *xdr,
6138 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006139{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006140 struct compound_hdr hdr;
6141 int status;
6142
Chuck Leverbf269552010-12-14 14:59:29 +00006143 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006144 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006145 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146 return status;
6147}
6148
6149/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006150 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006151 */
Chuck Leverbf269552010-12-14 14:59:29 +00006152static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6153 struct xdr_stream *xdr,
6154 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006156 struct compound_hdr hdr;
6157 int status;
6158
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006161 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006162 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006163 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006165 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006166 return status;
6167}
6168
6169/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006170 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006171 */
Chuck Leverbf269552010-12-14 14:59:29 +00006172static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6173 struct xdr_stream *xdr,
6174 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006175{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006176 struct compound_hdr hdr;
6177 int status;
6178
Chuck Leverbf269552010-12-14 14:59:29 +00006179 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006180 if (status)
6181 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006182 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006183 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006184 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006185 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006186 if (status != 0)
6187 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006188 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006189 if (status != 0)
6190 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006191 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006192 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01006193out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194 return status;
6195}
6196
Trond Myklebust683b57b2006-06-09 09:34:22 -04006197/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006198 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006199 */
Chuck Leverbf269552010-12-14 14:59:29 +00006200static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6201 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006202 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006203{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006204 struct compound_hdr hdr;
6205 int status;
6206
Chuck Leverbf269552010-12-14 14:59:29 +00006207 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006208 if (status)
6209 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006210 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006211 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006212 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006213 status = decode_putfh(xdr);
6214 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006215 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006216 status = decode_lookup(xdr);
6217 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006218 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006219 xdr_enter_page(xdr, PAGE_SIZE);
6220 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006221 res->fs_locations->server,
6222 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04006223out:
6224 return status;
6225}
6226
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006227/*
6228 * Decode SECINFO response
6229 */
6230static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6231 struct xdr_stream *xdr,
6232 struct nfs4_secinfo_res *res)
6233{
6234 struct compound_hdr hdr;
6235 int status;
6236
6237 status = decode_compound_hdr(xdr, &hdr);
6238 if (status)
6239 goto out;
6240 status = decode_sequence(xdr, &res->seq_res, rqstp);
6241 if (status)
6242 goto out;
6243 status = decode_putfh(xdr);
6244 if (status)
6245 goto out;
6246 status = decode_secinfo(xdr, res);
6247 if (status)
6248 goto out;
6249out:
6250 return status;
6251}
6252
Benny Halevy99fe60d2009-04-01 09:22:29 -04006253#if defined(CONFIG_NFS_V4_1)
6254/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006255 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006256 */
Chuck Leverbf269552010-12-14 14:59:29 +00006257static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6258 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006259 void *res)
6260{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006261 struct compound_hdr hdr;
6262 int status;
6263
Chuck Leverbf269552010-12-14 14:59:29 +00006264 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006265 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006266 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006267 return status;
6268}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006269
6270/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006271 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006272 */
Chuck Leverbf269552010-12-14 14:59:29 +00006273static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6274 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006275 struct nfs41_create_session_res *res)
6276{
Andy Adamsonfc931582009-04-01 09:22:31 -04006277 struct compound_hdr hdr;
6278 int status;
6279
Chuck Leverbf269552010-12-14 14:59:29 +00006280 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006281 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006282 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006283 return status;
6284}
6285
6286/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006287 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006288 */
Chuck Leverbf269552010-12-14 14:59:29 +00006289static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6290 struct xdr_stream *xdr,
6291 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006292{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006293 struct compound_hdr hdr;
6294 int status;
6295
Chuck Leverbf269552010-12-14 14:59:29 +00006296 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006297 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006298 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006299 return status;
6300}
6301
6302/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006303 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006304 */
Chuck Leverbf269552010-12-14 14:59:29 +00006305static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6306 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006307 struct nfs4_sequence_res *res)
6308{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006309 struct compound_hdr hdr;
6310 int status;
6311
Chuck Leverbf269552010-12-14 14:59:29 +00006312 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006313 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006314 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006315 return status;
6316}
6317
6318/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006319 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006320 */
Chuck Leverbf269552010-12-14 14:59:29 +00006321static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6322 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006323 struct nfs4_get_lease_time_res *res)
6324{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006325 struct compound_hdr hdr;
6326 int status;
6327
Chuck Leverbf269552010-12-14 14:59:29 +00006328 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006329 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006330 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006331 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006332 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006333 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006334 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006335 return status;
6336}
Ricardo Labiaga18019752009-12-05 16:08:40 -05006337
6338/*
6339 * Decode RECLAIM_COMPLETE response
6340 */
Chuck Leverbf269552010-12-14 14:59:29 +00006341static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6342 struct xdr_stream *xdr,
Ricardo Labiaga18019752009-12-05 16:08:40 -05006343 struct nfs41_reclaim_complete_res *res)
6344{
Ricardo Labiaga18019752009-12-05 16:08:40 -05006345 struct compound_hdr hdr;
6346 int status;
6347
Chuck Leverbf269552010-12-14 14:59:29 +00006348 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006349 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006350 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006351 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006352 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006353 return status;
6354}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006355
6356/*
6357 * Decode GETDEVINFO response
6358 */
Chuck Leverbf269552010-12-14 14:59:29 +00006359static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6360 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006361 struct nfs4_getdeviceinfo_res *res)
6362{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006363 struct compound_hdr hdr;
6364 int status;
6365
Chuck Leverbf269552010-12-14 14:59:29 +00006366 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006367 if (status != 0)
6368 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006369 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006370 if (status != 0)
6371 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006372 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006373out:
6374 return status;
6375}
6376
6377/*
6378 * Decode LAYOUTGET response
6379 */
Chuck Leverbf269552010-12-14 14:59:29 +00006380static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6381 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006382 struct nfs4_layoutget_res *res)
6383{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006384 struct compound_hdr hdr;
6385 int status;
6386
Chuck Leverbf269552010-12-14 14:59:29 +00006387 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006388 if (status)
6389 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006390 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006391 if (status)
6392 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006393 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006394 if (status)
6395 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006396 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006397out:
6398 return status;
6399}
Andy Adamson863a3c62011-03-23 13:27:54 +00006400
6401/*
Benny Halevycbe82602011-05-22 19:52:37 +03006402 * Decode LAYOUTRETURN response
6403 */
6404static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6405 struct xdr_stream *xdr,
6406 struct nfs4_layoutreturn_res *res)
6407{
6408 struct compound_hdr hdr;
6409 int status;
6410
6411 status = decode_compound_hdr(xdr, &hdr);
6412 if (status)
6413 goto out;
6414 status = decode_sequence(xdr, &res->seq_res, rqstp);
6415 if (status)
6416 goto out;
6417 status = decode_putfh(xdr);
6418 if (status)
6419 goto out;
6420 status = decode_layoutreturn(xdr, res);
6421out:
6422 return status;
6423}
6424
6425/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006426 * Decode LAYOUTCOMMIT response
6427 */
6428static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6429 struct xdr_stream *xdr,
6430 struct nfs4_layoutcommit_res *res)
6431{
6432 struct compound_hdr hdr;
6433 int status;
6434
6435 status = decode_compound_hdr(xdr, &hdr);
6436 if (status)
6437 goto out;
6438 status = decode_sequence(xdr, &res->seq_res, rqstp);
6439 if (status)
6440 goto out;
6441 status = decode_putfh(xdr);
6442 if (status)
6443 goto out;
6444 status = decode_layoutcommit(xdr, rqstp, res);
6445 if (status)
6446 goto out;
6447 decode_getfattr(xdr, res->fattr, res->server,
6448 !RPC_IS_ASYNC(rqstp->rq_task));
6449out:
6450 return status;
6451}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006452#endif /* CONFIG_NFS_V4_1 */
6453
Chuck Lever573c4e12010-12-14 14:58:11 +00006454/**
6455 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6456 * the local page cache.
6457 * @xdr: XDR stream where entry resides
6458 * @entry: buffer to fill in with entry data
6459 * @plus: boolean indicating whether this should be a readdirplus entry
6460 *
6461 * Returns zero if successful, otherwise a negative errno value is
6462 * returned.
6463 *
6464 * This function is not invoked during READDIR reply decoding, but
6465 * rather whenever an application invokes the getdents(2) system call
6466 * on a directory already in our cache.
6467 */
6468int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6469 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006470{
6471 uint32_t bitmap[2] = {0};
6472 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006473 __be32 *p = xdr_inline_decode(xdr, 4);
6474 if (unlikely(!p))
6475 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006476 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006477 p = xdr_inline_decode(xdr, 4);
6478 if (unlikely(!p))
6479 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006480 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006481 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006483 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484 }
6485
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006486 p = xdr_inline_decode(xdr, 12);
6487 if (unlikely(!p))
6488 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006489 entry->prev_cookie = entry->cookie;
6490 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006491 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006492
Trond Myklebust9af8c222010-10-24 11:52:55 -04006493 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006494 if (unlikely(!p))
6495 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006496 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497
6498 /*
6499 * In case the server doesn't return an inode number,
6500 * we fake one here. (We don't use inode number 0,
6501 * since glibc seems to choke on it...)
6502 */
6503 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006504 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006505
Trond Myklebust9af8c222010-10-24 11:52:55 -04006506 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006507 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006508
6509 if (decode_attr_length(xdr, &len, &p) < 0)
6510 goto out_overflow;
6511
Chuck Lever573c4e12010-12-14 14:58:11 +00006512 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6513 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006514 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006515 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6516 entry->ino = entry->fattr->mounted_on_fileid;
6517 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006518 entry->ino = entry->fattr->fileid;
6519
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006520 entry->d_type = DT_UNKNOWN;
6521 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6522 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6523
Chuck Lever573c4e12010-12-14 14:58:11 +00006524 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006525
6526out_overflow:
6527 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006528 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529}
6530
6531/*
6532 * We need to translate between nfs status return values and
6533 * the local errno values which may not be the same.
6534 */
6535static struct {
6536 int stat;
6537 int errno;
6538} nfs_errtbl[] = {
6539 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006540 { NFS4ERR_PERM, -EPERM },
6541 { NFS4ERR_NOENT, -ENOENT },
6542 { NFS4ERR_IO, -errno_NFSERR_IO},
6543 { NFS4ERR_NXIO, -ENXIO },
6544 { NFS4ERR_ACCESS, -EACCES },
6545 { NFS4ERR_EXIST, -EEXIST },
6546 { NFS4ERR_XDEV, -EXDEV },
6547 { NFS4ERR_NOTDIR, -ENOTDIR },
6548 { NFS4ERR_ISDIR, -EISDIR },
6549 { NFS4ERR_INVAL, -EINVAL },
6550 { NFS4ERR_FBIG, -EFBIG },
6551 { NFS4ERR_NOSPC, -ENOSPC },
6552 { NFS4ERR_ROFS, -EROFS },
6553 { NFS4ERR_MLINK, -EMLINK },
6554 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6555 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6556 { NFS4ERR_DQUOT, -EDQUOT },
6557 { NFS4ERR_STALE, -ESTALE },
6558 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006559 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6560 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6561 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006562 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006563 { NFS4ERR_BADTYPE, -EBADTYPE },
6564 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006565 { NFS4ERR_SYMLINK, -ELOOP },
6566 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6567 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006568 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006569};
6570
6571/*
6572 * Convert an NFS error code to a local one.
6573 * This one is used jointly by NFSv2 and NFSv3.
6574 */
6575static int
David Howells0a8ea432006-08-22 20:06:08 -04006576nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006577{
6578 int i;
6579 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6580 if (nfs_errtbl[i].stat == stat)
6581 return nfs_errtbl[i].errno;
6582 }
6583 if (stat <= 10000 || stat > 10100) {
6584 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006585 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006586 }
6587 /* If we cannot translate the error, the recovery routines should
6588 * handle it.
6589 * Note: remaining NFSv4 error codes have values > 10000, so should
6590 * not conflict with native Linux error codes.
6591 */
Benny Halevy856dff32008-03-31 17:39:06 +03006592 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593}
6594
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595#define PROC(proc, argtype, restype) \
6596[NFSPROC4_CLNT_##proc] = { \
6597 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006598 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006599 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006600 .p_arglen = NFS4_##argtype##_sz, \
6601 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006602 .p_statidx = NFSPROC4_CLNT_##proc, \
6603 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006604}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006605
6606struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006607 PROC(READ, enc_read, dec_read),
6608 PROC(WRITE, enc_write, dec_write),
6609 PROC(COMMIT, enc_commit, dec_commit),
6610 PROC(OPEN, enc_open, dec_open),
6611 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6612 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6613 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6614 PROC(CLOSE, enc_close, dec_close),
6615 PROC(SETATTR, enc_setattr, dec_setattr),
6616 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6617 PROC(RENEW, enc_renew, dec_renew),
6618 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6619 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6620 PROC(LOCK, enc_lock, dec_lock),
6621 PROC(LOCKT, enc_lockt, dec_lockt),
6622 PROC(LOCKU, enc_locku, dec_locku),
6623 PROC(ACCESS, enc_access, dec_access),
6624 PROC(GETATTR, enc_getattr, dec_getattr),
6625 PROC(LOOKUP, enc_lookup, dec_lookup),
6626 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6627 PROC(REMOVE, enc_remove, dec_remove),
6628 PROC(RENAME, enc_rename, dec_rename),
6629 PROC(LINK, enc_link, dec_link),
6630 PROC(SYMLINK, enc_symlink, dec_symlink),
6631 PROC(CREATE, enc_create, dec_create),
6632 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6633 PROC(STATFS, enc_statfs, dec_statfs),
6634 PROC(READLINK, enc_readlink, dec_readlink),
6635 PROC(READDIR, enc_readdir, dec_readdir),
6636 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6637 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6638 PROC(GETACL, enc_getacl, dec_getacl),
6639 PROC(SETACL, enc_setacl, dec_setacl),
6640 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6641 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006642 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006643#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00006644 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6645 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6646 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6647 PROC(SEQUENCE, enc_sequence, dec_sequence),
6648 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6649 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6650 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6651 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00006652 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03006653 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006654#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006655};
6656
6657struct rpc_version nfs_version4 = {
6658 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08006659 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07006660 .procs = nfs4_procedures
6661};
6662
6663/*
6664 * Local variables:
6665 * c-basic-offset: 8
6666 * End:
6667 */