blob: 68889469d11414628e7079f94eb3d26d244ab060 [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>
41#include <linux/slab.h>
42#include <linux/utsname.h>
43#include <linux/errno.h>
44#include <linux/string.h>
45#include <linux/in.h>
46#include <linux/pagemap.h>
47#include <linux/proc_fs.h>
48#include <linux/kdev_t.h>
49#include <linux/sunrpc/clnt.h>
50#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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#define NFSDBG_FACILITY NFSDBG_XDR
57
58/* Mapping from NFS error code to "errno" error code. */
59#define errno_NFSERR_IO EIO
60
David Howells0a8ea432006-08-22 20:06:08 -040061static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
64#ifdef DEBUG
65#define NFS4_MAXTAGLEN 20
66#else
67#define NFS4_MAXTAGLEN 0
68#endif
69
Andy Adamson6c0195a2008-12-23 16:06:15 -050070/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040071 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 */
Trond Myklebust9f958ab2007-07-02 13:58:33 -040073#define open_owner_id_maxsz (1 + 4)
74#define lock_owner_id_maxsz (1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040075#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78#define op_encode_hdr_maxsz (1)
79#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040080#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
85 (NFS4_FHSIZE >> 2))
86#define decode_putfh_maxsz (op_decode_hdr_maxsz)
87#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89#define encode_getfh_maxsz (op_encode_hdr_maxsz)
90#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000092#define nfs4_fattr_bitmap_maxsz 3
93#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040096#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +000098/* This is based on getfattr, which uses the most attributes: */
99#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000101#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400104#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
105 1 + 2 + 1 + \
106 nfs4_owner_maxsz + \
107 nfs4_group_maxsz + \
108 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#define encode_savefh_maxsz (op_encode_hdr_maxsz)
110#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400111#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200113#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116#define decode_renew_maxsz (op_decode_hdr_maxsz)
117#define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
121 1 /* sc_prog */ + \
122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
124 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#define decode_setclientid_maxsz \
126 (op_decode_hdr_maxsz + \
127 2 + \
128 1024) /* large value for CLID_INUSE */
129#define encode_setclientid_confirm_maxsz \
130 (op_encode_hdr_maxsz + \
131 3 + (NFS4_VERIFIER_SIZE >> 2))
132#define decode_setclientid_confirm_maxsz \
133 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400134#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400136#define encode_share_access_maxsz \
137 (2)
Trond Myklebust9104a552007-07-17 21:52:42 -0400138#define encode_createmode_maxsz (1 + encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400139#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141#define encode_open_maxsz (op_encode_hdr_maxsz + \
142 2 + encode_share_access_maxsz + 2 + \
143 open_owner_id_maxsz + \
144 encode_opentype_maxsz + \
145 encode_claim_null_maxsz)
146#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400147#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400148 decode_ace_maxsz)
149#define decode_change_info_maxsz (5)
150#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400151 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400155#define encode_open_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 encode_stateid_maxsz + 1)
158#define decode_open_confirm_maxsz \
159 (op_decode_hdr_maxsz + \
160 decode_stateid_maxsz)
161#define encode_open_downgrade_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1 + \
164 encode_share_access_maxsz)
165#define decode_open_downgrade_maxsz \
166 (op_decode_hdr_maxsz + \
167 decode_stateid_maxsz)
168#define encode_close_maxsz (op_encode_hdr_maxsz + \
169 1 + encode_stateid_maxsz)
170#define decode_close_maxsz (op_decode_hdr_maxsz + \
171 decode_stateid_maxsz)
172#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + \
174 encode_attrs_maxsz)
175#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
176 nfs4_fattr_bitmap_maxsz)
177#define encode_read_maxsz (op_encode_hdr_maxsz + \
178 encode_stateid_maxsz + 3)
179#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
180#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
181 2 + encode_verifier_maxsz + 5)
182#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
183 decode_verifier_maxsz)
184#define encode_readlink_maxsz (op_encode_hdr_maxsz)
185#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
186#define encode_write_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 4)
188#define decode_write_maxsz (op_decode_hdr_maxsz + \
189 2 + decode_verifier_maxsz)
190#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
191#define decode_commit_maxsz (op_decode_hdr_maxsz + \
192 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193#define encode_remove_maxsz (op_encode_hdr_maxsz + \
194 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400195#define decode_remove_maxsz (op_decode_hdr_maxsz + \
196 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#define encode_rename_maxsz (op_encode_hdr_maxsz + \
198 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400199#define decode_rename_maxsz (op_decode_hdr_maxsz + \
200 decode_change_info_maxsz + \
201 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#define encode_link_maxsz (op_encode_hdr_maxsz + \
203 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400204#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400205#define encode_lock_maxsz (op_encode_hdr_maxsz + \
206 7 + \
207 1 + encode_stateid_maxsz + 8)
208#define decode_lock_denied_maxsz \
209 (8 + decode_lockowner_maxsz)
210#define decode_lock_maxsz (op_decode_hdr_maxsz + \
211 decode_lock_denied_maxsz)
212#define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
213#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
215#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
216 encode_stateid_maxsz + \
217 4)
218#define decode_locku_maxsz (op_decode_hdr_maxsz + \
219 decode_stateid_maxsz)
220#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
221#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
223 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400224 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000225 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
227#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400228 1 + 2 + nfs4_name_maxsz + \
229 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400230#define decode_create_maxsz (op_decode_hdr_maxsz + \
231 decode_change_info_maxsz + \
232 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400233#define encode_statfs_maxsz (encode_getattr_maxsz)
234#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
236#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400237#define encode_getacl_maxsz (encode_getattr_maxsz)
238#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
239 nfs4_fattr_bitmap_maxsz + 1)
240#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
241 encode_stateid_maxsz + 3)
242#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400243#define encode_fs_locations_maxsz \
244 (encode_getattr_maxsz)
245#define decode_fs_locations_maxsz \
246 (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
248#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
249#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
250 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400251 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
253 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400254 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
256 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400257 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
259 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400260 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
262 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400263 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
265 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400266 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
268 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400269 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400270 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
272 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400273 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400274 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
276 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400277 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400278 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
280 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400281 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400282 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400284 encode_putfh_maxsz + \
285 encode_savefh_maxsz + \
286 encode_open_maxsz + \
287 encode_getfh_maxsz + \
288 encode_getattr_maxsz + \
289 encode_restorefh_maxsz + \
290 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400292 decode_putfh_maxsz + \
293 decode_savefh_maxsz + \
294 decode_open_maxsz + \
295 decode_getfh_maxsz + \
296 decode_getattr_maxsz + \
297 decode_restorefh_maxsz + \
298 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400299#define NFS4_enc_open_confirm_sz \
300 (compound_encode_hdr_maxsz + \
301 encode_putfh_maxsz + \
302 encode_open_confirm_maxsz)
303#define NFS4_dec_open_confirm_sz \
304 (compound_decode_hdr_maxsz + \
305 decode_putfh_maxsz + \
306 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
308 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400309 encode_open_maxsz + \
310 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
312 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400313 decode_open_maxsz + \
314 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315#define NFS4_enc_open_downgrade_sz \
316 (compound_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400317 encode_putfh_maxsz + \
318 encode_open_downgrade_maxsz + \
319 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320#define NFS4_dec_open_downgrade_sz \
321 (compound_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400322 decode_putfh_maxsz + \
323 decode_open_downgrade_maxsz + \
324 decode_getattr_maxsz)
325#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
326 encode_putfh_maxsz + \
327 encode_close_maxsz + \
328 encode_getattr_maxsz)
329#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
330 decode_putfh_maxsz + \
331 decode_close_maxsz + \
332 decode_getattr_maxsz)
333#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
334 encode_putfh_maxsz + \
335 encode_setattr_maxsz + \
336 encode_getattr_maxsz)
337#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
338 decode_putfh_maxsz + \
339 decode_setattr_maxsz + \
340 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
342 encode_putfh_maxsz + \
343 encode_fsinfo_maxsz)
344#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
345 decode_putfh_maxsz + \
346 decode_fsinfo_maxsz)
347#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
348 encode_renew_maxsz)
349#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
350 decode_renew_maxsz)
351#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
352 encode_setclientid_maxsz)
353#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
354 decode_setclientid_maxsz)
355#define NFS4_enc_setclientid_confirm_sz \
356 (compound_encode_hdr_maxsz + \
357 encode_setclientid_confirm_maxsz + \
358 encode_putrootfh_maxsz + \
359 encode_fsinfo_maxsz)
360#define NFS4_dec_setclientid_confirm_sz \
361 (compound_decode_hdr_maxsz + \
362 decode_setclientid_confirm_maxsz + \
363 decode_putrootfh_maxsz + \
364 decode_fsinfo_maxsz)
365#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
366 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400367 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
369 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400370 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
372 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400373 encode_lockt_maxsz)
374#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
375 decode_putfh_maxsz + \
376 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
378 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400379 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
381 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400382 decode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
384 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400385 encode_access_maxsz + \
386 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
388 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400389 decode_access_maxsz + \
390 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
392 encode_putfh_maxsz + \
393 encode_getattr_maxsz)
394#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
395 decode_putfh_maxsz + \
396 decode_getattr_maxsz)
397#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
398 encode_putfh_maxsz + \
399 encode_lookup_maxsz + \
400 encode_getattr_maxsz + \
401 encode_getfh_maxsz)
402#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
403 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400404 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 decode_getattr_maxsz + \
406 decode_getfh_maxsz)
407#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
408 encode_putrootfh_maxsz + \
409 encode_getattr_maxsz + \
410 encode_getfh_maxsz)
411#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
412 decode_putrootfh_maxsz + \
413 decode_getattr_maxsz + \
414 decode_getfh_maxsz)
415#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
416 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400417 encode_remove_maxsz + \
418 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
420 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400421 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400422 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
424 encode_putfh_maxsz + \
425 encode_savefh_maxsz + \
426 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400427 encode_rename_maxsz + \
428 encode_getattr_maxsz + \
429 encode_restorefh_maxsz + \
430 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
432 decode_putfh_maxsz + \
433 decode_savefh_maxsz + \
434 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400435 decode_rename_maxsz + \
436 decode_getattr_maxsz + \
437 decode_restorefh_maxsz + \
438 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
440 encode_putfh_maxsz + \
441 encode_savefh_maxsz + \
442 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400443 encode_link_maxsz + \
444 decode_getattr_maxsz + \
445 encode_restorefh_maxsz + \
446 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
448 decode_putfh_maxsz + \
449 decode_savefh_maxsz + \
450 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400451 decode_link_maxsz + \
452 decode_getattr_maxsz + \
453 decode_restorefh_maxsz + \
454 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
456 encode_putfh_maxsz + \
457 encode_symlink_maxsz + \
458 encode_getattr_maxsz + \
459 encode_getfh_maxsz)
460#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
461 decode_putfh_maxsz + \
462 decode_symlink_maxsz + \
463 decode_getattr_maxsz + \
464 decode_getfh_maxsz)
465#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
466 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400467 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400469 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400471 encode_restorefh_maxsz + \
472 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
474 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400475 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400477 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400479 decode_restorefh_maxsz + \
480 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
482 encode_putfh_maxsz + \
483 encode_getattr_maxsz)
484#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
485 decode_putfh_maxsz + \
486 decode_getattr_maxsz)
487#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
488 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400489 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
491 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400492 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800494 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 encode_getattr_maxsz)
496#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800497 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 decode_getattr_maxsz)
499#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
500 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100501 encode_delegreturn_maxsz + \
502 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100504 decode_delegreturn_maxsz + \
505 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000506#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
507 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400508 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000509#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
510 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400511 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000512#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
513 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400514 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000515#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
516 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400517 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400518#define NFS4_enc_fs_locations_sz \
519 (compound_encode_hdr_maxsz + \
520 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400521 encode_lookup_maxsz + \
522 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400523#define NFS4_dec_fs_locations_sz \
524 (compound_decode_hdr_maxsz + \
525 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400526 decode_lookup_maxsz + \
527 decode_fs_locations_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Trond Myklebustbca79472009-03-11 14:10:26 -0400529static const umode_t nfs_type2fmt[] = {
530 [NF4BAD] = 0,
531 [NF4REG] = S_IFREG,
532 [NF4DIR] = S_IFDIR,
533 [NF4BLK] = S_IFBLK,
534 [NF4CHR] = S_IFCHR,
535 [NF4LNK] = S_IFLNK,
536 [NF4SOCK] = S_IFSOCK,
537 [NF4FIFO] = S_IFIFO,
538 [NF4ATTRDIR] = 0,
539 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540};
541
542struct compound_hdr {
543 int32_t status;
544 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500545 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 uint32_t taglen;
547 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400548 uint32_t replen; /* expected reply words */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549};
550
551/*
552 * START OF "GENERIC" ENCODE ROUTINES.
553 * These may look a little ugly since they are imported from a "generic"
554 * set of XDR encode/decode routines which are intended to be shared by
555 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
556 *
557 * If the pain of reading these is too great, it should be a straightforward
558 * task to translate them into Linux-specific versions which are more
559 * consistent with the style used in NFSv2/v3...
560 */
561#define WRITE32(n) *p++ = htonl(n)
562#define WRITE64(n) do { \
563 *p++ = htonl((uint32_t)((n) >> 32)); \
564 *p++ = htonl((uint32_t)(n)); \
565} while (0)
566#define WRITEMEM(ptr,nbytes) do { \
567 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
568} while (0)
569
570#define RESERVE_SPACE(nbytes) do { \
571 p = xdr_reserve_space(xdr, nbytes); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 BUG_ON(!p); \
573} while (0)
574
575static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
576{
Al Viro8687b632006-10-19 23:28:48 -0700577 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
579 p = xdr_reserve_space(xdr, 4 + len);
580 BUG_ON(p == NULL);
581 xdr_encode_opaque(p, str, len);
582}
583
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400584static void encode_compound_hdr(struct xdr_stream *xdr,
585 struct rpc_rqst *req,
586 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587{
Al Viro8687b632006-10-19 23:28:48 -0700588 __be32 *p;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400589 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
590
591 /* initialize running count of expected bytes in reply.
592 * NOTE: the replied tag SHOULD be the same is the one sent,
593 * but this is not required as a MUST for the server to do so. */
594 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
597 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
598 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
599 WRITE32(hdr->taglen);
600 WRITEMEM(hdr->tag, hdr->taglen);
601 WRITE32(NFS4_MINOR_VERSION);
Andy Adamsond0179312008-12-23 16:06:17 -0500602 hdr->nops_p = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 WRITE32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500604}
605
606static void encode_nops(struct compound_hdr *hdr)
607{
608 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609}
610
611static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
612{
Al Viro8687b632006-10-19 23:28:48 -0700613 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
615 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
616 BUG_ON(p == NULL);
617 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
618}
619
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500620static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621{
622 char owner_name[IDMAP_NAMESZ];
623 char owner_group[IDMAP_NAMESZ];
624 int owner_namelen = 0;
625 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700626 __be32 *p;
627 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 int len;
629 uint32_t bmval0 = 0;
630 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
632 /*
633 * We reserve enough space to write the entire attribute buffer at once.
634 * In the worst-case, this would be
635 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
636 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000637 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 */
639 len = 16;
640
641 /* Sigh */
642 if (iap->ia_valid & ATTR_SIZE)
643 len += 8;
644 if (iap->ia_valid & ATTR_MODE)
645 len += 4;
646 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400647 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400649 dprintk("nfs: couldn't resolve uid %d to string\n",
650 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 /* XXX */
652 strcpy(owner_name, "nobody");
653 owner_namelen = sizeof("nobody") - 1;
654 /* goto out; */
655 }
656 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
657 }
658 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400659 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400661 dprintk("nfs: couldn't resolve gid %d to string\n",
662 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 strcpy(owner_group, "nobody");
664 owner_grouplen = sizeof("nobody") - 1;
665 /* goto out; */
666 }
667 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
668 }
669 if (iap->ia_valid & ATTR_ATIME_SET)
670 len += 16;
671 else if (iap->ia_valid & ATTR_ATIME)
672 len += 4;
673 if (iap->ia_valid & ATTR_MTIME_SET)
674 len += 16;
675 else if (iap->ia_valid & ATTR_MTIME)
676 len += 4;
677 RESERVE_SPACE(len);
678
679 /*
680 * We write the bitmap length now, but leave the bitmap and the attribute
681 * buffer length to be backfilled at the end of this routine.
682 */
683 WRITE32(2);
684 q = p;
685 p += 3;
686
687 if (iap->ia_valid & ATTR_SIZE) {
688 bmval0 |= FATTR4_WORD0_SIZE;
689 WRITE64(iap->ia_size);
690 }
691 if (iap->ia_valid & ATTR_MODE) {
692 bmval1 |= FATTR4_WORD1_MODE;
Trond Myklebustcf3fff52006-01-03 09:55:53 +0100693 WRITE32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 }
695 if (iap->ia_valid & ATTR_UID) {
696 bmval1 |= FATTR4_WORD1_OWNER;
697 WRITE32(owner_namelen);
698 WRITEMEM(owner_name, owner_namelen);
699 }
700 if (iap->ia_valid & ATTR_GID) {
701 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
702 WRITE32(owner_grouplen);
703 WRITEMEM(owner_group, owner_grouplen);
704 }
705 if (iap->ia_valid & ATTR_ATIME_SET) {
706 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
707 WRITE32(NFS4_SET_TO_CLIENT_TIME);
708 WRITE32(0);
709 WRITE32(iap->ia_mtime.tv_sec);
710 WRITE32(iap->ia_mtime.tv_nsec);
711 }
712 else if (iap->ia_valid & ATTR_ATIME) {
713 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
714 WRITE32(NFS4_SET_TO_SERVER_TIME);
715 }
716 if (iap->ia_valid & ATTR_MTIME_SET) {
717 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
718 WRITE32(NFS4_SET_TO_CLIENT_TIME);
719 WRITE32(0);
720 WRITE32(iap->ia_mtime.tv_sec);
721 WRITE32(iap->ia_mtime.tv_nsec);
722 }
723 else if (iap->ia_valid & ATTR_MTIME) {
724 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
725 WRITE32(NFS4_SET_TO_SERVER_TIME);
726 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 /*
729 * Now we backfill the bitmap and the attribute buffer length.
730 */
731 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400732 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 len, ((char *)p - (char *)q) + 4);
734 BUG();
735 }
736 len = (char *)p - (char *)q - 12;
737 *q++ = htonl(bmval0);
738 *q++ = htonl(bmval1);
739 *q++ = htonl(len);
740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742}
743
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500744static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745{
Al Viro8687b632006-10-19 23:28:48 -0700746 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748 RESERVE_SPACE(8);
749 WRITE32(OP_ACCESS);
750 WRITE32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500751 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400752 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753}
754
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500755static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756{
Al Viro8687b632006-10-19 23:28:48 -0700757 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400759 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 WRITE32(OP_CLOSE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700761 WRITE32(arg->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400762 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500763 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400764 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765}
766
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500767static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
Al Viro8687b632006-10-19 23:28:48 -0700769 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500770
Andy Adamson05d564f2008-12-23 16:06:15 -0500771 RESERVE_SPACE(16);
772 WRITE32(OP_COMMIT);
773 WRITE64(args->offset);
774 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500775 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400776 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777}
778
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500779static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780{
Al Viro8687b632006-10-19 23:28:48 -0700781 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500782
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 RESERVE_SPACE(8);
784 WRITE32(OP_CREATE);
785 WRITE32(create->ftype);
786
787 switch (create->ftype) {
788 case NF4LNK:
Chuck Lever94a6d752006-08-22 20:06:23 -0400789 RESERVE_SPACE(4);
790 WRITE32(create->u.symlink.len);
791 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 break;
793
794 case NF4BLK: case NF4CHR:
795 RESERVE_SPACE(8);
796 WRITE32(create->u.device.specdata1);
797 WRITE32(create->u.device.specdata2);
798 break;
799
800 default:
801 break;
802 }
803
804 RESERVE_SPACE(4 + create->name->len);
805 WRITE32(create->name->len);
806 WRITEMEM(create->name->name, create->name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500807 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400808 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500810 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811}
812
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500813static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
Andy Adamson05d564f2008-12-23 16:06:15 -0500815 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Andy Adamson05d564f2008-12-23 16:06:15 -0500817 RESERVE_SPACE(12);
818 WRITE32(OP_GETATTR);
819 WRITE32(1);
820 WRITE32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500821 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400822 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823}
824
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500825static 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 -0700826{
Andy Adamson05d564f2008-12-23 16:06:15 -0500827 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Andy Adamson05d564f2008-12-23 16:06:15 -0500829 RESERVE_SPACE(16);
830 WRITE32(OP_GETATTR);
831 WRITE32(2);
832 WRITE32(bm0);
833 WRITE32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -0500834 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400835 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836}
837
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500838static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500840 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
841 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842}
843
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500844static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500846 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
847 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848}
849
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500850static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -0400851{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500852 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
853 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -0400854}
855
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500856static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
Al Viro8687b632006-10-19 23:28:48 -0700858 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
860 RESERVE_SPACE(4);
861 WRITE32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -0500862 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400863 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864}
865
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500866static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867{
Al Viro8687b632006-10-19 23:28:48 -0700868 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
870 RESERVE_SPACE(8 + name->len);
871 WRITE32(OP_LINK);
872 WRITE32(name->len);
873 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500874 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400875 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876}
877
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100878static inline int nfs4_lock_type(struct file_lock *fl, int block)
879{
880 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
881 return block ? NFS4_READW_LT : NFS4_READ_LT;
882 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
883}
884
885static inline uint64_t nfs4_lock_length(struct file_lock *fl)
886{
887 if (fl->fl_end == OFFSET_MAX)
888 return ~(uint64_t)0;
889 return fl->fl_end - fl->fl_start + 1;
890}
891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892/*
893 * opcode,type,reclaim,offset,length,new_lock_owner = 32
894 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
895 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500896static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897{
Al Viro8687b632006-10-19 23:28:48 -0700898 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
900 RESERVE_SPACE(32);
901 WRITE32(OP_LOCK);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100902 WRITE32(nfs4_lock_type(args->fl, args->block));
903 WRITE32(args->reclaim);
904 WRITE64(args->fl->fl_start);
905 WRITE64(nfs4_lock_length(args->fl));
906 WRITE32(args->new_lock_owner);
907 if (args->new_lock_owner){
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400908 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100909 WRITE32(args->open_seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400910 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100911 WRITE32(args->lock_seqid->sequence->counter);
912 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400913 WRITE32(16);
914 WRITEMEM("lock id:", 8);
915 WRITE64(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 }
917 else {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400918 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
919 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100920 WRITE32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 }
Andy Adamsond0179312008-12-23 16:06:17 -0500922 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400923 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924}
925
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500926static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927{
Al Viro8687b632006-10-19 23:28:48 -0700928 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400930 RESERVE_SPACE(52);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 WRITE32(OP_LOCKT);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100932 WRITE32(nfs4_lock_type(args->fl, 0));
933 WRITE64(args->fl->fl_start);
934 WRITE64(nfs4_lock_length(args->fl));
935 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400936 WRITE32(16);
937 WRITEMEM("lock id:", 8);
938 WRITE64(args->lock_owner.id);
Andy Adamsond0179312008-12-23 16:06:17 -0500939 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400940 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941}
942
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500943static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944{
Al Viro8687b632006-10-19 23:28:48 -0700945 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400947 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 WRITE32(OP_LOCKU);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100949 WRITE32(nfs4_lock_type(args->fl, 0));
950 WRITE32(args->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400951 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100952 WRITE64(args->fl->fl_start);
953 WRITE64(nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -0500954 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400955 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956}
957
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500958static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959{
960 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -0700961 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
963 RESERVE_SPACE(8 + len);
964 WRITE32(OP_LOOKUP);
965 WRITE32(len);
966 WRITEMEM(name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -0500967 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400968 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969}
970
Trond Myklebustdc0b0272008-12-23 15:21:56 -0500971static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972{
Al Viro8687b632006-10-19 23:28:48 -0700973 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
975 RESERVE_SPACE(8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -0500976 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -0500977 case FMODE_READ:
978 WRITE32(NFS4_SHARE_ACCESS_READ);
979 break;
980 case FMODE_WRITE:
981 WRITE32(NFS4_SHARE_ACCESS_WRITE);
982 break;
983 case FMODE_READ|FMODE_WRITE:
984 WRITE32(NFS4_SHARE_ACCESS_BOTH);
985 break;
986 default:
987 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 }
989 WRITE32(0); /* for linux, share_deny = 0 always */
990}
991
992static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
993{
Al Viro8687b632006-10-19 23:28:48 -0700994 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 /*
996 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
997 * owner 4 = 32
998 */
999 RESERVE_SPACE(8);
1000 WRITE32(OP_OPEN);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001001 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001002 encode_share_access(xdr, arg->fmode);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001003 RESERVE_SPACE(28);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 WRITE64(arg->clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -04001005 WRITE32(16);
1006 WRITEMEM("open id:", 8);
1007 WRITE64(arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008}
1009
1010static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1011{
Al Viro8687b632006-10-19 23:28:48 -07001012 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
1014 RESERVE_SPACE(4);
1015 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001016 case 0:
1017 WRITE32(NFS4_CREATE_UNCHECKED);
1018 encode_attrs(xdr, arg->u.attrs, arg->server);
1019 break;
1020 default:
1021 WRITE32(NFS4_CREATE_EXCLUSIVE);
1022 encode_nfs4_verifier(xdr, &arg->u.verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 }
1024}
1025
1026static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1027{
Al Viro8687b632006-10-19 23:28:48 -07001028 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
1030 RESERVE_SPACE(4);
1031 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001032 case 0:
1033 WRITE32(NFS4_OPEN_NOCREATE);
1034 break;
1035 default:
1036 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1037 WRITE32(NFS4_OPEN_CREATE);
1038 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 }
1040}
1041
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001042static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043{
Al Viro8687b632006-10-19 23:28:48 -07001044 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
1046 RESERVE_SPACE(4);
1047 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001048 case 0:
1049 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1050 break;
1051 case FMODE_READ:
1052 WRITE32(NFS4_OPEN_DELEGATE_READ);
1053 break;
1054 case FMODE_WRITE|FMODE_READ:
1055 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1056 break;
1057 default:
1058 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 }
1060}
1061
1062static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1063{
Al Viro8687b632006-10-19 23:28:48 -07001064 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
1066 RESERVE_SPACE(4);
1067 WRITE32(NFS4_OPEN_CLAIM_NULL);
1068 encode_string(xdr, name->len, name->name);
1069}
1070
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001071static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072{
Al Viro8687b632006-10-19 23:28:48 -07001073 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
1075 RESERVE_SPACE(4);
1076 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1077 encode_delegation_type(xdr, type);
1078}
1079
1080static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1081{
Al Viro8687b632006-10-19 23:28:48 -07001082 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001084 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001086 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 encode_string(xdr, name->len, name->name);
1088}
1089
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001090static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
1092 encode_openhdr(xdr, arg);
1093 encode_opentype(xdr, arg);
1094 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001095 case NFS4_OPEN_CLAIM_NULL:
1096 encode_claim_null(xdr, arg->name);
1097 break;
1098 case NFS4_OPEN_CLAIM_PREVIOUS:
1099 encode_claim_previous(xdr, arg->u.delegation_type);
1100 break;
1101 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1102 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1103 break;
1104 default:
1105 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 }
Andy Adamsond0179312008-12-23 16:06:17 -05001107 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001108 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109}
1110
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001111static 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 -07001112{
Al Viro8687b632006-10-19 23:28:48 -07001113 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001115 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 WRITE32(OP_OPEN_CONFIRM);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001117 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001118 WRITE32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001119 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001120 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121}
1122
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001123static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124{
Al Viro8687b632006-10-19 23:28:48 -07001125 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001127 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 WRITE32(OP_OPEN_DOWNGRADE);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001129 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001130 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001131 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001132 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001133 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134}
1135
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001136static void
Andy Adamsond0179312008-12-23 16:06:17 -05001137encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138{
1139 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001140 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
1142 RESERVE_SPACE(8 + len);
1143 WRITE32(OP_PUTFH);
1144 WRITE32(len);
1145 WRITEMEM(fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001146 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001147 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148}
1149
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001150static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151{
Andy Adamson05d564f2008-12-23 16:06:15 -05001152 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001153
Andy Adamson05d564f2008-12-23 16:06:15 -05001154 RESERVE_SPACE(4);
1155 WRITE32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001156 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001157 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158}
1159
1160static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1161{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001163 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001165 RESERVE_SPACE(NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 if (ctx->state != NULL) {
1167 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001168 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 } else
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001170 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171}
1172
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001173static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174{
Al Viro8687b632006-10-19 23:28:48 -07001175 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
1177 RESERVE_SPACE(4);
1178 WRITE32(OP_READ);
1179
1180 encode_stateid(xdr, args->context);
1181
1182 RESERVE_SPACE(12);
1183 WRITE64(args->offset);
1184 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001185 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001186 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187}
1188
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001189static 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 -07001190{
Manoj Naik97d312d2005-06-22 17:16:39 +00001191 uint32_t attrs[2] = {
1192 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1193 FATTR4_WORD1_MOUNTED_ON_FILEID,
1194 };
Al Viro8687b632006-10-19 23:28:48 -07001195 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001197 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 WRITE32(OP_READDIR);
1199 WRITE64(readdir->cookie);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001200 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1202 WRITE32(readdir->count);
1203 WRITE32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001204 /* Switch to mounted_on_fileid if the server supports it */
1205 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1206 attrs[0] &= ~FATTR4_WORD0_FILEID;
1207 else
1208 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1209 WRITE32(attrs[0] & readdir->bitmask[0]);
1210 WRITE32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001211 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001212 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001213 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1214 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001215 (unsigned long long)readdir->cookie,
1216 ((u32 *)readdir->verifier.data)[0],
1217 ((u32 *)readdir->verifier.data)[1],
1218 attrs[0] & readdir->bitmask[0],
1219 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220}
1221
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001222static 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 -07001223{
Al Viro8687b632006-10-19 23:28:48 -07001224 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225
1226 RESERVE_SPACE(4);
1227 WRITE32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001228 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001229 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230}
1231
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001232static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233{
Al Viro8687b632006-10-19 23:28:48 -07001234 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
1236 RESERVE_SPACE(8 + name->len);
1237 WRITE32(OP_REMOVE);
1238 WRITE32(name->len);
1239 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001240 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001241 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242}
1243
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001244static 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 -07001245{
Al Viro8687b632006-10-19 23:28:48 -07001246 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
1248 RESERVE_SPACE(8 + oldname->len);
1249 WRITE32(OP_RENAME);
1250 WRITE32(oldname->len);
1251 WRITEMEM(oldname->name, oldname->len);
Andy Adamson6c0195a2008-12-23 16:06:15 -05001252
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 RESERVE_SPACE(4 + newname->len);
1254 WRITE32(newname->len);
1255 WRITEMEM(newname->name, newname->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001256 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001257 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258}
1259
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001260static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261{
Al Viro8687b632006-10-19 23:28:48 -07001262 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
1264 RESERVE_SPACE(12);
1265 WRITE32(OP_RENEW);
1266 WRITE64(client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001267 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001268 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269}
1270
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001271static void
Andy Adamsond0179312008-12-23 16:06:17 -05001272encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001273{
Al Viro8687b632006-10-19 23:28:48 -07001274 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001275
1276 RESERVE_SPACE(4);
1277 WRITE32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001278 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001279 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001280}
1281
1282static int
Andy Adamsond0179312008-12-23 16:06:17 -05001283encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001284{
Al Viro8687b632006-10-19 23:28:48 -07001285 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001286
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001287 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001288 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001289 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001290 RESERVE_SPACE(2*4);
1291 WRITE32(1);
1292 WRITE32(FATTR4_WORD0_ACL);
1293 if (arg->acl_len % 4)
1294 return -EINVAL;
1295 RESERVE_SPACE(4);
1296 WRITE32(arg->acl_len);
1297 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001298 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001299 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001300 return 0;
1301}
1302
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001303static void
Andy Adamsond0179312008-12-23 16:06:17 -05001304encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305{
Al Viro8687b632006-10-19 23:28:48 -07001306 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
1308 RESERVE_SPACE(4);
1309 WRITE32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001310 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001311 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312}
1313
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001314static 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 -07001315{
Al Viro8687b632006-10-19 23:28:48 -07001316 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001317
Andy Adamson05d564f2008-12-23 16:06:15 -05001318 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1319 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001320 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001321 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001322 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001323 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324}
1325
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001326static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327{
Al Viro8687b632006-10-19 23:28:48 -07001328 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001330 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 WRITE32(OP_SETCLIENTID);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001332 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
1334 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1335 RESERVE_SPACE(4);
1336 WRITE32(setclientid->sc_prog);
1337 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1338 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1339 RESERVE_SPACE(4);
1340 WRITE32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001341 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001342 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343}
1344
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001345static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346{
Andy Adamson05d564f2008-12-23 16:06:15 -05001347 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Andy Adamson05d564f2008-12-23 16:06:15 -05001349 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1350 WRITE32(OP_SETCLIENTID_CONFIRM);
1351 WRITE64(client_state->cl_clientid);
1352 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001353 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001354 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355}
1356
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001357static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358{
Al Viro8687b632006-10-19 23:28:48 -07001359 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
1361 RESERVE_SPACE(4);
1362 WRITE32(OP_WRITE);
1363
1364 encode_stateid(xdr, args->context);
1365
1366 RESERVE_SPACE(16);
1367 WRITE64(args->offset);
1368 WRITE32(args->stable);
1369 WRITE32(args->count);
1370
1371 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001372 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001373 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374}
1375
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001376static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377{
Al Viro8687b632006-10-19 23:28:48 -07001378 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001380 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
1382 WRITE32(OP_DELEGRETURN);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001383 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001384 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001385 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386}
1387/*
1388 * END OF "GENERIC" ENCODE ROUTINES.
1389 */
1390
1391/*
1392 * Encode an ACCESS request
1393 */
Al Viro8687b632006-10-19 23:28:48 -07001394static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395{
1396 struct xdr_stream xdr;
1397 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001398 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
1401 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001402 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001403 encode_putfh(&xdr, args->fh, &hdr);
1404 encode_access(&xdr, args->access, &hdr);
1405 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001406 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001407 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408}
1409
1410/*
1411 * Encode LOOKUP request
1412 */
Al Viro8687b632006-10-19 23:28:48 -07001413static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414{
1415 struct xdr_stream xdr;
1416 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001417 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
1420 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001421 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001422 encode_putfh(&xdr, args->dir_fh, &hdr);
1423 encode_lookup(&xdr, args->name, &hdr);
1424 encode_getfh(&xdr, &hdr);
1425 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001426 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001427 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428}
1429
1430/*
1431 * Encode LOOKUP_ROOT request
1432 */
Al Viro8687b632006-10-19 23:28:48 -07001433static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434{
1435 struct xdr_stream xdr;
1436 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001437 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
1440 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001441 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001442 encode_putrootfh(&xdr, &hdr);
1443 encode_getfh(&xdr, &hdr);
1444 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001445 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001446 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447}
1448
1449/*
1450 * Encode REMOVE request
1451 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001452static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453{
1454 struct xdr_stream xdr;
1455 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001456 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
1459 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001460 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001461 encode_putfh(&xdr, args->fh, &hdr);
1462 encode_remove(&xdr, &args->name, &hdr);
1463 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001464 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001465 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466}
1467
1468/*
1469 * Encode RENAME request
1470 */
Al Viro8687b632006-10-19 23:28:48 -07001471static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472{
1473 struct xdr_stream xdr;
1474 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001475 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
1478 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001479 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001480 encode_putfh(&xdr, args->old_dir, &hdr);
1481 encode_savefh(&xdr, &hdr);
1482 encode_putfh(&xdr, args->new_dir, &hdr);
1483 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1484 encode_getfattr(&xdr, args->bitmask, &hdr);
1485 encode_restorefh(&xdr, &hdr);
1486 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001487 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001488 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489}
1490
1491/*
1492 * Encode LINK request
1493 */
Al Viro8687b632006-10-19 23:28:48 -07001494static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495{
1496 struct xdr_stream xdr;
1497 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001498 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
1501 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001502 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001503 encode_putfh(&xdr, args->fh, &hdr);
1504 encode_savefh(&xdr, &hdr);
1505 encode_putfh(&xdr, args->dir_fh, &hdr);
1506 encode_link(&xdr, args->name, &hdr);
1507 encode_getfattr(&xdr, args->bitmask, &hdr);
1508 encode_restorefh(&xdr, &hdr);
1509 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001510 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001511 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512}
1513
1514/*
1515 * Encode CREATE request
1516 */
Al Viro8687b632006-10-19 23:28:48 -07001517static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518{
1519 struct xdr_stream xdr;
1520 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001521 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
1524 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001525 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001526 encode_putfh(&xdr, args->dir_fh, &hdr);
1527 encode_savefh(&xdr, &hdr);
1528 encode_create(&xdr, args, &hdr);
1529 encode_getfh(&xdr, &hdr);
1530 encode_getfattr(&xdr, args->bitmask, &hdr);
1531 encode_restorefh(&xdr, &hdr);
1532 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001533 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001534 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535}
1536
1537/*
1538 * Encode SYMLINK request
1539 */
Al Viro8687b632006-10-19 23:28:48 -07001540static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541{
1542 return nfs4_xdr_enc_create(req, p, args);
1543}
1544
1545/*
1546 * Encode GETATTR request
1547 */
Al Viro8687b632006-10-19 23:28:48 -07001548static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549{
1550 struct xdr_stream xdr;
1551 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001552 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
1555 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001556 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001557 encode_putfh(&xdr, args->fh, &hdr);
1558 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001559 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001560 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561}
1562
1563/*
1564 * Encode a CLOSE request
1565 */
Al Viro8687b632006-10-19 23:28:48 -07001566static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567{
Andy Adamson05d564f2008-12-23 16:06:15 -05001568 struct xdr_stream xdr;
1569 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001570 .nops = 0,
Andy Adamson05d564f2008-12-23 16:06:15 -05001571 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
Andy Adamson05d564f2008-12-23 16:06:15 -05001573 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001574 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001575 encode_putfh(&xdr, args->fh, &hdr);
1576 encode_close(&xdr, args, &hdr);
1577 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001578 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001579 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580}
1581
1582/*
1583 * Encode an OPEN request
1584 */
Al Viro8687b632006-10-19 23:28:48 -07001585static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586{
1587 struct xdr_stream xdr;
1588 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001589 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
1592 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001593 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001594 encode_putfh(&xdr, args->fh, &hdr);
1595 encode_savefh(&xdr, &hdr);
1596 encode_open(&xdr, args, &hdr);
1597 encode_getfh(&xdr, &hdr);
1598 encode_getfattr(&xdr, args->bitmask, &hdr);
1599 encode_restorefh(&xdr, &hdr);
1600 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001601 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001602 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603}
1604
1605/*
1606 * Encode an OPEN_CONFIRM request
1607 */
Al Viro8687b632006-10-19 23:28:48 -07001608static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609{
1610 struct xdr_stream xdr;
1611 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001612 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
1615 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001616 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001617 encode_putfh(&xdr, args->fh, &hdr);
1618 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001619 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001620 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621}
1622
1623/*
1624 * Encode an OPEN request with no attributes.
1625 */
Al Viro8687b632006-10-19 23:28:48 -07001626static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627{
1628 struct xdr_stream xdr;
1629 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001630 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632
1633 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001634 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001635 encode_putfh(&xdr, args->fh, &hdr);
1636 encode_open(&xdr, args, &hdr);
1637 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001638 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001639 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640}
1641
1642/*
1643 * Encode an OPEN_DOWNGRADE request
1644 */
Al Viro8687b632006-10-19 23:28:48 -07001645static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646{
1647 struct xdr_stream xdr;
1648 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001649 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
1652 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001653 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001654 encode_putfh(&xdr, args->fh, &hdr);
1655 encode_open_downgrade(&xdr, args, &hdr);
1656 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001657 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001658 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659}
1660
1661/*
1662 * Encode a LOCK request
1663 */
Al Viro8687b632006-10-19 23:28:48 -07001664static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665{
1666 struct xdr_stream xdr;
1667 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001668 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
1671 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001672 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001673 encode_putfh(&xdr, args->fh, &hdr);
1674 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001675 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001676 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677}
1678
1679/*
1680 * Encode a LOCKT request
1681 */
Al Viro8687b632006-10-19 23:28:48 -07001682static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683{
1684 struct xdr_stream xdr;
1685 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001686 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
1689 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001690 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001691 encode_putfh(&xdr, args->fh, &hdr);
1692 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001693 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001694 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695}
1696
1697/*
1698 * Encode a LOCKU request
1699 */
Al Viro8687b632006-10-19 23:28:48 -07001700static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701{
1702 struct xdr_stream xdr;
1703 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001704 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
1707 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001708 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001709 encode_putfh(&xdr, args->fh, &hdr);
1710 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001711 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001712 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713}
1714
1715/*
1716 * Encode a READLINK request
1717 */
Al Viro8687b632006-10-19 23:28:48 -07001718static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719{
1720 struct xdr_stream xdr;
1721 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001722 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001726 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001727 encode_putfh(&xdr, args->fh, &hdr);
1728 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04001729
Benny Halevy28f56692009-04-01 09:22:09 -04001730 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04001731 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05001732 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001733 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734}
1735
1736/*
1737 * Encode a READDIR request
1738 */
Al Viro8687b632006-10-19 23:28:48 -07001739static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740{
1741 struct xdr_stream xdr;
1742 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001743 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
1746 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001747 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001748 encode_putfh(&xdr, args->fh, &hdr);
1749 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001750
Benny Halevy28f56692009-04-01 09:22:09 -04001751 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001752 args->pgbase, args->count);
1753 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04001754 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001755 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001756 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001757 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758}
1759
1760/*
1761 * Encode a READ request
1762 */
Al Viro8687b632006-10-19 23:28:48 -07001763static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 struct xdr_stream xdr;
1766 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001767 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
1770 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001771 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001772 encode_putfh(&xdr, args->fh, &hdr);
1773 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
Benny Halevy28f56692009-04-01 09:22:09 -04001775 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04001777 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05001778 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001779 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780}
1781
1782/*
1783 * Encode an SETATTR request
1784 */
Al Viro8687b632006-10-19 23:28:48 -07001785static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786{
Andy Adamson05d564f2008-12-23 16:06:15 -05001787 struct xdr_stream xdr;
1788 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001789 .nops = 0,
Andy Adamson05d564f2008-12-23 16:06:15 -05001790 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
Andy Adamson05d564f2008-12-23 16:06:15 -05001792 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001793 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001794 encode_putfh(&xdr, args->fh, &hdr);
1795 encode_setattr(&xdr, args, args->server, &hdr);
1796 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001797 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001798 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799}
1800
1801/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00001802 * Encode a GETACL request
1803 */
1804static int
Al Viro8687b632006-10-19 23:28:48 -07001805nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001806 struct nfs_getaclargs *args)
1807{
1808 struct xdr_stream xdr;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001809 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001810 .nops = 0,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001811 };
Benny Halevy28f56692009-04-01 09:22:09 -04001812 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001813
1814 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001815 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001816 encode_putfh(&xdr, args->fh, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04001817 replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001818 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
1819
Benny Halevy28f56692009-04-01 09:22:09 -04001820 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001821 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001822 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001823 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001824}
1825
1826/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 * Encode a WRITE request
1828 */
Al Viro8687b632006-10-19 23:28:48 -07001829static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830{
1831 struct xdr_stream xdr;
1832 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001833 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
1836 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001837 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001838 encode_putfh(&xdr, args->fh, &hdr);
1839 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04001840 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001841 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001842 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001843 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844}
1845
1846/*
1847 * a COMMIT request
1848 */
Al Viro8687b632006-10-19 23:28:48 -07001849static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850{
1851 struct xdr_stream xdr;
1852 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001853 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
1856 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001857 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001858 encode_putfh(&xdr, args->fh, &hdr);
1859 encode_commit(&xdr, args, &hdr);
1860 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001861 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001862 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863}
1864
1865/*
1866 * FSINFO request
1867 */
Al Viro8687b632006-10-19 23:28:48 -07001868static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869{
1870 struct xdr_stream xdr;
1871 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001872 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
1875 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001876 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001877 encode_putfh(&xdr, args->fh, &hdr);
1878 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001879 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001880 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881}
1882
1883/*
1884 * a PATHCONF request
1885 */
Al Viro8687b632006-10-19 23:28:48 -07001886static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 struct xdr_stream xdr;
1889 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001890 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892
1893 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001894 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001895 encode_putfh(&xdr, args->fh, &hdr);
1896 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
1897 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001898 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001899 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900}
1901
1902/*
1903 * a STATFS request
1904 */
Al Viro8687b632006-10-19 23:28:48 -07001905static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 struct xdr_stream xdr;
1908 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001909 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911
1912 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001913 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001914 encode_putfh(&xdr, args->fh, &hdr);
1915 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
1916 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001917 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001918 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919}
1920
1921/*
1922 * GETATTR_BITMAP request
1923 */
Benny Halevy43652ad2009-04-01 09:21:54 -04001924static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
1925 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926{
1927 struct xdr_stream xdr;
1928 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001929 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931
1932 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001933 encode_compound_hdr(&xdr, req, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04001934 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001935 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1936 FATTR4_WORD0_LINK_SUPPORT|
1937 FATTR4_WORD0_SYMLINK_SUPPORT|
1938 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001939 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001940 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941}
1942
1943/*
1944 * a RENEW request
1945 */
Al Viro8687b632006-10-19 23:28:48 -07001946static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947{
1948 struct xdr_stream xdr;
1949 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001950 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 };
1952
1953 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001954 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001955 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001956 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001957 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958}
1959
1960/*
1961 * a SETCLIENTID request
1962 */
Al Viro8687b632006-10-19 23:28:48 -07001963static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964{
1965 struct xdr_stream xdr;
1966 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001967 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 };
1969
1970 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001971 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001972 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001973 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001974 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975}
1976
1977/*
1978 * a SETCLIENTID_CONFIRM request
1979 */
Al Viro8687b632006-10-19 23:28:48 -07001980static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981{
1982 struct xdr_stream xdr;
1983 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001984 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 };
1986 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987
1988 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001989 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001990 encode_setclientid_confirm(&xdr, clp, &hdr);
1991 encode_putrootfh(&xdr, &hdr);
1992 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001993 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001994 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995}
1996
1997/*
1998 * DELEGRETURN request
1999 */
Al Viro8687b632006-10-19 23:28:48 -07002000static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001{
2002 struct xdr_stream xdr;
2003 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002004 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
2007 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002008 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002009 encode_putfh(&xdr, args->fhandle, &hdr);
2010 encode_delegreturn(&xdr, args->stateid, &hdr);
2011 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002012 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002013 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014}
2015
2016/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002017 * Encode FS_LOCATIONS request
2018 */
Al Viro8687b632006-10-19 23:28:48 -07002019static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002020{
2021 struct xdr_stream xdr;
2022 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002023 .nops = 0,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002024 };
Benny Halevy28f56692009-04-01 09:22:09 -04002025 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002026
2027 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04002028 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002029 encode_putfh(&xdr, args->dir_fh, &hdr);
2030 encode_lookup(&xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002031 replen = hdr.replen; /* get the attribute into args->page */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002032 encode_fs_locations(&xdr, args->bitmask, &hdr);
2033
Benny Halevy28f56692009-04-01 09:22:09 -04002034 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002035 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002036 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002037 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002038}
2039
2040/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 * START OF "GENERIC" DECODE ROUTINES.
2042 * These may look a little ugly since they are imported from a "generic"
2043 * set of XDR encode/decode routines which are intended to be shared by
2044 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2045 *
2046 * If the pain of reading these is too great, it should be a straightforward
2047 * task to translate them into Linux-specific versions which are more
2048 * consistent with the style used in NFSv2/v3...
2049 */
2050#define READ32(x) (x) = ntohl(*p++)
2051#define READ64(x) do { \
2052 (x) = (u64)ntohl(*p++) << 32; \
2053 (x) |= ntohl(*p++); \
2054} while (0)
2055#define READTIME(x) do { \
2056 p++; \
2057 (x.tv_sec) = ntohl(*p++); \
2058 (x.tv_nsec) = ntohl(*p++); \
2059} while (0)
2060#define COPYMEM(x,nbytes) do { \
2061 memcpy((x), p, nbytes); \
2062 p += XDR_QUADLEN(nbytes); \
2063} while (0)
2064
2065#define READ_BUF(nbytes) do { \
2066 p = xdr_inline_decode(xdr, nbytes); \
Chuck Levere4cc6ee2007-05-08 18:23:28 -04002067 if (unlikely(!p)) { \
Chuck Leverfe82a182007-09-11 18:01:10 -04002068 dprintk("nfs: %s: prematurely hit end of receive" \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002069 " buffer\n", __func__); \
Chuck Leverfe82a182007-09-11 18:01:10 -04002070 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002071 __func__, xdr->p, nbytes, xdr->end); \
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 return -EIO; \
2073 } \
2074} while (0)
2075
Trond Myklebust683b57b2006-06-09 09:34:22 -04002076static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077{
Al Viro8687b632006-10-19 23:28:48 -07002078 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079
2080 READ_BUF(4);
2081 READ32(*len);
2082 READ_BUF(*len);
2083 *string = (char *)p;
2084 return 0;
2085}
2086
2087static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2088{
Al Viro8687b632006-10-19 23:28:48 -07002089 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090
2091 READ_BUF(8);
2092 READ32(hdr->status);
2093 READ32(hdr->taglen);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002094
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 READ_BUF(hdr->taglen + 4);
2096 hdr->tag = (char *)p;
2097 p += XDR_QUADLEN(hdr->taglen);
2098 READ32(hdr->nops);
Benny Halevyaadf6152008-12-23 16:06:13 -05002099 if (unlikely(hdr->nops < 1))
2100 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 return 0;
2102}
2103
2104static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2105{
Al Viro8687b632006-10-19 23:28:48 -07002106 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 uint32_t opnum;
2108 int32_t nfserr;
2109
2110 READ_BUF(8);
2111 READ32(opnum);
2112 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002113 dprintk("nfs: Server returned operation"
2114 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 opnum, expected);
2116 return -EIO;
2117 }
2118 READ32(nfserr);
2119 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002120 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 return 0;
2122}
2123
2124/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002125static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126{
Al Viro8687b632006-10-19 23:28:48 -07002127 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002128 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 char *str;
2130
2131 READ_BUF(12);
2132 return decode_opaque_inline(xdr, &strlen, &str);
2133}
2134
2135static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2136{
Al Viro8687b632006-10-19 23:28:48 -07002137 uint32_t bmlen;
2138 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
2140 READ_BUF(4);
2141 READ32(bmlen);
2142
2143 bitmap[0] = bitmap[1] = 0;
2144 READ_BUF((bmlen << 2));
2145 if (bmlen > 0) {
2146 READ32(bitmap[0]);
2147 if (bmlen > 1)
2148 READ32(bitmap[1]);
2149 }
2150 return 0;
2151}
2152
Al Viro8687b632006-10-19 23:28:48 -07002153static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154{
Al Viro8687b632006-10-19 23:28:48 -07002155 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156
2157 READ_BUF(4);
2158 READ32(*attrlen);
2159 *savep = xdr->p;
2160 return 0;
2161}
2162
2163static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2164{
2165 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2166 decode_attr_bitmap(xdr, bitmask);
2167 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2168 } else
2169 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002170 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 return 0;
2172}
2173
2174static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2175{
Al Viro8687b632006-10-19 23:28:48 -07002176 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002177 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
2179 *type = 0;
2180 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2181 return -EIO;
2182 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2183 READ_BUF(4);
2184 READ32(*type);
2185 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002186 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 return -EIO;
2188 }
2189 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002190 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002192 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002193 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194}
2195
2196static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2197{
Al Viro8687b632006-10-19 23:28:48 -07002198 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002199 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
2201 *change = 0;
2202 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2203 return -EIO;
2204 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2205 READ_BUF(8);
2206 READ64(*change);
2207 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002208 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002210 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002212 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213}
2214
2215static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2216{
Al Viro8687b632006-10-19 23:28:48 -07002217 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002218 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219
2220 *size = 0;
2221 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2222 return -EIO;
2223 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2224 READ_BUF(8);
2225 READ64(*size);
2226 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002227 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002229 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002230 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231}
2232
2233static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2234{
Al Viro8687b632006-10-19 23:28:48 -07002235 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
2237 *res = 0;
2238 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2239 return -EIO;
2240 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2241 READ_BUF(4);
2242 READ32(*res);
2243 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2244 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002245 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 return 0;
2247}
2248
2249static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2250{
Al Viro8687b632006-10-19 23:28:48 -07002251 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252
2253 *res = 0;
2254 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2255 return -EIO;
2256 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2257 READ_BUF(4);
2258 READ32(*res);
2259 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2260 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002261 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 return 0;
2263}
2264
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002265static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266{
Al Viro8687b632006-10-19 23:28:48 -07002267 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002268 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269
2270 fsid->major = 0;
2271 fsid->minor = 0;
2272 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2273 return -EIO;
2274 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2275 READ_BUF(16);
2276 READ64(fsid->major);
2277 READ64(fsid->minor);
2278 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002279 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002281 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 (unsigned long long)fsid->major,
2283 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002284 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285}
2286
2287static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2288{
Al Viro8687b632006-10-19 23:28:48 -07002289 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290
2291 *res = 60;
2292 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2293 return -EIO;
2294 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2295 READ_BUF(4);
2296 READ32(*res);
2297 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2298 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002299 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 return 0;
2301}
2302
2303static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2304{
Al Viro8687b632006-10-19 23:28:48 -07002305 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306
2307 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2308 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2309 return -EIO;
2310 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2311 READ_BUF(4);
2312 READ32(*res);
2313 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2314 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002315 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 return 0;
2317}
2318
2319static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2320{
Al Viro8687b632006-10-19 23:28:48 -07002321 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002322 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323
2324 *fileid = 0;
2325 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2326 return -EIO;
2327 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2328 READ_BUF(8);
2329 READ64(*fileid);
2330 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002331 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002333 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002334 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335}
2336
Manoj Naik99baf622006-06-09 09:34:24 -04002337static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2338{
Al Viro8687b632006-10-19 23:28:48 -07002339 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002340 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002341
2342 *fileid = 0;
2343 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2344 return -EIO;
2345 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2346 READ_BUF(8);
2347 READ64(*fileid);
2348 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002349 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002350 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002351 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002352 return ret;
Manoj Naik99baf622006-06-09 09:34:24 -04002353}
2354
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2356{
Al Viro8687b632006-10-19 23:28:48 -07002357 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 int status = 0;
2359
2360 *res = 0;
2361 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2362 return -EIO;
2363 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2364 READ_BUF(8);
2365 READ64(*res);
2366 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2367 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002368 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 return status;
2370}
2371
2372static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2373{
Al Viro8687b632006-10-19 23:28:48 -07002374 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 int status = 0;
2376
2377 *res = 0;
2378 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2379 return -EIO;
2380 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2381 READ_BUF(8);
2382 READ64(*res);
2383 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2384 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002385 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 return status;
2387}
2388
2389static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2390{
Al Viro8687b632006-10-19 23:28:48 -07002391 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 int status = 0;
2393
2394 *res = 0;
2395 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2396 return -EIO;
2397 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2398 READ_BUF(8);
2399 READ64(*res);
2400 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2401 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002402 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 return status;
2404}
2405
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002406static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2407{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002408 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002409 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002410 int status = 0;
2411
2412 READ_BUF(4);
2413 READ32(n);
Andy Adamson33a43f22006-06-09 09:34:30 -04002414 if (n == 0)
2415 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002416 dprintk("path ");
2417 path->ncomponents = 0;
2418 while (path->ncomponents < n) {
2419 struct nfs4_string *component = &path->components[path->ncomponents];
2420 status = decode_opaque_inline(xdr, &component->len, &component->data);
2421 if (unlikely(status != 0))
2422 goto out_eio;
2423 if (path->ncomponents != n)
2424 dprintk("/");
2425 dprintk("%s", component->data);
2426 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2427 path->ncomponents++;
2428 else {
2429 dprintk("cannot parse %d components in path\n", n);
2430 goto out_eio;
2431 }
2432 }
2433out:
2434 dprintk("\n");
2435 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002436root_path:
2437/* a root pathname is sent as a zero component4 */
2438 path->ncomponents = 1;
2439 path->components[0].len=0;
2440 path->components[0].data=NULL;
2441 dprintk("path /\n");
2442 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002443out_eio:
2444 dprintk(" status %d", status);
2445 status = -EIO;
2446 goto out;
2447}
2448
2449static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002450{
2451 int n;
Al Viro8687b632006-10-19 23:28:48 -07002452 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002453 int status = -EIO;
2454
2455 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2456 goto out;
2457 status = 0;
2458 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2459 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002460 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002461 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002462 if (unlikely(status != 0))
2463 goto out;
2464 READ_BUF(4);
2465 READ32(n);
2466 if (n <= 0)
2467 goto out_eio;
2468 res->nlocations = 0;
2469 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002470 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002471 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04002472
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002473 READ_BUF(4);
2474 READ32(m);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002475
2476 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002477 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002478 while (loc->nservers < m) {
2479 struct nfs4_string *server = &loc->servers[loc->nservers];
2480 status = decode_opaque_inline(xdr, &server->len, &server->data);
2481 if (unlikely(status != 0))
2482 goto out_eio;
2483 dprintk("%s ", server->data);
2484 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2485 loc->nservers++;
2486 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002487 unsigned int i;
2488 dprintk("%s: using first %u of %u servers "
2489 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002490 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04002491 NFS4_FS_LOCATION_MAXSERVERS,
2492 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002493 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002494 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002495 char *data;
2496 status = decode_opaque_inline(xdr, &len, &data);
2497 if (unlikely(status != 0))
2498 goto out_eio;
2499 }
2500 }
2501 }
2502 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002503 if (unlikely(status != 0))
2504 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002505 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002506 res->nlocations++;
2507 }
Trond Myklebust409924e2009-03-11 14:10:27 -04002508 if (res->nlocations != 0)
2509 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002510out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002511 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002512 return status;
2513out_eio:
2514 status = -EIO;
2515 goto out;
2516}
2517
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2519{
Al Viro8687b632006-10-19 23:28:48 -07002520 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 int status = 0;
2522
2523 *res = 0;
2524 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2525 return -EIO;
2526 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2527 READ_BUF(8);
2528 READ64(*res);
2529 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2530 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002531 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 return status;
2533}
2534
2535static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2536{
Al Viro8687b632006-10-19 23:28:48 -07002537 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 int status = 0;
2539
2540 *maxlink = 1;
2541 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2542 return -EIO;
2543 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2544 READ_BUF(4);
2545 READ32(*maxlink);
2546 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2547 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002548 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 return status;
2550}
2551
2552static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2553{
Al Viro8687b632006-10-19 23:28:48 -07002554 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 int status = 0;
2556
2557 *maxname = 1024;
2558 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2559 return -EIO;
2560 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2561 READ_BUF(4);
2562 READ32(*maxname);
2563 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2564 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002565 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 return status;
2567}
2568
2569static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2570{
Al Viro8687b632006-10-19 23:28:48 -07002571 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 int status = 0;
2573
2574 *res = 1024;
2575 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2576 return -EIO;
2577 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2578 uint64_t maxread;
2579 READ_BUF(8);
2580 READ64(maxread);
2581 if (maxread > 0x7FFFFFFF)
2582 maxread = 0x7FFFFFFF;
2583 *res = (uint32_t)maxread;
2584 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2585 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002586 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 return status;
2588}
2589
2590static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2591{
Al Viro8687b632006-10-19 23:28:48 -07002592 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 int status = 0;
2594
2595 *res = 1024;
2596 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2597 return -EIO;
2598 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2599 uint64_t maxwrite;
2600 READ_BUF(8);
2601 READ64(maxwrite);
2602 if (maxwrite > 0x7FFFFFFF)
2603 maxwrite = 0x7FFFFFFF;
2604 *res = (uint32_t)maxwrite;
2605 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2606 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002607 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 return status;
2609}
2610
Trond Myklebustbca79472009-03-11 14:10:26 -04002611static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612{
Trond Myklebustbca79472009-03-11 14:10:26 -04002613 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07002614 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002615 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616
2617 *mode = 0;
2618 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2619 return -EIO;
2620 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2621 READ_BUF(4);
Trond Myklebustbca79472009-03-11 14:10:26 -04002622 READ32(tmp);
2623 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002625 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002627 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04002628 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629}
2630
2631static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2632{
Al Viro8687b632006-10-19 23:28:48 -07002633 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002634 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
2636 *nlink = 1;
2637 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2638 return -EIO;
2639 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2640 READ_BUF(4);
2641 READ32(*nlink);
2642 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04002643 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002645 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04002646 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647}
2648
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002649static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650{
Al Viro8687b632006-10-19 23:28:48 -07002651 uint32_t len;
2652 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002653 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
2655 *uid = -2;
2656 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2657 return -EIO;
2658 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2659 READ_BUF(4);
2660 READ32(len);
2661 READ_BUF(len);
2662 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04002663 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
2664 ret = NFS_ATTR_FATTR_OWNER;
2665 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002667 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04002669 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002670 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2672 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002673 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002674 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675}
2676
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002677static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678{
Al Viro8687b632006-10-19 23:28:48 -07002679 uint32_t len;
2680 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002681 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
2683 *gid = -2;
2684 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2685 return -EIO;
2686 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2687 READ_BUF(4);
2688 READ32(len);
2689 READ_BUF(len);
2690 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04002691 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
2692 ret = NFS_ATTR_FATTR_GROUP;
2693 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002695 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04002697 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002698 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2700 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002701 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002702 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703}
2704
2705static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2706{
Al Viro8687b632006-10-19 23:28:48 -07002707 uint32_t major = 0, minor = 0;
2708 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002709 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710
2711 *rdev = MKDEV(0,0);
2712 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2713 return -EIO;
2714 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2715 dev_t tmp;
2716
2717 READ_BUF(8);
2718 READ32(major);
2719 READ32(minor);
2720 tmp = MKDEV(major, minor);
2721 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2722 *rdev = tmp;
2723 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04002724 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002726 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002727 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728}
2729
2730static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2731{
Al Viro8687b632006-10-19 23:28:48 -07002732 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 int status = 0;
2734
2735 *res = 0;
2736 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2737 return -EIO;
2738 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2739 READ_BUF(8);
2740 READ64(*res);
2741 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2742 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002743 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 return status;
2745}
2746
2747static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2748{
Al Viro8687b632006-10-19 23:28:48 -07002749 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 int status = 0;
2751
2752 *res = 0;
2753 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2754 return -EIO;
2755 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2756 READ_BUF(8);
2757 READ64(*res);
2758 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2759 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002760 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 return status;
2762}
2763
2764static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2765{
Al Viro8687b632006-10-19 23:28:48 -07002766 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 int status = 0;
2768
2769 *res = 0;
2770 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2771 return -EIO;
2772 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2773 READ_BUF(8);
2774 READ64(*res);
2775 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2776 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002777 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 return status;
2779}
2780
2781static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2782{
Al Viro8687b632006-10-19 23:28:48 -07002783 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002784 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785
2786 *used = 0;
2787 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2788 return -EIO;
2789 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2790 READ_BUF(8);
2791 READ64(*used);
2792 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04002793 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002795 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04002797 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798}
2799
2800static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2801{
Al Viro8687b632006-10-19 23:28:48 -07002802 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 uint64_t sec;
2804 uint32_t nsec;
2805
2806 READ_BUF(12);
2807 READ64(sec);
2808 READ32(nsec);
2809 time->tv_sec = (time_t)sec;
2810 time->tv_nsec = (long)nsec;
2811 return 0;
2812}
2813
2814static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2815{
2816 int status = 0;
2817
2818 time->tv_sec = 0;
2819 time->tv_nsec = 0;
2820 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2821 return -EIO;
2822 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2823 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04002824 if (status == 0)
2825 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2827 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002828 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 return status;
2830}
2831
2832static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2833{
2834 int status = 0;
2835
2836 time->tv_sec = 0;
2837 time->tv_nsec = 0;
2838 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2839 return -EIO;
2840 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2841 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04002842 if (status == 0)
2843 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2845 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002846 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 return status;
2848}
2849
2850static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2851{
2852 int status = 0;
2853
2854 time->tv_sec = 0;
2855 time->tv_nsec = 0;
2856 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2857 return -EIO;
2858 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2859 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04002860 if (status == 0)
2861 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2863 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002864 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 return status;
2866}
2867
Al Viro8687b632006-10-19 23:28:48 -07002868static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869{
2870 unsigned int attrwords = XDR_QUADLEN(attrlen);
2871 unsigned int nwords = xdr->p - savep;
2872
2873 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002874 dprintk("%s: server returned incorrect attribute length: "
2875 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002876 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 attrwords << 2,
2878 (attrwords < nwords) ? '<' : '>',
2879 nwords << 2);
2880 return -EIO;
2881 }
2882 return 0;
2883}
2884
2885static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2886{
Al Viro8687b632006-10-19 23:28:48 -07002887 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888
2889 READ_BUF(20);
2890 READ32(cinfo->atomic);
2891 READ64(cinfo->before);
2892 READ64(cinfo->after);
2893 return 0;
2894}
2895
2896static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2897{
Al Viro8687b632006-10-19 23:28:48 -07002898 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 uint32_t supp, acc;
2900 int status;
2901
2902 status = decode_op_hdr(xdr, OP_ACCESS);
2903 if (status)
2904 return status;
2905 READ_BUF(8);
2906 READ32(supp);
2907 READ32(acc);
2908 access->supported = supp;
2909 access->access = acc;
2910 return 0;
2911}
2912
2913static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2914{
Al Viro8687b632006-10-19 23:28:48 -07002915 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 int status;
2917
2918 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04002919 if (status != -EIO)
2920 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 if (status)
2922 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04002923 READ_BUF(NFS4_STATEID_SIZE);
2924 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 return 0;
2926}
2927
2928static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2929{
Al Viro8687b632006-10-19 23:28:48 -07002930 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 int status;
2932
2933 status = decode_op_hdr(xdr, OP_COMMIT);
2934 if (status)
2935 return status;
2936 READ_BUF(8);
2937 COPYMEM(res->verf->verifier, 8);
2938 return 0;
2939}
2940
2941static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2942{
Al Viro8687b632006-10-19 23:28:48 -07002943 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 uint32_t bmlen;
2945 int status;
2946
2947 status = decode_op_hdr(xdr, OP_CREATE);
2948 if (status)
2949 return status;
2950 if ((status = decode_change_info(xdr, cinfo)))
2951 return status;
2952 READ_BUF(4);
2953 READ32(bmlen);
2954 READ_BUF(bmlen << 2);
2955 return 0;
2956}
2957
2958static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2959{
Al Viro8687b632006-10-19 23:28:48 -07002960 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002961 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 int status;
2963
2964 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2965 goto xdr_error;
2966 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2967 goto xdr_error;
2968 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2969 goto xdr_error;
2970 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2971 goto xdr_error;
2972 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2973 goto xdr_error;
2974 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2975 goto xdr_error;
2976 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2977 goto xdr_error;
2978 status = verify_attr_len(xdr, savep, attrlen);
2979xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002980 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 return status;
2982}
Andy Adamson6c0195a2008-12-23 16:06:15 -05002983
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2985{
Al Viro8687b632006-10-19 23:28:48 -07002986 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002987 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002989
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2991 goto xdr_error;
2992 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2993 goto xdr_error;
2994 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2995 goto xdr_error;
2996
2997 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2998 goto xdr_error;
2999 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3000 goto xdr_error;
3001 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3002 goto xdr_error;
3003 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3004 goto xdr_error;
3005 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3006 goto xdr_error;
3007 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3008 goto xdr_error;
3009
3010 status = verify_attr_len(xdr, savep, attrlen);
3011xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003012 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 return status;
3014}
3015
3016static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3017{
Al Viro8687b632006-10-19 23:28:48 -07003018 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003019 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003021
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3023 goto xdr_error;
3024 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3025 goto xdr_error;
3026 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3027 goto xdr_error;
3028
3029 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3030 goto xdr_error;
3031 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3032 goto xdr_error;
3033
3034 status = verify_attr_len(xdr, savep, attrlen);
3035xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003036 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 return status;
3038}
3039
3040static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3041{
Al Viro8687b632006-10-19 23:28:48 -07003042 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 uint32_t attrlen,
3044 bitmap[2] = {0},
3045 type;
Trond Myklebustbca79472009-03-11 14:10:26 -04003046 int status;
3047 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003048 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003050 status = decode_op_hdr(xdr, OP_GETATTR);
3051 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 goto xdr_error;
3053
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003054 status = decode_attr_bitmap(xdr, bitmap);
3055 if (status < 0)
3056 goto xdr_error;
3057
3058 status = decode_attr_length(xdr, &attrlen, &savep);
3059 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 goto xdr_error;
3061
3062
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003063 status = decode_attr_type(xdr, bitmap, &type);
3064 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003066 fattr->mode = 0;
3067 if (status != 0) {
3068 fattr->mode |= nfs_type2fmt[type];
3069 fattr->valid |= status;
3070 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003072 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3073 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003075 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003076
3077 status = decode_attr_size(xdr, bitmap, &fattr->size);
3078 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003080 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003081
3082 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3083 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003085 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003086
3087 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3088 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003090 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003091
3092 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003093 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003094 fattr));
3095 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003096 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003097 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003098
3099 status = decode_attr_mode(xdr, bitmap, &fmode);
3100 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003102 if (status != 0) {
3103 fattr->mode |= fmode;
3104 fattr->valid |= status;
3105 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003106
3107 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3108 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003110 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003111
3112 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
3113 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003115 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003116
3117 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
3118 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003120 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003121
3122 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3123 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003125 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003126
3127 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3128 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003130 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003131
3132 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3133 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003135 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003136
3137 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3138 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003140 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003141
3142 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3143 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003145 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003146
3147 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3148 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003149 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003150 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003151 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003152 fattr->valid |= status;
3153 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003154
3155 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003157 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 return status;
3159}
3160
3161
3162static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3163{
Al Viro8687b632006-10-19 23:28:48 -07003164 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 uint32_t attrlen, bitmap[2];
3166 int status;
3167
3168 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3169 goto xdr_error;
3170 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3171 goto xdr_error;
3172 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3173 goto xdr_error;
3174
3175 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3176
3177 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3178 goto xdr_error;
3179 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3180 goto xdr_error;
3181 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3182 goto xdr_error;
3183 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3184 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3185 goto xdr_error;
3186 fsinfo->wtpref = fsinfo->wtmax;
3187
3188 status = verify_attr_len(xdr, savep, attrlen);
3189xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003190 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 return status;
3192}
3193
3194static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3195{
Al Viro8687b632006-10-19 23:28:48 -07003196 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 uint32_t len;
3198 int status;
3199
Trond Myklebust99367812007-07-17 21:52:41 -04003200 /* Zero handle first to allow comparisons */
3201 memset(fh, 0, sizeof(*fh));
3202
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 status = decode_op_hdr(xdr, OP_GETFH);
3204 if (status)
3205 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206
3207 READ_BUF(4);
3208 READ32(len);
3209 if (len > NFS4_FHSIZE)
3210 return -EIO;
3211 fh->size = len;
3212 READ_BUF(len);
3213 COPYMEM(fh->data, len);
3214 return 0;
3215}
3216
3217static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3218{
3219 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003220
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 status = decode_op_hdr(xdr, OP_LINK);
3222 if (status)
3223 return status;
3224 return decode_change_info(xdr, cinfo);
3225}
3226
3227/*
3228 * We create the owner, so we know a proper owner.id length is 4.
3229 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003230static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003232 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003233 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003234 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235
3236 READ_BUF(32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003237 READ64(offset);
3238 READ64(length);
3239 READ32(type);
3240 if (fl != NULL) {
3241 fl->fl_start = (loff_t)offset;
3242 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3243 if (length == ~(uint64_t)0)
3244 fl->fl_end = OFFSET_MAX;
3245 fl->fl_type = F_WRLCK;
3246 if (type & 1)
3247 fl->fl_type = F_RDLCK;
3248 fl->fl_pid = 0;
3249 }
3250 READ64(clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 READ32(namelen);
3252 READ_BUF(namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 return -NFS4ERR_DENIED;
3254}
3255
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003256static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257{
Al Viro8687b632006-10-19 23:28:48 -07003258 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 int status;
3260
3261 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003262 if (status == -EIO)
3263 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003265 READ_BUF(NFS4_STATEID_SIZE);
3266 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003268 status = decode_lock_denied(xdr, NULL);
3269 if (res->open_seqid != NULL)
3270 nfs_increment_open_seqid(status, res->open_seqid);
3271 nfs_increment_lock_seqid(status, res->lock_seqid);
3272out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 return status;
3274}
3275
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003276static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277{
3278 int status;
3279 status = decode_op_hdr(xdr, OP_LOCKT);
3280 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003281 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 return status;
3283}
3284
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003285static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286{
Al Viro8687b632006-10-19 23:28:48 -07003287 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 int status;
3289
3290 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003291 if (status != -EIO)
3292 nfs_increment_lock_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003294 READ_BUF(NFS4_STATEID_SIZE);
3295 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 }
3297 return status;
3298}
3299
3300static int decode_lookup(struct xdr_stream *xdr)
3301{
3302 return decode_op_hdr(xdr, OP_LOOKUP);
3303}
3304
3305/* This is too sick! */
3306static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3307{
Andy Adamson05d564f2008-12-23 16:06:15 -05003308 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 uint32_t limit_type, nblocks, blocksize;
3310
3311 READ_BUF(12);
3312 READ32(limit_type);
3313 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003314 case 1:
3315 READ64(*maxsize);
3316 break;
3317 case 2:
3318 READ32(nblocks);
3319 READ32(blocksize);
3320 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 }
3322 return 0;
3323}
3324
3325static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3326{
Andy Adamson05d564f2008-12-23 16:06:15 -05003327 __be32 *p;
3328 uint32_t delegation_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329
3330 READ_BUF(4);
3331 READ32(delegation_type);
3332 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3333 res->delegation_type = 0;
3334 return 0;
3335 }
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003336 READ_BUF(NFS4_STATEID_SIZE+4);
3337 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 READ32(res->do_recall);
Andy Adamson05d564f2008-12-23 16:06:15 -05003339
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003341 case NFS4_OPEN_DELEGATE_READ:
3342 res->delegation_type = FMODE_READ;
3343 break;
3344 case NFS4_OPEN_DELEGATE_WRITE:
3345 res->delegation_type = FMODE_WRITE|FMODE_READ;
3346 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347 return -EIO;
3348 }
David Howells7539bba2006-08-22 20:06:09 -04003349 return decode_ace(xdr, NULL, res->server->nfs_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350}
3351
3352static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3353{
Andy Adamson05d564f2008-12-23 16:06:15 -05003354 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003355 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05003356 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357
Andy Adamson05d564f2008-12-23 16:06:15 -05003358 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003359 if (status != -EIO)
3360 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003361 if (status)
3362 return status;
3363 READ_BUF(NFS4_STATEID_SIZE);
3364 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365
Andy Adamson05d564f2008-12-23 16:06:15 -05003366 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367
Andy Adamson05d564f2008-12-23 16:06:15 -05003368 READ_BUF(8);
3369 READ32(res->rflags);
3370 READ32(bmlen);
3371 if (bmlen > 10)
3372 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373
Andy Adamson05d564f2008-12-23 16:06:15 -05003374 READ_BUF(bmlen << 2);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003375 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3376 for (i = 0; i < savewords; ++i)
3377 READ32(res->attrset[i]);
3378 for (; i < NFS4_BITMAP_SIZE; i++)
3379 res->attrset[i] = 0;
3380
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 return decode_delegation(xdr, res);
3382xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003383 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 return -EIO;
3385}
3386
3387static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3388{
Andy Adamson05d564f2008-12-23 16:06:15 -05003389 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 int status;
3391
Andy Adamson05d564f2008-12-23 16:06:15 -05003392 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003393 if (status != -EIO)
3394 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003395 if (status)
3396 return status;
3397 READ_BUF(NFS4_STATEID_SIZE);
3398 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3399 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400}
3401
3402static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3403{
Al Viro8687b632006-10-19 23:28:48 -07003404 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405 int status;
3406
3407 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003408 if (status != -EIO)
3409 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 if (status)
3411 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003412 READ_BUF(NFS4_STATEID_SIZE);
3413 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 return 0;
3415}
3416
3417static int decode_putfh(struct xdr_stream *xdr)
3418{
3419 return decode_op_hdr(xdr, OP_PUTFH);
3420}
3421
3422static int decode_putrootfh(struct xdr_stream *xdr)
3423{
3424 return decode_op_hdr(xdr, OP_PUTROOTFH);
3425}
3426
3427static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3428{
3429 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07003430 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 uint32_t count, eof, recvd, hdrlen;
3432 int status;
3433
3434 status = decode_op_hdr(xdr, OP_READ);
3435 if (status)
3436 return status;
3437 READ_BUF(8);
3438 READ32(eof);
3439 READ32(count);
3440 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3441 recvd = req->rq_rcv_buf.len - hdrlen;
3442 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003443 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 "count %u > recvd %u\n", count, recvd);
3445 count = recvd;
3446 eof = 0;
3447 }
3448 xdr_read_pages(xdr, count);
3449 res->eof = eof;
3450 res->count = count;
3451 return 0;
3452}
3453
3454static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3455{
3456 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3457 struct page *page = *rcvbuf->pages;
3458 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003459 size_t hdrlen;
3460 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07003461 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003462 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04003463 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464
3465 status = decode_op_hdr(xdr, OP_READDIR);
3466 if (status)
3467 return status;
3468 READ_BUF(8);
3469 COPYMEM(readdir->verifier.data, 8);
Fred Isaman44109242008-04-02 15:21:15 +03003470 dprintk("%s: verifier = %08x:%08x\n",
3471 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00003472 ((u32 *)readdir->verifier.data)[0],
3473 ((u32 *)readdir->verifier.data)[1]);
3474
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475
3476 hdrlen = (char *) p - (char *) iov->iov_base;
3477 recvd = rcvbuf->len - hdrlen;
3478 if (pglen > recvd)
3479 pglen = recvd;
3480 xdr_read_pages(xdr, pglen);
3481
3482 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07003483 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04003484 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003486
3487 /* Make sure the packet actually has a value_follows and EOF entry */
3488 if ((entry + 1) > end)
3489 goto short_pkt;
3490
3491 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003492 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04003493 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003495 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496 p += 2; /* cookie */
3497 len = ntohl(*p++); /* filename length */
3498 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003499 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3500 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 goto err_unmap;
3502 }
David Howellse8896492006-08-24 15:44:19 -04003503 xlen = XDR_QUADLEN(len);
3504 if (end - p < xlen + 1)
3505 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003506 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04003507 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04003509 if (end - p < len + 1)
3510 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04003513 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04003515 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 entry = p;
3517 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003518 /*
3519 * Apparently some server sends responses that are a valid size, but
3520 * contain no entries, and have value_follows==0 and EOF==0. For
3521 * those, just set the EOF marker.
3522 */
3523 if (!nr && entry[1] == 0) {
3524 dprintk("NFS: readdir reply truncated!\n");
3525 entry[1] = 1;
3526 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05003527out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 kunmap_atomic(kaddr, KM_USER0);
3529 return 0;
3530short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003531 /*
3532 * When we get a short packet there are 2 possibilities. We can
3533 * return an error, or fix up the response to look like a valid
3534 * response and return what we have so far. If there are no
3535 * entries and the packet was short, then return -EIO. If there
3536 * are valid entries in the response, return them and pretend that
3537 * the call was successful, but incomplete. The caller can retry the
3538 * readdir starting at the last cookie.
3539 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07003540 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003542 if (nr)
3543 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544err_unmap:
3545 kunmap_atomic(kaddr, KM_USER0);
3546 return -errno_NFSERR_IO;
3547}
3548
3549static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3550{
3551 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3552 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003553 size_t hdrlen;
3554 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07003555 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 char *kaddr;
3557 int status;
3558
3559 status = decode_op_hdr(xdr, OP_READLINK);
3560 if (status)
3561 return status;
3562
3563 /* Convert length of symlink */
3564 READ_BUF(4);
3565 READ32(len);
3566 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003567 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568 return -ENAMETOOLONG;
3569 }
3570 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3571 recvd = req->rq_rcv_buf.len - hdrlen;
3572 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003573 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 "count %u > recvd %u\n", len, recvd);
3575 return -EIO;
3576 }
3577 xdr_read_pages(xdr, len);
3578 /*
3579 * The XDR encode routine has set things up so that
3580 * the link text will be copied directly into the
3581 * buffer. We just have to do overflow-checking,
3582 * and and null-terminate the text (the VFS expects
3583 * null-termination).
3584 */
3585 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3586 kaddr[len+rcvbuf->page_base] = '\0';
3587 kunmap_atomic(kaddr, KM_USER0);
3588 return 0;
3589}
3590
3591static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3592{
3593 int status;
3594
3595 status = decode_op_hdr(xdr, OP_REMOVE);
3596 if (status)
3597 goto out;
3598 status = decode_change_info(xdr, cinfo);
3599out:
3600 return status;
3601}
3602
3603static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3604 struct nfs4_change_info *new_cinfo)
3605{
3606 int status;
3607
3608 status = decode_op_hdr(xdr, OP_RENAME);
3609 if (status)
3610 goto out;
3611 if ((status = decode_change_info(xdr, old_cinfo)))
3612 goto out;
3613 status = decode_change_info(xdr, new_cinfo);
3614out:
3615 return status;
3616}
3617
3618static int decode_renew(struct xdr_stream *xdr)
3619{
3620 return decode_op_hdr(xdr, OP_RENEW);
3621}
3622
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003623static int
3624decode_restorefh(struct xdr_stream *xdr)
3625{
3626 return decode_op_hdr(xdr, OP_RESTOREFH);
3627}
3628
J. Bruce Fields029d1052005-06-22 17:16:22 +00003629static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3630 size_t *acl_len)
3631{
Al Viro8687b632006-10-19 23:28:48 -07003632 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003633 uint32_t attrlen,
3634 bitmap[2] = {0};
3635 struct kvec *iov = req->rq_rcv_buf.head;
3636 int status;
3637
3638 *acl_len = 0;
3639 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3640 goto out;
3641 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3642 goto out;
3643 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3644 goto out;
3645
3646 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3647 return -EIO;
3648 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003649 size_t hdrlen;
3650 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003651
3652 /* We ignore &savep and don't do consistency checks on
3653 * the attr length. Let userspace figure it out.... */
3654 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3655 recvd = req->rq_rcv_buf.len - hdrlen;
3656 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003657 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00003658 " acl reply: attrlen %u > recvd %u\n",
3659 attrlen, recvd);
3660 return -EINVAL;
3661 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04003662 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00003663 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04003664 } else
3665 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003666
3667out:
3668 return status;
3669}
3670
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671static int
3672decode_savefh(struct xdr_stream *xdr)
3673{
3674 return decode_op_hdr(xdr, OP_SAVEFH);
3675}
3676
Benny Halevy9e9ecc02009-04-01 09:22:00 -04003677static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678{
Al Viro8687b632006-10-19 23:28:48 -07003679 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680 uint32_t bmlen;
3681 int status;
3682
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 status = decode_op_hdr(xdr, OP_SETATTR);
3684 if (status)
3685 return status;
3686 READ_BUF(4);
3687 READ32(bmlen);
3688 READ_BUF(bmlen << 2);
3689 return 0;
3690}
3691
David Howellsadfa6f92006-08-22 20:06:08 -04003692static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693{
Al Viro8687b632006-10-19 23:28:48 -07003694 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 uint32_t opnum;
3696 int32_t nfserr;
3697
3698 READ_BUF(8);
3699 READ32(opnum);
3700 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003701 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05003702 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703 return -EIO;
3704 }
3705 READ32(nfserr);
3706 if (nfserr == NFS_OK) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003707 READ_BUF(8 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 READ64(clp->cl_clientid);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003709 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 } else if (nfserr == NFSERR_CLID_INUSE) {
3711 uint32_t len;
3712
3713 /* skip netid string */
3714 READ_BUF(4);
3715 READ32(len);
3716 READ_BUF(len);
3717
3718 /* skip uaddr string */
3719 READ_BUF(4);
3720 READ32(len);
3721 READ_BUF(len);
3722 return -NFSERR_CLID_INUSE;
3723 } else
Benny Halevy856dff32008-03-31 17:39:06 +03003724 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725
3726 return 0;
3727}
3728
3729static int decode_setclientid_confirm(struct xdr_stream *xdr)
3730{
3731 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3732}
3733
3734static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3735{
Al Viro8687b632006-10-19 23:28:48 -07003736 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 int status;
3738
3739 status = decode_op_hdr(xdr, OP_WRITE);
3740 if (status)
3741 return status;
3742
3743 READ_BUF(16);
3744 READ32(res->count);
3745 READ32(res->verf->committed);
3746 COPYMEM(res->verf->verifier, 8);
3747 return 0;
3748}
3749
3750static int decode_delegreturn(struct xdr_stream *xdr)
3751{
3752 return decode_op_hdr(xdr, OP_DELEGRETURN);
3753}
3754
3755/*
Benny Halevy49c25592008-12-23 16:06:16 -05003756 * END OF "GENERIC" DECODE ROUTINES.
3757 */
3758
3759/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760 * Decode OPEN_DOWNGRADE response
3761 */
Al Viro8687b632006-10-19 23:28:48 -07003762static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763{
Andy Adamson05d564f2008-12-23 16:06:15 -05003764 struct xdr_stream xdr;
3765 struct compound_hdr hdr;
3766 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767
Andy Adamson05d564f2008-12-23 16:06:15 -05003768 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3769 status = decode_compound_hdr(&xdr, &hdr);
3770 if (status)
3771 goto out;
3772 status = decode_putfh(&xdr);
3773 if (status)
3774 goto out;
3775 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04003776 if (status != 0)
3777 goto out;
3778 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779out:
Andy Adamson05d564f2008-12-23 16:06:15 -05003780 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781}
3782
3783/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 * Decode ACCESS response
3785 */
Al Viro8687b632006-10-19 23:28:48 -07003786static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787{
3788 struct xdr_stream xdr;
3789 struct compound_hdr hdr;
3790 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003791
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3793 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3794 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04003795 status = decode_putfh(&xdr);
3796 if (status != 0)
3797 goto out;
3798 status = decode_access(&xdr, res);
3799 if (status != 0)
3800 goto out;
3801 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802out:
3803 return status;
3804}
3805
3806/*
3807 * Decode LOOKUP response
3808 */
Al Viro8687b632006-10-19 23:28:48 -07003809static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810{
3811 struct xdr_stream xdr;
3812 struct compound_hdr hdr;
3813 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003814
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3816 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3817 goto out;
3818 if ((status = decode_putfh(&xdr)) != 0)
3819 goto out;
3820 if ((status = decode_lookup(&xdr)) != 0)
3821 goto out;
3822 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3823 goto out;
3824 status = decode_getfattr(&xdr, res->fattr, res->server);
3825out:
3826 return status;
3827}
3828
3829/*
3830 * Decode LOOKUP_ROOT response
3831 */
Al Viro8687b632006-10-19 23:28:48 -07003832static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833{
3834 struct xdr_stream xdr;
3835 struct compound_hdr hdr;
3836 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003837
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3839 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3840 goto out;
3841 if ((status = decode_putrootfh(&xdr)) != 0)
3842 goto out;
3843 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3844 status = decode_getfattr(&xdr, res->fattr, res->server);
3845out:
3846 return status;
3847}
3848
3849/*
3850 * Decode REMOVE response
3851 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04003852static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853{
3854 struct xdr_stream xdr;
3855 struct compound_hdr hdr;
3856 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003857
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3859 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3860 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04003861 if ((status = decode_putfh(&xdr)) != 0)
3862 goto out;
3863 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3864 goto out;
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04003865 decode_getfattr(&xdr, &res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866out:
3867 return status;
3868}
3869
3870/*
3871 * Decode RENAME response
3872 */
Al Viro8687b632006-10-19 23:28:48 -07003873static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874{
3875 struct xdr_stream xdr;
3876 struct compound_hdr hdr;
3877 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003878
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3880 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3881 goto out;
3882 if ((status = decode_putfh(&xdr)) != 0)
3883 goto out;
3884 if ((status = decode_savefh(&xdr)) != 0)
3885 goto out;
3886 if ((status = decode_putfh(&xdr)) != 0)
3887 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04003888 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3889 goto out;
3890 /* Current FH is target directory */
3891 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3892 goto out;
3893 if ((status = decode_restorefh(&xdr)) != 0)
3894 goto out;
3895 decode_getfattr(&xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896out:
3897 return status;
3898}
3899
3900/*
3901 * Decode LINK response
3902 */
Al Viro8687b632006-10-19 23:28:48 -07003903static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904{
3905 struct xdr_stream xdr;
3906 struct compound_hdr hdr;
3907 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003908
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3910 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3911 goto out;
3912 if ((status = decode_putfh(&xdr)) != 0)
3913 goto out;
3914 if ((status = decode_savefh(&xdr)) != 0)
3915 goto out;
3916 if ((status = decode_putfh(&xdr)) != 0)
3917 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04003918 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3919 goto out;
3920 /*
3921 * Note order: OP_LINK leaves the directory as the current
3922 * filehandle.
3923 */
3924 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3925 goto out;
3926 if ((status = decode_restorefh(&xdr)) != 0)
3927 goto out;
3928 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929out:
3930 return status;
3931}
3932
3933/*
3934 * Decode CREATE response
3935 */
Al Viro8687b632006-10-19 23:28:48 -07003936static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937{
3938 struct xdr_stream xdr;
3939 struct compound_hdr hdr;
3940 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003941
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3943 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3944 goto out;
3945 if ((status = decode_putfh(&xdr)) != 0)
3946 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003947 if ((status = decode_savefh(&xdr)) != 0)
3948 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3950 goto out;
3951 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3952 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003953 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3954 goto out;
3955 if ((status = decode_restorefh(&xdr)) != 0)
3956 goto out;
3957 decode_getfattr(&xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958out:
3959 return status;
3960}
3961
3962/*
3963 * Decode SYMLINK response
3964 */
Al Viro8687b632006-10-19 23:28:48 -07003965static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966{
3967 return nfs4_xdr_dec_create(rqstp, p, res);
3968}
3969
3970/*
3971 * Decode GETATTR response
3972 */
Al Viro8687b632006-10-19 23:28:48 -07003973static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974{
3975 struct xdr_stream xdr;
3976 struct compound_hdr hdr;
3977 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003978
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3980 status = decode_compound_hdr(&xdr, &hdr);
3981 if (status)
3982 goto out;
3983 status = decode_putfh(&xdr);
3984 if (status)
3985 goto out;
3986 status = decode_getfattr(&xdr, res->fattr, res->server);
3987out:
3988 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989}
3990
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003991/*
3992 * Encode an SETACL request
3993 */
3994static int
Al Viro8687b632006-10-19 23:28:48 -07003995nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003996{
Andy Adamson05d564f2008-12-23 16:06:15 -05003997 struct xdr_stream xdr;
3998 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05003999 .nops = 0,
Andy Adamson05d564f2008-12-23 16:06:15 -05004000 };
4001 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004002
Andy Adamson05d564f2008-12-23 16:06:15 -05004003 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Benny Halevy0c4e8c12009-04-01 09:22:07 -04004004 encode_compound_hdr(&xdr, req, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05004005 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004006 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05004007 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004008 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004009}
Andy Adamson05d564f2008-12-23 16:06:15 -05004010
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004011/*
4012 * Decode SETACL response
4013 */
4014static int
Benny Halevy73c403a2009-04-01 09:22:01 -04004015nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4016 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004017{
4018 struct xdr_stream xdr;
4019 struct compound_hdr hdr;
4020 int status;
4021
4022 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4023 status = decode_compound_hdr(&xdr, &hdr);
4024 if (status)
4025 goto out;
4026 status = decode_putfh(&xdr);
4027 if (status)
4028 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004029 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004030out:
4031 return status;
4032}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033
4034/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00004035 * Decode GETACL response
4036 */
4037static int
Benny Halevy663c79b2009-04-01 09:21:59 -04004038nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4039 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004040{
4041 struct xdr_stream xdr;
4042 struct compound_hdr hdr;
4043 int status;
4044
4045 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4046 status = decode_compound_hdr(&xdr, &hdr);
4047 if (status)
4048 goto out;
4049 status = decode_putfh(&xdr);
4050 if (status)
4051 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04004052 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004053
4054out:
4055 return status;
4056}
4057
4058/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059 * Decode CLOSE response
4060 */
Al Viro8687b632006-10-19 23:28:48 -07004061static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062{
Andy Adamson05d564f2008-12-23 16:06:15 -05004063 struct xdr_stream xdr;
4064 struct compound_hdr hdr;
4065 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066
Andy Adamson05d564f2008-12-23 16:06:15 -05004067 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4068 status = decode_compound_hdr(&xdr, &hdr);
4069 if (status)
4070 goto out;
4071 status = decode_putfh(&xdr);
4072 if (status)
4073 goto out;
4074 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004075 if (status != 0)
4076 goto out;
4077 /*
4078 * Note: Server may do delete on close for this file
4079 * in which case the getattr call will fail with
4080 * an ESTALE error. Shouldn't be a problem,
4081 * though, since fattr->valid will remain unset.
4082 */
4083 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004085 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086}
4087
4088/*
4089 * Decode OPEN response
4090 */
Al Viro8687b632006-10-19 23:28:48 -07004091static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092{
Andy Adamson05d564f2008-12-23 16:06:15 -05004093 struct xdr_stream xdr;
4094 struct compound_hdr hdr;
4095 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096
Andy Adamson05d564f2008-12-23 16:06:15 -05004097 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4098 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004099 if (status)
4100 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004101 status = decode_putfh(&xdr);
4102 if (status)
4103 goto out;
4104 status = decode_savefh(&xdr);
4105 if (status)
4106 goto out;
4107 status = decode_open(&xdr, res);
4108 if (status)
4109 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04004110 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004112 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4113 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04004114 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004115 goto out;
4116 decode_getfattr(&xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004118 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119}
4120
4121/*
4122 * Decode OPEN_CONFIRM response
4123 */
Al Viro8687b632006-10-19 23:28:48 -07004124static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125{
Andy Adamson05d564f2008-12-23 16:06:15 -05004126 struct xdr_stream xdr;
4127 struct compound_hdr hdr;
4128 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129
Andy Adamson05d564f2008-12-23 16:06:15 -05004130 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4131 status = decode_compound_hdr(&xdr, &hdr);
4132 if (status)
4133 goto out;
4134 status = decode_putfh(&xdr);
4135 if (status)
4136 goto out;
4137 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004139 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140}
4141
4142/*
4143 * Decode OPEN response
4144 */
Al Viro8687b632006-10-19 23:28:48 -07004145static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146{
Andy Adamson05d564f2008-12-23 16:06:15 -05004147 struct xdr_stream xdr;
4148 struct compound_hdr hdr;
4149 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150
Andy Adamson05d564f2008-12-23 16:06:15 -05004151 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4152 status = decode_compound_hdr(&xdr, &hdr);
4153 if (status)
4154 goto out;
4155 status = decode_putfh(&xdr);
4156 if (status)
4157 goto out;
4158 status = decode_open(&xdr, res);
4159 if (status)
4160 goto out;
Trond Myklebust864472e2006-01-03 09:55:15 +01004161 decode_getfattr(&xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004163 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164}
4165
4166/*
4167 * Decode SETATTR response
4168 */
Al Viro8687b632006-10-19 23:28:48 -07004169static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170{
Andy Adamson05d564f2008-12-23 16:06:15 -05004171 struct xdr_stream xdr;
4172 struct compound_hdr hdr;
4173 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174
Andy Adamson05d564f2008-12-23 16:06:15 -05004175 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4176 status = decode_compound_hdr(&xdr, &hdr);
4177 if (status)
4178 goto out;
4179 status = decode_putfh(&xdr);
4180 if (status)
4181 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004182 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004183 if (status)
4184 goto out;
Trond Myklebust78f945f2009-03-11 14:10:23 -04004185 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004187 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188}
4189
4190/*
4191 * Decode LOCK response
4192 */
Al Viro8687b632006-10-19 23:28:48 -07004193static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194{
4195 struct xdr_stream xdr;
4196 struct compound_hdr hdr;
4197 int status;
4198
4199 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4200 status = decode_compound_hdr(&xdr, &hdr);
4201 if (status)
4202 goto out;
4203 status = decode_putfh(&xdr);
4204 if (status)
4205 goto out;
4206 status = decode_lock(&xdr, res);
4207out:
4208 return status;
4209}
4210
4211/*
4212 * Decode LOCKT response
4213 */
Al Viro8687b632006-10-19 23:28:48 -07004214static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215{
4216 struct xdr_stream xdr;
4217 struct compound_hdr hdr;
4218 int status;
4219
4220 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4221 status = decode_compound_hdr(&xdr, &hdr);
4222 if (status)
4223 goto out;
4224 status = decode_putfh(&xdr);
4225 if (status)
4226 goto out;
4227 status = decode_lockt(&xdr, res);
4228out:
4229 return status;
4230}
4231
4232/*
4233 * Decode LOCKU response
4234 */
Al Viro8687b632006-10-19 23:28:48 -07004235static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004236{
4237 struct xdr_stream xdr;
4238 struct compound_hdr hdr;
4239 int status;
4240
4241 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4242 status = decode_compound_hdr(&xdr, &hdr);
4243 if (status)
4244 goto out;
4245 status = decode_putfh(&xdr);
4246 if (status)
4247 goto out;
4248 status = decode_locku(&xdr, res);
4249out:
4250 return status;
4251}
4252
4253/*
4254 * Decode READLINK response
4255 */
Benny Halevyf50c7002009-04-01 09:21:55 -04004256static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4257 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258{
4259 struct xdr_stream xdr;
4260 struct compound_hdr hdr;
4261 int status;
4262
4263 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4264 status = decode_compound_hdr(&xdr, &hdr);
4265 if (status)
4266 goto out;
4267 status = decode_putfh(&xdr);
4268 if (status)
4269 goto out;
4270 status = decode_readlink(&xdr, rqstp);
4271out:
4272 return status;
4273}
4274
4275/*
4276 * Decode READDIR response
4277 */
Al Viro8687b632006-10-19 23:28:48 -07004278static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279{
4280 struct xdr_stream xdr;
4281 struct compound_hdr hdr;
4282 int status;
4283
4284 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4285 status = decode_compound_hdr(&xdr, &hdr);
4286 if (status)
4287 goto out;
4288 status = decode_putfh(&xdr);
4289 if (status)
4290 goto out;
4291 status = decode_readdir(&xdr, rqstp, res);
4292out:
4293 return status;
4294}
4295
4296/*
4297 * Decode Read response
4298 */
Al Viro8687b632006-10-19 23:28:48 -07004299static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300{
4301 struct xdr_stream xdr;
4302 struct compound_hdr hdr;
4303 int status;
4304
4305 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4306 status = decode_compound_hdr(&xdr, &hdr);
4307 if (status)
4308 goto out;
4309 status = decode_putfh(&xdr);
4310 if (status)
4311 goto out;
4312 status = decode_read(&xdr, rqstp, res);
4313 if (!status)
4314 status = res->count;
4315out:
4316 return status;
4317}
4318
4319/*
4320 * Decode WRITE response
4321 */
Al Viro8687b632006-10-19 23:28:48 -07004322static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323{
4324 struct xdr_stream xdr;
4325 struct compound_hdr hdr;
4326 int status;
4327
4328 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4329 status = decode_compound_hdr(&xdr, &hdr);
4330 if (status)
4331 goto out;
4332 status = decode_putfh(&xdr);
4333 if (status)
4334 goto out;
4335 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004336 if (status)
4337 goto out;
4338 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004339 if (!status)
4340 status = res->count;
4341out:
4342 return status;
4343}
4344
4345/*
4346 * Decode COMMIT response
4347 */
Al Viro8687b632006-10-19 23:28:48 -07004348static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349{
4350 struct xdr_stream xdr;
4351 struct compound_hdr hdr;
4352 int status;
4353
4354 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4355 status = decode_compound_hdr(&xdr, &hdr);
4356 if (status)
4357 goto out;
4358 status = decode_putfh(&xdr);
4359 if (status)
4360 goto out;
4361 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004362 if (status)
4363 goto out;
4364 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365out:
4366 return status;
4367}
4368
4369/*
4370 * FSINFO request
4371 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04004372static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
4373 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374{
4375 struct xdr_stream xdr;
4376 struct compound_hdr hdr;
4377 int status;
4378
4379 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4380 status = decode_compound_hdr(&xdr, &hdr);
4381 if (!status)
4382 status = decode_putfh(&xdr);
4383 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04004384 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385 return status;
4386}
4387
4388/*
4389 * PATHCONF request
4390 */
Benny Halevyd45b2982009-04-01 09:21:58 -04004391static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
4392 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393{
4394 struct xdr_stream xdr;
4395 struct compound_hdr hdr;
4396 int status;
4397
4398 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4399 status = decode_compound_hdr(&xdr, &hdr);
4400 if (!status)
4401 status = decode_putfh(&xdr);
4402 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04004403 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 return status;
4405}
4406
4407/*
4408 * STATFS request
4409 */
Benny Halevy24ad1482009-04-01 09:21:56 -04004410static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
4411 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004412{
4413 struct xdr_stream xdr;
4414 struct compound_hdr hdr;
4415 int status;
4416
4417 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4418 status = decode_compound_hdr(&xdr, &hdr);
4419 if (!status)
4420 status = decode_putfh(&xdr);
4421 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04004422 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004423 return status;
4424}
4425
4426/*
4427 * GETATTR_BITMAP request
4428 */
Al Viro8687b632006-10-19 23:28:48 -07004429static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430{
4431 struct xdr_stream xdr;
4432 struct compound_hdr hdr;
4433 int status;
4434
4435 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4436 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4437 goto out;
4438 if ((status = decode_putfh(&xdr)) != 0)
4439 goto out;
4440 status = decode_server_caps(&xdr, res);
4441out:
4442 return status;
4443}
4444
4445/*
4446 * Decode RENEW response
4447 */
Al Viro8687b632006-10-19 23:28:48 -07004448static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449{
4450 struct xdr_stream xdr;
4451 struct compound_hdr hdr;
4452 int status;
4453
4454 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4455 status = decode_compound_hdr(&xdr, &hdr);
4456 if (!status)
4457 status = decode_renew(&xdr);
4458 return status;
4459}
4460
4461/*
4462 * a SETCLIENTID request
4463 */
Al Viro8687b632006-10-19 23:28:48 -07004464static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04004465 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004466{
4467 struct xdr_stream xdr;
4468 struct compound_hdr hdr;
4469 int status;
4470
4471 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4472 status = decode_compound_hdr(&xdr, &hdr);
4473 if (!status)
4474 status = decode_setclientid(&xdr, clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475 return status;
4476}
4477
4478/*
4479 * a SETCLIENTID_CONFIRM request
4480 */
Al Viro8687b632006-10-19 23:28:48 -07004481static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482{
4483 struct xdr_stream xdr;
4484 struct compound_hdr hdr;
4485 int status;
4486
4487 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4488 status = decode_compound_hdr(&xdr, &hdr);
4489 if (!status)
4490 status = decode_setclientid_confirm(&xdr);
4491 if (!status)
4492 status = decode_putrootfh(&xdr);
4493 if (!status)
4494 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495 return status;
4496}
4497
4498/*
4499 * DELEGRETURN request
4500 */
Al Viro8687b632006-10-19 23:28:48 -07004501static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502{
4503 struct xdr_stream xdr;
4504 struct compound_hdr hdr;
4505 int status;
4506
4507 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4508 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01004509 if (status != 0)
4510 goto out;
4511 status = decode_putfh(&xdr);
4512 if (status != 0)
4513 goto out;
4514 status = decode_delegreturn(&xdr);
4515 decode_getfattr(&xdr, res->fattr, res->server);
4516out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 return status;
4518}
4519
Trond Myklebust683b57b2006-06-09 09:34:22 -04004520/*
4521 * FS_LOCATIONS request
4522 */
Benny Halevy22958462009-04-01 09:22:02 -04004523static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
4524 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004525{
4526 struct xdr_stream xdr;
4527 struct compound_hdr hdr;
4528 int status;
4529
4530 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4531 status = decode_compound_hdr(&xdr, &hdr);
4532 if (status != 0)
4533 goto out;
4534 if ((status = decode_putfh(&xdr)) != 0)
4535 goto out;
4536 if ((status = decode_lookup(&xdr)) != 0)
4537 goto out;
4538 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04004539 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
4540 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04004541out:
4542 return status;
4543}
4544
Al Viro0dbb4c62006-10-19 23:28:49 -07004545__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004546{
4547 uint32_t bitmap[2] = {0};
4548 uint32_t len;
4549
4550 if (!*p++) {
4551 if (!*p)
4552 return ERR_PTR(-EAGAIN);
4553 entry->eof = 1;
4554 return ERR_PTR(-EBADCOOKIE);
4555 }
4556
4557 entry->prev_cookie = entry->cookie;
4558 p = xdr_decode_hyper(p, &entry->cookie);
4559 entry->len = ntohl(*p++);
4560 entry->name = (const char *) p;
4561 p += XDR_QUADLEN(entry->len);
4562
4563 /*
4564 * In case the server doesn't return an inode number,
4565 * we fake one here. (We don't use inode number 0,
4566 * since glibc seems to choke on it...)
4567 */
4568 entry->ino = 1;
4569
4570 len = ntohl(*p++); /* bitmap length */
4571 if (len-- > 0) {
4572 bitmap[0] = ntohl(*p++);
4573 if (len-- > 0) {
4574 bitmap[1] = ntohl(*p++);
4575 p += len;
4576 }
4577 }
4578 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4579 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00004580 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4581 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4582 /* Ignore the return value of rdattr_error for now */
4583 p++;
4584 len--;
4585 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4587 xdr_decode_hyper(p, &entry->ino);
4588 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4589 xdr_decode_hyper(p, &entry->ino);
4590 p += len;
4591 }
4592
4593 entry->eof = !p[0] && p[1];
4594 return p;
4595}
4596
4597/*
4598 * We need to translate between nfs status return values and
4599 * the local errno values which may not be the same.
4600 */
4601static struct {
4602 int stat;
4603 int errno;
4604} nfs_errtbl[] = {
4605 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03004606 { NFS4ERR_PERM, -EPERM },
4607 { NFS4ERR_NOENT, -ENOENT },
4608 { NFS4ERR_IO, -errno_NFSERR_IO},
4609 { NFS4ERR_NXIO, -ENXIO },
4610 { NFS4ERR_ACCESS, -EACCES },
4611 { NFS4ERR_EXIST, -EEXIST },
4612 { NFS4ERR_XDEV, -EXDEV },
4613 { NFS4ERR_NOTDIR, -ENOTDIR },
4614 { NFS4ERR_ISDIR, -EISDIR },
4615 { NFS4ERR_INVAL, -EINVAL },
4616 { NFS4ERR_FBIG, -EFBIG },
4617 { NFS4ERR_NOSPC, -ENOSPC },
4618 { NFS4ERR_ROFS, -EROFS },
4619 { NFS4ERR_MLINK, -EMLINK },
4620 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
4621 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
4622 { NFS4ERR_DQUOT, -EDQUOT },
4623 { NFS4ERR_STALE, -ESTALE },
4624 { NFS4ERR_BADHANDLE, -EBADHANDLE },
4625 { NFS4ERR_BADOWNER, -EINVAL },
4626 { NFS4ERR_BADNAME, -EINVAL },
4627 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
4628 { NFS4ERR_NOTSUPP, -ENOTSUPP },
4629 { NFS4ERR_TOOSMALL, -ETOOSMALL },
4630 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
4631 { NFS4ERR_BADTYPE, -EBADTYPE },
4632 { NFS4ERR_LOCKED, -EAGAIN },
4633 { NFS4ERR_RESOURCE, -EREMOTEIO },
4634 { NFS4ERR_SYMLINK, -ELOOP },
4635 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
4636 { NFS4ERR_DEADLOCK, -EDEADLK },
4637 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638 * to be handled by a
4639 * middle-layer.
4640 */
Benny Halevy856dff32008-03-31 17:39:06 +03004641 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642};
4643
4644/*
4645 * Convert an NFS error code to a local one.
4646 * This one is used jointly by NFSv2 and NFSv3.
4647 */
4648static int
David Howells0a8ea432006-08-22 20:06:08 -04004649nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004650{
4651 int i;
4652 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4653 if (nfs_errtbl[i].stat == stat)
4654 return nfs_errtbl[i].errno;
4655 }
4656 if (stat <= 10000 || stat > 10100) {
4657 /* The server is looney tunes. */
Benny Halevy856dff32008-03-31 17:39:06 +03004658 return -ESERVERFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659 }
4660 /* If we cannot translate the error, the recovery routines should
4661 * handle it.
4662 * Note: remaining NFSv4 error codes have values > 10000, so should
4663 * not conflict with native Linux error codes.
4664 */
Benny Halevy856dff32008-03-31 17:39:06 +03004665 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666}
4667
Linus Torvalds1da177e2005-04-16 15:20:36 -07004668#define PROC(proc, argtype, restype) \
4669[NFSPROC4_CLNT_##proc] = { \
4670 .p_proc = NFSPROC4_COMPOUND, \
4671 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4672 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04004673 .p_arglen = NFS4_##argtype##_sz, \
4674 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05004675 .p_statidx = NFSPROC4_CLNT_##proc, \
4676 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05004677}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678
4679struct rpc_procinfo nfs4_procedures[] = {
4680 PROC(READ, enc_read, dec_read),
4681 PROC(WRITE, enc_write, dec_write),
4682 PROC(COMMIT, enc_commit, dec_commit),
4683 PROC(OPEN, enc_open, dec_open),
4684 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4685 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4686 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4687 PROC(CLOSE, enc_close, dec_close),
4688 PROC(SETATTR, enc_setattr, dec_setattr),
4689 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4690 PROC(RENEW, enc_renew, dec_renew),
4691 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4692 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4693 PROC(LOCK, enc_lock, dec_lock),
4694 PROC(LOCKT, enc_lockt, dec_lockt),
4695 PROC(LOCKU, enc_locku, dec_locku),
4696 PROC(ACCESS, enc_access, dec_access),
4697 PROC(GETATTR, enc_getattr, dec_getattr),
4698 PROC(LOOKUP, enc_lookup, dec_lookup),
4699 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4700 PROC(REMOVE, enc_remove, dec_remove),
4701 PROC(RENAME, enc_rename, dec_rename),
4702 PROC(LINK, enc_link, dec_link),
4703 PROC(SYMLINK, enc_symlink, dec_symlink),
4704 PROC(CREATE, enc_create, dec_create),
4705 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4706 PROC(STATFS, enc_statfs, dec_statfs),
4707 PROC(READLINK, enc_readlink, dec_readlink),
4708 PROC(READDIR, enc_readdir, dec_readdir),
4709 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4710 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00004711 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004712 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04004713 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004714};
4715
4716struct rpc_version nfs_version4 = {
4717 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08004718 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719 .procs = nfs4_procedures
4720};
4721
4722/*
4723 * Local variables:
4724 * c-basic-offset: 8
4725 * End:
4726 */