blob: b8c28f2380a5bcf2aacb48cb45294df65379d21d [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 + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800390 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 encode_getattr_maxsz)
392#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800393 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 decode_getattr_maxsz)
395#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
396 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100397 encode_delegreturn_maxsz + \
398 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100400 decode_delegreturn_maxsz + \
401 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000402#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
403 encode_putfh_maxsz + \
404 encode_getattr_maxsz)
405#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
406 decode_putfh_maxsz + \
407 op_decode_hdr_maxsz + \
408 nfs4_fattr_bitmap_maxsz + 1)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000409#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
410 encode_putfh_maxsz + \
411 op_encode_hdr_maxsz + 4 + \
412 nfs4_fattr_bitmap_maxsz + 1)
413#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
414 decode_putfh_maxsz + \
415 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400416#define NFS4_enc_fs_locations_sz \
417 (compound_encode_hdr_maxsz + \
418 encode_putfh_maxsz + \
419 encode_getattr_maxsz)
420#define NFS4_dec_fs_locations_sz \
421 (compound_decode_hdr_maxsz + \
422 decode_putfh_maxsz + \
423 op_decode_hdr_maxsz + \
424 nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426static struct {
427 unsigned int mode;
428 unsigned int nfs2type;
429} nfs_type2fmt[] = {
430 { 0, NFNON },
431 { S_IFREG, NFREG },
432 { S_IFDIR, NFDIR },
433 { S_IFBLK, NFBLK },
434 { S_IFCHR, NFCHR },
435 { S_IFLNK, NFLNK },
436 { S_IFSOCK, NFSOCK },
437 { S_IFIFO, NFFIFO },
438 { 0, NFNON },
439 { 0, NFNON },
440};
441
442struct compound_hdr {
443 int32_t status;
444 uint32_t nops;
445 uint32_t taglen;
446 char * tag;
447};
448
449/*
450 * START OF "GENERIC" ENCODE ROUTINES.
451 * These may look a little ugly since they are imported from a "generic"
452 * set of XDR encode/decode routines which are intended to be shared by
453 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
454 *
455 * If the pain of reading these is too great, it should be a straightforward
456 * task to translate them into Linux-specific versions which are more
457 * consistent with the style used in NFSv2/v3...
458 */
459#define WRITE32(n) *p++ = htonl(n)
460#define WRITE64(n) do { \
461 *p++ = htonl((uint32_t)((n) >> 32)); \
462 *p++ = htonl((uint32_t)(n)); \
463} while (0)
464#define WRITEMEM(ptr,nbytes) do { \
465 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
466} while (0)
467
468#define RESERVE_SPACE(nbytes) do { \
469 p = xdr_reserve_space(xdr, nbytes); \
470 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
471 BUG_ON(!p); \
472} while (0)
473
474static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
475{
Al Viro8687b632006-10-19 23:28:48 -0700476 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478 p = xdr_reserve_space(xdr, 4 + len);
479 BUG_ON(p == NULL);
480 xdr_encode_opaque(p, str, len);
481}
482
483static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
484{
Al Viro8687b632006-10-19 23:28:48 -0700485 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
488 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
489 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
490 WRITE32(hdr->taglen);
491 WRITEMEM(hdr->tag, hdr->taglen);
492 WRITE32(NFS4_MINOR_VERSION);
493 WRITE32(hdr->nops);
494 return 0;
495}
496
497static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
498{
Al Viro8687b632006-10-19 23:28:48 -0700499 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
502 BUG_ON(p == NULL);
503 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
504}
505
506static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
507{
508 char owner_name[IDMAP_NAMESZ];
509 char owner_group[IDMAP_NAMESZ];
510 int owner_namelen = 0;
511 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700512 __be32 *p;
513 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 int len;
515 uint32_t bmval0 = 0;
516 uint32_t bmval1 = 0;
517 int status;
518
519 /*
520 * We reserve enough space to write the entire attribute buffer at once.
521 * In the worst-case, this would be
522 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
523 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000524 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 */
526 len = 16;
527
528 /* Sigh */
529 if (iap->ia_valid & ATTR_SIZE)
530 len += 8;
531 if (iap->ia_valid & ATTR_MODE)
532 len += 4;
533 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400534 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 if (owner_namelen < 0) {
536 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
537 iap->ia_uid);
538 /* XXX */
539 strcpy(owner_name, "nobody");
540 owner_namelen = sizeof("nobody") - 1;
541 /* goto out; */
542 }
543 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
544 }
545 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400546 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 if (owner_grouplen < 0) {
548 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
549 iap->ia_gid);
550 strcpy(owner_group, "nobody");
551 owner_grouplen = sizeof("nobody") - 1;
552 /* goto out; */
553 }
554 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
555 }
556 if (iap->ia_valid & ATTR_ATIME_SET)
557 len += 16;
558 else if (iap->ia_valid & ATTR_ATIME)
559 len += 4;
560 if (iap->ia_valid & ATTR_MTIME_SET)
561 len += 16;
562 else if (iap->ia_valid & ATTR_MTIME)
563 len += 4;
564 RESERVE_SPACE(len);
565
566 /*
567 * We write the bitmap length now, but leave the bitmap and the attribute
568 * buffer length to be backfilled at the end of this routine.
569 */
570 WRITE32(2);
571 q = p;
572 p += 3;
573
574 if (iap->ia_valid & ATTR_SIZE) {
575 bmval0 |= FATTR4_WORD0_SIZE;
576 WRITE64(iap->ia_size);
577 }
578 if (iap->ia_valid & ATTR_MODE) {
579 bmval1 |= FATTR4_WORD1_MODE;
Trond Myklebustcf3fff52006-01-03 09:55:53 +0100580 WRITE32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 }
582 if (iap->ia_valid & ATTR_UID) {
583 bmval1 |= FATTR4_WORD1_OWNER;
584 WRITE32(owner_namelen);
585 WRITEMEM(owner_name, owner_namelen);
586 }
587 if (iap->ia_valid & ATTR_GID) {
588 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
589 WRITE32(owner_grouplen);
590 WRITEMEM(owner_group, owner_grouplen);
591 }
592 if (iap->ia_valid & ATTR_ATIME_SET) {
593 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
594 WRITE32(NFS4_SET_TO_CLIENT_TIME);
595 WRITE32(0);
596 WRITE32(iap->ia_mtime.tv_sec);
597 WRITE32(iap->ia_mtime.tv_nsec);
598 }
599 else if (iap->ia_valid & ATTR_ATIME) {
600 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
601 WRITE32(NFS4_SET_TO_SERVER_TIME);
602 }
603 if (iap->ia_valid & ATTR_MTIME_SET) {
604 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
605 WRITE32(NFS4_SET_TO_CLIENT_TIME);
606 WRITE32(0);
607 WRITE32(iap->ia_mtime.tv_sec);
608 WRITE32(iap->ia_mtime.tv_nsec);
609 }
610 else if (iap->ia_valid & ATTR_MTIME) {
611 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
612 WRITE32(NFS4_SET_TO_SERVER_TIME);
613 }
614
615 /*
616 * Now we backfill the bitmap and the attribute buffer length.
617 */
618 if (len != ((char *)p - (char *)q) + 4) {
619 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
620 len, ((char *)p - (char *)q) + 4);
621 BUG();
622 }
623 len = (char *)p - (char *)q - 12;
624 *q++ = htonl(bmval0);
625 *q++ = htonl(bmval1);
626 *q++ = htonl(len);
627
628 status = 0;
629/* out: */
630 return status;
631}
632
633static int encode_access(struct xdr_stream *xdr, u32 access)
634{
Al Viro8687b632006-10-19 23:28:48 -0700635 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 RESERVE_SPACE(8);
638 WRITE32(OP_ACCESS);
639 WRITE32(access);
640
641 return 0;
642}
643
644static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
645{
Al Viro8687b632006-10-19 23:28:48 -0700646 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Trond Myklebust95121352005-10-18 14:20:12 -0700648 RESERVE_SPACE(8+sizeof(arg->stateid->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 WRITE32(OP_CLOSE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700650 WRITE32(arg->seqid->sequence->counter);
Trond Myklebust95121352005-10-18 14:20:12 -0700651 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653 return 0;
654}
655
656static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
657{
Al Viro8687b632006-10-19 23:28:48 -0700658 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
660 RESERVE_SPACE(16);
661 WRITE32(OP_COMMIT);
662 WRITE64(args->offset);
663 WRITE32(args->count);
664
665 return 0;
666}
667
668static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
669{
Al Viro8687b632006-10-19 23:28:48 -0700670 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
672 RESERVE_SPACE(8);
673 WRITE32(OP_CREATE);
674 WRITE32(create->ftype);
675
676 switch (create->ftype) {
677 case NF4LNK:
Chuck Lever94a6d752006-08-22 20:06:23 -0400678 RESERVE_SPACE(4);
679 WRITE32(create->u.symlink.len);
680 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 break;
682
683 case NF4BLK: case NF4CHR:
684 RESERVE_SPACE(8);
685 WRITE32(create->u.device.specdata1);
686 WRITE32(create->u.device.specdata2);
687 break;
688
689 default:
690 break;
691 }
692
693 RESERVE_SPACE(4 + create->name->len);
694 WRITE32(create->name->len);
695 WRITEMEM(create->name->name, create->name->len);
696
697 return encode_attrs(xdr, create->attrs, create->server);
698}
699
700static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
701{
Al Viro8687b632006-10-19 23:28:48 -0700702 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
704 RESERVE_SPACE(12);
705 WRITE32(OP_GETATTR);
706 WRITE32(1);
707 WRITE32(bitmap);
708 return 0;
709}
710
711static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
712{
Al Viro8687b632006-10-19 23:28:48 -0700713 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715 RESERVE_SPACE(16);
716 WRITE32(OP_GETATTR);
717 WRITE32(2);
718 WRITE32(bm0);
719 WRITE32(bm1);
720 return 0;
721}
722
723static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
724{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 return encode_getattr_two(xdr,
726 bitmask[0] & nfs4_fattr_bitmap[0],
727 bitmask[1] & nfs4_fattr_bitmap[1]);
728}
729
730static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
731{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
733 bitmask[1] & nfs4_fsinfo_bitmap[1]);
734}
735
Manoj Naik830b8e32006-06-09 09:34:25 -0400736static int encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask)
737{
738 return encode_getattr_two(xdr,
739 bitmask[0] & nfs4_fs_locations_bitmap[0],
740 bitmask[1] & nfs4_fs_locations_bitmap[1]);
741}
742
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743static int encode_getfh(struct xdr_stream *xdr)
744{
Al Viro8687b632006-10-19 23:28:48 -0700745 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 RESERVE_SPACE(4);
748 WRITE32(OP_GETFH);
749
750 return 0;
751}
752
753static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
754{
Al Viro8687b632006-10-19 23:28:48 -0700755 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
757 RESERVE_SPACE(8 + name->len);
758 WRITE32(OP_LINK);
759 WRITE32(name->len);
760 WRITEMEM(name->name, name->len);
761
762 return 0;
763}
764
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100765static inline int nfs4_lock_type(struct file_lock *fl, int block)
766{
767 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
768 return block ? NFS4_READW_LT : NFS4_READ_LT;
769 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
770}
771
772static inline uint64_t nfs4_lock_length(struct file_lock *fl)
773{
774 if (fl->fl_end == OFFSET_MAX)
775 return ~(uint64_t)0;
776 return fl->fl_end - fl->fl_start + 1;
777}
778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779/*
780 * opcode,type,reclaim,offset,length,new_lock_owner = 32
781 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
782 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100783static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784{
Al Viro8687b632006-10-19 23:28:48 -0700785 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 RESERVE_SPACE(32);
788 WRITE32(OP_LOCK);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100789 WRITE32(nfs4_lock_type(args->fl, args->block));
790 WRITE32(args->reclaim);
791 WRITE64(args->fl->fl_start);
792 WRITE64(nfs4_lock_length(args->fl));
793 WRITE32(args->new_lock_owner);
794 if (args->new_lock_owner){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 RESERVE_SPACE(40);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100796 WRITE32(args->open_seqid->sequence->counter);
797 WRITEMEM(args->open_stateid->data, sizeof(args->open_stateid->data));
798 WRITE32(args->lock_seqid->sequence->counter);
799 WRITE64(args->lock_owner.clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 WRITE32(4);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100801 WRITE32(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 }
803 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 RESERVE_SPACE(20);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100805 WRITEMEM(args->lock_stateid->data, sizeof(args->lock_stateid->data));
806 WRITE32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 }
808
809 return 0;
810}
811
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100812static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Al Viro8687b632006-10-19 23:28:48 -0700814 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
816 RESERVE_SPACE(40);
817 WRITE32(OP_LOCKT);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100818 WRITE32(nfs4_lock_type(args->fl, 0));
819 WRITE64(args->fl->fl_start);
820 WRITE64(nfs4_lock_length(args->fl));
821 WRITE64(args->lock_owner.clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 WRITE32(4);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100823 WRITE32(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825 return 0;
826}
827
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100828static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
Al Viro8687b632006-10-19 23:28:48 -0700830 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832 RESERVE_SPACE(44);
833 WRITE32(OP_LOCKU);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100834 WRITE32(nfs4_lock_type(args->fl, 0));
835 WRITE32(args->seqid->sequence->counter);
836 WRITEMEM(args->stateid->data, sizeof(args->stateid->data));
837 WRITE64(args->fl->fl_start);
838 WRITE64(nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840 return 0;
841}
842
843static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
844{
845 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -0700846 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
848 RESERVE_SPACE(8 + len);
849 WRITE32(OP_LOOKUP);
850 WRITE32(len);
851 WRITEMEM(name->name, len);
852
853 return 0;
854}
855
856static void encode_share_access(struct xdr_stream *xdr, int open_flags)
857{
Al Viro8687b632006-10-19 23:28:48 -0700858 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
860 RESERVE_SPACE(8);
861 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
862 case FMODE_READ:
863 WRITE32(NFS4_SHARE_ACCESS_READ);
864 break;
865 case FMODE_WRITE:
866 WRITE32(NFS4_SHARE_ACCESS_WRITE);
867 break;
868 case FMODE_READ|FMODE_WRITE:
869 WRITE32(NFS4_SHARE_ACCESS_BOTH);
870 break;
871 default:
872 BUG();
873 }
874 WRITE32(0); /* for linux, share_deny = 0 always */
875}
876
877static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
878{
Al Viro8687b632006-10-19 23:28:48 -0700879 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 /*
881 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
882 * owner 4 = 32
883 */
884 RESERVE_SPACE(8);
885 WRITE32(OP_OPEN);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700886 WRITE32(arg->seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 encode_share_access(xdr, arg->open_flags);
888 RESERVE_SPACE(16);
889 WRITE64(arg->clientid);
890 WRITE32(4);
891 WRITE32(arg->id);
892}
893
894static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
895{
Al Viro8687b632006-10-19 23:28:48 -0700896 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
898 RESERVE_SPACE(4);
899 switch(arg->open_flags & O_EXCL) {
900 case 0:
901 WRITE32(NFS4_CREATE_UNCHECKED);
902 encode_attrs(xdr, arg->u.attrs, arg->server);
903 break;
904 default:
905 WRITE32(NFS4_CREATE_EXCLUSIVE);
906 encode_nfs4_verifier(xdr, &arg->u.verifier);
907 }
908}
909
910static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
911{
Al Viro8687b632006-10-19 23:28:48 -0700912 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
914 RESERVE_SPACE(4);
915 switch (arg->open_flags & O_CREAT) {
916 case 0:
917 WRITE32(NFS4_OPEN_NOCREATE);
918 break;
919 default:
920 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
921 WRITE32(NFS4_OPEN_CREATE);
922 encode_createmode(xdr, arg);
923 }
924}
925
926static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
927{
Al Viro8687b632006-10-19 23:28:48 -0700928 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
930 RESERVE_SPACE(4);
931 switch (delegation_type) {
932 case 0:
933 WRITE32(NFS4_OPEN_DELEGATE_NONE);
934 break;
935 case FMODE_READ:
936 WRITE32(NFS4_OPEN_DELEGATE_READ);
937 break;
938 case FMODE_WRITE|FMODE_READ:
939 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
940 break;
941 default:
942 BUG();
943 }
944}
945
946static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
947{
Al Viro8687b632006-10-19 23:28:48 -0700948 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
950 RESERVE_SPACE(4);
951 WRITE32(NFS4_OPEN_CLAIM_NULL);
952 encode_string(xdr, name->len, name->name);
953}
954
955static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
956{
Al Viro8687b632006-10-19 23:28:48 -0700957 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959 RESERVE_SPACE(4);
960 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
961 encode_delegation_type(xdr, type);
962}
963
964static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
965{
Al Viro8687b632006-10-19 23:28:48 -0700966 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
968 RESERVE_SPACE(4+sizeof(stateid->data));
969 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
970 WRITEMEM(stateid->data, sizeof(stateid->data));
971 encode_string(xdr, name->len, name->name);
972}
973
974static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
975{
976 encode_openhdr(xdr, arg);
977 encode_opentype(xdr, arg);
978 switch (arg->claim) {
979 case NFS4_OPEN_CLAIM_NULL:
980 encode_claim_null(xdr, arg->name);
981 break;
982 case NFS4_OPEN_CLAIM_PREVIOUS:
983 encode_claim_previous(xdr, arg->u.delegation_type);
984 break;
985 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
986 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
987 break;
988 default:
989 BUG();
990 }
991 return 0;
992}
993
994static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
995{
Al Viro8687b632006-10-19 23:28:48 -0700996 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Trond Myklebustcdd4e682006-01-03 09:55:12 +0100998 RESERVE_SPACE(8+sizeof(arg->stateid->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 WRITE32(OP_OPEN_CONFIRM);
Trond Myklebustcdd4e682006-01-03 09:55:12 +01001000 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001001 WRITE32(arg->seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
1003 return 0;
1004}
1005
1006static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
1007{
Al Viro8687b632006-10-19 23:28:48 -07001008 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Trond Myklebust95121352005-10-18 14:20:12 -07001010 RESERVE_SPACE(8+sizeof(arg->stateid->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 WRITE32(OP_OPEN_DOWNGRADE);
Trond Myklebust95121352005-10-18 14:20:12 -07001012 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001013 WRITE32(arg->seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 encode_share_access(xdr, arg->open_flags);
1015 return 0;
1016}
1017
1018static int
1019encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
1020{
1021 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001022 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
1024 RESERVE_SPACE(8 + len);
1025 WRITE32(OP_PUTFH);
1026 WRITE32(len);
1027 WRITEMEM(fh->data, len);
1028
1029 return 0;
1030}
1031
1032static int encode_putrootfh(struct xdr_stream *xdr)
1033{
Al Viro8687b632006-10-19 23:28:48 -07001034 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
1036 RESERVE_SPACE(4);
1037 WRITE32(OP_PUTROOTFH);
1038
1039 return 0;
1040}
1041
1042static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1043{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001045 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
1047 RESERVE_SPACE(16);
1048 if (ctx->state != NULL) {
1049 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1050 WRITEMEM(stateid.data, sizeof(stateid.data));
1051 } else
1052 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1053}
1054
1055static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1056{
Al Viro8687b632006-10-19 23:28:48 -07001057 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
1059 RESERVE_SPACE(4);
1060 WRITE32(OP_READ);
1061
1062 encode_stateid(xdr, args->context);
1063
1064 RESERVE_SPACE(12);
1065 WRITE64(args->offset);
1066 WRITE32(args->count);
1067
1068 return 0;
1069}
1070
1071static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1072{
1073 struct rpc_auth *auth = req->rq_task->tk_auth;
Manoj Naik97d312d2005-06-22 17:16:39 +00001074 uint32_t attrs[2] = {
1075 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1076 FATTR4_WORD1_MOUNTED_ON_FILEID,
1077 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 int replen;
Al Viro8687b632006-10-19 23:28:48 -07001079 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
1081 RESERVE_SPACE(32+sizeof(nfs4_verifier));
1082 WRITE32(OP_READDIR);
1083 WRITE64(readdir->cookie);
1084 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1085 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1086 WRITE32(readdir->count);
1087 WRITE32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001088 /* Switch to mounted_on_fileid if the server supports it */
1089 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1090 attrs[0] &= ~FATTR4_WORD0_FILEID;
1091 else
1092 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1093 WRITE32(attrs[0] & readdir->bitmask[0]);
1094 WRITE32(attrs[1] & readdir->bitmask[1]);
Trond Myklebusteadf4592005-06-22 17:16:39 +00001095 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1096 __FUNCTION__,
1097 (unsigned long long)readdir->cookie,
1098 ((u32 *)readdir->verifier.data)[0],
1099 ((u32 *)readdir->verifier.data)[1],
1100 attrs[0] & readdir->bitmask[0],
1101 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
1103 /* set up reply kvec
1104 * toplevel_status + taglen + rescount + OP_PUTFH + status
1105 * + OP_READDIR + status + verifer(2) = 9
1106 */
1107 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1108 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1109 readdir->pgbase, readdir->count);
Trond Myklebusteadf4592005-06-22 17:16:39 +00001110 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1111 __FUNCTION__, replen, readdir->pages,
1112 readdir->pgbase, readdir->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
1114 return 0;
1115}
1116
1117static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1118{
1119 struct rpc_auth *auth = req->rq_task->tk_auth;
1120 unsigned int replen;
Al Viro8687b632006-10-19 23:28:48 -07001121 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
1123 RESERVE_SPACE(4);
1124 WRITE32(OP_READLINK);
1125
1126 /* set up reply kvec
1127 * toplevel_status + taglen + rescount + OP_PUTFH + status
1128 * + OP_READLINK + status + string length = 8
1129 */
1130 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1131 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1132 readlink->pgbase, readlink->pglen);
1133
1134 return 0;
1135}
1136
1137static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1138{
Al Viro8687b632006-10-19 23:28:48 -07001139 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
1141 RESERVE_SPACE(8 + name->len);
1142 WRITE32(OP_REMOVE);
1143 WRITE32(name->len);
1144 WRITEMEM(name->name, name->len);
1145
1146 return 0;
1147}
1148
1149static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1150{
Al Viro8687b632006-10-19 23:28:48 -07001151 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
1153 RESERVE_SPACE(8 + oldname->len);
1154 WRITE32(OP_RENAME);
1155 WRITE32(oldname->len);
1156 WRITEMEM(oldname->name, oldname->len);
1157
1158 RESERVE_SPACE(4 + newname->len);
1159 WRITE32(newname->len);
1160 WRITEMEM(newname->name, newname->len);
1161
1162 return 0;
1163}
1164
David Howellsadfa6f92006-08-22 20:06:08 -04001165static int encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166{
Al Viro8687b632006-10-19 23:28:48 -07001167 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
1169 RESERVE_SPACE(12);
1170 WRITE32(OP_RENEW);
1171 WRITE64(client_stateid->cl_clientid);
1172
1173 return 0;
1174}
1175
1176static int
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001177encode_restorefh(struct xdr_stream *xdr)
1178{
Al Viro8687b632006-10-19 23:28:48 -07001179 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001180
1181 RESERVE_SPACE(4);
1182 WRITE32(OP_RESTOREFH);
1183
1184 return 0;
1185}
1186
1187static int
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001188encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1189{
Al Viro8687b632006-10-19 23:28:48 -07001190 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001191
1192 RESERVE_SPACE(4+sizeof(zero_stateid.data));
1193 WRITE32(OP_SETATTR);
1194 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1195 RESERVE_SPACE(2*4);
1196 WRITE32(1);
1197 WRITE32(FATTR4_WORD0_ACL);
1198 if (arg->acl_len % 4)
1199 return -EINVAL;
1200 RESERVE_SPACE(4);
1201 WRITE32(arg->acl_len);
1202 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1203 return 0;
1204}
1205
1206static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207encode_savefh(struct xdr_stream *xdr)
1208{
Al Viro8687b632006-10-19 23:28:48 -07001209 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
1211 RESERVE_SPACE(4);
1212 WRITE32(OP_SAVEFH);
1213
1214 return 0;
1215}
1216
1217static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1218{
1219 int status;
Al Viro8687b632006-10-19 23:28:48 -07001220 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
1222 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1223 WRITE32(OP_SETATTR);
1224 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1225
1226 if ((status = encode_attrs(xdr, arg->iap, server)))
1227 return status;
1228
1229 return 0;
1230}
1231
1232static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1233{
Al Viro8687b632006-10-19 23:28:48 -07001234 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
1236 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1237 WRITE32(OP_SETCLIENTID);
1238 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1239
1240 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1241 RESERVE_SPACE(4);
1242 WRITE32(setclientid->sc_prog);
1243 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1244 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1245 RESERVE_SPACE(4);
1246 WRITE32(setclientid->sc_cb_ident);
1247
1248 return 0;
1249}
1250
David Howellsadfa6f92006-08-22 20:06:08 -04001251static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252{
Al Viro8687b632006-10-19 23:28:48 -07001253 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
1255 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1256 WRITE32(OP_SETCLIENTID_CONFIRM);
1257 WRITE64(client_state->cl_clientid);
1258 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1259
1260 return 0;
1261}
1262
1263static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1264{
Al Viro8687b632006-10-19 23:28:48 -07001265 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
1267 RESERVE_SPACE(4);
1268 WRITE32(OP_WRITE);
1269
1270 encode_stateid(xdr, args->context);
1271
1272 RESERVE_SPACE(16);
1273 WRITE64(args->offset);
1274 WRITE32(args->stable);
1275 WRITE32(args->count);
1276
1277 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1278
1279 return 0;
1280}
1281
1282static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1283{
Al Viro8687b632006-10-19 23:28:48 -07001284 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
1286 RESERVE_SPACE(20);
1287
1288 WRITE32(OP_DELEGRETURN);
1289 WRITEMEM(stateid->data, sizeof(stateid->data));
1290 return 0;
1291
1292}
1293/*
1294 * END OF "GENERIC" ENCODE ROUTINES.
1295 */
1296
1297/*
1298 * Encode an ACCESS request
1299 */
Al Viro8687b632006-10-19 23:28:48 -07001300static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301{
1302 struct xdr_stream xdr;
1303 struct compound_hdr hdr = {
1304 .nops = 2,
1305 };
1306 int status;
1307
1308 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1309 encode_compound_hdr(&xdr, &hdr);
1310 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1311 status = encode_access(&xdr, args->access);
1312 return status;
1313}
1314
1315/*
1316 * Encode LOOKUP request
1317 */
Al Viro8687b632006-10-19 23:28:48 -07001318static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319{
1320 struct xdr_stream xdr;
1321 struct compound_hdr hdr = {
1322 .nops = 4,
1323 };
1324 int status;
1325
1326 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1327 encode_compound_hdr(&xdr, &hdr);
1328 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1329 goto out;
1330 if ((status = encode_lookup(&xdr, args->name)) != 0)
1331 goto out;
1332 if ((status = encode_getfh(&xdr)) != 0)
1333 goto out;
1334 status = encode_getfattr(&xdr, args->bitmask);
1335out:
1336 return status;
1337}
1338
1339/*
1340 * Encode LOOKUP_ROOT request
1341 */
Al Viro8687b632006-10-19 23:28:48 -07001342static 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 -07001343{
1344 struct xdr_stream xdr;
1345 struct compound_hdr hdr = {
1346 .nops = 3,
1347 };
1348 int status;
1349
1350 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1351 encode_compound_hdr(&xdr, &hdr);
1352 if ((status = encode_putrootfh(&xdr)) != 0)
1353 goto out;
1354 if ((status = encode_getfh(&xdr)) == 0)
1355 status = encode_getfattr(&xdr, args->bitmask);
1356out:
1357 return status;
1358}
1359
1360/*
1361 * Encode REMOVE request
1362 */
Al Viro8687b632006-10-19 23:28:48 -07001363static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs4_remove_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364{
1365 struct xdr_stream xdr;
1366 struct compound_hdr hdr = {
Trond Myklebust16e42952005-10-27 22:12:44 -04001367 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 };
1369 int status;
1370
1371 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1372 encode_compound_hdr(&xdr, &hdr);
Trond Myklebust16e42952005-10-27 22:12:44 -04001373 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1374 goto out;
1375 if ((status = encode_remove(&xdr, args->name)) != 0)
1376 goto out;
1377 status = encode_getfattr(&xdr, args->bitmask);
1378out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 return status;
1380}
1381
1382/*
1383 * Encode RENAME request
1384 */
Al Viro8687b632006-10-19 23:28:48 -07001385static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386{
1387 struct xdr_stream xdr;
1388 struct compound_hdr hdr = {
Trond Myklebust6caf2c82005-10-27 22:12:43 -04001389 .nops = 7,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 };
1391 int status;
1392
1393 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1394 encode_compound_hdr(&xdr, &hdr);
1395 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1396 goto out;
1397 if ((status = encode_savefh(&xdr)) != 0)
1398 goto out;
1399 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1400 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04001401 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
1402 goto out;
1403 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1404 goto out;
1405 if ((status = encode_restorefh(&xdr)) != 0)
1406 goto out;
1407 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408out:
1409 return status;
1410}
1411
1412/*
1413 * Encode LINK request
1414 */
Al Viro8687b632006-10-19 23:28:48 -07001415static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416{
1417 struct xdr_stream xdr;
1418 struct compound_hdr hdr = {
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04001419 .nops = 7,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 };
1421 int status;
1422
1423 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1424 encode_compound_hdr(&xdr, &hdr);
1425 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1426 goto out;
1427 if ((status = encode_savefh(&xdr)) != 0)
1428 goto out;
1429 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1430 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04001431 if ((status = encode_link(&xdr, args->name)) != 0)
1432 goto out;
1433 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1434 goto out;
1435 if ((status = encode_restorefh(&xdr)) != 0)
1436 goto out;
1437 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438out:
1439 return status;
1440}
1441
1442/*
1443 * Encode CREATE request
1444 */
Al Viro8687b632006-10-19 23:28:48 -07001445static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446{
1447 struct xdr_stream xdr;
1448 struct compound_hdr hdr = {
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001449 .nops = 7,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 };
1451 int status;
1452
1453 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1454 encode_compound_hdr(&xdr, &hdr);
1455 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1456 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001457 if ((status = encode_savefh(&xdr)) != 0)
1458 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 if ((status = encode_create(&xdr, args)) != 0)
1460 goto out;
1461 if ((status = encode_getfh(&xdr)) != 0)
1462 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001463 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1464 goto out;
1465 if ((status = encode_restorefh(&xdr)) != 0)
1466 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 status = encode_getfattr(&xdr, args->bitmask);
1468out:
1469 return status;
1470}
1471
1472/*
1473 * Encode SYMLINK request
1474 */
Al Viro8687b632006-10-19 23:28:48 -07001475static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476{
1477 return nfs4_xdr_enc_create(req, p, args);
1478}
1479
1480/*
1481 * Encode GETATTR request
1482 */
Al Viro8687b632006-10-19 23:28:48 -07001483static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484{
1485 struct xdr_stream xdr;
1486 struct compound_hdr hdr = {
1487 .nops = 2,
1488 };
1489 int status;
1490
1491 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1492 encode_compound_hdr(&xdr, &hdr);
1493 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1494 status = encode_getfattr(&xdr, args->bitmask);
1495 return status;
1496}
1497
1498/*
1499 * Encode a CLOSE request
1500 */
Al Viro8687b632006-10-19 23:28:48 -07001501static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502{
1503 struct xdr_stream xdr;
1504 struct compound_hdr hdr = {
Trond Myklebust516a6af2005-10-27 22:12:41 -04001505 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 };
1507 int status;
1508
1509 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1510 encode_compound_hdr(&xdr, &hdr);
1511 status = encode_putfh(&xdr, args->fh);
1512 if(status)
1513 goto out;
1514 status = encode_close(&xdr, args);
Trond Myklebust516a6af2005-10-27 22:12:41 -04001515 if (status != 0)
1516 goto out;
1517 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518out:
1519 return status;
1520}
1521
1522/*
1523 * Encode an OPEN request
1524 */
Al Viro8687b632006-10-19 23:28:48 -07001525static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
1527 struct xdr_stream xdr;
1528 struct compound_hdr hdr = {
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001529 .nops = 7,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 };
1531 int status;
1532
1533 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1534 encode_compound_hdr(&xdr, &hdr);
1535 status = encode_putfh(&xdr, args->fh);
1536 if (status)
1537 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001538 status = encode_savefh(&xdr);
1539 if (status)
1540 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 status = encode_open(&xdr, args);
1542 if (status)
1543 goto out;
1544 status = encode_getfh(&xdr);
1545 if (status)
1546 goto out;
1547 status = encode_getfattr(&xdr, args->bitmask);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001548 if (status)
1549 goto out;
1550 status = encode_restorefh(&xdr);
1551 if (status)
1552 goto out;
1553 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554out:
1555 return status;
1556}
1557
1558/*
1559 * Encode an OPEN_CONFIRM request
1560 */
Al Viro8687b632006-10-19 23:28:48 -07001561static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562{
1563 struct xdr_stream xdr;
1564 struct compound_hdr hdr = {
1565 .nops = 2,
1566 };
1567 int status;
1568
1569 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1570 encode_compound_hdr(&xdr, &hdr);
1571 status = encode_putfh(&xdr, args->fh);
1572 if(status)
1573 goto out;
1574 status = encode_open_confirm(&xdr, args);
1575out:
1576 return status;
1577}
1578
1579/*
1580 * Encode an OPEN request with no attributes.
1581 */
Al Viro8687b632006-10-19 23:28:48 -07001582static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583{
1584 struct xdr_stream xdr;
1585 struct compound_hdr hdr = {
Trond Myklebust864472e2006-01-03 09:55:15 +01001586 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 };
1588 int status;
1589
1590 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1591 encode_compound_hdr(&xdr, &hdr);
1592 status = encode_putfh(&xdr, args->fh);
1593 if (status)
1594 goto out;
1595 status = encode_open(&xdr, args);
Trond Myklebust864472e2006-01-03 09:55:15 +01001596 if (status)
1597 goto out;
1598 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599out:
1600 return status;
1601}
1602
1603/*
1604 * Encode an OPEN_DOWNGRADE request
1605 */
Al Viro8687b632006-10-19 23:28:48 -07001606static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607{
1608 struct xdr_stream xdr;
1609 struct compound_hdr hdr = {
Trond Myklebust516a6af2005-10-27 22:12:41 -04001610 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 };
1612 int status;
1613
1614 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1615 encode_compound_hdr(&xdr, &hdr);
1616 status = encode_putfh(&xdr, args->fh);
1617 if (status)
1618 goto out;
1619 status = encode_open_downgrade(&xdr, args);
Trond Myklebust516a6af2005-10-27 22:12:41 -04001620 if (status != 0)
1621 goto out;
1622 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623out:
1624 return status;
1625}
1626
1627/*
1628 * Encode a LOCK request
1629 */
Al Viro8687b632006-10-19 23:28:48 -07001630static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631{
1632 struct xdr_stream xdr;
1633 struct compound_hdr hdr = {
1634 .nops = 2,
1635 };
1636 int status;
1637
1638 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1639 encode_compound_hdr(&xdr, &hdr);
1640 status = encode_putfh(&xdr, args->fh);
1641 if(status)
1642 goto out;
1643 status = encode_lock(&xdr, args);
1644out:
1645 return status;
1646}
1647
1648/*
1649 * Encode a LOCKT request
1650 */
Al Viro8687b632006-10-19 23:28:48 -07001651static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652{
1653 struct xdr_stream xdr;
1654 struct compound_hdr hdr = {
1655 .nops = 2,
1656 };
1657 int status;
1658
1659 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1660 encode_compound_hdr(&xdr, &hdr);
1661 status = encode_putfh(&xdr, args->fh);
1662 if(status)
1663 goto out;
1664 status = encode_lockt(&xdr, args);
1665out:
1666 return status;
1667}
1668
1669/*
1670 * Encode a LOCKU request
1671 */
Al Viro8687b632006-10-19 23:28:48 -07001672static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673{
1674 struct xdr_stream xdr;
1675 struct compound_hdr hdr = {
1676 .nops = 2,
1677 };
1678 int status;
1679
1680 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1681 encode_compound_hdr(&xdr, &hdr);
1682 status = encode_putfh(&xdr, args->fh);
1683 if(status)
1684 goto out;
1685 status = encode_locku(&xdr, args);
1686out:
1687 return status;
1688}
1689
1690/*
1691 * Encode a READLINK request
1692 */
Al Viro8687b632006-10-19 23:28:48 -07001693static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694{
1695 struct xdr_stream xdr;
1696 struct compound_hdr hdr = {
1697 .nops = 2,
1698 };
1699 int status;
1700
1701 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1702 encode_compound_hdr(&xdr, &hdr);
1703 status = encode_putfh(&xdr, args->fh);
1704 if(status)
1705 goto out;
1706 status = encode_readlink(&xdr, args, req);
1707out:
1708 return status;
1709}
1710
1711/*
1712 * Encode a READDIR request
1713 */
Al Viro8687b632006-10-19 23:28:48 -07001714static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715{
1716 struct xdr_stream xdr;
1717 struct compound_hdr hdr = {
1718 .nops = 2,
1719 };
1720 int status;
1721
1722 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1723 encode_compound_hdr(&xdr, &hdr);
1724 status = encode_putfh(&xdr, args->fh);
1725 if(status)
1726 goto out;
1727 status = encode_readdir(&xdr, args, req);
1728out:
1729 return status;
1730}
1731
1732/*
1733 * Encode a READ request
1734 */
Al Viro8687b632006-10-19 23:28:48 -07001735static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736{
1737 struct rpc_auth *auth = req->rq_task->tk_auth;
1738 struct xdr_stream xdr;
1739 struct compound_hdr hdr = {
1740 .nops = 2,
1741 };
1742 int replen, status;
1743
1744 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1745 encode_compound_hdr(&xdr, &hdr);
1746 status = encode_putfh(&xdr, args->fh);
1747 if (status)
1748 goto out;
1749 status = encode_read(&xdr, args);
1750 if (status)
1751 goto out;
1752
1753 /* set up reply kvec
1754 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1755 * + OP_READ + status + eof + datalen = 9
1756 */
1757 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1758 xdr_inline_pages(&req->rq_rcv_buf, replen,
1759 args->pages, args->pgbase, args->count);
1760out:
1761 return status;
1762}
1763
1764/*
1765 * Encode an SETATTR request
1766 */
Al Viro8687b632006-10-19 23:28:48 -07001767static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768
1769{
1770 struct xdr_stream xdr;
1771 struct compound_hdr hdr = {
1772 .nops = 3,
1773 };
1774 int status;
1775
1776 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1777 encode_compound_hdr(&xdr, &hdr);
1778 status = encode_putfh(&xdr, args->fh);
1779 if(status)
1780 goto out;
1781 status = encode_setattr(&xdr, args, args->server);
1782 if(status)
1783 goto out;
1784 status = encode_getfattr(&xdr, args->bitmask);
1785out:
1786 return status;
1787}
1788
1789/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00001790 * Encode a GETACL request
1791 */
1792static int
Al Viro8687b632006-10-19 23:28:48 -07001793nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001794 struct nfs_getaclargs *args)
1795{
1796 struct xdr_stream xdr;
1797 struct rpc_auth *auth = req->rq_task->tk_auth;
1798 struct compound_hdr hdr = {
1799 .nops = 2,
1800 };
1801 int replen, status;
1802
1803 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1804 encode_compound_hdr(&xdr, &hdr);
1805 status = encode_putfh(&xdr, args->fh);
1806 if (status)
1807 goto out;
1808 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1809 /* set up reply buffer: */
1810 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1811 xdr_inline_pages(&req->rq_rcv_buf, replen,
1812 args->acl_pages, args->acl_pgbase, args->acl_len);
1813out:
1814 return status;
1815}
1816
1817/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 * Encode a WRITE request
1819 */
Al Viro8687b632006-10-19 23:28:48 -07001820static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821{
1822 struct xdr_stream xdr;
1823 struct compound_hdr hdr = {
Trond Myklebust4f9838c2005-10-27 22:12:44 -04001824 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 };
1826 int status;
1827
1828 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1829 encode_compound_hdr(&xdr, &hdr);
1830 status = encode_putfh(&xdr, args->fh);
1831 if (status)
1832 goto out;
1833 status = encode_write(&xdr, args);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04001834 if (status)
1835 goto out;
1836 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837out:
1838 return status;
1839}
1840
1841/*
1842 * a COMMIT request
1843 */
Al Viro8687b632006-10-19 23:28:48 -07001844static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845{
1846 struct xdr_stream xdr;
1847 struct compound_hdr hdr = {
Trond Myklebust4f9838c2005-10-27 22:12:44 -04001848 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 };
1850 int status;
1851
1852 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1853 encode_compound_hdr(&xdr, &hdr);
1854 status = encode_putfh(&xdr, args->fh);
1855 if (status)
1856 goto out;
1857 status = encode_commit(&xdr, args);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04001858 if (status)
1859 goto out;
1860 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861out:
1862 return status;
1863}
1864
1865/*
1866 * FSINFO request
1867 */
Al Viro8687b632006-10-19 23:28:48 -07001868static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869{
1870 struct xdr_stream xdr;
1871 struct compound_hdr hdr = {
1872 .nops = 2,
1873 };
1874 int status;
1875
1876 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1877 encode_compound_hdr(&xdr, &hdr);
1878 status = encode_putfh(&xdr, args->fh);
1879 if (!status)
1880 status = encode_fsinfo(&xdr, args->bitmask);
1881 return status;
1882}
1883
1884/*
1885 * a PATHCONF request
1886 */
Al Viro8687b632006-10-19 23:28:48 -07001887static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 struct xdr_stream xdr;
1890 struct compound_hdr hdr = {
1891 .nops = 2,
1892 };
1893 int status;
1894
1895 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1896 encode_compound_hdr(&xdr, &hdr);
1897 status = encode_putfh(&xdr, args->fh);
1898 if (!status)
1899 status = encode_getattr_one(&xdr,
1900 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1901 return status;
1902}
1903
1904/*
1905 * a STATFS request
1906 */
Al Viro8687b632006-10-19 23:28:48 -07001907static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 struct xdr_stream xdr;
1910 struct compound_hdr hdr = {
1911 .nops = 2,
1912 };
1913 int status;
1914
1915 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1916 encode_compound_hdr(&xdr, &hdr);
1917 status = encode_putfh(&xdr, args->fh);
1918 if (status == 0)
1919 status = encode_getattr_two(&xdr,
1920 args->bitmask[0] & nfs4_statfs_bitmap[0],
1921 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1922 return status;
1923}
1924
1925/*
1926 * GETATTR_BITMAP request
1927 */
Al Viro8687b632006-10-19 23:28:48 -07001928static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929{
1930 struct xdr_stream xdr;
1931 struct compound_hdr hdr = {
1932 .nops = 2,
1933 };
1934 int status;
1935
1936 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1937 encode_compound_hdr(&xdr, &hdr);
1938 status = encode_putfh(&xdr, fhandle);
1939 if (status == 0)
1940 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1941 FATTR4_WORD0_LINK_SUPPORT|
1942 FATTR4_WORD0_SYMLINK_SUPPORT|
1943 FATTR4_WORD0_ACLSUPPORT);
1944 return status;
1945}
1946
1947/*
1948 * a RENEW request
1949 */
Al Viro8687b632006-10-19 23:28:48 -07001950static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951{
1952 struct xdr_stream xdr;
1953 struct compound_hdr hdr = {
1954 .nops = 1,
1955 };
1956
1957 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1958 encode_compound_hdr(&xdr, &hdr);
1959 return encode_renew(&xdr, clp);
1960}
1961
1962/*
1963 * a SETCLIENTID request
1964 */
Al Viro8687b632006-10-19 23:28:48 -07001965static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966{
1967 struct xdr_stream xdr;
1968 struct compound_hdr hdr = {
1969 .nops = 1,
1970 };
1971
1972 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1973 encode_compound_hdr(&xdr, &hdr);
1974 return encode_setclientid(&xdr, sc);
1975}
1976
1977/*
1978 * a SETCLIENTID_CONFIRM request
1979 */
Al Viro8687b632006-10-19 23:28:48 -07001980static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981{
1982 struct xdr_stream xdr;
1983 struct compound_hdr hdr = {
1984 .nops = 3,
1985 };
1986 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1987 int status;
1988
1989 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1990 encode_compound_hdr(&xdr, &hdr);
1991 status = encode_setclientid_confirm(&xdr, clp);
1992 if (!status)
1993 status = encode_putrootfh(&xdr);
1994 if (!status)
1995 status = encode_fsinfo(&xdr, lease_bitmap);
1996 return status;
1997}
1998
1999/*
2000 * DELEGRETURN request
2001 */
Al Viro8687b632006-10-19 23:28:48 -07002002static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003{
2004 struct xdr_stream xdr;
2005 struct compound_hdr hdr = {
Trond Myklebustfa178f22006-01-03 09:55:38 +01002006 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 };
2008 int status;
2009
2010 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2011 encode_compound_hdr(&xdr, &hdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01002012 status = encode_putfh(&xdr, args->fhandle);
2013 if (status != 0)
2014 goto out;
2015 status = encode_delegreturn(&xdr, args->stateid);
2016 if (status != 0)
2017 goto out;
2018 status = encode_getfattr(&xdr, args->bitmask);
2019out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 return status;
2021}
2022
2023/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002024 * Encode FS_LOCATIONS request
2025 */
Al Viro8687b632006-10-19 23:28:48 -07002026static 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 -04002027{
2028 struct xdr_stream xdr;
2029 struct compound_hdr hdr = {
2030 .nops = 3,
2031 };
2032 struct rpc_auth *auth = req->rq_task->tk_auth;
2033 int replen;
2034 int status;
2035
2036 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2037 encode_compound_hdr(&xdr, &hdr);
2038 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
2039 goto out;
2040 if ((status = encode_lookup(&xdr, args->name)) != 0)
2041 goto out;
Manoj Naik830b8e32006-06-09 09:34:25 -04002042 if ((status = encode_fs_locations(&xdr, args->bitmask)) != 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002043 goto out;
2044 /* set up reply
Manoj Naik830b8e32006-06-09 09:34:25 -04002045 * toplevel_status + OP_PUTFH + status
Trond Myklebust683b57b2006-06-09 09:34:22 -04002046 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2047 */
2048 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2049 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2050 0, PAGE_SIZE);
2051out:
2052 return status;
2053}
2054
2055/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 * START OF "GENERIC" DECODE ROUTINES.
2057 * These may look a little ugly since they are imported from a "generic"
2058 * set of XDR encode/decode routines which are intended to be shared by
2059 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2060 *
2061 * If the pain of reading these is too great, it should be a straightforward
2062 * task to translate them into Linux-specific versions which are more
2063 * consistent with the style used in NFSv2/v3...
2064 */
2065#define READ32(x) (x) = ntohl(*p++)
2066#define READ64(x) do { \
2067 (x) = (u64)ntohl(*p++) << 32; \
2068 (x) |= ntohl(*p++); \
2069} while (0)
2070#define READTIME(x) do { \
2071 p++; \
2072 (x.tv_sec) = ntohl(*p++); \
2073 (x.tv_nsec) = ntohl(*p++); \
2074} while (0)
2075#define COPYMEM(x,nbytes) do { \
2076 memcpy((x), p, nbytes); \
2077 p += XDR_QUADLEN(nbytes); \
2078} while (0)
2079
2080#define READ_BUF(nbytes) do { \
2081 p = xdr_inline_decode(xdr, nbytes); \
2082 if (!p) { \
2083 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
2084 __FUNCTION__, __LINE__); \
2085 return -EIO; \
2086 } \
2087} while (0)
2088
Trond Myklebust683b57b2006-06-09 09:34:22 -04002089static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090{
Al Viro8687b632006-10-19 23:28:48 -07002091 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092
2093 READ_BUF(4);
2094 READ32(*len);
2095 READ_BUF(*len);
2096 *string = (char *)p;
2097 return 0;
2098}
2099
2100static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2101{
Al Viro8687b632006-10-19 23:28:48 -07002102 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103
2104 READ_BUF(8);
2105 READ32(hdr->status);
2106 READ32(hdr->taglen);
2107
2108 READ_BUF(hdr->taglen + 4);
2109 hdr->tag = (char *)p;
2110 p += XDR_QUADLEN(hdr->taglen);
2111 READ32(hdr->nops);
2112 return 0;
2113}
2114
2115static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2116{
Al Viro8687b632006-10-19 23:28:48 -07002117 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 uint32_t opnum;
2119 int32_t nfserr;
2120
2121 READ_BUF(8);
2122 READ32(opnum);
2123 if (opnum != expected) {
2124 printk(KERN_NOTICE
2125 "nfs4_decode_op_hdr: Server returned operation"
2126 " %d but we issued a request for %d\n",
2127 opnum, expected);
2128 return -EIO;
2129 }
2130 READ32(nfserr);
2131 if (nfserr != NFS_OK)
David Howells0a8ea432006-08-22 20:06:08 -04002132 return -nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 return 0;
2134}
2135
2136/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002137static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138{
Al Viro8687b632006-10-19 23:28:48 -07002139 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002140 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 char *str;
2142
2143 READ_BUF(12);
2144 return decode_opaque_inline(xdr, &strlen, &str);
2145}
2146
2147static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2148{
Al Viro8687b632006-10-19 23:28:48 -07002149 uint32_t bmlen;
2150 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151
2152 READ_BUF(4);
2153 READ32(bmlen);
2154
2155 bitmap[0] = bitmap[1] = 0;
2156 READ_BUF((bmlen << 2));
2157 if (bmlen > 0) {
2158 READ32(bitmap[0]);
2159 if (bmlen > 1)
2160 READ32(bitmap[1]);
2161 }
2162 return 0;
2163}
2164
Al Viro8687b632006-10-19 23:28:48 -07002165static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166{
Al Viro8687b632006-10-19 23:28:48 -07002167 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
2169 READ_BUF(4);
2170 READ32(*attrlen);
2171 *savep = xdr->p;
2172 return 0;
2173}
2174
2175static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2176{
2177 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2178 decode_attr_bitmap(xdr, bitmask);
2179 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2180 } else
2181 bitmask[0] = bitmask[1] = 0;
2182 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2183 return 0;
2184}
2185
2186static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2187{
Al Viro8687b632006-10-19 23:28:48 -07002188 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189
2190 *type = 0;
2191 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2192 return -EIO;
2193 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2194 READ_BUF(4);
2195 READ32(*type);
2196 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2197 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2198 return -EIO;
2199 }
2200 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2201 }
2202 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2203 return 0;
2204}
2205
2206static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2207{
Al Viro8687b632006-10-19 23:28:48 -07002208 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
2210 *change = 0;
2211 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2212 return -EIO;
2213 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2214 READ_BUF(8);
2215 READ64(*change);
2216 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2217 }
2218 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2219 (unsigned long long)*change);
2220 return 0;
2221}
2222
2223static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2224{
Al Viro8687b632006-10-19 23:28:48 -07002225 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
2227 *size = 0;
2228 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2229 return -EIO;
2230 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2231 READ_BUF(8);
2232 READ64(*size);
2233 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2234 }
2235 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2236 return 0;
2237}
2238
2239static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2240{
Al Viro8687b632006-10-19 23:28:48 -07002241 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
2243 *res = 0;
2244 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2245 return -EIO;
2246 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2247 READ_BUF(4);
2248 READ32(*res);
2249 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2250 }
2251 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2252 return 0;
2253}
2254
2255static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2256{
Al Viro8687b632006-10-19 23:28:48 -07002257 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258
2259 *res = 0;
2260 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2261 return -EIO;
2262 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2263 READ_BUF(4);
2264 READ32(*res);
2265 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2266 }
2267 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2268 return 0;
2269}
2270
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002271static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272{
Al Viro8687b632006-10-19 23:28:48 -07002273 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274
2275 fsid->major = 0;
2276 fsid->minor = 0;
2277 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2278 return -EIO;
2279 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2280 READ_BUF(16);
2281 READ64(fsid->major);
2282 READ64(fsid->minor);
2283 bitmap[0] &= ~FATTR4_WORD0_FSID;
2284 }
2285 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2286 (unsigned long long)fsid->major,
2287 (unsigned long long)fsid->minor);
2288 return 0;
2289}
2290
2291static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2292{
Al Viro8687b632006-10-19 23:28:48 -07002293 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
2295 *res = 60;
2296 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2297 return -EIO;
2298 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2299 READ_BUF(4);
2300 READ32(*res);
2301 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2302 }
2303 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2304 return 0;
2305}
2306
2307static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2308{
Al Viro8687b632006-10-19 23:28:48 -07002309 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
2311 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2312 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2313 return -EIO;
2314 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2315 READ_BUF(4);
2316 READ32(*res);
2317 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2318 }
2319 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2320 return 0;
2321}
2322
2323static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2324{
Al Viro8687b632006-10-19 23:28:48 -07002325 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326
2327 *fileid = 0;
2328 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2329 return -EIO;
2330 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2331 READ_BUF(8);
2332 READ64(*fileid);
2333 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2334 }
2335 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2336 return 0;
2337}
2338
Manoj Naik99baf622006-06-09 09:34:24 -04002339static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2340{
Al Viro8687b632006-10-19 23:28:48 -07002341 __be32 *p;
Manoj Naik99baf622006-06-09 09:34:24 -04002342
2343 *fileid = 0;
2344 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2345 return -EIO;
2346 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2347 READ_BUF(8);
2348 READ64(*fileid);
2349 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2350 }
2351 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2352 return 0;
2353}
2354
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2356{
Al Viro8687b632006-10-19 23:28:48 -07002357 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 int status = 0;
2359
2360 *res = 0;
2361 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2362 return -EIO;
2363 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2364 READ_BUF(8);
2365 READ64(*res);
2366 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2367 }
2368 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2369 return status;
2370}
2371
2372static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2373{
Al Viro8687b632006-10-19 23:28:48 -07002374 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 int status = 0;
2376
2377 *res = 0;
2378 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2379 return -EIO;
2380 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2381 READ_BUF(8);
2382 READ64(*res);
2383 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2384 }
2385 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2386 return status;
2387}
2388
2389static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2390{
Al Viro8687b632006-10-19 23:28:48 -07002391 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 int status = 0;
2393
2394 *res = 0;
2395 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2396 return -EIO;
2397 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2398 READ_BUF(8);
2399 READ64(*res);
2400 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2401 }
2402 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2403 return status;
2404}
2405
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002406static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2407{
2408 int n;
Al Viro8687b632006-10-19 23:28:48 -07002409 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002410 int status = 0;
2411
2412 READ_BUF(4);
2413 READ32(n);
Andy Adamson33a43f22006-06-09 09:34:30 -04002414 if (n < 0)
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002415 goto out_eio;
Andy Adamson33a43f22006-06-09 09:34:30 -04002416 if (n == 0)
2417 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002418 dprintk("path ");
2419 path->ncomponents = 0;
2420 while (path->ncomponents < n) {
2421 struct nfs4_string *component = &path->components[path->ncomponents];
2422 status = decode_opaque_inline(xdr, &component->len, &component->data);
2423 if (unlikely(status != 0))
2424 goto out_eio;
2425 if (path->ncomponents != n)
2426 dprintk("/");
2427 dprintk("%s", component->data);
2428 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2429 path->ncomponents++;
2430 else {
2431 dprintk("cannot parse %d components in path\n", n);
2432 goto out_eio;
2433 }
2434 }
2435out:
2436 dprintk("\n");
2437 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002438root_path:
2439/* a root pathname is sent as a zero component4 */
2440 path->ncomponents = 1;
2441 path->components[0].len=0;
2442 path->components[0].data=NULL;
2443 dprintk("path /\n");
2444 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002445out_eio:
2446 dprintk(" status %d", status);
2447 status = -EIO;
2448 goto out;
2449}
2450
2451static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002452{
2453 int n;
Al Viro8687b632006-10-19 23:28:48 -07002454 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002455 int status = -EIO;
2456
2457 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2458 goto out;
2459 status = 0;
2460 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2461 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002462 dprintk("%s: fsroot ", __FUNCTION__);
2463 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002464 if (unlikely(status != 0))
2465 goto out;
2466 READ_BUF(4);
2467 READ32(n);
2468 if (n <= 0)
2469 goto out_eio;
2470 res->nlocations = 0;
2471 while (res->nlocations < n) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002472 int m;
2473 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04002474
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002475 READ_BUF(4);
2476 READ32(m);
2477 if (m <= 0)
2478 goto out_eio;
2479
2480 loc->nservers = 0;
2481 dprintk("%s: servers ", __FUNCTION__);
2482 while (loc->nservers < m) {
2483 struct nfs4_string *server = &loc->servers[loc->nservers];
2484 status = decode_opaque_inline(xdr, &server->len, &server->data);
2485 if (unlikely(status != 0))
2486 goto out_eio;
2487 dprintk("%s ", server->data);
2488 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2489 loc->nservers++;
2490 else {
2491 int i;
2492 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations);
2493 for (i = loc->nservers; i < m; i++) {
2494 int len;
2495 char *data;
2496 status = decode_opaque_inline(xdr, &len, &data);
2497 if (unlikely(status != 0))
2498 goto out_eio;
2499 }
2500 }
2501 }
2502 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002503 if (unlikely(status != 0))
2504 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002505 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002506 res->nlocations++;
2507 }
2508out:
2509 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status);
2510 return status;
2511out_eio:
2512 status = -EIO;
2513 goto out;
2514}
2515
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2517{
Al Viro8687b632006-10-19 23:28:48 -07002518 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 int status = 0;
2520
2521 *res = 0;
2522 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2523 return -EIO;
2524 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2525 READ_BUF(8);
2526 READ64(*res);
2527 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2528 }
2529 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2530 return status;
2531}
2532
2533static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2534{
Al Viro8687b632006-10-19 23:28:48 -07002535 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 int status = 0;
2537
2538 *maxlink = 1;
2539 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2540 return -EIO;
2541 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2542 READ_BUF(4);
2543 READ32(*maxlink);
2544 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2545 }
2546 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2547 return status;
2548}
2549
2550static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2551{
Al Viro8687b632006-10-19 23:28:48 -07002552 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 int status = 0;
2554
2555 *maxname = 1024;
2556 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2557 return -EIO;
2558 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2559 READ_BUF(4);
2560 READ32(*maxname);
2561 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2562 }
2563 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2564 return status;
2565}
2566
2567static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2568{
Al Viro8687b632006-10-19 23:28:48 -07002569 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 int status = 0;
2571
2572 *res = 1024;
2573 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2574 return -EIO;
2575 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2576 uint64_t maxread;
2577 READ_BUF(8);
2578 READ64(maxread);
2579 if (maxread > 0x7FFFFFFF)
2580 maxread = 0x7FFFFFFF;
2581 *res = (uint32_t)maxread;
2582 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2583 }
2584 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2585 return status;
2586}
2587
2588static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2589{
Al Viro8687b632006-10-19 23:28:48 -07002590 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 int status = 0;
2592
2593 *res = 1024;
2594 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2595 return -EIO;
2596 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2597 uint64_t maxwrite;
2598 READ_BUF(8);
2599 READ64(maxwrite);
2600 if (maxwrite > 0x7FFFFFFF)
2601 maxwrite = 0x7FFFFFFF;
2602 *res = (uint32_t)maxwrite;
2603 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2604 }
2605 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2606 return status;
2607}
2608
2609static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2610{
Al Viro8687b632006-10-19 23:28:48 -07002611 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612
2613 *mode = 0;
2614 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2615 return -EIO;
2616 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2617 READ_BUF(4);
2618 READ32(*mode);
2619 *mode &= ~S_IFMT;
2620 bitmap[1] &= ~FATTR4_WORD1_MODE;
2621 }
2622 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2623 return 0;
2624}
2625
2626static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2627{
Al Viro8687b632006-10-19 23:28:48 -07002628 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629
2630 *nlink = 1;
2631 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2632 return -EIO;
2633 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2634 READ_BUF(4);
2635 READ32(*nlink);
2636 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2637 }
2638 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2639 return 0;
2640}
2641
David Howellsadfa6f92006-08-22 20:06:08 -04002642static 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 -07002643{
Al Viro8687b632006-10-19 23:28:48 -07002644 uint32_t len;
2645 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646
2647 *uid = -2;
2648 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2649 return -EIO;
2650 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2651 READ_BUF(4);
2652 READ32(len);
2653 READ_BUF(len);
2654 if (len < XDR_MAX_NETOBJ) {
2655 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2656 dprintk("%s: nfs_map_name_to_uid failed!\n",
2657 __FUNCTION__);
2658 } else
2659 printk(KERN_WARNING "%s: name too long (%u)!\n",
2660 __FUNCTION__, len);
2661 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2662 }
2663 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2664 return 0;
2665}
2666
David Howellsadfa6f92006-08-22 20:06:08 -04002667static 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 -07002668{
Al Viro8687b632006-10-19 23:28:48 -07002669 uint32_t len;
2670 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671
2672 *gid = -2;
2673 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2674 return -EIO;
2675 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2676 READ_BUF(4);
2677 READ32(len);
2678 READ_BUF(len);
2679 if (len < XDR_MAX_NETOBJ) {
2680 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2681 dprintk("%s: nfs_map_group_to_gid failed!\n",
2682 __FUNCTION__);
2683 } else
2684 printk(KERN_WARNING "%s: name too long (%u)!\n",
2685 __FUNCTION__, len);
2686 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2687 }
2688 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2689 return 0;
2690}
2691
2692static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2693{
Al Viro8687b632006-10-19 23:28:48 -07002694 uint32_t major = 0, minor = 0;
2695 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696
2697 *rdev = MKDEV(0,0);
2698 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2699 return -EIO;
2700 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2701 dev_t tmp;
2702
2703 READ_BUF(8);
2704 READ32(major);
2705 READ32(minor);
2706 tmp = MKDEV(major, minor);
2707 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2708 *rdev = tmp;
2709 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2710 }
2711 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2712 return 0;
2713}
2714
2715static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2716{
Al Viro8687b632006-10-19 23:28:48 -07002717 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 int status = 0;
2719
2720 *res = 0;
2721 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2722 return -EIO;
2723 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2724 READ_BUF(8);
2725 READ64(*res);
2726 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2727 }
2728 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2729 return status;
2730}
2731
2732static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2733{
Al Viro8687b632006-10-19 23:28:48 -07002734 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 int status = 0;
2736
2737 *res = 0;
2738 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2739 return -EIO;
2740 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2741 READ_BUF(8);
2742 READ64(*res);
2743 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2744 }
2745 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2746 return status;
2747}
2748
2749static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2750{
Al Viro8687b632006-10-19 23:28:48 -07002751 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 int status = 0;
2753
2754 *res = 0;
2755 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2756 return -EIO;
2757 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2758 READ_BUF(8);
2759 READ64(*res);
2760 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2761 }
2762 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2763 return status;
2764}
2765
2766static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2767{
Al Viro8687b632006-10-19 23:28:48 -07002768 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769
2770 *used = 0;
2771 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2772 return -EIO;
2773 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2774 READ_BUF(8);
2775 READ64(*used);
2776 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2777 }
2778 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2779 (unsigned long long)*used);
2780 return 0;
2781}
2782
2783static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2784{
Al Viro8687b632006-10-19 23:28:48 -07002785 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 uint64_t sec;
2787 uint32_t nsec;
2788
2789 READ_BUF(12);
2790 READ64(sec);
2791 READ32(nsec);
2792 time->tv_sec = (time_t)sec;
2793 time->tv_nsec = (long)nsec;
2794 return 0;
2795}
2796
2797static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2798{
2799 int status = 0;
2800
2801 time->tv_sec = 0;
2802 time->tv_nsec = 0;
2803 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2804 return -EIO;
2805 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2806 status = decode_attr_time(xdr, time);
2807 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2808 }
2809 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2810 return status;
2811}
2812
2813static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2814{
2815 int status = 0;
2816
2817 time->tv_sec = 0;
2818 time->tv_nsec = 0;
2819 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2820 return -EIO;
2821 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2822 status = decode_attr_time(xdr, time);
2823 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2824 }
2825 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2826 return status;
2827}
2828
2829static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2830{
2831 int status = 0;
2832
2833 time->tv_sec = 0;
2834 time->tv_nsec = 0;
2835 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2836 return -EIO;
2837 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2838 status = decode_attr_time(xdr, time);
2839 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2840 }
2841 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2842 return status;
2843}
2844
Al Viro8687b632006-10-19 23:28:48 -07002845static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846{
2847 unsigned int attrwords = XDR_QUADLEN(attrlen);
2848 unsigned int nwords = xdr->p - savep;
2849
2850 if (unlikely(attrwords != nwords)) {
2851 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2852 __FUNCTION__,
2853 attrwords << 2,
2854 (attrwords < nwords) ? '<' : '>',
2855 nwords << 2);
2856 return -EIO;
2857 }
2858 return 0;
2859}
2860
2861static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2862{
Al Viro8687b632006-10-19 23:28:48 -07002863 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864
2865 READ_BUF(20);
2866 READ32(cinfo->atomic);
2867 READ64(cinfo->before);
2868 READ64(cinfo->after);
2869 return 0;
2870}
2871
2872static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2873{
Al Viro8687b632006-10-19 23:28:48 -07002874 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 uint32_t supp, acc;
2876 int status;
2877
2878 status = decode_op_hdr(xdr, OP_ACCESS);
2879 if (status)
2880 return status;
2881 READ_BUF(8);
2882 READ32(supp);
2883 READ32(acc);
2884 access->supported = supp;
2885 access->access = acc;
2886 return 0;
2887}
2888
2889static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2890{
Al Viro8687b632006-10-19 23:28:48 -07002891 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 int status;
2893
2894 status = decode_op_hdr(xdr, OP_CLOSE);
2895 if (status)
2896 return status;
2897 READ_BUF(sizeof(res->stateid.data));
2898 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2899 return 0;
2900}
2901
2902static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2903{
Al Viro8687b632006-10-19 23:28:48 -07002904 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 int status;
2906
2907 status = decode_op_hdr(xdr, OP_COMMIT);
2908 if (status)
2909 return status;
2910 READ_BUF(8);
2911 COPYMEM(res->verf->verifier, 8);
2912 return 0;
2913}
2914
2915static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2916{
Al Viro8687b632006-10-19 23:28:48 -07002917 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 uint32_t bmlen;
2919 int status;
2920
2921 status = decode_op_hdr(xdr, OP_CREATE);
2922 if (status)
2923 return status;
2924 if ((status = decode_change_info(xdr, cinfo)))
2925 return status;
2926 READ_BUF(4);
2927 READ32(bmlen);
2928 READ_BUF(bmlen << 2);
2929 return 0;
2930}
2931
2932static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2933{
Al Viro8687b632006-10-19 23:28:48 -07002934 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 uint32_t attrlen,
2936 bitmap[2] = {0};
2937 int status;
2938
2939 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2940 goto xdr_error;
2941 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2942 goto xdr_error;
2943 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2944 goto xdr_error;
2945 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2946 goto xdr_error;
2947 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2948 goto xdr_error;
2949 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2950 goto xdr_error;
2951 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2952 goto xdr_error;
2953 status = verify_attr_len(xdr, savep, attrlen);
2954xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04002955 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 return status;
2957}
2958
2959static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2960{
Al Viro8687b632006-10-19 23:28:48 -07002961 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 uint32_t attrlen,
2963 bitmap[2] = {0};
2964 int status;
2965
2966 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2967 goto xdr_error;
2968 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2969 goto xdr_error;
2970 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2971 goto xdr_error;
2972
2973 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2974 goto xdr_error;
2975 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2976 goto xdr_error;
2977 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2978 goto xdr_error;
2979 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2980 goto xdr_error;
2981 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2982 goto xdr_error;
2983 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2984 goto xdr_error;
2985
2986 status = verify_attr_len(xdr, savep, attrlen);
2987xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04002988 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 return status;
2990}
2991
2992static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2993{
Al Viro8687b632006-10-19 23:28:48 -07002994 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 uint32_t attrlen,
2996 bitmap[2] = {0};
2997 int status;
2998
2999 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3000 goto xdr_error;
3001 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3002 goto xdr_error;
3003 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3004 goto xdr_error;
3005
3006 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3007 goto xdr_error;
3008 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3009 goto xdr_error;
3010
3011 status = verify_attr_len(xdr, savep, attrlen);
3012xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04003013 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 return status;
3015}
3016
3017static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3018{
Al Viro8687b632006-10-19 23:28:48 -07003019 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 uint32_t attrlen,
3021 bitmap[2] = {0},
3022 type;
3023 int status, fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003024 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025
3026 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3027 goto xdr_error;
3028 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3029 goto xdr_error;
3030
3031 fattr->bitmap[0] = bitmap[0];
3032 fattr->bitmap[1] = bitmap[1];
3033
3034 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3035 goto xdr_error;
3036
3037
3038 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
3039 goto xdr_error;
3040 fattr->type = nfs_type2fmt[type].nfs2type;
3041 fmode = nfs_type2fmt[type].mode;
3042
3043 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
3044 goto xdr_error;
3045 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
3046 goto xdr_error;
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003047 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 goto xdr_error;
3049 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
3050 goto xdr_error;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003051 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003052 struct nfs4_fs_locations,
Trond Myklebust683b57b2006-06-09 09:34:22 -04003053 fattr))) != 0)
3054 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
3056 goto xdr_error;
3057 fattr->mode |= fmode;
3058 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
3059 goto xdr_error;
David Howells7539bba2006-08-22 20:06:09 -04003060 if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 goto xdr_error;
David Howells7539bba2006-08-22 20:06:09 -04003062 if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 goto xdr_error;
3064 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
3065 goto xdr_error;
3066 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
3067 goto xdr_error;
3068 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
3069 goto xdr_error;
3070 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
3071 goto xdr_error;
3072 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
3073 goto xdr_error;
Manoj Naik99baf622006-06-09 09:34:24 -04003074 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
3075 goto xdr_error;
3076 if (fattr->fileid == 0 && fileid != 0)
3077 fattr->fileid = fileid;
Trond Myklebust33801142005-10-27 22:12:39 -04003078 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04003081 dprintk("%s: xdr returned %d\n", __FUNCTION__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 return status;
3083}
3084
3085
3086static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3087{
Al Viro8687b632006-10-19 23:28:48 -07003088 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 uint32_t attrlen, bitmap[2];
3090 int status;
3091
3092 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3093 goto xdr_error;
3094 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3095 goto xdr_error;
3096 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3097 goto xdr_error;
3098
3099 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3100
3101 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3102 goto xdr_error;
3103 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3104 goto xdr_error;
3105 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3106 goto xdr_error;
3107 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3108 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3109 goto xdr_error;
3110 fsinfo->wtpref = fsinfo->wtmax;
3111
3112 status = verify_attr_len(xdr, savep, attrlen);
3113xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04003114 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 return status;
3116}
3117
3118static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3119{
Al Viro8687b632006-10-19 23:28:48 -07003120 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 uint32_t len;
3122 int status;
3123
3124 status = decode_op_hdr(xdr, OP_GETFH);
3125 if (status)
3126 return status;
3127 /* Zero handle first to allow comparisons */
3128 memset(fh, 0, sizeof(*fh));
3129
3130 READ_BUF(4);
3131 READ32(len);
3132 if (len > NFS4_FHSIZE)
3133 return -EIO;
3134 fh->size = len;
3135 READ_BUF(len);
3136 COPYMEM(fh->data, len);
3137 return 0;
3138}
3139
3140static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3141{
3142 int status;
3143
3144 status = decode_op_hdr(xdr, OP_LINK);
3145 if (status)
3146 return status;
3147 return decode_change_info(xdr, cinfo);
3148}
3149
3150/*
3151 * We create the owner, so we know a proper owner.id length is 4.
3152 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003153static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003155 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003156 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003157 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158
3159 READ_BUF(32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003160 READ64(offset);
3161 READ64(length);
3162 READ32(type);
3163 if (fl != NULL) {
3164 fl->fl_start = (loff_t)offset;
3165 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3166 if (length == ~(uint64_t)0)
3167 fl->fl_end = OFFSET_MAX;
3168 fl->fl_type = F_WRLCK;
3169 if (type & 1)
3170 fl->fl_type = F_RDLCK;
3171 fl->fl_pid = 0;
3172 }
3173 READ64(clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 READ32(namelen);
3175 READ_BUF(namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 return -NFS4ERR_DENIED;
3177}
3178
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003179static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180{
Al Viro8687b632006-10-19 23:28:48 -07003181 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 int status;
3183
3184 status = decode_op_hdr(xdr, OP_LOCK);
3185 if (status == 0) {
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003186 READ_BUF(sizeof(res->stateid.data));
3187 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 } else if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003189 return decode_lock_denied(xdr, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 return status;
3191}
3192
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003193static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194{
3195 int status;
3196 status = decode_op_hdr(xdr, OP_LOCKT);
3197 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003198 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 return status;
3200}
3201
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003202static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203{
Al Viro8687b632006-10-19 23:28:48 -07003204 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 int status;
3206
3207 status = decode_op_hdr(xdr, OP_LOCKU);
3208 if (status == 0) {
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003209 READ_BUF(sizeof(res->stateid.data));
3210 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 }
3212 return status;
3213}
3214
3215static int decode_lookup(struct xdr_stream *xdr)
3216{
3217 return decode_op_hdr(xdr, OP_LOOKUP);
3218}
3219
3220/* This is too sick! */
3221static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3222{
Al Viro8687b632006-10-19 23:28:48 -07003223 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 uint32_t limit_type, nblocks, blocksize;
3225
3226 READ_BUF(12);
3227 READ32(limit_type);
3228 switch (limit_type) {
3229 case 1:
3230 READ64(*maxsize);
3231 break;
3232 case 2:
3233 READ32(nblocks);
3234 READ32(blocksize);
3235 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3236 }
3237 return 0;
3238}
3239
3240static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3241{
Al Viro8687b632006-10-19 23:28:48 -07003242 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 uint32_t delegation_type;
3244
3245 READ_BUF(4);
3246 READ32(delegation_type);
3247 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3248 res->delegation_type = 0;
3249 return 0;
3250 }
3251 READ_BUF(20);
3252 COPYMEM(res->delegation.data, sizeof(res->delegation.data));
3253 READ32(res->do_recall);
3254 switch (delegation_type) {
3255 case NFS4_OPEN_DELEGATE_READ:
3256 res->delegation_type = FMODE_READ;
3257 break;
3258 case NFS4_OPEN_DELEGATE_WRITE:
3259 res->delegation_type = FMODE_WRITE|FMODE_READ;
3260 if (decode_space_limit(xdr, &res->maxsize) < 0)
3261 return -EIO;
3262 }
David Howells7539bba2006-08-22 20:06:09 -04003263 return decode_ace(xdr, NULL, res->server->nfs_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264}
3265
3266static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3267{
Al Viro8687b632006-10-19 23:28:48 -07003268 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 uint32_t bmlen;
3270 int status;
3271
3272 status = decode_op_hdr(xdr, OP_OPEN);
3273 if (status)
3274 return status;
3275 READ_BUF(sizeof(res->stateid.data));
3276 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3277
3278 decode_change_info(xdr, &res->cinfo);
3279
3280 READ_BUF(8);
3281 READ32(res->rflags);
3282 READ32(bmlen);
3283 if (bmlen > 10)
3284 goto xdr_error;
3285
3286 READ_BUF(bmlen << 2);
3287 p += bmlen;
3288 return decode_delegation(xdr, res);
3289xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04003290 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 return -EIO;
3292}
3293
3294static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3295{
Al Viro8687b632006-10-19 23:28:48 -07003296 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 int status;
3298
3299 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3300 if (status)
3301 return status;
3302 READ_BUF(sizeof(res->stateid.data));
3303 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3304 return 0;
3305}
3306
3307static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3308{
Al Viro8687b632006-10-19 23:28:48 -07003309 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 int status;
3311
3312 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3313 if (status)
3314 return status;
3315 READ_BUF(sizeof(res->stateid.data));
3316 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3317 return 0;
3318}
3319
3320static int decode_putfh(struct xdr_stream *xdr)
3321{
3322 return decode_op_hdr(xdr, OP_PUTFH);
3323}
3324
3325static int decode_putrootfh(struct xdr_stream *xdr)
3326{
3327 return decode_op_hdr(xdr, OP_PUTROOTFH);
3328}
3329
3330static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3331{
3332 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07003333 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 uint32_t count, eof, recvd, hdrlen;
3335 int status;
3336
3337 status = decode_op_hdr(xdr, OP_READ);
3338 if (status)
3339 return status;
3340 READ_BUF(8);
3341 READ32(eof);
3342 READ32(count);
3343 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3344 recvd = req->rq_rcv_buf.len - hdrlen;
3345 if (count > recvd) {
3346 printk(KERN_WARNING "NFS: server cheating in read reply: "
3347 "count %u > recvd %u\n", count, recvd);
3348 count = recvd;
3349 eof = 0;
3350 }
3351 xdr_read_pages(xdr, count);
3352 res->eof = eof;
3353 res->count = count;
3354 return 0;
3355}
3356
3357static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3358{
3359 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3360 struct page *page = *rcvbuf->pages;
3361 struct kvec *iov = rcvbuf->head;
3362 unsigned int nr, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07003363 __be32 *end, *entry, *p, *kaddr;
David Howellse8896492006-08-24 15:44:19 -04003364 uint32_t len, attrlen, xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 int hdrlen, recvd, status;
3366
3367 status = decode_op_hdr(xdr, OP_READDIR);
3368 if (status)
3369 return status;
3370 READ_BUF(8);
3371 COPYMEM(readdir->verifier.data, 8);
Trond Myklebusteadf4592005-06-22 17:16:39 +00003372 dprintk("%s: verifier = 0x%x%x\n",
3373 __FUNCTION__,
3374 ((u32 *)readdir->verifier.data)[0],
3375 ((u32 *)readdir->verifier.data)[1]);
3376
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377
3378 hdrlen = (char *) p - (char *) iov->iov_base;
3379 recvd = rcvbuf->len - hdrlen;
3380 if (pglen > recvd)
3381 pglen = recvd;
3382 xdr_read_pages(xdr, pglen);
3383
3384 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07003385 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04003386 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 entry = p;
3388 for (nr = 0; *p++; nr++) {
David Howellse8896492006-08-24 15:44:19 -04003389 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003391 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 p += 2; /* cookie */
3393 len = ntohl(*p++); /* filename length */
3394 if (len > NFS4_MAXNAMLEN) {
3395 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3396 goto err_unmap;
3397 }
David Howellse8896492006-08-24 15:44:19 -04003398 xlen = XDR_QUADLEN(len);
3399 if (end - p < xlen + 1)
3400 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003401 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04003402 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04003404 if (end - p < len + 1)
3405 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04003408 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04003410 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 entry = p;
3412 }
3413 if (!nr && (entry[0] != 0 || entry[1] == 0))
3414 goto short_pkt;
3415out:
3416 kunmap_atomic(kaddr, KM_USER0);
3417 return 0;
3418short_pkt:
Trond Myklebusteadf4592005-06-22 17:16:39 +00003419 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 entry[0] = entry[1] = 0;
3421 /* truncate listing ? */
3422 if (!nr) {
3423 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3424 entry[1] = 1;
3425 }
3426 goto out;
3427err_unmap:
3428 kunmap_atomic(kaddr, KM_USER0);
3429 return -errno_NFSERR_IO;
3430}
3431
3432static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3433{
3434 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3435 struct kvec *iov = rcvbuf->head;
3436 int hdrlen, len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07003437 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438 char *kaddr;
3439 int status;
3440
3441 status = decode_op_hdr(xdr, OP_READLINK);
3442 if (status)
3443 return status;
3444
3445 /* Convert length of symlink */
3446 READ_BUF(4);
3447 READ32(len);
3448 if (len >= rcvbuf->page_len || len <= 0) {
3449 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3450 return -ENAMETOOLONG;
3451 }
3452 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3453 recvd = req->rq_rcv_buf.len - hdrlen;
3454 if (recvd < len) {
3455 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3456 "count %u > recvd %u\n", len, recvd);
3457 return -EIO;
3458 }
3459 xdr_read_pages(xdr, len);
3460 /*
3461 * The XDR encode routine has set things up so that
3462 * the link text will be copied directly into the
3463 * buffer. We just have to do overflow-checking,
3464 * and and null-terminate the text (the VFS expects
3465 * null-termination).
3466 */
3467 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3468 kaddr[len+rcvbuf->page_base] = '\0';
3469 kunmap_atomic(kaddr, KM_USER0);
3470 return 0;
3471}
3472
3473static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3474{
3475 int status;
3476
3477 status = decode_op_hdr(xdr, OP_REMOVE);
3478 if (status)
3479 goto out;
3480 status = decode_change_info(xdr, cinfo);
3481out:
3482 return status;
3483}
3484
3485static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3486 struct nfs4_change_info *new_cinfo)
3487{
3488 int status;
3489
3490 status = decode_op_hdr(xdr, OP_RENAME);
3491 if (status)
3492 goto out;
3493 if ((status = decode_change_info(xdr, old_cinfo)))
3494 goto out;
3495 status = decode_change_info(xdr, new_cinfo);
3496out:
3497 return status;
3498}
3499
3500static int decode_renew(struct xdr_stream *xdr)
3501{
3502 return decode_op_hdr(xdr, OP_RENEW);
3503}
3504
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003505static int
3506decode_restorefh(struct xdr_stream *xdr)
3507{
3508 return decode_op_hdr(xdr, OP_RESTOREFH);
3509}
3510
J. Bruce Fields029d1052005-06-22 17:16:22 +00003511static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3512 size_t *acl_len)
3513{
Al Viro8687b632006-10-19 23:28:48 -07003514 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003515 uint32_t attrlen,
3516 bitmap[2] = {0};
3517 struct kvec *iov = req->rq_rcv_buf.head;
3518 int status;
3519
3520 *acl_len = 0;
3521 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3522 goto out;
3523 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3524 goto out;
3525 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3526 goto out;
3527
3528 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3529 return -EIO;
3530 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3531 int hdrlen, recvd;
3532
3533 /* We ignore &savep and don't do consistency checks on
3534 * the attr length. Let userspace figure it out.... */
3535 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3536 recvd = req->rq_rcv_buf.len - hdrlen;
3537 if (attrlen > recvd) {
3538 printk(KERN_WARNING "NFS: server cheating in getattr"
3539 " acl reply: attrlen %u > recvd %u\n",
3540 attrlen, recvd);
3541 return -EINVAL;
3542 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04003543 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00003544 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04003545 } else
3546 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003547
3548out:
3549 return status;
3550}
3551
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552static int
3553decode_savefh(struct xdr_stream *xdr)
3554{
3555 return decode_op_hdr(xdr, OP_SAVEFH);
3556}
3557
3558static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3559{
Al Viro8687b632006-10-19 23:28:48 -07003560 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561 uint32_t bmlen;
3562 int status;
3563
3564
3565 status = decode_op_hdr(xdr, OP_SETATTR);
3566 if (status)
3567 return status;
3568 READ_BUF(4);
3569 READ32(bmlen);
3570 READ_BUF(bmlen << 2);
3571 return 0;
3572}
3573
David Howellsadfa6f92006-08-22 20:06:08 -04003574static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575{
Al Viro8687b632006-10-19 23:28:48 -07003576 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577 uint32_t opnum;
3578 int32_t nfserr;
3579
3580 READ_BUF(8);
3581 READ32(opnum);
3582 if (opnum != OP_SETCLIENTID) {
3583 printk(KERN_NOTICE
3584 "nfs4_decode_setclientid: Server returned operation"
3585 " %d\n", opnum);
3586 return -EIO;
3587 }
3588 READ32(nfserr);
3589 if (nfserr == NFS_OK) {
3590 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3591 READ64(clp->cl_clientid);
3592 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3593 } else if (nfserr == NFSERR_CLID_INUSE) {
3594 uint32_t len;
3595
3596 /* skip netid string */
3597 READ_BUF(4);
3598 READ32(len);
3599 READ_BUF(len);
3600
3601 /* skip uaddr string */
3602 READ_BUF(4);
3603 READ32(len);
3604 READ_BUF(len);
3605 return -NFSERR_CLID_INUSE;
3606 } else
David Howells0a8ea432006-08-22 20:06:08 -04003607 return -nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608
3609 return 0;
3610}
3611
3612static int decode_setclientid_confirm(struct xdr_stream *xdr)
3613{
3614 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3615}
3616
3617static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3618{
Al Viro8687b632006-10-19 23:28:48 -07003619 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620 int status;
3621
3622 status = decode_op_hdr(xdr, OP_WRITE);
3623 if (status)
3624 return status;
3625
3626 READ_BUF(16);
3627 READ32(res->count);
3628 READ32(res->verf->committed);
3629 COPYMEM(res->verf->verifier, 8);
3630 return 0;
3631}
3632
3633static int decode_delegreturn(struct xdr_stream *xdr)
3634{
3635 return decode_op_hdr(xdr, OP_DELEGRETURN);
3636}
3637
3638/*
3639 * Decode OPEN_DOWNGRADE response
3640 */
Al Viro8687b632006-10-19 23:28:48 -07003641static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642{
3643 struct xdr_stream xdr;
3644 struct compound_hdr hdr;
3645 int status;
3646
3647 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3648 status = decode_compound_hdr(&xdr, &hdr);
3649 if (status)
3650 goto out;
3651 status = decode_putfh(&xdr);
3652 if (status)
3653 goto out;
3654 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04003655 if (status != 0)
3656 goto out;
3657 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658out:
3659 return status;
3660}
3661
3662/*
3663 * END OF "GENERIC" DECODE ROUTINES.
3664 */
3665
3666/*
3667 * Decode ACCESS response
3668 */
Al Viro8687b632006-10-19 23:28:48 -07003669static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670{
3671 struct xdr_stream xdr;
3672 struct compound_hdr hdr;
3673 int status;
3674
3675 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3676 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3677 goto out;
3678 if ((status = decode_putfh(&xdr)) == 0)
3679 status = decode_access(&xdr, res);
3680out:
3681 return status;
3682}
3683
3684/*
3685 * Decode LOOKUP response
3686 */
Al Viro8687b632006-10-19 23:28:48 -07003687static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688{
3689 struct xdr_stream xdr;
3690 struct compound_hdr hdr;
3691 int status;
3692
3693 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3694 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3695 goto out;
3696 if ((status = decode_putfh(&xdr)) != 0)
3697 goto out;
3698 if ((status = decode_lookup(&xdr)) != 0)
3699 goto out;
3700 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3701 goto out;
3702 status = decode_getfattr(&xdr, res->fattr, res->server);
3703out:
3704 return status;
3705}
3706
3707/*
3708 * Decode LOOKUP_ROOT response
3709 */
Al Viro8687b632006-10-19 23:28:48 -07003710static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711{
3712 struct xdr_stream xdr;
3713 struct compound_hdr hdr;
3714 int status;
3715
3716 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3717 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3718 goto out;
3719 if ((status = decode_putrootfh(&xdr)) != 0)
3720 goto out;
3721 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3722 status = decode_getfattr(&xdr, res->fattr, res->server);
3723out:
3724 return status;
3725}
3726
3727/*
3728 * Decode REMOVE response
3729 */
Al Viro8687b632006-10-19 23:28:48 -07003730static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_remove_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731{
3732 struct xdr_stream xdr;
3733 struct compound_hdr hdr;
3734 int status;
3735
3736 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3737 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3738 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04003739 if ((status = decode_putfh(&xdr)) != 0)
3740 goto out;
3741 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3742 goto out;
3743 decode_getfattr(&xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744out:
3745 return status;
3746}
3747
3748/*
3749 * Decode RENAME response
3750 */
Al Viro8687b632006-10-19 23:28:48 -07003751static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752{
3753 struct xdr_stream xdr;
3754 struct compound_hdr hdr;
3755 int status;
3756
3757 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3758 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3759 goto out;
3760 if ((status = decode_putfh(&xdr)) != 0)
3761 goto out;
3762 if ((status = decode_savefh(&xdr)) != 0)
3763 goto out;
3764 if ((status = decode_putfh(&xdr)) != 0)
3765 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04003766 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3767 goto out;
3768 /* Current FH is target directory */
3769 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3770 goto out;
3771 if ((status = decode_restorefh(&xdr)) != 0)
3772 goto out;
3773 decode_getfattr(&xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774out:
3775 return status;
3776}
3777
3778/*
3779 * Decode LINK response
3780 */
Al Viro8687b632006-10-19 23:28:48 -07003781static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782{
3783 struct xdr_stream xdr;
3784 struct compound_hdr hdr;
3785 int status;
3786
3787 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3788 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3789 goto out;
3790 if ((status = decode_putfh(&xdr)) != 0)
3791 goto out;
3792 if ((status = decode_savefh(&xdr)) != 0)
3793 goto out;
3794 if ((status = decode_putfh(&xdr)) != 0)
3795 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04003796 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3797 goto out;
3798 /*
3799 * Note order: OP_LINK leaves the directory as the current
3800 * filehandle.
3801 */
3802 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3803 goto out;
3804 if ((status = decode_restorefh(&xdr)) != 0)
3805 goto out;
3806 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807out:
3808 return status;
3809}
3810
3811/*
3812 * Decode CREATE response
3813 */
Al Viro8687b632006-10-19 23:28:48 -07003814static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815{
3816 struct xdr_stream xdr;
3817 struct compound_hdr hdr;
3818 int status;
3819
3820 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3821 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3822 goto out;
3823 if ((status = decode_putfh(&xdr)) != 0)
3824 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003825 if ((status = decode_savefh(&xdr)) != 0)
3826 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3828 goto out;
3829 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3830 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003831 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3832 goto out;
3833 if ((status = decode_restorefh(&xdr)) != 0)
3834 goto out;
3835 decode_getfattr(&xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836out:
3837 return status;
3838}
3839
3840/*
3841 * Decode SYMLINK response
3842 */
Al Viro8687b632006-10-19 23:28:48 -07003843static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844{
3845 return nfs4_xdr_dec_create(rqstp, p, res);
3846}
3847
3848/*
3849 * Decode GETATTR response
3850 */
Al Viro8687b632006-10-19 23:28:48 -07003851static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852{
3853 struct xdr_stream xdr;
3854 struct compound_hdr hdr;
3855 int status;
3856
3857 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3858 status = decode_compound_hdr(&xdr, &hdr);
3859 if (status)
3860 goto out;
3861 status = decode_putfh(&xdr);
3862 if (status)
3863 goto out;
3864 status = decode_getfattr(&xdr, res->fattr, res->server);
3865out:
3866 return status;
3867
3868}
3869
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003870/*
3871 * Encode an SETACL request
3872 */
3873static int
Al Viro8687b632006-10-19 23:28:48 -07003874nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003875{
3876 struct xdr_stream xdr;
3877 struct compound_hdr hdr = {
3878 .nops = 2,
3879 };
3880 int status;
3881
3882 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3883 encode_compound_hdr(&xdr, &hdr);
3884 status = encode_putfh(&xdr, args->fh);
3885 if (status)
3886 goto out;
3887 status = encode_setacl(&xdr, args);
3888out:
3889 return status;
3890}
3891/*
3892 * Decode SETACL response
3893 */
3894static int
Al Viro8687b632006-10-19 23:28:48 -07003895nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003896{
3897 struct xdr_stream xdr;
3898 struct compound_hdr hdr;
3899 int status;
3900
3901 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3902 status = decode_compound_hdr(&xdr, &hdr);
3903 if (status)
3904 goto out;
3905 status = decode_putfh(&xdr);
3906 if (status)
3907 goto out;
3908 status = decode_setattr(&xdr, res);
3909out:
3910 return status;
3911}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912
3913/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00003914 * Decode GETACL response
3915 */
3916static int
Al Viro8687b632006-10-19 23:28:48 -07003917nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
J. Bruce Fields029d1052005-06-22 17:16:22 +00003918{
3919 struct xdr_stream xdr;
3920 struct compound_hdr hdr;
3921 int status;
3922
3923 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3924 status = decode_compound_hdr(&xdr, &hdr);
3925 if (status)
3926 goto out;
3927 status = decode_putfh(&xdr);
3928 if (status)
3929 goto out;
3930 status = decode_getacl(&xdr, rqstp, acl_len);
3931
3932out:
3933 return status;
3934}
3935
3936/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 * Decode CLOSE response
3938 */
Al Viro8687b632006-10-19 23:28:48 -07003939static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940{
3941 struct xdr_stream xdr;
3942 struct compound_hdr hdr;
3943 int status;
3944
3945 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3946 status = decode_compound_hdr(&xdr, &hdr);
3947 if (status)
3948 goto out;
3949 status = decode_putfh(&xdr);
3950 if (status)
3951 goto out;
3952 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04003953 if (status != 0)
3954 goto out;
3955 /*
3956 * Note: Server may do delete on close for this file
3957 * in which case the getattr call will fail with
3958 * an ESTALE error. Shouldn't be a problem,
3959 * though, since fattr->valid will remain unset.
3960 */
3961 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962out:
3963 return status;
3964}
3965
3966/*
3967 * Decode OPEN response
3968 */
Al Viro8687b632006-10-19 23:28:48 -07003969static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970{
3971 struct xdr_stream xdr;
3972 struct compound_hdr hdr;
3973 int status;
3974
3975 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3976 status = decode_compound_hdr(&xdr, &hdr);
3977 if (status)
3978 goto out;
3979 status = decode_putfh(&xdr);
3980 if (status)
3981 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003982 status = decode_savefh(&xdr);
3983 if (status)
3984 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985 status = decode_open(&xdr, res);
3986 if (status)
3987 goto out;
3988 status = decode_getfh(&xdr, &res->fh);
3989 if (status)
3990 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003991 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
3992 goto out;
3993 if ((status = decode_restorefh(&xdr)) != 0)
3994 goto out;
3995 decode_getfattr(&xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996out:
3997 return status;
3998}
3999
4000/*
4001 * Decode OPEN_CONFIRM response
4002 */
Al Viro8687b632006-10-19 23:28:48 -07004003static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004{
4005 struct xdr_stream xdr;
4006 struct compound_hdr hdr;
4007 int status;
4008
4009 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4010 status = decode_compound_hdr(&xdr, &hdr);
4011 if (status)
4012 goto out;
4013 status = decode_putfh(&xdr);
4014 if (status)
4015 goto out;
4016 status = decode_open_confirm(&xdr, res);
4017out:
4018 return status;
4019}
4020
4021/*
4022 * Decode OPEN response
4023 */
Al Viro8687b632006-10-19 23:28:48 -07004024static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025{
4026 struct xdr_stream xdr;
4027 struct compound_hdr hdr;
4028 int status;
4029
4030 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4031 status = decode_compound_hdr(&xdr, &hdr);
4032 if (status)
4033 goto out;
4034 status = decode_putfh(&xdr);
4035 if (status)
4036 goto out;
4037 status = decode_open(&xdr, res);
Trond Myklebust864472e2006-01-03 09:55:15 +01004038 if (status)
4039 goto out;
4040 decode_getfattr(&xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041out:
4042 return status;
4043}
4044
4045/*
4046 * Decode SETATTR response
4047 */
Al Viro8687b632006-10-19 23:28:48 -07004048static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049{
4050 struct xdr_stream xdr;
4051 struct compound_hdr hdr;
4052 int status;
4053
4054 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4055 status = decode_compound_hdr(&xdr, &hdr);
4056 if (status)
4057 goto out;
4058 status = decode_putfh(&xdr);
4059 if (status)
4060 goto out;
4061 status = decode_setattr(&xdr, res);
4062 if (status)
4063 goto out;
4064 status = decode_getfattr(&xdr, res->fattr, res->server);
4065 if (status == NFS4ERR_DELAY)
4066 status = 0;
4067out:
4068 return status;
4069}
4070
4071/*
4072 * Decode LOCK response
4073 */
Al Viro8687b632006-10-19 23:28:48 -07004074static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075{
4076 struct xdr_stream xdr;
4077 struct compound_hdr hdr;
4078 int status;
4079
4080 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4081 status = decode_compound_hdr(&xdr, &hdr);
4082 if (status)
4083 goto out;
4084 status = decode_putfh(&xdr);
4085 if (status)
4086 goto out;
4087 status = decode_lock(&xdr, res);
4088out:
4089 return status;
4090}
4091
4092/*
4093 * Decode LOCKT response
4094 */
Al Viro8687b632006-10-19 23:28:48 -07004095static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096{
4097 struct xdr_stream xdr;
4098 struct compound_hdr hdr;
4099 int status;
4100
4101 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4102 status = decode_compound_hdr(&xdr, &hdr);
4103 if (status)
4104 goto out;
4105 status = decode_putfh(&xdr);
4106 if (status)
4107 goto out;
4108 status = decode_lockt(&xdr, res);
4109out:
4110 return status;
4111}
4112
4113/*
4114 * Decode LOCKU response
4115 */
Al Viro8687b632006-10-19 23:28:48 -07004116static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117{
4118 struct xdr_stream xdr;
4119 struct compound_hdr hdr;
4120 int status;
4121
4122 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4123 status = decode_compound_hdr(&xdr, &hdr);
4124 if (status)
4125 goto out;
4126 status = decode_putfh(&xdr);
4127 if (status)
4128 goto out;
4129 status = decode_locku(&xdr, res);
4130out:
4131 return status;
4132}
4133
4134/*
4135 * Decode READLINK response
4136 */
Al Viro8687b632006-10-19 23:28:48 -07004137static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138{
4139 struct xdr_stream xdr;
4140 struct compound_hdr hdr;
4141 int status;
4142
4143 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4144 status = decode_compound_hdr(&xdr, &hdr);
4145 if (status)
4146 goto out;
4147 status = decode_putfh(&xdr);
4148 if (status)
4149 goto out;
4150 status = decode_readlink(&xdr, rqstp);
4151out:
4152 return status;
4153}
4154
4155/*
4156 * Decode READDIR response
4157 */
Al Viro8687b632006-10-19 23:28:48 -07004158static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159{
4160 struct xdr_stream xdr;
4161 struct compound_hdr hdr;
4162 int status;
4163
4164 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4165 status = decode_compound_hdr(&xdr, &hdr);
4166 if (status)
4167 goto out;
4168 status = decode_putfh(&xdr);
4169 if (status)
4170 goto out;
4171 status = decode_readdir(&xdr, rqstp, res);
4172out:
4173 return status;
4174}
4175
4176/*
4177 * Decode Read response
4178 */
Al Viro8687b632006-10-19 23:28:48 -07004179static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180{
4181 struct xdr_stream xdr;
4182 struct compound_hdr hdr;
4183 int status;
4184
4185 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4186 status = decode_compound_hdr(&xdr, &hdr);
4187 if (status)
4188 goto out;
4189 status = decode_putfh(&xdr);
4190 if (status)
4191 goto out;
4192 status = decode_read(&xdr, rqstp, res);
4193 if (!status)
4194 status = res->count;
4195out:
4196 return status;
4197}
4198
4199/*
4200 * Decode WRITE response
4201 */
Al Viro8687b632006-10-19 23:28:48 -07004202static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203{
4204 struct xdr_stream xdr;
4205 struct compound_hdr hdr;
4206 int status;
4207
4208 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4209 status = decode_compound_hdr(&xdr, &hdr);
4210 if (status)
4211 goto out;
4212 status = decode_putfh(&xdr);
4213 if (status)
4214 goto out;
4215 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004216 if (status)
4217 goto out;
4218 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219 if (!status)
4220 status = res->count;
4221out:
4222 return status;
4223}
4224
4225/*
4226 * Decode COMMIT response
4227 */
Al Viro8687b632006-10-19 23:28:48 -07004228static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229{
4230 struct xdr_stream xdr;
4231 struct compound_hdr hdr;
4232 int status;
4233
4234 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4235 status = decode_compound_hdr(&xdr, &hdr);
4236 if (status)
4237 goto out;
4238 status = decode_putfh(&xdr);
4239 if (status)
4240 goto out;
4241 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004242 if (status)
4243 goto out;
4244 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245out:
4246 return status;
4247}
4248
4249/*
4250 * FSINFO request
4251 */
Al Viro8687b632006-10-19 23:28:48 -07004252static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253{
4254 struct xdr_stream xdr;
4255 struct compound_hdr hdr;
4256 int status;
4257
4258 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4259 status = decode_compound_hdr(&xdr, &hdr);
4260 if (!status)
4261 status = decode_putfh(&xdr);
4262 if (!status)
4263 status = decode_fsinfo(&xdr, fsinfo);
4264 if (!status)
David Howells0a8ea432006-08-22 20:06:08 -04004265 status = -nfs4_stat_to_errno(hdr.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004266 return status;
4267}
4268
4269/*
4270 * PATHCONF request
4271 */
Al Viro8687b632006-10-19 23:28:48 -07004272static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273{
4274 struct xdr_stream xdr;
4275 struct compound_hdr hdr;
4276 int status;
4277
4278 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4279 status = decode_compound_hdr(&xdr, &hdr);
4280 if (!status)
4281 status = decode_putfh(&xdr);
4282 if (!status)
4283 status = decode_pathconf(&xdr, pathconf);
4284 return status;
4285}
4286
4287/*
4288 * STATFS request
4289 */
Al Viro8687b632006-10-19 23:28:48 -07004290static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291{
4292 struct xdr_stream xdr;
4293 struct compound_hdr hdr;
4294 int status;
4295
4296 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4297 status = decode_compound_hdr(&xdr, &hdr);
4298 if (!status)
4299 status = decode_putfh(&xdr);
4300 if (!status)
4301 status = decode_statfs(&xdr, fsstat);
4302 return status;
4303}
4304
4305/*
4306 * GETATTR_BITMAP request
4307 */
Al Viro8687b632006-10-19 23:28:48 -07004308static 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 -07004309{
4310 struct xdr_stream xdr;
4311 struct compound_hdr hdr;
4312 int status;
4313
4314 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4315 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4316 goto out;
4317 if ((status = decode_putfh(&xdr)) != 0)
4318 goto out;
4319 status = decode_server_caps(&xdr, res);
4320out:
4321 return status;
4322}
4323
4324/*
4325 * Decode RENEW response
4326 */
Al Viro8687b632006-10-19 23:28:48 -07004327static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328{
4329 struct xdr_stream xdr;
4330 struct compound_hdr hdr;
4331 int status;
4332
4333 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4334 status = decode_compound_hdr(&xdr, &hdr);
4335 if (!status)
4336 status = decode_renew(&xdr);
4337 return status;
4338}
4339
4340/*
4341 * a SETCLIENTID request
4342 */
Al Viro8687b632006-10-19 23:28:48 -07004343static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04004344 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345{
4346 struct xdr_stream xdr;
4347 struct compound_hdr hdr;
4348 int status;
4349
4350 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4351 status = decode_compound_hdr(&xdr, &hdr);
4352 if (!status)
4353 status = decode_setclientid(&xdr, clp);
4354 if (!status)
David Howells0a8ea432006-08-22 20:06:08 -04004355 status = -nfs4_stat_to_errno(hdr.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356 return status;
4357}
4358
4359/*
4360 * a SETCLIENTID_CONFIRM request
4361 */
Al Viro8687b632006-10-19 23:28:48 -07004362static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363{
4364 struct xdr_stream xdr;
4365 struct compound_hdr hdr;
4366 int status;
4367
4368 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4369 status = decode_compound_hdr(&xdr, &hdr);
4370 if (!status)
4371 status = decode_setclientid_confirm(&xdr);
4372 if (!status)
4373 status = decode_putrootfh(&xdr);
4374 if (!status)
4375 status = decode_fsinfo(&xdr, fsinfo);
4376 if (!status)
David Howells0a8ea432006-08-22 20:06:08 -04004377 status = -nfs4_stat_to_errno(hdr.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378 return status;
4379}
4380
4381/*
4382 * DELEGRETURN request
4383 */
Al Viro8687b632006-10-19 23:28:48 -07004384static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385{
4386 struct xdr_stream xdr;
4387 struct compound_hdr hdr;
4388 int status;
4389
4390 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4391 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01004392 if (status != 0)
4393 goto out;
4394 status = decode_putfh(&xdr);
4395 if (status != 0)
4396 goto out;
4397 status = decode_delegreturn(&xdr);
4398 decode_getfattr(&xdr, res->fattr, res->server);
4399out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400 return status;
4401}
4402
Trond Myklebust683b57b2006-06-09 09:34:22 -04004403/*
4404 * FS_LOCATIONS request
4405 */
Al Viro8687b632006-10-19 23:28:48 -07004406static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004407{
4408 struct xdr_stream xdr;
4409 struct compound_hdr hdr;
4410 int status;
4411
4412 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4413 status = decode_compound_hdr(&xdr, &hdr);
4414 if (status != 0)
4415 goto out;
4416 if ((status = decode_putfh(&xdr)) != 0)
4417 goto out;
4418 if ((status = decode_lookup(&xdr)) != 0)
4419 goto out;
4420 xdr_enter_page(&xdr, PAGE_SIZE);
4421 status = decode_getfattr(&xdr, &res->fattr, res->server);
4422out:
4423 return status;
4424}
4425
Al Viro0dbb4c62006-10-19 23:28:49 -07004426__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427{
4428 uint32_t bitmap[2] = {0};
4429 uint32_t len;
4430
4431 if (!*p++) {
4432 if (!*p)
4433 return ERR_PTR(-EAGAIN);
4434 entry->eof = 1;
4435 return ERR_PTR(-EBADCOOKIE);
4436 }
4437
4438 entry->prev_cookie = entry->cookie;
4439 p = xdr_decode_hyper(p, &entry->cookie);
4440 entry->len = ntohl(*p++);
4441 entry->name = (const char *) p;
4442 p += XDR_QUADLEN(entry->len);
4443
4444 /*
4445 * In case the server doesn't return an inode number,
4446 * we fake one here. (We don't use inode number 0,
4447 * since glibc seems to choke on it...)
4448 */
4449 entry->ino = 1;
4450
4451 len = ntohl(*p++); /* bitmap length */
4452 if (len-- > 0) {
4453 bitmap[0] = ntohl(*p++);
4454 if (len-- > 0) {
4455 bitmap[1] = ntohl(*p++);
4456 p += len;
4457 }
4458 }
4459 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4460 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00004461 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4462 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4463 /* Ignore the return value of rdattr_error for now */
4464 p++;
4465 len--;
4466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4468 xdr_decode_hyper(p, &entry->ino);
4469 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4470 xdr_decode_hyper(p, &entry->ino);
4471 p += len;
4472 }
4473
4474 entry->eof = !p[0] && p[1];
4475 return p;
4476}
4477
4478/*
4479 * We need to translate between nfs status return values and
4480 * the local errno values which may not be the same.
4481 */
4482static struct {
4483 int stat;
4484 int errno;
4485} nfs_errtbl[] = {
4486 { NFS4_OK, 0 },
4487 { NFS4ERR_PERM, EPERM },
4488 { NFS4ERR_NOENT, ENOENT },
4489 { NFS4ERR_IO, errno_NFSERR_IO },
4490 { NFS4ERR_NXIO, ENXIO },
4491 { NFS4ERR_ACCESS, EACCES },
4492 { NFS4ERR_EXIST, EEXIST },
4493 { NFS4ERR_XDEV, EXDEV },
4494 { NFS4ERR_NOTDIR, ENOTDIR },
4495 { NFS4ERR_ISDIR, EISDIR },
4496 { NFS4ERR_INVAL, EINVAL },
4497 { NFS4ERR_FBIG, EFBIG },
4498 { NFS4ERR_NOSPC, ENOSPC },
4499 { NFS4ERR_ROFS, EROFS },
4500 { NFS4ERR_MLINK, EMLINK },
4501 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4502 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4503 { NFS4ERR_DQUOT, EDQUOT },
4504 { NFS4ERR_STALE, ESTALE },
4505 { NFS4ERR_BADHANDLE, EBADHANDLE },
Manoj Naik6ebf3652005-06-22 17:16:39 +00004506 { NFS4ERR_BADOWNER, EINVAL },
4507 { NFS4ERR_BADNAME, EINVAL },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4509 { NFS4ERR_NOTSUPP, ENOTSUPP },
4510 { NFS4ERR_TOOSMALL, ETOOSMALL },
4511 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4512 { NFS4ERR_BADTYPE, EBADTYPE },
4513 { NFS4ERR_LOCKED, EAGAIN },
4514 { NFS4ERR_RESOURCE, EREMOTEIO },
4515 { NFS4ERR_SYMLINK, ELOOP },
4516 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4517 { NFS4ERR_DEADLOCK, EDEADLK },
4518 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4519 * to be handled by a
4520 * middle-layer.
4521 */
4522 { -1, EIO }
4523};
4524
4525/*
4526 * Convert an NFS error code to a local one.
4527 * This one is used jointly by NFSv2 and NFSv3.
4528 */
4529static int
David Howells0a8ea432006-08-22 20:06:08 -04004530nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004531{
4532 int i;
4533 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4534 if (nfs_errtbl[i].stat == stat)
4535 return nfs_errtbl[i].errno;
4536 }
4537 if (stat <= 10000 || stat > 10100) {
4538 /* The server is looney tunes. */
4539 return ESERVERFAULT;
4540 }
4541 /* If we cannot translate the error, the recovery routines should
4542 * handle it.
4543 * Note: remaining NFSv4 error codes have values > 10000, so should
4544 * not conflict with native Linux error codes.
4545 */
4546 return stat;
4547}
4548
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549#define PROC(proc, argtype, restype) \
4550[NFSPROC4_CLNT_##proc] = { \
4551 .p_proc = NFSPROC4_COMPOUND, \
4552 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4553 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04004554 .p_arglen = NFS4_##argtype##_sz, \
4555 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05004556 .p_statidx = NFSPROC4_CLNT_##proc, \
4557 .p_name = #proc, \
Linus Torvalds1da177e2005-04-16 15:20:36 -07004558 }
4559
4560struct rpc_procinfo nfs4_procedures[] = {
4561 PROC(READ, enc_read, dec_read),
4562 PROC(WRITE, enc_write, dec_write),
4563 PROC(COMMIT, enc_commit, dec_commit),
4564 PROC(OPEN, enc_open, dec_open),
4565 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4566 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4567 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4568 PROC(CLOSE, enc_close, dec_close),
4569 PROC(SETATTR, enc_setattr, dec_setattr),
4570 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4571 PROC(RENEW, enc_renew, dec_renew),
4572 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4573 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4574 PROC(LOCK, enc_lock, dec_lock),
4575 PROC(LOCKT, enc_lockt, dec_lockt),
4576 PROC(LOCKU, enc_locku, dec_locku),
4577 PROC(ACCESS, enc_access, dec_access),
4578 PROC(GETATTR, enc_getattr, dec_getattr),
4579 PROC(LOOKUP, enc_lookup, dec_lookup),
4580 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4581 PROC(REMOVE, enc_remove, dec_remove),
4582 PROC(RENAME, enc_rename, dec_rename),
4583 PROC(LINK, enc_link, dec_link),
4584 PROC(SYMLINK, enc_symlink, dec_symlink),
4585 PROC(CREATE, enc_create, dec_create),
4586 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4587 PROC(STATFS, enc_statfs, dec_statfs),
4588 PROC(READLINK, enc_readlink, dec_readlink),
4589 PROC(READDIR, enc_readdir, dec_readdir),
4590 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4591 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00004592 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004593 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04004594 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595};
4596
4597struct rpc_version nfs_version4 = {
4598 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08004599 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 .procs = nfs4_procedures
4601};
4602
4603/*
4604 * Local variables:
4605 * c-basic-offset: 8
4606 * End:
4607 */