NFSv4: Add post-op attributes to NFSv4 write and commit callbacks.
[deliverable/linux.git] / fs / nfs / nfs4xdr.c
CommitLineData
1da177e4
LT
1/*
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>
4ce79717 54#include "nfs4_fs.h"
1da177e4
LT
55
56#define NFSDBG_FACILITY NFSDBG_XDR
57
58/* Mapping from NFS error code to "errno" error code. */
59#define errno_NFSERR_IO EIO
60
61static int nfs_stat_to_errno(int);
62
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))
96928206
BF
86#define nfs4_fattr_bitmap_maxsz 3
87#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
1da177e4
LT
88#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
89#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
96928206
BF
90/* 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)
1da177e4
LT
96#define encode_savefh_maxsz (op_encode_hdr_maxsz)
97#define decode_savefh_maxsz (op_decode_hdr_maxsz)
56ae19f3
TM
98#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
99#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
1da177e4
LT
100#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 + \
131 nfs4_path_maxsz + \
96928206 132 nfs4_fattr_maxsz)
1da177e4
LT
133#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
134#define encode_create_maxsz (op_encode_hdr_maxsz + \
135 2 + nfs4_name_maxsz + \
96928206 136 nfs4_fattr_maxsz)
1da177e4
LT
137#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 + \
4f9838c7
TM
162 op_encode_hdr_maxsz + 8 + \
163 encode_getattr_maxsz)
1da177e4
LT
164#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
165 decode_putfh_maxsz + \
4f9838c7
TM
166 op_decode_hdr_maxsz + 4 + \
167 decode_getattr_maxsz)
1da177e4
LT
168#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
169 encode_putfh_maxsz + \
4f9838c7
TM
170 op_encode_hdr_maxsz + 3 + \
171 encode_getattr_maxsz)
1da177e4
LT
172#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
173 decode_putfh_maxsz + \
4f9838c7
TM
174 op_decode_hdr_maxsz + 2 + \
175 decode_getattr_maxsz)
1da177e4
LT
176#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 + \
516a6af6
TM
205 op_encode_hdr_maxsz + 7 + \
206 encode_getattr_maxsz)
1da177e4
LT
207#define NFS4_dec_open_downgrade_sz \
208 (compound_decode_hdr_maxsz + \
209 decode_putfh_maxsz + \
516a6af6
TM
210 op_decode_hdr_maxsz + 4 + \
211 decode_getattr_maxsz)
1da177e4
LT
212#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
213 encode_putfh_maxsz + \
516a6af6
TM
214 op_encode_hdr_maxsz + 5 + \
215 encode_getattr_maxsz)
1da177e4
LT
216#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
217 decode_putfh_maxsz + \
516a6af6
TM
218 op_decode_hdr_maxsz + 4 + \
219 decode_getattr_maxsz)
1da177e4
LT
220#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
221 encode_putfh_maxsz + \
222 op_encode_hdr_maxsz + 4 + \
96928206 223 nfs4_fattr_maxsz + \
1da177e4
LT
224 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 + \
16e42959
TM
313 encode_remove_maxsz + \
314 encode_getattr_maxsz)
1da177e4
LT
315#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
316 decode_putfh_maxsz + \
16e42959
TM
317 op_decode_hdr_maxsz + 5 + \
318 decode_getattr_maxsz)
1da177e4
LT
319#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
320 encode_putfh_maxsz + \
321 encode_savefh_maxsz + \
322 encode_putfh_maxsz + \
6caf2c82
TM
323 encode_rename_maxsz + \
324 encode_getattr_maxsz + \
325 encode_restorefh_maxsz + \
326 encode_getattr_maxsz)
1da177e4
LT
327#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
328 decode_putfh_maxsz + \
329 decode_savefh_maxsz + \
330 decode_putfh_maxsz + \
6caf2c82
TM
331 decode_rename_maxsz + \
332 decode_getattr_maxsz + \
333 decode_restorefh_maxsz + \
334 decode_getattr_maxsz)
1da177e4
LT
335#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
336 encode_putfh_maxsz + \
337 encode_savefh_maxsz + \
338 encode_putfh_maxsz + \
91ba2eee
TM
339 encode_link_maxsz + \
340 decode_getattr_maxsz + \
341 encode_restorefh_maxsz + \
342 decode_getattr_maxsz)
1da177e4
LT
343#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
344 decode_putfh_maxsz + \
345 decode_savefh_maxsz + \
346 decode_putfh_maxsz + \
91ba2eee
TM
347 decode_link_maxsz + \
348 decode_getattr_maxsz + \
349 decode_restorefh_maxsz + \
350 decode_getattr_maxsz)
1da177e4
LT
351#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 + \
56ae19f3 363 encode_savefh_maxsz + \
1da177e4 364 encode_create_maxsz + \
56ae19f3 365 encode_getfh_maxsz + \
1da177e4 366 encode_getattr_maxsz + \
56ae19f3
TM
367 encode_restorefh_maxsz + \
368 encode_getattr_maxsz)
1da177e4
LT
369#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
370 decode_putfh_maxsz + \
56ae19f3 371 decode_savefh_maxsz + \
1da177e4 372 decode_create_maxsz + \
56ae19f3 373 decode_getfh_maxsz + \
1da177e4 374 decode_getattr_maxsz + \
56ae19f3
TM
375 decode_restorefh_maxsz + \
376 decode_getattr_maxsz)
1da177e4
LT
377#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
378 encode_putfh_maxsz + \
379 encode_getattr_maxsz)
380#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
381 decode_putfh_maxsz + \
382 decode_getattr_maxsz)
383#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
384 encode_putfh_maxsz + \
385 encode_getattr_maxsz)
386#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
387 decode_putfh_maxsz + \
388 op_decode_hdr_maxsz + 12)
389#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
390 encode_getattr_maxsz)
391#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
392 decode_getattr_maxsz)
393#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
394 encode_putfh_maxsz + \
395 encode_delegreturn_maxsz)
396#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
397 decode_delegreturn_maxsz)
029d105e
BF
398#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
399 encode_putfh_maxsz + \
400 encode_getattr_maxsz)
401#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
402 decode_putfh_maxsz + \
403 op_decode_hdr_maxsz + \
404 nfs4_fattr_bitmap_maxsz + 1)
23ec6965
BF
405#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
406 encode_putfh_maxsz + \
407 op_encode_hdr_maxsz + 4 + \
408 nfs4_fattr_bitmap_maxsz + 1)
409#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
410 decode_putfh_maxsz + \
411 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
1da177e4
LT
412
413static struct {
414 unsigned int mode;
415 unsigned int nfs2type;
416} nfs_type2fmt[] = {
417 { 0, NFNON },
418 { S_IFREG, NFREG },
419 { S_IFDIR, NFDIR },
420 { S_IFBLK, NFBLK },
421 { S_IFCHR, NFCHR },
422 { S_IFLNK, NFLNK },
423 { S_IFSOCK, NFSOCK },
424 { S_IFIFO, NFFIFO },
425 { 0, NFNON },
426 { 0, NFNON },
427};
428
429struct compound_hdr {
430 int32_t status;
431 uint32_t nops;
432 uint32_t taglen;
433 char * tag;
434};
435
436/*
437 * START OF "GENERIC" ENCODE ROUTINES.
438 * These may look a little ugly since they are imported from a "generic"
439 * set of XDR encode/decode routines which are intended to be shared by
440 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
441 *
442 * If the pain of reading these is too great, it should be a straightforward
443 * task to translate them into Linux-specific versions which are more
444 * consistent with the style used in NFSv2/v3...
445 */
446#define WRITE32(n) *p++ = htonl(n)
447#define WRITE64(n) do { \
448 *p++ = htonl((uint32_t)((n) >> 32)); \
449 *p++ = htonl((uint32_t)(n)); \
450} while (0)
451#define WRITEMEM(ptr,nbytes) do { \
452 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
453} while (0)
454
455#define RESERVE_SPACE(nbytes) do { \
456 p = xdr_reserve_space(xdr, nbytes); \
457 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
458 BUG_ON(!p); \
459} while (0)
460
461static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
462{
463 uint32_t *p;
464
465 p = xdr_reserve_space(xdr, 4 + len);
466 BUG_ON(p == NULL);
467 xdr_encode_opaque(p, str, len);
468}
469
470static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
471{
472 uint32_t *p;
473
474 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
475 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
476 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
477 WRITE32(hdr->taglen);
478 WRITEMEM(hdr->tag, hdr->taglen);
479 WRITE32(NFS4_MINOR_VERSION);
480 WRITE32(hdr->nops);
481 return 0;
482}
483
484static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
485{
486 uint32_t *p;
487
488 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
489 BUG_ON(p == NULL);
490 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
491}
492
493static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
494{
495 char owner_name[IDMAP_NAMESZ];
496 char owner_group[IDMAP_NAMESZ];
497 int owner_namelen = 0;
498 int owner_grouplen = 0;
499 uint32_t *p;
500 uint32_t *q;
501 int len;
502 uint32_t bmval0 = 0;
503 uint32_t bmval1 = 0;
504 int status;
505
506 /*
507 * We reserve enough space to write the entire attribute buffer at once.
508 * In the worst-case, this would be
509 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
510 * = 36 bytes, plus any contribution from variable-length fields
23ec6965 511 * such as owner/group.
1da177e4
LT
512 */
513 len = 16;
514
515 /* Sigh */
516 if (iap->ia_valid & ATTR_SIZE)
517 len += 8;
518 if (iap->ia_valid & ATTR_MODE)
519 len += 4;
520 if (iap->ia_valid & ATTR_UID) {
521 owner_namelen = nfs_map_uid_to_name(server->nfs4_state, iap->ia_uid, owner_name);
522 if (owner_namelen < 0) {
523 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
524 iap->ia_uid);
525 /* XXX */
526 strcpy(owner_name, "nobody");
527 owner_namelen = sizeof("nobody") - 1;
528 /* goto out; */
529 }
530 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
531 }
532 if (iap->ia_valid & ATTR_GID) {
533 owner_grouplen = nfs_map_gid_to_group(server->nfs4_state, iap->ia_gid, owner_group);
534 if (owner_grouplen < 0) {
535 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
536 iap->ia_gid);
537 strcpy(owner_group, "nobody");
538 owner_grouplen = sizeof("nobody") - 1;
539 /* goto out; */
540 }
541 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
542 }
543 if (iap->ia_valid & ATTR_ATIME_SET)
544 len += 16;
545 else if (iap->ia_valid & ATTR_ATIME)
546 len += 4;
547 if (iap->ia_valid & ATTR_MTIME_SET)
548 len += 16;
549 else if (iap->ia_valid & ATTR_MTIME)
550 len += 4;
551 RESERVE_SPACE(len);
552
553 /*
554 * We write the bitmap length now, but leave the bitmap and the attribute
555 * buffer length to be backfilled at the end of this routine.
556 */
557 WRITE32(2);
558 q = p;
559 p += 3;
560
561 if (iap->ia_valid & ATTR_SIZE) {
562 bmval0 |= FATTR4_WORD0_SIZE;
563 WRITE64(iap->ia_size);
564 }
565 if (iap->ia_valid & ATTR_MODE) {
566 bmval1 |= FATTR4_WORD1_MODE;
567 WRITE32(iap->ia_mode);
568 }
569 if (iap->ia_valid & ATTR_UID) {
570 bmval1 |= FATTR4_WORD1_OWNER;
571 WRITE32(owner_namelen);
572 WRITEMEM(owner_name, owner_namelen);
573 }
574 if (iap->ia_valid & ATTR_GID) {
575 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
576 WRITE32(owner_grouplen);
577 WRITEMEM(owner_group, owner_grouplen);
578 }
579 if (iap->ia_valid & ATTR_ATIME_SET) {
580 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
581 WRITE32(NFS4_SET_TO_CLIENT_TIME);
582 WRITE32(0);
583 WRITE32(iap->ia_mtime.tv_sec);
584 WRITE32(iap->ia_mtime.tv_nsec);
585 }
586 else if (iap->ia_valid & ATTR_ATIME) {
587 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
588 WRITE32(NFS4_SET_TO_SERVER_TIME);
589 }
590 if (iap->ia_valid & ATTR_MTIME_SET) {
591 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
592 WRITE32(NFS4_SET_TO_CLIENT_TIME);
593 WRITE32(0);
594 WRITE32(iap->ia_mtime.tv_sec);
595 WRITE32(iap->ia_mtime.tv_nsec);
596 }
597 else if (iap->ia_valid & ATTR_MTIME) {
598 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
599 WRITE32(NFS4_SET_TO_SERVER_TIME);
600 }
601
602 /*
603 * Now we backfill the bitmap and the attribute buffer length.
604 */
605 if (len != ((char *)p - (char *)q) + 4) {
606 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
607 len, ((char *)p - (char *)q) + 4);
608 BUG();
609 }
610 len = (char *)p - (char *)q - 12;
611 *q++ = htonl(bmval0);
612 *q++ = htonl(bmval1);
613 *q++ = htonl(len);
614
615 status = 0;
616/* out: */
617 return status;
618}
619
620static int encode_access(struct xdr_stream *xdr, u32 access)
621{
622 uint32_t *p;
623
624 RESERVE_SPACE(8);
625 WRITE32(OP_ACCESS);
626 WRITE32(access);
627
628 return 0;
629}
630
631static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
632{
633 uint32_t *p;
634
9512135d 635 RESERVE_SPACE(8+sizeof(arg->stateid->data));
1da177e4 636 WRITE32(OP_CLOSE);
cee54fc9 637 WRITE32(arg->seqid->sequence->counter);
9512135d 638 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
1da177e4
LT
639
640 return 0;
641}
642
643static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
644{
645 uint32_t *p;
646
647 RESERVE_SPACE(16);
648 WRITE32(OP_COMMIT);
649 WRITE64(args->offset);
650 WRITE32(args->count);
651
652 return 0;
653}
654
655static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
656{
657 uint32_t *p;
658
659 RESERVE_SPACE(8);
660 WRITE32(OP_CREATE);
661 WRITE32(create->ftype);
662
663 switch (create->ftype) {
664 case NF4LNK:
665 RESERVE_SPACE(4 + create->u.symlink->len);
666 WRITE32(create->u.symlink->len);
667 WRITEMEM(create->u.symlink->name, create->u.symlink->len);
668 break;
669
670 case NF4BLK: case NF4CHR:
671 RESERVE_SPACE(8);
672 WRITE32(create->u.device.specdata1);
673 WRITE32(create->u.device.specdata2);
674 break;
675
676 default:
677 break;
678 }
679
680 RESERVE_SPACE(4 + create->name->len);
681 WRITE32(create->name->len);
682 WRITEMEM(create->name->name, create->name->len);
683
684 return encode_attrs(xdr, create->attrs, create->server);
685}
686
687static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
688{
689 uint32_t *p;
690
691 RESERVE_SPACE(12);
692 WRITE32(OP_GETATTR);
693 WRITE32(1);
694 WRITE32(bitmap);
695 return 0;
696}
697
698static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
699{
700 uint32_t *p;
701
702 RESERVE_SPACE(16);
703 WRITE32(OP_GETATTR);
704 WRITE32(2);
705 WRITE32(bm0);
706 WRITE32(bm1);
707 return 0;
708}
709
710static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
711{
1da177e4
LT
712 return encode_getattr_two(xdr,
713 bitmask[0] & nfs4_fattr_bitmap[0],
714 bitmask[1] & nfs4_fattr_bitmap[1]);
715}
716
717static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
718{
1da177e4
LT
719 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
720 bitmask[1] & nfs4_fsinfo_bitmap[1]);
721}
722
723static int encode_getfh(struct xdr_stream *xdr)
724{
725 uint32_t *p;
726
727 RESERVE_SPACE(4);
728 WRITE32(OP_GETFH);
729
730 return 0;
731}
732
733static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
734{
735 uint32_t *p;
736
737 RESERVE_SPACE(8 + name->len);
738 WRITE32(OP_LINK);
739 WRITE32(name->len);
740 WRITEMEM(name->name, name->len);
741
742 return 0;
743}
744
745/*
746 * opcode,type,reclaim,offset,length,new_lock_owner = 32
747 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
748 */
749static int encode_lock(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
750{
751 uint32_t *p;
752 struct nfs_lock_opargs *opargs = arg->u.lock;
753
754 RESERVE_SPACE(32);
755 WRITE32(OP_LOCK);
756 WRITE32(arg->type);
757 WRITE32(opargs->reclaim);
758 WRITE64(arg->offset);
759 WRITE64(arg->length);
760 WRITE32(opargs->new_lock_owner);
761 if (opargs->new_lock_owner){
1da177e4 762 RESERVE_SPACE(40);
06735b34
TM
763 WRITE32(opargs->open_seqid->sequence->counter);
764 WRITEMEM(opargs->open_stateid->data, sizeof(opargs->open_stateid->data));
765 WRITE32(opargs->lock_seqid->sequence->counter);
766 WRITE64(opargs->lock_owner.clientid);
1da177e4 767 WRITE32(4);
06735b34 768 WRITE32(opargs->lock_owner.id);
1da177e4
LT
769 }
770 else {
1da177e4 771 RESERVE_SPACE(20);
06735b34
TM
772 WRITEMEM(opargs->lock_stateid->data, sizeof(opargs->lock_stateid->data));
773 WRITE32(opargs->lock_seqid->sequence->counter);
1da177e4
LT
774 }
775
776 return 0;
777}
778
779static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
780{
781 uint32_t *p;
782 struct nfs_lowner *opargs = arg->u.lockt;
783
784 RESERVE_SPACE(40);
785 WRITE32(OP_LOCKT);
786 WRITE32(arg->type);
787 WRITE64(arg->offset);
788 WRITE64(arg->length);
789 WRITE64(opargs->clientid);
790 WRITE32(4);
791 WRITE32(opargs->id);
792
793 return 0;
794}
795
796static int encode_locku(struct xdr_stream *xdr, const struct nfs_lockargs *arg)
797{
798 uint32_t *p;
799 struct nfs_locku_opargs *opargs = arg->u.locku;
800
801 RESERVE_SPACE(44);
802 WRITE32(OP_LOCKU);
803 WRITE32(arg->type);
cee54fc9 804 WRITE32(opargs->seqid->sequence->counter);
faf5f49c 805 WRITEMEM(opargs->stateid->data, sizeof(opargs->stateid->data));
1da177e4
LT
806 WRITE64(arg->offset);
807 WRITE64(arg->length);
808
809 return 0;
810}
811
812static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
813{
814 int len = name->len;
815 uint32_t *p;
816
817 RESERVE_SPACE(8 + len);
818 WRITE32(OP_LOOKUP);
819 WRITE32(len);
820 WRITEMEM(name->name, len);
821
822 return 0;
823}
824
825static void encode_share_access(struct xdr_stream *xdr, int open_flags)
826{
827 uint32_t *p;
828
829 RESERVE_SPACE(8);
830 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
831 case FMODE_READ:
832 WRITE32(NFS4_SHARE_ACCESS_READ);
833 break;
834 case FMODE_WRITE:
835 WRITE32(NFS4_SHARE_ACCESS_WRITE);
836 break;
837 case FMODE_READ|FMODE_WRITE:
838 WRITE32(NFS4_SHARE_ACCESS_BOTH);
839 break;
840 default:
841 BUG();
842 }
843 WRITE32(0); /* for linux, share_deny = 0 always */
844}
845
846static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
847{
848 uint32_t *p;
849 /*
850 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
851 * owner 4 = 32
852 */
853 RESERVE_SPACE(8);
854 WRITE32(OP_OPEN);
cee54fc9 855 WRITE32(arg->seqid->sequence->counter);
1da177e4
LT
856 encode_share_access(xdr, arg->open_flags);
857 RESERVE_SPACE(16);
858 WRITE64(arg->clientid);
859 WRITE32(4);
860 WRITE32(arg->id);
861}
862
863static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
864{
865 uint32_t *p;
866
867 RESERVE_SPACE(4);
868 switch(arg->open_flags & O_EXCL) {
869 case 0:
870 WRITE32(NFS4_CREATE_UNCHECKED);
871 encode_attrs(xdr, arg->u.attrs, arg->server);
872 break;
873 default:
874 WRITE32(NFS4_CREATE_EXCLUSIVE);
875 encode_nfs4_verifier(xdr, &arg->u.verifier);
876 }
877}
878
879static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
880{
881 uint32_t *p;
882
883 RESERVE_SPACE(4);
884 switch (arg->open_flags & O_CREAT) {
885 case 0:
886 WRITE32(NFS4_OPEN_NOCREATE);
887 break;
888 default:
889 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
890 WRITE32(NFS4_OPEN_CREATE);
891 encode_createmode(xdr, arg);
892 }
893}
894
895static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
896{
897 uint32_t *p;
898
899 RESERVE_SPACE(4);
900 switch (delegation_type) {
901 case 0:
902 WRITE32(NFS4_OPEN_DELEGATE_NONE);
903 break;
904 case FMODE_READ:
905 WRITE32(NFS4_OPEN_DELEGATE_READ);
906 break;
907 case FMODE_WRITE|FMODE_READ:
908 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
909 break;
910 default:
911 BUG();
912 }
913}
914
915static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
916{
917 uint32_t *p;
918
919 RESERVE_SPACE(4);
920 WRITE32(NFS4_OPEN_CLAIM_NULL);
921 encode_string(xdr, name->len, name->name);
922}
923
924static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
925{
926 uint32_t *p;
927
928 RESERVE_SPACE(4);
929 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
930 encode_delegation_type(xdr, type);
931}
932
933static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
934{
935 uint32_t *p;
936
937 RESERVE_SPACE(4+sizeof(stateid->data));
938 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
939 WRITEMEM(stateid->data, sizeof(stateid->data));
940 encode_string(xdr, name->len, name->name);
941}
942
943static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
944{
945 encode_openhdr(xdr, arg);
946 encode_opentype(xdr, arg);
947 switch (arg->claim) {
948 case NFS4_OPEN_CLAIM_NULL:
949 encode_claim_null(xdr, arg->name);
950 break;
951 case NFS4_OPEN_CLAIM_PREVIOUS:
952 encode_claim_previous(xdr, arg->u.delegation_type);
953 break;
954 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
955 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
956 break;
957 default:
958 BUG();
959 }
960 return 0;
961}
962
963static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
964{
965 uint32_t *p;
966
967 RESERVE_SPACE(8+sizeof(arg->stateid.data));
968 WRITE32(OP_OPEN_CONFIRM);
969 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
cee54fc9 970 WRITE32(arg->seqid->sequence->counter);
1da177e4
LT
971
972 return 0;
973}
974
975static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
976{
977 uint32_t *p;
978
9512135d 979 RESERVE_SPACE(8+sizeof(arg->stateid->data));
1da177e4 980 WRITE32(OP_OPEN_DOWNGRADE);
9512135d 981 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
cee54fc9 982 WRITE32(arg->seqid->sequence->counter);
1da177e4
LT
983 encode_share_access(xdr, arg->open_flags);
984 return 0;
985}
986
987static int
988encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
989{
990 int len = fh->size;
991 uint32_t *p;
992
993 RESERVE_SPACE(8 + len);
994 WRITE32(OP_PUTFH);
995 WRITE32(len);
996 WRITEMEM(fh->data, len);
997
998 return 0;
999}
1000
1001static int encode_putrootfh(struct xdr_stream *xdr)
1002{
1003 uint32_t *p;
1004
1005 RESERVE_SPACE(4);
1006 WRITE32(OP_PUTROOTFH);
1007
1008 return 0;
1009}
1010
1011static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1012{
1da177e4
LT
1013 nfs4_stateid stateid;
1014 uint32_t *p;
1015
1016 RESERVE_SPACE(16);
1017 if (ctx->state != NULL) {
1018 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1019 WRITEMEM(stateid.data, sizeof(stateid.data));
1020 } else
1021 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1022}
1023
1024static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1025{
1026 uint32_t *p;
1027
1028 RESERVE_SPACE(4);
1029 WRITE32(OP_READ);
1030
1031 encode_stateid(xdr, args->context);
1032
1033 RESERVE_SPACE(12);
1034 WRITE64(args->offset);
1035 WRITE32(args->count);
1036
1037 return 0;
1038}
1039
1040static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1041{
1042 struct rpc_auth *auth = req->rq_task->tk_auth;
97d312d0
MN
1043 uint32_t attrs[2] = {
1044 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1045 FATTR4_WORD1_MOUNTED_ON_FILEID,
1046 };
1da177e4
LT
1047 int replen;
1048 uint32_t *p;
1049
1050 RESERVE_SPACE(32+sizeof(nfs4_verifier));
1051 WRITE32(OP_READDIR);
1052 WRITE64(readdir->cookie);
1053 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1054 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1055 WRITE32(readdir->count);
1056 WRITE32(2);
97d312d0
MN
1057 /* Switch to mounted_on_fileid if the server supports it */
1058 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1059 attrs[0] &= ~FATTR4_WORD0_FILEID;
1060 else
1061 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1062 WRITE32(attrs[0] & readdir->bitmask[0]);
1063 WRITE32(attrs[1] & readdir->bitmask[1]);
eadf4598
TM
1064 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1065 __FUNCTION__,
1066 (unsigned long long)readdir->cookie,
1067 ((u32 *)readdir->verifier.data)[0],
1068 ((u32 *)readdir->verifier.data)[1],
1069 attrs[0] & readdir->bitmask[0],
1070 attrs[1] & readdir->bitmask[1]);
1da177e4
LT
1071
1072 /* set up reply kvec
1073 * toplevel_status + taglen + rescount + OP_PUTFH + status
1074 * + OP_READDIR + status + verifer(2) = 9
1075 */
1076 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1077 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1078 readdir->pgbase, readdir->count);
eadf4598
TM
1079 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1080 __FUNCTION__, replen, readdir->pages,
1081 readdir->pgbase, readdir->count);
1da177e4
LT
1082
1083 return 0;
1084}
1085
1086static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1087{
1088 struct rpc_auth *auth = req->rq_task->tk_auth;
1089 unsigned int replen;
1090 uint32_t *p;
1091
1092 RESERVE_SPACE(4);
1093 WRITE32(OP_READLINK);
1094
1095 /* set up reply kvec
1096 * toplevel_status + taglen + rescount + OP_PUTFH + status
1097 * + OP_READLINK + status + string length = 8
1098 */
1099 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1100 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1101 readlink->pgbase, readlink->pglen);
1102
1103 return 0;
1104}
1105
1106static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1107{
1108 uint32_t *p;
1109
1110 RESERVE_SPACE(8 + name->len);
1111 WRITE32(OP_REMOVE);
1112 WRITE32(name->len);
1113 WRITEMEM(name->name, name->len);
1114
1115 return 0;
1116}
1117
1118static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1119{
1120 uint32_t *p;
1121
1122 RESERVE_SPACE(8 + oldname->len);
1123 WRITE32(OP_RENAME);
1124 WRITE32(oldname->len);
1125 WRITEMEM(oldname->name, oldname->len);
1126
1127 RESERVE_SPACE(4 + newname->len);
1128 WRITE32(newname->len);
1129 WRITEMEM(newname->name, newname->len);
1130
1131 return 0;
1132}
1133
1134static int encode_renew(struct xdr_stream *xdr, const struct nfs4_client *client_stateid)
1135{
1136 uint32_t *p;
1137
1138 RESERVE_SPACE(12);
1139 WRITE32(OP_RENEW);
1140 WRITE64(client_stateid->cl_clientid);
1141
1142 return 0;
1143}
1144
56ae19f3
TM
1145static int
1146encode_restorefh(struct xdr_stream *xdr)
1147{
1148 uint32_t *p;
1149
1150 RESERVE_SPACE(4);
1151 WRITE32(OP_RESTOREFH);
1152
1153 return 0;
1154}
1155
23ec6965
BF
1156static int
1157encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1158{
1159 uint32_t *p;
1160
1161 RESERVE_SPACE(4+sizeof(zero_stateid.data));
1162 WRITE32(OP_SETATTR);
1163 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1164 RESERVE_SPACE(2*4);
1165 WRITE32(1);
1166 WRITE32(FATTR4_WORD0_ACL);
1167 if (arg->acl_len % 4)
1168 return -EINVAL;
1169 RESERVE_SPACE(4);
1170 WRITE32(arg->acl_len);
1171 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1172 return 0;
1173}
1174
1da177e4
LT
1175static int
1176encode_savefh(struct xdr_stream *xdr)
1177{
1178 uint32_t *p;
1179
1180 RESERVE_SPACE(4);
1181 WRITE32(OP_SAVEFH);
1182
1183 return 0;
1184}
1185
1186static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1187{
1188 int status;
1189 uint32_t *p;
1190
1191 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1192 WRITE32(OP_SETATTR);
1193 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1194
1195 if ((status = encode_attrs(xdr, arg->iap, server)))
1196 return status;
1197
1198 return 0;
1199}
1200
1201static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1202{
1203 uint32_t *p;
1204
1205 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1206 WRITE32(OP_SETCLIENTID);
1207 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1208
1209 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1210 RESERVE_SPACE(4);
1211 WRITE32(setclientid->sc_prog);
1212 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1213 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1214 RESERVE_SPACE(4);
1215 WRITE32(setclientid->sc_cb_ident);
1216
1217 return 0;
1218}
1219
1220static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_client *client_state)
1221{
1222 uint32_t *p;
1223
1224 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1225 WRITE32(OP_SETCLIENTID_CONFIRM);
1226 WRITE64(client_state->cl_clientid);
1227 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1228
1229 return 0;
1230}
1231
1232static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1233{
1234 uint32_t *p;
1235
1236 RESERVE_SPACE(4);
1237 WRITE32(OP_WRITE);
1238
1239 encode_stateid(xdr, args->context);
1240
1241 RESERVE_SPACE(16);
1242 WRITE64(args->offset);
1243 WRITE32(args->stable);
1244 WRITE32(args->count);
1245
1246 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1247
1248 return 0;
1249}
1250
1251static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1252{
1253 uint32_t *p;
1254
1255 RESERVE_SPACE(20);
1256
1257 WRITE32(OP_DELEGRETURN);
1258 WRITEMEM(stateid->data, sizeof(stateid->data));
1259 return 0;
1260
1261}
1262/*
1263 * END OF "GENERIC" ENCODE ROUTINES.
1264 */
1265
1266/*
1267 * Encode an ACCESS request
1268 */
1269static int nfs4_xdr_enc_access(struct rpc_rqst *req, uint32_t *p, const struct nfs4_accessargs *args)
1270{
1271 struct xdr_stream xdr;
1272 struct compound_hdr hdr = {
1273 .nops = 2,
1274 };
1275 int status;
1276
1277 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1278 encode_compound_hdr(&xdr, &hdr);
1279 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1280 status = encode_access(&xdr, args->access);
1281 return status;
1282}
1283
1284/*
1285 * Encode LOOKUP request
1286 */
1287static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_arg *args)
1288{
1289 struct xdr_stream xdr;
1290 struct compound_hdr hdr = {
1291 .nops = 4,
1292 };
1293 int status;
1294
1295 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1296 encode_compound_hdr(&xdr, &hdr);
1297 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1298 goto out;
1299 if ((status = encode_lookup(&xdr, args->name)) != 0)
1300 goto out;
1301 if ((status = encode_getfh(&xdr)) != 0)
1302 goto out;
1303 status = encode_getfattr(&xdr, args->bitmask);
1304out:
1305 return status;
1306}
1307
1308/*
1309 * Encode LOOKUP_ROOT request
1310 */
1311static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, uint32_t *p, const struct nfs4_lookup_root_arg *args)
1312{
1313 struct xdr_stream xdr;
1314 struct compound_hdr hdr = {
1315 .nops = 3,
1316 };
1317 int status;
1318
1319 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1320 encode_compound_hdr(&xdr, &hdr);
1321 if ((status = encode_putrootfh(&xdr)) != 0)
1322 goto out;
1323 if ((status = encode_getfh(&xdr)) == 0)
1324 status = encode_getfattr(&xdr, args->bitmask);
1325out:
1326 return status;
1327}
1328
1329/*
1330 * Encode REMOVE request
1331 */
1332static int nfs4_xdr_enc_remove(struct rpc_rqst *req, uint32_t *p, const struct nfs4_remove_arg *args)
1333{
1334 struct xdr_stream xdr;
1335 struct compound_hdr hdr = {
16e42959 1336 .nops = 3,
1da177e4
LT
1337 };
1338 int status;
1339
1340 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1341 encode_compound_hdr(&xdr, &hdr);
16e42959
TM
1342 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1343 goto out;
1344 if ((status = encode_remove(&xdr, args->name)) != 0)
1345 goto out;
1346 status = encode_getfattr(&xdr, args->bitmask);
1347out:
1da177e4
LT
1348 return status;
1349}
1350
1351/*
1352 * Encode RENAME request
1353 */
1354static int nfs4_xdr_enc_rename(struct rpc_rqst *req, uint32_t *p, const struct nfs4_rename_arg *args)
1355{
1356 struct xdr_stream xdr;
1357 struct compound_hdr hdr = {
6caf2c82 1358 .nops = 7,
1da177e4
LT
1359 };
1360 int status;
1361
1362 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1363 encode_compound_hdr(&xdr, &hdr);
1364 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1365 goto out;
1366 if ((status = encode_savefh(&xdr)) != 0)
1367 goto out;
1368 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1369 goto out;
6caf2c82
TM
1370 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
1371 goto out;
1372 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1373 goto out;
1374 if ((status = encode_restorefh(&xdr)) != 0)
1375 goto out;
1376 status = encode_getfattr(&xdr, args->bitmask);
1da177e4
LT
1377out:
1378 return status;
1379}
1380
1381/*
1382 * Encode LINK request
1383 */
1384static int nfs4_xdr_enc_link(struct rpc_rqst *req, uint32_t *p, const struct nfs4_link_arg *args)
1385{
1386 struct xdr_stream xdr;
1387 struct compound_hdr hdr = {
91ba2eee 1388 .nops = 7,
1da177e4
LT
1389 };
1390 int status;
1391
1392 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1393 encode_compound_hdr(&xdr, &hdr);
1394 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1395 goto out;
1396 if ((status = encode_savefh(&xdr)) != 0)
1397 goto out;
1398 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1399 goto out;
91ba2eee
TM
1400 if ((status = encode_link(&xdr, args->name)) != 0)
1401 goto out;
1402 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1403 goto out;
1404 if ((status = encode_restorefh(&xdr)) != 0)
1405 goto out;
1406 status = encode_getfattr(&xdr, args->bitmask);
1da177e4
LT
1407out:
1408 return status;
1409}
1410
1411/*
1412 * Encode CREATE request
1413 */
1414static int nfs4_xdr_enc_create(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1415{
1416 struct xdr_stream xdr;
1417 struct compound_hdr hdr = {
56ae19f3 1418 .nops = 7,
1da177e4
LT
1419 };
1420 int status;
1421
1422 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1423 encode_compound_hdr(&xdr, &hdr);
1424 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1425 goto out;
56ae19f3
TM
1426 if ((status = encode_savefh(&xdr)) != 0)
1427 goto out;
1da177e4
LT
1428 if ((status = encode_create(&xdr, args)) != 0)
1429 goto out;
1430 if ((status = encode_getfh(&xdr)) != 0)
1431 goto out;
56ae19f3
TM
1432 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1433 goto out;
1434 if ((status = encode_restorefh(&xdr)) != 0)
1435 goto out;
1da177e4
LT
1436 status = encode_getfattr(&xdr, args->bitmask);
1437out:
1438 return status;
1439}
1440
1441/*
1442 * Encode SYMLINK request
1443 */
1444static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_create_arg *args)
1445{
1446 return nfs4_xdr_enc_create(req, p, args);
1447}
1448
1449/*
1450 * Encode GETATTR request
1451 */
1452static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, uint32_t *p, const struct nfs4_getattr_arg *args)
1453{
1454 struct xdr_stream xdr;
1455 struct compound_hdr hdr = {
1456 .nops = 2,
1457 };
1458 int status;
1459
1460 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1461 encode_compound_hdr(&xdr, &hdr);
1462 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1463 status = encode_getfattr(&xdr, args->bitmask);
1464 return status;
1465}
1466
1467/*
1468 * Encode a CLOSE request
1469 */
1470static int nfs4_xdr_enc_close(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1471{
1472 struct xdr_stream xdr;
1473 struct compound_hdr hdr = {
516a6af6 1474 .nops = 3,
1da177e4
LT
1475 };
1476 int status;
1477
1478 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1479 encode_compound_hdr(&xdr, &hdr);
1480 status = encode_putfh(&xdr, args->fh);
1481 if(status)
1482 goto out;
1483 status = encode_close(&xdr, args);
516a6af6
TM
1484 if (status != 0)
1485 goto out;
1486 status = encode_getfattr(&xdr, args->bitmask);
1da177e4
LT
1487out:
1488 return status;
1489}
1490
1491/*
1492 * Encode an OPEN request
1493 */
1494static int nfs4_xdr_enc_open(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1495{
1496 struct xdr_stream xdr;
1497 struct compound_hdr hdr = {
56ae19f3 1498 .nops = 7,
1da177e4
LT
1499 };
1500 int status;
1501
cee54fc9
TM
1502 status = nfs_wait_on_sequence(args->seqid, req->rq_task);
1503 if (status != 0)
1504 goto out;
1da177e4
LT
1505 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1506 encode_compound_hdr(&xdr, &hdr);
1507 status = encode_putfh(&xdr, args->fh);
56ae19f3
TM
1508 if (status)
1509 goto out;
1510 status = encode_savefh(&xdr);
1da177e4
LT
1511 if (status)
1512 goto out;
1513 status = encode_open(&xdr, args);
1514 if (status)
1515 goto out;
1516 status = encode_getfh(&xdr);
1517 if (status)
1518 goto out;
1519 status = encode_getfattr(&xdr, args->bitmask);
56ae19f3
TM
1520 if (status)
1521 goto out;
1522 status = encode_restorefh(&xdr);
1523 if (status)
1524 goto out;
1525 status = encode_getfattr(&xdr, args->bitmask);
1da177e4
LT
1526out:
1527 return status;
1528}
1529
1530/*
1531 * Encode an OPEN_CONFIRM request
1532 */
1533static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_open_confirmargs *args)
1534{
1535 struct xdr_stream xdr;
1536 struct compound_hdr hdr = {
1537 .nops = 2,
1538 };
1539 int status;
1540
cee54fc9
TM
1541 status = nfs_wait_on_sequence(args->seqid, req->rq_task);
1542 if (status != 0)
1543 goto out;
1da177e4
LT
1544 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1545 encode_compound_hdr(&xdr, &hdr);
1546 status = encode_putfh(&xdr, args->fh);
1547 if(status)
1548 goto out;
1549 status = encode_open_confirm(&xdr, args);
1550out:
1551 return status;
1552}
1553
1554/*
1555 * Encode an OPEN request with no attributes.
1556 */
1557static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, uint32_t *p, struct nfs_openargs *args)
1558{
1559 struct xdr_stream xdr;
1560 struct compound_hdr hdr = {
1561 .nops = 2,
1562 };
1563 int status;
1564
cee54fc9
TM
1565 status = nfs_wait_on_sequence(args->seqid, req->rq_task);
1566 if (status != 0)
1567 goto out;
1da177e4
LT
1568 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1569 encode_compound_hdr(&xdr, &hdr);
1570 status = encode_putfh(&xdr, args->fh);
1571 if (status)
1572 goto out;
1573 status = encode_open(&xdr, args);
1574out:
1575 return status;
1576}
1577
1578/*
1579 * Encode an OPEN_DOWNGRADE request
1580 */
1581static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, uint32_t *p, struct nfs_closeargs *args)
1582{
1583 struct xdr_stream xdr;
1584 struct compound_hdr hdr = {
516a6af6 1585 .nops = 3,
1da177e4
LT
1586 };
1587 int status;
1588
1589 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1590 encode_compound_hdr(&xdr, &hdr);
1591 status = encode_putfh(&xdr, args->fh);
1592 if (status)
1593 goto out;
1594 status = encode_open_downgrade(&xdr, args);
516a6af6
TM
1595 if (status != 0)
1596 goto out;
1597 status = encode_getfattr(&xdr, args->bitmask);
1da177e4
LT
1598out:
1599 return status;
1600}
1601
1602/*
1603 * Encode a LOCK request
1604 */
1605static int nfs4_xdr_enc_lock(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1606{
1607 struct xdr_stream xdr;
1608 struct compound_hdr hdr = {
1609 .nops = 2,
1610 };
cee54fc9 1611 struct nfs_lock_opargs *opargs = args->u.lock;
1da177e4
LT
1612 int status;
1613
06735b34 1614 status = nfs_wait_on_sequence(opargs->lock_seqid, req->rq_task);
cee54fc9
TM
1615 if (status != 0)
1616 goto out;
06735b34
TM
1617 /* Do we need to do an open_to_lock_owner? */
1618 if (opargs->lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)
1619 opargs->new_lock_owner = 0;
1da177e4
LT
1620 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1621 encode_compound_hdr(&xdr, &hdr);
1622 status = encode_putfh(&xdr, args->fh);
1623 if(status)
1624 goto out;
1625 status = encode_lock(&xdr, args);
1626out:
1627 return status;
1628}
1629
1630/*
1631 * Encode a LOCKT request
1632 */
1633static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1634{
1635 struct xdr_stream xdr;
1636 struct compound_hdr hdr = {
1637 .nops = 2,
1638 };
1639 int status;
1640
1641 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1642 encode_compound_hdr(&xdr, &hdr);
1643 status = encode_putfh(&xdr, args->fh);
1644 if(status)
1645 goto out;
1646 status = encode_lockt(&xdr, args);
1647out:
1648 return status;
1649}
1650
1651/*
1652 * Encode a LOCKU request
1653 */
1654static int nfs4_xdr_enc_locku(struct rpc_rqst *req, uint32_t *p, struct nfs_lockargs *args)
1655{
1656 struct xdr_stream xdr;
1657 struct compound_hdr hdr = {
1658 .nops = 2,
1659 };
1660 int status;
1661
1662 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1663 encode_compound_hdr(&xdr, &hdr);
1664 status = encode_putfh(&xdr, args->fh);
1665 if(status)
1666 goto out;
1667 status = encode_locku(&xdr, args);
1668out:
1669 return status;
1670}
1671
1672/*
1673 * Encode a READLINK request
1674 */
1675static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readlink *args)
1676{
1677 struct xdr_stream xdr;
1678 struct compound_hdr hdr = {
1679 .nops = 2,
1680 };
1681 int status;
1682
1683 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1684 encode_compound_hdr(&xdr, &hdr);
1685 status = encode_putfh(&xdr, args->fh);
1686 if(status)
1687 goto out;
1688 status = encode_readlink(&xdr, args, req);
1689out:
1690 return status;
1691}
1692
1693/*
1694 * Encode a READDIR request
1695 */
1696static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, uint32_t *p, const struct nfs4_readdir_arg *args)
1697{
1698 struct xdr_stream xdr;
1699 struct compound_hdr hdr = {
1700 .nops = 2,
1701 };
1702 int status;
1703
1704 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1705 encode_compound_hdr(&xdr, &hdr);
1706 status = encode_putfh(&xdr, args->fh);
1707 if(status)
1708 goto out;
1709 status = encode_readdir(&xdr, args, req);
1710out:
1711 return status;
1712}
1713
1714/*
1715 * Encode a READ request
1716 */
1717static int nfs4_xdr_enc_read(struct rpc_rqst *req, uint32_t *p, struct nfs_readargs *args)
1718{
1719 struct rpc_auth *auth = req->rq_task->tk_auth;
1720 struct xdr_stream xdr;
1721 struct compound_hdr hdr = {
1722 .nops = 2,
1723 };
1724 int replen, status;
1725
1726 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1727 encode_compound_hdr(&xdr, &hdr);
1728 status = encode_putfh(&xdr, args->fh);
1729 if (status)
1730 goto out;
1731 status = encode_read(&xdr, args);
1732 if (status)
1733 goto out;
1734
1735 /* set up reply kvec
1736 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1737 * + OP_READ + status + eof + datalen = 9
1738 */
1739 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1740 xdr_inline_pages(&req->rq_rcv_buf, replen,
1741 args->pages, args->pgbase, args->count);
1742out:
1743 return status;
1744}
1745
1746/*
1747 * Encode an SETATTR request
1748 */
1749static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, uint32_t *p, struct nfs_setattrargs *args)
1750
1751{
1752 struct xdr_stream xdr;
1753 struct compound_hdr hdr = {
1754 .nops = 3,
1755 };
1756 int status;
1757
1758 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1759 encode_compound_hdr(&xdr, &hdr);
1760 status = encode_putfh(&xdr, args->fh);
1761 if(status)
1762 goto out;
1763 status = encode_setattr(&xdr, args, args->server);
1764 if(status)
1765 goto out;
1766 status = encode_getfattr(&xdr, args->bitmask);
1767out:
1768 return status;
1769}
1770
029d105e
BF
1771/*
1772 * Encode a GETACL request
1773 */
1774static int
1775nfs4_xdr_enc_getacl(struct rpc_rqst *req, uint32_t *p,
1776 struct nfs_getaclargs *args)
1777{
1778 struct xdr_stream xdr;
1779 struct rpc_auth *auth = req->rq_task->tk_auth;
1780 struct compound_hdr hdr = {
1781 .nops = 2,
1782 };
1783 int replen, status;
1784
1785 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1786 encode_compound_hdr(&xdr, &hdr);
1787 status = encode_putfh(&xdr, args->fh);
1788 if (status)
1789 goto out;
1790 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1791 /* set up reply buffer: */
1792 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1793 xdr_inline_pages(&req->rq_rcv_buf, replen,
1794 args->acl_pages, args->acl_pgbase, args->acl_len);
1795out:
1796 return status;
1797}
1798
1da177e4
LT
1799/*
1800 * Encode a WRITE request
1801 */
1802static int nfs4_xdr_enc_write(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1803{
1804 struct xdr_stream xdr;
1805 struct compound_hdr hdr = {
4f9838c7 1806 .nops = 3,
1da177e4
LT
1807 };
1808 int status;
1809
1810 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1811 encode_compound_hdr(&xdr, &hdr);
1812 status = encode_putfh(&xdr, args->fh);
1813 if (status)
1814 goto out;
1815 status = encode_write(&xdr, args);
4f9838c7
TM
1816 if (status)
1817 goto out;
1818 status = encode_getfattr(&xdr, args->bitmask);
1da177e4
LT
1819out:
1820 return status;
1821}
1822
1823/*
1824 * a COMMIT request
1825 */
1826static int nfs4_xdr_enc_commit(struct rpc_rqst *req, uint32_t *p, struct nfs_writeargs *args)
1827{
1828 struct xdr_stream xdr;
1829 struct compound_hdr hdr = {
4f9838c7 1830 .nops = 3,
1da177e4
LT
1831 };
1832 int status;
1833
1834 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1835 encode_compound_hdr(&xdr, &hdr);
1836 status = encode_putfh(&xdr, args->fh);
1837 if (status)
1838 goto out;
1839 status = encode_commit(&xdr, args);
4f9838c7
TM
1840 if (status)
1841 goto out;
1842 status = encode_getfattr(&xdr, args->bitmask);
1da177e4
LT
1843out:
1844 return status;
1845}
1846
1847/*
1848 * FSINFO request
1849 */
1850static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs4_fsinfo_arg *args)
1851{
1852 struct xdr_stream xdr;
1853 struct compound_hdr hdr = {
1854 .nops = 2,
1855 };
1856 int status;
1857
1858 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1859 encode_compound_hdr(&xdr, &hdr);
1860 status = encode_putfh(&xdr, args->fh);
1861 if (!status)
1862 status = encode_fsinfo(&xdr, args->bitmask);
1863 return status;
1864}
1865
1866/*
1867 * a PATHCONF request
1868 */
1869static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, uint32_t *p, const struct nfs4_pathconf_arg *args)
1870{
1da177e4
LT
1871 struct xdr_stream xdr;
1872 struct compound_hdr hdr = {
1873 .nops = 2,
1874 };
1875 int status;
1876
1877 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1878 encode_compound_hdr(&xdr, &hdr);
1879 status = encode_putfh(&xdr, args->fh);
1880 if (!status)
1881 status = encode_getattr_one(&xdr,
1882 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1883 return status;
1884}
1885
1886/*
1887 * a STATFS request
1888 */
1889static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, uint32_t *p, const struct nfs4_statfs_arg *args)
1890{
1da177e4
LT
1891 struct xdr_stream xdr;
1892 struct compound_hdr hdr = {
1893 .nops = 2,
1894 };
1895 int status;
1896
1897 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1898 encode_compound_hdr(&xdr, &hdr);
1899 status = encode_putfh(&xdr, args->fh);
1900 if (status == 0)
1901 status = encode_getattr_two(&xdr,
1902 args->bitmask[0] & nfs4_statfs_bitmap[0],
1903 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1904 return status;
1905}
1906
1907/*
1908 * GETATTR_BITMAP request
1909 */
1910static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, uint32_t *p, const struct nfs_fh *fhandle)
1911{
1912 struct xdr_stream xdr;
1913 struct compound_hdr hdr = {
1914 .nops = 2,
1915 };
1916 int status;
1917
1918 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1919 encode_compound_hdr(&xdr, &hdr);
1920 status = encode_putfh(&xdr, fhandle);
1921 if (status == 0)
1922 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1923 FATTR4_WORD0_LINK_SUPPORT|
1924 FATTR4_WORD0_SYMLINK_SUPPORT|
1925 FATTR4_WORD0_ACLSUPPORT);
1926 return status;
1927}
1928
1929/*
1930 * a RENEW request
1931 */
1932static int nfs4_xdr_enc_renew(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1933{
1934 struct xdr_stream xdr;
1935 struct compound_hdr hdr = {
1936 .nops = 1,
1937 };
1938
1939 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1940 encode_compound_hdr(&xdr, &hdr);
1941 return encode_renew(&xdr, clp);
1942}
1943
1944/*
1945 * a SETCLIENTID request
1946 */
1947static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, uint32_t *p, struct nfs4_setclientid *sc)
1948{
1949 struct xdr_stream xdr;
1950 struct compound_hdr hdr = {
1951 .nops = 1,
1952 };
1953
1954 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1955 encode_compound_hdr(&xdr, &hdr);
1956 return encode_setclientid(&xdr, sc);
1957}
1958
1959/*
1960 * a SETCLIENTID_CONFIRM request
1961 */
1962static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs4_client *clp)
1963{
1964 struct xdr_stream xdr;
1965 struct compound_hdr hdr = {
1966 .nops = 3,
1967 };
1968 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1969 int status;
1970
1971 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1972 encode_compound_hdr(&xdr, &hdr);
1973 status = encode_setclientid_confirm(&xdr, clp);
1974 if (!status)
1975 status = encode_putrootfh(&xdr);
1976 if (!status)
1977 status = encode_fsinfo(&xdr, lease_bitmap);
1978 return status;
1979}
1980
1981/*
1982 * DELEGRETURN request
1983 */
1984static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, uint32_t *p, const struct nfs4_delegreturnargs *args)
1985{
1986 struct xdr_stream xdr;
1987 struct compound_hdr hdr = {
1988 .nops = 2,
1989 };
1990 int status;
1991
1992 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1993 encode_compound_hdr(&xdr, &hdr);
1994 if ((status = encode_putfh(&xdr, args->fhandle)) == 0)
1995 status = encode_delegreturn(&xdr, args->stateid);
1996 return status;
1997}
1998
1999/*
2000 * START OF "GENERIC" DECODE ROUTINES.
2001 * These may look a little ugly since they are imported from a "generic"
2002 * set of XDR encode/decode routines which are intended to be shared by
2003 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2004 *
2005 * If the pain of reading these is too great, it should be a straightforward
2006 * task to translate them into Linux-specific versions which are more
2007 * consistent with the style used in NFSv2/v3...
2008 */
2009#define READ32(x) (x) = ntohl(*p++)
2010#define READ64(x) do { \
2011 (x) = (u64)ntohl(*p++) << 32; \
2012 (x) |= ntohl(*p++); \
2013} while (0)
2014#define READTIME(x) do { \
2015 p++; \
2016 (x.tv_sec) = ntohl(*p++); \
2017 (x.tv_nsec) = ntohl(*p++); \
2018} while (0)
2019#define COPYMEM(x,nbytes) do { \
2020 memcpy((x), p, nbytes); \
2021 p += XDR_QUADLEN(nbytes); \
2022} while (0)
2023
2024#define READ_BUF(nbytes) do { \
2025 p = xdr_inline_decode(xdr, nbytes); \
2026 if (!p) { \
2027 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
2028 __FUNCTION__, __LINE__); \
2029 return -EIO; \
2030 } \
2031} while (0)
2032
2033static int decode_opaque_inline(struct xdr_stream *xdr, uint32_t *len, char **string)
2034{
2035 uint32_t *p;
2036
2037 READ_BUF(4);
2038 READ32(*len);
2039 READ_BUF(*len);
2040 *string = (char *)p;
2041 return 0;
2042}
2043
2044static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2045{
2046 uint32_t *p;
2047
2048 READ_BUF(8);
2049 READ32(hdr->status);
2050 READ32(hdr->taglen);
2051
2052 READ_BUF(hdr->taglen + 4);
2053 hdr->tag = (char *)p;
2054 p += XDR_QUADLEN(hdr->taglen);
2055 READ32(hdr->nops);
2056 return 0;
2057}
2058
2059static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2060{
2061 uint32_t *p;
2062 uint32_t opnum;
2063 int32_t nfserr;
2064
2065 READ_BUF(8);
2066 READ32(opnum);
2067 if (opnum != expected) {
2068 printk(KERN_NOTICE
2069 "nfs4_decode_op_hdr: Server returned operation"
2070 " %d but we issued a request for %d\n",
2071 opnum, expected);
2072 return -EIO;
2073 }
2074 READ32(nfserr);
2075 if (nfserr != NFS_OK)
2076 return -nfs_stat_to_errno(nfserr);
2077 return 0;
2078}
2079
2080/* Dummy routine */
2081static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs4_client *clp)
2082{
2083 uint32_t *p;
2084 uint32_t strlen;
2085 char *str;
2086
2087 READ_BUF(12);
2088 return decode_opaque_inline(xdr, &strlen, &str);
2089}
2090
2091static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2092{
2093 uint32_t bmlen, *p;
2094
2095 READ_BUF(4);
2096 READ32(bmlen);
2097
2098 bitmap[0] = bitmap[1] = 0;
2099 READ_BUF((bmlen << 2));
2100 if (bmlen > 0) {
2101 READ32(bitmap[0]);
2102 if (bmlen > 1)
2103 READ32(bitmap[1]);
2104 }
2105 return 0;
2106}
2107
2108static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, uint32_t **savep)
2109{
2110 uint32_t *p;
2111
2112 READ_BUF(4);
2113 READ32(*attrlen);
2114 *savep = xdr->p;
2115 return 0;
2116}
2117
2118static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2119{
2120 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2121 decode_attr_bitmap(xdr, bitmask);
2122 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2123 } else
2124 bitmask[0] = bitmask[1] = 0;
2125 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2126 return 0;
2127}
2128
2129static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2130{
2131 uint32_t *p;
2132
2133 *type = 0;
2134 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2135 return -EIO;
2136 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2137 READ_BUF(4);
2138 READ32(*type);
2139 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2140 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2141 return -EIO;
2142 }
2143 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2144 }
2145 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2146 return 0;
2147}
2148
2149static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2150{
2151 uint32_t *p;
2152
2153 *change = 0;
2154 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2155 return -EIO;
2156 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2157 READ_BUF(8);
2158 READ64(*change);
2159 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2160 }
2161 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2162 (unsigned long long)*change);
2163 return 0;
2164}
2165
2166static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2167{
2168 uint32_t *p;
2169
2170 *size = 0;
2171 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2172 return -EIO;
2173 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2174 READ_BUF(8);
2175 READ64(*size);
2176 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2177 }
2178 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2179 return 0;
2180}
2181
2182static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2183{
2184 uint32_t *p;
2185
2186 *res = 0;
2187 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2188 return -EIO;
2189 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2190 READ_BUF(4);
2191 READ32(*res);
2192 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2193 }
2194 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2195 return 0;
2196}
2197
2198static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2199{
2200 uint32_t *p;
2201
2202 *res = 0;
2203 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2204 return -EIO;
2205 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2206 READ_BUF(4);
2207 READ32(*res);
2208 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2209 }
2210 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2211 return 0;
2212}
2213
2214static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fsid *fsid)
2215{
2216 uint32_t *p;
2217
2218 fsid->major = 0;
2219 fsid->minor = 0;
2220 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2221 return -EIO;
2222 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2223 READ_BUF(16);
2224 READ64(fsid->major);
2225 READ64(fsid->minor);
2226 bitmap[0] &= ~FATTR4_WORD0_FSID;
2227 }
2228 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2229 (unsigned long long)fsid->major,
2230 (unsigned long long)fsid->minor);
2231 return 0;
2232}
2233
2234static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2235{
2236 uint32_t *p;
2237
2238 *res = 60;
2239 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2240 return -EIO;
2241 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2242 READ_BUF(4);
2243 READ32(*res);
2244 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2245 }
2246 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2247 return 0;
2248}
2249
2250static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2251{
2252 uint32_t *p;
2253
2254 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2255 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2256 return -EIO;
2257 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2258 READ_BUF(4);
2259 READ32(*res);
2260 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2261 }
2262 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2263 return 0;
2264}
2265
2266static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2267{
2268 uint32_t *p;
2269
2270 *fileid = 0;
2271 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2272 return -EIO;
2273 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2274 READ_BUF(8);
2275 READ64(*fileid);
2276 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2277 }
2278 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2279 return 0;
2280}
2281
2282static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2283{
2284 uint32_t *p;
2285 int status = 0;
2286
2287 *res = 0;
2288 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2289 return -EIO;
2290 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2291 READ_BUF(8);
2292 READ64(*res);
2293 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2294 }
2295 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2296 return status;
2297}
2298
2299static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2300{
2301 uint32_t *p;
2302 int status = 0;
2303
2304 *res = 0;
2305 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2306 return -EIO;
2307 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2308 READ_BUF(8);
2309 READ64(*res);
2310 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2311 }
2312 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2313 return status;
2314}
2315
2316static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2317{
2318 uint32_t *p;
2319 int status = 0;
2320
2321 *res = 0;
2322 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2323 return -EIO;
2324 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2325 READ_BUF(8);
2326 READ64(*res);
2327 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2328 }
2329 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2330 return status;
2331}
2332
2333static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2334{
2335 uint32_t *p;
2336 int status = 0;
2337
2338 *res = 0;
2339 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2340 return -EIO;
2341 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2342 READ_BUF(8);
2343 READ64(*res);
2344 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2345 }
2346 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2347 return status;
2348}
2349
2350static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2351{
2352 uint32_t *p;
2353 int status = 0;
2354
2355 *maxlink = 1;
2356 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2357 return -EIO;
2358 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2359 READ_BUF(4);
2360 READ32(*maxlink);
2361 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2362 }
2363 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2364 return status;
2365}
2366
2367static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2368{
2369 uint32_t *p;
2370 int status = 0;
2371
2372 *maxname = 1024;
2373 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2374 return -EIO;
2375 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2376 READ_BUF(4);
2377 READ32(*maxname);
2378 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2379 }
2380 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2381 return status;
2382}
2383
2384static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2385{
2386 uint32_t *p;
2387 int status = 0;
2388
2389 *res = 1024;
2390 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2391 return -EIO;
2392 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2393 uint64_t maxread;
2394 READ_BUF(8);
2395 READ64(maxread);
2396 if (maxread > 0x7FFFFFFF)
2397 maxread = 0x7FFFFFFF;
2398 *res = (uint32_t)maxread;
2399 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2400 }
2401 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2402 return status;
2403}
2404
2405static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2406{
2407 uint32_t *p;
2408 int status = 0;
2409
2410 *res = 1024;
2411 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2412 return -EIO;
2413 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2414 uint64_t maxwrite;
2415 READ_BUF(8);
2416 READ64(maxwrite);
2417 if (maxwrite > 0x7FFFFFFF)
2418 maxwrite = 0x7FFFFFFF;
2419 *res = (uint32_t)maxwrite;
2420 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2421 }
2422 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2423 return status;
2424}
2425
2426static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2427{
2428 uint32_t *p;
2429
2430 *mode = 0;
2431 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2432 return -EIO;
2433 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2434 READ_BUF(4);
2435 READ32(*mode);
2436 *mode &= ~S_IFMT;
2437 bitmap[1] &= ~FATTR4_WORD1_MODE;
2438 }
2439 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2440 return 0;
2441}
2442
2443static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2444{
2445 uint32_t *p;
2446
2447 *nlink = 1;
2448 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2449 return -EIO;
2450 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2451 READ_BUF(4);
2452 READ32(*nlink);
2453 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2454 }
2455 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2456 return 0;
2457}
2458
2459static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *uid)
2460{
2461 uint32_t len, *p;
2462
2463 *uid = -2;
2464 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2465 return -EIO;
2466 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2467 READ_BUF(4);
2468 READ32(len);
2469 READ_BUF(len);
2470 if (len < XDR_MAX_NETOBJ) {
2471 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2472 dprintk("%s: nfs_map_name_to_uid failed!\n",
2473 __FUNCTION__);
2474 } else
2475 printk(KERN_WARNING "%s: name too long (%u)!\n",
2476 __FUNCTION__, len);
2477 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2478 }
2479 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2480 return 0;
2481}
2482
2483static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_client *clp, int32_t *gid)
2484{
2485 uint32_t len, *p;
2486
2487 *gid = -2;
2488 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2489 return -EIO;
2490 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2491 READ_BUF(4);
2492 READ32(len);
2493 READ_BUF(len);
2494 if (len < XDR_MAX_NETOBJ) {
2495 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2496 dprintk("%s: nfs_map_group_to_gid failed!\n",
2497 __FUNCTION__);
2498 } else
2499 printk(KERN_WARNING "%s: name too long (%u)!\n",
2500 __FUNCTION__, len);
2501 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2502 }
2503 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2504 return 0;
2505}
2506
2507static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2508{
2509 uint32_t major = 0, minor = 0, *p;
2510
2511 *rdev = MKDEV(0,0);
2512 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2513 return -EIO;
2514 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2515 dev_t tmp;
2516
2517 READ_BUF(8);
2518 READ32(major);
2519 READ32(minor);
2520 tmp = MKDEV(major, minor);
2521 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2522 *rdev = tmp;
2523 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2524 }
2525 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2526 return 0;
2527}
2528
2529static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2530{
2531 uint32_t *p;
2532 int status = 0;
2533
2534 *res = 0;
2535 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2536 return -EIO;
2537 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2538 READ_BUF(8);
2539 READ64(*res);
2540 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2541 }
2542 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2543 return status;
2544}
2545
2546static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2547{
2548 uint32_t *p;
2549 int status = 0;
2550
2551 *res = 0;
2552 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2553 return -EIO;
2554 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2555 READ_BUF(8);
2556 READ64(*res);
2557 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2558 }
2559 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2560 return status;
2561}
2562
2563static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2564{
2565 uint32_t *p;
2566 int status = 0;
2567
2568 *res = 0;
2569 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2570 return -EIO;
2571 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2572 READ_BUF(8);
2573 READ64(*res);
2574 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2575 }
2576 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2577 return status;
2578}
2579
2580static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2581{
2582 uint32_t *p;
2583
2584 *used = 0;
2585 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2586 return -EIO;
2587 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2588 READ_BUF(8);
2589 READ64(*used);
2590 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2591 }
2592 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2593 (unsigned long long)*used);
2594 return 0;
2595}
2596
2597static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2598{
2599 uint32_t *p;
2600 uint64_t sec;
2601 uint32_t nsec;
2602
2603 READ_BUF(12);
2604 READ64(sec);
2605 READ32(nsec);
2606 time->tv_sec = (time_t)sec;
2607 time->tv_nsec = (long)nsec;
2608 return 0;
2609}
2610
2611static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2612{
2613 int status = 0;
2614
2615 time->tv_sec = 0;
2616 time->tv_nsec = 0;
2617 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2618 return -EIO;
2619 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2620 status = decode_attr_time(xdr, time);
2621 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2622 }
2623 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2624 return status;
2625}
2626
2627static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2628{
2629 int status = 0;
2630
2631 time->tv_sec = 0;
2632 time->tv_nsec = 0;
2633 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2634 return -EIO;
2635 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2636 status = decode_attr_time(xdr, time);
2637 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2638 }
2639 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2640 return status;
2641}
2642
2643static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2644{
2645 int status = 0;
2646
2647 time->tv_sec = 0;
2648 time->tv_nsec = 0;
2649 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2650 return -EIO;
2651 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2652 status = decode_attr_time(xdr, time);
2653 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2654 }
2655 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2656 return status;
2657}
2658
2659static int verify_attr_len(struct xdr_stream *xdr, uint32_t *savep, uint32_t attrlen)
2660{
2661 unsigned int attrwords = XDR_QUADLEN(attrlen);
2662 unsigned int nwords = xdr->p - savep;
2663
2664 if (unlikely(attrwords != nwords)) {
2665 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2666 __FUNCTION__,
2667 attrwords << 2,
2668 (attrwords < nwords) ? '<' : '>',
2669 nwords << 2);
2670 return -EIO;
2671 }
2672 return 0;
2673}
2674
2675static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2676{
2677 uint32_t *p;
2678
2679 READ_BUF(20);
2680 READ32(cinfo->atomic);
2681 READ64(cinfo->before);
2682 READ64(cinfo->after);
2683 return 0;
2684}
2685
2686static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2687{
2688 uint32_t *p;
2689 uint32_t supp, acc;
2690 int status;
2691
2692 status = decode_op_hdr(xdr, OP_ACCESS);
2693 if (status)
2694 return status;
2695 READ_BUF(8);
2696 READ32(supp);
2697 READ32(acc);
2698 access->supported = supp;
2699 access->access = acc;
2700 return 0;
2701}
2702
2703static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2704{
2705 uint32_t *p;
2706 int status;
2707
2708 status = decode_op_hdr(xdr, OP_CLOSE);
2709 if (status)
2710 return status;
2711 READ_BUF(sizeof(res->stateid.data));
2712 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2713 return 0;
2714}
2715
2716static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2717{
2718 uint32_t *p;
2719 int status;
2720
2721 status = decode_op_hdr(xdr, OP_COMMIT);
2722 if (status)
2723 return status;
2724 READ_BUF(8);
2725 COPYMEM(res->verf->verifier, 8);
2726 return 0;
2727}
2728
2729static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2730{
2731 uint32_t *p;
2732 uint32_t bmlen;
2733 int status;
2734
2735 status = decode_op_hdr(xdr, OP_CREATE);
2736 if (status)
2737 return status;
2738 if ((status = decode_change_info(xdr, cinfo)))
2739 return status;
2740 READ_BUF(4);
2741 READ32(bmlen);
2742 READ_BUF(bmlen << 2);
2743 return 0;
2744}
2745
2746static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2747{
2748 uint32_t *savep;
2749 uint32_t attrlen,
2750 bitmap[2] = {0};
2751 int status;
2752
2753 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2754 goto xdr_error;
2755 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2756 goto xdr_error;
2757 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2758 goto xdr_error;
2759 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2760 goto xdr_error;
2761 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2762 goto xdr_error;
2763 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2764 goto xdr_error;
2765 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2766 goto xdr_error;
2767 status = verify_attr_len(xdr, savep, attrlen);
2768xdr_error:
2769 if (status != 0)
2770 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2771 return status;
2772}
2773
2774static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2775{
2776 uint32_t *savep;
2777 uint32_t attrlen,
2778 bitmap[2] = {0};
2779 int status;
2780
2781 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2782 goto xdr_error;
2783 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2784 goto xdr_error;
2785 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2786 goto xdr_error;
2787
2788 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2789 goto xdr_error;
2790 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2791 goto xdr_error;
2792 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2793 goto xdr_error;
2794 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2795 goto xdr_error;
2796 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2797 goto xdr_error;
2798 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2799 goto xdr_error;
2800
2801 status = verify_attr_len(xdr, savep, attrlen);
2802xdr_error:
2803 if (status != 0)
2804 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2805 return status;
2806}
2807
2808static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2809{
2810 uint32_t *savep;
2811 uint32_t attrlen,
2812 bitmap[2] = {0};
2813 int status;
2814
2815 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2816 goto xdr_error;
2817 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2818 goto xdr_error;
2819 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2820 goto xdr_error;
2821
2822 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2823 goto xdr_error;
2824 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2825 goto xdr_error;
2826
2827 status = verify_attr_len(xdr, savep, attrlen);
2828xdr_error:
2829 if (status != 0)
2830 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2831 return status;
2832}
2833
2834static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2835{
2836 uint32_t *savep;
2837 uint32_t attrlen,
2838 bitmap[2] = {0},
2839 type;
2840 int status, fmode = 0;
2841
2842 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2843 goto xdr_error;
2844 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2845 goto xdr_error;
2846
2847 fattr->bitmap[0] = bitmap[0];
2848 fattr->bitmap[1] = bitmap[1];
2849
2850 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2851 goto xdr_error;
2852
2853
2854 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
2855 goto xdr_error;
2856 fattr->type = nfs_type2fmt[type].nfs2type;
2857 fmode = nfs_type2fmt[type].mode;
2858
2859 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
2860 goto xdr_error;
2861 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
2862 goto xdr_error;
2863 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid_u.nfs4)) != 0)
2864 goto xdr_error;
2865 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
2866 goto xdr_error;
2867 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
2868 goto xdr_error;
2869 fattr->mode |= fmode;
2870 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
2871 goto xdr_error;
2872 if ((status = decode_attr_owner(xdr, bitmap, server->nfs4_state, &fattr->uid)) != 0)
2873 goto xdr_error;
2874 if ((status = decode_attr_group(xdr, bitmap, server->nfs4_state, &fattr->gid)) != 0)
2875 goto xdr_error;
2876 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
2877 goto xdr_error;
2878 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
2879 goto xdr_error;
2880 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
2881 goto xdr_error;
2882 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
2883 goto xdr_error;
2884 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
2885 goto xdr_error;
33801147 2886 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
1da177e4 2887 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
1da177e4
LT
2888xdr_error:
2889 if (status != 0)
2890 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2891 return status;
2892}
2893
2894
2895static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
2896{
2897 uint32_t *savep;
2898 uint32_t attrlen, bitmap[2];
2899 int status;
2900
2901 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2902 goto xdr_error;
2903 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2904 goto xdr_error;
2905 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2906 goto xdr_error;
2907
2908 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
2909
2910 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
2911 goto xdr_error;
2912 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
2913 goto xdr_error;
2914 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
2915 goto xdr_error;
2916 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
2917 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
2918 goto xdr_error;
2919 fsinfo->wtpref = fsinfo->wtmax;
2920
2921 status = verify_attr_len(xdr, savep, attrlen);
2922xdr_error:
2923 if (status != 0)
2924 printk(KERN_NOTICE "%s: xdr error %d!\n", __FUNCTION__, -status);
2925 return status;
2926}
2927
2928static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
2929{
2930 uint32_t *p;
2931 uint32_t len;
2932 int status;
2933
2934 status = decode_op_hdr(xdr, OP_GETFH);
2935 if (status)
2936 return status;
2937 /* Zero handle first to allow comparisons */
2938 memset(fh, 0, sizeof(*fh));
2939
2940 READ_BUF(4);
2941 READ32(len);
2942 if (len > NFS4_FHSIZE)
2943 return -EIO;
2944 fh->size = len;
2945 READ_BUF(len);
2946 COPYMEM(fh->data, len);
2947 return 0;
2948}
2949
2950static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2951{
2952 int status;
2953
2954 status = decode_op_hdr(xdr, OP_LINK);
2955 if (status)
2956 return status;
2957 return decode_change_info(xdr, cinfo);
2958}
2959
2960/*
2961 * We create the owner, so we know a proper owner.id length is 4.
2962 */
2963static int decode_lock_denied (struct xdr_stream *xdr, struct nfs_lock_denied *denied)
2964{
2965 uint32_t *p;
2966 uint32_t namelen;
2967
2968 READ_BUF(32);
2969 READ64(denied->offset);
2970 READ64(denied->length);
2971 READ32(denied->type);
2972 READ64(denied->owner.clientid);
2973 READ32(namelen);
2974 READ_BUF(namelen);
2975 if (namelen == 4)
2976 READ32(denied->owner.id);
2977 return -NFS4ERR_DENIED;
2978}
2979
2980static int decode_lock(struct xdr_stream *xdr, struct nfs_lockres *res)
2981{
2982 uint32_t *p;
2983 int status;
2984
2985 status = decode_op_hdr(xdr, OP_LOCK);
2986 if (status == 0) {
06735b34
TM
2987 READ_BUF(sizeof(res->u.stateid.data));
2988 COPYMEM(res->u.stateid.data, sizeof(res->u.stateid.data));
1da177e4
LT
2989 } else if (status == -NFS4ERR_DENIED)
2990 return decode_lock_denied(xdr, &res->u.denied);
2991 return status;
2992}
2993
2994static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockres *res)
2995{
2996 int status;
2997 status = decode_op_hdr(xdr, OP_LOCKT);
2998 if (status == -NFS4ERR_DENIED)
2999 return decode_lock_denied(xdr, &res->u.denied);
3000 return status;
3001}
3002
3003static int decode_locku(struct xdr_stream *xdr, struct nfs_lockres *res)
3004{
3005 uint32_t *p;
3006 int status;
3007
3008 status = decode_op_hdr(xdr, OP_LOCKU);
3009 if (status == 0) {
faf5f49c
TM
3010 READ_BUF(sizeof(res->u.stateid.data));
3011 COPYMEM(res->u.stateid.data, sizeof(res->u.stateid.data));
1da177e4
LT
3012 }
3013 return status;
3014}
3015
3016static int decode_lookup(struct xdr_stream *xdr)
3017{
3018 return decode_op_hdr(xdr, OP_LOOKUP);
3019}
3020
3021/* This is too sick! */
3022static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3023{
3024 uint32_t *p;
3025 uint32_t limit_type, nblocks, blocksize;
3026
3027 READ_BUF(12);
3028 READ32(limit_type);
3029 switch (limit_type) {
3030 case 1:
3031 READ64(*maxsize);
3032 break;
3033 case 2:
3034 READ32(nblocks);
3035 READ32(blocksize);
3036 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3037 }
3038 return 0;
3039}
3040
3041static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3042{
3043 uint32_t *p;
3044 uint32_t delegation_type;
3045
3046 READ_BUF(4);
3047 READ32(delegation_type);
3048 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3049 res->delegation_type = 0;
3050 return 0;
3051 }
3052 READ_BUF(20);
3053 COPYMEM(res->delegation.data, sizeof(res->delegation.data));
3054 READ32(res->do_recall);
3055 switch (delegation_type) {
3056 case NFS4_OPEN_DELEGATE_READ:
3057 res->delegation_type = FMODE_READ;
3058 break;
3059 case NFS4_OPEN_DELEGATE_WRITE:
3060 res->delegation_type = FMODE_WRITE|FMODE_READ;
3061 if (decode_space_limit(xdr, &res->maxsize) < 0)
3062 return -EIO;
3063 }
3064 return decode_ace(xdr, NULL, res->server->nfs4_state);
3065}
3066
3067static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3068{
3069 uint32_t *p;
3070 uint32_t bmlen;
3071 int status;
3072
3073 status = decode_op_hdr(xdr, OP_OPEN);
3074 if (status)
3075 return status;
3076 READ_BUF(sizeof(res->stateid.data));
3077 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3078
3079 decode_change_info(xdr, &res->cinfo);
3080
3081 READ_BUF(8);
3082 READ32(res->rflags);
3083 READ32(bmlen);
3084 if (bmlen > 10)
3085 goto xdr_error;
3086
3087 READ_BUF(bmlen << 2);
3088 p += bmlen;
3089 return decode_delegation(xdr, res);
3090xdr_error:
3091 printk(KERN_NOTICE "%s: xdr error!\n", __FUNCTION__);
3092 return -EIO;
3093}
3094
3095static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3096{
3097 uint32_t *p;
3098 int status;
3099
3100 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3101 if (status)
3102 return status;
3103 READ_BUF(sizeof(res->stateid.data));
3104 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3105 return 0;
3106}
3107
3108static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3109{
3110 uint32_t *p;
3111 int status;
3112
3113 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3114 if (status)
3115 return status;
3116 READ_BUF(sizeof(res->stateid.data));
3117 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3118 return 0;
3119}
3120
3121static int decode_putfh(struct xdr_stream *xdr)
3122{
3123 return decode_op_hdr(xdr, OP_PUTFH);
3124}
3125
3126static int decode_putrootfh(struct xdr_stream *xdr)
3127{
3128 return decode_op_hdr(xdr, OP_PUTROOTFH);
3129}
3130
3131static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3132{
3133 struct kvec *iov = req->rq_rcv_buf.head;
3134 uint32_t *p;
3135 uint32_t count, eof, recvd, hdrlen;
3136 int status;
3137
3138 status = decode_op_hdr(xdr, OP_READ);
3139 if (status)
3140 return status;
3141 READ_BUF(8);
3142 READ32(eof);
3143 READ32(count);
3144 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3145 recvd = req->rq_rcv_buf.len - hdrlen;
3146 if (count > recvd) {
3147 printk(KERN_WARNING "NFS: server cheating in read reply: "
3148 "count %u > recvd %u\n", count, recvd);
3149 count = recvd;
3150 eof = 0;
3151 }
3152 xdr_read_pages(xdr, count);
3153 res->eof = eof;
3154 res->count = count;
3155 return 0;
3156}
3157
3158static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3159{
3160 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3161 struct page *page = *rcvbuf->pages;
3162 struct kvec *iov = rcvbuf->head;
3163 unsigned int nr, pglen = rcvbuf->page_len;
3164 uint32_t *end, *entry, *p, *kaddr;
3165 uint32_t len, attrlen;
3166 int hdrlen, recvd, status;
3167
3168 status = decode_op_hdr(xdr, OP_READDIR);
3169 if (status)
3170 return status;
3171 READ_BUF(8);
3172 COPYMEM(readdir->verifier.data, 8);
eadf4598
TM
3173 dprintk("%s: verifier = 0x%x%x\n",
3174 __FUNCTION__,
3175 ((u32 *)readdir->verifier.data)[0],
3176 ((u32 *)readdir->verifier.data)[1]);
3177
1da177e4
LT
3178
3179 hdrlen = (char *) p - (char *) iov->iov_base;
3180 recvd = rcvbuf->len - hdrlen;
3181 if (pglen > recvd)
3182 pglen = recvd;
3183 xdr_read_pages(xdr, pglen);
3184
3185 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3186 kaddr = p = (uint32_t *) kmap_atomic(page, KM_USER0);
3187 end = (uint32_t *) ((char *)p + pglen + readdir->pgbase);
3188 entry = p;
3189 for (nr = 0; *p++; nr++) {
3190 if (p + 3 > end)
3191 goto short_pkt;
eadf4598 3192 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
1da177e4
LT
3193 p += 2; /* cookie */
3194 len = ntohl(*p++); /* filename length */
3195 if (len > NFS4_MAXNAMLEN) {
3196 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3197 goto err_unmap;
3198 }
eadf4598 3199 dprintk("filename = %*s\n", len, (char *)p);
1da177e4
LT
3200 p += XDR_QUADLEN(len);
3201 if (p + 1 > end)
3202 goto short_pkt;
3203 len = ntohl(*p++); /* bitmap length */
3204 p += len;
3205 if (p + 1 > end)
3206 goto short_pkt;
3207 attrlen = XDR_QUADLEN(ntohl(*p++));
3208 p += attrlen; /* attributes */
3209 if (p + 2 > end)
3210 goto short_pkt;
3211 entry = p;
3212 }
3213 if (!nr && (entry[0] != 0 || entry[1] == 0))
3214 goto short_pkt;
3215out:
3216 kunmap_atomic(kaddr, KM_USER0);
3217 return 0;
3218short_pkt:
eadf4598 3219 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
1da177e4
LT
3220 entry[0] = entry[1] = 0;
3221 /* truncate listing ? */
3222 if (!nr) {
3223 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3224 entry[1] = 1;
3225 }
3226 goto out;
3227err_unmap:
3228 kunmap_atomic(kaddr, KM_USER0);
3229 return -errno_NFSERR_IO;
3230}
3231
3232static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3233{
3234 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3235 struct kvec *iov = rcvbuf->head;
3236 int hdrlen, len, recvd;
3237 uint32_t *p;
3238 char *kaddr;
3239 int status;
3240
3241 status = decode_op_hdr(xdr, OP_READLINK);
3242 if (status)
3243 return status;
3244
3245 /* Convert length of symlink */
3246 READ_BUF(4);
3247 READ32(len);
3248 if (len >= rcvbuf->page_len || len <= 0) {
3249 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3250 return -ENAMETOOLONG;
3251 }
3252 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3253 recvd = req->rq_rcv_buf.len - hdrlen;
3254 if (recvd < len) {
3255 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3256 "count %u > recvd %u\n", len, recvd);
3257 return -EIO;
3258 }
3259 xdr_read_pages(xdr, len);
3260 /*
3261 * The XDR encode routine has set things up so that
3262 * the link text will be copied directly into the
3263 * buffer. We just have to do overflow-checking,
3264 * and and null-terminate the text (the VFS expects
3265 * null-termination).
3266 */
3267 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3268 kaddr[len+rcvbuf->page_base] = '\0';
3269 kunmap_atomic(kaddr, KM_USER0);
3270 return 0;
3271}
3272
3273static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3274{
3275 int status;
3276
3277 status = decode_op_hdr(xdr, OP_REMOVE);
3278 if (status)
3279 goto out;
3280 status = decode_change_info(xdr, cinfo);
3281out:
3282 return status;
3283}
3284
3285static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3286 struct nfs4_change_info *new_cinfo)
3287{
3288 int status;
3289
3290 status = decode_op_hdr(xdr, OP_RENAME);
3291 if (status)
3292 goto out;
3293 if ((status = decode_change_info(xdr, old_cinfo)))
3294 goto out;
3295 status = decode_change_info(xdr, new_cinfo);
3296out:
3297 return status;
3298}
3299
3300static int decode_renew(struct xdr_stream *xdr)
3301{
3302 return decode_op_hdr(xdr, OP_RENEW);
3303}
3304
56ae19f3
TM
3305static int
3306decode_restorefh(struct xdr_stream *xdr)
3307{
3308 return decode_op_hdr(xdr, OP_RESTOREFH);
3309}
3310
029d105e
BF
3311static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3312 size_t *acl_len)
3313{
3314 uint32_t *savep;
3315 uint32_t attrlen,
3316 bitmap[2] = {0};
3317 struct kvec *iov = req->rq_rcv_buf.head;
3318 int status;
3319
3320 *acl_len = 0;
3321 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3322 goto out;
3323 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3324 goto out;
3325 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3326 goto out;
3327
3328 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3329 return -EIO;
3330 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3331 int hdrlen, recvd;
3332
3333 /* We ignore &savep and don't do consistency checks on
3334 * the attr length. Let userspace figure it out.... */
3335 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3336 recvd = req->rq_rcv_buf.len - hdrlen;
3337 if (attrlen > recvd) {
3338 printk(KERN_WARNING "NFS: server cheating in getattr"
3339 " acl reply: attrlen %u > recvd %u\n",
3340 attrlen, recvd);
3341 return -EINVAL;
3342 }
3343 if (attrlen <= *acl_len)
3344 xdr_read_pages(xdr, attrlen);
3345 *acl_len = attrlen;
8c233cf9
BF
3346 } else
3347 status = -EOPNOTSUPP;
029d105e
BF
3348
3349out:
3350 return status;
3351}
3352
1da177e4
LT
3353static int
3354decode_savefh(struct xdr_stream *xdr)
3355{
3356 return decode_op_hdr(xdr, OP_SAVEFH);
3357}
3358
3359static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3360{
3361 uint32_t *p;
3362 uint32_t bmlen;
3363 int status;
3364
3365
3366 status = decode_op_hdr(xdr, OP_SETATTR);
3367 if (status)
3368 return status;
3369 READ_BUF(4);
3370 READ32(bmlen);
3371 READ_BUF(bmlen << 2);
3372 return 0;
3373}
3374
3375static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_client *clp)
3376{
3377 uint32_t *p;
3378 uint32_t opnum;
3379 int32_t nfserr;
3380
3381 READ_BUF(8);
3382 READ32(opnum);
3383 if (opnum != OP_SETCLIENTID) {
3384 printk(KERN_NOTICE
3385 "nfs4_decode_setclientid: Server returned operation"
3386 " %d\n", opnum);
3387 return -EIO;
3388 }
3389 READ32(nfserr);
3390 if (nfserr == NFS_OK) {
3391 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3392 READ64(clp->cl_clientid);
3393 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3394 } else if (nfserr == NFSERR_CLID_INUSE) {
3395 uint32_t len;
3396
3397 /* skip netid string */
3398 READ_BUF(4);
3399 READ32(len);
3400 READ_BUF(len);
3401
3402 /* skip uaddr string */
3403 READ_BUF(4);
3404 READ32(len);
3405 READ_BUF(len);
3406 return -NFSERR_CLID_INUSE;
3407 } else
3408 return -nfs_stat_to_errno(nfserr);
3409
3410 return 0;
3411}
3412
3413static int decode_setclientid_confirm(struct xdr_stream *xdr)
3414{
3415 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3416}
3417
3418static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3419{
3420 uint32_t *p;
3421 int status;
3422
3423 status = decode_op_hdr(xdr, OP_WRITE);
3424 if (status)
3425 return status;
3426
3427 READ_BUF(16);
3428 READ32(res->count);
3429 READ32(res->verf->committed);
3430 COPYMEM(res->verf->verifier, 8);
3431 return 0;
3432}
3433
3434static int decode_delegreturn(struct xdr_stream *xdr)
3435{
3436 return decode_op_hdr(xdr, OP_DELEGRETURN);
3437}
3438
3439/*
3440 * Decode OPEN_DOWNGRADE response
3441 */
3442static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3443{
3444 struct xdr_stream xdr;
3445 struct compound_hdr hdr;
3446 int status;
3447
3448 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3449 status = decode_compound_hdr(&xdr, &hdr);
3450 if (status)
3451 goto out;
3452 status = decode_putfh(&xdr);
3453 if (status)
3454 goto out;
3455 status = decode_open_downgrade(&xdr, res);
516a6af6
TM
3456 if (status != 0)
3457 goto out;
3458 decode_getfattr(&xdr, res->fattr, res->server);
1da177e4
LT
3459out:
3460 return status;
3461}
3462
3463/*
3464 * END OF "GENERIC" DECODE ROUTINES.
3465 */
3466
3467/*
3468 * Decode ACCESS response
3469 */
3470static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_accessres *res)
3471{
3472 struct xdr_stream xdr;
3473 struct compound_hdr hdr;
3474 int status;
3475
3476 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3477 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3478 goto out;
3479 if ((status = decode_putfh(&xdr)) == 0)
3480 status = decode_access(&xdr, res);
3481out:
3482 return status;
3483}
3484
3485/*
3486 * Decode LOOKUP response
3487 */
3488static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3489{
3490 struct xdr_stream xdr;
3491 struct compound_hdr hdr;
3492 int status;
3493
3494 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3495 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3496 goto out;
3497 if ((status = decode_putfh(&xdr)) != 0)
3498 goto out;
3499 if ((status = decode_lookup(&xdr)) != 0)
3500 goto out;
3501 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3502 goto out;
3503 status = decode_getfattr(&xdr, res->fattr, res->server);
3504out:
3505 return status;
3506}
3507
3508/*
3509 * Decode LOOKUP_ROOT response
3510 */
3511static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_lookup_res *res)
3512{
3513 struct xdr_stream xdr;
3514 struct compound_hdr hdr;
3515 int status;
3516
3517 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3518 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3519 goto out;
3520 if ((status = decode_putrootfh(&xdr)) != 0)
3521 goto out;
3522 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3523 status = decode_getfattr(&xdr, res->fattr, res->server);
3524out:
3525 return status;
3526}
3527
3528/*
3529 * Decode REMOVE response
3530 */
16e42959 3531static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_remove_res *res)
1da177e4
LT
3532{
3533 struct xdr_stream xdr;
3534 struct compound_hdr hdr;
3535 int status;
3536
3537 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3538 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3539 goto out;
16e42959
TM
3540 if ((status = decode_putfh(&xdr)) != 0)
3541 goto out;
3542 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3543 goto out;
3544 decode_getfattr(&xdr, res->dir_attr, res->server);
1da177e4
LT
3545out:
3546 return status;
3547}
3548
3549/*
3550 * Decode RENAME response
3551 */
3552static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_rename_res *res)
3553{
3554 struct xdr_stream xdr;
3555 struct compound_hdr hdr;
3556 int status;
3557
3558 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3559 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3560 goto out;
3561 if ((status = decode_putfh(&xdr)) != 0)
3562 goto out;
3563 if ((status = decode_savefh(&xdr)) != 0)
3564 goto out;
3565 if ((status = decode_putfh(&xdr)) != 0)
3566 goto out;
6caf2c82
TM
3567 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3568 goto out;
3569 /* Current FH is target directory */
3570 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3571 goto out;
3572 if ((status = decode_restorefh(&xdr)) != 0)
3573 goto out;
3574 decode_getfattr(&xdr, res->old_fattr, res->server);
1da177e4
LT
3575out:
3576 return status;
3577}
3578
3579/*
3580 * Decode LINK response
3581 */
91ba2eee 3582static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_link_res *res)
1da177e4
LT
3583{
3584 struct xdr_stream xdr;
3585 struct compound_hdr hdr;
3586 int status;
3587
3588 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3589 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3590 goto out;
3591 if ((status = decode_putfh(&xdr)) != 0)
3592 goto out;
3593 if ((status = decode_savefh(&xdr)) != 0)
3594 goto out;
3595 if ((status = decode_putfh(&xdr)) != 0)
3596 goto out;
91ba2eee
TM
3597 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3598 goto out;
3599 /*
3600 * Note order: OP_LINK leaves the directory as the current
3601 * filehandle.
3602 */
3603 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3604 goto out;
3605 if ((status = decode_restorefh(&xdr)) != 0)
3606 goto out;
3607 decode_getfattr(&xdr, res->fattr, res->server);
1da177e4
LT
3608out:
3609 return status;
3610}
3611
3612/*
3613 * Decode CREATE response
3614 */
3615static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3616{
3617 struct xdr_stream xdr;
3618 struct compound_hdr hdr;
3619 int status;
3620
3621 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3622 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3623 goto out;
3624 if ((status = decode_putfh(&xdr)) != 0)
3625 goto out;
56ae19f3
TM
3626 if ((status = decode_savefh(&xdr)) != 0)
3627 goto out;
1da177e4
LT
3628 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3629 goto out;
3630 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3631 goto out;
56ae19f3
TM
3632 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3633 goto out;
3634 if ((status = decode_restorefh(&xdr)) != 0)
3635 goto out;
3636 decode_getfattr(&xdr, res->dir_fattr, res->server);
1da177e4
LT
3637out:
3638 return status;
3639}
3640
3641/*
3642 * Decode SYMLINK response
3643 */
3644static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_create_res *res)
3645{
3646 return nfs4_xdr_dec_create(rqstp, p, res);
3647}
3648
3649/*
3650 * Decode GETATTR response
3651 */
3652static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_getattr_res *res)
3653{
3654 struct xdr_stream xdr;
3655 struct compound_hdr hdr;
3656 int status;
3657
3658 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3659 status = decode_compound_hdr(&xdr, &hdr);
3660 if (status)
3661 goto out;
3662 status = decode_putfh(&xdr);
3663 if (status)
3664 goto out;
3665 status = decode_getfattr(&xdr, res->fattr, res->server);
3666out:
3667 return status;
3668
3669}
3670
23ec6965
BF
3671/*
3672 * Encode an SETACL request
3673 */
3674static int
3675nfs4_xdr_enc_setacl(struct rpc_rqst *req, uint32_t *p, struct nfs_setaclargs *args)
3676{
3677 struct xdr_stream xdr;
3678 struct compound_hdr hdr = {
3679 .nops = 2,
3680 };
3681 int status;
3682
3683 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3684 encode_compound_hdr(&xdr, &hdr);
3685 status = encode_putfh(&xdr, args->fh);
3686 if (status)
3687 goto out;
3688 status = encode_setacl(&xdr, args);
3689out:
3690 return status;
3691}
3692/*
3693 * Decode SETACL response
3694 */
3695static int
3696nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3697{
3698 struct xdr_stream xdr;
3699 struct compound_hdr hdr;
3700 int status;
3701
3702 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3703 status = decode_compound_hdr(&xdr, &hdr);
3704 if (status)
3705 goto out;
3706 status = decode_putfh(&xdr);
3707 if (status)
3708 goto out;
3709 status = decode_setattr(&xdr, res);
3710out:
3711 return status;
3712}
1da177e4 3713
029d105e
BF
3714/*
3715 * Decode GETACL response
3716 */
3717static int
3718nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, uint32_t *p, size_t *acl_len)
3719{
3720 struct xdr_stream xdr;
3721 struct compound_hdr hdr;
3722 int status;
3723
3724 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3725 status = decode_compound_hdr(&xdr, &hdr);
3726 if (status)
3727 goto out;
3728 status = decode_putfh(&xdr);
3729 if (status)
3730 goto out;
3731 status = decode_getacl(&xdr, rqstp, acl_len);
3732
3733out:
3734 return status;
3735}
3736
1da177e4
LT
3737/*
3738 * Decode CLOSE response
3739 */
3740static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_closeres *res)
3741{
3742 struct xdr_stream xdr;
3743 struct compound_hdr hdr;
3744 int status;
3745
3746 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3747 status = decode_compound_hdr(&xdr, &hdr);
3748 if (status)
3749 goto out;
3750 status = decode_putfh(&xdr);
3751 if (status)
3752 goto out;
3753 status = decode_close(&xdr, res);
516a6af6
TM
3754 if (status != 0)
3755 goto out;
3756 /*
3757 * Note: Server may do delete on close for this file
3758 * in which case the getattr call will fail with
3759 * an ESTALE error. Shouldn't be a problem,
3760 * though, since fattr->valid will remain unset.
3761 */
3762 decode_getfattr(&xdr, res->fattr, res->server);
1da177e4
LT
3763out:
3764 return status;
3765}
3766
3767/*
3768 * Decode OPEN response
3769 */
3770static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3771{
3772 struct xdr_stream xdr;
3773 struct compound_hdr hdr;
3774 int status;
3775
3776 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3777 status = decode_compound_hdr(&xdr, &hdr);
3778 if (status)
3779 goto out;
3780 status = decode_putfh(&xdr);
3781 if (status)
3782 goto out;
56ae19f3
TM
3783 status = decode_savefh(&xdr);
3784 if (status)
3785 goto out;
1da177e4
LT
3786 status = decode_open(&xdr, res);
3787 if (status)
3788 goto out;
3789 status = decode_getfh(&xdr, &res->fh);
3790 if (status)
3791 goto out;
56ae19f3
TM
3792 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
3793 goto out;
3794 if ((status = decode_restorefh(&xdr)) != 0)
3795 goto out;
3796 decode_getfattr(&xdr, res->dir_attr, res->server);
1da177e4
LT
3797out:
3798 return status;
3799}
3800
3801/*
3802 * Decode OPEN_CONFIRM response
3803 */
3804static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_open_confirmres *res)
3805{
3806 struct xdr_stream xdr;
3807 struct compound_hdr hdr;
3808 int status;
3809
3810 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3811 status = decode_compound_hdr(&xdr, &hdr);
3812 if (status)
3813 goto out;
3814 status = decode_putfh(&xdr);
3815 if (status)
3816 goto out;
3817 status = decode_open_confirm(&xdr, res);
3818out:
3819 return status;
3820}
3821
3822/*
3823 * Decode OPEN response
3824 */
3825static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_openres *res)
3826{
3827 struct xdr_stream xdr;
3828 struct compound_hdr hdr;
3829 int status;
3830
3831 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3832 status = decode_compound_hdr(&xdr, &hdr);
3833 if (status)
3834 goto out;
3835 status = decode_putfh(&xdr);
3836 if (status)
3837 goto out;
3838 status = decode_open(&xdr, res);
3839out:
3840 return status;
3841}
3842
3843/*
3844 * Decode SETATTR response
3845 */
3846static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_setattrres *res)
3847{
3848 struct xdr_stream xdr;
3849 struct compound_hdr hdr;
3850 int status;
3851
3852 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3853 status = decode_compound_hdr(&xdr, &hdr);
3854 if (status)
3855 goto out;
3856 status = decode_putfh(&xdr);
3857 if (status)
3858 goto out;
3859 status = decode_setattr(&xdr, res);
3860 if (status)
3861 goto out;
3862 status = decode_getfattr(&xdr, res->fattr, res->server);
3863 if (status == NFS4ERR_DELAY)
3864 status = 0;
3865out:
3866 return status;
3867}
3868
3869/*
3870 * Decode LOCK response
3871 */
3872static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3873{
3874 struct xdr_stream xdr;
3875 struct compound_hdr hdr;
3876 int status;
3877
3878 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3879 status = decode_compound_hdr(&xdr, &hdr);
3880 if (status)
3881 goto out;
3882 status = decode_putfh(&xdr);
3883 if (status)
3884 goto out;
3885 status = decode_lock(&xdr, res);
3886out:
3887 return status;
3888}
3889
3890/*
3891 * Decode LOCKT response
3892 */
3893static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3894{
3895 struct xdr_stream xdr;
3896 struct compound_hdr hdr;
3897 int status;
3898
3899 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3900 status = decode_compound_hdr(&xdr, &hdr);
3901 if (status)
3902 goto out;
3903 status = decode_putfh(&xdr);
3904 if (status)
3905 goto out;
3906 status = decode_lockt(&xdr, res);
3907out:
3908 return status;
3909}
3910
3911/*
3912 * Decode LOCKU response
3913 */
3914static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_lockres *res)
3915{
3916 struct xdr_stream xdr;
3917 struct compound_hdr hdr;
3918 int status;
3919
3920 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3921 status = decode_compound_hdr(&xdr, &hdr);
3922 if (status)
3923 goto out;
3924 status = decode_putfh(&xdr);
3925 if (status)
3926 goto out;
3927 status = decode_locku(&xdr, res);
3928out:
3929 return status;
3930}
3931
3932/*
3933 * Decode READLINK response
3934 */
3935static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, uint32_t *p, void *res)
3936{
3937 struct xdr_stream xdr;
3938 struct compound_hdr hdr;
3939 int status;
3940
3941 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3942 status = decode_compound_hdr(&xdr, &hdr);
3943 if (status)
3944 goto out;
3945 status = decode_putfh(&xdr);
3946 if (status)
3947 goto out;
3948 status = decode_readlink(&xdr, rqstp);
3949out:
3950 return status;
3951}
3952
3953/*
3954 * Decode READDIR response
3955 */
3956static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, uint32_t *p, struct nfs4_readdir_res *res)
3957{
3958 struct xdr_stream xdr;
3959 struct compound_hdr hdr;
3960 int status;
3961
3962 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3963 status = decode_compound_hdr(&xdr, &hdr);
3964 if (status)
3965 goto out;
3966 status = decode_putfh(&xdr);
3967 if (status)
3968 goto out;
3969 status = decode_readdir(&xdr, rqstp, res);
3970out:
3971 return status;
3972}
3973
3974/*
3975 * Decode Read response
3976 */
3977static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_readres *res)
3978{
3979 struct xdr_stream xdr;
3980 struct compound_hdr hdr;
3981 int status;
3982
3983 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3984 status = decode_compound_hdr(&xdr, &hdr);
3985 if (status)
3986 goto out;
3987 status = decode_putfh(&xdr);
3988 if (status)
3989 goto out;
3990 status = decode_read(&xdr, rqstp, res);
3991 if (!status)
3992 status = res->count;
3993out:
3994 return status;
3995}
3996
3997/*
3998 * Decode WRITE response
3999 */
4000static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
4001{
4002 struct xdr_stream xdr;
4003 struct compound_hdr hdr;
4004 int status;
4005
4006 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4007 status = decode_compound_hdr(&xdr, &hdr);
4008 if (status)
4009 goto out;
4010 status = decode_putfh(&xdr);
4011 if (status)
4012 goto out;
4013 status = decode_write(&xdr, res);
4f9838c7
TM
4014 if (status)
4015 goto out;
4016 decode_getfattr(&xdr, res->fattr, res->server);
1da177e4
LT
4017 if (!status)
4018 status = res->count;
4019out:
4020 return status;
4021}
4022
4023/*
4024 * Decode COMMIT response
4025 */
4026static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, uint32_t *p, struct nfs_writeres *res)
4027{
4028 struct xdr_stream xdr;
4029 struct compound_hdr hdr;
4030 int status;
4031
4032 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4033 status = decode_compound_hdr(&xdr, &hdr);
4034 if (status)
4035 goto out;
4036 status = decode_putfh(&xdr);
4037 if (status)
4038 goto out;
4039 status = decode_commit(&xdr, res);
4f9838c7
TM
4040 if (status)
4041 goto out;
4042 decode_getfattr(&xdr, res->fattr, res->server);
1da177e4
LT
4043out:
4044 return status;
4045}
4046
4047/*
4048 * FSINFO request
4049 */
4050static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
4051{
4052 struct xdr_stream xdr;
4053 struct compound_hdr hdr;
4054 int status;
4055
4056 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4057 status = decode_compound_hdr(&xdr, &hdr);
4058 if (!status)
4059 status = decode_putfh(&xdr);
4060 if (!status)
4061 status = decode_fsinfo(&xdr, fsinfo);
4062 if (!status)
4063 status = -nfs_stat_to_errno(hdr.status);
4064 return status;
4065}
4066
4067/*
4068 * PATHCONF request
4069 */
4070static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, uint32_t *p, struct nfs_pathconf *pathconf)
4071{
4072 struct xdr_stream xdr;
4073 struct compound_hdr hdr;
4074 int status;
4075
4076 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4077 status = decode_compound_hdr(&xdr, &hdr);
4078 if (!status)
4079 status = decode_putfh(&xdr);
4080 if (!status)
4081 status = decode_pathconf(&xdr, pathconf);
4082 return status;
4083}
4084
4085/*
4086 * STATFS request
4087 */
4088static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, uint32_t *p, struct nfs_fsstat *fsstat)
4089{
4090 struct xdr_stream xdr;
4091 struct compound_hdr hdr;
4092 int status;
4093
4094 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4095 status = decode_compound_hdr(&xdr, &hdr);
4096 if (!status)
4097 status = decode_putfh(&xdr);
4098 if (!status)
4099 status = decode_statfs(&xdr, fsstat);
4100 return status;
4101}
4102
4103/*
4104 * GETATTR_BITMAP request
4105 */
4106static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, uint32_t *p, struct nfs4_server_caps_res *res)
4107{
4108 struct xdr_stream xdr;
4109 struct compound_hdr hdr;
4110 int status;
4111
4112 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4113 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4114 goto out;
4115 if ((status = decode_putfh(&xdr)) != 0)
4116 goto out;
4117 status = decode_server_caps(&xdr, res);
4118out:
4119 return status;
4120}
4121
4122/*
4123 * Decode RENEW response
4124 */
4125static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
4126{
4127 struct xdr_stream xdr;
4128 struct compound_hdr hdr;
4129 int status;
4130
4131 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4132 status = decode_compound_hdr(&xdr, &hdr);
4133 if (!status)
4134 status = decode_renew(&xdr);
4135 return status;
4136}
4137
4138/*
4139 * a SETCLIENTID request
4140 */
4141static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, uint32_t *p,
4142 struct nfs4_client *clp)
4143{
4144 struct xdr_stream xdr;
4145 struct compound_hdr hdr;
4146 int status;
4147
4148 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4149 status = decode_compound_hdr(&xdr, &hdr);
4150 if (!status)
4151 status = decode_setclientid(&xdr, clp);
4152 if (!status)
4153 status = -nfs_stat_to_errno(hdr.status);
4154 return status;
4155}
4156
4157/*
4158 * a SETCLIENTID_CONFIRM request
4159 */
4160static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, uint32_t *p, struct nfs_fsinfo *fsinfo)
4161{
4162 struct xdr_stream xdr;
4163 struct compound_hdr hdr;
4164 int status;
4165
4166 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4167 status = decode_compound_hdr(&xdr, &hdr);
4168 if (!status)
4169 status = decode_setclientid_confirm(&xdr);
4170 if (!status)
4171 status = decode_putrootfh(&xdr);
4172 if (!status)
4173 status = decode_fsinfo(&xdr, fsinfo);
4174 if (!status)
4175 status = -nfs_stat_to_errno(hdr.status);
4176 return status;
4177}
4178
4179/*
4180 * DELEGRETURN request
4181 */
4182static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, uint32_t *p, void *dummy)
4183{
4184 struct xdr_stream xdr;
4185 struct compound_hdr hdr;
4186 int status;
4187
4188 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4189 status = decode_compound_hdr(&xdr, &hdr);
4190 if (status == 0) {
4191 status = decode_putfh(&xdr);
4192 if (status == 0)
4193 status = decode_delegreturn(&xdr);
4194 }
4195 return status;
4196}
4197
4198uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus)
4199{
4200 uint32_t bitmap[2] = {0};
4201 uint32_t len;
4202
4203 if (!*p++) {
4204 if (!*p)
4205 return ERR_PTR(-EAGAIN);
4206 entry->eof = 1;
4207 return ERR_PTR(-EBADCOOKIE);
4208 }
4209
4210 entry->prev_cookie = entry->cookie;
4211 p = xdr_decode_hyper(p, &entry->cookie);
4212 entry->len = ntohl(*p++);
4213 entry->name = (const char *) p;
4214 p += XDR_QUADLEN(entry->len);
4215
4216 /*
4217 * In case the server doesn't return an inode number,
4218 * we fake one here. (We don't use inode number 0,
4219 * since glibc seems to choke on it...)
4220 */
4221 entry->ino = 1;
4222
4223 len = ntohl(*p++); /* bitmap length */
4224 if (len-- > 0) {
4225 bitmap[0] = ntohl(*p++);
4226 if (len-- > 0) {
4227 bitmap[1] = ntohl(*p++);
4228 p += len;
4229 }
4230 }
4231 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4232 if (len > 0) {
97d312d0
MN
4233 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4234 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4235 /* Ignore the return value of rdattr_error for now */
4236 p++;
4237 len--;
4238 }
1da177e4
LT
4239 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4240 xdr_decode_hyper(p, &entry->ino);
4241 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4242 xdr_decode_hyper(p, &entry->ino);
4243 p += len;
4244 }
4245
4246 entry->eof = !p[0] && p[1];
4247 return p;
4248}
4249
4250/*
4251 * We need to translate between nfs status return values and
4252 * the local errno values which may not be the same.
4253 */
4254static struct {
4255 int stat;
4256 int errno;
4257} nfs_errtbl[] = {
4258 { NFS4_OK, 0 },
4259 { NFS4ERR_PERM, EPERM },
4260 { NFS4ERR_NOENT, ENOENT },
4261 { NFS4ERR_IO, errno_NFSERR_IO },
4262 { NFS4ERR_NXIO, ENXIO },
4263 { NFS4ERR_ACCESS, EACCES },
4264 { NFS4ERR_EXIST, EEXIST },
4265 { NFS4ERR_XDEV, EXDEV },
4266 { NFS4ERR_NOTDIR, ENOTDIR },
4267 { NFS4ERR_ISDIR, EISDIR },
4268 { NFS4ERR_INVAL, EINVAL },
4269 { NFS4ERR_FBIG, EFBIG },
4270 { NFS4ERR_NOSPC, ENOSPC },
4271 { NFS4ERR_ROFS, EROFS },
4272 { NFS4ERR_MLINK, EMLINK },
4273 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4274 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4275 { NFS4ERR_DQUOT, EDQUOT },
4276 { NFS4ERR_STALE, ESTALE },
4277 { NFS4ERR_BADHANDLE, EBADHANDLE },
6ebf3656
MN
4278 { NFS4ERR_BADOWNER, EINVAL },
4279 { NFS4ERR_BADNAME, EINVAL },
1da177e4
LT
4280 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4281 { NFS4ERR_NOTSUPP, ENOTSUPP },
4282 { NFS4ERR_TOOSMALL, ETOOSMALL },
4283 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4284 { NFS4ERR_BADTYPE, EBADTYPE },
4285 { NFS4ERR_LOCKED, EAGAIN },
4286 { NFS4ERR_RESOURCE, EREMOTEIO },
4287 { NFS4ERR_SYMLINK, ELOOP },
4288 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4289 { NFS4ERR_DEADLOCK, EDEADLK },
4290 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4291 * to be handled by a
4292 * middle-layer.
4293 */
4294 { -1, EIO }
4295};
4296
4297/*
4298 * Convert an NFS error code to a local one.
4299 * This one is used jointly by NFSv2 and NFSv3.
4300 */
4301static int
4302nfs_stat_to_errno(int stat)
4303{
4304 int i;
4305 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4306 if (nfs_errtbl[i].stat == stat)
4307 return nfs_errtbl[i].errno;
4308 }
4309 if (stat <= 10000 || stat > 10100) {
4310 /* The server is looney tunes. */
4311 return ESERVERFAULT;
4312 }
4313 /* If we cannot translate the error, the recovery routines should
4314 * handle it.
4315 * Note: remaining NFSv4 error codes have values > 10000, so should
4316 * not conflict with native Linux error codes.
4317 */
4318 return stat;
4319}
4320
4321#ifndef MAX
4322# define MAX(a, b) (((a) > (b))? (a) : (b))
4323#endif
4324
4325#define PROC(proc, argtype, restype) \
4326[NFSPROC4_CLNT_##proc] = { \
4327 .p_proc = NFSPROC4_COMPOUND, \
4328 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4329 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4330 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
4331 }
4332
4333struct rpc_procinfo nfs4_procedures[] = {
4334 PROC(READ, enc_read, dec_read),
4335 PROC(WRITE, enc_write, dec_write),
4336 PROC(COMMIT, enc_commit, dec_commit),
4337 PROC(OPEN, enc_open, dec_open),
4338 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4339 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4340 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4341 PROC(CLOSE, enc_close, dec_close),
4342 PROC(SETATTR, enc_setattr, dec_setattr),
4343 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4344 PROC(RENEW, enc_renew, dec_renew),
4345 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4346 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4347 PROC(LOCK, enc_lock, dec_lock),
4348 PROC(LOCKT, enc_lockt, dec_lockt),
4349 PROC(LOCKU, enc_locku, dec_locku),
4350 PROC(ACCESS, enc_access, dec_access),
4351 PROC(GETATTR, enc_getattr, dec_getattr),
4352 PROC(LOOKUP, enc_lookup, dec_lookup),
4353 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4354 PROC(REMOVE, enc_remove, dec_remove),
4355 PROC(RENAME, enc_rename, dec_rename),
4356 PROC(LINK, enc_link, dec_link),
4357 PROC(SYMLINK, enc_symlink, dec_symlink),
4358 PROC(CREATE, enc_create, dec_create),
4359 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4360 PROC(STATFS, enc_statfs, dec_statfs),
4361 PROC(READLINK, enc_readlink, dec_readlink),
4362 PROC(READDIR, enc_readdir, dec_readdir),
4363 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4364 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
029d105e 4365 PROC(GETACL, enc_getacl, dec_getacl),
23ec6965 4366 PROC(SETACL, enc_setacl, dec_setacl),
1da177e4
LT
4367};
4368
4369struct rpc_version nfs_version4 = {
4370 .number = 4,
4371 .nrprocs = sizeof(nfs4_procedures)/sizeof(nfs4_procedures[0]),
4372 .procs = nfs4_procedures
4373};
4374
4375/*
4376 * Local variables:
4377 * c-basic-offset: 8
4378 * End:
4379 */
This page took 0.241414 seconds and 5 git commands to generate.