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 nfs_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)
228 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
229 encode_putfh_maxsz + \
231 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
232 decode_putfh_maxsz + \
234 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
236 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
238 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
239 encode_setclientid_maxsz)
240 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
241 decode_setclientid_maxsz)
242 #define NFS4_enc_setclientid_confirm_sz \
243 (compound_encode_hdr_maxsz + \
244 encode_setclientid_confirm_maxsz + \
245 encode_putrootfh_maxsz + \
247 #define NFS4_dec_setclientid_confirm_sz \
248 (compound_decode_hdr_maxsz + \
249 decode_setclientid_confirm_maxsz + \
250 decode_putrootfh_maxsz + \
252 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
253 encode_putfh_maxsz + \
254 encode_getattr_maxsz + \
255 op_encode_hdr_maxsz + \
259 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
260 decode_putfh_maxsz + \
261 decode_getattr_maxsz + \
262 op_decode_hdr_maxsz + \
265 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
266 encode_putfh_maxsz + \
267 encode_getattr_maxsz + \
268 op_encode_hdr_maxsz + \
271 #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
272 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
273 encode_putfh_maxsz + \
274 encode_getattr_maxsz + \
275 op_encode_hdr_maxsz + \
277 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
278 decode_putfh_maxsz + \
279 decode_getattr_maxsz + \
280 op_decode_hdr_maxsz + 4)
281 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
282 encode_putfh_maxsz + \
283 op_encode_hdr_maxsz + 1)
284 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
285 decode_putfh_maxsz + \
286 op_decode_hdr_maxsz + 2)
287 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
288 encode_putfh_maxsz + \
289 encode_getattr_maxsz)
290 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
291 decode_putfh_maxsz + \
292 decode_getattr_maxsz)
293 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
294 encode_putfh_maxsz + \
295 encode_lookup_maxsz + \
296 encode_getattr_maxsz + \
298 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
299 decode_putfh_maxsz + \
300 op_decode_hdr_maxsz + \
301 decode_getattr_maxsz + \
303 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
304 encode_putrootfh_maxsz + \
305 encode_getattr_maxsz + \
307 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
308 decode_putrootfh_maxsz + \
309 decode_getattr_maxsz + \
311 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
312 encode_putfh_maxsz + \
313 encode_remove_maxsz + \
314 encode_getattr_maxsz)
315 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
316 decode_putfh_maxsz + \
317 op_decode_hdr_maxsz + 5 + \
318 decode_getattr_maxsz)
319 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
320 encode_putfh_maxsz + \
321 encode_savefh_maxsz + \
322 encode_putfh_maxsz + \
323 encode_rename_maxsz + \
324 encode_getattr_maxsz + \
325 encode_restorefh_maxsz + \
326 encode_getattr_maxsz)
327 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
328 decode_putfh_maxsz + \
329 decode_savefh_maxsz + \
330 decode_putfh_maxsz + \
331 decode_rename_maxsz + \
332 decode_getattr_maxsz + \
333 decode_restorefh_maxsz + \
334 decode_getattr_maxsz)
335 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
336 encode_putfh_maxsz + \
337 encode_savefh_maxsz + \
338 encode_putfh_maxsz + \
339 encode_link_maxsz + \
340 decode_getattr_maxsz + \
341 encode_restorefh_maxsz + \
342 decode_getattr_maxsz)
343 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
344 decode_putfh_maxsz + \
345 decode_savefh_maxsz + \
346 decode_putfh_maxsz + \
347 decode_link_maxsz + \
348 decode_getattr_maxsz + \
349 decode_restorefh_maxsz + \
350 decode_getattr_maxsz)
351 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
352 encode_putfh_maxsz + \
353 encode_symlink_maxsz + \
354 encode_getattr_maxsz + \
356 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
357 decode_putfh_maxsz + \
358 decode_symlink_maxsz + \
359 decode_getattr_maxsz + \
361 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
362 encode_putfh_maxsz + \
363 encode_savefh_maxsz + \
364 encode_create_maxsz + \
365 encode_getfh_maxsz + \
366 encode_getattr_maxsz + \
367 encode_restorefh_maxsz + \
368 encode_getattr_maxsz)
369 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
370 decode_putfh_maxsz + \
371 decode_savefh_maxsz + \
372 decode_create_maxsz + \
373 decode_getfh_maxsz + \
374 decode_getattr_maxsz + \
375 decode_restorefh_maxsz + \
376 decode_getattr_maxsz)
377 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
378 encode_putfh_maxsz + \
379 encode_getattr_maxsz)
380 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
381 decode_putfh_maxsz + \
382 decode_getattr_maxsz)
383 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
384 encode_putfh_maxsz + \
385 encode_getattr_maxsz)
386 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
387 decode_putfh_maxsz + \
388 op_decode_hdr_maxsz + 12)
389 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
390 encode_getattr_maxsz)
391 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
392 decode_getattr_maxsz)
393 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
394 encode_putfh_maxsz + \
395 encode_delegreturn_maxsz + \
396 encode_getattr_maxsz)
397 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
398 decode_delegreturn_maxsz + \
399 decode_getattr_maxsz)
400 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
401 encode_putfh_maxsz + \
402 encode_getattr_maxsz)
403 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
404 decode_putfh_maxsz + \
405 op_decode_hdr_maxsz + \
406 nfs4_fattr_bitmap_maxsz + 1)
407 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
408 encode_putfh_maxsz + \
409 op_encode_hdr_maxsz + 4 + \
410 nfs4_fattr_bitmap_maxsz + 1)
411 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
412 decode_putfh_maxsz + \
413 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
414 #define NFS4_enc_fs_locations_sz \
415 (compound_encode_hdr_maxsz + \
416 encode_putfh_maxsz + \
417 encode_getattr_maxsz)
418 #define NFS4_dec_fs_locations_sz \
419 (compound_decode_hdr_maxsz + \
420 decode_putfh_maxsz + \
421 op_decode_hdr_maxsz + \
422 nfs4_fattr_bitmap_maxsz)
426 unsigned int nfs2type
;
434 { S_IFSOCK
, NFSOCK
},
440 struct compound_hdr
{
448 * START OF "GENERIC" ENCODE ROUTINES.
449 * These may look a little ugly since they are imported from a "generic"
450 * set of XDR encode/decode routines which are intended to be shared by
451 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
453 * If the pain of reading these is too great, it should be a straightforward
454 * task to translate them into Linux-specific versions which are more
455 * consistent with the style used in NFSv2/v3...
457 #define WRITE32(n) *p++ = htonl(n)
458 #define WRITE64(n) do { \
459 *p++ = htonl((uint32_t)((n) >> 32)); \
460 *p++ = htonl((uint32_t)(n)); \
462 #define WRITEMEM(ptr,nbytes) do { \
463 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
466 #define RESERVE_SPACE(nbytes) do { \
467 p = xdr_reserve_space(xdr, nbytes); \
468 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
472 static void encode_string(struct xdr_stream
*xdr
, unsigned int len
, const char *str
)
476 p
= xdr_reserve_space(xdr
, 4 + len
);
478 xdr_encode_opaque(p
, str
, len
);
481 static int encode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
485 dprintk("encode_compound: tag=%.*s\n", (int)hdr
->taglen
, hdr
->tag
);
486 BUG_ON(hdr
->taglen
> NFS4_MAXTAGLEN
);
487 RESERVE_SPACE(12+(XDR_QUADLEN(hdr
->taglen
)<<2));
488 WRITE32(hdr
->taglen
);
489 WRITEMEM(hdr
->tag
, hdr
->taglen
);
490 WRITE32(NFS4_MINOR_VERSION
);
495 static void encode_nfs4_verifier(struct xdr_stream
*xdr
, const nfs4_verifier
*verf
)
499 p
= xdr_reserve_space(xdr
, NFS4_VERIFIER_SIZE
);
501 xdr_encode_opaque_fixed(p
, verf
->data
, NFS4_VERIFIER_SIZE
);
504 static int encode_attrs(struct xdr_stream
*xdr
, const struct iattr
*iap
, const struct nfs_server
*server
)
506 char owner_name
[IDMAP_NAMESZ
];
507 char owner_group
[IDMAP_NAMESZ
];
508 int owner_namelen
= 0;
509 int owner_grouplen
= 0;
518 * We reserve enough space to write the entire attribute buffer at once.
519 * In the worst-case, this would be
520 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
521 * = 36 bytes, plus any contribution from variable-length fields
522 * such as owner/group.
527 if (iap
->ia_valid
& ATTR_SIZE
)
529 if (iap
->ia_valid
& ATTR_MODE
)
531 if (iap
->ia_valid
& ATTR_UID
) {
532 owner_namelen
= nfs_map_uid_to_name(server
->nfs4_state
, iap
->ia_uid
, owner_name
);
533 if (owner_namelen
< 0) {
534 printk(KERN_WARNING
"nfs: couldn't resolve uid %d to string\n",
537 strcpy(owner_name
, "nobody");
538 owner_namelen
= sizeof("nobody") - 1;
541 len
+= 4 + (XDR_QUADLEN(owner_namelen
) << 2);
543 if (iap
->ia_valid
& ATTR_GID
) {
544 owner_grouplen
= nfs_map_gid_to_group(server
->nfs4_state
, iap
->ia_gid
, owner_group
);
545 if (owner_grouplen
< 0) {
546 printk(KERN_WARNING
"nfs4: couldn't resolve gid %d to string\n",
548 strcpy(owner_group
, "nobody");
549 owner_grouplen
= sizeof("nobody") - 1;
552 len
+= 4 + (XDR_QUADLEN(owner_grouplen
) << 2);
554 if (iap
->ia_valid
& ATTR_ATIME_SET
)
556 else if (iap
->ia_valid
& ATTR_ATIME
)
558 if (iap
->ia_valid
& ATTR_MTIME_SET
)
560 else if (iap
->ia_valid
& ATTR_MTIME
)
565 * We write the bitmap length now, but leave the bitmap and the attribute
566 * buffer length to be backfilled at the end of this routine.
572 if (iap
->ia_valid
& ATTR_SIZE
) {
573 bmval0
|= FATTR4_WORD0_SIZE
;
574 WRITE64(iap
->ia_size
);
576 if (iap
->ia_valid
& ATTR_MODE
) {
577 bmval1
|= FATTR4_WORD1_MODE
;
578 WRITE32(iap
->ia_mode
& S_IALLUGO
);
580 if (iap
->ia_valid
& ATTR_UID
) {
581 bmval1
|= FATTR4_WORD1_OWNER
;
582 WRITE32(owner_namelen
);
583 WRITEMEM(owner_name
, owner_namelen
);
585 if (iap
->ia_valid
& ATTR_GID
) {
586 bmval1
|= FATTR4_WORD1_OWNER_GROUP
;
587 WRITE32(owner_grouplen
);
588 WRITEMEM(owner_group
, owner_grouplen
);
590 if (iap
->ia_valid
& ATTR_ATIME_SET
) {
591 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
592 WRITE32(NFS4_SET_TO_CLIENT_TIME
);
594 WRITE32(iap
->ia_mtime
.tv_sec
);
595 WRITE32(iap
->ia_mtime
.tv_nsec
);
597 else if (iap
->ia_valid
& ATTR_ATIME
) {
598 bmval1
|= FATTR4_WORD1_TIME_ACCESS_SET
;
599 WRITE32(NFS4_SET_TO_SERVER_TIME
);
601 if (iap
->ia_valid
& ATTR_MTIME_SET
) {
602 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
603 WRITE32(NFS4_SET_TO_CLIENT_TIME
);
605 WRITE32(iap
->ia_mtime
.tv_sec
);
606 WRITE32(iap
->ia_mtime
.tv_nsec
);
608 else if (iap
->ia_valid
& ATTR_MTIME
) {
609 bmval1
|= FATTR4_WORD1_TIME_MODIFY_SET
;
610 WRITE32(NFS4_SET_TO_SERVER_TIME
);
614 * Now we backfill the bitmap and the attribute buffer length.
616 if (len
!= ((char *)p
- (char *)q
) + 4) {
617 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
618 len
, ((char *)p
- (char *)q
) + 4);
621 len
= (char *)p
- (char *)q
- 12;
622 *q
++ = htonl(bmval0
);
623 *q
++ = htonl(bmval1
);
631 static int encode_access(struct xdr_stream
*xdr
, u32 access
)
642 static int encode_close(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
)
646 RESERVE_SPACE(8+sizeof(arg
->stateid
->data
));
648 WRITE32(arg
->seqid
->sequence
->counter
);
649 WRITEMEM(arg
->stateid
->data
, sizeof(arg
->stateid
->data
));
654 static int encode_commit(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
)
660 WRITE64(args
->offset
);
661 WRITE32(args
->count
);
666 static int encode_create(struct xdr_stream
*xdr
, const struct nfs4_create_arg
*create
)
672 WRITE32(create
->ftype
);
674 switch (create
->ftype
) {
676 RESERVE_SPACE(4 + create
->u
.symlink
->len
);
677 WRITE32(create
->u
.symlink
->len
);
678 WRITEMEM(create
->u
.symlink
->name
, create
->u
.symlink
->len
);
681 case NF4BLK
: case NF4CHR
:
683 WRITE32(create
->u
.device
.specdata1
);
684 WRITE32(create
->u
.device
.specdata2
);
691 RESERVE_SPACE(4 + create
->name
->len
);
692 WRITE32(create
->name
->len
);
693 WRITEMEM(create
->name
->name
, create
->name
->len
);
695 return encode_attrs(xdr
, create
->attrs
, create
->server
);
698 static int encode_getattr_one(struct xdr_stream
*xdr
, uint32_t bitmap
)
709 static int encode_getattr_two(struct xdr_stream
*xdr
, uint32_t bm0
, uint32_t bm1
)
721 static int encode_getfattr(struct xdr_stream
*xdr
, const u32
* bitmask
)
723 return encode_getattr_two(xdr
,
724 bitmask
[0] & nfs4_fattr_bitmap
[0],
725 bitmask
[1] & nfs4_fattr_bitmap
[1]);
728 static int encode_fsinfo(struct xdr_stream
*xdr
, const u32
* bitmask
)
730 return encode_getattr_two(xdr
, bitmask
[0] & nfs4_fsinfo_bitmap
[0],
731 bitmask
[1] & nfs4_fsinfo_bitmap
[1]);
734 static int encode_getfh(struct xdr_stream
*xdr
)
744 static int encode_link(struct xdr_stream
*xdr
, const struct qstr
*name
)
748 RESERVE_SPACE(8 + name
->len
);
751 WRITEMEM(name
->name
, name
->len
);
756 static inline int nfs4_lock_type(struct file_lock
*fl
, int block
)
758 if ((fl
->fl_type
& (F_RDLCK
|F_WRLCK
|F_UNLCK
)) == F_RDLCK
)
759 return block
? NFS4_READW_LT
: NFS4_READ_LT
;
760 return block
? NFS4_WRITEW_LT
: NFS4_WRITE_LT
;
763 static inline uint64_t nfs4_lock_length(struct file_lock
*fl
)
765 if (fl
->fl_end
== OFFSET_MAX
)
767 return fl
->fl_end
- fl
->fl_start
+ 1;
771 * opcode,type,reclaim,offset,length,new_lock_owner = 32
772 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
774 static int encode_lock(struct xdr_stream
*xdr
, const struct nfs_lock_args
*args
)
780 WRITE32(nfs4_lock_type(args
->fl
, args
->block
));
781 WRITE32(args
->reclaim
);
782 WRITE64(args
->fl
->fl_start
);
783 WRITE64(nfs4_lock_length(args
->fl
));
784 WRITE32(args
->new_lock_owner
);
785 if (args
->new_lock_owner
){
787 WRITE32(args
->open_seqid
->sequence
->counter
);
788 WRITEMEM(args
->open_stateid
->data
, sizeof(args
->open_stateid
->data
));
789 WRITE32(args
->lock_seqid
->sequence
->counter
);
790 WRITE64(args
->lock_owner
.clientid
);
792 WRITE32(args
->lock_owner
.id
);
796 WRITEMEM(args
->lock_stateid
->data
, sizeof(args
->lock_stateid
->data
));
797 WRITE32(args
->lock_seqid
->sequence
->counter
);
803 static int encode_lockt(struct xdr_stream
*xdr
, const struct nfs_lockt_args
*args
)
809 WRITE32(nfs4_lock_type(args
->fl
, 0));
810 WRITE64(args
->fl
->fl_start
);
811 WRITE64(nfs4_lock_length(args
->fl
));
812 WRITE64(args
->lock_owner
.clientid
);
814 WRITE32(args
->lock_owner
.id
);
819 static int encode_locku(struct xdr_stream
*xdr
, const struct nfs_locku_args
*args
)
825 WRITE32(nfs4_lock_type(args
->fl
, 0));
826 WRITE32(args
->seqid
->sequence
->counter
);
827 WRITEMEM(args
->stateid
->data
, sizeof(args
->stateid
->data
));
828 WRITE64(args
->fl
->fl_start
);
829 WRITE64(nfs4_lock_length(args
->fl
));
834 static int encode_lookup(struct xdr_stream
*xdr
, const struct qstr
*name
)
839 RESERVE_SPACE(8 + len
);
842 WRITEMEM(name
->name
, len
);
847 static void encode_share_access(struct xdr_stream
*xdr
, int open_flags
)
852 switch (open_flags
& (FMODE_READ
|FMODE_WRITE
)) {
854 WRITE32(NFS4_SHARE_ACCESS_READ
);
857 WRITE32(NFS4_SHARE_ACCESS_WRITE
);
859 case FMODE_READ
|FMODE_WRITE
:
860 WRITE32(NFS4_SHARE_ACCESS_BOTH
);
865 WRITE32(0); /* for linux, share_deny = 0 always */
868 static inline void encode_openhdr(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
872 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
877 WRITE32(arg
->seqid
->sequence
->counter
);
878 encode_share_access(xdr
, arg
->open_flags
);
880 WRITE64(arg
->clientid
);
885 static inline void encode_createmode(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
890 switch(arg
->open_flags
& O_EXCL
) {
892 WRITE32(NFS4_CREATE_UNCHECKED
);
893 encode_attrs(xdr
, arg
->u
.attrs
, arg
->server
);
896 WRITE32(NFS4_CREATE_EXCLUSIVE
);
897 encode_nfs4_verifier(xdr
, &arg
->u
.verifier
);
901 static void encode_opentype(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
906 switch (arg
->open_flags
& O_CREAT
) {
908 WRITE32(NFS4_OPEN_NOCREATE
);
911 BUG_ON(arg
->claim
!= NFS4_OPEN_CLAIM_NULL
);
912 WRITE32(NFS4_OPEN_CREATE
);
913 encode_createmode(xdr
, arg
);
917 static inline void encode_delegation_type(struct xdr_stream
*xdr
, int delegation_type
)
922 switch (delegation_type
) {
924 WRITE32(NFS4_OPEN_DELEGATE_NONE
);
927 WRITE32(NFS4_OPEN_DELEGATE_READ
);
929 case FMODE_WRITE
|FMODE_READ
:
930 WRITE32(NFS4_OPEN_DELEGATE_WRITE
);
937 static inline void encode_claim_null(struct xdr_stream
*xdr
, const struct qstr
*name
)
942 WRITE32(NFS4_OPEN_CLAIM_NULL
);
943 encode_string(xdr
, name
->len
, name
->name
);
946 static inline void encode_claim_previous(struct xdr_stream
*xdr
, int type
)
951 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS
);
952 encode_delegation_type(xdr
, type
);
955 static inline void encode_claim_delegate_cur(struct xdr_stream
*xdr
, const struct qstr
*name
, const nfs4_stateid
*stateid
)
959 RESERVE_SPACE(4+sizeof(stateid
->data
));
960 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR
);
961 WRITEMEM(stateid
->data
, sizeof(stateid
->data
));
962 encode_string(xdr
, name
->len
, name
->name
);
965 static int encode_open(struct xdr_stream
*xdr
, const struct nfs_openargs
*arg
)
967 encode_openhdr(xdr
, arg
);
968 encode_opentype(xdr
, arg
);
969 switch (arg
->claim
) {
970 case NFS4_OPEN_CLAIM_NULL
:
971 encode_claim_null(xdr
, arg
->name
);
973 case NFS4_OPEN_CLAIM_PREVIOUS
:
974 encode_claim_previous(xdr
, arg
->u
.delegation_type
);
976 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
977 encode_claim_delegate_cur(xdr
, arg
->name
, &arg
->u
.delegation
);
985 static int encode_open_confirm(struct xdr_stream
*xdr
, const struct nfs_open_confirmargs
*arg
)
989 RESERVE_SPACE(8+sizeof(arg
->stateid
->data
));
990 WRITE32(OP_OPEN_CONFIRM
);
991 WRITEMEM(arg
->stateid
->data
, sizeof(arg
->stateid
->data
));
992 WRITE32(arg
->seqid
->sequence
->counter
);
997 static int encode_open_downgrade(struct xdr_stream
*xdr
, const struct nfs_closeargs
*arg
)
1001 RESERVE_SPACE(8+sizeof(arg
->stateid
->data
));
1002 WRITE32(OP_OPEN_DOWNGRADE
);
1003 WRITEMEM(arg
->stateid
->data
, sizeof(arg
->stateid
->data
));
1004 WRITE32(arg
->seqid
->sequence
->counter
);
1005 encode_share_access(xdr
, arg
->open_flags
);
1010 encode_putfh(struct xdr_stream
*xdr
, const struct nfs_fh
*fh
)
1015 RESERVE_SPACE(8 + len
);
1018 WRITEMEM(fh
->data
, len
);
1023 static int encode_putrootfh(struct xdr_stream
*xdr
)
1028 WRITE32(OP_PUTROOTFH
);
1033 static void encode_stateid(struct xdr_stream
*xdr
, const struct nfs_open_context
*ctx
)
1035 nfs4_stateid stateid
;
1039 if (ctx
->state
!= NULL
) {
1040 nfs4_copy_stateid(&stateid
, ctx
->state
, ctx
->lockowner
);
1041 WRITEMEM(stateid
.data
, sizeof(stateid
.data
));
1043 WRITEMEM(zero_stateid
.data
, sizeof(zero_stateid
.data
));
1046 static int encode_read(struct xdr_stream
*xdr
, const struct nfs_readargs
*args
)
1053 encode_stateid(xdr
, args
->context
);
1056 WRITE64(args
->offset
);
1057 WRITE32(args
->count
);
1062 static int encode_readdir(struct xdr_stream
*xdr
, const struct nfs4_readdir_arg
*readdir
, struct rpc_rqst
*req
)
1064 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1065 uint32_t attrs
[2] = {
1066 FATTR4_WORD0_RDATTR_ERROR
|FATTR4_WORD0_FILEID
,
1067 FATTR4_WORD1_MOUNTED_ON_FILEID
,
1072 RESERVE_SPACE(32+sizeof(nfs4_verifier
));
1073 WRITE32(OP_READDIR
);
1074 WRITE64(readdir
->cookie
);
1075 WRITEMEM(readdir
->verifier
.data
, sizeof(readdir
->verifier
.data
));
1076 WRITE32(readdir
->count
>> 1); /* We're not doing readdirplus */
1077 WRITE32(readdir
->count
);
1079 /* Switch to mounted_on_fileid if the server supports it */
1080 if (readdir
->bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
1081 attrs
[0] &= ~FATTR4_WORD0_FILEID
;
1083 attrs
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
1084 WRITE32(attrs
[0] & readdir
->bitmask
[0]);
1085 WRITE32(attrs
[1] & readdir
->bitmask
[1]);
1086 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1088 (unsigned long long)readdir
->cookie
,
1089 ((u32
*)readdir
->verifier
.data
)[0],
1090 ((u32
*)readdir
->verifier
.data
)[1],
1091 attrs
[0] & readdir
->bitmask
[0],
1092 attrs
[1] & readdir
->bitmask
[1]);
1094 /* set up reply kvec
1095 * toplevel_status + taglen + rescount + OP_PUTFH + status
1096 * + OP_READDIR + status + verifer(2) = 9
1098 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ 9) << 2;
1099 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, readdir
->pages
,
1100 readdir
->pgbase
, readdir
->count
);
1101 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1102 __FUNCTION__
, replen
, readdir
->pages
,
1103 readdir
->pgbase
, readdir
->count
);
1108 static int encode_readlink(struct xdr_stream
*xdr
, const struct nfs4_readlink
*readlink
, struct rpc_rqst
*req
)
1110 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1111 unsigned int replen
;
1115 WRITE32(OP_READLINK
);
1117 /* set up reply kvec
1118 * toplevel_status + taglen + rescount + OP_PUTFH + status
1119 * + OP_READLINK + status + string length = 8
1121 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ 8) << 2;
1122 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, readlink
->pages
,
1123 readlink
->pgbase
, readlink
->pglen
);
1128 static int encode_remove(struct xdr_stream
*xdr
, const struct qstr
*name
)
1132 RESERVE_SPACE(8 + name
->len
);
1135 WRITEMEM(name
->name
, name
->len
);
1140 static int encode_rename(struct xdr_stream
*xdr
, const struct qstr
*oldname
, const struct qstr
*newname
)
1144 RESERVE_SPACE(8 + oldname
->len
);
1146 WRITE32(oldname
->len
);
1147 WRITEMEM(oldname
->name
, oldname
->len
);
1149 RESERVE_SPACE(4 + newname
->len
);
1150 WRITE32(newname
->len
);
1151 WRITEMEM(newname
->name
, newname
->len
);
1156 static int encode_renew(struct xdr_stream
*xdr
, const struct nfs4_client
*client_stateid
)
1162 WRITE64(client_stateid
->cl_clientid
);
1168 encode_restorefh(struct xdr_stream
*xdr
)
1173 WRITE32(OP_RESTOREFH
);
1179 encode_setacl(struct xdr_stream
*xdr
, struct nfs_setaclargs
*arg
)
1183 RESERVE_SPACE(4+sizeof(zero_stateid
.data
));
1184 WRITE32(OP_SETATTR
);
1185 WRITEMEM(zero_stateid
.data
, sizeof(zero_stateid
.data
));
1188 WRITE32(FATTR4_WORD0_ACL
);
1189 if (arg
->acl_len
% 4)
1192 WRITE32(arg
->acl_len
);
1193 xdr_write_pages(xdr
, arg
->acl_pages
, arg
->acl_pgbase
, arg
->acl_len
);
1198 encode_savefh(struct xdr_stream
*xdr
)
1208 static int encode_setattr(struct xdr_stream
*xdr
, const struct nfs_setattrargs
*arg
, const struct nfs_server
*server
)
1213 RESERVE_SPACE(4+sizeof(arg
->stateid
.data
));
1214 WRITE32(OP_SETATTR
);
1215 WRITEMEM(arg
->stateid
.data
, sizeof(arg
->stateid
.data
));
1217 if ((status
= encode_attrs(xdr
, arg
->iap
, server
)))
1223 static int encode_setclientid(struct xdr_stream
*xdr
, const struct nfs4_setclientid
*setclientid
)
1227 RESERVE_SPACE(4 + sizeof(setclientid
->sc_verifier
->data
));
1228 WRITE32(OP_SETCLIENTID
);
1229 WRITEMEM(setclientid
->sc_verifier
->data
, sizeof(setclientid
->sc_verifier
->data
));
1231 encode_string(xdr
, setclientid
->sc_name_len
, setclientid
->sc_name
);
1233 WRITE32(setclientid
->sc_prog
);
1234 encode_string(xdr
, setclientid
->sc_netid_len
, setclientid
->sc_netid
);
1235 encode_string(xdr
, setclientid
->sc_uaddr_len
, setclientid
->sc_uaddr
);
1237 WRITE32(setclientid
->sc_cb_ident
);
1242 static int encode_setclientid_confirm(struct xdr_stream
*xdr
, const struct nfs4_client
*client_state
)
1246 RESERVE_SPACE(12 + sizeof(client_state
->cl_confirm
.data
));
1247 WRITE32(OP_SETCLIENTID_CONFIRM
);
1248 WRITE64(client_state
->cl_clientid
);
1249 WRITEMEM(client_state
->cl_confirm
.data
, sizeof(client_state
->cl_confirm
.data
));
1254 static int encode_write(struct xdr_stream
*xdr
, const struct nfs_writeargs
*args
)
1261 encode_stateid(xdr
, args
->context
);
1264 WRITE64(args
->offset
);
1265 WRITE32(args
->stable
);
1266 WRITE32(args
->count
);
1268 xdr_write_pages(xdr
, args
->pages
, args
->pgbase
, args
->count
);
1273 static int encode_delegreturn(struct xdr_stream
*xdr
, const nfs4_stateid
*stateid
)
1279 WRITE32(OP_DELEGRETURN
);
1280 WRITEMEM(stateid
->data
, sizeof(stateid
->data
));
1285 * END OF "GENERIC" ENCODE ROUTINES.
1289 * Encode an ACCESS request
1291 static int nfs4_xdr_enc_access(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_accessargs
*args
)
1293 struct xdr_stream xdr
;
1294 struct compound_hdr hdr
= {
1299 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1300 encode_compound_hdr(&xdr
, &hdr
);
1301 if ((status
= encode_putfh(&xdr
, args
->fh
)) == 0)
1302 status
= encode_access(&xdr
, args
->access
);
1307 * Encode LOOKUP request
1309 static int nfs4_xdr_enc_lookup(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_lookup_arg
*args
)
1311 struct xdr_stream xdr
;
1312 struct compound_hdr hdr
= {
1317 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1318 encode_compound_hdr(&xdr
, &hdr
);
1319 if ((status
= encode_putfh(&xdr
, args
->dir_fh
)) != 0)
1321 if ((status
= encode_lookup(&xdr
, args
->name
)) != 0)
1323 if ((status
= encode_getfh(&xdr
)) != 0)
1325 status
= encode_getfattr(&xdr
, args
->bitmask
);
1331 * Encode LOOKUP_ROOT request
1333 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_lookup_root_arg
*args
)
1335 struct xdr_stream xdr
;
1336 struct compound_hdr hdr
= {
1341 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1342 encode_compound_hdr(&xdr
, &hdr
);
1343 if ((status
= encode_putrootfh(&xdr
)) != 0)
1345 if ((status
= encode_getfh(&xdr
)) == 0)
1346 status
= encode_getfattr(&xdr
, args
->bitmask
);
1352 * Encode REMOVE request
1354 static int nfs4_xdr_enc_remove(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_remove_arg
*args
)
1356 struct xdr_stream xdr
;
1357 struct compound_hdr hdr
= {
1362 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1363 encode_compound_hdr(&xdr
, &hdr
);
1364 if ((status
= encode_putfh(&xdr
, args
->fh
)) != 0)
1366 if ((status
= encode_remove(&xdr
, args
->name
)) != 0)
1368 status
= encode_getfattr(&xdr
, args
->bitmask
);
1374 * Encode RENAME request
1376 static int nfs4_xdr_enc_rename(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_rename_arg
*args
)
1378 struct xdr_stream xdr
;
1379 struct compound_hdr hdr
= {
1384 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1385 encode_compound_hdr(&xdr
, &hdr
);
1386 if ((status
= encode_putfh(&xdr
, args
->old_dir
)) != 0)
1388 if ((status
= encode_savefh(&xdr
)) != 0)
1390 if ((status
= encode_putfh(&xdr
, args
->new_dir
)) != 0)
1392 if ((status
= encode_rename(&xdr
, args
->old_name
, args
->new_name
)) != 0)
1394 if ((status
= encode_getfattr(&xdr
, args
->bitmask
)) != 0)
1396 if ((status
= encode_restorefh(&xdr
)) != 0)
1398 status
= encode_getfattr(&xdr
, args
->bitmask
);
1404 * Encode LINK request
1406 static int nfs4_xdr_enc_link(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_link_arg
*args
)
1408 struct xdr_stream xdr
;
1409 struct compound_hdr hdr
= {
1414 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1415 encode_compound_hdr(&xdr
, &hdr
);
1416 if ((status
= encode_putfh(&xdr
, args
->fh
)) != 0)
1418 if ((status
= encode_savefh(&xdr
)) != 0)
1420 if ((status
= encode_putfh(&xdr
, args
->dir_fh
)) != 0)
1422 if ((status
= encode_link(&xdr
, args
->name
)) != 0)
1424 if ((status
= encode_getfattr(&xdr
, args
->bitmask
)) != 0)
1426 if ((status
= encode_restorefh(&xdr
)) != 0)
1428 status
= encode_getfattr(&xdr
, args
->bitmask
);
1434 * Encode CREATE request
1436 static int nfs4_xdr_enc_create(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_create_arg
*args
)
1438 struct xdr_stream xdr
;
1439 struct compound_hdr hdr
= {
1444 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1445 encode_compound_hdr(&xdr
, &hdr
);
1446 if ((status
= encode_putfh(&xdr
, args
->dir_fh
)) != 0)
1448 if ((status
= encode_savefh(&xdr
)) != 0)
1450 if ((status
= encode_create(&xdr
, args
)) != 0)
1452 if ((status
= encode_getfh(&xdr
)) != 0)
1454 if ((status
= encode_getfattr(&xdr
, args
->bitmask
)) != 0)
1456 if ((status
= encode_restorefh(&xdr
)) != 0)
1458 status
= encode_getfattr(&xdr
, args
->bitmask
);
1464 * Encode SYMLINK request
1466 static int nfs4_xdr_enc_symlink(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_create_arg
*args
)
1468 return nfs4_xdr_enc_create(req
, p
, args
);
1472 * Encode GETATTR request
1474 static int nfs4_xdr_enc_getattr(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_getattr_arg
*args
)
1476 struct xdr_stream xdr
;
1477 struct compound_hdr hdr
= {
1482 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1483 encode_compound_hdr(&xdr
, &hdr
);
1484 if ((status
= encode_putfh(&xdr
, args
->fh
)) == 0)
1485 status
= encode_getfattr(&xdr
, args
->bitmask
);
1490 * Encode a CLOSE request
1492 static int nfs4_xdr_enc_close(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_closeargs
*args
)
1494 struct xdr_stream xdr
;
1495 struct compound_hdr hdr
= {
1500 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1501 encode_compound_hdr(&xdr
, &hdr
);
1502 status
= encode_putfh(&xdr
, args
->fh
);
1505 status
= encode_close(&xdr
, args
);
1508 status
= encode_getfattr(&xdr
, args
->bitmask
);
1514 * Encode an OPEN request
1516 static int nfs4_xdr_enc_open(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_openargs
*args
)
1518 struct xdr_stream xdr
;
1519 struct compound_hdr hdr
= {
1524 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1525 encode_compound_hdr(&xdr
, &hdr
);
1526 status
= encode_putfh(&xdr
, args
->fh
);
1529 status
= encode_savefh(&xdr
);
1532 status
= encode_open(&xdr
, args
);
1535 status
= encode_getfh(&xdr
);
1538 status
= encode_getfattr(&xdr
, args
->bitmask
);
1541 status
= encode_restorefh(&xdr
);
1544 status
= encode_getfattr(&xdr
, args
->bitmask
);
1550 * Encode an OPEN_CONFIRM request
1552 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_open_confirmargs
*args
)
1554 struct xdr_stream xdr
;
1555 struct compound_hdr hdr
= {
1560 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1561 encode_compound_hdr(&xdr
, &hdr
);
1562 status
= encode_putfh(&xdr
, args
->fh
);
1565 status
= encode_open_confirm(&xdr
, args
);
1571 * Encode an OPEN request with no attributes.
1573 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_openargs
*args
)
1575 struct xdr_stream xdr
;
1576 struct compound_hdr hdr
= {
1581 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1582 encode_compound_hdr(&xdr
, &hdr
);
1583 status
= encode_putfh(&xdr
, args
->fh
);
1586 status
= encode_open(&xdr
, args
);
1589 status
= encode_getfattr(&xdr
, args
->bitmask
);
1595 * Encode an OPEN_DOWNGRADE request
1597 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_closeargs
*args
)
1599 struct xdr_stream xdr
;
1600 struct compound_hdr hdr
= {
1605 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1606 encode_compound_hdr(&xdr
, &hdr
);
1607 status
= encode_putfh(&xdr
, args
->fh
);
1610 status
= encode_open_downgrade(&xdr
, args
);
1613 status
= encode_getfattr(&xdr
, args
->bitmask
);
1619 * Encode a LOCK request
1621 static int nfs4_xdr_enc_lock(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_lock_args
*args
)
1623 struct xdr_stream xdr
;
1624 struct compound_hdr hdr
= {
1629 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1630 encode_compound_hdr(&xdr
, &hdr
);
1631 status
= encode_putfh(&xdr
, args
->fh
);
1634 status
= encode_lock(&xdr
, args
);
1640 * Encode a LOCKT request
1642 static int nfs4_xdr_enc_lockt(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_lockt_args
*args
)
1644 struct xdr_stream xdr
;
1645 struct compound_hdr hdr
= {
1650 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1651 encode_compound_hdr(&xdr
, &hdr
);
1652 status
= encode_putfh(&xdr
, args
->fh
);
1655 status
= encode_lockt(&xdr
, args
);
1661 * Encode a LOCKU request
1663 static int nfs4_xdr_enc_locku(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_locku_args
*args
)
1665 struct xdr_stream xdr
;
1666 struct compound_hdr hdr
= {
1671 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1672 encode_compound_hdr(&xdr
, &hdr
);
1673 status
= encode_putfh(&xdr
, args
->fh
);
1676 status
= encode_locku(&xdr
, args
);
1682 * Encode a READLINK request
1684 static int nfs4_xdr_enc_readlink(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_readlink
*args
)
1686 struct xdr_stream xdr
;
1687 struct compound_hdr hdr
= {
1692 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1693 encode_compound_hdr(&xdr
, &hdr
);
1694 status
= encode_putfh(&xdr
, args
->fh
);
1697 status
= encode_readlink(&xdr
, args
, req
);
1703 * Encode a READDIR request
1705 static int nfs4_xdr_enc_readdir(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_readdir_arg
*args
)
1707 struct xdr_stream xdr
;
1708 struct compound_hdr hdr
= {
1713 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1714 encode_compound_hdr(&xdr
, &hdr
);
1715 status
= encode_putfh(&xdr
, args
->fh
);
1718 status
= encode_readdir(&xdr
, args
, req
);
1724 * Encode a READ request
1726 static int nfs4_xdr_enc_read(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_readargs
*args
)
1728 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1729 struct xdr_stream xdr
;
1730 struct compound_hdr hdr
= {
1735 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1736 encode_compound_hdr(&xdr
, &hdr
);
1737 status
= encode_putfh(&xdr
, args
->fh
);
1740 status
= encode_read(&xdr
, args
);
1744 /* set up reply kvec
1745 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1746 * + OP_READ + status + eof + datalen = 9
1748 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ NFS4_dec_read_sz
) << 2;
1749 xdr_inline_pages(&req
->rq_rcv_buf
, replen
,
1750 args
->pages
, args
->pgbase
, args
->count
);
1756 * Encode an SETATTR request
1758 static int nfs4_xdr_enc_setattr(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_setattrargs
*args
)
1761 struct xdr_stream xdr
;
1762 struct compound_hdr hdr
= {
1767 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1768 encode_compound_hdr(&xdr
, &hdr
);
1769 status
= encode_putfh(&xdr
, args
->fh
);
1772 status
= encode_setattr(&xdr
, args
, args
->server
);
1775 status
= encode_getfattr(&xdr
, args
->bitmask
);
1781 * Encode a GETACL request
1784 nfs4_xdr_enc_getacl(struct rpc_rqst
*req
, uint32_t *p
,
1785 struct nfs_getaclargs
*args
)
1787 struct xdr_stream xdr
;
1788 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
1789 struct compound_hdr hdr
= {
1794 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1795 encode_compound_hdr(&xdr
, &hdr
);
1796 status
= encode_putfh(&xdr
, args
->fh
);
1799 status
= encode_getattr_two(&xdr
, FATTR4_WORD0_ACL
, 0);
1800 /* set up reply buffer: */
1801 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ NFS4_dec_getacl_sz
) << 2;
1802 xdr_inline_pages(&req
->rq_rcv_buf
, replen
,
1803 args
->acl_pages
, args
->acl_pgbase
, args
->acl_len
);
1809 * Encode a WRITE request
1811 static int nfs4_xdr_enc_write(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_writeargs
*args
)
1813 struct xdr_stream xdr
;
1814 struct compound_hdr hdr
= {
1819 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1820 encode_compound_hdr(&xdr
, &hdr
);
1821 status
= encode_putfh(&xdr
, args
->fh
);
1824 status
= encode_write(&xdr
, args
);
1827 status
= encode_getfattr(&xdr
, args
->bitmask
);
1835 static int nfs4_xdr_enc_commit(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_writeargs
*args
)
1837 struct xdr_stream xdr
;
1838 struct compound_hdr hdr
= {
1843 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1844 encode_compound_hdr(&xdr
, &hdr
);
1845 status
= encode_putfh(&xdr
, args
->fh
);
1848 status
= encode_commit(&xdr
, args
);
1851 status
= encode_getfattr(&xdr
, args
->bitmask
);
1859 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst
*req
, uint32_t *p
, struct nfs4_fsinfo_arg
*args
)
1861 struct xdr_stream xdr
;
1862 struct compound_hdr hdr
= {
1867 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1868 encode_compound_hdr(&xdr
, &hdr
);
1869 status
= encode_putfh(&xdr
, args
->fh
);
1871 status
= encode_fsinfo(&xdr
, args
->bitmask
);
1876 * a PATHCONF request
1878 static int nfs4_xdr_enc_pathconf(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_pathconf_arg
*args
)
1880 struct xdr_stream xdr
;
1881 struct compound_hdr hdr
= {
1886 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1887 encode_compound_hdr(&xdr
, &hdr
);
1888 status
= encode_putfh(&xdr
, args
->fh
);
1890 status
= encode_getattr_one(&xdr
,
1891 args
->bitmask
[0] & nfs4_pathconf_bitmap
[0]);
1898 static int nfs4_xdr_enc_statfs(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_statfs_arg
*args
)
1900 struct xdr_stream xdr
;
1901 struct compound_hdr hdr
= {
1906 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1907 encode_compound_hdr(&xdr
, &hdr
);
1908 status
= encode_putfh(&xdr
, args
->fh
);
1910 status
= encode_getattr_two(&xdr
,
1911 args
->bitmask
[0] & nfs4_statfs_bitmap
[0],
1912 args
->bitmask
[1] & nfs4_statfs_bitmap
[1]);
1917 * GETATTR_BITMAP request
1919 static int nfs4_xdr_enc_server_caps(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs_fh
*fhandle
)
1921 struct xdr_stream xdr
;
1922 struct compound_hdr hdr
= {
1927 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1928 encode_compound_hdr(&xdr
, &hdr
);
1929 status
= encode_putfh(&xdr
, fhandle
);
1931 status
= encode_getattr_one(&xdr
, FATTR4_WORD0_SUPPORTED_ATTRS
|
1932 FATTR4_WORD0_LINK_SUPPORT
|
1933 FATTR4_WORD0_SYMLINK_SUPPORT
|
1934 FATTR4_WORD0_ACLSUPPORT
);
1941 static int nfs4_xdr_enc_renew(struct rpc_rqst
*req
, uint32_t *p
, struct nfs4_client
*clp
)
1943 struct xdr_stream xdr
;
1944 struct compound_hdr hdr
= {
1948 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1949 encode_compound_hdr(&xdr
, &hdr
);
1950 return encode_renew(&xdr
, clp
);
1954 * a SETCLIENTID request
1956 static int nfs4_xdr_enc_setclientid(struct rpc_rqst
*req
, uint32_t *p
, struct nfs4_setclientid
*sc
)
1958 struct xdr_stream xdr
;
1959 struct compound_hdr hdr
= {
1963 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1964 encode_compound_hdr(&xdr
, &hdr
);
1965 return encode_setclientid(&xdr
, sc
);
1969 * a SETCLIENTID_CONFIRM request
1971 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst
*req
, uint32_t *p
, struct nfs4_client
*clp
)
1973 struct xdr_stream xdr
;
1974 struct compound_hdr hdr
= {
1977 const u32 lease_bitmap
[2] = { FATTR4_WORD0_LEASE_TIME
, 0 };
1980 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
1981 encode_compound_hdr(&xdr
, &hdr
);
1982 status
= encode_setclientid_confirm(&xdr
, clp
);
1984 status
= encode_putrootfh(&xdr
);
1986 status
= encode_fsinfo(&xdr
, lease_bitmap
);
1991 * DELEGRETURN request
1993 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst
*req
, uint32_t *p
, const struct nfs4_delegreturnargs
*args
)
1995 struct xdr_stream xdr
;
1996 struct compound_hdr hdr
= {
2001 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2002 encode_compound_hdr(&xdr
, &hdr
);
2003 status
= encode_putfh(&xdr
, args
->fhandle
);
2006 status
= encode_delegreturn(&xdr
, args
->stateid
);
2009 status
= encode_getfattr(&xdr
, args
->bitmask
);
2015 * Encode FS_LOCATIONS request
2017 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst
*req
, uint32_t *p
, struct nfs4_fs_locations_arg
*args
)
2019 struct xdr_stream xdr
;
2020 struct compound_hdr hdr
= {
2023 struct rpc_auth
*auth
= req
->rq_task
->tk_auth
;
2027 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
2028 encode_compound_hdr(&xdr
, &hdr
);
2029 if ((status
= encode_putfh(&xdr
, args
->dir_fh
)) != 0)
2031 if ((status
= encode_lookup(&xdr
, args
->name
)) != 0)
2033 if ((status
= encode_getfattr(&xdr
, args
->bitmask
)) != 0)
2036 * toplevel_status + taglen + rescount + OP_PUTFH + status
2037 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2039 replen
= (RPC_REPHDRSIZE
+ auth
->au_rslack
+ 7) << 2;
2040 xdr_inline_pages(&req
->rq_rcv_buf
, replen
, &args
->page
,
2047 * START OF "GENERIC" DECODE ROUTINES.
2048 * These may look a little ugly since they are imported from a "generic"
2049 * set of XDR encode/decode routines which are intended to be shared by
2050 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2052 * If the pain of reading these is too great, it should be a straightforward
2053 * task to translate them into Linux-specific versions which are more
2054 * consistent with the style used in NFSv2/v3...
2056 #define READ32(x) (x) = ntohl(*p++)
2057 #define READ64(x) do { \
2058 (x) = (u64)ntohl(*p++) << 32; \
2059 (x) |= ntohl(*p++); \
2061 #define READTIME(x) do { \
2063 (x.tv_sec) = ntohl(*p++); \
2064 (x.tv_nsec) = ntohl(*p++); \
2066 #define COPYMEM(x,nbytes) do { \
2067 memcpy((x), p, nbytes); \
2068 p += XDR_QUADLEN(nbytes); \
2071 #define READ_BUF(nbytes) do { \
2072 p = xdr_inline_decode(xdr, nbytes); \
2074 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
2075 __FUNCTION__, __LINE__); \
2080 static int decode_opaque_inline(struct xdr_stream
*xdr
, unsigned int *len
, char **string
)
2087 *string
= (char *)p
;
2091 static int decode_compound_hdr(struct xdr_stream
*xdr
, struct compound_hdr
*hdr
)
2096 READ32(hdr
->status
);
2097 READ32(hdr
->taglen
);
2099 READ_BUF(hdr
->taglen
+ 4);
2100 hdr
->tag
= (char *)p
;
2101 p
+= XDR_QUADLEN(hdr
->taglen
);
2106 static int decode_op_hdr(struct xdr_stream
*xdr
, enum nfs_opnum4 expected
)
2114 if (opnum
!= expected
) {
2116 "nfs4_decode_op_hdr: Server returned operation"
2117 " %d but we issued a request for %d\n",
2122 if (nfserr
!= NFS_OK
)
2123 return -nfs_stat_to_errno(nfserr
);
2128 static int decode_ace(struct xdr_stream
*xdr
, void *ace
, struct nfs4_client
*clp
)
2131 unsigned int strlen
;
2135 return decode_opaque_inline(xdr
, &strlen
, &str
);
2138 static int decode_attr_bitmap(struct xdr_stream
*xdr
, uint32_t *bitmap
)
2145 bitmap
[0] = bitmap
[1] = 0;
2146 READ_BUF((bmlen
<< 2));
2155 static inline int decode_attr_length(struct xdr_stream
*xdr
, uint32_t *attrlen
, uint32_t **savep
)
2165 static int decode_attr_supported(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *bitmask
)
2167 if (likely(bitmap
[0] & FATTR4_WORD0_SUPPORTED_ATTRS
)) {
2168 decode_attr_bitmap(xdr
, bitmask
);
2169 bitmap
[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS
;
2171 bitmask
[0] = bitmask
[1] = 0;
2172 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__
, bitmask
[0], bitmask
[1]);
2176 static int decode_attr_type(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *type
)
2181 if (unlikely(bitmap
[0] & (FATTR4_WORD0_TYPE
- 1U)))
2183 if (likely(bitmap
[0] & FATTR4_WORD0_TYPE
)) {
2186 if (*type
< NF4REG
|| *type
> NF4NAMEDATTR
) {
2187 dprintk("%s: bad type %d\n", __FUNCTION__
, *type
);
2190 bitmap
[0] &= ~FATTR4_WORD0_TYPE
;
2192 dprintk("%s: type=0%o\n", __FUNCTION__
, nfs_type2fmt
[*type
].nfs2type
);
2196 static int decode_attr_change(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *change
)
2201 if (unlikely(bitmap
[0] & (FATTR4_WORD0_CHANGE
- 1U)))
2203 if (likely(bitmap
[0] & FATTR4_WORD0_CHANGE
)) {
2206 bitmap
[0] &= ~FATTR4_WORD0_CHANGE
;
2208 dprintk("%s: change attribute=%Lu\n", __FUNCTION__
,
2209 (unsigned long long)*change
);
2213 static int decode_attr_size(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *size
)
2218 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SIZE
- 1U)))
2220 if (likely(bitmap
[0] & FATTR4_WORD0_SIZE
)) {
2223 bitmap
[0] &= ~FATTR4_WORD0_SIZE
;
2225 dprintk("%s: file size=%Lu\n", __FUNCTION__
, (unsigned long long)*size
);
2229 static int decode_attr_link_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2234 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LINK_SUPPORT
- 1U)))
2236 if (likely(bitmap
[0] & FATTR4_WORD0_LINK_SUPPORT
)) {
2239 bitmap
[0] &= ~FATTR4_WORD0_LINK_SUPPORT
;
2241 dprintk("%s: link support=%s\n", __FUNCTION__
, *res
== 0 ? "false" : "true");
2245 static int decode_attr_symlink_support(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2250 if (unlikely(bitmap
[0] & (FATTR4_WORD0_SYMLINK_SUPPORT
- 1U)))
2252 if (likely(bitmap
[0] & FATTR4_WORD0_SYMLINK_SUPPORT
)) {
2255 bitmap
[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT
;
2257 dprintk("%s: symlink support=%s\n", __FUNCTION__
, *res
== 0 ? "false" : "true");
2261 static int decode_attr_fsid(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs_fsid
*fsid
)
2267 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FSID
- 1U)))
2269 if (likely(bitmap
[0] & FATTR4_WORD0_FSID
)) {
2271 READ64(fsid
->major
);
2272 READ64(fsid
->minor
);
2273 bitmap
[0] &= ~FATTR4_WORD0_FSID
;
2275 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__
,
2276 (unsigned long long)fsid
->major
,
2277 (unsigned long long)fsid
->minor
);
2281 static int decode_attr_lease_time(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2286 if (unlikely(bitmap
[0] & (FATTR4_WORD0_LEASE_TIME
- 1U)))
2288 if (likely(bitmap
[0] & FATTR4_WORD0_LEASE_TIME
)) {
2291 bitmap
[0] &= ~FATTR4_WORD0_LEASE_TIME
;
2293 dprintk("%s: file size=%u\n", __FUNCTION__
, (unsigned int)*res
);
2297 static int decode_attr_aclsupport(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2301 *res
= ACL4_SUPPORT_ALLOW_ACL
|ACL4_SUPPORT_DENY_ACL
;
2302 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACLSUPPORT
- 1U)))
2304 if (likely(bitmap
[0] & FATTR4_WORD0_ACLSUPPORT
)) {
2307 bitmap
[0] &= ~FATTR4_WORD0_ACLSUPPORT
;
2309 dprintk("%s: ACLs supported=%u\n", __FUNCTION__
, (unsigned int)*res
);
2313 static int decode_attr_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
2318 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILEID
- 1U)))
2320 if (likely(bitmap
[0] & FATTR4_WORD0_FILEID
)) {
2323 bitmap
[0] &= ~FATTR4_WORD0_FILEID
;
2325 dprintk("%s: fileid=%Lu\n", __FUNCTION__
, (unsigned long long)*fileid
);
2329 static int decode_attr_mounted_on_fileid(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *fileid
)
2334 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID
- 1U)))
2336 if (likely(bitmap
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)) {
2339 bitmap
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
2341 dprintk("%s: fileid=%Lu\n", __FUNCTION__
, (unsigned long long)*fileid
);
2345 static int decode_attr_files_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2351 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_AVAIL
- 1U)))
2353 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_AVAIL
)) {
2356 bitmap
[0] &= ~FATTR4_WORD0_FILES_AVAIL
;
2358 dprintk("%s: files avail=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2362 static int decode_attr_files_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2368 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_FREE
- 1U)))
2370 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_FREE
)) {
2373 bitmap
[0] &= ~FATTR4_WORD0_FILES_FREE
;
2375 dprintk("%s: files free=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2379 static int decode_attr_files_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2385 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FILES_TOTAL
- 1U)))
2387 if (likely(bitmap
[0] & FATTR4_WORD0_FILES_TOTAL
)) {
2390 bitmap
[0] &= ~FATTR4_WORD0_FILES_TOTAL
;
2392 dprintk("%s: files total=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2396 static int decode_pathname(struct xdr_stream
*xdr
, struct nfs4_pathname
*path
)
2407 path
->ncomponents
= 0;
2408 while (path
->ncomponents
< n
) {
2409 struct nfs4_string
*component
= &path
->components
[path
->ncomponents
];
2410 status
= decode_opaque_inline(xdr
, &component
->len
, &component
->data
);
2411 if (unlikely(status
!= 0))
2413 if (path
->ncomponents
!= n
)
2415 dprintk("%s", component
->data
);
2416 if (path
->ncomponents
< NFS4_PATHNAME_MAXCOMPONENTS
)
2417 path
->ncomponents
++;
2419 dprintk("cannot parse %d components in path\n", n
);
2427 dprintk(" status %d", status
);
2432 static int decode_attr_fs_locations(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_fs_locations
*res
)
2438 if (unlikely(bitmap
[0] & (FATTR4_WORD0_FS_LOCATIONS
-1U)))
2441 if (unlikely(!(bitmap
[0] & FATTR4_WORD0_FS_LOCATIONS
)))
2443 dprintk("%s: fsroot ", __FUNCTION__
);
2444 status
= decode_pathname(xdr
, &res
->fs_path
);
2445 if (unlikely(status
!= 0))
2451 res
->nlocations
= 0;
2452 while (res
->nlocations
< n
) {
2454 struct nfs4_fs_location
*loc
= &res
->locations
[res
->nlocations
];
2462 dprintk("%s: servers ", __FUNCTION__
);
2463 while (loc
->nservers
< m
) {
2464 struct nfs4_string
*server
= &loc
->servers
[loc
->nservers
];
2465 status
= decode_opaque_inline(xdr
, &server
->len
, &server
->data
);
2466 if (unlikely(status
!= 0))
2468 dprintk("%s ", server
->data
);
2469 if (loc
->nservers
< NFS4_FS_LOCATION_MAXSERVERS
)
2473 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__
, NFS4_FS_LOCATION_MAXSERVERS
, m
, res
->nlocations
);
2474 for (i
= loc
->nservers
; i
< m
; i
++) {
2477 status
= decode_opaque_inline(xdr
, &len
, &data
);
2478 if (unlikely(status
!= 0))
2483 status
= decode_pathname(xdr
, &loc
->rootpath
);
2484 if (unlikely(status
!= 0))
2486 if (res
->nlocations
< NFS4_FS_LOCATIONS_MAXENTRIES
)
2490 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__
, status
);
2497 static int decode_attr_maxfilesize(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2503 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXFILESIZE
- 1U)))
2505 if (likely(bitmap
[0] & FATTR4_WORD0_MAXFILESIZE
)) {
2508 bitmap
[0] &= ~FATTR4_WORD0_MAXFILESIZE
;
2510 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2514 static int decode_attr_maxlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxlink
)
2520 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXLINK
- 1U)))
2522 if (likely(bitmap
[0] & FATTR4_WORD0_MAXLINK
)) {
2525 bitmap
[0] &= ~FATTR4_WORD0_MAXLINK
;
2527 dprintk("%s: maxlink=%u\n", __FUNCTION__
, *maxlink
);
2531 static int decode_attr_maxname(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *maxname
)
2537 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXNAME
- 1U)))
2539 if (likely(bitmap
[0] & FATTR4_WORD0_MAXNAME
)) {
2542 bitmap
[0] &= ~FATTR4_WORD0_MAXNAME
;
2544 dprintk("%s: maxname=%u\n", __FUNCTION__
, *maxname
);
2548 static int decode_attr_maxread(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2554 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXREAD
- 1U)))
2556 if (likely(bitmap
[0] & FATTR4_WORD0_MAXREAD
)) {
2560 if (maxread
> 0x7FFFFFFF)
2561 maxread
= 0x7FFFFFFF;
2562 *res
= (uint32_t)maxread
;
2563 bitmap
[0] &= ~FATTR4_WORD0_MAXREAD
;
2565 dprintk("%s: maxread=%lu\n", __FUNCTION__
, (unsigned long)*res
);
2569 static int decode_attr_maxwrite(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *res
)
2575 if (unlikely(bitmap
[0] & (FATTR4_WORD0_MAXWRITE
- 1U)))
2577 if (likely(bitmap
[0] & FATTR4_WORD0_MAXWRITE
)) {
2581 if (maxwrite
> 0x7FFFFFFF)
2582 maxwrite
= 0x7FFFFFFF;
2583 *res
= (uint32_t)maxwrite
;
2584 bitmap
[0] &= ~FATTR4_WORD0_MAXWRITE
;
2586 dprintk("%s: maxwrite=%lu\n", __FUNCTION__
, (unsigned long)*res
);
2590 static int decode_attr_mode(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *mode
)
2595 if (unlikely(bitmap
[1] & (FATTR4_WORD1_MODE
- 1U)))
2597 if (likely(bitmap
[1] & FATTR4_WORD1_MODE
)) {
2601 bitmap
[1] &= ~FATTR4_WORD1_MODE
;
2603 dprintk("%s: file mode=0%o\n", __FUNCTION__
, (unsigned int)*mode
);
2607 static int decode_attr_nlink(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint32_t *nlink
)
2612 if (unlikely(bitmap
[1] & (FATTR4_WORD1_NUMLINKS
- 1U)))
2614 if (likely(bitmap
[1] & FATTR4_WORD1_NUMLINKS
)) {
2617 bitmap
[1] &= ~FATTR4_WORD1_NUMLINKS
;
2619 dprintk("%s: nlink=%u\n", __FUNCTION__
, (unsigned int)*nlink
);
2623 static int decode_attr_owner(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_client
*clp
, int32_t *uid
)
2628 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER
- 1U)))
2630 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER
)) {
2634 if (len
< XDR_MAX_NETOBJ
) {
2635 if (nfs_map_name_to_uid(clp
, (char *)p
, len
, uid
) != 0)
2636 dprintk("%s: nfs_map_name_to_uid failed!\n",
2639 printk(KERN_WARNING
"%s: name too long (%u)!\n",
2641 bitmap
[1] &= ~FATTR4_WORD1_OWNER
;
2643 dprintk("%s: uid=%d\n", __FUNCTION__
, (int)*uid
);
2647 static int decode_attr_group(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct nfs4_client
*clp
, int32_t *gid
)
2652 if (unlikely(bitmap
[1] & (FATTR4_WORD1_OWNER_GROUP
- 1U)))
2654 if (likely(bitmap
[1] & FATTR4_WORD1_OWNER_GROUP
)) {
2658 if (len
< XDR_MAX_NETOBJ
) {
2659 if (nfs_map_group_to_gid(clp
, (char *)p
, len
, gid
) != 0)
2660 dprintk("%s: nfs_map_group_to_gid failed!\n",
2663 printk(KERN_WARNING
"%s: name too long (%u)!\n",
2665 bitmap
[1] &= ~FATTR4_WORD1_OWNER_GROUP
;
2667 dprintk("%s: gid=%d\n", __FUNCTION__
, (int)*gid
);
2671 static int decode_attr_rdev(struct xdr_stream
*xdr
, uint32_t *bitmap
, dev_t
*rdev
)
2673 uint32_t major
= 0, minor
= 0, *p
;
2676 if (unlikely(bitmap
[1] & (FATTR4_WORD1_RAWDEV
- 1U)))
2678 if (likely(bitmap
[1] & FATTR4_WORD1_RAWDEV
)) {
2684 tmp
= MKDEV(major
, minor
);
2685 if (MAJOR(tmp
) == major
&& MINOR(tmp
) == minor
)
2687 bitmap
[1] &= ~ FATTR4_WORD1_RAWDEV
;
2689 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__
, major
, minor
);
2693 static int decode_attr_space_avail(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2699 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_AVAIL
- 1U)))
2701 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_AVAIL
)) {
2704 bitmap
[1] &= ~FATTR4_WORD1_SPACE_AVAIL
;
2706 dprintk("%s: space avail=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2710 static int decode_attr_space_free(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2716 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_FREE
- 1U)))
2718 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_FREE
)) {
2721 bitmap
[1] &= ~FATTR4_WORD1_SPACE_FREE
;
2723 dprintk("%s: space free=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2727 static int decode_attr_space_total(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *res
)
2733 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_TOTAL
- 1U)))
2735 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_TOTAL
)) {
2738 bitmap
[1] &= ~FATTR4_WORD1_SPACE_TOTAL
;
2740 dprintk("%s: space total=%Lu\n", __FUNCTION__
, (unsigned long long)*res
);
2744 static int decode_attr_space_used(struct xdr_stream
*xdr
, uint32_t *bitmap
, uint64_t *used
)
2749 if (unlikely(bitmap
[1] & (FATTR4_WORD1_SPACE_USED
- 1U)))
2751 if (likely(bitmap
[1] & FATTR4_WORD1_SPACE_USED
)) {
2754 bitmap
[1] &= ~FATTR4_WORD1_SPACE_USED
;
2756 dprintk("%s: space used=%Lu\n", __FUNCTION__
,
2757 (unsigned long long)*used
);
2761 static int decode_attr_time(struct xdr_stream
*xdr
, struct timespec
*time
)
2770 time
->tv_sec
= (time_t)sec
;
2771 time
->tv_nsec
= (long)nsec
;
2775 static int decode_attr_time_access(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
2781 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_ACCESS
- 1U)))
2783 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_ACCESS
)) {
2784 status
= decode_attr_time(xdr
, time
);
2785 bitmap
[1] &= ~FATTR4_WORD1_TIME_ACCESS
;
2787 dprintk("%s: atime=%ld\n", __FUNCTION__
, (long)time
->tv_sec
);
2791 static int decode_attr_time_metadata(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
2797 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_METADATA
- 1U)))
2799 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_METADATA
)) {
2800 status
= decode_attr_time(xdr
, time
);
2801 bitmap
[1] &= ~FATTR4_WORD1_TIME_METADATA
;
2803 dprintk("%s: ctime=%ld\n", __FUNCTION__
, (long)time
->tv_sec
);
2807 static int decode_attr_time_modify(struct xdr_stream
*xdr
, uint32_t *bitmap
, struct timespec
*time
)
2813 if (unlikely(bitmap
[1] & (FATTR4_WORD1_TIME_MODIFY
- 1U)))
2815 if (likely(bitmap
[1] & FATTR4_WORD1_TIME_MODIFY
)) {
2816 status
= decode_attr_time(xdr
, time
);
2817 bitmap
[1] &= ~FATTR4_WORD1_TIME_MODIFY
;
2819 dprintk("%s: mtime=%ld\n", __FUNCTION__
, (long)time
->tv_sec
);
2823 static int verify_attr_len(struct xdr_stream
*xdr
, uint32_t *savep
, uint32_t attrlen
)
2825 unsigned int attrwords
= XDR_QUADLEN(attrlen
);
2826 unsigned int nwords
= xdr
->p
- savep
;
2828 if (unlikely(attrwords
!= nwords
)) {
2829 printk(KERN_WARNING
"%s: server returned incorrect attribute length: %u %c %u\n",
2832 (attrwords
< nwords
) ? '<' : '>',
2839 static int decode_change_info(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
2844 READ32(cinfo
->atomic
);
2845 READ64(cinfo
->before
);
2846 READ64(cinfo
->after
);
2850 static int decode_access(struct xdr_stream
*xdr
, struct nfs4_accessres
*access
)
2856 status
= decode_op_hdr(xdr
, OP_ACCESS
);
2862 access
->supported
= supp
;
2863 access
->access
= acc
;
2867 static int decode_close(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
2872 status
= decode_op_hdr(xdr
, OP_CLOSE
);
2875 READ_BUF(sizeof(res
->stateid
.data
));
2876 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
2880 static int decode_commit(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
2885 status
= decode_op_hdr(xdr
, OP_COMMIT
);
2889 COPYMEM(res
->verf
->verifier
, 8);
2893 static int decode_create(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
2899 status
= decode_op_hdr(xdr
, OP_CREATE
);
2902 if ((status
= decode_change_info(xdr
, cinfo
)))
2906 READ_BUF(bmlen
<< 2);
2910 static int decode_server_caps(struct xdr_stream
*xdr
, struct nfs4_server_caps_res
*res
)
2917 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
2919 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
2921 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
2923 if ((status
= decode_attr_supported(xdr
, bitmap
, res
->attr_bitmask
)) != 0)
2925 if ((status
= decode_attr_link_support(xdr
, bitmap
, &res
->has_links
)) != 0)
2927 if ((status
= decode_attr_symlink_support(xdr
, bitmap
, &res
->has_symlinks
)) != 0)
2929 if ((status
= decode_attr_aclsupport(xdr
, bitmap
, &res
->acl_bitmask
)) != 0)
2931 status
= verify_attr_len(xdr
, savep
, attrlen
);
2933 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
2937 static int decode_statfs(struct xdr_stream
*xdr
, struct nfs_fsstat
*fsstat
)
2944 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
2946 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
2948 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
2951 if ((status
= decode_attr_files_avail(xdr
, bitmap
, &fsstat
->afiles
)) != 0)
2953 if ((status
= decode_attr_files_free(xdr
, bitmap
, &fsstat
->ffiles
)) != 0)
2955 if ((status
= decode_attr_files_total(xdr
, bitmap
, &fsstat
->tfiles
)) != 0)
2957 if ((status
= decode_attr_space_avail(xdr
, bitmap
, &fsstat
->abytes
)) != 0)
2959 if ((status
= decode_attr_space_free(xdr
, bitmap
, &fsstat
->fbytes
)) != 0)
2961 if ((status
= decode_attr_space_total(xdr
, bitmap
, &fsstat
->tbytes
)) != 0)
2964 status
= verify_attr_len(xdr
, savep
, attrlen
);
2966 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
2970 static int decode_pathconf(struct xdr_stream
*xdr
, struct nfs_pathconf
*pathconf
)
2977 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
2979 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
2981 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
2984 if ((status
= decode_attr_maxlink(xdr
, bitmap
, &pathconf
->max_link
)) != 0)
2986 if ((status
= decode_attr_maxname(xdr
, bitmap
, &pathconf
->max_namelen
)) != 0)
2989 status
= verify_attr_len(xdr
, savep
, attrlen
);
2991 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
2995 static int decode_getfattr(struct xdr_stream
*xdr
, struct nfs_fattr
*fattr
, const struct nfs_server
*server
)
3001 int status
, fmode
= 0;
3004 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3006 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3009 fattr
->bitmap
[0] = bitmap
[0];
3010 fattr
->bitmap
[1] = bitmap
[1];
3012 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3016 if ((status
= decode_attr_type(xdr
, bitmap
, &type
)) != 0)
3018 fattr
->type
= nfs_type2fmt
[type
].nfs2type
;
3019 fmode
= nfs_type2fmt
[type
].mode
;
3021 if ((status
= decode_attr_change(xdr
, bitmap
, &fattr
->change_attr
)) != 0)
3023 if ((status
= decode_attr_size(xdr
, bitmap
, &fattr
->size
)) != 0)
3025 if ((status
= decode_attr_fsid(xdr
, bitmap
, &fattr
->fsid
)) != 0)
3027 if ((status
= decode_attr_fileid(xdr
, bitmap
, &fattr
->fileid
)) != 0)
3029 if ((status
= decode_attr_fs_locations(xdr
, bitmap
, container_of(fattr
,
3030 struct nfs4_fs_locations
,
3033 if ((status
= decode_attr_mode(xdr
, bitmap
, &fattr
->mode
)) != 0)
3035 fattr
->mode
|= fmode
;
3036 if ((status
= decode_attr_nlink(xdr
, bitmap
, &fattr
->nlink
)) != 0)
3038 if ((status
= decode_attr_owner(xdr
, bitmap
, server
->nfs4_state
, &fattr
->uid
)) != 0)
3040 if ((status
= decode_attr_group(xdr
, bitmap
, server
->nfs4_state
, &fattr
->gid
)) != 0)
3042 if ((status
= decode_attr_rdev(xdr
, bitmap
, &fattr
->rdev
)) != 0)
3044 if ((status
= decode_attr_space_used(xdr
, bitmap
, &fattr
->du
.nfs3
.used
)) != 0)
3046 if ((status
= decode_attr_time_access(xdr
, bitmap
, &fattr
->atime
)) != 0)
3048 if ((status
= decode_attr_time_metadata(xdr
, bitmap
, &fattr
->ctime
)) != 0)
3050 if ((status
= decode_attr_time_modify(xdr
, bitmap
, &fattr
->mtime
)) != 0)
3052 if ((status
= decode_attr_mounted_on_fileid(xdr
, bitmap
, &fileid
)) != 0)
3054 if (fattr
->fileid
== 0 && fileid
!= 0)
3055 fattr
->fileid
= fileid
;
3056 if ((status
= verify_attr_len(xdr
, savep
, attrlen
)) == 0)
3057 fattr
->valid
= NFS_ATTR_FATTR
| NFS_ATTR_FATTR_V3
| NFS_ATTR_FATTR_V4
;
3059 dprintk("%s: xdr returned %d\n", __FUNCTION__
, -status
);
3064 static int decode_fsinfo(struct xdr_stream
*xdr
, struct nfs_fsinfo
*fsinfo
)
3067 uint32_t attrlen
, bitmap
[2];
3070 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3072 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3074 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3077 fsinfo
->rtmult
= fsinfo
->wtmult
= 512; /* ??? */
3079 if ((status
= decode_attr_lease_time(xdr
, bitmap
, &fsinfo
->lease_time
)) != 0)
3081 if ((status
= decode_attr_maxfilesize(xdr
, bitmap
, &fsinfo
->maxfilesize
)) != 0)
3083 if ((status
= decode_attr_maxread(xdr
, bitmap
, &fsinfo
->rtmax
)) != 0)
3085 fsinfo
->rtpref
= fsinfo
->dtpref
= fsinfo
->rtmax
;
3086 if ((status
= decode_attr_maxwrite(xdr
, bitmap
, &fsinfo
->wtmax
)) != 0)
3088 fsinfo
->wtpref
= fsinfo
->wtmax
;
3090 status
= verify_attr_len(xdr
, savep
, attrlen
);
3092 dprintk("%s: xdr returned %d!\n", __FUNCTION__
, -status
);
3096 static int decode_getfh(struct xdr_stream
*xdr
, struct nfs_fh
*fh
)
3102 status
= decode_op_hdr(xdr
, OP_GETFH
);
3105 /* Zero handle first to allow comparisons */
3106 memset(fh
, 0, sizeof(*fh
));
3110 if (len
> NFS4_FHSIZE
)
3114 COPYMEM(fh
->data
, len
);
3118 static int decode_link(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3122 status
= decode_op_hdr(xdr
, OP_LINK
);
3125 return decode_change_info(xdr
, cinfo
);
3129 * We create the owner, so we know a proper owner.id length is 4.
3131 static int decode_lock_denied (struct xdr_stream
*xdr
, struct file_lock
*fl
)
3133 uint64_t offset
, length
, clientid
;
3135 uint32_t namelen
, type
;
3142 fl
->fl_start
= (loff_t
)offset
;
3143 fl
->fl_end
= fl
->fl_start
+ (loff_t
)length
- 1;
3144 if (length
== ~(uint64_t)0)
3145 fl
->fl_end
= OFFSET_MAX
;
3146 fl
->fl_type
= F_WRLCK
;
3148 fl
->fl_type
= F_RDLCK
;
3154 return -NFS4ERR_DENIED
;
3157 static int decode_lock(struct xdr_stream
*xdr
, struct nfs_lock_res
*res
)
3162 status
= decode_op_hdr(xdr
, OP_LOCK
);
3164 READ_BUF(sizeof(res
->stateid
.data
));
3165 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
3166 } else if (status
== -NFS4ERR_DENIED
)
3167 return decode_lock_denied(xdr
, NULL
);
3171 static int decode_lockt(struct xdr_stream
*xdr
, struct nfs_lockt_res
*res
)
3174 status
= decode_op_hdr(xdr
, OP_LOCKT
);
3175 if (status
== -NFS4ERR_DENIED
)
3176 return decode_lock_denied(xdr
, res
->denied
);
3180 static int decode_locku(struct xdr_stream
*xdr
, struct nfs_locku_res
*res
)
3185 status
= decode_op_hdr(xdr
, OP_LOCKU
);
3187 READ_BUF(sizeof(res
->stateid
.data
));
3188 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
3193 static int decode_lookup(struct xdr_stream
*xdr
)
3195 return decode_op_hdr(xdr
, OP_LOOKUP
);
3198 /* This is too sick! */
3199 static int decode_space_limit(struct xdr_stream
*xdr
, u64
*maxsize
)
3202 uint32_t limit_type
, nblocks
, blocksize
;
3206 switch (limit_type
) {
3213 *maxsize
= (uint64_t)nblocks
* (uint64_t)blocksize
;
3218 static int decode_delegation(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
3221 uint32_t delegation_type
;
3224 READ32(delegation_type
);
3225 if (delegation_type
== NFS4_OPEN_DELEGATE_NONE
) {
3226 res
->delegation_type
= 0;
3230 COPYMEM(res
->delegation
.data
, sizeof(res
->delegation
.data
));
3231 READ32(res
->do_recall
);
3232 switch (delegation_type
) {
3233 case NFS4_OPEN_DELEGATE_READ
:
3234 res
->delegation_type
= FMODE_READ
;
3236 case NFS4_OPEN_DELEGATE_WRITE
:
3237 res
->delegation_type
= FMODE_WRITE
|FMODE_READ
;
3238 if (decode_space_limit(xdr
, &res
->maxsize
) < 0)
3241 return decode_ace(xdr
, NULL
, res
->server
->nfs4_state
);
3244 static int decode_open(struct xdr_stream
*xdr
, struct nfs_openres
*res
)
3250 status
= decode_op_hdr(xdr
, OP_OPEN
);
3253 READ_BUF(sizeof(res
->stateid
.data
));
3254 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
3256 decode_change_info(xdr
, &res
->cinfo
);
3259 READ32(res
->rflags
);
3264 READ_BUF(bmlen
<< 2);
3266 return decode_delegation(xdr
, res
);
3268 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__
, bmlen
);
3272 static int decode_open_confirm(struct xdr_stream
*xdr
, struct nfs_open_confirmres
*res
)
3277 status
= decode_op_hdr(xdr
, OP_OPEN_CONFIRM
);
3280 READ_BUF(sizeof(res
->stateid
.data
));
3281 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
3285 static int decode_open_downgrade(struct xdr_stream
*xdr
, struct nfs_closeres
*res
)
3290 status
= decode_op_hdr(xdr
, OP_OPEN_DOWNGRADE
);
3293 READ_BUF(sizeof(res
->stateid
.data
));
3294 COPYMEM(res
->stateid
.data
, sizeof(res
->stateid
.data
));
3298 static int decode_putfh(struct xdr_stream
*xdr
)
3300 return decode_op_hdr(xdr
, OP_PUTFH
);
3303 static int decode_putrootfh(struct xdr_stream
*xdr
)
3305 return decode_op_hdr(xdr
, OP_PUTROOTFH
);
3308 static int decode_read(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs_readres
*res
)
3310 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
3312 uint32_t count
, eof
, recvd
, hdrlen
;
3315 status
= decode_op_hdr(xdr
, OP_READ
);
3321 hdrlen
= (u8
*) p
- (u8
*) iov
->iov_base
;
3322 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
3323 if (count
> recvd
) {
3324 printk(KERN_WARNING
"NFS: server cheating in read reply: "
3325 "count %u > recvd %u\n", count
, recvd
);
3329 xdr_read_pages(xdr
, count
);
3335 static int decode_readdir(struct xdr_stream
*xdr
, struct rpc_rqst
*req
, struct nfs4_readdir_res
*readdir
)
3337 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
3338 struct page
*page
= *rcvbuf
->pages
;
3339 struct kvec
*iov
= rcvbuf
->head
;
3340 unsigned int nr
, pglen
= rcvbuf
->page_len
;
3341 uint32_t *end
, *entry
, *p
, *kaddr
;
3342 uint32_t len
, attrlen
;
3343 int hdrlen
, recvd
, status
;
3345 status
= decode_op_hdr(xdr
, OP_READDIR
);
3349 COPYMEM(readdir
->verifier
.data
, 8);
3350 dprintk("%s: verifier = 0x%x%x\n",
3352 ((u32
*)readdir
->verifier
.data
)[0],
3353 ((u32
*)readdir
->verifier
.data
)[1]);
3356 hdrlen
= (char *) p
- (char *) iov
->iov_base
;
3357 recvd
= rcvbuf
->len
- hdrlen
;
3360 xdr_read_pages(xdr
, pglen
);
3362 BUG_ON(pglen
+ readdir
->pgbase
> PAGE_CACHE_SIZE
);
3363 kaddr
= p
= (uint32_t *) kmap_atomic(page
, KM_USER0
);
3364 end
= (uint32_t *) ((char *)p
+ pglen
+ readdir
->pgbase
);
3366 for (nr
= 0; *p
++; nr
++) {
3369 dprintk("cookie = %Lu, ", *((unsigned long long *)p
));
3370 p
+= 2; /* cookie */
3371 len
= ntohl(*p
++); /* filename length */
3372 if (len
> NFS4_MAXNAMLEN
) {
3373 printk(KERN_WARNING
"NFS: giant filename in readdir (len 0x%x)\n", len
);
3376 dprintk("filename = %*s\n", len
, (char *)p
);
3377 p
+= XDR_QUADLEN(len
);
3380 len
= ntohl(*p
++); /* bitmap length */
3384 attrlen
= XDR_QUADLEN(ntohl(*p
++));
3385 p
+= attrlen
; /* attributes */
3390 if (!nr
&& (entry
[0] != 0 || entry
[1] == 0))
3393 kunmap_atomic(kaddr
, KM_USER0
);
3396 dprintk("%s: short packet at entry %d\n", __FUNCTION__
, nr
);
3397 entry
[0] = entry
[1] = 0;
3398 /* truncate listing ? */
3400 printk(KERN_NOTICE
"NFS: readdir reply truncated!\n");
3405 kunmap_atomic(kaddr
, KM_USER0
);
3406 return -errno_NFSERR_IO
;
3409 static int decode_readlink(struct xdr_stream
*xdr
, struct rpc_rqst
*req
)
3411 struct xdr_buf
*rcvbuf
= &req
->rq_rcv_buf
;
3412 struct kvec
*iov
= rcvbuf
->head
;
3413 int hdrlen
, len
, recvd
;
3418 status
= decode_op_hdr(xdr
, OP_READLINK
);
3422 /* Convert length of symlink */
3425 if (len
>= rcvbuf
->page_len
|| len
<= 0) {
3426 dprintk(KERN_WARNING
"nfs: server returned giant symlink!\n");
3427 return -ENAMETOOLONG
;
3429 hdrlen
= (char *) xdr
->p
- (char *) iov
->iov_base
;
3430 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
3432 printk(KERN_WARNING
"NFS: server cheating in readlink reply: "
3433 "count %u > recvd %u\n", len
, recvd
);
3436 xdr_read_pages(xdr
, len
);
3438 * The XDR encode routine has set things up so that
3439 * the link text will be copied directly into the
3440 * buffer. We just have to do overflow-checking,
3441 * and and null-terminate the text (the VFS expects
3442 * null-termination).
3444 kaddr
= (char *)kmap_atomic(rcvbuf
->pages
[0], KM_USER0
);
3445 kaddr
[len
+rcvbuf
->page_base
] = '\0';
3446 kunmap_atomic(kaddr
, KM_USER0
);
3450 static int decode_remove(struct xdr_stream
*xdr
, struct nfs4_change_info
*cinfo
)
3454 status
= decode_op_hdr(xdr
, OP_REMOVE
);
3457 status
= decode_change_info(xdr
, cinfo
);
3462 static int decode_rename(struct xdr_stream
*xdr
, struct nfs4_change_info
*old_cinfo
,
3463 struct nfs4_change_info
*new_cinfo
)
3467 status
= decode_op_hdr(xdr
, OP_RENAME
);
3470 if ((status
= decode_change_info(xdr
, old_cinfo
)))
3472 status
= decode_change_info(xdr
, new_cinfo
);
3477 static int decode_renew(struct xdr_stream
*xdr
)
3479 return decode_op_hdr(xdr
, OP_RENEW
);
3483 decode_restorefh(struct xdr_stream
*xdr
)
3485 return decode_op_hdr(xdr
, OP_RESTOREFH
);
3488 static int decode_getacl(struct xdr_stream
*xdr
, struct rpc_rqst
*req
,
3494 struct kvec
*iov
= req
->rq_rcv_buf
.head
;
3498 if ((status
= decode_op_hdr(xdr
, OP_GETATTR
)) != 0)
3500 if ((status
= decode_attr_bitmap(xdr
, bitmap
)) != 0)
3502 if ((status
= decode_attr_length(xdr
, &attrlen
, &savep
)) != 0)
3505 if (unlikely(bitmap
[0] & (FATTR4_WORD0_ACL
- 1U)))
3507 if (likely(bitmap
[0] & FATTR4_WORD0_ACL
)) {
3510 /* We ignore &savep and don't do consistency checks on
3511 * the attr length. Let userspace figure it out.... */
3512 hdrlen
= (u8
*)xdr
->p
- (u8
*)iov
->iov_base
;
3513 recvd
= req
->rq_rcv_buf
.len
- hdrlen
;
3514 if (attrlen
> recvd
) {
3515 printk(KERN_WARNING
"NFS: server cheating in getattr"
3516 " acl reply: attrlen %u > recvd %u\n",
3520 xdr_read_pages(xdr
, attrlen
);
3523 status
= -EOPNOTSUPP
;
3530 decode_savefh(struct xdr_stream
*xdr
)
3532 return decode_op_hdr(xdr
, OP_SAVEFH
);
3535 static int decode_setattr(struct xdr_stream
*xdr
, struct nfs_setattrres
*res
)
3542 status
= decode_op_hdr(xdr
, OP_SETATTR
);
3547 READ_BUF(bmlen
<< 2);
3551 static int decode_setclientid(struct xdr_stream
*xdr
, struct nfs4_client
*clp
)
3559 if (opnum
!= OP_SETCLIENTID
) {
3561 "nfs4_decode_setclientid: Server returned operation"
3566 if (nfserr
== NFS_OK
) {
3567 READ_BUF(8 + sizeof(clp
->cl_confirm
.data
));
3568 READ64(clp
->cl_clientid
);
3569 COPYMEM(clp
->cl_confirm
.data
, sizeof(clp
->cl_confirm
.data
));
3570 } else if (nfserr
== NFSERR_CLID_INUSE
) {
3573 /* skip netid string */
3578 /* skip uaddr string */
3582 return -NFSERR_CLID_INUSE
;
3584 return -nfs_stat_to_errno(nfserr
);
3589 static int decode_setclientid_confirm(struct xdr_stream
*xdr
)
3591 return decode_op_hdr(xdr
, OP_SETCLIENTID_CONFIRM
);
3594 static int decode_write(struct xdr_stream
*xdr
, struct nfs_writeres
*res
)
3599 status
= decode_op_hdr(xdr
, OP_WRITE
);
3605 READ32(res
->verf
->committed
);
3606 COPYMEM(res
->verf
->verifier
, 8);
3610 static int decode_delegreturn(struct xdr_stream
*xdr
)
3612 return decode_op_hdr(xdr
, OP_DELEGRETURN
);
3616 * Decode OPEN_DOWNGRADE response
3618 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_closeres
*res
)
3620 struct xdr_stream xdr
;
3621 struct compound_hdr hdr
;
3624 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3625 status
= decode_compound_hdr(&xdr
, &hdr
);
3628 status
= decode_putfh(&xdr
);
3631 status
= decode_open_downgrade(&xdr
, res
);
3634 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3640 * END OF "GENERIC" DECODE ROUTINES.
3644 * Decode ACCESS response
3646 static int nfs4_xdr_dec_access(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_accessres
*res
)
3648 struct xdr_stream xdr
;
3649 struct compound_hdr hdr
;
3652 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3653 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3655 if ((status
= decode_putfh(&xdr
)) == 0)
3656 status
= decode_access(&xdr
, res
);
3662 * Decode LOOKUP response
3664 static int nfs4_xdr_dec_lookup(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_lookup_res
*res
)
3666 struct xdr_stream xdr
;
3667 struct compound_hdr hdr
;
3670 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3671 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3673 if ((status
= decode_putfh(&xdr
)) != 0)
3675 if ((status
= decode_lookup(&xdr
)) != 0)
3677 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
3679 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3685 * Decode LOOKUP_ROOT response
3687 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_lookup_res
*res
)
3689 struct xdr_stream xdr
;
3690 struct compound_hdr hdr
;
3693 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3694 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3696 if ((status
= decode_putrootfh(&xdr
)) != 0)
3698 if ((status
= decode_getfh(&xdr
, res
->fh
)) == 0)
3699 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3705 * Decode REMOVE response
3707 static int nfs4_xdr_dec_remove(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_remove_res
*res
)
3709 struct xdr_stream xdr
;
3710 struct compound_hdr hdr
;
3713 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3714 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3716 if ((status
= decode_putfh(&xdr
)) != 0)
3718 if ((status
= decode_remove(&xdr
, &res
->cinfo
)) != 0)
3720 decode_getfattr(&xdr
, res
->dir_attr
, res
->server
);
3726 * Decode RENAME response
3728 static int nfs4_xdr_dec_rename(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_rename_res
*res
)
3730 struct xdr_stream xdr
;
3731 struct compound_hdr hdr
;
3734 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3735 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3737 if ((status
= decode_putfh(&xdr
)) != 0)
3739 if ((status
= decode_savefh(&xdr
)) != 0)
3741 if ((status
= decode_putfh(&xdr
)) != 0)
3743 if ((status
= decode_rename(&xdr
, &res
->old_cinfo
, &res
->new_cinfo
)) != 0)
3745 /* Current FH is target directory */
3746 if (decode_getfattr(&xdr
, res
->new_fattr
, res
->server
) != 0)
3748 if ((status
= decode_restorefh(&xdr
)) != 0)
3750 decode_getfattr(&xdr
, res
->old_fattr
, res
->server
);
3756 * Decode LINK response
3758 static int nfs4_xdr_dec_link(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_link_res
*res
)
3760 struct xdr_stream xdr
;
3761 struct compound_hdr hdr
;
3764 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3765 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3767 if ((status
= decode_putfh(&xdr
)) != 0)
3769 if ((status
= decode_savefh(&xdr
)) != 0)
3771 if ((status
= decode_putfh(&xdr
)) != 0)
3773 if ((status
= decode_link(&xdr
, &res
->cinfo
)) != 0)
3776 * Note order: OP_LINK leaves the directory as the current
3779 if (decode_getfattr(&xdr
, res
->dir_attr
, res
->server
) != 0)
3781 if ((status
= decode_restorefh(&xdr
)) != 0)
3783 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3789 * Decode CREATE response
3791 static int nfs4_xdr_dec_create(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_create_res
*res
)
3793 struct xdr_stream xdr
;
3794 struct compound_hdr hdr
;
3797 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3798 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
3800 if ((status
= decode_putfh(&xdr
)) != 0)
3802 if ((status
= decode_savefh(&xdr
)) != 0)
3804 if ((status
= decode_create(&xdr
,&res
->dir_cinfo
)) != 0)
3806 if ((status
= decode_getfh(&xdr
, res
->fh
)) != 0)
3808 if (decode_getfattr(&xdr
, res
->fattr
, res
->server
) != 0)
3810 if ((status
= decode_restorefh(&xdr
)) != 0)
3812 decode_getfattr(&xdr
, res
->dir_fattr
, res
->server
);
3818 * Decode SYMLINK response
3820 static int nfs4_xdr_dec_symlink(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_create_res
*res
)
3822 return nfs4_xdr_dec_create(rqstp
, p
, res
);
3826 * Decode GETATTR response
3828 static int nfs4_xdr_dec_getattr(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_getattr_res
*res
)
3830 struct xdr_stream xdr
;
3831 struct compound_hdr hdr
;
3834 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3835 status
= decode_compound_hdr(&xdr
, &hdr
);
3838 status
= decode_putfh(&xdr
);
3841 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3848 * Encode an SETACL request
3851 nfs4_xdr_enc_setacl(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_setaclargs
*args
)
3853 struct xdr_stream xdr
;
3854 struct compound_hdr hdr
= {
3859 xdr_init_encode(&xdr
, &req
->rq_snd_buf
, p
);
3860 encode_compound_hdr(&xdr
, &hdr
);
3861 status
= encode_putfh(&xdr
, args
->fh
);
3864 status
= encode_setacl(&xdr
, args
);
3869 * Decode SETACL response
3872 nfs4_xdr_dec_setacl(struct rpc_rqst
*rqstp
, uint32_t *p
, void *res
)
3874 struct xdr_stream xdr
;
3875 struct compound_hdr hdr
;
3878 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3879 status
= decode_compound_hdr(&xdr
, &hdr
);
3882 status
= decode_putfh(&xdr
);
3885 status
= decode_setattr(&xdr
, res
);
3891 * Decode GETACL response
3894 nfs4_xdr_dec_getacl(struct rpc_rqst
*rqstp
, uint32_t *p
, size_t *acl_len
)
3896 struct xdr_stream xdr
;
3897 struct compound_hdr hdr
;
3900 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3901 status
= decode_compound_hdr(&xdr
, &hdr
);
3904 status
= decode_putfh(&xdr
);
3907 status
= decode_getacl(&xdr
, rqstp
, acl_len
);
3914 * Decode CLOSE response
3916 static int nfs4_xdr_dec_close(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_closeres
*res
)
3918 struct xdr_stream xdr
;
3919 struct compound_hdr hdr
;
3922 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3923 status
= decode_compound_hdr(&xdr
, &hdr
);
3926 status
= decode_putfh(&xdr
);
3929 status
= decode_close(&xdr
, res
);
3933 * Note: Server may do delete on close for this file
3934 * in which case the getattr call will fail with
3935 * an ESTALE error. Shouldn't be a problem,
3936 * though, since fattr->valid will remain unset.
3938 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
3944 * Decode OPEN response
3946 static int nfs4_xdr_dec_open(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_openres
*res
)
3948 struct xdr_stream xdr
;
3949 struct compound_hdr hdr
;
3952 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3953 status
= decode_compound_hdr(&xdr
, &hdr
);
3956 status
= decode_putfh(&xdr
);
3959 status
= decode_savefh(&xdr
);
3962 status
= decode_open(&xdr
, res
);
3965 status
= decode_getfh(&xdr
, &res
->fh
);
3968 if (decode_getfattr(&xdr
, res
->f_attr
, res
->server
) != 0)
3970 if ((status
= decode_restorefh(&xdr
)) != 0)
3972 decode_getfattr(&xdr
, res
->dir_attr
, res
->server
);
3978 * Decode OPEN_CONFIRM response
3980 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_open_confirmres
*res
)
3982 struct xdr_stream xdr
;
3983 struct compound_hdr hdr
;
3986 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
3987 status
= decode_compound_hdr(&xdr
, &hdr
);
3990 status
= decode_putfh(&xdr
);
3993 status
= decode_open_confirm(&xdr
, res
);
3999 * Decode OPEN response
4001 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_openres
*res
)
4003 struct xdr_stream xdr
;
4004 struct compound_hdr hdr
;
4007 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4008 status
= decode_compound_hdr(&xdr
, &hdr
);
4011 status
= decode_putfh(&xdr
);
4014 status
= decode_open(&xdr
, res
);
4017 decode_getfattr(&xdr
, res
->f_attr
, res
->server
);
4023 * Decode SETATTR response
4025 static int nfs4_xdr_dec_setattr(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_setattrres
*res
)
4027 struct xdr_stream xdr
;
4028 struct compound_hdr hdr
;
4031 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4032 status
= decode_compound_hdr(&xdr
, &hdr
);
4035 status
= decode_putfh(&xdr
);
4038 status
= decode_setattr(&xdr
, res
);
4041 status
= decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4042 if (status
== NFS4ERR_DELAY
)
4049 * Decode LOCK response
4051 static int nfs4_xdr_dec_lock(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_lock_res
*res
)
4053 struct xdr_stream xdr
;
4054 struct compound_hdr hdr
;
4057 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4058 status
= decode_compound_hdr(&xdr
, &hdr
);
4061 status
= decode_putfh(&xdr
);
4064 status
= decode_lock(&xdr
, res
);
4070 * Decode LOCKT response
4072 static int nfs4_xdr_dec_lockt(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_lockt_res
*res
)
4074 struct xdr_stream xdr
;
4075 struct compound_hdr hdr
;
4078 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4079 status
= decode_compound_hdr(&xdr
, &hdr
);
4082 status
= decode_putfh(&xdr
);
4085 status
= decode_lockt(&xdr
, res
);
4091 * Decode LOCKU response
4093 static int nfs4_xdr_dec_locku(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_locku_res
*res
)
4095 struct xdr_stream xdr
;
4096 struct compound_hdr hdr
;
4099 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4100 status
= decode_compound_hdr(&xdr
, &hdr
);
4103 status
= decode_putfh(&xdr
);
4106 status
= decode_locku(&xdr
, res
);
4112 * Decode READLINK response
4114 static int nfs4_xdr_dec_readlink(struct rpc_rqst
*rqstp
, uint32_t *p
, void *res
)
4116 struct xdr_stream xdr
;
4117 struct compound_hdr hdr
;
4120 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4121 status
= decode_compound_hdr(&xdr
, &hdr
);
4124 status
= decode_putfh(&xdr
);
4127 status
= decode_readlink(&xdr
, rqstp
);
4133 * Decode READDIR response
4135 static int nfs4_xdr_dec_readdir(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_readdir_res
*res
)
4137 struct xdr_stream xdr
;
4138 struct compound_hdr hdr
;
4141 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4142 status
= decode_compound_hdr(&xdr
, &hdr
);
4145 status
= decode_putfh(&xdr
);
4148 status
= decode_readdir(&xdr
, rqstp
, res
);
4154 * Decode Read response
4156 static int nfs4_xdr_dec_read(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_readres
*res
)
4158 struct xdr_stream xdr
;
4159 struct compound_hdr hdr
;
4162 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4163 status
= decode_compound_hdr(&xdr
, &hdr
);
4166 status
= decode_putfh(&xdr
);
4169 status
= decode_read(&xdr
, rqstp
, res
);
4171 status
= res
->count
;
4177 * Decode WRITE response
4179 static int nfs4_xdr_dec_write(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_writeres
*res
)
4181 struct xdr_stream xdr
;
4182 struct compound_hdr hdr
;
4185 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4186 status
= decode_compound_hdr(&xdr
, &hdr
);
4189 status
= decode_putfh(&xdr
);
4192 status
= decode_write(&xdr
, res
);
4195 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4197 status
= res
->count
;
4203 * Decode COMMIT response
4205 static int nfs4_xdr_dec_commit(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs_writeres
*res
)
4207 struct xdr_stream xdr
;
4208 struct compound_hdr hdr
;
4211 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4212 status
= decode_compound_hdr(&xdr
, &hdr
);
4215 status
= decode_putfh(&xdr
);
4218 status
= decode_commit(&xdr
, res
);
4221 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4229 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_fsinfo
*fsinfo
)
4231 struct xdr_stream xdr
;
4232 struct compound_hdr hdr
;
4235 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4236 status
= decode_compound_hdr(&xdr
, &hdr
);
4238 status
= decode_putfh(&xdr
);
4240 status
= decode_fsinfo(&xdr
, fsinfo
);
4242 status
= -nfs_stat_to_errno(hdr
.status
);
4249 static int nfs4_xdr_dec_pathconf(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_pathconf
*pathconf
)
4251 struct xdr_stream xdr
;
4252 struct compound_hdr hdr
;
4255 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4256 status
= decode_compound_hdr(&xdr
, &hdr
);
4258 status
= decode_putfh(&xdr
);
4260 status
= decode_pathconf(&xdr
, pathconf
);
4267 static int nfs4_xdr_dec_statfs(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_fsstat
*fsstat
)
4269 struct xdr_stream xdr
;
4270 struct compound_hdr hdr
;
4273 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4274 status
= decode_compound_hdr(&xdr
, &hdr
);
4276 status
= decode_putfh(&xdr
);
4278 status
= decode_statfs(&xdr
, fsstat
);
4283 * GETATTR_BITMAP request
4285 static int nfs4_xdr_dec_server_caps(struct rpc_rqst
*req
, uint32_t *p
, struct nfs4_server_caps_res
*res
)
4287 struct xdr_stream xdr
;
4288 struct compound_hdr hdr
;
4291 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4292 if ((status
= decode_compound_hdr(&xdr
, &hdr
)) != 0)
4294 if ((status
= decode_putfh(&xdr
)) != 0)
4296 status
= decode_server_caps(&xdr
, res
);
4302 * Decode RENEW response
4304 static int nfs4_xdr_dec_renew(struct rpc_rqst
*rqstp
, uint32_t *p
, void *dummy
)
4306 struct xdr_stream xdr
;
4307 struct compound_hdr hdr
;
4310 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4311 status
= decode_compound_hdr(&xdr
, &hdr
);
4313 status
= decode_renew(&xdr
);
4318 * a SETCLIENTID request
4320 static int nfs4_xdr_dec_setclientid(struct rpc_rqst
*req
, uint32_t *p
,
4321 struct nfs4_client
*clp
)
4323 struct xdr_stream xdr
;
4324 struct compound_hdr hdr
;
4327 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4328 status
= decode_compound_hdr(&xdr
, &hdr
);
4330 status
= decode_setclientid(&xdr
, clp
);
4332 status
= -nfs_stat_to_errno(hdr
.status
);
4337 * a SETCLIENTID_CONFIRM request
4339 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst
*req
, uint32_t *p
, struct nfs_fsinfo
*fsinfo
)
4341 struct xdr_stream xdr
;
4342 struct compound_hdr hdr
;
4345 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4346 status
= decode_compound_hdr(&xdr
, &hdr
);
4348 status
= decode_setclientid_confirm(&xdr
);
4350 status
= decode_putrootfh(&xdr
);
4352 status
= decode_fsinfo(&xdr
, fsinfo
);
4354 status
= -nfs_stat_to_errno(hdr
.status
);
4359 * DELEGRETURN request
4361 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst
*rqstp
, uint32_t *p
, struct nfs4_delegreturnres
*res
)
4363 struct xdr_stream xdr
;
4364 struct compound_hdr hdr
;
4367 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, p
);
4368 status
= decode_compound_hdr(&xdr
, &hdr
);
4371 status
= decode_putfh(&xdr
);
4374 status
= decode_delegreturn(&xdr
);
4375 decode_getfattr(&xdr
, res
->fattr
, res
->server
);
4381 * FS_LOCATIONS request
4383 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst
*req
, uint32_t *p
, struct nfs4_fs_locations
*res
)
4385 struct xdr_stream xdr
;
4386 struct compound_hdr hdr
;
4389 xdr_init_decode(&xdr
, &req
->rq_rcv_buf
, p
);
4390 status
= decode_compound_hdr(&xdr
, &hdr
);
4393 if ((status
= decode_putfh(&xdr
)) != 0)
4395 if ((status
= decode_lookup(&xdr
)) != 0)
4397 xdr_enter_page(&xdr
, PAGE_SIZE
);
4398 status
= decode_getfattr(&xdr
, &res
->fattr
, res
->server
);
4403 uint32_t *nfs4_decode_dirent(uint32_t *p
, struct nfs_entry
*entry
, int plus
)
4405 uint32_t bitmap
[2] = {0};
4410 return ERR_PTR(-EAGAIN
);
4412 return ERR_PTR(-EBADCOOKIE
);
4415 entry
->prev_cookie
= entry
->cookie
;
4416 p
= xdr_decode_hyper(p
, &entry
->cookie
);
4417 entry
->len
= ntohl(*p
++);
4418 entry
->name
= (const char *) p
;
4419 p
+= XDR_QUADLEN(entry
->len
);
4422 * In case the server doesn't return an inode number,
4423 * we fake one here. (We don't use inode number 0,
4424 * since glibc seems to choke on it...)
4428 len
= ntohl(*p
++); /* bitmap length */
4430 bitmap
[0] = ntohl(*p
++);
4432 bitmap
[1] = ntohl(*p
++);
4436 len
= XDR_QUADLEN(ntohl(*p
++)); /* attribute buffer length */
4438 if (bitmap
[0] & FATTR4_WORD0_RDATTR_ERROR
) {
4439 bitmap
[0] &= ~FATTR4_WORD0_RDATTR_ERROR
;
4440 /* Ignore the return value of rdattr_error for now */
4444 if (bitmap
[0] == 0 && bitmap
[1] == FATTR4_WORD1_MOUNTED_ON_FILEID
)
4445 xdr_decode_hyper(p
, &entry
->ino
);
4446 else if (bitmap
[0] == FATTR4_WORD0_FILEID
)
4447 xdr_decode_hyper(p
, &entry
->ino
);
4451 entry
->eof
= !p
[0] && p
[1];
4456 * We need to translate between nfs status return values and
4457 * the local errno values which may not be the same.
4464 { NFS4ERR_PERM
, EPERM
},
4465 { NFS4ERR_NOENT
, ENOENT
},
4466 { NFS4ERR_IO
, errno_NFSERR_IO
},
4467 { NFS4ERR_NXIO
, ENXIO
},
4468 { NFS4ERR_ACCESS
, EACCES
},
4469 { NFS4ERR_EXIST
, EEXIST
},
4470 { NFS4ERR_XDEV
, EXDEV
},
4471 { NFS4ERR_NOTDIR
, ENOTDIR
},
4472 { NFS4ERR_ISDIR
, EISDIR
},
4473 { NFS4ERR_INVAL
, EINVAL
},
4474 { NFS4ERR_FBIG
, EFBIG
},
4475 { NFS4ERR_NOSPC
, ENOSPC
},
4476 { NFS4ERR_ROFS
, EROFS
},
4477 { NFS4ERR_MLINK
, EMLINK
},
4478 { NFS4ERR_NAMETOOLONG
, ENAMETOOLONG
},
4479 { NFS4ERR_NOTEMPTY
, ENOTEMPTY
},
4480 { NFS4ERR_DQUOT
, EDQUOT
},
4481 { NFS4ERR_STALE
, ESTALE
},
4482 { NFS4ERR_BADHANDLE
, EBADHANDLE
},
4483 { NFS4ERR_BADOWNER
, EINVAL
},
4484 { NFS4ERR_BADNAME
, EINVAL
},
4485 { NFS4ERR_BAD_COOKIE
, EBADCOOKIE
},
4486 { NFS4ERR_NOTSUPP
, ENOTSUPP
},
4487 { NFS4ERR_TOOSMALL
, ETOOSMALL
},
4488 { NFS4ERR_SERVERFAULT
, ESERVERFAULT
},
4489 { NFS4ERR_BADTYPE
, EBADTYPE
},
4490 { NFS4ERR_LOCKED
, EAGAIN
},
4491 { NFS4ERR_RESOURCE
, EREMOTEIO
},
4492 { NFS4ERR_SYMLINK
, ELOOP
},
4493 { NFS4ERR_OP_ILLEGAL
, EOPNOTSUPP
},
4494 { NFS4ERR_DEADLOCK
, EDEADLK
},
4495 { NFS4ERR_WRONGSEC
, EPERM
}, /* FIXME: this needs
4496 * to be handled by a
4503 * Convert an NFS error code to a local one.
4504 * This one is used jointly by NFSv2 and NFSv3.
4507 nfs_stat_to_errno(int stat
)
4510 for (i
= 0; nfs_errtbl
[i
].stat
!= -1; i
++) {
4511 if (nfs_errtbl
[i
].stat
== stat
)
4512 return nfs_errtbl
[i
].errno
;
4514 if (stat
<= 10000 || stat
> 10100) {
4515 /* The server is looney tunes. */
4516 return ESERVERFAULT
;
4518 /* If we cannot translate the error, the recovery routines should
4520 * Note: remaining NFSv4 error codes have values > 10000, so should
4521 * not conflict with native Linux error codes.
4527 # define MAX(a, b) (((a) > (b))? (a) : (b))
4530 #define PROC(proc, argtype, restype) \
4531 [NFSPROC4_CLNT_##proc] = { \
4532 .p_proc = NFSPROC4_COMPOUND, \
4533 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4534 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4535 .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
4536 .p_statidx = NFSPROC4_CLNT_##proc, \
4540 struct rpc_procinfo nfs4_procedures
[] = {
4541 PROC(READ
, enc_read
, dec_read
),
4542 PROC(WRITE
, enc_write
, dec_write
),
4543 PROC(COMMIT
, enc_commit
, dec_commit
),
4544 PROC(OPEN
, enc_open
, dec_open
),
4545 PROC(OPEN_CONFIRM
, enc_open_confirm
, dec_open_confirm
),
4546 PROC(OPEN_NOATTR
, enc_open_noattr
, dec_open_noattr
),
4547 PROC(OPEN_DOWNGRADE
, enc_open_downgrade
, dec_open_downgrade
),
4548 PROC(CLOSE
, enc_close
, dec_close
),
4549 PROC(SETATTR
, enc_setattr
, dec_setattr
),
4550 PROC(FSINFO
, enc_fsinfo
, dec_fsinfo
),
4551 PROC(RENEW
, enc_renew
, dec_renew
),
4552 PROC(SETCLIENTID
, enc_setclientid
, dec_setclientid
),
4553 PROC(SETCLIENTID_CONFIRM
, enc_setclientid_confirm
, dec_setclientid_confirm
),
4554 PROC(LOCK
, enc_lock
, dec_lock
),
4555 PROC(LOCKT
, enc_lockt
, dec_lockt
),
4556 PROC(LOCKU
, enc_locku
, dec_locku
),
4557 PROC(ACCESS
, enc_access
, dec_access
),
4558 PROC(GETATTR
, enc_getattr
, dec_getattr
),
4559 PROC(LOOKUP
, enc_lookup
, dec_lookup
),
4560 PROC(LOOKUP_ROOT
, enc_lookup_root
, dec_lookup_root
),
4561 PROC(REMOVE
, enc_remove
, dec_remove
),
4562 PROC(RENAME
, enc_rename
, dec_rename
),
4563 PROC(LINK
, enc_link
, dec_link
),
4564 PROC(SYMLINK
, enc_symlink
, dec_symlink
),
4565 PROC(CREATE
, enc_create
, dec_create
),
4566 PROC(PATHCONF
, enc_pathconf
, dec_pathconf
),
4567 PROC(STATFS
, enc_statfs
, dec_statfs
),
4568 PROC(READLINK
, enc_readlink
, dec_readlink
),
4569 PROC(READDIR
, enc_readdir
, dec_readdir
),
4570 PROC(SERVER_CAPS
, enc_server_caps
, dec_server_caps
),
4571 PROC(DELEGRETURN
, enc_delegreturn
, dec_delegreturn
),
4572 PROC(GETACL
, enc_getacl
, dec_getacl
),
4573 PROC(SETACL
, enc_setacl
, dec_setacl
),
4574 PROC(FS_LOCATIONS
, enc_fs_locations
, dec_fs_locations
),
4577 struct rpc_version nfs_version4
= {
4579 .nrprocs
= ARRAY_SIZE(nfs4_procedures
),
4580 .procs
= nfs4_procedures