blob: 0cf3fa312a332f565e8b57914eed5c60197caa21 [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>
11 *
12 * 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
70/* lock,open owner id:
71 * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2)
72 */
73#define owner_id_maxsz (1 + 1)
74#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
75#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
76#define op_encode_hdr_maxsz (1)
77#define op_decode_hdr_maxsz (2)
78#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
79 (NFS4_FHSIZE >> 2))
80#define decode_putfh_maxsz (op_decode_hdr_maxsz)
81#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
82#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
83#define encode_getfh_maxsz (op_encode_hdr_maxsz)
84#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
85 ((3+NFS4_FHSIZE) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000086#define nfs4_fattr_bitmap_maxsz 3
87#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
89#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000090/* This is based on getfattr, which uses the most attributes: */
91#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
92 3 + 3 + 3 + 2 * nfs4_name_maxsz))
93#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
94 nfs4_fattr_value_maxsz)
95#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#define encode_savefh_maxsz (op_encode_hdr_maxsz)
97#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -040098#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
99#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
101#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
102#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
103#define decode_renew_maxsz (op_decode_hdr_maxsz)
104#define encode_setclientid_maxsz \
105 (op_encode_hdr_maxsz + \
106 4 /*server->ip_addr*/ + \
107 1 /*Netid*/ + \
108 6 /*uaddr*/ + \
109 6 + (NFS4_VERIFIER_SIZE >> 2))
110#define decode_setclientid_maxsz \
111 (op_decode_hdr_maxsz + \
112 2 + \
113 1024) /* large value for CLID_INUSE */
114#define encode_setclientid_confirm_maxsz \
115 (op_encode_hdr_maxsz + \
116 3 + (NFS4_VERIFIER_SIZE >> 2))
117#define decode_setclientid_confirm_maxsz \
118 (op_decode_hdr_maxsz)
119#define encode_lookup_maxsz (op_encode_hdr_maxsz + \
120 1 + ((3 + NFS4_FHSIZE) >> 2))
121#define encode_remove_maxsz (op_encode_hdr_maxsz + \
122 nfs4_name_maxsz)
123#define encode_rename_maxsz (op_encode_hdr_maxsz + \
124 2 * nfs4_name_maxsz)
125#define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
126#define encode_link_maxsz (op_encode_hdr_maxsz + \
127 nfs4_name_maxsz)
128#define decode_link_maxsz (op_decode_hdr_maxsz + 5)
129#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
130 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400131 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000132 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
134#define encode_create_maxsz (op_encode_hdr_maxsz + \
135 2 + nfs4_name_maxsz + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000136 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#define decode_create_maxsz (op_decode_hdr_maxsz + 8)
138#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
139#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
140#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
141#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
142#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
143 encode_putfh_maxsz + \
144 op_encode_hdr_maxsz + 7)
145#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
146 decode_putfh_maxsz + \
147 op_decode_hdr_maxsz + 2)
148#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
149 encode_putfh_maxsz + \
150 op_encode_hdr_maxsz)
151#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
152 decode_putfh_maxsz + \
153 op_decode_hdr_maxsz)
154#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
155 encode_putfh_maxsz + \
156 op_encode_hdr_maxsz + 9)
157#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
158 decode_putfh_maxsz + \
159 op_decode_hdr_maxsz + 2)
160#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
161 encode_putfh_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400162 op_encode_hdr_maxsz + 8 + \
163 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
165 decode_putfh_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400166 op_decode_hdr_maxsz + 4 + \
167 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
169 encode_putfh_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400170 op_encode_hdr_maxsz + 3 + \
171 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
173 decode_putfh_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400174 op_decode_hdr_maxsz + 2 + \
175 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
177 encode_putfh_maxsz + \
178 op_encode_hdr_maxsz + \
179 13 + 3 + 2 + 64 + \
180 encode_getattr_maxsz + \
181 encode_getfh_maxsz)
182#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
183 decode_putfh_maxsz + \
184 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
185 decode_getattr_maxsz + \
186 decode_getfh_maxsz)
187#define NFS4_enc_open_confirm_sz \
188 (compound_encode_hdr_maxsz + \
189 encode_putfh_maxsz + \
190 op_encode_hdr_maxsz + 5)
191#define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
192 decode_putfh_maxsz + \
193 op_decode_hdr_maxsz + 4)
194#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
195 encode_putfh_maxsz + \
196 op_encode_hdr_maxsz + \
197 11)
198#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
199 decode_putfh_maxsz + \
200 op_decode_hdr_maxsz + \
201 4 + 5 + 2 + 3)
202#define NFS4_enc_open_downgrade_sz \
203 (compound_encode_hdr_maxsz + \
204 encode_putfh_maxsz + \
Trond Myklebust516a6af2005-10-27 22:12:41 -0400205 op_encode_hdr_maxsz + 7 + \
206 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#define NFS4_dec_open_downgrade_sz \
208 (compound_decode_hdr_maxsz + \
209 decode_putfh_maxsz + \
Trond Myklebust516a6af2005-10-27 22:12:41 -0400210 op_decode_hdr_maxsz + 4 + \
211 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
213 encode_putfh_maxsz + \
Trond Myklebust516a6af2005-10-27 22:12:41 -0400214 op_encode_hdr_maxsz + 5 + \
215 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
217 decode_putfh_maxsz + \
Trond Myklebust516a6af2005-10-27 22:12:41 -0400218 op_decode_hdr_maxsz + 4 + \
219 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
221 encode_putfh_maxsz + \
222 op_encode_hdr_maxsz + 4 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000223 nfs4_fattr_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 encode_getattr_maxsz)
225#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
226 decode_putfh_maxsz + \
227 op_decode_hdr_maxsz + 3)
228#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
229 encode_putfh_maxsz + \
230 encode_fsinfo_maxsz)
231#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
232 decode_putfh_maxsz + \
233 decode_fsinfo_maxsz)
234#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
235 encode_renew_maxsz)
236#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
237 decode_renew_maxsz)
238#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
239 encode_setclientid_maxsz)
240#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
241 decode_setclientid_maxsz)
242#define NFS4_enc_setclientid_confirm_sz \
243 (compound_encode_hdr_maxsz + \
244 encode_setclientid_confirm_maxsz + \
245 encode_putrootfh_maxsz + \
246 encode_fsinfo_maxsz)
247#define NFS4_dec_setclientid_confirm_sz \
248 (compound_decode_hdr_maxsz + \
249 decode_setclientid_confirm_maxsz + \
250 decode_putrootfh_maxsz + \
251 decode_fsinfo_maxsz)
252#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
253 encode_putfh_maxsz + \
254 encode_getattr_maxsz + \
255 op_encode_hdr_maxsz + \
256 1 + 1 + 2 + 2 + \
257 1 + 4 + 1 + 2 + \
258 owner_id_maxsz)
259#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
260 decode_putfh_maxsz + \
261 decode_getattr_maxsz + \
262 op_decode_hdr_maxsz + \
263 2 + 2 + 1 + 2 + \
264 owner_id_maxsz)
265#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
266 encode_putfh_maxsz + \
267 encode_getattr_maxsz + \
268 op_encode_hdr_maxsz + \
269 1 + 2 + 2 + 2 + \
270 owner_id_maxsz)
271#define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
272#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
273 encode_putfh_maxsz + \
274 encode_getattr_maxsz + \
275 op_encode_hdr_maxsz + \
276 1 + 1 + 4 + 2 + 2)
277#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
278 decode_putfh_maxsz + \
279 decode_getattr_maxsz + \
280 op_decode_hdr_maxsz + 4)
281#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
282 encode_putfh_maxsz + \
283 op_encode_hdr_maxsz + 1)
284#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
285 decode_putfh_maxsz + \
286 op_decode_hdr_maxsz + 2)
287#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
288 encode_putfh_maxsz + \
289 encode_getattr_maxsz)
290#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
291 decode_putfh_maxsz + \
292 decode_getattr_maxsz)
293#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
294 encode_putfh_maxsz + \
295 encode_lookup_maxsz + \
296 encode_getattr_maxsz + \
297 encode_getfh_maxsz)
298#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
299 decode_putfh_maxsz + \
300 op_decode_hdr_maxsz + \
301 decode_getattr_maxsz + \
302 decode_getfh_maxsz)
303#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
304 encode_putrootfh_maxsz + \
305 encode_getattr_maxsz + \
306 encode_getfh_maxsz)
307#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
308 decode_putrootfh_maxsz + \
309 decode_getattr_maxsz + \
310 decode_getfh_maxsz)
311#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
312 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400313 encode_remove_maxsz + \
314 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
316 decode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400317 op_decode_hdr_maxsz + 5 + \
318 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
320 encode_putfh_maxsz + \
321 encode_savefh_maxsz + \
322 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400323 encode_rename_maxsz + \
324 encode_getattr_maxsz + \
325 encode_restorefh_maxsz + \
326 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
328 decode_putfh_maxsz + \
329 decode_savefh_maxsz + \
330 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400331 decode_rename_maxsz + \
332 decode_getattr_maxsz + \
333 decode_restorefh_maxsz + \
334 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
336 encode_putfh_maxsz + \
337 encode_savefh_maxsz + \
338 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400339 encode_link_maxsz + \
340 decode_getattr_maxsz + \
341 encode_restorefh_maxsz + \
342 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
344 decode_putfh_maxsz + \
345 decode_savefh_maxsz + \
346 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400347 decode_link_maxsz + \
348 decode_getattr_maxsz + \
349 decode_restorefh_maxsz + \
350 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
352 encode_putfh_maxsz + \
353 encode_symlink_maxsz + \
354 encode_getattr_maxsz + \
355 encode_getfh_maxsz)
356#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
357 decode_putfh_maxsz + \
358 decode_symlink_maxsz + \
359 decode_getattr_maxsz + \
360 decode_getfh_maxsz)
361#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
362 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400363 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400365 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400367 encode_restorefh_maxsz + \
368 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
370 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400371 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400373 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400375 decode_restorefh_maxsz + \
376 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
378 encode_putfh_maxsz + \
379 encode_getattr_maxsz)
380#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
381 decode_putfh_maxsz + \
382 decode_getattr_maxsz)
383#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
384 encode_putfh_maxsz + \
385 encode_getattr_maxsz)
386#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
387 decode_putfh_maxsz + \
388 op_decode_hdr_maxsz + 12)
389#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
390 encode_getattr_maxsz)
391#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
392 decode_getattr_maxsz)
393#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
394 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100395 encode_delegreturn_maxsz + \
396 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100398 decode_delegreturn_maxsz + \
399 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000400#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
401 encode_putfh_maxsz + \
402 encode_getattr_maxsz)
403#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
404 decode_putfh_maxsz + \
405 op_decode_hdr_maxsz + \
406 nfs4_fattr_bitmap_maxsz + 1)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000407#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
408 encode_putfh_maxsz + \
409 op_encode_hdr_maxsz + 4 + \
410 nfs4_fattr_bitmap_maxsz + 1)
411#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
412 decode_putfh_maxsz + \
413 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400414#define NFS4_enc_fs_locations_sz \
415 (compound_encode_hdr_maxsz + \
416 encode_putfh_maxsz + \
417 encode_getattr_maxsz)
418#define NFS4_dec_fs_locations_sz \
419 (compound_decode_hdr_maxsz + \
420 decode_putfh_maxsz + \
421 op_decode_hdr_maxsz + \
422 nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
424static struct {
425 unsigned int mode;
426 unsigned int nfs2type;
427} nfs_type2fmt[] = {
428 { 0, NFNON },
429 { S_IFREG, NFREG },
430 { S_IFDIR, NFDIR },
431 { S_IFBLK, NFBLK },
432 { S_IFCHR, NFCHR },
433 { S_IFLNK, NFLNK },
434 { S_IFSOCK, NFSOCK },
435 { S_IFIFO, NFFIFO },
436 { 0, NFNON },
437 { 0, NFNON },
438};
439
440struct compound_hdr {
441 int32_t status;
442 uint32_t nops;
443 uint32_t taglen;
444 char * tag;
445};
446
447/*
448 * START OF "GENERIC" ENCODE ROUTINES.
449 * These may look a little ugly since they are imported from a "generic"
450 * set of XDR encode/decode routines which are intended to be shared by
451 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
452 *
453 * If the pain of reading these is too great, it should be a straightforward
454 * task to translate them into Linux-specific versions which are more
455 * consistent with the style used in NFSv2/v3...
456 */
457#define WRITE32(n) *p++ = htonl(n)
458#define WRITE64(n) do { \
459 *p++ = htonl((uint32_t)((n) >> 32)); \
460 *p++ = htonl((uint32_t)(n)); \
461} while (0)
462#define WRITEMEM(ptr,nbytes) do { \
463 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
464} while (0)
465
466#define RESERVE_SPACE(nbytes) do { \
467 p = xdr_reserve_space(xdr, nbytes); \
468 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
469 BUG_ON(!p); \
470} while (0)
471
472static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
473{
Al Viro8687b632006-10-19 23:28:48 -0700474 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
476 p = xdr_reserve_space(xdr, 4 + len);
477 BUG_ON(p == NULL);
478 xdr_encode_opaque(p, str, len);
479}
480
481static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
482{
Al Viro8687b632006-10-19 23:28:48 -0700483 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
486 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
487 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
488 WRITE32(hdr->taglen);
489 WRITEMEM(hdr->tag, hdr->taglen);
490 WRITE32(NFS4_MINOR_VERSION);
491 WRITE32(hdr->nops);
492 return 0;
493}
494
495static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
496{
Al Viro8687b632006-10-19 23:28:48 -0700497 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
500 BUG_ON(p == NULL);
501 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
502}
503
504static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
505{
506 char owner_name[IDMAP_NAMESZ];
507 char owner_group[IDMAP_NAMESZ];
508 int owner_namelen = 0;
509 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700510 __be32 *p;
511 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 int len;
513 uint32_t bmval0 = 0;
514 uint32_t bmval1 = 0;
515 int status;
516
517 /*
518 * We reserve enough space to write the entire attribute buffer at once.
519 * In the worst-case, this would be
520 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
521 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000522 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 */
524 len = 16;
525
526 /* Sigh */
527 if (iap->ia_valid & ATTR_SIZE)
528 len += 8;
529 if (iap->ia_valid & ATTR_MODE)
530 len += 4;
531 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400532 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 if (owner_namelen < 0) {
534 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
535 iap->ia_uid);
536 /* XXX */
537 strcpy(owner_name, "nobody");
538 owner_namelen = sizeof("nobody") - 1;
539 /* goto out; */
540 }
541 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
542 }
543 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400544 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 if (owner_grouplen < 0) {
546 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
547 iap->ia_gid);
548 strcpy(owner_group, "nobody");
549 owner_grouplen = sizeof("nobody") - 1;
550 /* goto out; */
551 }
552 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
553 }
554 if (iap->ia_valid & ATTR_ATIME_SET)
555 len += 16;
556 else if (iap->ia_valid & ATTR_ATIME)
557 len += 4;
558 if (iap->ia_valid & ATTR_MTIME_SET)
559 len += 16;
560 else if (iap->ia_valid & ATTR_MTIME)
561 len += 4;
562 RESERVE_SPACE(len);
563
564 /*
565 * We write the bitmap length now, but leave the bitmap and the attribute
566 * buffer length to be backfilled at the end of this routine.
567 */
568 WRITE32(2);
569 q = p;
570 p += 3;
571
572 if (iap->ia_valid & ATTR_SIZE) {
573 bmval0 |= FATTR4_WORD0_SIZE;
574 WRITE64(iap->ia_size);
575 }
576 if (iap->ia_valid & ATTR_MODE) {
577 bmval1 |= FATTR4_WORD1_MODE;
Trond Myklebustcf3fff52006-01-03 09:55:53 +0100578 WRITE32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
580 if (iap->ia_valid & ATTR_UID) {
581 bmval1 |= FATTR4_WORD1_OWNER;
582 WRITE32(owner_namelen);
583 WRITEMEM(owner_name, owner_namelen);
584 }
585 if (iap->ia_valid & ATTR_GID) {
586 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
587 WRITE32(owner_grouplen);
588 WRITEMEM(owner_group, owner_grouplen);
589 }
590 if (iap->ia_valid & ATTR_ATIME_SET) {
591 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
592 WRITE32(NFS4_SET_TO_CLIENT_TIME);
593 WRITE32(0);
594 WRITE32(iap->ia_mtime.tv_sec);
595 WRITE32(iap->ia_mtime.tv_nsec);
596 }
597 else if (iap->ia_valid & ATTR_ATIME) {
598 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
599 WRITE32(NFS4_SET_TO_SERVER_TIME);
600 }
601 if (iap->ia_valid & ATTR_MTIME_SET) {
602 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
603 WRITE32(NFS4_SET_TO_CLIENT_TIME);
604 WRITE32(0);
605 WRITE32(iap->ia_mtime.tv_sec);
606 WRITE32(iap->ia_mtime.tv_nsec);
607 }
608 else if (iap->ia_valid & ATTR_MTIME) {
609 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
610 WRITE32(NFS4_SET_TO_SERVER_TIME);
611 }
612
613 /*
614 * Now we backfill the bitmap and the attribute buffer length.
615 */
616 if (len != ((char *)p - (char *)q) + 4) {
617 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
618 len, ((char *)p - (char *)q) + 4);
619 BUG();
620 }
621 len = (char *)p - (char *)q - 12;
622 *q++ = htonl(bmval0);
623 *q++ = htonl(bmval1);
624 *q++ = htonl(len);
625
626 status = 0;
627/* out: */
628 return status;
629}
630
631static int encode_access(struct xdr_stream *xdr, u32 access)
632{
Al Viro8687b632006-10-19 23:28:48 -0700633 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
635 RESERVE_SPACE(8);
636 WRITE32(OP_ACCESS);
637 WRITE32(access);
638
639 return 0;
640}
641
642static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
643{
Al Viro8687b632006-10-19 23:28:48 -0700644 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Trond Myklebust95121352005-10-18 14:20:12 -0700646 RESERVE_SPACE(8+sizeof(arg->stateid->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 WRITE32(OP_CLOSE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700648 WRITE32(arg->seqid->sequence->counter);
Trond Myklebust95121352005-10-18 14:20:12 -0700649 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
651 return 0;
652}
653
654static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
655{
Al Viro8687b632006-10-19 23:28:48 -0700656 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
658 RESERVE_SPACE(16);
659 WRITE32(OP_COMMIT);
660 WRITE64(args->offset);
661 WRITE32(args->count);
662
663 return 0;
664}
665
666static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
667{
Al Viro8687b632006-10-19 23:28:48 -0700668 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670 RESERVE_SPACE(8);
671 WRITE32(OP_CREATE);
672 WRITE32(create->ftype);
673
674 switch (create->ftype) {
675 case NF4LNK:
Chuck Lever94a6d752006-08-22 20:06:23 -0400676 RESERVE_SPACE(4);
677 WRITE32(create->u.symlink.len);
678 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 break;
680
681 case NF4BLK: case NF4CHR:
682 RESERVE_SPACE(8);
683 WRITE32(create->u.device.specdata1);
684 WRITE32(create->u.device.specdata2);
685 break;
686
687 default:
688 break;
689 }
690
691 RESERVE_SPACE(4 + create->name->len);
692 WRITE32(create->name->len);
693 WRITEMEM(create->name->name, create->name->len);
694
695 return encode_attrs(xdr, create->attrs, create->server);
696}
697
698static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
699{
Al Viro8687b632006-10-19 23:28:48 -0700700 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
702 RESERVE_SPACE(12);
703 WRITE32(OP_GETATTR);
704 WRITE32(1);
705 WRITE32(bitmap);
706 return 0;
707}
708
709static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
710{
Al Viro8687b632006-10-19 23:28:48 -0700711 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
713 RESERVE_SPACE(16);
714 WRITE32(OP_GETATTR);
715 WRITE32(2);
716 WRITE32(bm0);
717 WRITE32(bm1);
718 return 0;
719}
720
721static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
722{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 return encode_getattr_two(xdr,
724 bitmask[0] & nfs4_fattr_bitmap[0],
725 bitmask[1] & nfs4_fattr_bitmap[1]);
726}
727
728static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
729{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
731 bitmask[1] & nfs4_fsinfo_bitmap[1]);
732}
733
Manoj Naik830b8e32006-06-09 09:34:25 -0400734static int encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask)
735{
736 return encode_getattr_two(xdr,
737 bitmask[0] & nfs4_fs_locations_bitmap[0],
738 bitmask[1] & nfs4_fs_locations_bitmap[1]);
739}
740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741static int encode_getfh(struct xdr_stream *xdr)
742{
Al Viro8687b632006-10-19 23:28:48 -0700743 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
745 RESERVE_SPACE(4);
746 WRITE32(OP_GETFH);
747
748 return 0;
749}
750
751static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
752{
Al Viro8687b632006-10-19 23:28:48 -0700753 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
755 RESERVE_SPACE(8 + name->len);
756 WRITE32(OP_LINK);
757 WRITE32(name->len);
758 WRITEMEM(name->name, name->len);
759
760 return 0;
761}
762
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100763static inline int nfs4_lock_type(struct file_lock *fl, int block)
764{
765 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
766 return block ? NFS4_READW_LT : NFS4_READ_LT;
767 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
768}
769
770static inline uint64_t nfs4_lock_length(struct file_lock *fl)
771{
772 if (fl->fl_end == OFFSET_MAX)
773 return ~(uint64_t)0;
774 return fl->fl_end - fl->fl_start + 1;
775}
776
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777/*
778 * opcode,type,reclaim,offset,length,new_lock_owner = 32
779 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
780 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100781static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782{
Al Viro8687b632006-10-19 23:28:48 -0700783 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
785 RESERVE_SPACE(32);
786 WRITE32(OP_LOCK);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100787 WRITE32(nfs4_lock_type(args->fl, args->block));
788 WRITE32(args->reclaim);
789 WRITE64(args->fl->fl_start);
790 WRITE64(nfs4_lock_length(args->fl));
791 WRITE32(args->new_lock_owner);
792 if (args->new_lock_owner){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 RESERVE_SPACE(40);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100794 WRITE32(args->open_seqid->sequence->counter);
795 WRITEMEM(args->open_stateid->data, sizeof(args->open_stateid->data));
796 WRITE32(args->lock_seqid->sequence->counter);
797 WRITE64(args->lock_owner.clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 WRITE32(4);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100799 WRITE32(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 }
801 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 RESERVE_SPACE(20);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100803 WRITEMEM(args->lock_stateid->data, sizeof(args->lock_stateid->data));
804 WRITE32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 }
806
807 return 0;
808}
809
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100810static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811{
Al Viro8687b632006-10-19 23:28:48 -0700812 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 RESERVE_SPACE(40);
815 WRITE32(OP_LOCKT);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100816 WRITE32(nfs4_lock_type(args->fl, 0));
817 WRITE64(args->fl->fl_start);
818 WRITE64(nfs4_lock_length(args->fl));
819 WRITE64(args->lock_owner.clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 WRITE32(4);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100821 WRITE32(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823 return 0;
824}
825
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100826static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
Al Viro8687b632006-10-19 23:28:48 -0700828 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 RESERVE_SPACE(44);
831 WRITE32(OP_LOCKU);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100832 WRITE32(nfs4_lock_type(args->fl, 0));
833 WRITE32(args->seqid->sequence->counter);
834 WRITEMEM(args->stateid->data, sizeof(args->stateid->data));
835 WRITE64(args->fl->fl_start);
836 WRITE64(nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
838 return 0;
839}
840
841static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
842{
843 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -0700844 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
846 RESERVE_SPACE(8 + len);
847 WRITE32(OP_LOOKUP);
848 WRITE32(len);
849 WRITEMEM(name->name, len);
850
851 return 0;
852}
853
854static void encode_share_access(struct xdr_stream *xdr, int open_flags)
855{
Al Viro8687b632006-10-19 23:28:48 -0700856 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
858 RESERVE_SPACE(8);
859 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
860 case FMODE_READ:
861 WRITE32(NFS4_SHARE_ACCESS_READ);
862 break;
863 case FMODE_WRITE:
864 WRITE32(NFS4_SHARE_ACCESS_WRITE);
865 break;
866 case FMODE_READ|FMODE_WRITE:
867 WRITE32(NFS4_SHARE_ACCESS_BOTH);
868 break;
869 default:
870 BUG();
871 }
872 WRITE32(0); /* for linux, share_deny = 0 always */
873}
874
875static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
876{
Al Viro8687b632006-10-19 23:28:48 -0700877 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 /*
879 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
880 * owner 4 = 32
881 */
882 RESERVE_SPACE(8);
883 WRITE32(OP_OPEN);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700884 WRITE32(arg->seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 encode_share_access(xdr, arg->open_flags);
886 RESERVE_SPACE(16);
887 WRITE64(arg->clientid);
888 WRITE32(4);
889 WRITE32(arg->id);
890}
891
892static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
893{
Al Viro8687b632006-10-19 23:28:48 -0700894 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
896 RESERVE_SPACE(4);
897 switch(arg->open_flags & O_EXCL) {
898 case 0:
899 WRITE32(NFS4_CREATE_UNCHECKED);
900 encode_attrs(xdr, arg->u.attrs, arg->server);
901 break;
902 default:
903 WRITE32(NFS4_CREATE_EXCLUSIVE);
904 encode_nfs4_verifier(xdr, &arg->u.verifier);
905 }
906}
907
908static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
909{
Al Viro8687b632006-10-19 23:28:48 -0700910 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912 RESERVE_SPACE(4);
913 switch (arg->open_flags & O_CREAT) {
914 case 0:
915 WRITE32(NFS4_OPEN_NOCREATE);
916 break;
917 default:
918 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
919 WRITE32(NFS4_OPEN_CREATE);
920 encode_createmode(xdr, arg);
921 }
922}
923
924static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
925{
Al Viro8687b632006-10-19 23:28:48 -0700926 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928 RESERVE_SPACE(4);
929 switch (delegation_type) {
930 case 0:
931 WRITE32(NFS4_OPEN_DELEGATE_NONE);
932 break;
933 case FMODE_READ:
934 WRITE32(NFS4_OPEN_DELEGATE_READ);
935 break;
936 case FMODE_WRITE|FMODE_READ:
937 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
938 break;
939 default:
940 BUG();
941 }
942}
943
944static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
945{
Al Viro8687b632006-10-19 23:28:48 -0700946 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
948 RESERVE_SPACE(4);
949 WRITE32(NFS4_OPEN_CLAIM_NULL);
950 encode_string(xdr, name->len, name->name);
951}
952
953static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
954{
Al Viro8687b632006-10-19 23:28:48 -0700955 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
957 RESERVE_SPACE(4);
958 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
959 encode_delegation_type(xdr, type);
960}
961
962static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
963{
Al Viro8687b632006-10-19 23:28:48 -0700964 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
966 RESERVE_SPACE(4+sizeof(stateid->data));
967 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
968 WRITEMEM(stateid->data, sizeof(stateid->data));
969 encode_string(xdr, name->len, name->name);
970}
971
972static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
973{
974 encode_openhdr(xdr, arg);
975 encode_opentype(xdr, arg);
976 switch (arg->claim) {
977 case NFS4_OPEN_CLAIM_NULL:
978 encode_claim_null(xdr, arg->name);
979 break;
980 case NFS4_OPEN_CLAIM_PREVIOUS:
981 encode_claim_previous(xdr, arg->u.delegation_type);
982 break;
983 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
984 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
985 break;
986 default:
987 BUG();
988 }
989 return 0;
990}
991
992static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
993{
Al Viro8687b632006-10-19 23:28:48 -0700994 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
Trond Myklebustcdd4e682006-01-03 09:55:12 +0100996 RESERVE_SPACE(8+sizeof(arg->stateid->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 WRITE32(OP_OPEN_CONFIRM);
Trond Myklebustcdd4e682006-01-03 09:55:12 +0100998 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700999 WRITE32(arg->seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000
1001 return 0;
1002}
1003
1004static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
1005{
Al Viro8687b632006-10-19 23:28:48 -07001006 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Trond Myklebust95121352005-10-18 14:20:12 -07001008 RESERVE_SPACE(8+sizeof(arg->stateid->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 WRITE32(OP_OPEN_DOWNGRADE);
Trond Myklebust95121352005-10-18 14:20:12 -07001010 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001011 WRITE32(arg->seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 encode_share_access(xdr, arg->open_flags);
1013 return 0;
1014}
1015
1016static int
1017encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
1018{
1019 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001020 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
1022 RESERVE_SPACE(8 + len);
1023 WRITE32(OP_PUTFH);
1024 WRITE32(len);
1025 WRITEMEM(fh->data, len);
1026
1027 return 0;
1028}
1029
1030static int encode_putrootfh(struct xdr_stream *xdr)
1031{
Al Viro8687b632006-10-19 23:28:48 -07001032 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
1034 RESERVE_SPACE(4);
1035 WRITE32(OP_PUTROOTFH);
1036
1037 return 0;
1038}
1039
1040static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1041{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001043 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045 RESERVE_SPACE(16);
1046 if (ctx->state != NULL) {
1047 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1048 WRITEMEM(stateid.data, sizeof(stateid.data));
1049 } else
1050 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1051}
1052
1053static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1054{
Al Viro8687b632006-10-19 23:28:48 -07001055 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
1057 RESERVE_SPACE(4);
1058 WRITE32(OP_READ);
1059
1060 encode_stateid(xdr, args->context);
1061
1062 RESERVE_SPACE(12);
1063 WRITE64(args->offset);
1064 WRITE32(args->count);
1065
1066 return 0;
1067}
1068
1069static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1070{
1071 struct rpc_auth *auth = req->rq_task->tk_auth;
Manoj Naik97d312d2005-06-22 17:16:39 +00001072 uint32_t attrs[2] = {
1073 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1074 FATTR4_WORD1_MOUNTED_ON_FILEID,
1075 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 int replen;
Al Viro8687b632006-10-19 23:28:48 -07001077 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
1079 RESERVE_SPACE(32+sizeof(nfs4_verifier));
1080 WRITE32(OP_READDIR);
1081 WRITE64(readdir->cookie);
1082 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1083 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1084 WRITE32(readdir->count);
1085 WRITE32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001086 /* Switch to mounted_on_fileid if the server supports it */
1087 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1088 attrs[0] &= ~FATTR4_WORD0_FILEID;
1089 else
1090 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1091 WRITE32(attrs[0] & readdir->bitmask[0]);
1092 WRITE32(attrs[1] & readdir->bitmask[1]);
Trond Myklebusteadf4592005-06-22 17:16:39 +00001093 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1094 __FUNCTION__,
1095 (unsigned long long)readdir->cookie,
1096 ((u32 *)readdir->verifier.data)[0],
1097 ((u32 *)readdir->verifier.data)[1],
1098 attrs[0] & readdir->bitmask[0],
1099 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
1101 /* set up reply kvec
1102 * toplevel_status + taglen + rescount + OP_PUTFH + status
1103 * + OP_READDIR + status + verifer(2) = 9
1104 */
1105 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1106 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1107 readdir->pgbase, readdir->count);
Trond Myklebusteadf4592005-06-22 17:16:39 +00001108 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1109 __FUNCTION__, replen, readdir->pages,
1110 readdir->pgbase, readdir->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
1112 return 0;
1113}
1114
1115static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1116{
1117 struct rpc_auth *auth = req->rq_task->tk_auth;
1118 unsigned int replen;
Al Viro8687b632006-10-19 23:28:48 -07001119 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
1121 RESERVE_SPACE(4);
1122 WRITE32(OP_READLINK);
1123
1124 /* set up reply kvec
1125 * toplevel_status + taglen + rescount + OP_PUTFH + status
1126 * + OP_READLINK + status + string length = 8
1127 */
1128 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1129 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1130 readlink->pgbase, readlink->pglen);
1131
1132 return 0;
1133}
1134
1135static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1136{
Al Viro8687b632006-10-19 23:28:48 -07001137 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
1139 RESERVE_SPACE(8 + name->len);
1140 WRITE32(OP_REMOVE);
1141 WRITE32(name->len);
1142 WRITEMEM(name->name, name->len);
1143
1144 return 0;
1145}
1146
1147static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1148{
Al Viro8687b632006-10-19 23:28:48 -07001149 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
1151 RESERVE_SPACE(8 + oldname->len);
1152 WRITE32(OP_RENAME);
1153 WRITE32(oldname->len);
1154 WRITEMEM(oldname->name, oldname->len);
1155
1156 RESERVE_SPACE(4 + newname->len);
1157 WRITE32(newname->len);
1158 WRITEMEM(newname->name, newname->len);
1159
1160 return 0;
1161}
1162
David Howellsadfa6f92006-08-22 20:06:08 -04001163static int encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164{
Al Viro8687b632006-10-19 23:28:48 -07001165 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
1167 RESERVE_SPACE(12);
1168 WRITE32(OP_RENEW);
1169 WRITE64(client_stateid->cl_clientid);
1170
1171 return 0;
1172}
1173
1174static int
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001175encode_restorefh(struct xdr_stream *xdr)
1176{
Al Viro8687b632006-10-19 23:28:48 -07001177 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001178
1179 RESERVE_SPACE(4);
1180 WRITE32(OP_RESTOREFH);
1181
1182 return 0;
1183}
1184
1185static int
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001186encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1187{
Al Viro8687b632006-10-19 23:28:48 -07001188 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001189
1190 RESERVE_SPACE(4+sizeof(zero_stateid.data));
1191 WRITE32(OP_SETATTR);
1192 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1193 RESERVE_SPACE(2*4);
1194 WRITE32(1);
1195 WRITE32(FATTR4_WORD0_ACL);
1196 if (arg->acl_len % 4)
1197 return -EINVAL;
1198 RESERVE_SPACE(4);
1199 WRITE32(arg->acl_len);
1200 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1201 return 0;
1202}
1203
1204static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205encode_savefh(struct xdr_stream *xdr)
1206{
Al Viro8687b632006-10-19 23:28:48 -07001207 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
1209 RESERVE_SPACE(4);
1210 WRITE32(OP_SAVEFH);
1211
1212 return 0;
1213}
1214
1215static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1216{
1217 int status;
Al Viro8687b632006-10-19 23:28:48 -07001218 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
1220 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1221 WRITE32(OP_SETATTR);
1222 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1223
1224 if ((status = encode_attrs(xdr, arg->iap, server)))
1225 return status;
1226
1227 return 0;
1228}
1229
1230static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1231{
Al Viro8687b632006-10-19 23:28:48 -07001232 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
1234 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1235 WRITE32(OP_SETCLIENTID);
1236 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1237
1238 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1239 RESERVE_SPACE(4);
1240 WRITE32(setclientid->sc_prog);
1241 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1242 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1243 RESERVE_SPACE(4);
1244 WRITE32(setclientid->sc_cb_ident);
1245
1246 return 0;
1247}
1248
David Howellsadfa6f92006-08-22 20:06:08 -04001249static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250{
Al Viro8687b632006-10-19 23:28:48 -07001251 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
1253 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1254 WRITE32(OP_SETCLIENTID_CONFIRM);
1255 WRITE64(client_state->cl_clientid);
1256 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1257
1258 return 0;
1259}
1260
1261static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1262{
Al Viro8687b632006-10-19 23:28:48 -07001263 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
1265 RESERVE_SPACE(4);
1266 WRITE32(OP_WRITE);
1267
1268 encode_stateid(xdr, args->context);
1269
1270 RESERVE_SPACE(16);
1271 WRITE64(args->offset);
1272 WRITE32(args->stable);
1273 WRITE32(args->count);
1274
1275 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1276
1277 return 0;
1278}
1279
1280static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1281{
Al Viro8687b632006-10-19 23:28:48 -07001282 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
1284 RESERVE_SPACE(20);
1285
1286 WRITE32(OP_DELEGRETURN);
1287 WRITEMEM(stateid->data, sizeof(stateid->data));
1288 return 0;
1289
1290}
1291/*
1292 * END OF "GENERIC" ENCODE ROUTINES.
1293 */
1294
1295/*
1296 * Encode an ACCESS request
1297 */
Al Viro8687b632006-10-19 23:28:48 -07001298static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299{
1300 struct xdr_stream xdr;
1301 struct compound_hdr hdr = {
1302 .nops = 2,
1303 };
1304 int status;
1305
1306 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1307 encode_compound_hdr(&xdr, &hdr);
1308 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1309 status = encode_access(&xdr, args->access);
1310 return status;
1311}
1312
1313/*
1314 * Encode LOOKUP request
1315 */
Al Viro8687b632006-10-19 23:28:48 -07001316static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317{
1318 struct xdr_stream xdr;
1319 struct compound_hdr hdr = {
1320 .nops = 4,
1321 };
1322 int status;
1323
1324 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1325 encode_compound_hdr(&xdr, &hdr);
1326 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1327 goto out;
1328 if ((status = encode_lookup(&xdr, args->name)) != 0)
1329 goto out;
1330 if ((status = encode_getfh(&xdr)) != 0)
1331 goto out;
1332 status = encode_getfattr(&xdr, args->bitmask);
1333out:
1334 return status;
1335}
1336
1337/*
1338 * Encode LOOKUP_ROOT request
1339 */
Al Viro8687b632006-10-19 23:28:48 -07001340static 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 -07001341{
1342 struct xdr_stream xdr;
1343 struct compound_hdr hdr = {
1344 .nops = 3,
1345 };
1346 int status;
1347
1348 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1349 encode_compound_hdr(&xdr, &hdr);
1350 if ((status = encode_putrootfh(&xdr)) != 0)
1351 goto out;
1352 if ((status = encode_getfh(&xdr)) == 0)
1353 status = encode_getfattr(&xdr, args->bitmask);
1354out:
1355 return status;
1356}
1357
1358/*
1359 * Encode REMOVE request
1360 */
Al Viro8687b632006-10-19 23:28:48 -07001361static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs4_remove_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362{
1363 struct xdr_stream xdr;
1364 struct compound_hdr hdr = {
Trond Myklebust16e42952005-10-27 22:12:44 -04001365 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 };
1367 int status;
1368
1369 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1370 encode_compound_hdr(&xdr, &hdr);
Trond Myklebust16e42952005-10-27 22:12:44 -04001371 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1372 goto out;
1373 if ((status = encode_remove(&xdr, args->name)) != 0)
1374 goto out;
1375 status = encode_getfattr(&xdr, args->bitmask);
1376out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 return status;
1378}
1379
1380/*
1381 * Encode RENAME request
1382 */
Al Viro8687b632006-10-19 23:28:48 -07001383static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384{
1385 struct xdr_stream xdr;
1386 struct compound_hdr hdr = {
Trond Myklebust6caf2c82005-10-27 22:12:43 -04001387 .nops = 7,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 };
1389 int status;
1390
1391 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1392 encode_compound_hdr(&xdr, &hdr);
1393 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1394 goto out;
1395 if ((status = encode_savefh(&xdr)) != 0)
1396 goto out;
1397 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1398 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04001399 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
1400 goto out;
1401 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1402 goto out;
1403 if ((status = encode_restorefh(&xdr)) != 0)
1404 goto out;
1405 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406out:
1407 return status;
1408}
1409
1410/*
1411 * Encode LINK request
1412 */
Al Viro8687b632006-10-19 23:28:48 -07001413static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414{
1415 struct xdr_stream xdr;
1416 struct compound_hdr hdr = {
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04001417 .nops = 7,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 };
1419 int status;
1420
1421 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1422 encode_compound_hdr(&xdr, &hdr);
1423 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1424 goto out;
1425 if ((status = encode_savefh(&xdr)) != 0)
1426 goto out;
1427 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1428 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04001429 if ((status = encode_link(&xdr, args->name)) != 0)
1430 goto out;
1431 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1432 goto out;
1433 if ((status = encode_restorefh(&xdr)) != 0)
1434 goto out;
1435 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436out:
1437 return status;
1438}
1439
1440/*
1441 * Encode CREATE request
1442 */
Al Viro8687b632006-10-19 23:28:48 -07001443static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
1445 struct xdr_stream xdr;
1446 struct compound_hdr hdr = {
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001447 .nops = 7,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 };
1449 int status;
1450
1451 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1452 encode_compound_hdr(&xdr, &hdr);
1453 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1454 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001455 if ((status = encode_savefh(&xdr)) != 0)
1456 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 if ((status = encode_create(&xdr, args)) != 0)
1458 goto out;
1459 if ((status = encode_getfh(&xdr)) != 0)
1460 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001461 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1462 goto out;
1463 if ((status = encode_restorefh(&xdr)) != 0)
1464 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 status = encode_getfattr(&xdr, args->bitmask);
1466out:
1467 return status;
1468}
1469
1470/*
1471 * Encode SYMLINK request
1472 */
Al Viro8687b632006-10-19 23:28:48 -07001473static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474{
1475 return nfs4_xdr_enc_create(req, p, args);
1476}
1477
1478/*
1479 * Encode GETATTR request
1480 */
Al Viro8687b632006-10-19 23:28:48 -07001481static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482{
1483 struct xdr_stream xdr;
1484 struct compound_hdr hdr = {
1485 .nops = 2,
1486 };
1487 int status;
1488
1489 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1490 encode_compound_hdr(&xdr, &hdr);
1491 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1492 status = encode_getfattr(&xdr, args->bitmask);
1493 return status;
1494}
1495
1496/*
1497 * Encode a CLOSE request
1498 */
Al Viro8687b632006-10-19 23:28:48 -07001499static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500{
1501 struct xdr_stream xdr;
1502 struct compound_hdr hdr = {
Trond Myklebust516a6af2005-10-27 22:12:41 -04001503 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 };
1505 int status;
1506
1507 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1508 encode_compound_hdr(&xdr, &hdr);
1509 status = encode_putfh(&xdr, args->fh);
1510 if(status)
1511 goto out;
1512 status = encode_close(&xdr, args);
Trond Myklebust516a6af2005-10-27 22:12:41 -04001513 if (status != 0)
1514 goto out;
1515 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516out:
1517 return status;
1518}
1519
1520/*
1521 * Encode an OPEN request
1522 */
Al Viro8687b632006-10-19 23:28:48 -07001523static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524{
1525 struct xdr_stream xdr;
1526 struct compound_hdr hdr = {
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001527 .nops = 7,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 };
1529 int status;
1530
1531 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1532 encode_compound_hdr(&xdr, &hdr);
1533 status = encode_putfh(&xdr, args->fh);
1534 if (status)
1535 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001536 status = encode_savefh(&xdr);
1537 if (status)
1538 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 status = encode_open(&xdr, args);
1540 if (status)
1541 goto out;
1542 status = encode_getfh(&xdr);
1543 if (status)
1544 goto out;
1545 status = encode_getfattr(&xdr, args->bitmask);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001546 if (status)
1547 goto out;
1548 status = encode_restorefh(&xdr);
1549 if (status)
1550 goto out;
1551 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552out:
1553 return status;
1554}
1555
1556/*
1557 * Encode an OPEN_CONFIRM request
1558 */
Al Viro8687b632006-10-19 23:28:48 -07001559static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560{
1561 struct xdr_stream xdr;
1562 struct compound_hdr hdr = {
1563 .nops = 2,
1564 };
1565 int status;
1566
1567 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1568 encode_compound_hdr(&xdr, &hdr);
1569 status = encode_putfh(&xdr, args->fh);
1570 if(status)
1571 goto out;
1572 status = encode_open_confirm(&xdr, args);
1573out:
1574 return status;
1575}
1576
1577/*
1578 * Encode an OPEN request with no attributes.
1579 */
Al Viro8687b632006-10-19 23:28:48 -07001580static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581{
1582 struct xdr_stream xdr;
1583 struct compound_hdr hdr = {
Trond Myklebust864472e2006-01-03 09:55:15 +01001584 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 };
1586 int status;
1587
1588 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1589 encode_compound_hdr(&xdr, &hdr);
1590 status = encode_putfh(&xdr, args->fh);
1591 if (status)
1592 goto out;
1593 status = encode_open(&xdr, args);
Trond Myklebust864472e2006-01-03 09:55:15 +01001594 if (status)
1595 goto out;
1596 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597out:
1598 return status;
1599}
1600
1601/*
1602 * Encode an OPEN_DOWNGRADE request
1603 */
Al Viro8687b632006-10-19 23:28:48 -07001604static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605{
1606 struct xdr_stream xdr;
1607 struct compound_hdr hdr = {
Trond Myklebust516a6af2005-10-27 22:12:41 -04001608 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 };
1610 int status;
1611
1612 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1613 encode_compound_hdr(&xdr, &hdr);
1614 status = encode_putfh(&xdr, args->fh);
1615 if (status)
1616 goto out;
1617 status = encode_open_downgrade(&xdr, args);
Trond Myklebust516a6af2005-10-27 22:12:41 -04001618 if (status != 0)
1619 goto out;
1620 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621out:
1622 return status;
1623}
1624
1625/*
1626 * Encode a LOCK request
1627 */
Al Viro8687b632006-10-19 23:28:48 -07001628static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629{
1630 struct xdr_stream xdr;
1631 struct compound_hdr hdr = {
1632 .nops = 2,
1633 };
1634 int status;
1635
1636 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1637 encode_compound_hdr(&xdr, &hdr);
1638 status = encode_putfh(&xdr, args->fh);
1639 if(status)
1640 goto out;
1641 status = encode_lock(&xdr, args);
1642out:
1643 return status;
1644}
1645
1646/*
1647 * Encode a LOCKT request
1648 */
Al Viro8687b632006-10-19 23:28:48 -07001649static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650{
1651 struct xdr_stream xdr;
1652 struct compound_hdr hdr = {
1653 .nops = 2,
1654 };
1655 int status;
1656
1657 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1658 encode_compound_hdr(&xdr, &hdr);
1659 status = encode_putfh(&xdr, args->fh);
1660 if(status)
1661 goto out;
1662 status = encode_lockt(&xdr, args);
1663out:
1664 return status;
1665}
1666
1667/*
1668 * Encode a LOCKU request
1669 */
Al Viro8687b632006-10-19 23:28:48 -07001670static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671{
1672 struct xdr_stream xdr;
1673 struct compound_hdr hdr = {
1674 .nops = 2,
1675 };
1676 int status;
1677
1678 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1679 encode_compound_hdr(&xdr, &hdr);
1680 status = encode_putfh(&xdr, args->fh);
1681 if(status)
1682 goto out;
1683 status = encode_locku(&xdr, args);
1684out:
1685 return status;
1686}
1687
1688/*
1689 * Encode a READLINK request
1690 */
Al Viro8687b632006-10-19 23:28:48 -07001691static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692{
1693 struct xdr_stream xdr;
1694 struct compound_hdr hdr = {
1695 .nops = 2,
1696 };
1697 int status;
1698
1699 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1700 encode_compound_hdr(&xdr, &hdr);
1701 status = encode_putfh(&xdr, args->fh);
1702 if(status)
1703 goto out;
1704 status = encode_readlink(&xdr, args, req);
1705out:
1706 return status;
1707}
1708
1709/*
1710 * Encode a READDIR request
1711 */
Al Viro8687b632006-10-19 23:28:48 -07001712static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713{
1714 struct xdr_stream xdr;
1715 struct compound_hdr hdr = {
1716 .nops = 2,
1717 };
1718 int status;
1719
1720 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1721 encode_compound_hdr(&xdr, &hdr);
1722 status = encode_putfh(&xdr, args->fh);
1723 if(status)
1724 goto out;
1725 status = encode_readdir(&xdr, args, req);
1726out:
1727 return status;
1728}
1729
1730/*
1731 * Encode a READ request
1732 */
Al Viro8687b632006-10-19 23:28:48 -07001733static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734{
1735 struct rpc_auth *auth = req->rq_task->tk_auth;
1736 struct xdr_stream xdr;
1737 struct compound_hdr hdr = {
1738 .nops = 2,
1739 };
1740 int replen, status;
1741
1742 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1743 encode_compound_hdr(&xdr, &hdr);
1744 status = encode_putfh(&xdr, args->fh);
1745 if (status)
1746 goto out;
1747 status = encode_read(&xdr, args);
1748 if (status)
1749 goto out;
1750
1751 /* set up reply kvec
1752 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1753 * + OP_READ + status + eof + datalen = 9
1754 */
1755 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1756 xdr_inline_pages(&req->rq_rcv_buf, replen,
1757 args->pages, args->pgbase, args->count);
1758out:
1759 return status;
1760}
1761
1762/*
1763 * Encode an SETATTR request
1764 */
Al Viro8687b632006-10-19 23:28:48 -07001765static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
1767{
1768 struct xdr_stream xdr;
1769 struct compound_hdr hdr = {
1770 .nops = 3,
1771 };
1772 int status;
1773
1774 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1775 encode_compound_hdr(&xdr, &hdr);
1776 status = encode_putfh(&xdr, args->fh);
1777 if(status)
1778 goto out;
1779 status = encode_setattr(&xdr, args, args->server);
1780 if(status)
1781 goto out;
1782 status = encode_getfattr(&xdr, args->bitmask);
1783out:
1784 return status;
1785}
1786
1787/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00001788 * Encode a GETACL request
1789 */
1790static int
Al Viro8687b632006-10-19 23:28:48 -07001791nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001792 struct nfs_getaclargs *args)
1793{
1794 struct xdr_stream xdr;
1795 struct rpc_auth *auth = req->rq_task->tk_auth;
1796 struct compound_hdr hdr = {
1797 .nops = 2,
1798 };
1799 int replen, status;
1800
1801 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1802 encode_compound_hdr(&xdr, &hdr);
1803 status = encode_putfh(&xdr, args->fh);
1804 if (status)
1805 goto out;
1806 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1807 /* set up reply buffer: */
1808 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1809 xdr_inline_pages(&req->rq_rcv_buf, replen,
1810 args->acl_pages, args->acl_pgbase, args->acl_len);
1811out:
1812 return status;
1813}
1814
1815/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 * Encode a WRITE request
1817 */
Al Viro8687b632006-10-19 23:28:48 -07001818static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819{
1820 struct xdr_stream xdr;
1821 struct compound_hdr hdr = {
Trond Myklebust4f9838c2005-10-27 22:12:44 -04001822 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 };
1824 int status;
1825
1826 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1827 encode_compound_hdr(&xdr, &hdr);
1828 status = encode_putfh(&xdr, args->fh);
1829 if (status)
1830 goto out;
1831 status = encode_write(&xdr, args);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04001832 if (status)
1833 goto out;
1834 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835out:
1836 return status;
1837}
1838
1839/*
1840 * a COMMIT request
1841 */
Al Viro8687b632006-10-19 23:28:48 -07001842static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843{
1844 struct xdr_stream xdr;
1845 struct compound_hdr hdr = {
Trond Myklebust4f9838c2005-10-27 22:12:44 -04001846 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 };
1848 int status;
1849
1850 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1851 encode_compound_hdr(&xdr, &hdr);
1852 status = encode_putfh(&xdr, args->fh);
1853 if (status)
1854 goto out;
1855 status = encode_commit(&xdr, args);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04001856 if (status)
1857 goto out;
1858 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859out:
1860 return status;
1861}
1862
1863/*
1864 * FSINFO request
1865 */
Al Viro8687b632006-10-19 23:28:48 -07001866static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867{
1868 struct xdr_stream xdr;
1869 struct compound_hdr hdr = {
1870 .nops = 2,
1871 };
1872 int status;
1873
1874 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1875 encode_compound_hdr(&xdr, &hdr);
1876 status = encode_putfh(&xdr, args->fh);
1877 if (!status)
1878 status = encode_fsinfo(&xdr, args->bitmask);
1879 return status;
1880}
1881
1882/*
1883 * a PATHCONF request
1884 */
Al Viro8687b632006-10-19 23:28:48 -07001885static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 struct xdr_stream xdr;
1888 struct compound_hdr hdr = {
1889 .nops = 2,
1890 };
1891 int status;
1892
1893 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1894 encode_compound_hdr(&xdr, &hdr);
1895 status = encode_putfh(&xdr, args->fh);
1896 if (!status)
1897 status = encode_getattr_one(&xdr,
1898 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1899 return status;
1900}
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 = {
1909 .nops = 2,
1910 };
1911 int status;
1912
1913 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1914 encode_compound_hdr(&xdr, &hdr);
1915 status = encode_putfh(&xdr, args->fh);
1916 if (status == 0)
1917 status = encode_getattr_two(&xdr,
1918 args->bitmask[0] & nfs4_statfs_bitmap[0],
1919 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1920 return status;
1921}
1922
1923/*
1924 * GETATTR_BITMAP request
1925 */
Al Viro8687b632006-10-19 23:28:48 -07001926static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927{
1928 struct xdr_stream xdr;
1929 struct compound_hdr hdr = {
1930 .nops = 2,
1931 };
1932 int status;
1933
1934 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1935 encode_compound_hdr(&xdr, &hdr);
1936 status = encode_putfh(&xdr, fhandle);
1937 if (status == 0)
1938 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1939 FATTR4_WORD0_LINK_SUPPORT|
1940 FATTR4_WORD0_SYMLINK_SUPPORT|
1941 FATTR4_WORD0_ACLSUPPORT);
1942 return status;
1943}
1944
1945/*
1946 * a RENEW request
1947 */
Al Viro8687b632006-10-19 23:28:48 -07001948static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949{
1950 struct xdr_stream xdr;
1951 struct compound_hdr hdr = {
1952 .nops = 1,
1953 };
1954
1955 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1956 encode_compound_hdr(&xdr, &hdr);
1957 return encode_renew(&xdr, clp);
1958}
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 = {
1967 .nops = 1,
1968 };
1969
1970 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1971 encode_compound_hdr(&xdr, &hdr);
1972 return encode_setclientid(&xdr, sc);
1973}
1974
1975/*
1976 * a SETCLIENTID_CONFIRM request
1977 */
Al Viro8687b632006-10-19 23:28:48 -07001978static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979{
1980 struct xdr_stream xdr;
1981 struct compound_hdr hdr = {
1982 .nops = 3,
1983 };
1984 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1985 int status;
1986
1987 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1988 encode_compound_hdr(&xdr, &hdr);
1989 status = encode_setclientid_confirm(&xdr, clp);
1990 if (!status)
1991 status = encode_putrootfh(&xdr);
1992 if (!status)
1993 status = encode_fsinfo(&xdr, lease_bitmap);
1994 return status;
1995}
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 = {
Trond Myklebustfa178f22006-01-03 09:55:38 +01002004 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 };
2006 int status;
2007
2008 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2009 encode_compound_hdr(&xdr, &hdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01002010 status = encode_putfh(&xdr, args->fhandle);
2011 if (status != 0)
2012 goto out;
2013 status = encode_delegreturn(&xdr, args->stateid);
2014 if (status != 0)
2015 goto out;
2016 status = encode_getfattr(&xdr, args->bitmask);
2017out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 return status;
2019}
2020
2021/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002022 * Encode FS_LOCATIONS request
2023 */
Al Viro8687b632006-10-19 23:28:48 -07002024static 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 -04002025{
2026 struct xdr_stream xdr;
2027 struct compound_hdr hdr = {
2028 .nops = 3,
2029 };
2030 struct rpc_auth *auth = req->rq_task->tk_auth;
2031 int replen;
2032 int status;
2033
2034 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2035 encode_compound_hdr(&xdr, &hdr);
2036 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
2037 goto out;
2038 if ((status = encode_lookup(&xdr, args->name)) != 0)
2039 goto out;
Manoj Naik830b8e32006-06-09 09:34:25 -04002040 if ((status = encode_fs_locations(&xdr, args->bitmask)) != 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002041 goto out;
2042 /* set up reply
Manoj Naik830b8e32006-06-09 09:34:25 -04002043 * toplevel_status + OP_PUTFH + status
Trond Myklebust683b57b2006-06-09 09:34:22 -04002044 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2045 */
2046 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2047 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2048 0, PAGE_SIZE);
2049out:
2050 return status;
2051}
2052
2053/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 * START OF "GENERIC" DECODE ROUTINES.
2055 * These may look a little ugly since they are imported from a "generic"
2056 * set of XDR encode/decode routines which are intended to be shared by
2057 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2058 *
2059 * If the pain of reading these is too great, it should be a straightforward
2060 * task to translate them into Linux-specific versions which are more
2061 * consistent with the style used in NFSv2/v3...
2062 */
2063#define READ32(x) (x) = ntohl(*p++)
2064#define READ64(x) do { \
2065 (x) = (u64)ntohl(*p++) << 32; \
2066 (x) |= ntohl(*p++); \
2067} while (0)
2068#define READTIME(x) do { \
2069 p++; \
2070 (x.tv_sec) = ntohl(*p++); \
2071 (x.tv_nsec) = ntohl(*p++); \
2072} while (0)
2073#define COPYMEM(x,nbytes) do { \
2074 memcpy((x), p, nbytes); \
2075 p += XDR_QUADLEN(nbytes); \
2076} while (0)
2077
2078#define READ_BUF(nbytes) do { \
2079 p = xdr_inline_decode(xdr, nbytes); \
2080 if (!p) { \
2081 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
2082 __FUNCTION__, __LINE__); \
2083 return -EIO; \
2084 } \
2085} while (0)
2086
Trond Myklebust683b57b2006-06-09 09:34:22 -04002087static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088{
Al Viro8687b632006-10-19 23:28:48 -07002089 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090
2091 READ_BUF(4);
2092 READ32(*len);
2093 READ_BUF(*len);
2094 *string = (char *)p;
2095 return 0;
2096}
2097
2098static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2099{
Al Viro8687b632006-10-19 23:28:48 -07002100 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
2102 READ_BUF(8);
2103 READ32(hdr->status);
2104 READ32(hdr->taglen);
2105
2106 READ_BUF(hdr->taglen + 4);
2107 hdr->tag = (char *)p;
2108 p += XDR_QUADLEN(hdr->taglen);
2109 READ32(hdr->nops);
2110 return 0;
2111}
2112
2113static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2114{
Al Viro8687b632006-10-19 23:28:48 -07002115 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 uint32_t opnum;
2117 int32_t nfserr;
2118
2119 READ_BUF(8);
2120 READ32(opnum);
2121 if (opnum != expected) {
2122 printk(KERN_NOTICE
2123 "nfs4_decode_op_hdr: Server returned operation"
2124 " %d but we issued a request for %d\n",
2125 opnum, expected);
2126 return -EIO;
2127 }
2128 READ32(nfserr);
2129 if (nfserr != NFS_OK)
David Howells0a8ea432006-08-22 20:06:08 -04002130 return -nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 return 0;
2132}
2133
2134/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002135static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136{
Al Viro8687b632006-10-19 23:28:48 -07002137 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002138 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 char *str;
2140
2141 READ_BUF(12);
2142 return decode_opaque_inline(xdr, &strlen, &str);
2143}
2144
2145static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2146{
Al Viro8687b632006-10-19 23:28:48 -07002147 uint32_t bmlen;
2148 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
2150 READ_BUF(4);
2151 READ32(bmlen);
2152
2153 bitmap[0] = bitmap[1] = 0;
2154 READ_BUF((bmlen << 2));
2155 if (bmlen > 0) {
2156 READ32(bitmap[0]);
2157 if (bmlen > 1)
2158 READ32(bitmap[1]);
2159 }
2160 return 0;
2161}
2162
Al Viro8687b632006-10-19 23:28:48 -07002163static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164{
Al Viro8687b632006-10-19 23:28:48 -07002165 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
2167 READ_BUF(4);
2168 READ32(*attrlen);
2169 *savep = xdr->p;
2170 return 0;
2171}
2172
2173static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2174{
2175 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2176 decode_attr_bitmap(xdr, bitmask);
2177 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2178 } else
2179 bitmask[0] = bitmask[1] = 0;
2180 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2181 return 0;
2182}
2183
2184static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2185{
Al Viro8687b632006-10-19 23:28:48 -07002186 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187
2188 *type = 0;
2189 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2190 return -EIO;
2191 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2192 READ_BUF(4);
2193 READ32(*type);
2194 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2195 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2196 return -EIO;
2197 }
2198 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2199 }
2200 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2201 return 0;
2202}
2203
2204static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2205{
Al Viro8687b632006-10-19 23:28:48 -07002206 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207
2208 *change = 0;
2209 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2210 return -EIO;
2211 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2212 READ_BUF(8);
2213 READ64(*change);
2214 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2215 }
2216 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2217 (unsigned long long)*change);
2218 return 0;
2219}
2220
2221static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2222{
Al Viro8687b632006-10-19 23:28:48 -07002223 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
2225 *size = 0;
2226 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2227 return -EIO;
2228 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2229 READ_BUF(8);
2230 READ64(*size);
2231 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2232 }
2233 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2234 return 0;
2235}
2236
2237static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2238{
Al Viro8687b632006-10-19 23:28:48 -07002239 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
2241 *res = 0;
2242 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2243 return -EIO;
2244 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2245 READ_BUF(4);
2246 READ32(*res);
2247 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2248 }
2249 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2250 return 0;
2251}
2252
2253static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2254{
Al Viro8687b632006-10-19 23:28:48 -07002255 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256
2257 *res = 0;
2258 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2259 return -EIO;
2260 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2261 READ_BUF(4);
2262 READ32(*res);
2263 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2264 }
2265 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2266 return 0;
2267}
2268
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002269static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270{
Al Viro8687b632006-10-19 23:28:48 -07002271 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272
2273 fsid->major = 0;
2274 fsid->minor = 0;
2275 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2276 return -EIO;
2277 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2278 READ_BUF(16);
2279 READ64(fsid->major);
2280 READ64(fsid->minor);
2281 bitmap[0] &= ~FATTR4_WORD0_FSID;
2282 }
2283 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2284 (unsigned long long)fsid->major,
2285 (unsigned long long)fsid->minor);
2286 return 0;
2287}
2288
2289static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2290{
Al Viro8687b632006-10-19 23:28:48 -07002291 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
2293 *res = 60;
2294 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2295 return -EIO;
2296 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2297 READ_BUF(4);
2298 READ32(*res);
2299 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2300 }
2301 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2302 return 0;
2303}
2304
2305static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2306{
Al Viro8687b632006-10-19 23:28:48 -07002307 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308
2309 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2310 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2311 return -EIO;
2312 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2313 READ_BUF(4);
2314 READ32(*res);
2315 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2316 }
2317 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2318 return 0;
2319}
2320
2321static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2322{
Al Viro8687b632006-10-19 23:28:48 -07002323 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
2325 *fileid = 0;
2326 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2327 return -EIO;
2328 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2329 READ_BUF(8);
2330 READ64(*fileid);
2331 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2332 }
2333 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2334 return 0;
2335}
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;
Manoj Naik99baf622006-06-09 09:34:24 -04002340
2341 *fileid = 0;
2342 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2343 return -EIO;
2344 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2345 READ_BUF(8);
2346 READ64(*fileid);
2347 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2348 }
2349 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2350 return 0;
2351}
2352
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2354{
Al Viro8687b632006-10-19 23:28:48 -07002355 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 int status = 0;
2357
2358 *res = 0;
2359 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2360 return -EIO;
2361 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2362 READ_BUF(8);
2363 READ64(*res);
2364 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2365 }
2366 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2367 return status;
2368}
2369
2370static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2371{
Al Viro8687b632006-10-19 23:28:48 -07002372 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 int status = 0;
2374
2375 *res = 0;
2376 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2377 return -EIO;
2378 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2379 READ_BUF(8);
2380 READ64(*res);
2381 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2382 }
2383 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2384 return status;
2385}
2386
2387static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2388{
Al Viro8687b632006-10-19 23:28:48 -07002389 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 int status = 0;
2391
2392 *res = 0;
2393 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2394 return -EIO;
2395 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2396 READ_BUF(8);
2397 READ64(*res);
2398 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2399 }
2400 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2401 return status;
2402}
2403
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002404static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2405{
2406 int n;
Al Viro8687b632006-10-19 23:28:48 -07002407 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002408 int status = 0;
2409
2410 READ_BUF(4);
2411 READ32(n);
Andy Adamson33a43f22006-06-09 09:34:30 -04002412 if (n < 0)
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002413 goto out_eio;
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;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002460 dprintk("%s: fsroot ", __FUNCTION__);
2461 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) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002470 int m;
2471 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);
2475 if (m <= 0)
2476 goto out_eio;
2477
2478 loc->nservers = 0;
2479 dprintk("%s: servers ", __FUNCTION__);
2480 while (loc->nservers < m) {
2481 struct nfs4_string *server = &loc->servers[loc->nservers];
2482 status = decode_opaque_inline(xdr, &server->len, &server->data);
2483 if (unlikely(status != 0))
2484 goto out_eio;
2485 dprintk("%s ", server->data);
2486 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2487 loc->nservers++;
2488 else {
2489 int i;
2490 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations);
2491 for (i = loc->nservers; i < m; i++) {
2492 int len;
2493 char *data;
2494 status = decode_opaque_inline(xdr, &len, &data);
2495 if (unlikely(status != 0))
2496 goto out_eio;
2497 }
2498 }
2499 }
2500 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002501 if (unlikely(status != 0))
2502 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002503 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002504 res->nlocations++;
2505 }
2506out:
2507 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status);
2508 return status;
2509out_eio:
2510 status = -EIO;
2511 goto out;
2512}
2513
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2515{
Al Viro8687b632006-10-19 23:28:48 -07002516 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 int status = 0;
2518
2519 *res = 0;
2520 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2521 return -EIO;
2522 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2523 READ_BUF(8);
2524 READ64(*res);
2525 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2526 }
2527 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2528 return status;
2529}
2530
2531static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2532{
Al Viro8687b632006-10-19 23:28:48 -07002533 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 int status = 0;
2535
2536 *maxlink = 1;
2537 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2538 return -EIO;
2539 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2540 READ_BUF(4);
2541 READ32(*maxlink);
2542 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2543 }
2544 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2545 return status;
2546}
2547
2548static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2549{
Al Viro8687b632006-10-19 23:28:48 -07002550 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 int status = 0;
2552
2553 *maxname = 1024;
2554 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2555 return -EIO;
2556 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2557 READ_BUF(4);
2558 READ32(*maxname);
2559 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2560 }
2561 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2562 return status;
2563}
2564
2565static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2566{
Al Viro8687b632006-10-19 23:28:48 -07002567 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 int status = 0;
2569
2570 *res = 1024;
2571 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2572 return -EIO;
2573 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2574 uint64_t maxread;
2575 READ_BUF(8);
2576 READ64(maxread);
2577 if (maxread > 0x7FFFFFFF)
2578 maxread = 0x7FFFFFFF;
2579 *res = (uint32_t)maxread;
2580 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2581 }
2582 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2583 return status;
2584}
2585
2586static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2587{
Al Viro8687b632006-10-19 23:28:48 -07002588 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 int status = 0;
2590
2591 *res = 1024;
2592 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2593 return -EIO;
2594 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2595 uint64_t maxwrite;
2596 READ_BUF(8);
2597 READ64(maxwrite);
2598 if (maxwrite > 0x7FFFFFFF)
2599 maxwrite = 0x7FFFFFFF;
2600 *res = (uint32_t)maxwrite;
2601 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2602 }
2603 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2604 return status;
2605}
2606
2607static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2608{
Al Viro8687b632006-10-19 23:28:48 -07002609 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610
2611 *mode = 0;
2612 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2613 return -EIO;
2614 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2615 READ_BUF(4);
2616 READ32(*mode);
2617 *mode &= ~S_IFMT;
2618 bitmap[1] &= ~FATTR4_WORD1_MODE;
2619 }
2620 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2621 return 0;
2622}
2623
2624static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2625{
Al Viro8687b632006-10-19 23:28:48 -07002626 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627
2628 *nlink = 1;
2629 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2630 return -EIO;
2631 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2632 READ_BUF(4);
2633 READ32(*nlink);
2634 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2635 }
2636 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2637 return 0;
2638}
2639
David Howellsadfa6f92006-08-22 20:06:08 -04002640static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, int32_t *uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641{
Al Viro8687b632006-10-19 23:28:48 -07002642 uint32_t len;
2643 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
2645 *uid = -2;
2646 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2647 return -EIO;
2648 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2649 READ_BUF(4);
2650 READ32(len);
2651 READ_BUF(len);
2652 if (len < XDR_MAX_NETOBJ) {
2653 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2654 dprintk("%s: nfs_map_name_to_uid failed!\n",
2655 __FUNCTION__);
2656 } else
2657 printk(KERN_WARNING "%s: name too long (%u)!\n",
2658 __FUNCTION__, len);
2659 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2660 }
2661 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2662 return 0;
2663}
2664
David Howellsadfa6f92006-08-22 20:06:08 -04002665static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, int32_t *gid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666{
Al Viro8687b632006-10-19 23:28:48 -07002667 uint32_t len;
2668 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669
2670 *gid = -2;
2671 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2672 return -EIO;
2673 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2674 READ_BUF(4);
2675 READ32(len);
2676 READ_BUF(len);
2677 if (len < XDR_MAX_NETOBJ) {
2678 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2679 dprintk("%s: nfs_map_group_to_gid failed!\n",
2680 __FUNCTION__);
2681 } else
2682 printk(KERN_WARNING "%s: name too long (%u)!\n",
2683 __FUNCTION__, len);
2684 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2685 }
2686 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2687 return 0;
2688}
2689
2690static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2691{
Al Viro8687b632006-10-19 23:28:48 -07002692 uint32_t major = 0, minor = 0;
2693 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694
2695 *rdev = MKDEV(0,0);
2696 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2697 return -EIO;
2698 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2699 dev_t tmp;
2700
2701 READ_BUF(8);
2702 READ32(major);
2703 READ32(minor);
2704 tmp = MKDEV(major, minor);
2705 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2706 *rdev = tmp;
2707 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2708 }
2709 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2710 return 0;
2711}
2712
2713static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2714{
Al Viro8687b632006-10-19 23:28:48 -07002715 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 int status = 0;
2717
2718 *res = 0;
2719 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2720 return -EIO;
2721 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2722 READ_BUF(8);
2723 READ64(*res);
2724 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2725 }
2726 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2727 return status;
2728}
2729
2730static int decode_attr_space_free(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_FREE - 1U)))
2737 return -EIO;
2738 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2739 READ_BUF(8);
2740 READ64(*res);
2741 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2742 }
2743 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2744 return status;
2745}
2746
2747static int decode_attr_space_total(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_TOTAL - 1U)))
2754 return -EIO;
2755 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2756 READ_BUF(8);
2757 READ64(*res);
2758 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2759 }
2760 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2761 return status;
2762}
2763
2764static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2765{
Al Viro8687b632006-10-19 23:28:48 -07002766 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767
2768 *used = 0;
2769 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2770 return -EIO;
2771 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2772 READ_BUF(8);
2773 READ64(*used);
2774 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2775 }
2776 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2777 (unsigned long long)*used);
2778 return 0;
2779}
2780
2781static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2782{
Al Viro8687b632006-10-19 23:28:48 -07002783 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 uint64_t sec;
2785 uint32_t nsec;
2786
2787 READ_BUF(12);
2788 READ64(sec);
2789 READ32(nsec);
2790 time->tv_sec = (time_t)sec;
2791 time->tv_nsec = (long)nsec;
2792 return 0;
2793}
2794
2795static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2796{
2797 int status = 0;
2798
2799 time->tv_sec = 0;
2800 time->tv_nsec = 0;
2801 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2802 return -EIO;
2803 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2804 status = decode_attr_time(xdr, time);
2805 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2806 }
2807 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2808 return status;
2809}
2810
2811static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2812{
2813 int status = 0;
2814
2815 time->tv_sec = 0;
2816 time->tv_nsec = 0;
2817 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2818 return -EIO;
2819 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2820 status = decode_attr_time(xdr, time);
2821 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2822 }
2823 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2824 return status;
2825}
2826
2827static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2828{
2829 int status = 0;
2830
2831 time->tv_sec = 0;
2832 time->tv_nsec = 0;
2833 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2834 return -EIO;
2835 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2836 status = decode_attr_time(xdr, time);
2837 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2838 }
2839 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2840 return status;
2841}
2842
Al Viro8687b632006-10-19 23:28:48 -07002843static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844{
2845 unsigned int attrwords = XDR_QUADLEN(attrlen);
2846 unsigned int nwords = xdr->p - savep;
2847
2848 if (unlikely(attrwords != nwords)) {
2849 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2850 __FUNCTION__,
2851 attrwords << 2,
2852 (attrwords < nwords) ? '<' : '>',
2853 nwords << 2);
2854 return -EIO;
2855 }
2856 return 0;
2857}
2858
2859static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2860{
Al Viro8687b632006-10-19 23:28:48 -07002861 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862
2863 READ_BUF(20);
2864 READ32(cinfo->atomic);
2865 READ64(cinfo->before);
2866 READ64(cinfo->after);
2867 return 0;
2868}
2869
2870static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2871{
Al Viro8687b632006-10-19 23:28:48 -07002872 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 uint32_t supp, acc;
2874 int status;
2875
2876 status = decode_op_hdr(xdr, OP_ACCESS);
2877 if (status)
2878 return status;
2879 READ_BUF(8);
2880 READ32(supp);
2881 READ32(acc);
2882 access->supported = supp;
2883 access->access = acc;
2884 return 0;
2885}
2886
2887static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2888{
Al Viro8687b632006-10-19 23:28:48 -07002889 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 int status;
2891
2892 status = decode_op_hdr(xdr, OP_CLOSE);
2893 if (status)
2894 return status;
2895 READ_BUF(sizeof(res->stateid.data));
2896 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2897 return 0;
2898}
2899
2900static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2901{
Al Viro8687b632006-10-19 23:28:48 -07002902 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 int status;
2904
2905 status = decode_op_hdr(xdr, OP_COMMIT);
2906 if (status)
2907 return status;
2908 READ_BUF(8);
2909 COPYMEM(res->verf->verifier, 8);
2910 return 0;
2911}
2912
2913static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2914{
Al Viro8687b632006-10-19 23:28:48 -07002915 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 uint32_t bmlen;
2917 int status;
2918
2919 status = decode_op_hdr(xdr, OP_CREATE);
2920 if (status)
2921 return status;
2922 if ((status = decode_change_info(xdr, cinfo)))
2923 return status;
2924 READ_BUF(4);
2925 READ32(bmlen);
2926 READ_BUF(bmlen << 2);
2927 return 0;
2928}
2929
2930static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2931{
Al Viro8687b632006-10-19 23:28:48 -07002932 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 uint32_t attrlen,
2934 bitmap[2] = {0};
2935 int status;
2936
2937 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2938 goto xdr_error;
2939 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2940 goto xdr_error;
2941 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2942 goto xdr_error;
2943 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2944 goto xdr_error;
2945 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2946 goto xdr_error;
2947 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2948 goto xdr_error;
2949 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2950 goto xdr_error;
2951 status = verify_attr_len(xdr, savep, attrlen);
2952xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04002953 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 return status;
2955}
2956
2957static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2958{
Al Viro8687b632006-10-19 23:28:48 -07002959 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 uint32_t attrlen,
2961 bitmap[2] = {0};
2962 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
2971 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2972 goto xdr_error;
2973 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2974 goto xdr_error;
2975 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2976 goto xdr_error;
2977 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2978 goto xdr_error;
2979 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2980 goto xdr_error;
2981 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2982 goto xdr_error;
2983
2984 status = verify_attr_len(xdr, savep, attrlen);
2985xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04002986 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 return status;
2988}
2989
2990static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2991{
Al Viro8687b632006-10-19 23:28:48 -07002992 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 uint32_t attrlen,
2994 bitmap[2] = {0};
2995 int status;
2996
2997 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2998 goto xdr_error;
2999 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3000 goto xdr_error;
3001 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3002 goto xdr_error;
3003
3004 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3005 goto xdr_error;
3006 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3007 goto xdr_error;
3008
3009 status = verify_attr_len(xdr, savep, attrlen);
3010xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04003011 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 return status;
3013}
3014
3015static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3016{
Al Viro8687b632006-10-19 23:28:48 -07003017 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 uint32_t attrlen,
3019 bitmap[2] = {0},
3020 type;
3021 int status, fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003022 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023
3024 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3025 goto xdr_error;
3026 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3027 goto xdr_error;
3028
3029 fattr->bitmap[0] = bitmap[0];
3030 fattr->bitmap[1] = bitmap[1];
3031
3032 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3033 goto xdr_error;
3034
3035
3036 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
3037 goto xdr_error;
3038 fattr->type = nfs_type2fmt[type].nfs2type;
3039 fmode = nfs_type2fmt[type].mode;
3040
3041 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
3042 goto xdr_error;
3043 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
3044 goto xdr_error;
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003045 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 goto xdr_error;
3047 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
3048 goto xdr_error;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003049 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003050 struct nfs4_fs_locations,
Trond Myklebust683b57b2006-06-09 09:34:22 -04003051 fattr))) != 0)
3052 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
3054 goto xdr_error;
3055 fattr->mode |= fmode;
3056 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
3057 goto xdr_error;
David Howells7539bba2006-08-22 20:06:09 -04003058 if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 goto xdr_error;
David Howells7539bba2006-08-22 20:06:09 -04003060 if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 goto xdr_error;
3062 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
3063 goto xdr_error;
3064 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
3065 goto xdr_error;
3066 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
3067 goto xdr_error;
3068 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
3069 goto xdr_error;
3070 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
3071 goto xdr_error;
Manoj Naik99baf622006-06-09 09:34:24 -04003072 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
3073 goto xdr_error;
3074 if (fattr->fileid == 0 && fileid != 0)
3075 fattr->fileid = fileid;
Trond Myklebust33801142005-10-27 22:12:39 -04003076 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04003079 dprintk("%s: xdr returned %d\n", __FUNCTION__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 return status;
3081}
3082
3083
3084static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3085{
Al Viro8687b632006-10-19 23:28:48 -07003086 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 uint32_t attrlen, bitmap[2];
3088 int status;
3089
3090 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3091 goto xdr_error;
3092 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3093 goto xdr_error;
3094 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3095 goto xdr_error;
3096
3097 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3098
3099 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3100 goto xdr_error;
3101 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3102 goto xdr_error;
3103 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3104 goto xdr_error;
3105 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3106 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3107 goto xdr_error;
3108 fsinfo->wtpref = fsinfo->wtmax;
3109
3110 status = verify_attr_len(xdr, savep, attrlen);
3111xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04003112 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 return status;
3114}
3115
3116static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3117{
Al Viro8687b632006-10-19 23:28:48 -07003118 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 uint32_t len;
3120 int status;
3121
3122 status = decode_op_hdr(xdr, OP_GETFH);
3123 if (status)
3124 return status;
3125 /* Zero handle first to allow comparisons */
3126 memset(fh, 0, sizeof(*fh));
3127
3128 READ_BUF(4);
3129 READ32(len);
3130 if (len > NFS4_FHSIZE)
3131 return -EIO;
3132 fh->size = len;
3133 READ_BUF(len);
3134 COPYMEM(fh->data, len);
3135 return 0;
3136}
3137
3138static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3139{
3140 int status;
3141
3142 status = decode_op_hdr(xdr, OP_LINK);
3143 if (status)
3144 return status;
3145 return decode_change_info(xdr, cinfo);
3146}
3147
3148/*
3149 * We create the owner, so we know a proper owner.id length is 4.
3150 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003151static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003153 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003154 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003155 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156
3157 READ_BUF(32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003158 READ64(offset);
3159 READ64(length);
3160 READ32(type);
3161 if (fl != NULL) {
3162 fl->fl_start = (loff_t)offset;
3163 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3164 if (length == ~(uint64_t)0)
3165 fl->fl_end = OFFSET_MAX;
3166 fl->fl_type = F_WRLCK;
3167 if (type & 1)
3168 fl->fl_type = F_RDLCK;
3169 fl->fl_pid = 0;
3170 }
3171 READ64(clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 READ32(namelen);
3173 READ_BUF(namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 return -NFS4ERR_DENIED;
3175}
3176
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003177static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178{
Al Viro8687b632006-10-19 23:28:48 -07003179 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 int status;
3181
3182 status = decode_op_hdr(xdr, OP_LOCK);
3183 if (status == 0) {
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003184 READ_BUF(sizeof(res->stateid.data));
3185 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 } else if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003187 return decode_lock_denied(xdr, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 return status;
3189}
3190
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003191static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192{
3193 int status;
3194 status = decode_op_hdr(xdr, OP_LOCKT);
3195 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003196 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 return status;
3198}
3199
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003200static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201{
Al Viro8687b632006-10-19 23:28:48 -07003202 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 int status;
3204
3205 status = decode_op_hdr(xdr, OP_LOCKU);
3206 if (status == 0) {
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003207 READ_BUF(sizeof(res->stateid.data));
3208 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 }
3210 return status;
3211}
3212
3213static int decode_lookup(struct xdr_stream *xdr)
3214{
3215 return decode_op_hdr(xdr, OP_LOOKUP);
3216}
3217
3218/* This is too sick! */
3219static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3220{
Al Viro8687b632006-10-19 23:28:48 -07003221 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 uint32_t limit_type, nblocks, blocksize;
3223
3224 READ_BUF(12);
3225 READ32(limit_type);
3226 switch (limit_type) {
3227 case 1:
3228 READ64(*maxsize);
3229 break;
3230 case 2:
3231 READ32(nblocks);
3232 READ32(blocksize);
3233 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3234 }
3235 return 0;
3236}
3237
3238static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3239{
Al Viro8687b632006-10-19 23:28:48 -07003240 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 uint32_t delegation_type;
3242
3243 READ_BUF(4);
3244 READ32(delegation_type);
3245 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3246 res->delegation_type = 0;
3247 return 0;
3248 }
3249 READ_BUF(20);
3250 COPYMEM(res->delegation.data, sizeof(res->delegation.data));
3251 READ32(res->do_recall);
3252 switch (delegation_type) {
3253 case NFS4_OPEN_DELEGATE_READ:
3254 res->delegation_type = FMODE_READ;
3255 break;
3256 case NFS4_OPEN_DELEGATE_WRITE:
3257 res->delegation_type = FMODE_WRITE|FMODE_READ;
3258 if (decode_space_limit(xdr, &res->maxsize) < 0)
3259 return -EIO;
3260 }
David Howells7539bba2006-08-22 20:06:09 -04003261 return decode_ace(xdr, NULL, res->server->nfs_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262}
3263
3264static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3265{
Al Viro8687b632006-10-19 23:28:48 -07003266 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 uint32_t bmlen;
3268 int status;
3269
3270 status = decode_op_hdr(xdr, OP_OPEN);
3271 if (status)
3272 return status;
3273 READ_BUF(sizeof(res->stateid.data));
3274 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3275
3276 decode_change_info(xdr, &res->cinfo);
3277
3278 READ_BUF(8);
3279 READ32(res->rflags);
3280 READ32(bmlen);
3281 if (bmlen > 10)
3282 goto xdr_error;
3283
3284 READ_BUF(bmlen << 2);
3285 p += bmlen;
3286 return decode_delegation(xdr, res);
3287xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04003288 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 return -EIO;
3290}
3291
3292static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3293{
Al Viro8687b632006-10-19 23:28:48 -07003294 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295 int status;
3296
3297 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3298 if (status)
3299 return status;
3300 READ_BUF(sizeof(res->stateid.data));
3301 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3302 return 0;
3303}
3304
3305static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3306{
Al Viro8687b632006-10-19 23:28:48 -07003307 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 int status;
3309
3310 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3311 if (status)
3312 return status;
3313 READ_BUF(sizeof(res->stateid.data));
3314 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3315 return 0;
3316}
3317
3318static int decode_putfh(struct xdr_stream *xdr)
3319{
3320 return decode_op_hdr(xdr, OP_PUTFH);
3321}
3322
3323static int decode_putrootfh(struct xdr_stream *xdr)
3324{
3325 return decode_op_hdr(xdr, OP_PUTROOTFH);
3326}
3327
3328static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3329{
3330 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07003331 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 uint32_t count, eof, recvd, hdrlen;
3333 int status;
3334
3335 status = decode_op_hdr(xdr, OP_READ);
3336 if (status)
3337 return status;
3338 READ_BUF(8);
3339 READ32(eof);
3340 READ32(count);
3341 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3342 recvd = req->rq_rcv_buf.len - hdrlen;
3343 if (count > recvd) {
3344 printk(KERN_WARNING "NFS: server cheating in read reply: "
3345 "count %u > recvd %u\n", count, recvd);
3346 count = recvd;
3347 eof = 0;
3348 }
3349 xdr_read_pages(xdr, count);
3350 res->eof = eof;
3351 res->count = count;
3352 return 0;
3353}
3354
3355static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3356{
3357 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3358 struct page *page = *rcvbuf->pages;
3359 struct kvec *iov = rcvbuf->head;
3360 unsigned int nr, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07003361 __be32 *end, *entry, *p, *kaddr;
David Howellse8896492006-08-24 15:44:19 -04003362 uint32_t len, attrlen, xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 int hdrlen, recvd, status;
3364
3365 status = decode_op_hdr(xdr, OP_READDIR);
3366 if (status)
3367 return status;
3368 READ_BUF(8);
3369 COPYMEM(readdir->verifier.data, 8);
Trond Myklebusteadf4592005-06-22 17:16:39 +00003370 dprintk("%s: verifier = 0x%x%x\n",
3371 __FUNCTION__,
3372 ((u32 *)readdir->verifier.data)[0],
3373 ((u32 *)readdir->verifier.data)[1]);
3374
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375
3376 hdrlen = (char *) p - (char *) iov->iov_base;
3377 recvd = rcvbuf->len - hdrlen;
3378 if (pglen > recvd)
3379 pglen = recvd;
3380 xdr_read_pages(xdr, pglen);
3381
3382 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07003383 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04003384 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 entry = p;
3386 for (nr = 0; *p++; nr++) {
David Howellse8896492006-08-24 15:44:19 -04003387 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003389 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 p += 2; /* cookie */
3391 len = ntohl(*p++); /* filename length */
3392 if (len > NFS4_MAXNAMLEN) {
3393 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3394 goto err_unmap;
3395 }
David Howellse8896492006-08-24 15:44:19 -04003396 xlen = XDR_QUADLEN(len);
3397 if (end - p < xlen + 1)
3398 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003399 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04003400 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04003402 if (end - p < len + 1)
3403 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04003406 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04003408 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 entry = p;
3410 }
3411 if (!nr && (entry[0] != 0 || entry[1] == 0))
3412 goto short_pkt;
3413out:
3414 kunmap_atomic(kaddr, KM_USER0);
3415 return 0;
3416short_pkt:
Trond Myklebusteadf4592005-06-22 17:16:39 +00003417 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 entry[0] = entry[1] = 0;
3419 /* truncate listing ? */
3420 if (!nr) {
3421 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3422 entry[1] = 1;
3423 }
3424 goto out;
3425err_unmap:
3426 kunmap_atomic(kaddr, KM_USER0);
3427 return -errno_NFSERR_IO;
3428}
3429
3430static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3431{
3432 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3433 struct kvec *iov = rcvbuf->head;
3434 int hdrlen, len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07003435 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 char *kaddr;
3437 int status;
3438
3439 status = decode_op_hdr(xdr, OP_READLINK);
3440 if (status)
3441 return status;
3442
3443 /* Convert length of symlink */
3444 READ_BUF(4);
3445 READ32(len);
3446 if (len >= rcvbuf->page_len || len <= 0) {
3447 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3448 return -ENAMETOOLONG;
3449 }
3450 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3451 recvd = req->rq_rcv_buf.len - hdrlen;
3452 if (recvd < len) {
3453 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3454 "count %u > recvd %u\n", len, recvd);
3455 return -EIO;
3456 }
3457 xdr_read_pages(xdr, len);
3458 /*
3459 * The XDR encode routine has set things up so that
3460 * the link text will be copied directly into the
3461 * buffer. We just have to do overflow-checking,
3462 * and and null-terminate the text (the VFS expects
3463 * null-termination).
3464 */
3465 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3466 kaddr[len+rcvbuf->page_base] = '\0';
3467 kunmap_atomic(kaddr, KM_USER0);
3468 return 0;
3469}
3470
3471static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3472{
3473 int status;
3474
3475 status = decode_op_hdr(xdr, OP_REMOVE);
3476 if (status)
3477 goto out;
3478 status = decode_change_info(xdr, cinfo);
3479out:
3480 return status;
3481}
3482
3483static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3484 struct nfs4_change_info *new_cinfo)
3485{
3486 int status;
3487
3488 status = decode_op_hdr(xdr, OP_RENAME);
3489 if (status)
3490 goto out;
3491 if ((status = decode_change_info(xdr, old_cinfo)))
3492 goto out;
3493 status = decode_change_info(xdr, new_cinfo);
3494out:
3495 return status;
3496}
3497
3498static int decode_renew(struct xdr_stream *xdr)
3499{
3500 return decode_op_hdr(xdr, OP_RENEW);
3501}
3502
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003503static int
3504decode_restorefh(struct xdr_stream *xdr)
3505{
3506 return decode_op_hdr(xdr, OP_RESTOREFH);
3507}
3508
J. Bruce Fields029d1052005-06-22 17:16:22 +00003509static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3510 size_t *acl_len)
3511{
Al Viro8687b632006-10-19 23:28:48 -07003512 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003513 uint32_t attrlen,
3514 bitmap[2] = {0};
3515 struct kvec *iov = req->rq_rcv_buf.head;
3516 int status;
3517
3518 *acl_len = 0;
3519 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3520 goto out;
3521 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3522 goto out;
3523 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3524 goto out;
3525
3526 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3527 return -EIO;
3528 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3529 int hdrlen, recvd;
3530
3531 /* We ignore &savep and don't do consistency checks on
3532 * the attr length. Let userspace figure it out.... */
3533 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3534 recvd = req->rq_rcv_buf.len - hdrlen;
3535 if (attrlen > recvd) {
3536 printk(KERN_WARNING "NFS: server cheating in getattr"
3537 " acl reply: attrlen %u > recvd %u\n",
3538 attrlen, recvd);
3539 return -EINVAL;
3540 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04003541 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00003542 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04003543 } else
3544 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003545
3546out:
3547 return status;
3548}
3549
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550static int
3551decode_savefh(struct xdr_stream *xdr)
3552{
3553 return decode_op_hdr(xdr, OP_SAVEFH);
3554}
3555
3556static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3557{
Al Viro8687b632006-10-19 23:28:48 -07003558 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 uint32_t bmlen;
3560 int status;
3561
3562
3563 status = decode_op_hdr(xdr, OP_SETATTR);
3564 if (status)
3565 return status;
3566 READ_BUF(4);
3567 READ32(bmlen);
3568 READ_BUF(bmlen << 2);
3569 return 0;
3570}
3571
David Howellsadfa6f92006-08-22 20:06:08 -04003572static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573{
Al Viro8687b632006-10-19 23:28:48 -07003574 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 uint32_t opnum;
3576 int32_t nfserr;
3577
3578 READ_BUF(8);
3579 READ32(opnum);
3580 if (opnum != OP_SETCLIENTID) {
3581 printk(KERN_NOTICE
3582 "nfs4_decode_setclientid: Server returned operation"
3583 " %d\n", opnum);
3584 return -EIO;
3585 }
3586 READ32(nfserr);
3587 if (nfserr == NFS_OK) {
3588 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3589 READ64(clp->cl_clientid);
3590 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3591 } else if (nfserr == NFSERR_CLID_INUSE) {
3592 uint32_t len;
3593
3594 /* skip netid string */
3595 READ_BUF(4);
3596 READ32(len);
3597 READ_BUF(len);
3598
3599 /* skip uaddr string */
3600 READ_BUF(4);
3601 READ32(len);
3602 READ_BUF(len);
3603 return -NFSERR_CLID_INUSE;
3604 } else
David Howells0a8ea432006-08-22 20:06:08 -04003605 return -nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606
3607 return 0;
3608}
3609
3610static int decode_setclientid_confirm(struct xdr_stream *xdr)
3611{
3612 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3613}
3614
3615static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3616{
Al Viro8687b632006-10-19 23:28:48 -07003617 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618 int status;
3619
3620 status = decode_op_hdr(xdr, OP_WRITE);
3621 if (status)
3622 return status;
3623
3624 READ_BUF(16);
3625 READ32(res->count);
3626 READ32(res->verf->committed);
3627 COPYMEM(res->verf->verifier, 8);
3628 return 0;
3629}
3630
3631static int decode_delegreturn(struct xdr_stream *xdr)
3632{
3633 return decode_op_hdr(xdr, OP_DELEGRETURN);
3634}
3635
3636/*
3637 * Decode OPEN_DOWNGRADE response
3638 */
Al Viro8687b632006-10-19 23:28:48 -07003639static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640{
3641 struct xdr_stream xdr;
3642 struct compound_hdr hdr;
3643 int status;
3644
3645 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3646 status = decode_compound_hdr(&xdr, &hdr);
3647 if (status)
3648 goto out;
3649 status = decode_putfh(&xdr);
3650 if (status)
3651 goto out;
3652 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04003653 if (status != 0)
3654 goto out;
3655 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656out:
3657 return status;
3658}
3659
3660/*
3661 * END OF "GENERIC" DECODE ROUTINES.
3662 */
3663
3664/*
3665 * Decode ACCESS response
3666 */
Al Viro8687b632006-10-19 23:28:48 -07003667static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668{
3669 struct xdr_stream xdr;
3670 struct compound_hdr hdr;
3671 int status;
3672
3673 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3674 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3675 goto out;
3676 if ((status = decode_putfh(&xdr)) == 0)
3677 status = decode_access(&xdr, res);
3678out:
3679 return status;
3680}
3681
3682/*
3683 * Decode LOOKUP response
3684 */
Al Viro8687b632006-10-19 23:28:48 -07003685static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686{
3687 struct xdr_stream xdr;
3688 struct compound_hdr hdr;
3689 int status;
3690
3691 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3692 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3693 goto out;
3694 if ((status = decode_putfh(&xdr)) != 0)
3695 goto out;
3696 if ((status = decode_lookup(&xdr)) != 0)
3697 goto out;
3698 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3699 goto out;
3700 status = decode_getfattr(&xdr, res->fattr, res->server);
3701out:
3702 return status;
3703}
3704
3705/*
3706 * Decode LOOKUP_ROOT response
3707 */
Al Viro8687b632006-10-19 23:28:48 -07003708static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709{
3710 struct xdr_stream xdr;
3711 struct compound_hdr hdr;
3712 int status;
3713
3714 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3715 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3716 goto out;
3717 if ((status = decode_putrootfh(&xdr)) != 0)
3718 goto out;
3719 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3720 status = decode_getfattr(&xdr, res->fattr, res->server);
3721out:
3722 return status;
3723}
3724
3725/*
3726 * Decode REMOVE response
3727 */
Al Viro8687b632006-10-19 23:28:48 -07003728static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_remove_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729{
3730 struct xdr_stream xdr;
3731 struct compound_hdr hdr;
3732 int status;
3733
3734 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3735 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3736 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04003737 if ((status = decode_putfh(&xdr)) != 0)
3738 goto out;
3739 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3740 goto out;
3741 decode_getfattr(&xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742out:
3743 return status;
3744}
3745
3746/*
3747 * Decode RENAME response
3748 */
Al Viro8687b632006-10-19 23:28:48 -07003749static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750{
3751 struct xdr_stream xdr;
3752 struct compound_hdr hdr;
3753 int status;
3754
3755 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3756 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3757 goto out;
3758 if ((status = decode_putfh(&xdr)) != 0)
3759 goto out;
3760 if ((status = decode_savefh(&xdr)) != 0)
3761 goto out;
3762 if ((status = decode_putfh(&xdr)) != 0)
3763 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04003764 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3765 goto out;
3766 /* Current FH is target directory */
3767 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3768 goto out;
3769 if ((status = decode_restorefh(&xdr)) != 0)
3770 goto out;
3771 decode_getfattr(&xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772out:
3773 return status;
3774}
3775
3776/*
3777 * Decode LINK response
3778 */
Al Viro8687b632006-10-19 23:28:48 -07003779static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780{
3781 struct xdr_stream xdr;
3782 struct compound_hdr hdr;
3783 int status;
3784
3785 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3786 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3787 goto out;
3788 if ((status = decode_putfh(&xdr)) != 0)
3789 goto out;
3790 if ((status = decode_savefh(&xdr)) != 0)
3791 goto out;
3792 if ((status = decode_putfh(&xdr)) != 0)
3793 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04003794 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3795 goto out;
3796 /*
3797 * Note order: OP_LINK leaves the directory as the current
3798 * filehandle.
3799 */
3800 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3801 goto out;
3802 if ((status = decode_restorefh(&xdr)) != 0)
3803 goto out;
3804 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805out:
3806 return status;
3807}
3808
3809/*
3810 * Decode CREATE response
3811 */
Al Viro8687b632006-10-19 23:28:48 -07003812static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813{
3814 struct xdr_stream xdr;
3815 struct compound_hdr hdr;
3816 int status;
3817
3818 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3819 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3820 goto out;
3821 if ((status = decode_putfh(&xdr)) != 0)
3822 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003823 if ((status = decode_savefh(&xdr)) != 0)
3824 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3826 goto out;
3827 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3828 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003829 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3830 goto out;
3831 if ((status = decode_restorefh(&xdr)) != 0)
3832 goto out;
3833 decode_getfattr(&xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834out:
3835 return status;
3836}
3837
3838/*
3839 * Decode SYMLINK response
3840 */
Al Viro8687b632006-10-19 23:28:48 -07003841static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842{
3843 return nfs4_xdr_dec_create(rqstp, p, res);
3844}
3845
3846/*
3847 * Decode GETATTR response
3848 */
Al Viro8687b632006-10-19 23:28:48 -07003849static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850{
3851 struct xdr_stream xdr;
3852 struct compound_hdr hdr;
3853 int status;
3854
3855 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3856 status = decode_compound_hdr(&xdr, &hdr);
3857 if (status)
3858 goto out;
3859 status = decode_putfh(&xdr);
3860 if (status)
3861 goto out;
3862 status = decode_getfattr(&xdr, res->fattr, res->server);
3863out:
3864 return status;
3865
3866}
3867
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003868/*
3869 * Encode an SETACL request
3870 */
3871static int
Al Viro8687b632006-10-19 23:28:48 -07003872nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003873{
3874 struct xdr_stream xdr;
3875 struct compound_hdr hdr = {
3876 .nops = 2,
3877 };
3878 int status;
3879
3880 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3881 encode_compound_hdr(&xdr, &hdr);
3882 status = encode_putfh(&xdr, args->fh);
3883 if (status)
3884 goto out;
3885 status = encode_setacl(&xdr, args);
3886out:
3887 return status;
3888}
3889/*
3890 * Decode SETACL response
3891 */
3892static int
Al Viro8687b632006-10-19 23:28:48 -07003893nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003894{
3895 struct xdr_stream xdr;
3896 struct compound_hdr hdr;
3897 int status;
3898
3899 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3900 status = decode_compound_hdr(&xdr, &hdr);
3901 if (status)
3902 goto out;
3903 status = decode_putfh(&xdr);
3904 if (status)
3905 goto out;
3906 status = decode_setattr(&xdr, res);
3907out:
3908 return status;
3909}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910
3911/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00003912 * Decode GETACL response
3913 */
3914static int
Al Viro8687b632006-10-19 23:28:48 -07003915nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
J. Bruce Fields029d1052005-06-22 17:16:22 +00003916{
3917 struct xdr_stream xdr;
3918 struct compound_hdr hdr;
3919 int status;
3920
3921 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3922 status = decode_compound_hdr(&xdr, &hdr);
3923 if (status)
3924 goto out;
3925 status = decode_putfh(&xdr);
3926 if (status)
3927 goto out;
3928 status = decode_getacl(&xdr, rqstp, acl_len);
3929
3930out:
3931 return status;
3932}
3933
3934/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935 * Decode CLOSE response
3936 */
Al Viro8687b632006-10-19 23:28:48 -07003937static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938{
3939 struct xdr_stream xdr;
3940 struct compound_hdr hdr;
3941 int status;
3942
3943 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3944 status = decode_compound_hdr(&xdr, &hdr);
3945 if (status)
3946 goto out;
3947 status = decode_putfh(&xdr);
3948 if (status)
3949 goto out;
3950 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04003951 if (status != 0)
3952 goto out;
3953 /*
3954 * Note: Server may do delete on close for this file
3955 * in which case the getattr call will fail with
3956 * an ESTALE error. Shouldn't be a problem,
3957 * though, since fattr->valid will remain unset.
3958 */
3959 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960out:
3961 return status;
3962}
3963
3964/*
3965 * Decode OPEN response
3966 */
Al Viro8687b632006-10-19 23:28:48 -07003967static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968{
3969 struct xdr_stream xdr;
3970 struct compound_hdr hdr;
3971 int status;
3972
3973 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3974 status = decode_compound_hdr(&xdr, &hdr);
3975 if (status)
3976 goto out;
3977 status = decode_putfh(&xdr);
3978 if (status)
3979 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003980 status = decode_savefh(&xdr);
3981 if (status)
3982 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983 status = decode_open(&xdr, res);
3984 if (status)
3985 goto out;
3986 status = decode_getfh(&xdr, &res->fh);
3987 if (status)
3988 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003989 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
3990 goto out;
3991 if ((status = decode_restorefh(&xdr)) != 0)
3992 goto out;
3993 decode_getfattr(&xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994out:
3995 return status;
3996}
3997
3998/*
3999 * Decode OPEN_CONFIRM response
4000 */
Al Viro8687b632006-10-19 23:28:48 -07004001static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002{
4003 struct xdr_stream xdr;
4004 struct compound_hdr hdr;
4005 int status;
4006
4007 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4008 status = decode_compound_hdr(&xdr, &hdr);
4009 if (status)
4010 goto out;
4011 status = decode_putfh(&xdr);
4012 if (status)
4013 goto out;
4014 status = decode_open_confirm(&xdr, res);
4015out:
4016 return status;
4017}
4018
4019/*
4020 * Decode OPEN response
4021 */
Al Viro8687b632006-10-19 23:28:48 -07004022static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004023{
4024 struct xdr_stream xdr;
4025 struct compound_hdr hdr;
4026 int status;
4027
4028 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4029 status = decode_compound_hdr(&xdr, &hdr);
4030 if (status)
4031 goto out;
4032 status = decode_putfh(&xdr);
4033 if (status)
4034 goto out;
4035 status = decode_open(&xdr, res);
Trond Myklebust864472e2006-01-03 09:55:15 +01004036 if (status)
4037 goto out;
4038 decode_getfattr(&xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039out:
4040 return status;
4041}
4042
4043/*
4044 * Decode SETATTR response
4045 */
Al Viro8687b632006-10-19 23:28:48 -07004046static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047{
4048 struct xdr_stream xdr;
4049 struct compound_hdr hdr;
4050 int status;
4051
4052 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4053 status = decode_compound_hdr(&xdr, &hdr);
4054 if (status)
4055 goto out;
4056 status = decode_putfh(&xdr);
4057 if (status)
4058 goto out;
4059 status = decode_setattr(&xdr, res);
4060 if (status)
4061 goto out;
4062 status = decode_getfattr(&xdr, res->fattr, res->server);
4063 if (status == NFS4ERR_DELAY)
4064 status = 0;
4065out:
4066 return status;
4067}
4068
4069/*
4070 * Decode LOCK response
4071 */
Al Viro8687b632006-10-19 23:28:48 -07004072static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073{
4074 struct xdr_stream xdr;
4075 struct compound_hdr hdr;
4076 int status;
4077
4078 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4079 status = decode_compound_hdr(&xdr, &hdr);
4080 if (status)
4081 goto out;
4082 status = decode_putfh(&xdr);
4083 if (status)
4084 goto out;
4085 status = decode_lock(&xdr, res);
4086out:
4087 return status;
4088}
4089
4090/*
4091 * Decode LOCKT response
4092 */
Al Viro8687b632006-10-19 23:28:48 -07004093static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094{
4095 struct xdr_stream xdr;
4096 struct compound_hdr hdr;
4097 int status;
4098
4099 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4100 status = decode_compound_hdr(&xdr, &hdr);
4101 if (status)
4102 goto out;
4103 status = decode_putfh(&xdr);
4104 if (status)
4105 goto out;
4106 status = decode_lockt(&xdr, res);
4107out:
4108 return status;
4109}
4110
4111/*
4112 * Decode LOCKU response
4113 */
Al Viro8687b632006-10-19 23:28:48 -07004114static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115{
4116 struct xdr_stream xdr;
4117 struct compound_hdr hdr;
4118 int status;
4119
4120 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4121 status = decode_compound_hdr(&xdr, &hdr);
4122 if (status)
4123 goto out;
4124 status = decode_putfh(&xdr);
4125 if (status)
4126 goto out;
4127 status = decode_locku(&xdr, res);
4128out:
4129 return status;
4130}
4131
4132/*
4133 * Decode READLINK response
4134 */
Al Viro8687b632006-10-19 23:28:48 -07004135static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136{
4137 struct xdr_stream xdr;
4138 struct compound_hdr hdr;
4139 int status;
4140
4141 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4142 status = decode_compound_hdr(&xdr, &hdr);
4143 if (status)
4144 goto out;
4145 status = decode_putfh(&xdr);
4146 if (status)
4147 goto out;
4148 status = decode_readlink(&xdr, rqstp);
4149out:
4150 return status;
4151}
4152
4153/*
4154 * Decode READDIR response
4155 */
Al Viro8687b632006-10-19 23:28:48 -07004156static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157{
4158 struct xdr_stream xdr;
4159 struct compound_hdr hdr;
4160 int status;
4161
4162 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4163 status = decode_compound_hdr(&xdr, &hdr);
4164 if (status)
4165 goto out;
4166 status = decode_putfh(&xdr);
4167 if (status)
4168 goto out;
4169 status = decode_readdir(&xdr, rqstp, res);
4170out:
4171 return status;
4172}
4173
4174/*
4175 * Decode Read response
4176 */
Al Viro8687b632006-10-19 23:28:48 -07004177static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178{
4179 struct xdr_stream xdr;
4180 struct compound_hdr hdr;
4181 int status;
4182
4183 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4184 status = decode_compound_hdr(&xdr, &hdr);
4185 if (status)
4186 goto out;
4187 status = decode_putfh(&xdr);
4188 if (status)
4189 goto out;
4190 status = decode_read(&xdr, rqstp, res);
4191 if (!status)
4192 status = res->count;
4193out:
4194 return status;
4195}
4196
4197/*
4198 * Decode WRITE response
4199 */
Al Viro8687b632006-10-19 23:28:48 -07004200static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201{
4202 struct xdr_stream xdr;
4203 struct compound_hdr hdr;
4204 int status;
4205
4206 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4207 status = decode_compound_hdr(&xdr, &hdr);
4208 if (status)
4209 goto out;
4210 status = decode_putfh(&xdr);
4211 if (status)
4212 goto out;
4213 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004214 if (status)
4215 goto out;
4216 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 if (!status)
4218 status = res->count;
4219out:
4220 return status;
4221}
4222
4223/*
4224 * Decode COMMIT response
4225 */
Al Viro8687b632006-10-19 23:28:48 -07004226static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227{
4228 struct xdr_stream xdr;
4229 struct compound_hdr hdr;
4230 int status;
4231
4232 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4233 status = decode_compound_hdr(&xdr, &hdr);
4234 if (status)
4235 goto out;
4236 status = decode_putfh(&xdr);
4237 if (status)
4238 goto out;
4239 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004240 if (status)
4241 goto out;
4242 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243out:
4244 return status;
4245}
4246
4247/*
4248 * FSINFO request
4249 */
Al Viro8687b632006-10-19 23:28:48 -07004250static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004251{
4252 struct xdr_stream xdr;
4253 struct compound_hdr hdr;
4254 int status;
4255
4256 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4257 status = decode_compound_hdr(&xdr, &hdr);
4258 if (!status)
4259 status = decode_putfh(&xdr);
4260 if (!status)
4261 status = decode_fsinfo(&xdr, fsinfo);
4262 if (!status)
David Howells0a8ea432006-08-22 20:06:08 -04004263 status = -nfs4_stat_to_errno(hdr.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264 return status;
4265}
4266
4267/*
4268 * PATHCONF request
4269 */
Al Viro8687b632006-10-19 23:28:48 -07004270static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271{
4272 struct xdr_stream xdr;
4273 struct compound_hdr hdr;
4274 int status;
4275
4276 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4277 status = decode_compound_hdr(&xdr, &hdr);
4278 if (!status)
4279 status = decode_putfh(&xdr);
4280 if (!status)
4281 status = decode_pathconf(&xdr, pathconf);
4282 return status;
4283}
4284
4285/*
4286 * STATFS request
4287 */
Al Viro8687b632006-10-19 23:28:48 -07004288static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289{
4290 struct xdr_stream xdr;
4291 struct compound_hdr hdr;
4292 int status;
4293
4294 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4295 status = decode_compound_hdr(&xdr, &hdr);
4296 if (!status)
4297 status = decode_putfh(&xdr);
4298 if (!status)
4299 status = decode_statfs(&xdr, fsstat);
4300 return status;
4301}
4302
4303/*
4304 * GETATTR_BITMAP request
4305 */
Al Viro8687b632006-10-19 23:28:48 -07004306static 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 -07004307{
4308 struct xdr_stream xdr;
4309 struct compound_hdr hdr;
4310 int status;
4311
4312 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4313 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4314 goto out;
4315 if ((status = decode_putfh(&xdr)) != 0)
4316 goto out;
4317 status = decode_server_caps(&xdr, res);
4318out:
4319 return status;
4320}
4321
4322/*
4323 * Decode RENEW response
4324 */
Al Viro8687b632006-10-19 23:28:48 -07004325static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326{
4327 struct xdr_stream xdr;
4328 struct compound_hdr hdr;
4329 int status;
4330
4331 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4332 status = decode_compound_hdr(&xdr, &hdr);
4333 if (!status)
4334 status = decode_renew(&xdr);
4335 return status;
4336}
4337
4338/*
4339 * a SETCLIENTID request
4340 */
Al Viro8687b632006-10-19 23:28:48 -07004341static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04004342 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343{
4344 struct xdr_stream xdr;
4345 struct compound_hdr hdr;
4346 int status;
4347
4348 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4349 status = decode_compound_hdr(&xdr, &hdr);
4350 if (!status)
4351 status = decode_setclientid(&xdr, clp);
4352 if (!status)
David Howells0a8ea432006-08-22 20:06:08 -04004353 status = -nfs4_stat_to_errno(hdr.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354 return status;
4355}
4356
4357/*
4358 * a SETCLIENTID_CONFIRM request
4359 */
Al Viro8687b632006-10-19 23:28:48 -07004360static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361{
4362 struct xdr_stream xdr;
4363 struct compound_hdr hdr;
4364 int status;
4365
4366 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4367 status = decode_compound_hdr(&xdr, &hdr);
4368 if (!status)
4369 status = decode_setclientid_confirm(&xdr);
4370 if (!status)
4371 status = decode_putrootfh(&xdr);
4372 if (!status)
4373 status = decode_fsinfo(&xdr, fsinfo);
4374 if (!status)
David Howells0a8ea432006-08-22 20:06:08 -04004375 status = -nfs4_stat_to_errno(hdr.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376 return status;
4377}
4378
4379/*
4380 * DELEGRETURN request
4381 */
Al Viro8687b632006-10-19 23:28:48 -07004382static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004383{
4384 struct xdr_stream xdr;
4385 struct compound_hdr hdr;
4386 int status;
4387
4388 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4389 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01004390 if (status != 0)
4391 goto out;
4392 status = decode_putfh(&xdr);
4393 if (status != 0)
4394 goto out;
4395 status = decode_delegreturn(&xdr);
4396 decode_getfattr(&xdr, res->fattr, res->server);
4397out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398 return status;
4399}
4400
Trond Myklebust683b57b2006-06-09 09:34:22 -04004401/*
4402 * FS_LOCATIONS request
4403 */
Al Viro8687b632006-10-19 23:28:48 -07004404static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004405{
4406 struct xdr_stream xdr;
4407 struct compound_hdr hdr;
4408 int status;
4409
4410 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4411 status = decode_compound_hdr(&xdr, &hdr);
4412 if (status != 0)
4413 goto out;
4414 if ((status = decode_putfh(&xdr)) != 0)
4415 goto out;
4416 if ((status = decode_lookup(&xdr)) != 0)
4417 goto out;
4418 xdr_enter_page(&xdr, PAGE_SIZE);
4419 status = decode_getfattr(&xdr, &res->fattr, res->server);
4420out:
4421 return status;
4422}
4423
Al Viro0dbb4c62006-10-19 23:28:49 -07004424__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425{
4426 uint32_t bitmap[2] = {0};
4427 uint32_t len;
4428
4429 if (!*p++) {
4430 if (!*p)
4431 return ERR_PTR(-EAGAIN);
4432 entry->eof = 1;
4433 return ERR_PTR(-EBADCOOKIE);
4434 }
4435
4436 entry->prev_cookie = entry->cookie;
4437 p = xdr_decode_hyper(p, &entry->cookie);
4438 entry->len = ntohl(*p++);
4439 entry->name = (const char *) p;
4440 p += XDR_QUADLEN(entry->len);
4441
4442 /*
4443 * In case the server doesn't return an inode number,
4444 * we fake one here. (We don't use inode number 0,
4445 * since glibc seems to choke on it...)
4446 */
4447 entry->ino = 1;
4448
4449 len = ntohl(*p++); /* bitmap length */
4450 if (len-- > 0) {
4451 bitmap[0] = ntohl(*p++);
4452 if (len-- > 0) {
4453 bitmap[1] = ntohl(*p++);
4454 p += len;
4455 }
4456 }
4457 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4458 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00004459 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4460 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4461 /* Ignore the return value of rdattr_error for now */
4462 p++;
4463 len--;
4464 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4466 xdr_decode_hyper(p, &entry->ino);
4467 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4468 xdr_decode_hyper(p, &entry->ino);
4469 p += len;
4470 }
4471
4472 entry->eof = !p[0] && p[1];
4473 return p;
4474}
4475
4476/*
4477 * We need to translate between nfs status return values and
4478 * the local errno values which may not be the same.
4479 */
4480static struct {
4481 int stat;
4482 int errno;
4483} nfs_errtbl[] = {
4484 { NFS4_OK, 0 },
4485 { NFS4ERR_PERM, EPERM },
4486 { NFS4ERR_NOENT, ENOENT },
4487 { NFS4ERR_IO, errno_NFSERR_IO },
4488 { NFS4ERR_NXIO, ENXIO },
4489 { NFS4ERR_ACCESS, EACCES },
4490 { NFS4ERR_EXIST, EEXIST },
4491 { NFS4ERR_XDEV, EXDEV },
4492 { NFS4ERR_NOTDIR, ENOTDIR },
4493 { NFS4ERR_ISDIR, EISDIR },
4494 { NFS4ERR_INVAL, EINVAL },
4495 { NFS4ERR_FBIG, EFBIG },
4496 { NFS4ERR_NOSPC, ENOSPC },
4497 { NFS4ERR_ROFS, EROFS },
4498 { NFS4ERR_MLINK, EMLINK },
4499 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4500 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4501 { NFS4ERR_DQUOT, EDQUOT },
4502 { NFS4ERR_STALE, ESTALE },
4503 { NFS4ERR_BADHANDLE, EBADHANDLE },
Manoj Naik6ebf3652005-06-22 17:16:39 +00004504 { NFS4ERR_BADOWNER, EINVAL },
4505 { NFS4ERR_BADNAME, EINVAL },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4507 { NFS4ERR_NOTSUPP, ENOTSUPP },
4508 { NFS4ERR_TOOSMALL, ETOOSMALL },
4509 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4510 { NFS4ERR_BADTYPE, EBADTYPE },
4511 { NFS4ERR_LOCKED, EAGAIN },
4512 { NFS4ERR_RESOURCE, EREMOTEIO },
4513 { NFS4ERR_SYMLINK, ELOOP },
4514 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4515 { NFS4ERR_DEADLOCK, EDEADLK },
4516 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4517 * to be handled by a
4518 * middle-layer.
4519 */
4520 { -1, EIO }
4521};
4522
4523/*
4524 * Convert an NFS error code to a local one.
4525 * This one is used jointly by NFSv2 and NFSv3.
4526 */
4527static int
David Howells0a8ea432006-08-22 20:06:08 -04004528nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529{
4530 int i;
4531 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4532 if (nfs_errtbl[i].stat == stat)
4533 return nfs_errtbl[i].errno;
4534 }
4535 if (stat <= 10000 || stat > 10100) {
4536 /* The server is looney tunes. */
4537 return ESERVERFAULT;
4538 }
4539 /* If we cannot translate the error, the recovery routines should
4540 * handle it.
4541 * Note: remaining NFSv4 error codes have values > 10000, so should
4542 * not conflict with native Linux error codes.
4543 */
4544 return stat;
4545}
4546
4547#ifndef MAX
4548# define MAX(a, b) (((a) > (b))? (a) : (b))
4549#endif
4550
4551#define PROC(proc, argtype, restype) \
4552[NFSPROC4_CLNT_##proc] = { \
4553 .p_proc = NFSPROC4_COMPOUND, \
4554 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4555 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4556 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
Chuck Levercc0175c2006-03-20 13:44:22 -05004557 .p_statidx = NFSPROC4_CLNT_##proc, \
4558 .p_name = #proc, \
Linus Torvalds1da177e2005-04-16 15:20:36 -07004559 }
4560
4561struct rpc_procinfo nfs4_procedures[] = {
4562 PROC(READ, enc_read, dec_read),
4563 PROC(WRITE, enc_write, dec_write),
4564 PROC(COMMIT, enc_commit, dec_commit),
4565 PROC(OPEN, enc_open, dec_open),
4566 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4567 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4568 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4569 PROC(CLOSE, enc_close, dec_close),
4570 PROC(SETATTR, enc_setattr, dec_setattr),
4571 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4572 PROC(RENEW, enc_renew, dec_renew),
4573 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4574 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4575 PROC(LOCK, enc_lock, dec_lock),
4576 PROC(LOCKT, enc_lockt, dec_lockt),
4577 PROC(LOCKU, enc_locku, dec_locku),
4578 PROC(ACCESS, enc_access, dec_access),
4579 PROC(GETATTR, enc_getattr, dec_getattr),
4580 PROC(LOOKUP, enc_lookup, dec_lookup),
4581 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4582 PROC(REMOVE, enc_remove, dec_remove),
4583 PROC(RENAME, enc_rename, dec_rename),
4584 PROC(LINK, enc_link, dec_link),
4585 PROC(SYMLINK, enc_symlink, dec_symlink),
4586 PROC(CREATE, enc_create, dec_create),
4587 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4588 PROC(STATFS, enc_statfs, dec_statfs),
4589 PROC(READLINK, enc_readlink, dec_readlink),
4590 PROC(READDIR, enc_readdir, dec_readdir),
4591 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4592 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00004593 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004594 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04004595 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596};
4597
4598struct rpc_version nfs_version4 = {
4599 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08004600 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601 .procs = nfs4_procedures
4602};
4603
4604/*
4605 * Local variables:
4606 * c-basic-offset: 8
4607 * End:
4608 */