4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
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.
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.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.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>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs4_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2)
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 + \
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))
86 #define nfs4_fattr_bitmap_maxsz 3
87 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
88 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
89 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
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)
96 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
97 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
98 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
99 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
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*/ + \
109 6 + (NFS4_VERIFIER_SIZE >> 2))
110 #define decode_setclientid_maxsz \
111 (op_decode_hdr_maxsz + \
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 + \
123 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
125 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
126 #define encode_link_maxsz (op_encode_hdr_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 + \
133 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
134 #define encode_create_maxsz (op_encode_hdr_maxsz + \
135 2 + nfs4_name_maxsz + \
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 + \
151 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
152 decode_putfh_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 + \
162 op_encode_hdr_maxsz + 8 + \
163 encode_getattr_maxsz)
164 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
165 decode_putfh_maxsz + \
166 op_decode_hdr_maxsz + 4 + \
167 decode_getattr_maxsz)
168 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
169 encode_putfh_maxsz + \
170 op_encode_hdr_maxsz + 3 + \
171 encode_getattr_maxsz)
172 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
173 decode_putfh_maxsz + \
174 op_decode_hdr_maxsz + 2 + \
175 decode_getattr_maxsz)
176 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
177 encode_putfh_maxsz + \
178 op_encode_hdr_maxsz + \
180 encode_getattr_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 + \
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 + \
198 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
199 decode_putfh_maxsz + \
200 op_decode_hdr_maxsz + \
202 #define NFS4_enc_open_downgrade_sz \
203 (compound_encode_hdr_maxsz + \
204 encode_putfh_maxsz + \
205 op_encode_hdr_maxsz + 7 + \
206 encode_getattr_maxsz)
207 #define NFS4_dec_open_downgrade_sz \
208 (compound_decode_hdr_maxsz + \
209 decode_putfh_maxsz + \
210 op_decode_hdr_maxsz + 4 + \
211 decode_getattr_maxsz)
212 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
213 encode_putfh_maxsz + \
214 op_encode_hdr_maxsz + 5 + \
215 encode_getattr_maxsz)
216 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
217 decode_putfh_maxsz + \
218 op_decode_hdr_maxsz + 4 + \
219 decode_getattr_maxsz)
220 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
221 encode_putfh_maxsz + \
222 op_encode_hdr_maxsz + 4 + \
224 encode_getattr_maxsz)
225 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
226 decode_putfh_maxsz + \
227 op_decode_hdr_maxsz + 3 + \
229 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
230 encode_putfh_maxsz + \
232 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
233 decode_putfh_maxsz + \
235 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
237 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
239 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
240 encode_setclientid_maxsz)
241 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
242 decode_setclientid_maxsz)
243 #define NFS4_enc_setclientid_confirm_sz \
244 (compound_encode_hdr_maxsz + \
245 encode_setclientid_confirm_maxsz + \
246 encode_putrootfh_maxsz + \
248 #define NFS4_dec_setclientid_confirm_sz \
249 (compound_decode_hdr_maxsz + \
250 decode_setclientid_confirm_maxsz + \
251 decode_putrootfh_maxsz + \
253 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
254 encode_putfh_maxsz + \
255 encode_getattr_maxsz + \
256 op_encode_hdr_maxsz + \
260 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
261 decode_putfh_maxsz + \
262 decode_getattr_maxsz + \
263 op_decode_hdr_maxsz + \
266 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
267 encode_putfh_maxsz + \
268 encode_getattr_maxsz + \
269 op_encode_hdr_maxsz + \
272 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
273 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
274 encode_putfh_maxsz + \
275 encode_getattr_maxsz + \
276 op_encode_hdr_maxsz + \
278 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
279 decode_putfh_maxsz + \
280 decode_getattr_maxsz + \
281 op_decode_hdr_maxsz + 4)
282 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
283 encode_putfh_maxsz + \
284 op_encode_hdr_maxsz + 1)
285 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
286 decode_putfh_maxsz + \
287 op_decode_hdr_maxsz + 2)
288 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
289 encode_putfh_maxsz + \
290 encode_getattr_maxsz)
291 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
292 decode_putfh_maxsz + \
293 decode_getattr_maxsz)
294 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
295 encode_putfh_maxsz + \
296 encode_lookup_maxsz + \
297 encode_getattr_maxsz + \
299 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
300 decode_putfh_maxsz + \
301 op_decode_hdr_maxsz + \
302 decode_getattr_maxsz + \
304 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
305 encode_putrootfh_maxsz + \
306 encode_getattr_maxsz + \
308 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
309 decode_putrootfh_maxsz + \
310 decode_getattr_maxsz + \
312 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
313 encode_putfh_maxsz + \
314 encode_remove_maxsz + \
315 encode_getattr_maxsz)
316 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
317 decode_putfh_maxsz + \
318 op_decode_hdr_maxsz + 5 + \
319 decode_getattr_maxsz)
320 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
321 encode_putfh_maxsz + \
322 encode_savefh_maxsz + \
323 encode_putfh_maxsz + \
324 encode_rename_maxsz + \
325 encode_getattr_maxsz + \
326 encode_restorefh_maxsz + \
327 encode_getattr_maxsz)
328 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
329 decode_putfh_maxsz + \
330 decode_savefh_maxsz + \
331 decode_putfh_maxsz + \
332 decode_rename_maxsz + \
333 decode_getattr_maxsz + \
334 decode_restorefh_maxsz + \
335 decode_getattr_maxsz)
336 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
337 encode_putfh_maxsz + \
338 encode_savefh_maxsz + \
339 encode_putfh_maxsz + \
340 encode_link_maxsz + \
341 decode_getattr_maxsz + \
342 encode_restorefh_maxsz + \
343 decode_getattr_maxsz)
344 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
345 decode_putfh_maxsz + \
346 decode_savefh_maxsz + \
347 decode_putfh_maxsz + \
348 decode_link_maxsz + \
349 decode_getattr_maxsz + \
350 decode_restorefh_maxsz + \
351 decode_getattr_maxsz)
352 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
353 encode_putfh_maxsz + \
354 encode_symlink_maxsz + \
355 encode_getattr_maxsz + \
357 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
358 decode_putfh_maxsz + \
359 decode_symlink_maxsz + \
360 decode_getattr_maxsz + \
362 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
363 encode_putfh_maxsz + \
364 encode_savefh_maxsz + \
365 encode_create_maxsz + \
366 encode_getfh_maxsz + \
367 encode_getattr_maxsz + \
368 encode_restorefh_maxsz + \
369 encode_getattr_maxsz)
370 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
371 decode_putfh_maxsz + \
372 decode_savefh_maxsz + \
373 decode_create_maxsz + \
374 decode_getfh_maxsz + \
375 decode_getattr_maxsz + \
376 decode_restorefh_maxsz + \
377 decode_getattr_maxsz)
378 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
379 encode_putfh_maxsz + \
380 encode_getattr_maxsz)
381 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
382 decode_putfh_maxsz + \
383 decode_getattr_maxsz)
384 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
385 encode_putfh_maxsz + \
386 encode_getattr_maxsz)
387 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
388 decode_putfh_maxsz + \
389 op_decode_hdr_maxsz + 12)
390 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
391 encode_putfh_maxsz + \
392 encode_getattr_maxsz)
393 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
394 decode_putfh_maxsz + \
395 decode_getattr_maxsz)
396 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
397 encode_putfh_maxsz + \
398 encode_delegreturn_maxsz + \
399 encode_getattr_maxsz)
400 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
401 decode_delegreturn_maxsz + \
402 decode_getattr_maxsz)
403 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
404 encode_putfh_maxsz + \
405 encode_getattr_maxsz)
406 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
407 decode_putfh_maxsz + \
408 op_decode_hdr_maxsz + \
409 nfs4_fattr_bitmap_maxsz + 1)
410 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
411 encode_putfh_maxsz + \
412 op_encode_hdr_maxsz + 4 + \
413 nfs4_fattr_bitmap_maxsz + 1)
414 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
415 decode_putfh_maxsz + \
416 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
417 #define NFS4_enc_fs_locations_sz \
418 (compound_encode_hdr_maxsz + \
419 encode_putfh_maxsz + \
420 encode_getattr_maxsz)
421 #define NFS4_dec_fs_locations_sz \
422 (compound_decode_hdr_maxsz + \
423 decode_putfh_maxsz + \
424 op_decode_hdr_maxsz + \
425 nfs4_fattr_bitmap_maxsz)
429 unsigned int nfs2type
;
437 { S_IFSOCK
, NFSOCK
},
443 struct compound_hdr
{
451 * START OF "GENERIC" ENCODE ROUTINES.
452 * These may look a little ugly since they are imported from a "generic"
453 * set of XDR encode/decode routines which are intended to be shared by
454 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
456 * If the pain of reading these is too great, it should be a straightforward
457 * task to translate them into Linux-specific versions which are more
458 * consistent with the style used in NFSv2/v3...
460 #define WRITE32(n) *p++ = htonl(n)
461 #define WRITE64(n) do { \
462 *p++ = htonl((uint32_t)((n) >> 32)); \
463 *p++ = htonl((uint32_t)(n)); \
465 #define WRITEMEM(ptr,nbytes) do { \
466 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
469 #define RESERVE_SPACE(nbytes) do { \
470 p = xdr_reserve_space(xdr, nbytes); \
471 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
475 static void encode_string(struct xdr_stream
*xdr
, unsigned int len
, const char *str
)
479 p
= xdr_reserve_space(xdr
, 4 + len
);
481 xdr_encode_opaque(p
, str
, len
);
484 static int encode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
488 dprintk("encode_compound: tag=%.*s\n", (int)hdr
->taglen
, hdr
->tag
);
489 BUG_ON(hdr
->taglen
> NFS4_MAXTAGLEN
);
490 RESERVE_SPACE(12+(XDR_QUADLEN(hdr
->taglen
)<<2));
491 WRITE32(hdr
->taglen
);
492 WRITEMEM(hdr
->tag
, hdr
->taglen
);
493 WRITE32(NFS4_MINOR_VERSION
);
498 static void encode_nfs4_verifier(struct xdr_stream
*xdr
, const nfs4_verifier
*verf
)
502 p
= xdr_reserve_space(xdr
, NFS4_VERIFIER_SIZE
);
504 xdr_encode_opaque_fixed(p
, verf
->data
, NFS4_VERIFIER_SIZE
);
507 static int encode_attrs(struct xdr_stream
*xdr
, const struct iattr
*iap
, const struct nfs_server
*server
)
509 char owner_name
[IDMAP_NAMESZ
];
510 char owner_group
[IDMAP_NAMESZ
];
511 int owner_namelen
= 0;
512 int owner_grouplen
= 0;
521 * We reserve enough space to write the entire attribute buffer at once.
522 * In the worst-case, this would be
523 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
524 * = 36 bytes, plus any contribution from variable-length fields
525 * such as owner/group.
530 if (iap
->ia_valid
& ATTR_SIZE
)
532 if (iap
->ia_valid
& ATTR_MODE
)
534 if (iap
->ia_valid
& ATTR_UID
) {
535 owner_namelen
= nfs_map_uid_to_name(server
->nfs_client
, iap
->ia_uid
, owner_name
);
536 if (owner_namelen
< 0) {
537 printk(KERN_WARNING
"nfs: couldn't resolve uid %d to string\n",
540 strcpy(owner_name
, "nobody");
541 owner_namelen
= sizeof("nobody") - 1;
544 len
+= 4 + (XDR_QUADLEN(owner_namelen
) << 2);
546 if (iap
->ia_valid
& ATTR_GID
) {
547 owner_grouplen
= nfs_map_gid_to_group(server
->nfs_client
, iap
->ia_gid
, owner_group
);
548 if (owner_grouplen
< 0) {
549 printk(KERN_WARNING
"nfs4: couldn't resolve gid %d to string\n",
551 strcpy(owner_group
, "nobody");
552 owner_grouplen
= sizeof("nobody") - 1;
555 len
+= 4 + (XDR_QUADLEN(owner_grouplen
) << 2);
557 if (iap
->ia_valid
& ATTR_ATIME_SET
)
559 else if (iap
->ia_valid
& ATTR_ATIME
)
561 if (iap
->ia_valid
& ATTR_MTIME_SET
)
563 else if (iap
->ia_valid
& ATTR_MTIME
)
568 * We write the bitmap length now, but leave the bitmap and the attribute
569 * buffer length to be backfilled at the end of this routine.
575 if (iap
->ia_valid
& ATTR_SIZE
) {
576 bmval0
|= FATTR4_WORD0_SIZE
;
577 WRITE64(iap
->ia_size
);
579 if (iap
->ia_valid
& ATTR_MODE
) {
580 bmval1
|= FATTR4_WORD1_MODE
;
581 WRITE32(iap
->ia_mode
& S_IALLUGO
);
583 if (iap
->ia_valid
& ATTR_UID
) {
584 bmval1
|= FATTR4_WORD1_OWNER
;
585 WRITE32(owner_namelen
);
586 WRITEMEM(owner_name
, owner_namelen
);
588 if (iap
->ia_valid
& ATTR_GID
) {
589 bmval1
|= FATTR4_WORD1_OWNER_GROUP
;
590 WRITE32(owner_grouplen
);
591 WRITEMEM(owner_group
, owner_grouplen
);
593 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
594 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
595 WRITE32(NFS4_SET_TO_CLIENT_TIME
);
597 WRITE32(iap
->ia_mtime
.tv_sec
);
598 WRITE32(iap
->ia_mtime
.tv_nsec
);
600 else if (iap
->ia_valid
& ATTR_ATIME
) {
601 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
602 WRITE32(NFS4_SET_TO_SERVER_TIME
);
604 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
605 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
606 WRITE32(NFS4_SET_TO_CLIENT_TIME
);
608 WRITE32(iap
->ia_mtime
.tv_sec
);
609 WRITE32(iap
->ia_mtime
.tv_nsec
);
611 else if (iap
->ia_valid
& ATTR_MTIME
) {
612 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
613 WRITE32(NFS4_SET_TO_SERVER_TIME
);
617 * Now we backfill the bitmap and the attribute buffer length.
619 if (len
!= ((char *)p
- (char *)q
) + 4) {
620 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
621 len
, ((char *)p
- (char *)q
) + 4);
624 len
= (char *)p
- (char *)q
- 12;
625 *q
++ = htonl(bmval0
);
626 *q
++ = htonl(bmval1
);
634 static int encode_access(struct xdr_stream
*xdr
, u32 access
)
645 static int encode_close(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
)
649 RESERVE_SPACE(8+NFS4_STATEID_SIZE
);
651 WRITE32(arg
->seqid
->sequence
->counter
);
652 WRITEMEM(arg
->stateid
->data
, NFS4_STATEID_SIZE
);
657 static int encode_commit(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
)
663 WRITE64(args
->offset
);
664 WRITE32(args
->count
);
669 static int encode_create(struct xdr_stream
*xdr
, const struct nfs4_create_arg
*create
)
675 WRITE32(create
->ftype
);
677 switch (create
->ftype
) {
680 WRITE32(create
->u
.symlink
.len
);
681 xdr_write_pages(xdr
, create
->u
.symlink
.pages
, 0, create
->u
.symlink
.len
);
684 case NF4BLK
: case NF4CHR
:
686 WRITE32(create
->u
.device
.specdata1
);
687 WRITE32(create
->u
.device
.specdata2
);
694 RESERVE_SPACE(4 + create
->name
->len
);
695 WRITE32(create
->name
->len
);
696 WRITEMEM(create
->name
->name
, create
->name
->len
);
698 return encode_attrs(xdr
, create
->attrs
, create
->server
);
701 static int encode_getattr_one(struct xdr_stream
*xdr
, uint32_t bitmap
)
712 static int encode_getattr_two(struct xdr_stream
*xdr
, uint32_t bm0
, uint32_t bm1
)
724 static int encode_getfattr(struct xdr_stream
*xdr
, const u32
* bitmask
)
726 return encode_getattr_two(xdr
,
727 bitmask
[0] & nfs4_fattr_bitmap
[0],
728 bitmask
[1] & nfs4_fattr_bitmap
[1]);
731 static int encode_fsinfo(struct xdr_stream
*xdr
, const u32
* bitmask
)
733 return encode_getattr_two(xdr
, bitmask
[0] & nfs4_fsinfo_bitmap
[0],
734 bitmask
[1] & nfs4_fsinfo_bitmap
[1]);
737 static int encode_fs_locations(struct xdr_stream
*xdr
, const u32
* bitmask
)
739 return encode_getattr_two(xdr
,
740 bitmask
[0] & nfs4_fs_locations_bitmap
[0],
741 bitmask
[1] & nfs4_fs_locations_bitmap
[1]);
744 static int encode_getfh(struct xdr_stream
*xdr
)
754 static int encode_link(struct xdr_stream
*xdr
, const struct qstr
*name
)
758 RESERVE_SPACE(8 + name
->len
);
761 WRITEMEM(name
->name
, name
->len
);
766 static inline int nfs4_lock_type(struct file_lock
*fl
, int block
)
768 if ((fl
->fl_type
& (F_RDLCK
|F_WRLCK
|F_UNLCK
)) == F_RDLCK
)
769 return block
? NFS4_READW_LT
: NFS4_READ_LT
;
770 return block
? NFS4_WRITEW_LT
: NFS4_WRITE_LT
;
773 static inline uint64_t nfs4_lock_length(struct file_lock
*fl
)
775 if (fl
->fl_end
== OFFSET_MAX
)
777 return fl
->fl_end
- fl
->fl_start
+ 1;
781 * opcode,type,reclaim,offset,length,new_lock_owner = 32
782 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
784 static int encode_lock(struct xdr_stream
*xdr
, const struct nfs_lock_args
*args
)
790 WRITE32(nfs4_lock_type(args
->fl
, args
->block
));
791 WRITE32(args
->reclaim
);
792 WRITE64(args
->fl
->fl_start
);
793 WRITE64(nfs4_lock_length(args
->fl
));
794 WRITE32(args
->new_lock_owner
);
795 if (args
->new_lock_owner
){
796 RESERVE_SPACE(4+NFS4_STATEID_SIZE
+20);
797 WRITE32(args
->open_seqid
->sequence
->counter
);
798 WRITEMEM(args
->open_stateid
->data
, NFS4_STATEID_SIZE
);
799 WRITE32(args
->lock_seqid
->sequence
->counter
);
800 WRITE64(args
->lock_owner
.clientid
);
802 WRITE32(args
->lock_owner
.id
);
805 RESERVE_SPACE(NFS4_STATEID_SIZE
+4);
806 WRITEMEM(args
->lock_stateid
->data
, NFS4_STATEID_SIZE
);
807 WRITE32(args
->lock_seqid
->sequence
->counter
);
813 static int encode_lockt(struct xdr_stream
*xdr
, const struct nfs_lockt_args
*args
)
819 WRITE32(nfs4_lock_type(args
->fl
, 0));
820 WRITE64(args
->fl
->fl_start
);
821 WRITE64(nfs4_lock_length(args
->fl
));
822 WRITE64(args
->lock_owner
.clientid
);
824 WRITE32(args
->lock_owner
.id
);
829 static int encode_locku(struct xdr_stream
*xdr
, const struct nfs_locku_args
*args
)
833 RESERVE_SPACE(12+NFS4_STATEID_SIZE
+16);
835 WRITE32(nfs4_lock_type(args
->fl
, 0));
836 WRITE32(args
->seqid
->sequence
->counter
);
837 WRITEMEM(args
->stateid
->data
, NFS4_STATEID_SIZE
);
838 WRITE64(args
->fl
->fl_start
);
839 WRITE64(nfs4_lock_length(args
->fl
));
844 static int encode_lookup(struct xdr_stream
*xdr
, const struct qstr
*name
)
849 RESERVE_SPACE(8 + len
);
852 WRITEMEM(name
->name
, len
);
857 static void encode_share_access(struct xdr_stream
*xdr
, int open_flags
)
862 switch (open_flags
& (FMODE_READ
|FMODE_WRITE
)) {
864 WRITE32(NFS4_SHARE_ACCESS_READ
);
867 WRITE32(NFS4_SHARE_ACCESS_WRITE
);
869 case FMODE_READ
|FMODE_WRITE
:
870 WRITE32(NFS4_SHARE_ACCESS_BOTH
);
875 WRITE32(0); /* for linux, share_deny = 0 always */
878 static inline void encode_openhdr(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
882 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
887 WRITE32(arg
->seqid
->sequence
->counter
);
888 encode_share_access(xdr
, arg
->open_flags
);
890 WRITE64(arg
->clientid
);
895 static inline void encode_createmode(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
900 switch(arg
->open_flags
& O_EXCL
) {
902 WRITE32(NFS4_CREATE_UNCHECKED
);
903 encode_attrs(xdr
, arg
->u
.attrs
, arg
->server
);
906 WRITE32(NFS4_CREATE_EXCLUSIVE
);
907 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
911 static void encode_opentype(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
916 switch (arg
->open_flags
& O_CREAT
) {
918 WRITE32(NFS4_OPEN_NOCREATE
);
921 BUG_ON(arg
->claim
!= NFS4_OPEN_CLAIM_NULL
);
922 WRITE32(NFS4_OPEN_CREATE
);
923 encode_createmode(xdr
, arg
);
927 static inline void encode_delegation_type(struct xdr_stream
*xdr
, int delegation_type
)
932 switch (delegation_type
) {
934 WRITE32(NFS4_OPEN_DELEGATE_NONE
);
937 WRITE32(NFS4_OPEN_DELEGATE_READ
);
939 case FMODE_WRITE
|FMODE_READ
:
940 WRITE32(NFS4_OPEN_DELEGATE_WRITE
);
947 static inline void encode_claim_null(struct xdr_stream
*xdr
, const struct qstr
*name
)
952 WRITE32(NFS4_OPEN_CLAIM_NULL
);
953 encode_string(xdr
, name
->len
, name
->name
);
956 static inline void encode_claim_previous(struct xdr_stream
*xdr
, int type
)
961 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS
);
962 encode_delegation_type(xdr
, type
);
965 static inline void encode_claim_delegate_cur(struct xdr_stream
*xdr
, const struct qstr
*name
, const nfs4_stateid
*stateid
)
969 RESERVE_SPACE(4+NFS4_STATEID_SIZE
);
970 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR
);
971 WRITEMEM(stateid
->data
, NFS4_STATEID_SIZE
);
972 encode_string(xdr
, name
->len
, name
->name
);
975 static int encode_open(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
977 encode_openhdr(xdr
, arg
);
978 encode_opentype(xdr
, arg
);
979 switch (arg
->claim
) {
980 case NFS4_OPEN_CLAIM_NULL
:
981 encode_claim_null(xdr
, arg
->name
);
983 case NFS4_OPEN_CLAIM_PREVIOUS
:
984 encode_claim_previous(xdr
, arg
->u
.delegation_type
);
986 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
987 encode_claim_delegate_cur(xdr
, arg
->name
, &arg
->u
.delegation
);
995 static int encode_open_confirm(struct xdr_stream
*xdr
, const struct nfs_open_confirmargs
*arg
)
999 RESERVE_SPACE(4+NFS4_STATEID_SIZE
+4);
1000 WRITE32(OP_OPEN_CONFIRM
);
1001 WRITEMEM(arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1002 WRITE32(arg
->seqid
->sequence
->counter
);
1007 static int encode_open_downgrade(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
)
1011 RESERVE_SPACE(4+NFS4_STATEID_SIZE
+4);
1012 WRITE32(OP_OPEN_DOWNGRADE
);
1013 WRITEMEM(arg
->stateid
->data
, NFS4_STATEID_SIZE
);
1014 WRITE32(arg
->seqid
->sequence
->counter
);
1015 encode_share_access(xdr
, arg
->open_flags
);
1020 encode_putfh(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
)
1025 RESERVE_SPACE(8 + len
);
1028 WRITEMEM(fh
->data
, len
);
1033 static int encode_putrootfh(struct xdr_stream
*xdr
)
1038 WRITE32(OP_PUTROOTFH
);
1043 static void encode_stateid(struct xdr_stream
*xdr
, const struct nfs_open_context
*ctx
)
1045 nfs4_stateid stateid
;
1048 RESERVE_SPACE(NFS4_STATEID_SIZE
);
1049 if (ctx
->state
!= NULL
) {
1050 nfs4_copy_stateid(&stateid
, ctx
->state
, ctx
->lockowner
);
1051 WRITEMEM(stateid
.data
, NFS4_STATEID_SIZE
);
1053 WRITEMEM(zero_stateid
.data
, NFS4_STATEID_SIZE
);
1056 static int encode_read(struct xdr_stream
*xdr
, const struct nfs_readargs
*args
)
1063 encode_stateid(xdr
, args
->context
);
1066 WRITE64(args
->offset
);
1067 WRITE32(args
->count
);
1072 static int encode_readdir(struct xdr_stream
*xdr
, const struct nfs4_readdir_arg
*readdir
, struct rpc_rqst
*req
)
1074 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1075 uint32_t attrs
[2] = {
1076 FATTR4_WORD0_RDATTR_ERROR
|FATTR4_WORD0_FILEID
,
1077 FATTR4_WORD1_MOUNTED_ON_FILEID
,
1082 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE
+20);
1083 WRITE32(OP_READDIR
);
1084 WRITE64(readdir
->cookie
);
1085 WRITEMEM(readdir
->verifier
.data
, NFS4_VERIFIER_SIZE
);
1086 WRITE32(readdir
->count
>> 1); /* We're not doing readdirplus */
1087 WRITE32(readdir
->count
);
1089 /* Switch to mounted_on_fileid if the server supports it */
1090 if (readdir
->bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
1091 attrs
[0] &= ~FATTR4_WORD0_FILEID
;
1093 attrs
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
1094 WRITE32(attrs
[0] & readdir
->bitmask
[0]);
1095 WRITE32(attrs
[1] & readdir
->bitmask
[1]);
1096 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1098 (unsigned long long)readdir
->cookie
,
1099 ((u32
*)readdir
->verifier
.data
)[0],
1100 ((u32
*)readdir
->verifier
.data
)[1],
1101 attrs
[0] & readdir
->bitmask
[0],
1102 attrs
[1] & readdir
->bitmask
[1]);
1104 /* set up reply kvec
1105 * toplevel_status + taglen + rescount + OP_PUTFH + status
1106 * + OP_READDIR + status + verifer(2) = 9
1108 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ 9) << 2;
1109 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, readdir
->pages
,
1110 readdir
->pgbase
, readdir
->count
);
1111 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1112 __FUNCTION__
, replen
, readdir
->pages
,
1113 readdir
->pgbase
, readdir
->count
);
1118 static int encode_readlink(struct xdr_stream
*xdr
, const struct nfs4_readlink
*readlink
, struct rpc_rqst
*req
)
1120 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1121 unsigned int replen
;
1125 WRITE32(OP_READLINK
);
1127 /* set up reply kvec
1128 * toplevel_status + taglen + rescount + OP_PUTFH + status
1129 * + OP_READLINK + status + string length = 8
1131 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ 8) << 2;
1132 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, readlink
->pages
,
1133 readlink
->pgbase
, readlink
->pglen
);
1138 static int encode_remove(struct xdr_stream
*xdr
, const struct qstr
*name
)
1142 RESERVE_SPACE(8 + name
->len
);
1145 WRITEMEM(name
->name
, name
->len
);
1150 static int encode_rename(struct xdr_stream
*xdr
, const struct qstr
*oldname
, const struct qstr
*newname
)
1154 RESERVE_SPACE(8 + oldname
->len
);
1156 WRITE32(oldname
->len
);
1157 WRITEMEM(oldname
->name
, oldname
->len
);
1159 RESERVE_SPACE(4 + newname
->len
);
1160 WRITE32(newname
->len
);
1161 WRITEMEM(newname
->name
, newname
->len
);
1166 static int encode_renew(struct xdr_stream
*xdr
, const struct nfs_client
*client_stateid
)
1172 WRITE64(client_stateid
->cl_clientid
);
1178 encode_restorefh(struct xdr_stream
*xdr
)
1183 WRITE32(OP_RESTOREFH
);
1189 encode_setacl(struct xdr_stream
*xdr
, struct nfs_setaclargs
*arg
)
1193 RESERVE_SPACE(4+NFS4_STATEID_SIZE
);
1194 WRITE32(OP_SETATTR
);
1195 WRITEMEM(zero_stateid
.data
, NFS4_STATEID_SIZE
);
1198 WRITE32(FATTR4_WORD0_ACL
);
1199 if (arg
->acl_len
% 4)
1202 WRITE32(arg
->acl_len
);
1203 xdr_write_pages(xdr
, arg
->acl_pages
, arg
->acl_pgbase
, arg
->acl_len
);
1208 encode_savefh(struct xdr_stream
*xdr
)
1218 static int encode_setattr(struct xdr_stream
*xdr
, const struct nfs_setattrargs
*arg
, const struct nfs_server
*server
)
1223 RESERVE_SPACE(4+NFS4_STATEID_SIZE
);
1224 WRITE32(OP_SETATTR
);
1225 WRITEMEM(arg
->stateid
.data
, NFS4_STATEID_SIZE
);
1227 if ((status
= encode_attrs(xdr
, arg
->iap
, server
)))
1233 static int encode_setclientid(struct xdr_stream
*xdr
, const struct nfs4_setclientid
*setclientid
)
1237 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE
);
1238 WRITE32(OP_SETCLIENTID
);
1239 WRITEMEM(setclientid
->sc_verifier
->data
, NFS4_VERIFIER_SIZE
);
1241 encode_string(xdr
, setclientid
->sc_name_len
, setclientid
->sc_name
);
1243 WRITE32(setclientid
->sc_prog
);
1244 encode_string(xdr
, setclientid
->sc_netid_len
, setclientid
->sc_netid
);
1245 encode_string(xdr
, setclientid
->sc_uaddr_len
, setclientid
->sc_uaddr
);
1247 WRITE32(setclientid
->sc_cb_ident
);
1252 static int encode_setclientid_confirm(struct xdr_stream
*xdr
, const struct nfs_client
*client_state
)
1256 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE
);
1257 WRITE32(OP_SETCLIENTID_CONFIRM
);
1258 WRITE64(client_state
->cl_clientid
);
1259 WRITEMEM(client_state
->cl_confirm
.data
, NFS4_VERIFIER_SIZE
);
1264 static int encode_write(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
)
1271 encode_stateid(xdr
, args
->context
);
1274 WRITE64(args
->offset
);
1275 WRITE32(args
->stable
);
1276 WRITE32(args
->count
);
1278 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, args
->count
);
1283 static int encode_delegreturn(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
)
1287 RESERVE_SPACE(4+NFS4_STATEID_SIZE
);
1289 WRITE32(OP_DELEGRETURN
);
1290 WRITEMEM(stateid
->data
, NFS4_STATEID_SIZE
);
1295 * END OF "GENERIC" ENCODE ROUTINES.
1299 * Encode an ACCESS request
1301 static int nfs4_xdr_enc_access(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_accessargs
*args
)
1303 struct xdr_stream xdr
;
1304 struct compound_hdr hdr
= {
1309 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1310 encode_compound_hdr(&xdr
, &hdr
);
1311 if ((status
= encode_putfh(&xdr
, args
->fh
)) == 0)
1312 status
= encode_access(&xdr
, args
->access
);
1317 * Encode LOOKUP request
1319 static int nfs4_xdr_enc_lookup(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_lookup_arg
*args
)
1321 struct xdr_stream xdr
;
1322 struct compound_hdr hdr
= {
1327 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1328 encode_compound_hdr(&xdr
, &hdr
);
1329 if ((status
= encode_putfh(&xdr
, args
->dir_fh
)) != 0)
1331 if ((status
= encode_lookup(&xdr
, args
->name
)) != 0)
1333 if ((status
= encode_getfh(&xdr
)) != 0)
1335 status
= encode_getfattr(&xdr
, args
->bitmask
);
1341 * Encode LOOKUP_ROOT request
1343 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_lookup_root_arg
*args
)
1345 struct xdr_stream xdr
;
1346 struct compound_hdr hdr
= {
1351 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1352 encode_compound_hdr(&xdr
, &hdr
);
1353 if ((status
= encode_putrootfh(&xdr
)) != 0)
1355 if ((status
= encode_getfh(&xdr
)) == 0)
1356 status
= encode_getfattr(&xdr
, args
->bitmask
);
1362 * Encode REMOVE request
1364 static int nfs4_xdr_enc_remove(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_remove_arg
*args
)
1366 struct xdr_stream xdr
;
1367 struct compound_hdr hdr
= {
1372 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1373 encode_compound_hdr(&xdr
, &hdr
);
1374 if ((status
= encode_putfh(&xdr
, args
->fh
)) != 0)
1376 if ((status
= encode_remove(&xdr
, args
->name
)) != 0)
1378 status
= encode_getfattr(&xdr
, args
->bitmask
);
1384 * Encode RENAME request
1386 static int nfs4_xdr_enc_rename(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_rename_arg
*args
)
1388 struct xdr_stream xdr
;
1389 struct compound_hdr hdr
= {
1394 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1395 encode_compound_hdr(&xdr
, &hdr
);
1396 if ((status
= encode_putfh(&xdr
, args
->old_dir
)) != 0)
1398 if ((status
= encode_savefh(&xdr
)) != 0)
1400 if ((status
= encode_putfh(&xdr
, args
->new_dir
)) != 0)
1402 if ((status
= encode_rename(&xdr
, args
->old_name
, args
->new_name
)) != 0)
1404 if ((status
= encode_getfattr(&xdr
, args
->bitmask
)) != 0)
1406 if ((status
= encode_restorefh(&xdr
)) != 0)
1408 status
= encode_getfattr(&xdr
, args
->bitmask
);
1414 * Encode LINK request
1416 static int nfs4_xdr_enc_link(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_link_arg
*args
)
1418 struct xdr_stream xdr
;
1419 struct compound_hdr hdr
= {
1424 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1425 encode_compound_hdr(&xdr
, &hdr
);
1426 if ((status
= encode_putfh(&xdr
, args
->fh
)) != 0)
1428 if ((status
= encode_savefh(&xdr
)) != 0)
1430 if ((status
= encode_putfh(&xdr
, args
->dir_fh
)) != 0)
1432 if ((status
= encode_link(&xdr
, args
->name
)) != 0)
1434 if ((status
= encode_getfattr(&xdr
, args
->bitmask
)) != 0)
1436 if ((status
= encode_restorefh(&xdr
)) != 0)
1438 status
= encode_getfattr(&xdr
, args
->bitmask
);
1444 * Encode CREATE request
1446 static int nfs4_xdr_enc_create(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_create_arg
*args
)
1448 struct xdr_stream xdr
;
1449 struct compound_hdr hdr
= {
1454 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1455 encode_compound_hdr(&xdr
, &hdr
);
1456 if ((status
= encode_putfh(&xdr
, args
->dir_fh
)) != 0)
1458 if ((status
= encode_savefh(&xdr
)) != 0)
1460 if ((status
= encode_create(&xdr
, args
)) != 0)
1462 if ((status
= encode_getfh(&xdr
)) != 0)
1464 if ((status
= encode_getfattr(&xdr
, args
->bitmask
)) != 0)
1466 if ((status
= encode_restorefh(&xdr
)) != 0)
1468 status
= encode_getfattr(&xdr
, args
->bitmask
);
1474 * Encode SYMLINK request
1476 static int nfs4_xdr_enc_symlink(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_create_arg
*args
)
1478 return nfs4_xdr_enc_create(req
, p
, args
);
1482 * Encode GETATTR request
1484 static int nfs4_xdr_enc_getattr(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_getattr_arg
*args
)
1486 struct xdr_stream xdr
;
1487 struct compound_hdr hdr
= {
1492 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1493 encode_compound_hdr(&xdr
, &hdr
);
1494 if ((status
= encode_putfh(&xdr
, args
->fh
)) == 0)
1495 status
= encode_getfattr(&xdr
, args
->bitmask
);
1500 * Encode a CLOSE request
1502 static int nfs4_xdr_enc_close(struct rpc_rqst
*req
, __be32
*p
, struct nfs_closeargs
*args
)
1504 struct xdr_stream xdr
;
1505 struct compound_hdr hdr
= {
1510 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1511 encode_compound_hdr(&xdr
, &hdr
);
1512 status
= encode_putfh(&xdr
, args
->fh
);
1515 status
= encode_close(&xdr
, args
);
1518 status
= encode_getfattr(&xdr
, args
->bitmask
);
1524 * Encode an OPEN request
1526 static int nfs4_xdr_enc_open(struct rpc_rqst
*req
, __be32
*p
, struct nfs_openargs
*args
)
1528 struct xdr_stream xdr
;
1529 struct compound_hdr hdr
= {
1534 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1535 encode_compound_hdr(&xdr
, &hdr
);
1536 status
= encode_putfh(&xdr
, args
->fh
);
1539 status
= encode_savefh(&xdr
);
1542 status
= encode_open(&xdr
, args
);
1545 status
= encode_getfh(&xdr
);
1548 status
= encode_getfattr(&xdr
, args
->bitmask
);
1551 status
= encode_restorefh(&xdr
);
1554 status
= encode_getfattr(&xdr
, args
->bitmask
);
1560 * Encode an OPEN_CONFIRM request
1562 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_open_confirmargs
*args
)
1564 struct xdr_stream xdr
;
1565 struct compound_hdr hdr
= {
1570 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1571 encode_compound_hdr(&xdr
, &hdr
);
1572 status
= encode_putfh(&xdr
, args
->fh
);
1575 status
= encode_open_confirm(&xdr
, args
);
1581 * Encode an OPEN request with no attributes.
1583 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst
*req
, __be32
*p
, struct nfs_openargs
*args
)
1585 struct xdr_stream xdr
;
1586 struct compound_hdr hdr
= {
1591 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1592 encode_compound_hdr(&xdr
, &hdr
);
1593 status
= encode_putfh(&xdr
, args
->fh
);
1596 status
= encode_open(&xdr
, args
);
1599 status
= encode_getfattr(&xdr
, args
->bitmask
);
1605 * Encode an OPEN_DOWNGRADE request
1607 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst
*req
, __be32
*p
, struct nfs_closeargs
*args
)
1609 struct xdr_stream xdr
;
1610 struct compound_hdr hdr
= {
1615 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1616 encode_compound_hdr(&xdr
, &hdr
);
1617 status
= encode_putfh(&xdr
, args
->fh
);
1620 status
= encode_open_downgrade(&xdr
, args
);
1623 status
= encode_getfattr(&xdr
, args
->bitmask
);
1629 * Encode a LOCK request
1631 static int nfs4_xdr_enc_lock(struct rpc_rqst
*req
, __be32
*p
, struct nfs_lock_args
*args
)
1633 struct xdr_stream xdr
;
1634 struct compound_hdr hdr
= {
1639 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1640 encode_compound_hdr(&xdr
, &hdr
);
1641 status
= encode_putfh(&xdr
, args
->fh
);
1644 status
= encode_lock(&xdr
, args
);
1650 * Encode a LOCKT request
1652 static int nfs4_xdr_enc_lockt(struct rpc_rqst
*req
, __be32
*p
, struct nfs_lockt_args
*args
)
1654 struct xdr_stream xdr
;
1655 struct compound_hdr hdr
= {
1660 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1661 encode_compound_hdr(&xdr
, &hdr
);
1662 status
= encode_putfh(&xdr
, args
->fh
);
1665 status
= encode_lockt(&xdr
, args
);
1671 * Encode a LOCKU request
1673 static int nfs4_xdr_enc_locku(struct rpc_rqst
*req
, __be32
*p
, struct nfs_locku_args
*args
)
1675 struct xdr_stream xdr
;
1676 struct compound_hdr hdr
= {
1681 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1682 encode_compound_hdr(&xdr
, &hdr
);
1683 status
= encode_putfh(&xdr
, args
->fh
);
1686 status
= encode_locku(&xdr
, args
);
1692 * Encode a READLINK request
1694 static int nfs4_xdr_enc_readlink(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_readlink
*args
)
1696 struct xdr_stream xdr
;
1697 struct compound_hdr hdr
= {
1702 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1703 encode_compound_hdr(&xdr
, &hdr
);
1704 status
= encode_putfh(&xdr
, args
->fh
);
1707 status
= encode_readlink(&xdr
, args
, req
);
1713 * Encode a READDIR request
1715 static int nfs4_xdr_enc_readdir(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_readdir_arg
*args
)
1717 struct xdr_stream xdr
;
1718 struct compound_hdr hdr
= {
1723 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1724 encode_compound_hdr(&xdr
, &hdr
);
1725 status
= encode_putfh(&xdr
, args
->fh
);
1728 status
= encode_readdir(&xdr
, args
, req
);
1734 * Encode a READ request
1736 static int nfs4_xdr_enc_read(struct rpc_rqst
*req
, __be32
*p
, struct nfs_readargs
*args
)
1738 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1739 struct xdr_stream xdr
;
1740 struct compound_hdr hdr
= {
1745 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1746 encode_compound_hdr(&xdr
, &hdr
);
1747 status
= encode_putfh(&xdr
, args
->fh
);
1750 status
= encode_read(&xdr
, args
);
1754 /* set up reply kvec
1755 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1756 * + OP_READ + status + eof + datalen = 9
1758 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ NFS4_dec_read_sz
) << 2;
1759 xdr_inline_pages(&req
->rq_rcv_buf
, replen
,
1760 args
->pages
, args
->pgbase
, args
->count
);
1766 * Encode an SETATTR request
1768 static int nfs4_xdr_enc_setattr(struct rpc_rqst
*req
, __be32
*p
, struct nfs_setattrargs
*args
)
1771 struct xdr_stream xdr
;
1772 struct compound_hdr hdr
= {
1777 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1778 encode_compound_hdr(&xdr
, &hdr
);
1779 status
= encode_putfh(&xdr
, args
->fh
);
1782 status
= encode_setattr(&xdr
, args
, args
->server
);
1785 status
= encode_getfattr(&xdr
, args
->bitmask
);
1791 * Encode a GETACL request
1794 nfs4_xdr_enc_getacl(struct rpc_rqst
*req
, __be32
*p
,
1795 struct nfs_getaclargs
*args
)
1797 struct xdr_stream xdr
;
1798 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1799 struct compound_hdr hdr
= {
1804 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1805 encode_compound_hdr(&xdr
, &hdr
);
1806 status
= encode_putfh(&xdr
, args
->fh
);
1809 status
= encode_getattr_two(&xdr
, FATTR4_WORD0_ACL
, 0);
1810 /* set up reply buffer: */
1811 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ NFS4_dec_getacl_sz
) << 2;
1812 xdr_inline_pages(&req
->rq_rcv_buf
, replen
,
1813 args
->acl_pages
, args
->acl_pgbase
, args
->acl_len
);
1819 * Encode a WRITE request
1821 static int nfs4_xdr_enc_write(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeargs
*args
)
1823 struct xdr_stream xdr
;
1824 struct compound_hdr hdr
= {
1829 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1830 encode_compound_hdr(&xdr
, &hdr
);
1831 status
= encode_putfh(&xdr
, args
->fh
);
1834 status
= encode_write(&xdr
, args
);
1837 status
= encode_getfattr(&xdr
, args
->bitmask
);
1845 static int nfs4_xdr_enc_commit(struct rpc_rqst
*req
, __be32
*p
, struct nfs_writeargs
*args
)
1847 struct xdr_stream xdr
;
1848 struct compound_hdr hdr
= {
1853 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1854 encode_compound_hdr(&xdr
, &hdr
);
1855 status
= encode_putfh(&xdr
, args
->fh
);
1858 status
= encode_commit(&xdr
, args
);
1861 status
= encode_getfattr(&xdr
, args
->bitmask
);
1869 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_fsinfo_arg
*args
)
1871 struct xdr_stream xdr
;
1872 struct compound_hdr hdr
= {
1877 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1878 encode_compound_hdr(&xdr
, &hdr
);
1879 status
= encode_putfh(&xdr
, args
->fh
);
1881 status
= encode_fsinfo(&xdr
, args
->bitmask
);
1886 * a PATHCONF request
1888 static int nfs4_xdr_enc_pathconf(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_pathconf_arg
*args
)
1890 struct xdr_stream xdr
;
1891 struct compound_hdr hdr
= {
1896 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1897 encode_compound_hdr(&xdr
, &hdr
);
1898 status
= encode_putfh(&xdr
, args
->fh
);
1900 status
= encode_getattr_one(&xdr
,
1901 args
->bitmask
[0] & nfs4_pathconf_bitmap
[0]);
1908 static int nfs4_xdr_enc_statfs(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_statfs_arg
*args
)
1910 struct xdr_stream xdr
;
1911 struct compound_hdr hdr
= {
1916 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1917 encode_compound_hdr(&xdr
, &hdr
);
1918 status
= encode_putfh(&xdr
, args
->fh
);
1920 status
= encode_getattr_two(&xdr
,
1921 args
->bitmask
[0] & nfs4_statfs_bitmap
[0],
1922 args
->bitmask
[1] & nfs4_statfs_bitmap
[1]);
1927 * GETATTR_BITMAP request
1929 static int nfs4_xdr_enc_server_caps(struct rpc_rqst
*req
, __be32
*p
, const struct nfs_fh
*fhandle
)
1931 struct xdr_stream xdr
;
1932 struct compound_hdr hdr
= {
1937 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1938 encode_compound_hdr(&xdr
, &hdr
);
1939 status
= encode_putfh(&xdr
, fhandle
);
1941 status
= encode_getattr_one(&xdr
, FATTR4_WORD0_SUPPORTED_ATTRS
|
1942 FATTR4_WORD0_LINK_SUPPORT
|
1943 FATTR4_WORD0_SYMLINK_SUPPORT
|
1944 FATTR4_WORD0_ACLSUPPORT
);
1951 static int nfs4_xdr_enc_renew(struct rpc_rqst
*req
, __be32
*p
, struct nfs_client
*clp
)
1953 struct xdr_stream xdr
;
1954 struct compound_hdr hdr
= {
1958 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1959 encode_compound_hdr(&xdr
, &hdr
);
1960 return encode_renew(&xdr
, clp
);
1964 * a SETCLIENTID request
1966 static int nfs4_xdr_enc_setclientid(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_setclientid
*sc
)
1968 struct xdr_stream xdr
;
1969 struct compound_hdr hdr
= {
1973 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1974 encode_compound_hdr(&xdr
, &hdr
);
1975 return encode_setclientid(&xdr
, sc
);
1979 * a SETCLIENTID_CONFIRM request
1981 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_client
*clp
)
1983 struct xdr_stream xdr
;
1984 struct compound_hdr hdr
= {
1987 const u32 lease_bitmap
[2] = { FATTR4_WORD0_LEASE_TIME
, 0 };
1990 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1991 encode_compound_hdr(&xdr
, &hdr
);
1992 status
= encode_setclientid_confirm(&xdr
, clp
);
1994 status
= encode_putrootfh(&xdr
);
1996 status
= encode_fsinfo(&xdr
, lease_bitmap
);
2001 * DELEGRETURN request
2003 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst
*req
, __be32
*p
, const struct nfs4_delegreturnargs
*args
)
2005 struct xdr_stream xdr
;
2006 struct compound_hdr hdr
= {
2011 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2012 encode_compound_hdr(&xdr
, &hdr
);
2013 status
= encode_putfh(&xdr
, args
->fhandle
);
2016 status
= encode_delegreturn(&xdr
, args
->stateid
);
2019 status
= encode_getfattr(&xdr
, args
->bitmask
);
2025 * Encode FS_LOCATIONS request
2027 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_fs_locations_arg
*args
)
2029 struct xdr_stream xdr
;
2030 struct compound_hdr hdr
= {
2033 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
2037 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2038 encode_compound_hdr(&xdr
, &hdr
);
2039 if ((status
= encode_putfh(&xdr
, args
->dir_fh
)) != 0)
2041 if ((status
= encode_lookup(&xdr
, args
->name
)) != 0)
2043 if ((status
= encode_fs_locations(&xdr
, args
->bitmask
)) != 0)
2046 * toplevel_status + OP_PUTFH + status
2047 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2049 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ 7) << 2;
2050 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, &args
->page
,
2057 * START OF "GENERIC" DECODE ROUTINES.
2058 * These may look a little ugly since they are imported from a "generic"
2059 * set of XDR encode/decode routines which are intended to be shared by
2060 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2062 * If the pain of reading these is too great, it should be a straightforward
2063 * task to translate them into Linux-specific versions which are more
2064 * consistent with the style used in NFSv2/v3...
2066 #define READ32(x) (x) = ntohl(*p++)
2067 #define READ64(x) do { \
2068 (x) = (u64)ntohl(*p++) << 32; \
2069 (x) |= ntohl(*p++); \
2071 #define READTIME(x) do { \
2073 (x.tv_sec) = ntohl(*p++); \
2074 (x.tv_nsec) = ntohl(*p++); \
2076 #define COPYMEM(x,nbytes) do { \
2077 memcpy((x), p, nbytes); \
2078 p += XDR_QUADLEN(nbytes); \
2081 #define READ_BUF(nbytes) do { \
2082 p = xdr_inline_decode(xdr, nbytes); \
2083 if (unlikely(!p)) { \
2084 printk(KERN_INFO "%s: prematurely hit end of receive" \
2085 " buffer\n", __FUNCTION__); \
2086 printk(KERN_INFO "%s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2087 __FUNCTION__, xdr->p, nbytes, xdr->end); \
2092 static int decode_opaque_inline(struct xdr_stream
*xdr
, unsigned int *len
, char **string
)
2099 *string
= (char *)p
;
2103 static int decode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
2108 READ32(hdr
->status
);
2109 READ32(hdr
->taglen
);
2111 READ_BUF(hdr
->taglen
+ 4);
2112 hdr
->tag
= (char *)p
;
2113 p
+= XDR_QUADLEN(hdr
->taglen
);
2118 static int decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
)
2126 if (opnum
!= expected
) {
2128 "nfs4_decode_op_hdr: Server returned operation"
2129 " %d but we issued a request for %d\n",
2134 if (nfserr
!= NFS_OK
)
2135 return -nfs4_stat_to_errno(nfserr
);
2140 static int decode_ace(struct xdr_stream
*xdr
, void *ace
, struct nfs_client
*clp
)
2143 unsigned int strlen
;
2147 return decode_opaque_inline(xdr
, &strlen
, &str
);
2150 static int decode_attr_bitmap(struct xdr_stream
*xdr
, uint32_t *bitmap
)
2158 bitmap
[0] = bitmap
[1] = 0;
2159 READ_BUF((bmlen
<< 2));
2168 static inline int decode_attr_length(struct xdr_stream
*xdr
, uint32_t *attrlen
, __be32
**savep
)
2178 static int decode_attr_supported(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *bitmask
)
2180 if (likely(bitmap
[0] & FATTR4_WORD0_SUPPORTED_ATTRS
)) {
2181 decode_attr_bitmap(xdr
, bitmask
);
2182 bitmap
[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS
;
2184 bitmask
[0] = bitmask
[1] = 0;
2185 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__
, bitmask
[0], bitmask
[1]);
2189 static int decode_attr_type(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *type
)
2194 if (unlikely(bitmap
[0] & (FATTR4_WORD0_TYPE
- 1U)))
2196 if (likely(bitmap
[0] & FATTR4_WORD0_TYPE
)) {
2199 if (*type
< NF4REG
|| *type
> NF4NAMEDATTR
) {
2200 dprintk("%s: bad type %d\n", __FUNCTION__
, *type
);
2203 bitmap
[0] &= ~FATTR4_WORD0_TYPE
;
2205 dprintk("%s: type=0%o\n", __FUNCTION__
, nfs_type2fmt
[*type
].nfs2type
);
2209 static int decode_attr_change(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *change
)
2214 if (unlikely(bitmap
[0] & (FATTR4_WORD0_CHANGE
- 1U)))
2216 if (likely(bitmap
[0] & FATTR4_WORD0_CHANGE
)) {
2219 bitmap
[0] &= ~FATTR4_WORD0_CHANGE
;
2221 dprintk("%s: change attribute=%Lu\n", __FUNCTION__
,
2222 (unsigned long long)*change
);
2226 static int decode_attr_size(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *size
)
2231 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SIZE
- 1U)))
2233 if (likely(bitmap
[0] & FATTR4_WORD0_SIZE
)) {
2236 bitmap
[0] &= ~FATTR4_WORD0_SIZE
;
2238 dprintk("%s: file size=%Lu\n", __FUNCTION__
, (unsigned long long)*size
);
2242 static int decode_attr_link_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2247 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LINK_SUPPORT
- 1U)))
2249 if (likely(bitmap
[0] & FATTR4_WORD0_LINK_SUPPORT
)) {
2252 bitmap
[0] &= ~FATTR4_WORD0_LINK_SUPPORT
;
2254 dprintk("%s: link support=%s\n", __FUNCTION__
, *res
== 0 ? "false" : "true");
2258 static int decode_attr_symlink_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2263 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SYMLINK_SUPPORT
- 1U)))
2265 if (likely(bitmap
[0] & FATTR4_WORD0_SYMLINK_SUPPORT
)) {
2268 bitmap
[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT
;
2270 dprintk("%s: symlink support=%s\n", __FUNCTION__
, *res
== 0 ? "false" : "true");
2274 static int decode_attr_fsid(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fsid
*fsid
)
2280 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FSID
- 1U)))
2282 if (likely(bitmap
[0] & FATTR4_WORD0_FSID
)) {
2284 READ64(fsid
->major
);
2285 READ64(fsid
->minor
);
2286 bitmap
[0] &= ~FATTR4_WORD0_FSID
;
2288 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__
,
2289 (unsigned long long)fsid
->major
,
2290 (unsigned long long)fsid
->minor
);
2294 static int decode_attr_lease_time(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2299 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LEASE_TIME
- 1U)))
2301 if (likely(bitmap
[0] & FATTR4_WORD0_LEASE_TIME
)) {
2304 bitmap
[0] &= ~FATTR4_WORD0_LEASE_TIME
;
2306 dprintk("%s: file size=%u\n", __FUNCTION__
, (unsigned int)*res
);
2310 static int decode_attr_aclsupport(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2314 *res
= ACL4_SUPPORT_ALLOW_ACL
|ACL4_SUPPORT_DENY_ACL
;
2315 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACLSUPPORT
- 1U)))
2317 if (likely(bitmap
[0] & FATTR4_WORD0_ACLSUPPORT
)) {
2320 bitmap
[0] &= ~FATTR4_WORD0_ACLSUPPORT
;
2322 dprintk("%s: ACLs supported=%u\n", __FUNCTION__
, (unsigned int)*res
);
2326 static int decode_attr_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
2331 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEID
- 1U)))
2333 if (likely(bitmap
[0] & FATTR4_WORD0_FILEID
)) {
2336 bitmap
[0] &= ~FATTR4_WORD0_FILEID
;
2338 dprintk("%s: fileid=%Lu\n", __FUNCTION__
, (unsigned long long)*fileid
);
2342 static int decode_attr_mounted_on_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
2347 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID
- 1U)))
2349 if (likely(bitmap
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)) {
2352 bitmap
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
2354 dprintk("%s: fileid=%Lu\n", __FUNCTION__
, (unsigned long long)*fileid
);
2358 static int decode_attr_files_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2364 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_AVAIL
- 1U)))
2366 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_AVAIL
)) {
2369 bitmap
[0] &= ~FATTR4_WORD0_FILES_AVAIL
;
2371 dprintk("%s: files avail=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2375 static int decode_attr_files_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2381 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_FREE
- 1U)))
2383 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_FREE
)) {
2386 bitmap
[0] &= ~FATTR4_WORD0_FILES_FREE
;
2388 dprintk("%s: files free=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2392 static int decode_attr_files_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2398 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_TOTAL
- 1U)))
2400 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_TOTAL
)) {
2403 bitmap
[0] &= ~FATTR4_WORD0_FILES_TOTAL
;
2405 dprintk("%s: files total=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2409 static int decode_pathname(struct xdr_stream
*xdr
, struct nfs4_pathname
*path
)
2422 path
->ncomponents
= 0;
2423 while (path
->ncomponents
< n
) {
2424 struct nfs4_string
*component
= &path
->components
[path
->ncomponents
];
2425 status
= decode_opaque_inline(xdr
, &component
->len
, &component
->data
);
2426 if (unlikely(status
!= 0))
2428 if (path
->ncomponents
!= n
)
2430 dprintk("%s", component
->data
);
2431 if (path
->ncomponents
< NFS4_PATHNAME_MAXCOMPONENTS
)
2432 path
->ncomponents
++;
2434 dprintk("cannot parse %d components in path\n", n
);
2442 /* a root pathname is sent as a zero component4 */
2443 path
->ncomponents
= 1;
2444 path
->components
[0].len
=0;
2445 path
->components
[0].data
=NULL
;
2446 dprintk("path /\n");
2449 dprintk(" status %d", status
);
2454 static int decode_attr_fs_locations(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_fs_locations
*res
)
2460 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FS_LOCATIONS
-1U)))
2463 if (unlikely(!(bitmap
[0] & FATTR4_WORD0_FS_LOCATIONS
)))
2465 dprintk("%s: fsroot ", __FUNCTION__
);
2466 status
= decode_pathname(xdr
, &res
->fs_path
);
2467 if (unlikely(status
!= 0))
2473 res
->nlocations
= 0;
2474 while (res
->nlocations
< n
) {
2476 struct nfs4_fs_location
*loc
= &res
->locations
[res
->nlocations
];
2484 dprintk("%s: servers ", __FUNCTION__
);
2485 while (loc
->nservers
< m
) {
2486 struct nfs4_string
*server
= &loc
->servers
[loc
->nservers
];
2487 status
= decode_opaque_inline(xdr
, &server
->len
, &server
->data
);
2488 if (unlikely(status
!= 0))
2490 dprintk("%s ", server
->data
);
2491 if (loc
->nservers
< NFS4_FS_LOCATION_MAXSERVERS
)
2495 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__
, NFS4_FS_LOCATION_MAXSERVERS
, m
, res
->nlocations
);
2496 for (i
= loc
->nservers
; i
< m
; i
++) {
2499 status
= decode_opaque_inline(xdr
, &len
, &data
);
2500 if (unlikely(status
!= 0))
2505 status
= decode_pathname(xdr
, &loc
->rootpath
);
2506 if (unlikely(status
!= 0))
2508 if (res
->nlocations
< NFS4_FS_LOCATIONS_MAXENTRIES
)
2512 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__
, status
);
2519 static int decode_attr_maxfilesize(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2525 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXFILESIZE
- 1U)))
2527 if (likely(bitmap
[0] & FATTR4_WORD0_MAXFILESIZE
)) {
2530 bitmap
[0] &= ~FATTR4_WORD0_MAXFILESIZE
;
2532 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2536 static int decode_attr_maxlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxlink
)
2542 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXLINK
- 1U)))
2544 if (likely(bitmap
[0] & FATTR4_WORD0_MAXLINK
)) {
2547 bitmap
[0] &= ~FATTR4_WORD0_MAXLINK
;
2549 dprintk("%s: maxlink=%u\n", __FUNCTION__
, *maxlink
);
2553 static int decode_attr_maxname(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxname
)
2559 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXNAME
- 1U)))
2561 if (likely(bitmap
[0] & FATTR4_WORD0_MAXNAME
)) {
2564 bitmap
[0] &= ~FATTR4_WORD0_MAXNAME
;
2566 dprintk("%s: maxname=%u\n", __FUNCTION__
, *maxname
);
2570 static int decode_attr_maxread(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2576 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXREAD
- 1U)))
2578 if (likely(bitmap
[0] & FATTR4_WORD0_MAXREAD
)) {
2582 if (maxread
> 0x7FFFFFFF)
2583 maxread
= 0x7FFFFFFF;
2584 *res
= (uint32_t)maxread
;
2585 bitmap
[0] &= ~FATTR4_WORD0_MAXREAD
;
2587 dprintk("%s: maxread=%lu\n", __FUNCTION__
, (unsigned long)*res
);
2591 static int decode_attr_maxwrite(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2597 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXWRITE
- 1U)))
2599 if (likely(bitmap
[0] & FATTR4_WORD0_MAXWRITE
)) {
2603 if (maxwrite
> 0x7FFFFFFF)
2604 maxwrite
= 0x7FFFFFFF;
2605 *res
= (uint32_t)maxwrite
;
2606 bitmap
[0] &= ~FATTR4_WORD0_MAXWRITE
;
2608 dprintk("%s: maxwrite=%lu\n", __FUNCTION__
, (unsigned long)*res
);
2612 static int decode_attr_mode(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *mode
)
2617 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MODE
- 1U)))
2619 if (likely(bitmap
[1] & FATTR4_WORD1_MODE
)) {
2623 bitmap
[1] &= ~FATTR4_WORD1_MODE
;
2625 dprintk("%s: file mode=0%o\n", __FUNCTION__
, (unsigned int)*mode
);
2629 static int decode_attr_nlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *nlink
)
2634 if (unlikely(bitmap
[1] & (FATTR4_WORD1_NUMLINKS
- 1U)))
2636 if (likely(bitmap
[1] & FATTR4_WORD1_NUMLINKS
)) {
2639 bitmap
[1] &= ~FATTR4_WORD1_NUMLINKS
;
2641 dprintk("%s: nlink=%u\n", __FUNCTION__
, (unsigned int)*nlink
);
2645 static int decode_attr_owner(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_client
*clp
, uint32_t *uid
)
2651 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER
- 1U)))
2653 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER
)) {
2657 if (len
< XDR_MAX_NETOBJ
) {
2658 if (nfs_map_name_to_uid(clp
, (char *)p
, len
, uid
) != 0)
2659 dprintk("%s: nfs_map_name_to_uid failed!\n",
2662 printk(KERN_WARNING
"%s: name too long (%u)!\n",
2664 bitmap
[1] &= ~FATTR4_WORD1_OWNER
;
2666 dprintk("%s: uid=%d\n", __FUNCTION__
, (int)*uid
);
2670 static int decode_attr_group(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_client
*clp
, uint32_t *gid
)
2676 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER_GROUP
- 1U)))
2678 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER_GROUP
)) {
2682 if (len
< XDR_MAX_NETOBJ
) {
2683 if (nfs_map_group_to_gid(clp
, (char *)p
, len
, gid
) != 0)
2684 dprintk("%s: nfs_map_group_to_gid failed!\n",
2687 printk(KERN_WARNING
"%s: name too long (%u)!\n",
2689 bitmap
[1] &= ~FATTR4_WORD1_OWNER_GROUP
;
2691 dprintk("%s: gid=%d\n", __FUNCTION__
, (int)*gid
);
2695 static int decode_attr_rdev(struct xdr_stream
*xdr
, uint32_t *bitmap
, dev_t
*rdev
)
2697 uint32_t major
= 0, minor
= 0;
2701 if (unlikely(bitmap
[1] & (FATTR4_WORD1_RAWDEV
- 1U)))
2703 if (likely(bitmap
[1] & FATTR4_WORD1_RAWDEV
)) {
2709 tmp
= MKDEV(major
, minor
);
2710 if (MAJOR(tmp
) == major
&& MINOR(tmp
) == minor
)
2712 bitmap
[1] &= ~ FATTR4_WORD1_RAWDEV
;
2714 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__
, major
, minor
);
2718 static int decode_attr_space_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2724 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_AVAIL
- 1U)))
2726 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_AVAIL
)) {
2729 bitmap
[1] &= ~FATTR4_WORD1_SPACE_AVAIL
;
2731 dprintk("%s: space avail=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2735 static int decode_attr_space_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2741 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_FREE
- 1U)))
2743 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_FREE
)) {
2746 bitmap
[1] &= ~FATTR4_WORD1_SPACE_FREE
;
2748 dprintk("%s: space free=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2752 static int decode_attr_space_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2758 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_TOTAL
- 1U)))
2760 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_TOTAL
)) {
2763 bitmap
[1] &= ~FATTR4_WORD1_SPACE_TOTAL
;
2765 dprintk("%s: space total=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2769 static int decode_attr_space_used(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *used
)
2774 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_USED
- 1U)))
2776 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_USED
)) {
2779 bitmap
[1] &= ~FATTR4_WORD1_SPACE_USED
;
2781 dprintk("%s: space used=%Lu\n", __FUNCTION__
,
2782 (unsigned long long)*used
);
2786 static int decode_attr_time(struct xdr_stream
*xdr
, struct timespec
*time
)
2795 time
->tv_sec
= (time_t)sec
;
2796 time
->tv_nsec
= (long)nsec
;
2800 static int decode_attr_time_access(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
2806 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_ACCESS
- 1U)))
2808 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_ACCESS
)) {
2809 status
= decode_attr_time(xdr
, time
);
2810 bitmap
[1] &= ~FATTR4_WORD1_TIME_ACCESS
;
2812 dprintk("%s: atime=%ld\n", __FUNCTION__
, (long)time
->tv_sec
);
2816 static int decode_attr_time_metadata(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
2822 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_METADATA
- 1U)))
2824 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_METADATA
)) {
2825 status
= decode_attr_time(xdr
, time
);
2826 bitmap
[1] &= ~FATTR4_WORD1_TIME_METADATA
;
2828 dprintk("%s: ctime=%ld\n", __FUNCTION__
, (long)time
->tv_sec
);
2832 static int decode_attr_time_modify(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
2838 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_MODIFY
- 1U)))
2840 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_MODIFY
)) {
2841 status
= decode_attr_time(xdr
, time
);
2842 bitmap
[1] &= ~FATTR4_WORD1_TIME_MODIFY
;
2844 dprintk("%s: mtime=%ld\n", __FUNCTION__
, (long)time
->tv_sec
);
2848 static int verify_attr_len(struct xdr_stream
*xdr
, __be32
*savep
, uint32_t attrlen
)
2850 unsigned int attrwords
= XDR_QUADLEN(attrlen
);
2851 unsigned int nwords
= xdr
->p
- savep
;
2853 if (unlikely(attrwords
!= nwords
)) {
2854 printk(KERN_WARNING
"%s: server returned incorrect attribute length: %u %c %u\n",
2857 (attrwords
< nwords
) ? '<' : '>',
2864 static int decode_change_info(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
2869 READ32(cinfo
->atomic
);
2870 READ64(cinfo
->before
);
2871 READ64(cinfo
->after
);
2875 static int decode_access(struct xdr_stream
*xdr
, struct nfs4_accessres
*access
)
2881 status
= decode_op_hdr(xdr
, OP_ACCESS
);
2887 access
->supported
= supp
;
2888 access
->access
= acc
;
2892 static int decode_close(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
2897 status
= decode_op_hdr(xdr
, OP_CLOSE
);
2900 READ_BUF(NFS4_STATEID_SIZE
);
2901 COPYMEM(res
->stateid
.data
, NFS4_STATEID_SIZE
);
2905 static int decode_commit(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
2910 status
= decode_op_hdr(xdr
, OP_COMMIT
);
2914 COPYMEM(res
->verf
->verifier
, 8);
2918 static int decode_create(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
2924 status
= decode_op_hdr(xdr
, OP_CREATE
);
2927 if ((status
= decode_change_info(xdr
, cinfo
)))
2931 READ_BUF(bmlen
<< 2);
2935 static int decode_server_caps(struct xdr_stream
*xdr
, struct nfs4_server_caps_res
*res
)
2942 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
2944 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
2946 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
2948 if ((status
= decode_attr_supported(xdr
, bitmap
, res
->attr_bitmask
)) != 0)
2950 if ((status
= decode_attr_link_support(xdr
, bitmap
, &res
->has_links
)) != 0)
2952 if ((status
= decode_attr_symlink_support(xdr
, bitmap
, &res
->has_symlinks
)) != 0)
2954 if ((status
= decode_attr_aclsupport(xdr
, bitmap
, &res
->acl_bitmask
)) != 0)
2956 status
= verify_attr_len(xdr
, savep
, attrlen
);
2958 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
2962 static int decode_statfs(struct xdr_stream
*xdr
, struct nfs_fsstat
*fsstat
)
2969 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
2971 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
2973 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
2976 if ((status
= decode_attr_files_avail(xdr
, bitmap
, &fsstat
->afiles
)) != 0)
2978 if ((status
= decode_attr_files_free(xdr
, bitmap
, &fsstat
->ffiles
)) != 0)
2980 if ((status
= decode_attr_files_total(xdr
, bitmap
, &fsstat
->tfiles
)) != 0)
2982 if ((status
= decode_attr_space_avail(xdr
, bitmap
, &fsstat
->abytes
)) != 0)
2984 if ((status
= decode_attr_space_free(xdr
, bitmap
, &fsstat
->fbytes
)) != 0)
2986 if ((status
= decode_attr_space_total(xdr
, bitmap
, &fsstat
->tbytes
)) != 0)
2989 status
= verify_attr_len(xdr
, savep
, attrlen
);
2991 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
2995 static int decode_pathconf(struct xdr_stream
*xdr
, struct nfs_pathconf
*pathconf
)
3002 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3004 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3006 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3009 if ((status
= decode_attr_maxlink(xdr
, bitmap
, &pathconf
->max_link
)) != 0)
3011 if ((status
= decode_attr_maxname(xdr
, bitmap
, &pathconf
->max_namelen
)) != 0)
3014 status
= verify_attr_len(xdr
, savep
, attrlen
);
3016 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
3020 static int decode_getfattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
, const struct nfs_server
*server
)
3026 int status
, fmode
= 0;
3029 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3031 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3034 fattr
->bitmap
[0] = bitmap
[0];
3035 fattr
->bitmap
[1] = bitmap
[1];
3037 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3041 if ((status
= decode_attr_type(xdr
, bitmap
, &type
)) != 0)
3043 fattr
->type
= nfs_type2fmt
[type
].nfs2type
;
3044 fmode
= nfs_type2fmt
[type
].mode
;
3046 if ((status
= decode_attr_change(xdr
, bitmap
, &fattr
->change_attr
)) != 0)
3048 if ((status
= decode_attr_size(xdr
, bitmap
, &fattr
->size
)) != 0)
3050 if ((status
= decode_attr_fsid(xdr
, bitmap
, &fattr
->fsid
)) != 0)
3052 if ((status
= decode_attr_fileid(xdr
, bitmap
, &fattr
->fileid
)) != 0)
3054 if ((status
= decode_attr_fs_locations(xdr
, bitmap
, container_of(fattr
,
3055 struct nfs4_fs_locations
,
3058 if ((status
= decode_attr_mode(xdr
, bitmap
, &fattr
->mode
)) != 0)
3060 fattr
->mode
|= fmode
;
3061 if ((status
= decode_attr_nlink(xdr
, bitmap
, &fattr
->nlink
)) != 0)
3063 if ((status
= decode_attr_owner(xdr
, bitmap
, server
->nfs_client
, &fattr
->uid
)) != 0)
3065 if ((status
= decode_attr_group(xdr
, bitmap
, server
->nfs_client
, &fattr
->gid
)) != 0)
3067 if ((status
= decode_attr_rdev(xdr
, bitmap
, &fattr
->rdev
)) != 0)
3069 if ((status
= decode_attr_space_used(xdr
, bitmap
, &fattr
->du
.nfs3
.used
)) != 0)
3071 if ((status
= decode_attr_time_access(xdr
, bitmap
, &fattr
->atime
)) != 0)
3073 if ((status
= decode_attr_time_metadata(xdr
, bitmap
, &fattr
->ctime
)) != 0)
3075 if ((status
= decode_attr_time_modify(xdr
, bitmap
, &fattr
->mtime
)) != 0)
3077 if ((status
= decode_attr_mounted_on_fileid(xdr
, bitmap
, &fileid
)) != 0)
3079 if (fattr
->fileid
== 0 && fileid
!= 0)
3080 fattr
->fileid
= fileid
;
3081 if ((status
= verify_attr_len(xdr
, savep
, attrlen
)) == 0)
3082 fattr
->valid
= NFS_ATTR_FATTR
| NFS_ATTR_FATTR_V3
| NFS_ATTR_FATTR_V4
;
3084 dprintk("%s: xdr returned %d\n", __FUNCTION__
, -status
);
3089 static int decode_fsinfo(struct xdr_stream
*xdr
, struct nfs_fsinfo
*fsinfo
)
3092 uint32_t attrlen
, bitmap
[2];
3095 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3097 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3099 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3102 fsinfo
->rtmult
= fsinfo
->wtmult
= 512; /* ??? */
3104 if ((status
= decode_attr_lease_time(xdr
, bitmap
, &fsinfo
->lease_time
)) != 0)
3106 if ((status
= decode_attr_maxfilesize(xdr
, bitmap
, &fsinfo
->maxfilesize
)) != 0)
3108 if ((status
= decode_attr_maxread(xdr
, bitmap
, &fsinfo
->rtmax
)) != 0)
3110 fsinfo
->rtpref
= fsinfo
->dtpref
= fsinfo
->rtmax
;
3111 if ((status
= decode_attr_maxwrite(xdr
, bitmap
, &fsinfo
->wtmax
)) != 0)
3113 fsinfo
->wtpref
= fsinfo
->wtmax
;
3115 status
= verify_attr_len(xdr
, savep
, attrlen
);
3117 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
3121 static int decode_getfh(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
3127 status
= decode_op_hdr(xdr
, OP_GETFH
);
3130 /* Zero handle first to allow comparisons */
3131 memset(fh
, 0, sizeof(*fh
));
3135 if (len
> NFS4_FHSIZE
)
3139 COPYMEM(fh
->data
, len
);
3143 static int decode_link(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3147 status
= decode_op_hdr(xdr
, OP_LINK
);
3150 return decode_change_info(xdr
, cinfo
);
3154 * We create the owner, so we know a proper owner.id length is 4.
3156 static int decode_lock_denied (struct xdr_stream
*xdr
, struct file_lock
*fl
)
3158 uint64_t offset
, length
, clientid
;
3160 uint32_t namelen
, type
;
3167 fl
->fl_start
= (loff_t
)offset
;
3168 fl
->fl_end
= fl
->fl_start
+ (loff_t
)length
- 1;
3169 if (length
== ~(uint64_t)0)
3170 fl
->fl_end
= OFFSET_MAX
;
3171 fl
->fl_type
= F_WRLCK
;
3173 fl
->fl_type
= F_RDLCK
;
3179 return -NFS4ERR_DENIED
;
3182 static int decode_lock(struct xdr_stream
*xdr
, struct nfs_lock_res
*res
)
3187 status
= decode_op_hdr(xdr
, OP_LOCK
);
3189 READ_BUF(NFS4_STATEID_SIZE
);
3190 COPYMEM(res
->stateid
.data
, NFS4_STATEID_SIZE
);
3191 } else if (status
== -NFS4ERR_DENIED
)
3192 return decode_lock_denied(xdr
, NULL
);
3196 static int decode_lockt(struct xdr_stream
*xdr
, struct nfs_lockt_res
*res
)
3199 status
= decode_op_hdr(xdr
, OP_LOCKT
);
3200 if (status
== -NFS4ERR_DENIED
)
3201 return decode_lock_denied(xdr
, res
->denied
);
3205 static int decode_locku(struct xdr_stream
*xdr
, struct nfs_locku_res
*res
)
3210 status
= decode_op_hdr(xdr
, OP_LOCKU
);
3212 READ_BUF(NFS4_STATEID_SIZE
);
3213 COPYMEM(res
->stateid
.data
, NFS4_STATEID_SIZE
);
3218 static int decode_lookup(struct xdr_stream
*xdr
)
3220 return decode_op_hdr(xdr
, OP_LOOKUP
);
3223 /* This is too sick! */
3224 static int decode_space_limit(struct xdr_stream
*xdr
, u64
*maxsize
)
3227 uint32_t limit_type
, nblocks
, blocksize
;
3231 switch (limit_type
) {
3238 *maxsize
= (uint64_t)nblocks
* (uint64_t)blocksize
;
3243 static int decode_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
3246 uint32_t delegation_type
;
3249 READ32(delegation_type
);
3250 if (delegation_type
== NFS4_OPEN_DELEGATE_NONE
) {
3251 res
->delegation_type
= 0;
3254 READ_BUF(NFS4_STATEID_SIZE
+4);
3255 COPYMEM(res
->delegation
.data
, NFS4_STATEID_SIZE
);
3256 READ32(res
->do_recall
);
3257 switch (delegation_type
) {
3258 case NFS4_OPEN_DELEGATE_READ
:
3259 res
->delegation_type
= FMODE_READ
;
3261 case NFS4_OPEN_DELEGATE_WRITE
:
3262 res
->delegation_type
= FMODE_WRITE
|FMODE_READ
;
3263 if (decode_space_limit(xdr
, &res
->maxsize
) < 0)
3266 return decode_ace(xdr
, NULL
, res
->server
->nfs_client
);
3269 static int decode_open(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
3272 uint32_t savewords
, bmlen
, i
;
3275 status
= decode_op_hdr(xdr
, OP_OPEN
);
3278 READ_BUF(NFS4_STATEID_SIZE
);
3279 COPYMEM(res
->stateid
.data
, NFS4_STATEID_SIZE
);
3281 decode_change_info(xdr
, &res
->cinfo
);
3284 READ32(res
->rflags
);
3289 READ_BUF(bmlen
<< 2);
3290 savewords
= min_t(uint32_t, bmlen
, NFS4_BITMAP_SIZE
);
3291 for (i
= 0; i
< savewords
; ++i
)
3292 READ32(res
->attrset
[i
]);
3293 for (; i
< NFS4_BITMAP_SIZE
; i
++)
3294 res
->attrset
[i
] = 0;
3296 return decode_delegation(xdr
, res
);
3298 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__
, bmlen
);
3302 static int decode_open_confirm(struct xdr_stream
*xdr
, struct nfs_open_confirmres
*res
)
3307 status
= decode_op_hdr(xdr
, OP_OPEN_CONFIRM
);
3310 READ_BUF(NFS4_STATEID_SIZE
);
3311 COPYMEM(res
->stateid
.data
, NFS4_STATEID_SIZE
);
3315 static int decode_open_downgrade(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
3320 status
= decode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
);
3323 READ_BUF(NFS4_STATEID_SIZE
);
3324 COPYMEM(res
->stateid
.data
, NFS4_STATEID_SIZE
);
3328 static int decode_putfh(struct xdr_stream
*xdr
)
3330 return decode_op_hdr(xdr
, OP_PUTFH
);
3333 static int decode_putrootfh(struct xdr_stream
*xdr
)
3335 return decode_op_hdr(xdr
, OP_PUTROOTFH
);
3338 static int decode_read(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs_readres
*res
)
3340 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
3342 uint32_t count
, eof
, recvd
, hdrlen
;
3345 status
= decode_op_hdr(xdr
, OP_READ
);
3351 hdrlen
= (u8
*) p
- (u8
*) iov
->iov_base
;
3352 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
3353 if (count
> recvd
) {
3354 printk(KERN_WARNING
"NFS: server cheating in read reply: "
3355 "count %u > recvd %u\n", count
, recvd
);
3359 xdr_read_pages(xdr
, count
);
3365 static int decode_readdir(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs4_readdir_res
*readdir
)
3367 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
3368 struct page
*page
= *rcvbuf
->pages
;
3369 struct kvec
*iov
= rcvbuf
->head
;
3370 unsigned int nr
, pglen
= rcvbuf
->page_len
;
3371 __be32
*end
, *entry
, *p
, *kaddr
;
3372 uint32_t len
, attrlen
, xlen
;
3373 int hdrlen
, recvd
, status
;
3375 status
= decode_op_hdr(xdr
, OP_READDIR
);
3379 COPYMEM(readdir
->verifier
.data
, 8);
3380 dprintk("%s: verifier = 0x%x%x\n",
3382 ((u32
*)readdir
->verifier
.data
)[0],
3383 ((u32
*)readdir
->verifier
.data
)[1]);
3386 hdrlen
= (char *) p
- (char *) iov
->iov_base
;
3387 recvd
= rcvbuf
->len
- hdrlen
;
3390 xdr_read_pages(xdr
, pglen
);
3392 BUG_ON(pglen
+ readdir
->pgbase
> PAGE_CACHE_SIZE
);
3393 kaddr
= p
= kmap_atomic(page
, KM_USER0
);
3394 end
= p
+ ((pglen
+ readdir
->pgbase
) >> 2);
3396 for (nr
= 0; *p
++; nr
++) {
3399 dprintk("cookie = %Lu, ", *((unsigned long long *)p
));
3400 p
+= 2; /* cookie */
3401 len
= ntohl(*p
++); /* filename length */
3402 if (len
> NFS4_MAXNAMLEN
) {
3403 printk(KERN_WARNING
"NFS: giant filename in readdir (len 0x%x)\n", len
);
3406 xlen
= XDR_QUADLEN(len
);
3407 if (end
- p
< xlen
+ 1)
3409 dprintk("filename = %*s\n", len
, (char *)p
);
3411 len
= ntohl(*p
++); /* bitmap length */
3412 if (end
- p
< len
+ 1)
3415 attrlen
= XDR_QUADLEN(ntohl(*p
++));
3416 if (end
- p
< attrlen
+ 2)
3418 p
+= attrlen
; /* attributes */
3421 if (!nr
&& (entry
[0] != 0 || entry
[1] == 0))
3424 kunmap_atomic(kaddr
, KM_USER0
);
3427 dprintk("%s: short packet at entry %d\n", __FUNCTION__
, nr
);
3428 entry
[0] = entry
[1] = 0;
3429 /* truncate listing ? */
3431 printk(KERN_NOTICE
"NFS: readdir reply truncated!\n");
3436 kunmap_atomic(kaddr
, KM_USER0
);
3437 return -errno_NFSERR_IO
;
3440 static int decode_readlink(struct xdr_stream
*xdr
, struct rpc_rqst
*req
)
3442 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
3443 struct kvec
*iov
= rcvbuf
->head
;
3444 int hdrlen
, len
, recvd
;
3449 status
= decode_op_hdr(xdr
, OP_READLINK
);
3453 /* Convert length of symlink */
3456 if (len
>= rcvbuf
->page_len
|| len
<= 0) {
3457 dprintk(KERN_WARNING
"nfs: server returned giant symlink!\n");
3458 return -ENAMETOOLONG
;
3460 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
3461 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
3463 printk(KERN_WARNING
"NFS: server cheating in readlink reply: "
3464 "count %u > recvd %u\n", len
, recvd
);
3467 xdr_read_pages(xdr
, len
);
3469 * The XDR encode routine has set things up so that
3470 * the link text will be copied directly into the
3471 * buffer. We just have to do overflow-checking,
3472 * and and null-terminate the text (the VFS expects
3473 * null-termination).
3475 kaddr
= (char *)kmap_atomic(rcvbuf
->pages
[0], KM_USER0
);
3476 kaddr
[len
+rcvbuf
->page_base
] = '\0';
3477 kunmap_atomic(kaddr
, KM_USER0
);
3481 static int decode_remove(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3485 status
= decode_op_hdr(xdr
, OP_REMOVE
);
3488 status
= decode_change_info(xdr
, cinfo
);
3493 static int decode_rename(struct xdr_stream
*xdr
, struct nfs4_change_info
*old_cinfo
,
3494 struct nfs4_change_info
*new_cinfo
)
3498 status
= decode_op_hdr(xdr
, OP_RENAME
);
3501 if ((status
= decode_change_info(xdr
, old_cinfo
)))
3503 status
= decode_change_info(xdr
, new_cinfo
);
3508 static int decode_renew(struct xdr_stream
*xdr
)
3510 return decode_op_hdr(xdr
, OP_RENEW
);
3514 decode_restorefh(struct xdr_stream
*xdr
)
3516 return decode_op_hdr(xdr
, OP_RESTOREFH
);
3519 static int decode_getacl(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
3525 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
3529 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3531 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3533 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3536 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACL
- 1U)))
3538 if (likely(bitmap
[0] & FATTR4_WORD0_ACL
)) {
3541 /* We ignore &savep and don't do consistency checks on
3542 * the attr length. Let userspace figure it out.... */
3543 hdrlen
= (u8
*)xdr
->p
- (u8
*)iov
->iov_base
;
3544 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
3545 if (attrlen
> recvd
) {
3546 printk(KERN_WARNING
"NFS: server cheating in getattr"
3547 " acl reply: attrlen %u > recvd %u\n",
3551 xdr_read_pages(xdr
, attrlen
);
3554 status
= -EOPNOTSUPP
;
3561 decode_savefh(struct xdr_stream
*xdr
)
3563 return decode_op_hdr(xdr
, OP_SAVEFH
);
3566 static int decode_setattr(struct xdr_stream
*xdr
, struct nfs_setattrres
*res
)
3573 status
= decode_op_hdr(xdr
, OP_SETATTR
);
3578 READ_BUF(bmlen
<< 2);
3582 static int decode_setclientid(struct xdr_stream
*xdr
, struct nfs_client
*clp
)
3590 if (opnum
!= OP_SETCLIENTID
) {
3592 "nfs4_decode_setclientid: Server returned operation"
3597 if (nfserr
== NFS_OK
) {
3598 READ_BUF(8 + NFS4_VERIFIER_SIZE
);
3599 READ64(clp
->cl_clientid
);
3600 COPYMEM(clp
->cl_confirm
.data
, NFS4_VERIFIER_SIZE
);
3601 } else if (nfserr
== NFSERR_CLID_INUSE
) {
3604 /* skip netid string */
3609 /* skip uaddr string */
3613 return -NFSERR_CLID_INUSE
;
3615 return -nfs4_stat_to_errno(nfserr
);
3620 static int decode_setclientid_confirm(struct xdr_stream
*xdr
)
3622 return decode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
);
3625 static int decode_write(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
3630 status
= decode_op_hdr(xdr
, OP_WRITE
);
3636 READ32(res
->verf
->committed
);
3637 COPYMEM(res
->verf
->verifier
, 8);
3641 static int decode_delegreturn(struct xdr_stream
*xdr
)
3643 return decode_op_hdr(xdr
, OP_DELEGRETURN
);
3647 * Decode OPEN_DOWNGRADE response
3649 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_closeres
*res
)
3651 struct xdr_stream xdr
;
3652 struct compound_hdr hdr
;
3655 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3656 status
= decode_compound_hdr(&xdr
, &hdr
);
3659 status
= decode_putfh(&xdr
);
3662 status
= decode_open_downgrade(&xdr
, res
);
3665 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3671 * END OF "GENERIC" DECODE ROUTINES.
3675 * Decode ACCESS response
3677 static int nfs4_xdr_dec_access(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_accessres
*res
)
3679 struct xdr_stream xdr
;
3680 struct compound_hdr hdr
;
3683 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3684 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3686 if ((status
= decode_putfh(&xdr
)) == 0)
3687 status
= decode_access(&xdr
, res
);
3693 * Decode LOOKUP response
3695 static int nfs4_xdr_dec_lookup(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_lookup_res
*res
)
3697 struct xdr_stream xdr
;
3698 struct compound_hdr hdr
;
3701 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3702 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3704 if ((status
= decode_putfh(&xdr
)) != 0)
3706 if ((status
= decode_lookup(&xdr
)) != 0)
3708 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
3710 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3716 * Decode LOOKUP_ROOT response
3718 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_lookup_res
*res
)
3720 struct xdr_stream xdr
;
3721 struct compound_hdr hdr
;
3724 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3725 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3727 if ((status
= decode_putrootfh(&xdr
)) != 0)
3729 if ((status
= decode_getfh(&xdr
, res
->fh
)) == 0)
3730 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3736 * Decode REMOVE response
3738 static int nfs4_xdr_dec_remove(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_remove_res
*res
)
3740 struct xdr_stream xdr
;
3741 struct compound_hdr hdr
;
3744 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3745 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3747 if ((status
= decode_putfh(&xdr
)) != 0)
3749 if ((status
= decode_remove(&xdr
, &res
->cinfo
)) != 0)
3751 decode_getfattr(&xdr
, res
->dir_attr
, res
->server
);
3757 * Decode RENAME response
3759 static int nfs4_xdr_dec_rename(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_rename_res
*res
)
3761 struct xdr_stream xdr
;
3762 struct compound_hdr hdr
;
3765 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3766 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3768 if ((status
= decode_putfh(&xdr
)) != 0)
3770 if ((status
= decode_savefh(&xdr
)) != 0)
3772 if ((status
= decode_putfh(&xdr
)) != 0)
3774 if ((status
= decode_rename(&xdr
, &res
->old_cinfo
, &res
->new_cinfo
)) != 0)
3776 /* Current FH is target directory */
3777 if (decode_getfattr(&xdr
, res
->new_fattr
, res
->server
) != 0)
3779 if ((status
= decode_restorefh(&xdr
)) != 0)
3781 decode_getfattr(&xdr
, res
->old_fattr
, res
->server
);
3787 * Decode LINK response
3789 static int nfs4_xdr_dec_link(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_link_res
*res
)
3791 struct xdr_stream xdr
;
3792 struct compound_hdr hdr
;
3795 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3796 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3798 if ((status
= decode_putfh(&xdr
)) != 0)
3800 if ((status
= decode_savefh(&xdr
)) != 0)
3802 if ((status
= decode_putfh(&xdr
)) != 0)
3804 if ((status
= decode_link(&xdr
, &res
->cinfo
)) != 0)
3807 * Note order: OP_LINK leaves the directory as the current
3810 if (decode_getfattr(&xdr
, res
->dir_attr
, res
->server
) != 0)
3812 if ((status
= decode_restorefh(&xdr
)) != 0)
3814 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3820 * Decode CREATE response
3822 static int nfs4_xdr_dec_create(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_create_res
*res
)
3824 struct xdr_stream xdr
;
3825 struct compound_hdr hdr
;
3828 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3829 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3831 if ((status
= decode_putfh(&xdr
)) != 0)
3833 if ((status
= decode_savefh(&xdr
)) != 0)
3835 if ((status
= decode_create(&xdr
,&res
->dir_cinfo
)) != 0)
3837 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
3839 if (decode_getfattr(&xdr
, res
->fattr
, res
->server
) != 0)
3841 if ((status
= decode_restorefh(&xdr
)) != 0)
3843 decode_getfattr(&xdr
, res
->dir_fattr
, res
->server
);
3849 * Decode SYMLINK response
3851 static int nfs4_xdr_dec_symlink(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_create_res
*res
)
3853 return nfs4_xdr_dec_create(rqstp
, p
, res
);
3857 * Decode GETATTR response
3859 static int nfs4_xdr_dec_getattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_getattr_res
*res
)
3861 struct xdr_stream xdr
;
3862 struct compound_hdr hdr
;
3865 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3866 status
= decode_compound_hdr(&xdr
, &hdr
);
3869 status
= decode_putfh(&xdr
);
3872 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3879 * Encode an SETACL request
3882 nfs4_xdr_enc_setacl(struct rpc_rqst
*req
, __be32
*p
, struct nfs_setaclargs
*args
)
3884 struct xdr_stream xdr
;
3885 struct compound_hdr hdr
= {
3890 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
3891 encode_compound_hdr(&xdr
, &hdr
);
3892 status
= encode_putfh(&xdr
, args
->fh
);
3895 status
= encode_setacl(&xdr
, args
);
3900 * Decode SETACL response
3903 nfs4_xdr_dec_setacl(struct rpc_rqst
*rqstp
, __be32
*p
, void *res
)
3905 struct xdr_stream xdr
;
3906 struct compound_hdr hdr
;
3909 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3910 status
= decode_compound_hdr(&xdr
, &hdr
);
3913 status
= decode_putfh(&xdr
);
3916 status
= decode_setattr(&xdr
, res
);
3922 * Decode GETACL response
3925 nfs4_xdr_dec_getacl(struct rpc_rqst
*rqstp
, __be32
*p
, size_t *acl_len
)
3927 struct xdr_stream xdr
;
3928 struct compound_hdr hdr
;
3931 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3932 status
= decode_compound_hdr(&xdr
, &hdr
);
3935 status
= decode_putfh(&xdr
);
3938 status
= decode_getacl(&xdr
, rqstp
, acl_len
);
3945 * Decode CLOSE response
3947 static int nfs4_xdr_dec_close(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_closeres
*res
)
3949 struct xdr_stream xdr
;
3950 struct compound_hdr hdr
;
3953 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3954 status
= decode_compound_hdr(&xdr
, &hdr
);
3957 status
= decode_putfh(&xdr
);
3960 status
= decode_close(&xdr
, res
);
3964 * Note: Server may do delete on close for this file
3965 * in which case the getattr call will fail with
3966 * an ESTALE error. Shouldn't be a problem,
3967 * though, since fattr->valid will remain unset.
3969 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3975 * Decode OPEN response
3977 static int nfs4_xdr_dec_open(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_openres
*res
)
3979 struct xdr_stream xdr
;
3980 struct compound_hdr hdr
;
3983 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3984 status
= decode_compound_hdr(&xdr
, &hdr
);
3987 status
= decode_putfh(&xdr
);
3990 status
= decode_savefh(&xdr
);
3993 status
= decode_open(&xdr
, res
);
3996 status
= decode_getfh(&xdr
, &res
->fh
);
3999 if (decode_getfattr(&xdr
, res
->f_attr
, res
->server
) != 0)
4001 if ((status
= decode_restorefh(&xdr
)) != 0)
4003 decode_getfattr(&xdr
, res
->dir_attr
, res
->server
);
4009 * Decode OPEN_CONFIRM response
4011 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_open_confirmres
*res
)
4013 struct xdr_stream xdr
;
4014 struct compound_hdr hdr
;
4017 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4018 status
= decode_compound_hdr(&xdr
, &hdr
);
4021 status
= decode_putfh(&xdr
);
4024 status
= decode_open_confirm(&xdr
, res
);
4030 * Decode OPEN response
4032 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_openres
*res
)
4034 struct xdr_stream xdr
;
4035 struct compound_hdr hdr
;
4038 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4039 status
= decode_compound_hdr(&xdr
, &hdr
);
4042 status
= decode_putfh(&xdr
);
4045 status
= decode_open(&xdr
, res
);
4048 decode_getfattr(&xdr
, res
->f_attr
, res
->server
);
4054 * Decode SETATTR response
4056 static int nfs4_xdr_dec_setattr(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_setattrres
*res
)
4058 struct xdr_stream xdr
;
4059 struct compound_hdr hdr
;
4062 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4063 status
= decode_compound_hdr(&xdr
, &hdr
);
4066 status
= decode_putfh(&xdr
);
4069 status
= decode_setattr(&xdr
, res
);
4072 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4073 if (status
== NFS4ERR_DELAY
)
4080 * Decode LOCK response
4082 static int nfs4_xdr_dec_lock(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_lock_res
*res
)
4084 struct xdr_stream xdr
;
4085 struct compound_hdr hdr
;
4088 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4089 status
= decode_compound_hdr(&xdr
, &hdr
);
4092 status
= decode_putfh(&xdr
);
4095 status
= decode_lock(&xdr
, res
);
4101 * Decode LOCKT response
4103 static int nfs4_xdr_dec_lockt(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_lockt_res
*res
)
4105 struct xdr_stream xdr
;
4106 struct compound_hdr hdr
;
4109 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4110 status
= decode_compound_hdr(&xdr
, &hdr
);
4113 status
= decode_putfh(&xdr
);
4116 status
= decode_lockt(&xdr
, res
);
4122 * Decode LOCKU response
4124 static int nfs4_xdr_dec_locku(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_locku_res
*res
)
4126 struct xdr_stream xdr
;
4127 struct compound_hdr hdr
;
4130 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4131 status
= decode_compound_hdr(&xdr
, &hdr
);
4134 status
= decode_putfh(&xdr
);
4137 status
= decode_locku(&xdr
, res
);
4143 * Decode READLINK response
4145 static int nfs4_xdr_dec_readlink(struct rpc_rqst
*rqstp
, __be32
*p
, void *res
)
4147 struct xdr_stream xdr
;
4148 struct compound_hdr hdr
;
4151 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4152 status
= decode_compound_hdr(&xdr
, &hdr
);
4155 status
= decode_putfh(&xdr
);
4158 status
= decode_readlink(&xdr
, rqstp
);
4164 * Decode READDIR response
4166 static int nfs4_xdr_dec_readdir(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_readdir_res
*res
)
4168 struct xdr_stream xdr
;
4169 struct compound_hdr hdr
;
4172 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4173 status
= decode_compound_hdr(&xdr
, &hdr
);
4176 status
= decode_putfh(&xdr
);
4179 status
= decode_readdir(&xdr
, rqstp
, res
);
4185 * Decode Read response
4187 static int nfs4_xdr_dec_read(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_readres
*res
)
4189 struct xdr_stream xdr
;
4190 struct compound_hdr hdr
;
4193 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4194 status
= decode_compound_hdr(&xdr
, &hdr
);
4197 status
= decode_putfh(&xdr
);
4200 status
= decode_read(&xdr
, rqstp
, res
);
4202 status
= res
->count
;
4208 * Decode WRITE response
4210 static int nfs4_xdr_dec_write(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_writeres
*res
)
4212 struct xdr_stream xdr
;
4213 struct compound_hdr hdr
;
4216 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4217 status
= decode_compound_hdr(&xdr
, &hdr
);
4220 status
= decode_putfh(&xdr
);
4223 status
= decode_write(&xdr
, res
);
4226 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4228 status
= res
->count
;
4234 * Decode COMMIT response
4236 static int nfs4_xdr_dec_commit(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs_writeres
*res
)
4238 struct xdr_stream xdr
;
4239 struct compound_hdr hdr
;
4242 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4243 status
= decode_compound_hdr(&xdr
, &hdr
);
4246 status
= decode_putfh(&xdr
);
4249 status
= decode_commit(&xdr
, res
);
4252 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4260 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fsinfo
*fsinfo
)
4262 struct xdr_stream xdr
;
4263 struct compound_hdr hdr
;
4266 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4267 status
= decode_compound_hdr(&xdr
, &hdr
);
4269 status
= decode_putfh(&xdr
);
4271 status
= decode_fsinfo(&xdr
, fsinfo
);
4273 status
= -nfs4_stat_to_errno(hdr
.status
);
4280 static int nfs4_xdr_dec_pathconf(struct rpc_rqst
*req
, __be32
*p
, struct nfs_pathconf
*pathconf
)
4282 struct xdr_stream xdr
;
4283 struct compound_hdr hdr
;
4286 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4287 status
= decode_compound_hdr(&xdr
, &hdr
);
4289 status
= decode_putfh(&xdr
);
4291 status
= decode_pathconf(&xdr
, pathconf
);
4298 static int nfs4_xdr_dec_statfs(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fsstat
*fsstat
)
4300 struct xdr_stream xdr
;
4301 struct compound_hdr hdr
;
4304 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4305 status
= decode_compound_hdr(&xdr
, &hdr
);
4307 status
= decode_putfh(&xdr
);
4309 status
= decode_statfs(&xdr
, fsstat
);
4314 * GETATTR_BITMAP request
4316 static int nfs4_xdr_dec_server_caps(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_server_caps_res
*res
)
4318 struct xdr_stream xdr
;
4319 struct compound_hdr hdr
;
4322 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4323 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
4325 if ((status
= decode_putfh(&xdr
)) != 0)
4327 status
= decode_server_caps(&xdr
, res
);
4333 * Decode RENEW response
4335 static int nfs4_xdr_dec_renew(struct rpc_rqst
*rqstp
, __be32
*p
, void *dummy
)
4337 struct xdr_stream xdr
;
4338 struct compound_hdr hdr
;
4341 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4342 status
= decode_compound_hdr(&xdr
, &hdr
);
4344 status
= decode_renew(&xdr
);
4349 * a SETCLIENTID request
4351 static int nfs4_xdr_dec_setclientid(struct rpc_rqst
*req
, __be32
*p
,
4352 struct nfs_client
*clp
)
4354 struct xdr_stream xdr
;
4355 struct compound_hdr hdr
;
4358 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4359 status
= decode_compound_hdr(&xdr
, &hdr
);
4361 status
= decode_setclientid(&xdr
, clp
);
4363 status
= -nfs4_stat_to_errno(hdr
.status
);
4368 * a SETCLIENTID_CONFIRM request
4370 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst
*req
, __be32
*p
, struct nfs_fsinfo
*fsinfo
)
4372 struct xdr_stream xdr
;
4373 struct compound_hdr hdr
;
4376 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4377 status
= decode_compound_hdr(&xdr
, &hdr
);
4379 status
= decode_setclientid_confirm(&xdr
);
4381 status
= decode_putrootfh(&xdr
);
4383 status
= decode_fsinfo(&xdr
, fsinfo
);
4385 status
= -nfs4_stat_to_errno(hdr
.status
);
4390 * DELEGRETURN request
4392 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst
*rqstp
, __be32
*p
, struct nfs4_delegreturnres
*res
)
4394 struct xdr_stream xdr
;
4395 struct compound_hdr hdr
;
4398 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4399 status
= decode_compound_hdr(&xdr
, &hdr
);
4402 status
= decode_putfh(&xdr
);
4405 status
= decode_delegreturn(&xdr
);
4406 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4412 * FS_LOCATIONS request
4414 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst
*req
, __be32
*p
, struct nfs4_fs_locations
*res
)
4416 struct xdr_stream xdr
;
4417 struct compound_hdr hdr
;
4420 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4421 status
= decode_compound_hdr(&xdr
, &hdr
);
4424 if ((status
= decode_putfh(&xdr
)) != 0)
4426 if ((status
= decode_lookup(&xdr
)) != 0)
4428 xdr_enter_page(&xdr
, PAGE_SIZE
);
4429 status
= decode_getfattr(&xdr
, &res
->fattr
, res
->server
);
4434 __be32
*nfs4_decode_dirent(__be32
*p
, struct nfs_entry
*entry
, int plus
)
4436 uint32_t bitmap
[2] = {0};
4441 return ERR_PTR(-EAGAIN
);
4443 return ERR_PTR(-EBADCOOKIE
);
4446 entry
->prev_cookie
= entry
->cookie
;
4447 p
= xdr_decode_hyper(p
, &entry
->cookie
);
4448 entry
->len
= ntohl(*p
++);
4449 entry
->name
= (const char *) p
;
4450 p
+= XDR_QUADLEN(entry
->len
);
4453 * In case the server doesn't return an inode number,
4454 * we fake one here. (We don't use inode number 0,
4455 * since glibc seems to choke on it...)
4459 len
= ntohl(*p
++); /* bitmap length */
4461 bitmap
[0] = ntohl(*p
++);
4463 bitmap
[1] = ntohl(*p
++);
4467 len
= XDR_QUADLEN(ntohl(*p
++)); /* attribute buffer length */
4469 if (bitmap
[0] & FATTR4_WORD0_RDATTR_ERROR
) {
4470 bitmap
[0] &= ~FATTR4_WORD0_RDATTR_ERROR
;
4471 /* Ignore the return value of rdattr_error for now */
4475 if (bitmap
[0] == 0 && bitmap
[1] == FATTR4_WORD1_MOUNTED_ON_FILEID
)
4476 xdr_decode_hyper(p
, &entry
->ino
);
4477 else if (bitmap
[0] == FATTR4_WORD0_FILEID
)
4478 xdr_decode_hyper(p
, &entry
->ino
);
4482 entry
->eof
= !p
[0] && p
[1];
4487 * We need to translate between nfs status return values and
4488 * the local errno values which may not be the same.
4495 { NFS4ERR_PERM
, EPERM
},
4496 { NFS4ERR_NOENT
, ENOENT
},
4497 { NFS4ERR_IO
, errno_NFSERR_IO
},
4498 { NFS4ERR_NXIO
, ENXIO
},
4499 { NFS4ERR_ACCESS
, EACCES
},
4500 { NFS4ERR_EXIST
, EEXIST
},
4501 { NFS4ERR_XDEV
, EXDEV
},
4502 { NFS4ERR_NOTDIR
, ENOTDIR
},
4503 { NFS4ERR_ISDIR
, EISDIR
},
4504 { NFS4ERR_INVAL
, EINVAL
},
4505 { NFS4ERR_FBIG
, EFBIG
},
4506 { NFS4ERR_NOSPC
, ENOSPC
},
4507 { NFS4ERR_ROFS
, EROFS
},
4508 { NFS4ERR_MLINK
, EMLINK
},
4509 { NFS4ERR_NAMETOOLONG
, ENAMETOOLONG
},
4510 { NFS4ERR_NOTEMPTY
, ENOTEMPTY
},
4511 { NFS4ERR_DQUOT
, EDQUOT
},
4512 { NFS4ERR_STALE
, ESTALE
},
4513 { NFS4ERR_BADHANDLE
, EBADHANDLE
},
4514 { NFS4ERR_BADOWNER
, EINVAL
},
4515 { NFS4ERR_BADNAME
, EINVAL
},
4516 { NFS4ERR_BAD_COOKIE
, EBADCOOKIE
},
4517 { NFS4ERR_NOTSUPP
, ENOTSUPP
},
4518 { NFS4ERR_TOOSMALL
, ETOOSMALL
},
4519 { NFS4ERR_SERVERFAULT
, ESERVERFAULT
},
4520 { NFS4ERR_BADTYPE
, EBADTYPE
},
4521 { NFS4ERR_LOCKED
, EAGAIN
},
4522 { NFS4ERR_RESOURCE
, EREMOTEIO
},
4523 { NFS4ERR_SYMLINK
, ELOOP
},
4524 { NFS4ERR_OP_ILLEGAL
, EOPNOTSUPP
},
4525 { NFS4ERR_DEADLOCK
, EDEADLK
},
4526 { NFS4ERR_WRONGSEC
, EPERM
}, /* FIXME: this needs
4527 * to be handled by a
4534 * Convert an NFS error code to a local one.
4535 * This one is used jointly by NFSv2 and NFSv3.
4538 nfs4_stat_to_errno(int stat
)
4541 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
4542 if (nfs_errtbl
[i
].stat
== stat
)
4543 return nfs_errtbl
[i
].errno
;
4545 if (stat
<= 10000 || stat
> 10100) {
4546 /* The server is looney tunes. */
4547 return ESERVERFAULT
;
4549 /* If we cannot translate the error, the recovery routines should
4551 * Note: remaining NFSv4 error codes have values > 10000, so should
4552 * not conflict with native Linux error codes.
4557 #define PROC(proc, argtype, restype) \
4558 [NFSPROC4_CLNT_##proc] = { \
4559 .p_proc = NFSPROC4_COMPOUND, \
4560 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4561 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4562 .p_arglen = NFS4_##argtype##_sz, \
4563 .p_replen = NFS4_##restype##_sz, \
4564 .p_statidx = NFSPROC4_CLNT_##proc, \
4568 struct rpc_procinfo nfs4_procedures
[] = {
4569 PROC(READ
, enc_read
, dec_read
),
4570 PROC(WRITE
, enc_write
, dec_write
),
4571 PROC(COMMIT
, enc_commit
, dec_commit
),
4572 PROC(OPEN
, enc_open
, dec_open
),
4573 PROC(OPEN_CONFIRM
, enc_open_confirm
, dec_open_confirm
),
4574 PROC(OPEN_NOATTR
, enc_open_noattr
, dec_open_noattr
),
4575 PROC(OPEN_DOWNGRADE
, enc_open_downgrade
, dec_open_downgrade
),
4576 PROC(CLOSE
, enc_close
, dec_close
),
4577 PROC(SETATTR
, enc_setattr
, dec_setattr
),
4578 PROC(FSINFO
, enc_fsinfo
, dec_fsinfo
),
4579 PROC(RENEW
, enc_renew
, dec_renew
),
4580 PROC(SETCLIENTID
, enc_setclientid
, dec_setclientid
),
4581 PROC(SETCLIENTID_CONFIRM
, enc_setclientid_confirm
, dec_setclientid_confirm
),
4582 PROC(LOCK
, enc_lock
, dec_lock
),
4583 PROC(LOCKT
, enc_lockt
, dec_lockt
),
4584 PROC(LOCKU
, enc_locku
, dec_locku
),
4585 PROC(ACCESS
, enc_access
, dec_access
),
4586 PROC(GETATTR
, enc_getattr
, dec_getattr
),
4587 PROC(LOOKUP
, enc_lookup
, dec_lookup
),
4588 PROC(LOOKUP_ROOT
, enc_lookup_root
, dec_lookup_root
),
4589 PROC(REMOVE
, enc_remove
, dec_remove
),
4590 PROC(RENAME
, enc_rename
, dec_rename
),
4591 PROC(LINK
, enc_link
, dec_link
),
4592 PROC(SYMLINK
, enc_symlink
, dec_symlink
),
4593 PROC(CREATE
, enc_create
, dec_create
),
4594 PROC(PATHCONF
, enc_pathconf
, dec_pathconf
),
4595 PROC(STATFS
, enc_statfs
, dec_statfs
),
4596 PROC(READLINK
, enc_readlink
, dec_readlink
),
4597 PROC(READDIR
, enc_readdir
, dec_readdir
),
4598 PROC(SERVER_CAPS
, enc_server_caps
, dec_server_caps
),
4599 PROC(DELEGRETURN
, enc_delegreturn
, dec_delegreturn
),
4600 PROC(GETACL
, enc_getacl
, dec_getacl
),
4601 PROC(SETACL
, enc_setacl
, dec_setacl
),
4602 PROC(FS_LOCATIONS
, enc_fs_locations
, dec_fs_locations
),
4605 struct rpc_version nfs_version4
= {
4607 .nrprocs
= ARRAY_SIZE(nfs4_procedures
),
4608 .procs
= nfs4_procedures