4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
46 #include <linux/pagemap.h>
47 #include <linux/proc_fs.h>
48 #include <linux/kdev_t.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs4_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define open_owner_id_maxsz (1 + 4)
74 #define lock_owner_id_maxsz (1 + 4)
75 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
76 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78 #define op_encode_hdr_maxsz (1)
79 #define op_decode_hdr_maxsz (2)
80 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
84 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
86 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
87 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
90 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
92 #define nfs4_fattr_bitmap_maxsz 3
93 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
94 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
96 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98 /* This is based on getfattr, which uses the most attributes: */
99 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
101 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
104 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
110 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
111 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
113 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
114 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116 #define decode_renew_maxsz (op_decode_hdr_maxsz)
117 #define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
125 #define decode_setclientid_maxsz \
126 (op_decode_hdr_maxsz + \
128 1024) /* large value for CLID_INUSE */
129 #define encode_setclientid_confirm_maxsz \
130 (op_encode_hdr_maxsz + \
131 3 + (NFS4_VERIFIER_SIZE >> 2))
132 #define decode_setclientid_confirm_maxsz \
133 (op_decode_hdr_maxsz)
134 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
136 #define encode_share_access_maxsz \
138 #define encode_createmode_maxsz (1 + encode_attrs_maxsz)
139 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141 #define encode_open_maxsz (op_encode_hdr_maxsz + \
142 2 + encode_share_access_maxsz + 2 + \
143 open_owner_id_maxsz + \
144 encode_opentype_maxsz + \
145 encode_claim_null_maxsz)
146 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
147 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
149 #define decode_change_info_maxsz (5)
150 #define decode_open_maxsz (op_decode_hdr_maxsz + \
151 decode_stateid_maxsz + \
152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
155 #define encode_open_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 encode_stateid_maxsz + 1)
158 #define decode_open_confirm_maxsz \
159 (op_decode_hdr_maxsz + \
160 decode_stateid_maxsz)
161 #define encode_open_downgrade_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1 + \
164 encode_share_access_maxsz)
165 #define decode_open_downgrade_maxsz \
166 (op_decode_hdr_maxsz + \
167 decode_stateid_maxsz)
168 #define encode_close_maxsz (op_encode_hdr_maxsz + \
169 1 + encode_stateid_maxsz)
170 #define decode_close_maxsz (op_decode_hdr_maxsz + \
171 decode_stateid_maxsz)
172 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + \
175 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
176 nfs4_fattr_bitmap_maxsz)
177 #define encode_read_maxsz (op_encode_hdr_maxsz + \
178 encode_stateid_maxsz + 3)
179 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
180 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
181 2 + encode_verifier_maxsz + 5)
182 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
183 decode_verifier_maxsz)
184 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
185 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
186 #define encode_write_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 4)
188 #define decode_write_maxsz (op_decode_hdr_maxsz + \
189 2 + decode_verifier_maxsz)
190 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
191 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
192 decode_verifier_maxsz)
193 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
195 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
196 decode_change_info_maxsz)
197 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
199 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
200 decode_change_info_maxsz + \
201 decode_change_info_maxsz)
202 #define encode_link_maxsz (op_encode_hdr_maxsz + \
204 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
205 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
207 1 + encode_stateid_maxsz + 8)
208 #define decode_lock_denied_maxsz \
209 (8 + decode_lockowner_maxsz)
210 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
211 decode_lock_denied_maxsz)
212 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
213 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
215 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
216 encode_stateid_maxsz + \
218 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
219 decode_stateid_maxsz)
220 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
221 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
222 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
223 1 + nfs4_name_maxsz + \
226 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
227 #define encode_create_maxsz (op_encode_hdr_maxsz + \
228 1 + 2 + nfs4_name_maxsz + \
230 #define decode_create_maxsz (op_decode_hdr_maxsz + \
231 decode_change_info_maxsz + \
232 nfs4_fattr_bitmap_maxsz)
233 #define encode_statfs_maxsz (encode_getattr_maxsz)
234 #define decode_statfs_maxsz (decode_getattr_maxsz)
235 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
236 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
237 #define encode_getacl_maxsz (encode_getattr_maxsz)
238 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
239 nfs4_fattr_bitmap_maxsz + 1)
240 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
241 encode_stateid_maxsz + 3)
242 #define decode_setacl_maxsz (decode_setattr_maxsz)
243 #define encode_fs_locations_maxsz \
244 (encode_getattr_maxsz)
245 #define decode_fs_locations_maxsz \
247 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
248 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
249 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
250 encode_putfh_maxsz + \
252 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
253 decode_putfh_maxsz + \
255 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
256 encode_putfh_maxsz + \
257 encode_readlink_maxsz)
258 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
259 decode_putfh_maxsz + \
260 decode_readlink_maxsz)
261 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
262 encode_putfh_maxsz + \
263 encode_readdir_maxsz)
264 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
265 decode_putfh_maxsz + \
266 decode_readdir_maxsz)
267 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
268 encode_putfh_maxsz + \
269 encode_write_maxsz + \
270 encode_getattr_maxsz)
271 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
272 decode_putfh_maxsz + \
273 decode_write_maxsz + \
274 decode_getattr_maxsz)
275 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
276 encode_putfh_maxsz + \
277 encode_commit_maxsz + \
278 encode_getattr_maxsz)
279 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
280 decode_putfh_maxsz + \
281 decode_commit_maxsz + \
282 decode_getattr_maxsz)
283 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
284 encode_putfh_maxsz + \
285 encode_savefh_maxsz + \
286 encode_open_maxsz + \
287 encode_getfh_maxsz + \
288 encode_getattr_maxsz + \
289 encode_restorefh_maxsz + \
290 encode_getattr_maxsz)
291 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
292 decode_putfh_maxsz + \
293 decode_savefh_maxsz + \
294 decode_open_maxsz + \
295 decode_getfh_maxsz + \
296 decode_getattr_maxsz + \
297 decode_restorefh_maxsz + \
298 decode_getattr_maxsz)
299 #define NFS4_enc_open_confirm_sz \
300 (compound_encode_hdr_maxsz + \
301 encode_putfh_maxsz + \
302 encode_open_confirm_maxsz)
303 #define NFS4_dec_open_confirm_sz \
304 (compound_decode_hdr_maxsz + \
305 decode_putfh_maxsz + \
306 decode_open_confirm_maxsz)
307 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
308 encode_putfh_maxsz + \
309 encode_open_maxsz + \
310 encode_getattr_maxsz)
311 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
312 decode_putfh_maxsz + \
313 decode_open_maxsz + \
314 decode_getattr_maxsz)
315 #define NFS4_enc_open_downgrade_sz \
316 (compound_encode_hdr_maxsz + \
317 encode_putfh_maxsz + \
318 encode_open_downgrade_maxsz + \
319 encode_getattr_maxsz)
320 #define NFS4_dec_open_downgrade_sz \
321 (compound_decode_hdr_maxsz + \
322 decode_putfh_maxsz + \
323 decode_open_downgrade_maxsz + \
324 decode_getattr_maxsz)
325 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
326 encode_putfh_maxsz + \
327 encode_close_maxsz + \
328 encode_getattr_maxsz)
329 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
330 decode_putfh_maxsz + \
331 decode_close_maxsz + \
332 decode_getattr_maxsz)
333 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
334 encode_putfh_maxsz + \
335 encode_setattr_maxsz + \
336 encode_getattr_maxsz)
337 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
338 decode_putfh_maxsz + \
339 decode_setattr_maxsz + \
340 decode_getattr_maxsz)
341 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
342 encode_putfh_maxsz + \
344 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
345 decode_putfh_maxsz + \
347 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
349 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
351 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
352 encode_setclientid_maxsz)
353 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
354 decode_setclientid_maxsz)
355 #define NFS4_enc_setclientid_confirm_sz \
356 (compound_encode_hdr_maxsz + \
357 encode_setclientid_confirm_maxsz + \
358 encode_putrootfh_maxsz + \
360 #define NFS4_dec_setclientid_confirm_sz \
361 (compound_decode_hdr_maxsz + \
362 decode_setclientid_confirm_maxsz + \
363 decode_putrootfh_maxsz + \
365 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
366 encode_putfh_maxsz + \
368 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
369 decode_putfh_maxsz + \
371 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
372 encode_putfh_maxsz + \
374 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
375 decode_putfh_maxsz + \
377 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
378 encode_putfh_maxsz + \
380 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
381 decode_putfh_maxsz + \
383 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
384 encode_putfh_maxsz + \
385 encode_access_maxsz + \
386 encode_getattr_maxsz)
387 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
388 decode_putfh_maxsz + \
389 decode_access_maxsz + \
390 decode_getattr_maxsz)
391 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
392 encode_putfh_maxsz + \
393 encode_getattr_maxsz)
394 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
395 decode_putfh_maxsz + \
396 decode_getattr_maxsz)
397 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
398 encode_putfh_maxsz + \
399 encode_lookup_maxsz + \
400 encode_getattr_maxsz + \
402 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
403 decode_putfh_maxsz + \
404 decode_lookup_maxsz + \
405 decode_getattr_maxsz + \
407 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
408 encode_putrootfh_maxsz + \
409 encode_getattr_maxsz + \
411 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
412 decode_putrootfh_maxsz + \
413 decode_getattr_maxsz + \
415 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
416 encode_putfh_maxsz + \
417 encode_remove_maxsz + \
418 encode_getattr_maxsz)
419 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
420 decode_putfh_maxsz + \
421 decode_remove_maxsz + \
422 decode_getattr_maxsz)
423 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
424 encode_putfh_maxsz + \
425 encode_savefh_maxsz + \
426 encode_putfh_maxsz + \
427 encode_rename_maxsz + \
428 encode_getattr_maxsz + \
429 encode_restorefh_maxsz + \
430 encode_getattr_maxsz)
431 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
432 decode_putfh_maxsz + \
433 decode_savefh_maxsz + \
434 decode_putfh_maxsz + \
435 decode_rename_maxsz + \
436 decode_getattr_maxsz + \
437 decode_restorefh_maxsz + \
438 decode_getattr_maxsz)
439 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
440 encode_putfh_maxsz + \
441 encode_savefh_maxsz + \
442 encode_putfh_maxsz + \
443 encode_link_maxsz + \
444 decode_getattr_maxsz + \
445 encode_restorefh_maxsz + \
446 decode_getattr_maxsz)
447 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
448 decode_putfh_maxsz + \
449 decode_savefh_maxsz + \
450 decode_putfh_maxsz + \
451 decode_link_maxsz + \
452 decode_getattr_maxsz + \
453 decode_restorefh_maxsz + \
454 decode_getattr_maxsz)
455 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
456 encode_putfh_maxsz + \
457 encode_symlink_maxsz + \
458 encode_getattr_maxsz + \
460 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
461 decode_putfh_maxsz + \
462 decode_symlink_maxsz + \
463 decode_getattr_maxsz + \
465 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
466 encode_putfh_maxsz + \
467 encode_savefh_maxsz + \
468 encode_create_maxsz + \
469 encode_getfh_maxsz + \
470 encode_getattr_maxsz + \
471 encode_restorefh_maxsz + \
472 encode_getattr_maxsz)
473 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
474 decode_putfh_maxsz + \
475 decode_savefh_maxsz + \
476 decode_create_maxsz + \
477 decode_getfh_maxsz + \
478 decode_getattr_maxsz + \
479 decode_restorefh_maxsz + \
480 decode_getattr_maxsz)
481 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
482 encode_putfh_maxsz + \
483 encode_getattr_maxsz)
484 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
485 decode_putfh_maxsz + \
486 decode_getattr_maxsz)
487 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
488 encode_putfh_maxsz + \
490 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
491 decode_putfh_maxsz + \
493 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
494 encode_putfh_maxsz + \
495 encode_getattr_maxsz)
496 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
497 decode_putfh_maxsz + \
498 decode_getattr_maxsz)
499 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
500 encode_putfh_maxsz + \
501 encode_delegreturn_maxsz + \
502 encode_getattr_maxsz)
503 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
504 decode_delegreturn_maxsz + \
505 decode_getattr_maxsz)
506 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
507 encode_putfh_maxsz + \
509 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
510 decode_putfh_maxsz + \
512 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
513 encode_putfh_maxsz + \
515 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
516 decode_putfh_maxsz + \
518 #define NFS4_enc_fs_locations_sz \
519 (compound_encode_hdr_maxsz + \
520 encode_putfh_maxsz + \
521 encode_lookup_maxsz + \
522 encode_fs_locations_maxsz)
523 #define NFS4_dec_fs_locations_sz \
524 (compound_decode_hdr_maxsz + \
525 decode_putfh_maxsz + \
526 decode_lookup_maxsz + \
527 decode_fs_locations_maxsz)
529 static const umode_t nfs_type2fmt[] = {
536 [NF4SOCK] = S_IFSOCK,
542 struct compound_hdr {
548 uint32_t replen; /* expected reply words */
552 * START OF "GENERIC" ENCODE ROUTINES.
553 * These may look a little ugly since they are imported from a "generic"
554 * set of XDR encode/decode routines which are intended to be shared by
555 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
557 * If the pain of reading these is too great, it should be a straightforward
558 * task to translate them into Linux-specific versions which are more
559 * consistent with the style used in NFSv2/v3...
561 #define WRITE32(n) *p++ = htonl(n)
562 #define WRITE64(n) do { \
563 *p++ = htonl((uint32_t)((n) >> 32)); \
564 *p++ = htonl((uint32_t)(n)); \
566 #define WRITEMEM(ptr,nbytes) do { \
567 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
570 #define RESERVE_SPACE(nbytes) do { \
571 p = xdr_reserve_space(xdr, nbytes); \
575 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
579 p = xdr_reserve_space(xdr, 4 + len);
581 xdr_encode_opaque(p, str, len);
584 static void encode_compound_hdr(struct xdr_stream *xdr,
585 struct rpc_rqst *req,
586 struct compound_hdr *hdr)
589 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
591 /* initialize running count of expected bytes in reply.
592 * NOTE: the replied tag SHOULD be the same is the one sent,
593 * but this is not required as a MUST for the server to do so. */
594 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
596 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
597 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
598 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
599 WRITE32(hdr->taglen);
600 WRITEMEM(hdr->tag, hdr->taglen);
601 WRITE32(NFS4_MINOR_VERSION);
606 static void encode_nops(struct compound_hdr *hdr)
608 *hdr->nops_p = htonl(hdr->nops);
611 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
615 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
617 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
620 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
622 char owner_name[IDMAP_NAMESZ];
623 char owner_group[IDMAP_NAMESZ];
624 int owner_namelen = 0;
625 int owner_grouplen = 0;
633 * We reserve enough space to write the entire attribute buffer at once.
634 * In the worst-case, this would be
635 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
636 * = 36 bytes, plus any contribution from variable-length fields
637 * such as owner/group.
642 if (iap->ia_valid & ATTR_SIZE)
644 if (iap->ia_valid & ATTR_MODE)
646 if (iap->ia_valid & ATTR_UID) {
647 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
648 if (owner_namelen < 0) {
649 dprintk("nfs: couldn't resolve uid %d to string\n",
652 strcpy(owner_name, "nobody");
653 owner_namelen = sizeof("nobody") - 1;
656 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
658 if (iap->ia_valid & ATTR_GID) {
659 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
660 if (owner_grouplen < 0) {
661 dprintk("nfs: couldn't resolve gid %d to string\n",
663 strcpy(owner_group, "nobody");
664 owner_grouplen = sizeof("nobody") - 1;
667 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
669 if (iap->ia_valid & ATTR_ATIME_SET)
671 else if (iap->ia_valid & ATTR_ATIME)
673 if (iap->ia_valid & ATTR_MTIME_SET)
675 else if (iap->ia_valid & ATTR_MTIME)
680 * We write the bitmap length now, but leave the bitmap and the attribute
681 * buffer length to be backfilled at the end of this routine.
687 if (iap->ia_valid & ATTR_SIZE) {
688 bmval0 |= FATTR4_WORD0_SIZE;
689 WRITE64(iap->ia_size);
691 if (iap->ia_valid & ATTR_MODE) {
692 bmval1 |= FATTR4_WORD1_MODE;
693 WRITE32(iap->ia_mode & S_IALLUGO);
695 if (iap->ia_valid & ATTR_UID) {
696 bmval1 |= FATTR4_WORD1_OWNER;
697 WRITE32(owner_namelen);
698 WRITEMEM(owner_name, owner_namelen);
700 if (iap->ia_valid & ATTR_GID) {
701 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
702 WRITE32(owner_grouplen);
703 WRITEMEM(owner_group, owner_grouplen);
705 if (iap->ia_valid & ATTR_ATIME_SET) {
706 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
707 WRITE32(NFS4_SET_TO_CLIENT_TIME);
709 WRITE32(iap->ia_mtime.tv_sec);
710 WRITE32(iap->ia_mtime.tv_nsec);
712 else if (iap->ia_valid & ATTR_ATIME) {
713 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
714 WRITE32(NFS4_SET_TO_SERVER_TIME);
716 if (iap->ia_valid & ATTR_MTIME_SET) {
717 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
718 WRITE32(NFS4_SET_TO_CLIENT_TIME);
720 WRITE32(iap->ia_mtime.tv_sec);
721 WRITE32(iap->ia_mtime.tv_nsec);
723 else if (iap->ia_valid & ATTR_MTIME) {
724 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
725 WRITE32(NFS4_SET_TO_SERVER_TIME);
729 * Now we backfill the bitmap and the attribute buffer length.
731 if (len != ((char *)p - (char *)q) + 4) {
732 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
733 len, ((char *)p - (char *)q) + 4);
736 len = (char *)p - (char *)q - 12;
737 *q++ = htonl(bmval0);
738 *q++ = htonl(bmval1);
744 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
752 hdr->replen += decode_access_maxsz;
755 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
759 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
761 WRITE32(arg->seqid->sequence->counter);
762 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
764 hdr->replen += decode_close_maxsz;
767 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
773 WRITE64(args->offset);
774 WRITE32(args->count);
776 hdr->replen += decode_commit_maxsz;
779 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
785 WRITE32(create->ftype);
787 switch (create->ftype) {
790 WRITE32(create->u.symlink.len);
791 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
794 case NF4BLK: case NF4CHR:
796 WRITE32(create->u.device.specdata1);
797 WRITE32(create->u.device.specdata2);
804 RESERVE_SPACE(4 + create->name->len);
805 WRITE32(create->name->len);
806 WRITEMEM(create->name->name, create->name->len);
808 hdr->replen += decode_create_maxsz;
810 encode_attrs(xdr, create->attrs, create->server);
813 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
822 hdr->replen += decode_getattr_maxsz;
825 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
835 hdr->replen += decode_getattr_maxsz;
838 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
840 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
841 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
844 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
846 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
847 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
850 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
852 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
853 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
856 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
863 hdr->replen += decode_getfh_maxsz;
866 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
870 RESERVE_SPACE(8 + name->len);
873 WRITEMEM(name->name, name->len);
875 hdr->replen += decode_link_maxsz;
878 static inline int nfs4_lock_type(struct file_lock *fl, int block)
880 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
881 return block ? NFS4_READW_LT : NFS4_READ_LT;
882 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
885 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
887 if (fl->fl_end == OFFSET_MAX)
889 return fl->fl_end - fl->fl_start + 1;
893 * opcode,type,reclaim,offset,length,new_lock_owner = 32
894 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
896 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
902 WRITE32(nfs4_lock_type(args->fl, args->block));
903 WRITE32(args->reclaim);
904 WRITE64(args->fl->fl_start);
905 WRITE64(nfs4_lock_length(args->fl));
906 WRITE32(args->new_lock_owner);
907 if (args->new_lock_owner){
908 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
909 WRITE32(args->open_seqid->sequence->counter);
910 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
911 WRITE32(args->lock_seqid->sequence->counter);
912 WRITE64(args->lock_owner.clientid);
914 WRITEMEM("lock id:", 8);
915 WRITE64(args->lock_owner.id);
918 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
919 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
920 WRITE32(args->lock_seqid->sequence->counter);
923 hdr->replen += decode_lock_maxsz;
926 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
932 WRITE32(nfs4_lock_type(args->fl, 0));
933 WRITE64(args->fl->fl_start);
934 WRITE64(nfs4_lock_length(args->fl));
935 WRITE64(args->lock_owner.clientid);
937 WRITEMEM("lock id:", 8);
938 WRITE64(args->lock_owner.id);
940 hdr->replen += decode_lockt_maxsz;
943 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
947 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
949 WRITE32(nfs4_lock_type(args->fl, 0));
950 WRITE32(args->seqid->sequence->counter);
951 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
952 WRITE64(args->fl->fl_start);
953 WRITE64(nfs4_lock_length(args->fl));
955 hdr->replen += decode_locku_maxsz;
958 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
963 RESERVE_SPACE(8 + len);
966 WRITEMEM(name->name, len);
968 hdr->replen += decode_lookup_maxsz;
971 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
976 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
978 WRITE32(NFS4_SHARE_ACCESS_READ);
981 WRITE32(NFS4_SHARE_ACCESS_WRITE);
983 case FMODE_READ|FMODE_WRITE:
984 WRITE32(NFS4_SHARE_ACCESS_BOTH);
989 WRITE32(0); /* for linux, share_deny = 0 always */
992 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
996 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1001 WRITE32(arg->seqid->sequence->counter);
1002 encode_share_access(xdr, arg->fmode);
1004 WRITE64(arg->clientid);
1006 WRITEMEM("open id:", 8);
1010 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1015 switch(arg->open_flags & O_EXCL) {
1017 WRITE32(NFS4_CREATE_UNCHECKED);
1018 encode_attrs(xdr, arg->u.attrs, arg->server);
1021 WRITE32(NFS4_CREATE_EXCLUSIVE);
1022 encode_nfs4_verifier(xdr, &arg->u.verifier);
1026 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1031 switch (arg->open_flags & O_CREAT) {
1033 WRITE32(NFS4_OPEN_NOCREATE);
1036 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1037 WRITE32(NFS4_OPEN_CREATE);
1038 encode_createmode(xdr, arg);
1042 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1047 switch (delegation_type) {
1049 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1052 WRITE32(NFS4_OPEN_DELEGATE_READ);
1054 case FMODE_WRITE|FMODE_READ:
1055 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1062 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1067 WRITE32(NFS4_OPEN_CLAIM_NULL);
1068 encode_string(xdr, name->len, name->name);
1071 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1076 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1077 encode_delegation_type(xdr, type);
1080 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1084 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1085 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1086 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1087 encode_string(xdr, name->len, name->name);
1090 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1092 encode_openhdr(xdr, arg);
1093 encode_opentype(xdr, arg);
1094 switch (arg->claim) {
1095 case NFS4_OPEN_CLAIM_NULL:
1096 encode_claim_null(xdr, arg->name);
1098 case NFS4_OPEN_CLAIM_PREVIOUS:
1099 encode_claim_previous(xdr, arg->u.delegation_type);
1101 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1102 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1108 hdr->replen += decode_open_maxsz;
1111 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1115 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1116 WRITE32(OP_OPEN_CONFIRM);
1117 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1118 WRITE32(arg->seqid->sequence->counter);
1120 hdr->replen += decode_open_confirm_maxsz;
1123 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1127 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1128 WRITE32(OP_OPEN_DOWNGRADE);
1129 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1130 WRITE32(arg->seqid->sequence->counter);
1131 encode_share_access(xdr, arg->fmode);
1133 hdr->replen += decode_open_downgrade_maxsz;
1137 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1142 RESERVE_SPACE(8 + len);
1145 WRITEMEM(fh->data, len);
1147 hdr->replen += decode_putfh_maxsz;
1150 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1155 WRITE32(OP_PUTROOTFH);
1157 hdr->replen += decode_putrootfh_maxsz;
1160 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1162 nfs4_stateid stateid;
1165 RESERVE_SPACE(NFS4_STATEID_SIZE);
1166 if (ctx->state != NULL) {
1167 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1168 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1170 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1173 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1180 encode_stateid(xdr, args->context);
1183 WRITE64(args->offset);
1184 WRITE32(args->count);
1186 hdr->replen += decode_read_maxsz;
1189 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1191 uint32_t attrs[2] = {
1192 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1193 FATTR4_WORD1_MOUNTED_ON_FILEID,
1197 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1198 WRITE32(OP_READDIR);
1199 WRITE64(readdir->cookie);
1200 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1201 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1202 WRITE32(readdir->count);
1204 /* Switch to mounted_on_fileid if the server supports it */
1205 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1206 attrs[0] &= ~FATTR4_WORD0_FILEID;
1208 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1209 WRITE32(attrs[0] & readdir->bitmask[0]);
1210 WRITE32(attrs[1] & readdir->bitmask[1]);
1212 hdr->replen += decode_readdir_maxsz;
1213 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1215 (unsigned long long)readdir->cookie,
1216 ((u32 *)readdir->verifier.data)[0],
1217 ((u32 *)readdir->verifier.data)[1],
1218 attrs[0] & readdir->bitmask[0],
1219 attrs[1] & readdir->bitmask[1]);
1222 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1227 WRITE32(OP_READLINK);
1229 hdr->replen += decode_readlink_maxsz;
1232 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1236 RESERVE_SPACE(8 + name->len);
1239 WRITEMEM(name->name, name->len);
1241 hdr->replen += decode_remove_maxsz;
1244 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1248 RESERVE_SPACE(8 + oldname->len);
1250 WRITE32(oldname->len);
1251 WRITEMEM(oldname->name, oldname->len);
1253 RESERVE_SPACE(4 + newname->len);
1254 WRITE32(newname->len);
1255 WRITEMEM(newname->name, newname->len);
1257 hdr->replen += decode_rename_maxsz;
1260 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1266 WRITE64(client_stateid->cl_clientid);
1268 hdr->replen += decode_renew_maxsz;
1272 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1277 WRITE32(OP_RESTOREFH);
1279 hdr->replen += decode_restorefh_maxsz;
1283 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1287 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1288 WRITE32(OP_SETATTR);
1289 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1292 WRITE32(FATTR4_WORD0_ACL);
1293 if (arg->acl_len % 4)
1296 WRITE32(arg->acl_len);
1297 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1299 hdr->replen += decode_setacl_maxsz;
1304 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1311 hdr->replen += decode_savefh_maxsz;
1314 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1318 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1319 WRITE32(OP_SETATTR);
1320 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1322 hdr->replen += decode_setattr_maxsz;
1323 encode_attrs(xdr, arg->iap, server);
1326 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1330 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1331 WRITE32(OP_SETCLIENTID);
1332 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1334 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1336 WRITE32(setclientid->sc_prog);
1337 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1338 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1340 WRITE32(setclientid->sc_cb_ident);
1342 hdr->replen += decode_setclientid_maxsz;
1345 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
1349 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1350 WRITE32(OP_SETCLIENTID_CONFIRM);
1351 WRITE64(client_state->cl_clientid);
1352 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1354 hdr->replen += decode_setclientid_confirm_maxsz;
1357 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1364 encode_stateid(xdr, args->context);
1367 WRITE64(args->offset);
1368 WRITE32(args->stable);
1369 WRITE32(args->count);
1371 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1373 hdr->replen += decode_write_maxsz;
1376 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1380 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1382 WRITE32(OP_DELEGRETURN);
1383 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1385 hdr->replen += decode_delegreturn_maxsz;
1388 * END OF "GENERIC" ENCODE ROUTINES.
1392 * Encode an ACCESS request
1394 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1396 struct xdr_stream xdr;
1397 struct compound_hdr hdr = {
1401 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1402 encode_compound_hdr(&xdr, req, &hdr);
1403 encode_putfh(&xdr, args->fh, &hdr);
1404 encode_access(&xdr, args->access, &hdr);
1405 encode_getfattr(&xdr, args->bitmask, &hdr);
1411 * Encode LOOKUP request
1413 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1415 struct xdr_stream xdr;
1416 struct compound_hdr hdr = {
1420 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1421 encode_compound_hdr(&xdr, req, &hdr);
1422 encode_putfh(&xdr, args->dir_fh, &hdr);
1423 encode_lookup(&xdr, args->name, &hdr);
1424 encode_getfh(&xdr, &hdr);
1425 encode_getfattr(&xdr, args->bitmask, &hdr);
1431 * Encode LOOKUP_ROOT request
1433 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1435 struct xdr_stream xdr;
1436 struct compound_hdr hdr = {
1440 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1441 encode_compound_hdr(&xdr, req, &hdr);
1442 encode_putrootfh(&xdr, &hdr);
1443 encode_getfh(&xdr, &hdr);
1444 encode_getfattr(&xdr, args->bitmask, &hdr);
1450 * Encode REMOVE request
1452 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
1454 struct xdr_stream xdr;
1455 struct compound_hdr hdr = {
1459 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1460 encode_compound_hdr(&xdr, req, &hdr);
1461 encode_putfh(&xdr, args->fh, &hdr);
1462 encode_remove(&xdr, &args->name, &hdr);
1463 encode_getfattr(&xdr, args->bitmask, &hdr);
1469 * Encode RENAME request
1471 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1473 struct xdr_stream xdr;
1474 struct compound_hdr hdr = {
1478 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1479 encode_compound_hdr(&xdr, req, &hdr);
1480 encode_putfh(&xdr, args->old_dir, &hdr);
1481 encode_savefh(&xdr, &hdr);
1482 encode_putfh(&xdr, args->new_dir, &hdr);
1483 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1484 encode_getfattr(&xdr, args->bitmask, &hdr);
1485 encode_restorefh(&xdr, &hdr);
1486 encode_getfattr(&xdr, args->bitmask, &hdr);
1492 * Encode LINK request
1494 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1496 struct xdr_stream xdr;
1497 struct compound_hdr hdr = {
1501 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1502 encode_compound_hdr(&xdr, req, &hdr);
1503 encode_putfh(&xdr, args->fh, &hdr);
1504 encode_savefh(&xdr, &hdr);
1505 encode_putfh(&xdr, args->dir_fh, &hdr);
1506 encode_link(&xdr, args->name, &hdr);
1507 encode_getfattr(&xdr, args->bitmask, &hdr);
1508 encode_restorefh(&xdr, &hdr);
1509 encode_getfattr(&xdr, args->bitmask, &hdr);
1515 * Encode CREATE request
1517 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1519 struct xdr_stream xdr;
1520 struct compound_hdr hdr = {
1524 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1525 encode_compound_hdr(&xdr, req, &hdr);
1526 encode_putfh(&xdr, args->dir_fh, &hdr);
1527 encode_savefh(&xdr, &hdr);
1528 encode_create(&xdr, args, &hdr);
1529 encode_getfh(&xdr, &hdr);
1530 encode_getfattr(&xdr, args->bitmask, &hdr);
1531 encode_restorefh(&xdr, &hdr);
1532 encode_getfattr(&xdr, args->bitmask, &hdr);
1538 * Encode SYMLINK request
1540 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1542 return nfs4_xdr_enc_create(req, p, args);
1546 * Encode GETATTR request
1548 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1550 struct xdr_stream xdr;
1551 struct compound_hdr hdr = {
1555 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1556 encode_compound_hdr(&xdr, req, &hdr);
1557 encode_putfh(&xdr, args->fh, &hdr);
1558 encode_getfattr(&xdr, args->bitmask, &hdr);
1564 * Encode a CLOSE request
1566 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1568 struct xdr_stream xdr;
1569 struct compound_hdr hdr = {
1573 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1574 encode_compound_hdr(&xdr, req, &hdr);
1575 encode_putfh(&xdr, args->fh, &hdr);
1576 encode_close(&xdr, args, &hdr);
1577 encode_getfattr(&xdr, args->bitmask, &hdr);
1583 * Encode an OPEN request
1585 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1587 struct xdr_stream xdr;
1588 struct compound_hdr hdr = {
1592 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1593 encode_compound_hdr(&xdr, req, &hdr);
1594 encode_putfh(&xdr, args->fh, &hdr);
1595 encode_savefh(&xdr, &hdr);
1596 encode_open(&xdr, args, &hdr);
1597 encode_getfh(&xdr, &hdr);
1598 encode_getfattr(&xdr, args->bitmask, &hdr);
1599 encode_restorefh(&xdr, &hdr);
1600 encode_getfattr(&xdr, args->bitmask, &hdr);
1606 * Encode an OPEN_CONFIRM request
1608 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1610 struct xdr_stream xdr;
1611 struct compound_hdr hdr = {
1615 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1616 encode_compound_hdr(&xdr, req, &hdr);
1617 encode_putfh(&xdr, args->fh, &hdr);
1618 encode_open_confirm(&xdr, args, &hdr);
1624 * Encode an OPEN request with no attributes.
1626 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1628 struct xdr_stream xdr;
1629 struct compound_hdr hdr = {
1633 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1634 encode_compound_hdr(&xdr, req, &hdr);
1635 encode_putfh(&xdr, args->fh, &hdr);
1636 encode_open(&xdr, args, &hdr);
1637 encode_getfattr(&xdr, args->bitmask, &hdr);
1643 * Encode an OPEN_DOWNGRADE request
1645 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1647 struct xdr_stream xdr;
1648 struct compound_hdr hdr = {
1652 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1653 encode_compound_hdr(&xdr, req, &hdr);
1654 encode_putfh(&xdr, args->fh, &hdr);
1655 encode_open_downgrade(&xdr, args, &hdr);
1656 encode_getfattr(&xdr, args->bitmask, &hdr);
1662 * Encode a LOCK request
1664 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1666 struct xdr_stream xdr;
1667 struct compound_hdr hdr = {
1671 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1672 encode_compound_hdr(&xdr, req, &hdr);
1673 encode_putfh(&xdr, args->fh, &hdr);
1674 encode_lock(&xdr, args, &hdr);
1680 * Encode a LOCKT request
1682 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1684 struct xdr_stream xdr;
1685 struct compound_hdr hdr = {
1689 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1690 encode_compound_hdr(&xdr, req, &hdr);
1691 encode_putfh(&xdr, args->fh, &hdr);
1692 encode_lockt(&xdr, args, &hdr);
1698 * Encode a LOCKU request
1700 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1702 struct xdr_stream xdr;
1703 struct compound_hdr hdr = {
1707 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1708 encode_compound_hdr(&xdr, req, &hdr);
1709 encode_putfh(&xdr, args->fh, &hdr);
1710 encode_locku(&xdr, args, &hdr);
1716 * Encode a READLINK request
1718 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1720 struct xdr_stream xdr;
1721 struct compound_hdr hdr = {
1725 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1726 encode_compound_hdr(&xdr, req, &hdr);
1727 encode_putfh(&xdr, args->fh, &hdr);
1728 encode_readlink(&xdr, args, req, &hdr);
1730 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
1731 args->pgbase, args->pglen);
1737 * Encode a READDIR request
1739 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1741 struct xdr_stream xdr;
1742 struct compound_hdr hdr = {
1746 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1747 encode_compound_hdr(&xdr, req, &hdr);
1748 encode_putfh(&xdr, args->fh, &hdr);
1749 encode_readdir(&xdr, args, req, &hdr);
1751 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
1752 args->pgbase, args->count);
1753 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1754 __func__, hdr.replen << 2, args->pages,
1755 args->pgbase, args->count);
1761 * Encode a READ request
1763 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1765 struct xdr_stream xdr;
1766 struct compound_hdr hdr = {
1770 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1771 encode_compound_hdr(&xdr, req, &hdr);
1772 encode_putfh(&xdr, args->fh, &hdr);
1773 encode_read(&xdr, args, &hdr);
1775 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
1776 args->pages, args->pgbase, args->count);
1777 req->rq_rcv_buf.flags |= XDRBUF_READ;
1783 * Encode an SETATTR request
1785 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1787 struct xdr_stream xdr;
1788 struct compound_hdr hdr = {
1792 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1793 encode_compound_hdr(&xdr, req, &hdr);
1794 encode_putfh(&xdr, args->fh, &hdr);
1795 encode_setattr(&xdr, args, args->server, &hdr);
1796 encode_getfattr(&xdr, args->bitmask, &hdr);
1802 * Encode a GETACL request
1805 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
1806 struct nfs_getaclargs *args)
1808 struct xdr_stream xdr;
1809 struct compound_hdr hdr = {
1814 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1815 encode_compound_hdr(&xdr, req, &hdr);
1816 encode_putfh(&xdr, args->fh, &hdr);
1817 replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1;
1818 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
1820 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
1821 args->acl_pages, args->acl_pgbase, args->acl_len);
1827 * Encode a WRITE request
1829 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1831 struct xdr_stream xdr;
1832 struct compound_hdr hdr = {
1836 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1837 encode_compound_hdr(&xdr, req, &hdr);
1838 encode_putfh(&xdr, args->fh, &hdr);
1839 encode_write(&xdr, args, &hdr);
1840 req->rq_snd_buf.flags |= XDRBUF_WRITE;
1841 encode_getfattr(&xdr, args->bitmask, &hdr);
1849 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1851 struct xdr_stream xdr;
1852 struct compound_hdr hdr = {
1856 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1857 encode_compound_hdr(&xdr, req, &hdr);
1858 encode_putfh(&xdr, args->fh, &hdr);
1859 encode_commit(&xdr, args, &hdr);
1860 encode_getfattr(&xdr, args->bitmask, &hdr);
1868 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
1870 struct xdr_stream xdr;
1871 struct compound_hdr hdr = {
1875 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1876 encode_compound_hdr(&xdr, req, &hdr);
1877 encode_putfh(&xdr, args->fh, &hdr);
1878 encode_fsinfo(&xdr, args->bitmask, &hdr);
1884 * a PATHCONF request
1886 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
1888 struct xdr_stream xdr;
1889 struct compound_hdr hdr = {
1893 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1894 encode_compound_hdr(&xdr, req, &hdr);
1895 encode_putfh(&xdr, args->fh, &hdr);
1896 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
1905 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
1907 struct xdr_stream xdr;
1908 struct compound_hdr hdr = {
1912 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1913 encode_compound_hdr(&xdr, req, &hdr);
1914 encode_putfh(&xdr, args->fh, &hdr);
1915 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
1916 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
1922 * GETATTR_BITMAP request
1924 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
1925 struct nfs4_server_caps_arg *args)
1927 struct xdr_stream xdr;
1928 struct compound_hdr hdr = {
1932 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1933 encode_compound_hdr(&xdr, req, &hdr);
1934 encode_putfh(&xdr, args->fhandle, &hdr);
1935 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1936 FATTR4_WORD0_LINK_SUPPORT|
1937 FATTR4_WORD0_SYMLINK_SUPPORT|
1938 FATTR4_WORD0_ACLSUPPORT, &hdr);
1946 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1948 struct xdr_stream xdr;
1949 struct compound_hdr hdr = {
1953 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1954 encode_compound_hdr(&xdr, req, &hdr);
1955 encode_renew(&xdr, clp, &hdr);
1961 * a SETCLIENTID request
1963 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
1965 struct xdr_stream xdr;
1966 struct compound_hdr hdr = {
1970 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1971 encode_compound_hdr(&xdr, req, &hdr);
1972 encode_setclientid(&xdr, sc, &hdr);
1978 * a SETCLIENTID_CONFIRM request
1980 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1982 struct xdr_stream xdr;
1983 struct compound_hdr hdr = {
1986 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1988 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1989 encode_compound_hdr(&xdr, req, &hdr);
1990 encode_setclientid_confirm(&xdr, clp, &hdr);
1991 encode_putrootfh(&xdr, &hdr);
1992 encode_fsinfo(&xdr, lease_bitmap, &hdr);
1998 * DELEGRETURN request
2000 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
2002 struct xdr_stream xdr;
2003 struct compound_hdr hdr = {
2007 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2008 encode_compound_hdr(&xdr, req, &hdr);
2009 encode_putfh(&xdr, args->fhandle, &hdr);
2010 encode_delegreturn(&xdr, args->stateid, &hdr);
2011 encode_getfattr(&xdr, args->bitmask, &hdr);
2017 * Encode FS_LOCATIONS request
2019 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2021 struct xdr_stream xdr;
2022 struct compound_hdr hdr = {
2027 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2028 encode_compound_hdr(&xdr, req, &hdr);
2029 encode_putfh(&xdr, args->dir_fh, &hdr);
2030 encode_lookup(&xdr, args->name, &hdr);
2031 replen = hdr.replen; /* get the attribute into args->page */
2032 encode_fs_locations(&xdr, args->bitmask, &hdr);
2034 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2041 * START OF "GENERIC" DECODE ROUTINES.
2042 * These may look a little ugly since they are imported from a "generic"
2043 * set of XDR encode/decode routines which are intended to be shared by
2044 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2046 * If the pain of reading these is too great, it should be a straightforward
2047 * task to translate them into Linux-specific versions which are more
2048 * consistent with the style used in NFSv2/v3...
2050 #define READ32(x) (x) = ntohl(*p++)
2051 #define READ64(x) do { \
2052 (x) = (u64)ntohl(*p++) << 32; \
2053 (x) |= ntohl(*p++); \
2055 #define READTIME(x) do { \
2057 (x.tv_sec) = ntohl(*p++); \
2058 (x.tv_nsec) = ntohl(*p++); \
2060 #define COPYMEM(x,nbytes) do { \
2061 memcpy((x), p, nbytes); \
2062 p += XDR_QUADLEN(nbytes); \
2065 #define READ_BUF(nbytes) do { \
2066 p = xdr_inline_decode(xdr, nbytes); \
2067 if (unlikely(!p)) { \
2068 dprintk("nfs: %s: prematurely hit end of receive" \
2069 " buffer\n", __func__); \
2070 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2071 __func__, xdr->p, nbytes, xdr->end); \
2076 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2083 *string = (char *)p;
2087 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2092 READ32(hdr->status);
2093 READ32(hdr->taglen);
2095 READ_BUF(hdr->taglen + 4);
2096 hdr->tag = (char *)p;
2097 p += XDR_QUADLEN(hdr->taglen);
2099 if (unlikely(hdr->nops < 1))
2100 return nfs4_stat_to_errno(hdr->status);
2104 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2112 if (opnum != expected) {
2113 dprintk("nfs: Server returned operation"
2114 " %d but we issued a request for %d\n",
2119 if (nfserr != NFS_OK)
2120 return nfs4_stat_to_errno(nfserr);
2125 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2128 unsigned int strlen;
2132 return decode_opaque_inline(xdr, &strlen, &str);
2135 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2143 bitmap[0] = bitmap[1] = 0;
2144 READ_BUF((bmlen << 2));
2153 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2163 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2165 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2166 decode_attr_bitmap(xdr, bitmask);
2167 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2169 bitmask[0] = bitmask[1] = 0;
2170 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
2174 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2180 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2182 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2185 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2186 dprintk("%s: bad type %d\n", __func__, *type);
2189 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2190 ret = NFS_ATTR_FATTR_TYPE;
2192 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
2196 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2202 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2204 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2207 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2208 ret = NFS_ATTR_FATTR_CHANGE;
2210 dprintk("%s: change attribute=%Lu\n", __func__,
2211 (unsigned long long)*change);
2215 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2221 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2223 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2226 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2227 ret = NFS_ATTR_FATTR_SIZE;
2229 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
2233 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2238 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2240 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2243 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2245 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
2249 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2254 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2256 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2259 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2261 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
2265 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2272 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2274 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2276 READ64(fsid->major);
2277 READ64(fsid->minor);
2278 bitmap[0] &= ~FATTR4_WORD0_FSID;
2279 ret = NFS_ATTR_FATTR_FSID;
2281 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
2282 (unsigned long long)fsid->major,
2283 (unsigned long long)fsid->minor);
2287 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2292 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2294 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2297 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2299 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
2303 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2307 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2308 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2310 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2313 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2315 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
2319 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2325 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2327 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2330 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2331 ret = NFS_ATTR_FATTR_FILEID;
2333 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2337 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2343 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2345 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2348 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2349 ret = NFS_ATTR_FATTR_FILEID;
2351 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2355 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2361 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2363 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2366 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2368 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
2372 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2378 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2380 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2383 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2385 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
2389 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2395 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2397 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2400 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2402 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
2406 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2417 path->ncomponents = 0;
2418 while (path->ncomponents < n) {
2419 struct nfs4_string *component = &path->components[path->ncomponents];
2420 status = decode_opaque_inline(xdr, &component->len, &component->data);
2421 if (unlikely(status != 0))
2423 if (path->ncomponents != n)
2425 dprintk("%s", component->data);
2426 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2427 path->ncomponents++;
2429 dprintk("cannot parse %d components in path\n", n);
2437 /* a root pathname is sent as a zero component4 */
2438 path->ncomponents = 1;
2439 path->components[0].len=0;
2440 path->components[0].data=NULL;
2441 dprintk("path /\n");
2444 dprintk(" status %d", status);
2449 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2455 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2458 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2460 dprintk("%s: fsroot ", __func__);
2461 status = decode_pathname(xdr, &res->fs_path);
2462 if (unlikely(status != 0))
2468 res->nlocations = 0;
2469 while (res->nlocations < n) {
2471 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2477 dprintk("%s: servers ", __func__);
2478 while (loc->nservers < m) {
2479 struct nfs4_string *server = &loc->servers[loc->nservers];
2480 status = decode_opaque_inline(xdr, &server->len, &server->data);
2481 if (unlikely(status != 0))
2483 dprintk("%s ", server->data);
2484 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2488 dprintk("%s: using first %u of %u servers "
2489 "returned for location %u\n",
2491 NFS4_FS_LOCATION_MAXSERVERS,
2492 m, res->nlocations);
2493 for (i = loc->nservers; i < m; i++) {
2496 status = decode_opaque_inline(xdr, &len, &data);
2497 if (unlikely(status != 0))
2502 status = decode_pathname(xdr, &loc->rootpath);
2503 if (unlikely(status != 0))
2505 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2508 if (res->nlocations != 0)
2509 status = NFS_ATTR_FATTR_V4_REFERRAL;
2511 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
2518 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2524 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2526 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2529 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2531 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
2535 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2541 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2543 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2546 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2548 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
2552 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2558 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2560 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2563 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2565 dprintk("%s: maxname=%u\n", __func__, *maxname);
2569 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2575 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2577 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2581 if (maxread > 0x7FFFFFFF)
2582 maxread = 0x7FFFFFFF;
2583 *res = (uint32_t)maxread;
2584 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2586 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
2590 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2596 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2598 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2602 if (maxwrite > 0x7FFFFFFF)
2603 maxwrite = 0x7FFFFFFF;
2604 *res = (uint32_t)maxwrite;
2605 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2607 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
2611 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
2618 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2620 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2623 *mode = tmp & ~S_IFMT;
2624 bitmap[1] &= ~FATTR4_WORD1_MODE;
2625 ret = NFS_ATTR_FATTR_MODE;
2627 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
2631 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2637 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2639 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2642 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2643 ret = NFS_ATTR_FATTR_NLINK;
2645 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
2649 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
2656 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2658 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2662 if (len < XDR_MAX_NETOBJ) {
2663 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
2664 ret = NFS_ATTR_FATTR_OWNER;
2666 dprintk("%s: nfs_map_name_to_uid failed!\n",
2669 dprintk("%s: name too long (%u)!\n",
2671 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2673 dprintk("%s: uid=%d\n", __func__, (int)*uid);
2677 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
2684 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2686 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2690 if (len < XDR_MAX_NETOBJ) {
2691 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
2692 ret = NFS_ATTR_FATTR_GROUP;
2694 dprintk("%s: nfs_map_group_to_gid failed!\n",
2697 dprintk("%s: name too long (%u)!\n",
2699 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2701 dprintk("%s: gid=%d\n", __func__, (int)*gid);
2705 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2707 uint32_t major = 0, minor = 0;
2712 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2714 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2720 tmp = MKDEV(major, minor);
2721 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2723 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2724 ret = NFS_ATTR_FATTR_RDEV;
2726 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
2730 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2736 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2738 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2741 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2743 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
2747 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2753 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2755 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2758 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2760 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
2764 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2770 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2772 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2775 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2777 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
2781 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2787 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2789 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2792 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2793 ret = NFS_ATTR_FATTR_SPACE_USED;
2795 dprintk("%s: space used=%Lu\n", __func__,
2796 (unsigned long long)*used);
2800 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2809 time->tv_sec = (time_t)sec;
2810 time->tv_nsec = (long)nsec;
2814 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2820 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2822 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2823 status = decode_attr_time(xdr, time);
2825 status = NFS_ATTR_FATTR_ATIME;
2826 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2828 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
2832 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2838 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2840 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2841 status = decode_attr_time(xdr, time);
2843 status = NFS_ATTR_FATTR_CTIME;
2844 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2846 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
2850 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2856 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2858 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2859 status = decode_attr_time(xdr, time);
2861 status = NFS_ATTR_FATTR_MTIME;
2862 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2864 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
2868 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
2870 unsigned int attrwords = XDR_QUADLEN(attrlen);
2871 unsigned int nwords = xdr->p - savep;
2873 if (unlikely(attrwords != nwords)) {
2874 dprintk("%s: server returned incorrect attribute length: "
2878 (attrwords < nwords) ? '<' : '>',
2885 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2890 READ32(cinfo->atomic);
2891 READ64(cinfo->before);
2892 READ64(cinfo->after);
2896 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2902 status = decode_op_hdr(xdr, OP_ACCESS);
2908 access->supported = supp;
2909 access->access = acc;
2913 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2918 status = decode_op_hdr(xdr, OP_CLOSE);
2920 nfs_increment_open_seqid(status, res->seqid);
2923 READ_BUF(NFS4_STATEID_SIZE);
2924 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
2928 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2933 status = decode_op_hdr(xdr, OP_COMMIT);
2937 COPYMEM(res->verf->verifier, 8);
2941 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2947 status = decode_op_hdr(xdr, OP_CREATE);
2950 if ((status = decode_change_info(xdr, cinfo)))
2954 READ_BUF(bmlen << 2);
2958 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2961 uint32_t attrlen, bitmap[2] = {0};
2964 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2966 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2968 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2970 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2972 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2974 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2976 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2978 status = verify_attr_len(xdr, savep, attrlen);
2980 dprintk("%s: xdr returned %d!\n", __func__, -status);
2984 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2987 uint32_t attrlen, bitmap[2] = {0};
2990 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2992 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2994 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2997 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2999 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3001 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3003 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3005 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3007 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3010 status = verify_attr_len(xdr, savep, attrlen);
3012 dprintk("%s: xdr returned %d!\n", __func__, -status);
3016 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3019 uint32_t attrlen, bitmap[2] = {0};
3022 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3024 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3026 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3029 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3031 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3034 status = verify_attr_len(xdr, savep, attrlen);
3036 dprintk("%s: xdr returned %d!\n", __func__, -status);
3040 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3050 status = decode_op_hdr(xdr, OP_GETATTR);
3054 status = decode_attr_bitmap(xdr, bitmap);
3058 status = decode_attr_length(xdr, &attrlen, &savep);
3063 status = decode_attr_type(xdr, bitmap, &type);
3068 fattr->mode |= nfs_type2fmt[type];
3069 fattr->valid |= status;
3072 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3075 fattr->valid |= status;
3077 status = decode_attr_size(xdr, bitmap, &fattr->size);
3080 fattr->valid |= status;
3082 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3085 fattr->valid |= status;
3087 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3090 fattr->valid |= status;
3092 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3093 struct nfs4_fs_locations,
3097 fattr->valid |= status;
3099 status = decode_attr_mode(xdr, bitmap, &fmode);
3103 fattr->mode |= fmode;
3104 fattr->valid |= status;
3107 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3110 fattr->valid |= status;
3112 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
3115 fattr->valid |= status;
3117 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
3120 fattr->valid |= status;
3122 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3125 fattr->valid |= status;
3127 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3130 fattr->valid |= status;
3132 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3135 fattr->valid |= status;
3137 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3140 fattr->valid |= status;
3142 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3145 fattr->valid |= status;
3147 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3150 if (status != 0 && !(fattr->valid & status)) {
3151 fattr->fileid = fileid;
3152 fattr->valid |= status;
3155 status = verify_attr_len(xdr, savep, attrlen);
3157 dprintk("%s: xdr returned %d\n", __func__, -status);
3162 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3165 uint32_t attrlen, bitmap[2];
3168 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3170 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3172 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3175 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3177 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3179 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3181 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3183 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3184 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3186 fsinfo->wtpref = fsinfo->wtmax;
3188 status = verify_attr_len(xdr, savep, attrlen);
3190 dprintk("%s: xdr returned %d!\n", __func__, -status);
3194 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3200 /* Zero handle first to allow comparisons */
3201 memset(fh, 0, sizeof(*fh));
3203 status = decode_op_hdr(xdr, OP_GETFH);
3209 if (len > NFS4_FHSIZE)
3213 COPYMEM(fh->data, len);
3217 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3221 status = decode_op_hdr(xdr, OP_LINK);
3224 return decode_change_info(xdr, cinfo);
3228 * We create the owner, so we know a proper owner.id length is 4.
3230 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3232 uint64_t offset, length, clientid;
3234 uint32_t namelen, type;
3241 fl->fl_start = (loff_t)offset;
3242 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3243 if (length == ~(uint64_t)0)
3244 fl->fl_end = OFFSET_MAX;
3245 fl->fl_type = F_WRLCK;
3247 fl->fl_type = F_RDLCK;
3253 return -NFS4ERR_DENIED;
3256 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3261 status = decode_op_hdr(xdr, OP_LOCK);
3265 READ_BUF(NFS4_STATEID_SIZE);
3266 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3267 } else if (status == -NFS4ERR_DENIED)
3268 status = decode_lock_denied(xdr, NULL);
3269 if (res->open_seqid != NULL)
3270 nfs_increment_open_seqid(status, res->open_seqid);
3271 nfs_increment_lock_seqid(status, res->lock_seqid);
3276 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3279 status = decode_op_hdr(xdr, OP_LOCKT);
3280 if (status == -NFS4ERR_DENIED)
3281 return decode_lock_denied(xdr, res->denied);
3285 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3290 status = decode_op_hdr(xdr, OP_LOCKU);
3292 nfs_increment_lock_seqid(status, res->seqid);
3294 READ_BUF(NFS4_STATEID_SIZE);
3295 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3300 static int decode_lookup(struct xdr_stream *xdr)
3302 return decode_op_hdr(xdr, OP_LOOKUP);
3305 /* This is too sick! */
3306 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3309 uint32_t limit_type, nblocks, blocksize;
3313 switch (limit_type) {
3320 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3325 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3328 uint32_t delegation_type;
3331 READ32(delegation_type);
3332 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3333 res->delegation_type = 0;
3336 READ_BUF(NFS4_STATEID_SIZE+4);
3337 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3338 READ32(res->do_recall);
3340 switch (delegation_type) {
3341 case NFS4_OPEN_DELEGATE_READ:
3342 res->delegation_type = FMODE_READ;
3344 case NFS4_OPEN_DELEGATE_WRITE:
3345 res->delegation_type = FMODE_WRITE|FMODE_READ;
3346 if (decode_space_limit(xdr, &res->maxsize) < 0)
3349 return decode_ace(xdr, NULL, res->server->nfs_client);
3352 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3355 uint32_t savewords, bmlen, i;
3358 status = decode_op_hdr(xdr, OP_OPEN);
3360 nfs_increment_open_seqid(status, res->seqid);
3363 READ_BUF(NFS4_STATEID_SIZE);
3364 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3366 decode_change_info(xdr, &res->cinfo);
3369 READ32(res->rflags);
3374 READ_BUF(bmlen << 2);
3375 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3376 for (i = 0; i < savewords; ++i)
3377 READ32(res->attrset[i]);
3378 for (; i < NFS4_BITMAP_SIZE; i++)
3379 res->attrset[i] = 0;
3381 return decode_delegation(xdr, res);
3383 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
3387 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3392 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3394 nfs_increment_open_seqid(status, res->seqid);
3397 READ_BUF(NFS4_STATEID_SIZE);
3398 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3402 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3407 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3409 nfs_increment_open_seqid(status, res->seqid);
3412 READ_BUF(NFS4_STATEID_SIZE);
3413 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3417 static int decode_putfh(struct xdr_stream *xdr)
3419 return decode_op_hdr(xdr, OP_PUTFH);
3422 static int decode_putrootfh(struct xdr_stream *xdr)
3424 return decode_op_hdr(xdr, OP_PUTROOTFH);
3427 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3429 struct kvec *iov = req->rq_rcv_buf.head;
3431 uint32_t count, eof, recvd, hdrlen;
3434 status = decode_op_hdr(xdr, OP_READ);
3440 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3441 recvd = req->rq_rcv_buf.len - hdrlen;
3442 if (count > recvd) {
3443 dprintk("NFS: server cheating in read reply: "
3444 "count %u > recvd %u\n", count, recvd);
3448 xdr_read_pages(xdr, count);
3454 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3456 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3457 struct page *page = *rcvbuf->pages;
3458 struct kvec *iov = rcvbuf->head;
3460 u32 recvd, pglen = rcvbuf->page_len;
3461 __be32 *end, *entry, *p, *kaddr;
3462 unsigned int nr = 0;
3465 status = decode_op_hdr(xdr, OP_READDIR);
3469 COPYMEM(readdir->verifier.data, 8);
3470 dprintk("%s: verifier = %08x:%08x\n",
3472 ((u32 *)readdir->verifier.data)[0],
3473 ((u32 *)readdir->verifier.data)[1]);
3476 hdrlen = (char *) p - (char *) iov->iov_base;
3477 recvd = rcvbuf->len - hdrlen;
3480 xdr_read_pages(xdr, pglen);
3482 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3483 kaddr = p = kmap_atomic(page, KM_USER0);
3484 end = p + ((pglen + readdir->pgbase) >> 2);
3487 /* Make sure the packet actually has a value_follows and EOF entry */
3488 if ((entry + 1) > end)
3491 for (; *p++; nr++) {
3492 u32 len, attrlen, xlen;
3495 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3496 p += 2; /* cookie */
3497 len = ntohl(*p++); /* filename length */
3498 if (len > NFS4_MAXNAMLEN) {
3499 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3503 xlen = XDR_QUADLEN(len);
3504 if (end - p < xlen + 1)
3506 dprintk("filename = %*s\n", len, (char *)p);
3508 len = ntohl(*p++); /* bitmap length */
3509 if (end - p < len + 1)
3512 attrlen = XDR_QUADLEN(ntohl(*p++));
3513 if (end - p < attrlen + 2)
3515 p += attrlen; /* attributes */
3519 * Apparently some server sends responses that are a valid size, but
3520 * contain no entries, and have value_follows==0 and EOF==0. For
3521 * those, just set the EOF marker.
3523 if (!nr && entry[1] == 0) {
3524 dprintk("NFS: readdir reply truncated!\n");
3528 kunmap_atomic(kaddr, KM_USER0);
3532 * When we get a short packet there are 2 possibilities. We can
3533 * return an error, or fix up the response to look like a valid
3534 * response and return what we have so far. If there are no
3535 * entries and the packet was short, then return -EIO. If there
3536 * are valid entries in the response, return them and pretend that
3537 * the call was successful, but incomplete. The caller can retry the
3538 * readdir starting at the last cookie.
3540 dprintk("%s: short packet at entry %d\n", __func__, nr);
3541 entry[0] = entry[1] = 0;
3545 kunmap_atomic(kaddr, KM_USER0);
3546 return -errno_NFSERR_IO;
3549 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3551 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3552 struct kvec *iov = rcvbuf->head;
3559 status = decode_op_hdr(xdr, OP_READLINK);
3563 /* Convert length of symlink */
3566 if (len >= rcvbuf->page_len || len <= 0) {
3567 dprintk("nfs: server returned giant symlink!\n");
3568 return -ENAMETOOLONG;
3570 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3571 recvd = req->rq_rcv_buf.len - hdrlen;
3573 dprintk("NFS: server cheating in readlink reply: "
3574 "count %u > recvd %u\n", len, recvd);
3577 xdr_read_pages(xdr, len);
3579 * The XDR encode routine has set things up so that
3580 * the link text will be copied directly into the
3581 * buffer. We just have to do overflow-checking,
3582 * and and null-terminate the text (the VFS expects
3583 * null-termination).
3585 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3586 kaddr[len+rcvbuf->page_base] = '\0';
3587 kunmap_atomic(kaddr, KM_USER0);
3591 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3595 status = decode_op_hdr(xdr, OP_REMOVE);
3598 status = decode_change_info(xdr, cinfo);
3603 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3604 struct nfs4_change_info *new_cinfo)
3608 status = decode_op_hdr(xdr, OP_RENAME);
3611 if ((status = decode_change_info(xdr, old_cinfo)))
3613 status = decode_change_info(xdr, new_cinfo);
3618 static int decode_renew(struct xdr_stream *xdr)
3620 return decode_op_hdr(xdr, OP_RENEW);
3624 decode_restorefh(struct xdr_stream *xdr)
3626 return decode_op_hdr(xdr, OP_RESTOREFH);
3629 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3635 struct kvec *iov = req->rq_rcv_buf.head;
3639 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3641 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3643 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3646 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3648 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3652 /* We ignore &savep and don't do consistency checks on
3653 * the attr length. Let userspace figure it out.... */
3654 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3655 recvd = req->rq_rcv_buf.len - hdrlen;
3656 if (attrlen > recvd) {
3657 dprintk("NFS: server cheating in getattr"
3658 " acl reply: attrlen %u > recvd %u\n",
3662 xdr_read_pages(xdr, attrlen);
3665 status = -EOPNOTSUPP;
3672 decode_savefh(struct xdr_stream *xdr)
3674 return decode_op_hdr(xdr, OP_SAVEFH);
3677 static int decode_setattr(struct xdr_stream *xdr)
3683 status = decode_op_hdr(xdr, OP_SETATTR);
3688 READ_BUF(bmlen << 2);
3692 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
3700 if (opnum != OP_SETCLIENTID) {
3701 dprintk("nfs: decode_setclientid: Server returned operation"
3706 if (nfserr == NFS_OK) {
3707 READ_BUF(8 + NFS4_VERIFIER_SIZE);
3708 READ64(clp->cl_clientid);
3709 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
3710 } else if (nfserr == NFSERR_CLID_INUSE) {
3713 /* skip netid string */
3718 /* skip uaddr string */
3722 return -NFSERR_CLID_INUSE;
3724 return nfs4_stat_to_errno(nfserr);
3729 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3731 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3734 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3739 status = decode_op_hdr(xdr, OP_WRITE);
3745 READ32(res->verf->committed);
3746 COPYMEM(res->verf->verifier, 8);
3750 static int decode_delegreturn(struct xdr_stream *xdr)
3752 return decode_op_hdr(xdr, OP_DELEGRETURN);
3756 * END OF "GENERIC" DECODE ROUTINES.
3760 * Decode OPEN_DOWNGRADE response
3762 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3764 struct xdr_stream xdr;
3765 struct compound_hdr hdr;
3768 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3769 status = decode_compound_hdr(&xdr, &hdr);
3772 status = decode_putfh(&xdr);
3775 status = decode_open_downgrade(&xdr, res);
3778 decode_getfattr(&xdr, res->fattr, res->server);
3784 * Decode ACCESS response
3786 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
3788 struct xdr_stream xdr;
3789 struct compound_hdr hdr;
3792 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3793 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3795 status = decode_putfh(&xdr);
3798 status = decode_access(&xdr, res);
3801 decode_getfattr(&xdr, res->fattr, res->server);
3807 * Decode LOOKUP response
3809 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3811 struct xdr_stream xdr;
3812 struct compound_hdr hdr;
3815 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3816 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3818 if ((status = decode_putfh(&xdr)) != 0)
3820 if ((status = decode_lookup(&xdr)) != 0)
3822 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3824 status = decode_getfattr(&xdr, res->fattr, res->server);
3830 * Decode LOOKUP_ROOT response
3832 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3834 struct xdr_stream xdr;
3835 struct compound_hdr hdr;
3838 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3839 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3841 if ((status = decode_putrootfh(&xdr)) != 0)
3843 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3844 status = decode_getfattr(&xdr, res->fattr, res->server);
3850 * Decode REMOVE response
3852 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
3854 struct xdr_stream xdr;
3855 struct compound_hdr hdr;
3858 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3859 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3861 if ((status = decode_putfh(&xdr)) != 0)
3863 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3865 decode_getfattr(&xdr, &res->dir_attr, res->server);
3871 * Decode RENAME response
3873 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
3875 struct xdr_stream xdr;
3876 struct compound_hdr hdr;
3879 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3880 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3882 if ((status = decode_putfh(&xdr)) != 0)
3884 if ((status = decode_savefh(&xdr)) != 0)
3886 if ((status = decode_putfh(&xdr)) != 0)
3888 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3890 /* Current FH is target directory */
3891 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3893 if ((status = decode_restorefh(&xdr)) != 0)
3895 decode_getfattr(&xdr, res->old_fattr, res->server);
3901 * Decode LINK response
3903 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
3905 struct xdr_stream xdr;
3906 struct compound_hdr hdr;
3909 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3910 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3912 if ((status = decode_putfh(&xdr)) != 0)
3914 if ((status = decode_savefh(&xdr)) != 0)
3916 if ((status = decode_putfh(&xdr)) != 0)
3918 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3921 * Note order: OP_LINK leaves the directory as the current
3924 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3926 if ((status = decode_restorefh(&xdr)) != 0)
3928 decode_getfattr(&xdr, res->fattr, res->server);
3934 * Decode CREATE response
3936 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3938 struct xdr_stream xdr;
3939 struct compound_hdr hdr;
3942 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3943 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3945 if ((status = decode_putfh(&xdr)) != 0)
3947 if ((status = decode_savefh(&xdr)) != 0)
3949 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3951 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3953 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3955 if ((status = decode_restorefh(&xdr)) != 0)
3957 decode_getfattr(&xdr, res->dir_fattr, res->server);
3963 * Decode SYMLINK response
3965 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3967 return nfs4_xdr_dec_create(rqstp, p, res);
3971 * Decode GETATTR response
3973 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
3975 struct xdr_stream xdr;
3976 struct compound_hdr hdr;
3979 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3980 status = decode_compound_hdr(&xdr, &hdr);
3983 status = decode_putfh(&xdr);
3986 status = decode_getfattr(&xdr, res->fattr, res->server);
3992 * Encode an SETACL request
3995 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
3997 struct xdr_stream xdr;
3998 struct compound_hdr hdr = {
4003 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
4004 encode_compound_hdr(&xdr, req, &hdr);
4005 encode_putfh(&xdr, args->fh, &hdr);
4006 status = encode_setacl(&xdr, args, &hdr);
4012 * Decode SETACL response
4015 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4016 struct nfs_setaclres *res)
4018 struct xdr_stream xdr;
4019 struct compound_hdr hdr;
4022 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4023 status = decode_compound_hdr(&xdr, &hdr);
4026 status = decode_putfh(&xdr);
4029 status = decode_setattr(&xdr);
4035 * Decode GETACL response
4038 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4039 struct nfs_getaclres *res)
4041 struct xdr_stream xdr;
4042 struct compound_hdr hdr;
4045 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4046 status = decode_compound_hdr(&xdr, &hdr);
4049 status = decode_putfh(&xdr);
4052 status = decode_getacl(&xdr, rqstp, &res->acl_len);
4059 * Decode CLOSE response
4061 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
4063 struct xdr_stream xdr;
4064 struct compound_hdr hdr;
4067 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4068 status = decode_compound_hdr(&xdr, &hdr);
4071 status = decode_putfh(&xdr);
4074 status = decode_close(&xdr, res);
4078 * Note: Server may do delete on close for this file
4079 * in which case the getattr call will fail with
4080 * an ESTALE error. Shouldn't be a problem,
4081 * though, since fattr->valid will remain unset.
4083 decode_getfattr(&xdr, res->fattr, res->server);
4089 * Decode OPEN response
4091 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4093 struct xdr_stream xdr;
4094 struct compound_hdr hdr;
4097 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4098 status = decode_compound_hdr(&xdr, &hdr);
4101 status = decode_putfh(&xdr);
4104 status = decode_savefh(&xdr);
4107 status = decode_open(&xdr, res);
4110 if (decode_getfh(&xdr, &res->fh) != 0)
4112 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4114 if (decode_restorefh(&xdr) != 0)
4116 decode_getfattr(&xdr, res->dir_attr, res->server);
4122 * Decode OPEN_CONFIRM response
4124 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4126 struct xdr_stream xdr;
4127 struct compound_hdr hdr;
4130 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4131 status = decode_compound_hdr(&xdr, &hdr);
4134 status = decode_putfh(&xdr);
4137 status = decode_open_confirm(&xdr, res);
4143 * Decode OPEN response
4145 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4147 struct xdr_stream xdr;
4148 struct compound_hdr hdr;
4151 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4152 status = decode_compound_hdr(&xdr, &hdr);
4155 status = decode_putfh(&xdr);
4158 status = decode_open(&xdr, res);
4161 decode_getfattr(&xdr, res->f_attr, res->server);
4167 * Decode SETATTR response
4169 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4171 struct xdr_stream xdr;
4172 struct compound_hdr hdr;
4175 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4176 status = decode_compound_hdr(&xdr, &hdr);
4179 status = decode_putfh(&xdr);
4182 status = decode_setattr(&xdr);
4185 decode_getfattr(&xdr, res->fattr, res->server);
4191 * Decode LOCK response
4193 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4195 struct xdr_stream xdr;
4196 struct compound_hdr hdr;
4199 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4200 status = decode_compound_hdr(&xdr, &hdr);
4203 status = decode_putfh(&xdr);
4206 status = decode_lock(&xdr, res);
4212 * Decode LOCKT response
4214 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4216 struct xdr_stream xdr;
4217 struct compound_hdr hdr;
4220 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4221 status = decode_compound_hdr(&xdr, &hdr);
4224 status = decode_putfh(&xdr);
4227 status = decode_lockt(&xdr, res);
4233 * Decode LOCKU response
4235 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4237 struct xdr_stream xdr;
4238 struct compound_hdr hdr;
4241 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4242 status = decode_compound_hdr(&xdr, &hdr);
4245 status = decode_putfh(&xdr);
4248 status = decode_locku(&xdr, res);
4254 * Decode READLINK response
4256 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4257 struct nfs4_readlink_res *res)
4259 struct xdr_stream xdr;
4260 struct compound_hdr hdr;
4263 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4264 status = decode_compound_hdr(&xdr, &hdr);
4267 status = decode_putfh(&xdr);
4270 status = decode_readlink(&xdr, rqstp);
4276 * Decode READDIR response
4278 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4280 struct xdr_stream xdr;
4281 struct compound_hdr hdr;
4284 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4285 status = decode_compound_hdr(&xdr, &hdr);
4288 status = decode_putfh(&xdr);
4291 status = decode_readdir(&xdr, rqstp, res);
4297 * Decode Read response
4299 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4301 struct xdr_stream xdr;
4302 struct compound_hdr hdr;
4305 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4306 status = decode_compound_hdr(&xdr, &hdr);
4309 status = decode_putfh(&xdr);
4312 status = decode_read(&xdr, rqstp, res);
4314 status = res->count;
4320 * Decode WRITE response
4322 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4324 struct xdr_stream xdr;
4325 struct compound_hdr hdr;
4328 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4329 status = decode_compound_hdr(&xdr, &hdr);
4332 status = decode_putfh(&xdr);
4335 status = decode_write(&xdr, res);
4338 decode_getfattr(&xdr, res->fattr, res->server);
4340 status = res->count;
4346 * Decode COMMIT response
4348 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4350 struct xdr_stream xdr;
4351 struct compound_hdr hdr;
4354 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4355 status = decode_compound_hdr(&xdr, &hdr);
4358 status = decode_putfh(&xdr);
4361 status = decode_commit(&xdr, res);
4364 decode_getfattr(&xdr, res->fattr, res->server);
4372 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
4373 struct nfs4_fsinfo_res *res)
4375 struct xdr_stream xdr;
4376 struct compound_hdr hdr;
4379 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4380 status = decode_compound_hdr(&xdr, &hdr);
4382 status = decode_putfh(&xdr);
4384 status = decode_fsinfo(&xdr, res->fsinfo);
4391 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
4392 struct nfs4_pathconf_res *res)
4394 struct xdr_stream xdr;
4395 struct compound_hdr hdr;
4398 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4399 status = decode_compound_hdr(&xdr, &hdr);
4401 status = decode_putfh(&xdr);
4403 status = decode_pathconf(&xdr, res->pathconf);
4410 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
4411 struct nfs4_statfs_res *res)
4413 struct xdr_stream xdr;
4414 struct compound_hdr hdr;
4417 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4418 status = decode_compound_hdr(&xdr, &hdr);
4420 status = decode_putfh(&xdr);
4422 status = decode_statfs(&xdr, res->fsstat);
4427 * GETATTR_BITMAP request
4429 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
4431 struct xdr_stream xdr;
4432 struct compound_hdr hdr;
4435 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4436 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4438 if ((status = decode_putfh(&xdr)) != 0)
4440 status = decode_server_caps(&xdr, res);
4446 * Decode RENEW response
4448 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
4450 struct xdr_stream xdr;
4451 struct compound_hdr hdr;
4454 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4455 status = decode_compound_hdr(&xdr, &hdr);
4457 status = decode_renew(&xdr);
4462 * a SETCLIENTID request
4464 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4465 struct nfs_client *clp)
4467 struct xdr_stream xdr;
4468 struct compound_hdr hdr;
4471 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4472 status = decode_compound_hdr(&xdr, &hdr);
4474 status = decode_setclientid(&xdr, clp);
4479 * a SETCLIENTID_CONFIRM request
4481 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4483 struct xdr_stream xdr;
4484 struct compound_hdr hdr;
4487 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4488 status = decode_compound_hdr(&xdr, &hdr);
4490 status = decode_setclientid_confirm(&xdr);
4492 status = decode_putrootfh(&xdr);
4494 status = decode_fsinfo(&xdr, fsinfo);
4499 * DELEGRETURN request
4501 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
4503 struct xdr_stream xdr;
4504 struct compound_hdr hdr;
4507 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4508 status = decode_compound_hdr(&xdr, &hdr);
4511 status = decode_putfh(&xdr);
4514 status = decode_delegreturn(&xdr);
4515 decode_getfattr(&xdr, res->fattr, res->server);
4521 * FS_LOCATIONS request
4523 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
4524 struct nfs4_fs_locations_res *res)
4526 struct xdr_stream xdr;
4527 struct compound_hdr hdr;
4530 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4531 status = decode_compound_hdr(&xdr, &hdr);
4534 if ((status = decode_putfh(&xdr)) != 0)
4536 if ((status = decode_lookup(&xdr)) != 0)
4538 xdr_enter_page(&xdr, PAGE_SIZE);
4539 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
4540 res->fs_locations->server);
4545 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
4547 uint32_t bitmap[2] = {0};
4552 return ERR_PTR(-EAGAIN);
4554 return ERR_PTR(-EBADCOOKIE);
4557 entry->prev_cookie = entry->cookie;
4558 p = xdr_decode_hyper(p, &entry->cookie);
4559 entry->len = ntohl(*p++);
4560 entry->name = (const char *) p;
4561 p += XDR_QUADLEN(entry->len);
4564 * In case the server doesn't return an inode number,
4565 * we fake one here. (We don't use inode number 0,
4566 * since glibc seems to choke on it...)
4570 len = ntohl(*p++); /* bitmap length */
4572 bitmap[0] = ntohl(*p++);
4574 bitmap[1] = ntohl(*p++);
4578 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4580 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4581 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4582 /* Ignore the return value of rdattr_error for now */
4586 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4587 xdr_decode_hyper(p, &entry->ino);
4588 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4589 xdr_decode_hyper(p, &entry->ino);
4593 entry->eof = !p[0] && p[1];
4598 * We need to translate between nfs status return values and
4599 * the local errno values which may not be the same.
4606 { NFS4ERR_PERM, -EPERM },
4607 { NFS4ERR_NOENT, -ENOENT },
4608 { NFS4ERR_IO, -errno_NFSERR_IO},
4609 { NFS4ERR_NXIO, -ENXIO },
4610 { NFS4ERR_ACCESS, -EACCES },
4611 { NFS4ERR_EXIST, -EEXIST },
4612 { NFS4ERR_XDEV, -EXDEV },
4613 { NFS4ERR_NOTDIR, -ENOTDIR },
4614 { NFS4ERR_ISDIR, -EISDIR },
4615 { NFS4ERR_INVAL, -EINVAL },
4616 { NFS4ERR_FBIG, -EFBIG },
4617 { NFS4ERR_NOSPC, -ENOSPC },
4618 { NFS4ERR_ROFS, -EROFS },
4619 { NFS4ERR_MLINK, -EMLINK },
4620 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
4621 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
4622 { NFS4ERR_DQUOT, -EDQUOT },
4623 { NFS4ERR_STALE, -ESTALE },
4624 { NFS4ERR_BADHANDLE, -EBADHANDLE },
4625 { NFS4ERR_BADOWNER, -EINVAL },
4626 { NFS4ERR_BADNAME, -EINVAL },
4627 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
4628 { NFS4ERR_NOTSUPP, -ENOTSUPP },
4629 { NFS4ERR_TOOSMALL, -ETOOSMALL },
4630 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
4631 { NFS4ERR_BADTYPE, -EBADTYPE },
4632 { NFS4ERR_LOCKED, -EAGAIN },
4633 { NFS4ERR_RESOURCE, -EREMOTEIO },
4634 { NFS4ERR_SYMLINK, -ELOOP },
4635 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
4636 { NFS4ERR_DEADLOCK, -EDEADLK },
4637 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
4638 * to be handled by a
4645 * Convert an NFS error code to a local one.
4646 * This one is used jointly by NFSv2 and NFSv3.
4649 nfs4_stat_to_errno(int stat)
4652 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4653 if (nfs_errtbl[i].stat == stat)
4654 return nfs_errtbl[i].errno;
4656 if (stat <= 10000 || stat > 10100) {
4657 /* The server is looney tunes. */
4658 return -ESERVERFAULT;
4660 /* If we cannot translate the error, the recovery routines should
4662 * Note: remaining NFSv4 error codes have values > 10000, so should
4663 * not conflict with native Linux error codes.
4668 #define PROC(proc, argtype, restype) \
4669 [NFSPROC4_CLNT_##proc] = { \
4670 .p_proc = NFSPROC4_COMPOUND, \
4671 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4672 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4673 .p_arglen = NFS4_##argtype##_sz, \
4674 .p_replen = NFS4_##restype##_sz, \
4675 .p_statidx = NFSPROC4_CLNT_##proc, \
4679 struct rpc_procinfo nfs4_procedures[] = {
4680 PROC(READ, enc_read, dec_read),
4681 PROC(WRITE, enc_write, dec_write),
4682 PROC(COMMIT, enc_commit, dec_commit),
4683 PROC(OPEN, enc_open, dec_open),
4684 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4685 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4686 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4687 PROC(CLOSE, enc_close, dec_close),
4688 PROC(SETATTR, enc_setattr, dec_setattr),
4689 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4690 PROC(RENEW, enc_renew, dec_renew),
4691 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4692 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4693 PROC(LOCK, enc_lock, dec_lock),
4694 PROC(LOCKT, enc_lockt, dec_lockt),
4695 PROC(LOCKU, enc_locku, dec_locku),
4696 PROC(ACCESS, enc_access, dec_access),
4697 PROC(GETATTR, enc_getattr, dec_getattr),
4698 PROC(LOOKUP, enc_lookup, dec_lookup),
4699 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4700 PROC(REMOVE, enc_remove, dec_remove),
4701 PROC(RENAME, enc_rename, dec_rename),
4702 PROC(LINK, enc_link, dec_link),
4703 PROC(SYMLINK, enc_symlink, dec_symlink),
4704 PROC(CREATE, enc_create, dec_create),
4705 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4706 PROC(STATFS, enc_statfs, dec_statfs),
4707 PROC(READLINK, enc_readlink, dec_readlink),
4708 PROC(READDIR, enc_readdir, dec_readdir),
4709 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4710 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4711 PROC(GETACL, enc_getacl, dec_getacl),
4712 PROC(SETACL, enc_setacl, dec_setacl),
4713 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4716 struct rpc_version nfs_version4 = {
4718 .nrprocs = ARRAY_SIZE(nfs4_procedures),
4719 .procs = nfs4_procedures