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 encode_rename_maxsz (op_encode_hdr_maxsz + \
197 #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
198 #define encode_link_maxsz (op_encode_hdr_maxsz + \
200 #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
201 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
203 1 + encode_stateid_maxsz + 8)
204 #define decode_lock_denied_maxsz \
205 (8 + decode_lockowner_maxsz)
206 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
207 decode_lock_denied_maxsz)
208 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
209 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
210 decode_lock_denied_maxsz)
211 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
212 encode_stateid_maxsz + \
214 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
215 decode_stateid_maxsz)
216 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
217 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
218 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
219 1 + nfs4_name_maxsz + \
222 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
223 #define encode_create_maxsz (op_encode_hdr_maxsz + \
224 1 + 2 + nfs4_name_maxsz + \
226 #define decode_create_maxsz (op_decode_hdr_maxsz + \
227 decode_change_info_maxsz + \
228 nfs4_fattr_bitmap_maxsz)
229 #define encode_statfs_maxsz (encode_getattr_maxsz)
230 #define decode_statfs_maxsz (decode_getattr_maxsz)
231 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
232 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
233 #define encode_getacl_maxsz (encode_getattr_maxsz)
234 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
235 nfs4_fattr_bitmap_maxsz + 1)
236 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
237 encode_stateid_maxsz + 3)
238 #define decode_setacl_maxsz (decode_setattr_maxsz)
239 #define encode_fs_locations_maxsz \
240 (encode_getattr_maxsz)
241 #define decode_fs_locations_maxsz \
243 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
244 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
245 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
246 encode_putfh_maxsz + \
248 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
249 decode_putfh_maxsz + \
251 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
252 encode_putfh_maxsz + \
253 encode_readlink_maxsz)
254 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
255 decode_putfh_maxsz + \
256 decode_readlink_maxsz)
257 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
258 encode_putfh_maxsz + \
259 encode_readdir_maxsz)
260 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
261 decode_putfh_maxsz + \
262 decode_readdir_maxsz)
263 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
264 encode_putfh_maxsz + \
265 encode_write_maxsz + \
266 encode_getattr_maxsz)
267 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
268 decode_putfh_maxsz + \
269 decode_write_maxsz + \
270 decode_getattr_maxsz)
271 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
272 encode_putfh_maxsz + \
273 encode_commit_maxsz + \
274 encode_getattr_maxsz)
275 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
276 decode_putfh_maxsz + \
277 decode_commit_maxsz + \
278 decode_getattr_maxsz)
279 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
280 encode_putfh_maxsz + \
281 encode_savefh_maxsz + \
282 encode_open_maxsz + \
283 encode_getfh_maxsz + \
284 encode_getattr_maxsz + \
285 encode_restorefh_maxsz + \
286 encode_getattr_maxsz)
287 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
288 decode_putfh_maxsz + \
289 decode_savefh_maxsz + \
290 decode_open_maxsz + \
291 decode_getfh_maxsz + \
292 decode_getattr_maxsz + \
293 decode_restorefh_maxsz + \
294 decode_getattr_maxsz)
295 #define NFS4_enc_open_confirm_sz \
296 (compound_encode_hdr_maxsz + \
297 encode_putfh_maxsz + \
298 encode_open_confirm_maxsz)
299 #define NFS4_dec_open_confirm_sz \
300 (compound_decode_hdr_maxsz + \
301 decode_putfh_maxsz + \
302 decode_open_confirm_maxsz)
303 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
304 encode_putfh_maxsz + \
305 encode_open_maxsz + \
306 encode_getattr_maxsz)
307 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
308 decode_putfh_maxsz + \
309 decode_open_maxsz + \
310 decode_getattr_maxsz)
311 #define NFS4_enc_open_downgrade_sz \
312 (compound_encode_hdr_maxsz + \
313 encode_putfh_maxsz + \
314 encode_open_downgrade_maxsz + \
315 encode_getattr_maxsz)
316 #define NFS4_dec_open_downgrade_sz \
317 (compound_decode_hdr_maxsz + \
318 decode_putfh_maxsz + \
319 decode_open_downgrade_maxsz + \
320 decode_getattr_maxsz)
321 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
322 encode_putfh_maxsz + \
323 encode_close_maxsz + \
324 encode_getattr_maxsz)
325 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
326 decode_putfh_maxsz + \
327 decode_close_maxsz + \
328 decode_getattr_maxsz)
329 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
330 encode_putfh_maxsz + \
331 encode_setattr_maxsz + \
332 encode_getattr_maxsz)
333 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
334 decode_putfh_maxsz + \
335 decode_setattr_maxsz + \
336 decode_getattr_maxsz)
337 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
338 encode_putfh_maxsz + \
340 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
341 decode_putfh_maxsz + \
343 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
345 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
347 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
348 encode_setclientid_maxsz)
349 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
350 decode_setclientid_maxsz)
351 #define NFS4_enc_setclientid_confirm_sz \
352 (compound_encode_hdr_maxsz + \
353 encode_setclientid_confirm_maxsz + \
354 encode_putrootfh_maxsz + \
356 #define NFS4_dec_setclientid_confirm_sz \
357 (compound_decode_hdr_maxsz + \
358 decode_setclientid_confirm_maxsz + \
359 decode_putrootfh_maxsz + \
361 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
362 encode_putfh_maxsz + \
364 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
365 decode_putfh_maxsz + \
367 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
368 encode_putfh_maxsz + \
370 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
371 decode_putfh_maxsz + \
373 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
374 encode_putfh_maxsz + \
376 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
377 decode_putfh_maxsz + \
379 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
380 encode_putfh_maxsz + \
381 encode_access_maxsz + \
382 encode_getattr_maxsz)
383 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
384 decode_putfh_maxsz + \
385 decode_access_maxsz + \
386 decode_getattr_maxsz)
387 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
388 encode_putfh_maxsz + \
389 encode_getattr_maxsz)
390 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
391 decode_putfh_maxsz + \
392 decode_getattr_maxsz)
393 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
394 encode_putfh_maxsz + \
395 encode_lookup_maxsz + \
396 encode_getattr_maxsz + \
398 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
399 decode_putfh_maxsz + \
400 decode_lookup_maxsz + \
401 decode_getattr_maxsz + \
403 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
404 encode_putrootfh_maxsz + \
405 encode_getattr_maxsz + \
407 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
408 decode_putrootfh_maxsz + \
409 decode_getattr_maxsz + \
411 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
412 encode_putfh_maxsz + \
413 encode_remove_maxsz + \
414 encode_getattr_maxsz)
415 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
416 decode_putfh_maxsz + \
417 op_decode_hdr_maxsz + 5 + \
418 decode_getattr_maxsz)
419 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
420 encode_putfh_maxsz + \
421 encode_savefh_maxsz + \
422 encode_putfh_maxsz + \
423 encode_rename_maxsz + \
424 encode_getattr_maxsz + \
425 encode_restorefh_maxsz + \
426 encode_getattr_maxsz)
427 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
428 decode_putfh_maxsz + \
429 decode_savefh_maxsz + \
430 decode_putfh_maxsz + \
431 decode_rename_maxsz + \
432 decode_getattr_maxsz + \
433 decode_restorefh_maxsz + \
434 decode_getattr_maxsz)
435 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
436 encode_putfh_maxsz + \
437 encode_savefh_maxsz + \
438 encode_putfh_maxsz + \
439 encode_link_maxsz + \
440 decode_getattr_maxsz + \
441 encode_restorefh_maxsz + \
442 decode_getattr_maxsz)
443 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
444 decode_putfh_maxsz + \
445 decode_savefh_maxsz + \
446 decode_putfh_maxsz + \
447 decode_link_maxsz + \
448 decode_getattr_maxsz + \
449 decode_restorefh_maxsz + \
450 decode_getattr_maxsz)
451 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
452 encode_putfh_maxsz + \
453 encode_symlink_maxsz + \
454 encode_getattr_maxsz + \
456 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
457 decode_putfh_maxsz + \
458 decode_symlink_maxsz + \
459 decode_getattr_maxsz + \
461 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
462 encode_putfh_maxsz + \
463 encode_savefh_maxsz + \
464 encode_create_maxsz + \
465 encode_getfh_maxsz + \
466 encode_getattr_maxsz + \
467 encode_restorefh_maxsz + \
468 encode_getattr_maxsz)
469 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
470 decode_putfh_maxsz + \
471 decode_savefh_maxsz + \
472 decode_create_maxsz + \
473 decode_getfh_maxsz + \
474 decode_getattr_maxsz + \
475 decode_restorefh_maxsz + \
476 decode_getattr_maxsz)
477 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
478 encode_putfh_maxsz + \
479 encode_getattr_maxsz)
480 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
481 decode_putfh_maxsz + \
482 decode_getattr_maxsz)
483 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
484 encode_putfh_maxsz + \
486 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
487 decode_putfh_maxsz + \
489 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
490 encode_putfh_maxsz + \
491 encode_getattr_maxsz)
492 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
493 decode_putfh_maxsz + \
494 decode_getattr_maxsz)
495 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
496 encode_putfh_maxsz + \
497 encode_delegreturn_maxsz + \
498 encode_getattr_maxsz)
499 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
500 decode_delegreturn_maxsz + \
501 decode_getattr_maxsz)
502 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
503 encode_putfh_maxsz + \
505 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
506 decode_putfh_maxsz + \
508 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
509 encode_putfh_maxsz + \
511 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
512 decode_putfh_maxsz + \
514 #define NFS4_enc_fs_locations_sz \
515 (compound_encode_hdr_maxsz + \
516 encode_putfh_maxsz + \
517 encode_lookup_maxsz + \
518 encode_fs_locations_maxsz)
519 #define NFS4_dec_fs_locations_sz \
520 (compound_decode_hdr_maxsz + \
521 decode_putfh_maxsz + \
522 decode_lookup_maxsz + \
523 decode_fs_locations_maxsz)
527 unsigned int nfs2type;
535 { S_IFSOCK, NFSOCK },
541 struct compound_hdr {
550 * START OF "GENERIC" ENCODE ROUTINES.
551 * These may look a little ugly since they are imported from a "generic"
552 * set of XDR encode/decode routines which are intended to be shared by
553 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
555 * If the pain of reading these is too great, it should be a straightforward
556 * task to translate them into Linux-specific versions which are more
557 * consistent with the style used in NFSv2/v3...
559 #define WRITE32(n) *p++ = htonl(n)
560 #define WRITE64(n) do { \
561 *p++ = htonl((uint32_t)((n) >> 32)); \
562 *p++ = htonl((uint32_t)(n)); \
564 #define WRITEMEM(ptr,nbytes) do { \
565 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
568 #define RESERVE_SPACE(nbytes) do { \
569 p = xdr_reserve_space(xdr, nbytes); \
573 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
577 p = xdr_reserve_space(xdr, 4 + len);
579 xdr_encode_opaque(p, str, len);
582 static void encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
586 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
587 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
588 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
589 WRITE32(hdr->taglen);
590 WRITEMEM(hdr->tag, hdr->taglen);
591 WRITE32(NFS4_MINOR_VERSION);
596 static void encode_nops(struct compound_hdr *hdr)
598 *hdr->nops_p = htonl(hdr->nops);
601 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
605 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
607 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
610 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
612 char owner_name[IDMAP_NAMESZ];
613 char owner_group[IDMAP_NAMESZ];
614 int owner_namelen = 0;
615 int owner_grouplen = 0;
623 * We reserve enough space to write the entire attribute buffer at once.
624 * In the worst-case, this would be
625 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
626 * = 36 bytes, plus any contribution from variable-length fields
627 * such as owner/group.
632 if (iap->ia_valid & ATTR_SIZE)
634 if (iap->ia_valid & ATTR_MODE)
636 if (iap->ia_valid & ATTR_UID) {
637 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
638 if (owner_namelen < 0) {
639 dprintk("nfs: couldn't resolve uid %d to string\n",
642 strcpy(owner_name, "nobody");
643 owner_namelen = sizeof("nobody") - 1;
646 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
648 if (iap->ia_valid & ATTR_GID) {
649 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
650 if (owner_grouplen < 0) {
651 dprintk("nfs: couldn't resolve gid %d to string\n",
653 strcpy(owner_group, "nobody");
654 owner_grouplen = sizeof("nobody") - 1;
657 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
659 if (iap->ia_valid & ATTR_ATIME_SET)
661 else if (iap->ia_valid & ATTR_ATIME)
663 if (iap->ia_valid & ATTR_MTIME_SET)
665 else if (iap->ia_valid & ATTR_MTIME)
670 * We write the bitmap length now, but leave the bitmap and the attribute
671 * buffer length to be backfilled at the end of this routine.
677 if (iap->ia_valid & ATTR_SIZE) {
678 bmval0 |= FATTR4_WORD0_SIZE;
679 WRITE64(iap->ia_size);
681 if (iap->ia_valid & ATTR_MODE) {
682 bmval1 |= FATTR4_WORD1_MODE;
683 WRITE32(iap->ia_mode & S_IALLUGO);
685 if (iap->ia_valid & ATTR_UID) {
686 bmval1 |= FATTR4_WORD1_OWNER;
687 WRITE32(owner_namelen);
688 WRITEMEM(owner_name, owner_namelen);
690 if (iap->ia_valid & ATTR_GID) {
691 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
692 WRITE32(owner_grouplen);
693 WRITEMEM(owner_group, owner_grouplen);
695 if (iap->ia_valid & ATTR_ATIME_SET) {
696 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
697 WRITE32(NFS4_SET_TO_CLIENT_TIME);
699 WRITE32(iap->ia_mtime.tv_sec);
700 WRITE32(iap->ia_mtime.tv_nsec);
702 else if (iap->ia_valid & ATTR_ATIME) {
703 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
704 WRITE32(NFS4_SET_TO_SERVER_TIME);
706 if (iap->ia_valid & ATTR_MTIME_SET) {
707 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
708 WRITE32(NFS4_SET_TO_CLIENT_TIME);
710 WRITE32(iap->ia_mtime.tv_sec);
711 WRITE32(iap->ia_mtime.tv_nsec);
713 else if (iap->ia_valid & ATTR_MTIME) {
714 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
715 WRITE32(NFS4_SET_TO_SERVER_TIME);
719 * Now we backfill the bitmap and the attribute buffer length.
721 if (len != ((char *)p - (char *)q) + 4) {
722 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
723 len, ((char *)p - (char *)q) + 4);
726 len = (char *)p - (char *)q - 12;
727 *q++ = htonl(bmval0);
728 *q++ = htonl(bmval1);
734 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
744 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
748 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
750 WRITE32(arg->seqid->sequence->counter);
751 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
755 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
761 WRITE64(args->offset);
762 WRITE32(args->count);
766 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
772 WRITE32(create->ftype);
774 switch (create->ftype) {
777 WRITE32(create->u.symlink.len);
778 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
781 case NF4BLK: case NF4CHR:
783 WRITE32(create->u.device.specdata1);
784 WRITE32(create->u.device.specdata2);
791 RESERVE_SPACE(4 + create->name->len);
792 WRITE32(create->name->len);
793 WRITEMEM(create->name->name, create->name->len);
796 encode_attrs(xdr, create->attrs, create->server);
799 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
810 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
822 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
824 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
825 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
828 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
830 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
831 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
834 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
836 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
837 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
840 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
849 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
853 RESERVE_SPACE(8 + name->len);
856 WRITEMEM(name->name, name->len);
860 static inline int nfs4_lock_type(struct file_lock *fl, int block)
862 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
863 return block ? NFS4_READW_LT : NFS4_READ_LT;
864 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
867 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
869 if (fl->fl_end == OFFSET_MAX)
871 return fl->fl_end - fl->fl_start + 1;
875 * opcode,type,reclaim,offset,length,new_lock_owner = 32
876 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
878 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
884 WRITE32(nfs4_lock_type(args->fl, args->block));
885 WRITE32(args->reclaim);
886 WRITE64(args->fl->fl_start);
887 WRITE64(nfs4_lock_length(args->fl));
888 WRITE32(args->new_lock_owner);
889 if (args->new_lock_owner){
890 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
891 WRITE32(args->open_seqid->sequence->counter);
892 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
893 WRITE32(args->lock_seqid->sequence->counter);
894 WRITE64(args->lock_owner.clientid);
896 WRITEMEM("lock id:", 8);
897 WRITE64(args->lock_owner.id);
900 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
901 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
902 WRITE32(args->lock_seqid->sequence->counter);
907 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
913 WRITE32(nfs4_lock_type(args->fl, 0));
914 WRITE64(args->fl->fl_start);
915 WRITE64(nfs4_lock_length(args->fl));
916 WRITE64(args->lock_owner.clientid);
918 WRITEMEM("lock id:", 8);
919 WRITE64(args->lock_owner.id);
923 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
927 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
929 WRITE32(nfs4_lock_type(args->fl, 0));
930 WRITE32(args->seqid->sequence->counter);
931 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
932 WRITE64(args->fl->fl_start);
933 WRITE64(nfs4_lock_length(args->fl));
937 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
942 RESERVE_SPACE(8 + len);
945 WRITEMEM(name->name, len);
949 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
954 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
956 WRITE32(NFS4_SHARE_ACCESS_READ);
959 WRITE32(NFS4_SHARE_ACCESS_WRITE);
961 case FMODE_READ|FMODE_WRITE:
962 WRITE32(NFS4_SHARE_ACCESS_BOTH);
967 WRITE32(0); /* for linux, share_deny = 0 always */
970 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
974 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
979 WRITE32(arg->seqid->sequence->counter);
980 encode_share_access(xdr, arg->fmode);
982 WRITE64(arg->clientid);
984 WRITEMEM("open id:", 8);
988 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
993 switch(arg->open_flags & O_EXCL) {
995 WRITE32(NFS4_CREATE_UNCHECKED);
996 encode_attrs(xdr, arg->u.attrs, arg->server);
999 WRITE32(NFS4_CREATE_EXCLUSIVE);
1000 encode_nfs4_verifier(xdr, &arg->u.verifier);
1004 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1009 switch (arg->open_flags & O_CREAT) {
1011 WRITE32(NFS4_OPEN_NOCREATE);
1014 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1015 WRITE32(NFS4_OPEN_CREATE);
1016 encode_createmode(xdr, arg);
1020 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1025 switch (delegation_type) {
1027 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1030 WRITE32(NFS4_OPEN_DELEGATE_READ);
1032 case FMODE_WRITE|FMODE_READ:
1033 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1040 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1045 WRITE32(NFS4_OPEN_CLAIM_NULL);
1046 encode_string(xdr, name->len, name->name);
1049 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1054 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1055 encode_delegation_type(xdr, type);
1058 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1062 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1063 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1064 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1065 encode_string(xdr, name->len, name->name);
1068 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1070 encode_openhdr(xdr, arg);
1071 encode_opentype(xdr, arg);
1072 switch (arg->claim) {
1073 case NFS4_OPEN_CLAIM_NULL:
1074 encode_claim_null(xdr, arg->name);
1076 case NFS4_OPEN_CLAIM_PREVIOUS:
1077 encode_claim_previous(xdr, arg->u.delegation_type);
1079 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1080 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1088 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1092 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1093 WRITE32(OP_OPEN_CONFIRM);
1094 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1095 WRITE32(arg->seqid->sequence->counter);
1099 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1103 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1104 WRITE32(OP_OPEN_DOWNGRADE);
1105 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1106 WRITE32(arg->seqid->sequence->counter);
1107 encode_share_access(xdr, arg->fmode);
1112 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1117 RESERVE_SPACE(8 + len);
1120 WRITEMEM(fh->data, len);
1124 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1129 WRITE32(OP_PUTROOTFH);
1133 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1135 nfs4_stateid stateid;
1138 RESERVE_SPACE(NFS4_STATEID_SIZE);
1139 if (ctx->state != NULL) {
1140 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1141 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1143 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1146 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1153 encode_stateid(xdr, args->context);
1156 WRITE64(args->offset);
1157 WRITE32(args->count);
1161 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1163 uint32_t attrs[2] = {
1164 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1165 FATTR4_WORD1_MOUNTED_ON_FILEID,
1169 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1170 WRITE32(OP_READDIR);
1171 WRITE64(readdir->cookie);
1172 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1173 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1174 WRITE32(readdir->count);
1176 /* Switch to mounted_on_fileid if the server supports it */
1177 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1178 attrs[0] &= ~FATTR4_WORD0_FILEID;
1180 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1181 WRITE32(attrs[0] & readdir->bitmask[0]);
1182 WRITE32(attrs[1] & readdir->bitmask[1]);
1184 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1186 (unsigned long long)readdir->cookie,
1187 ((u32 *)readdir->verifier.data)[0],
1188 ((u32 *)readdir->verifier.data)[1],
1189 attrs[0] & readdir->bitmask[0],
1190 attrs[1] & readdir->bitmask[1]);
1193 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1198 WRITE32(OP_READLINK);
1202 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1206 RESERVE_SPACE(8 + name->len);
1209 WRITEMEM(name->name, name->len);
1213 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1217 RESERVE_SPACE(8 + oldname->len);
1219 WRITE32(oldname->len);
1220 WRITEMEM(oldname->name, oldname->len);
1222 RESERVE_SPACE(4 + newname->len);
1223 WRITE32(newname->len);
1224 WRITEMEM(newname->name, newname->len);
1228 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1234 WRITE64(client_stateid->cl_clientid);
1239 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1244 WRITE32(OP_RESTOREFH);
1249 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1253 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1254 WRITE32(OP_SETATTR);
1255 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1258 WRITE32(FATTR4_WORD0_ACL);
1259 if (arg->acl_len % 4)
1262 WRITE32(arg->acl_len);
1263 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1269 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1278 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1282 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1283 WRITE32(OP_SETATTR);
1284 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1286 encode_attrs(xdr, arg->iap, server);
1289 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1293 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1294 WRITE32(OP_SETCLIENTID);
1295 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1297 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1299 WRITE32(setclientid->sc_prog);
1300 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1301 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1303 WRITE32(setclientid->sc_cb_ident);
1307 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
1311 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1312 WRITE32(OP_SETCLIENTID_CONFIRM);
1313 WRITE64(client_state->cl_clientid);
1314 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1318 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1325 encode_stateid(xdr, args->context);
1328 WRITE64(args->offset);
1329 WRITE32(args->stable);
1330 WRITE32(args->count);
1332 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1336 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1340 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1342 WRITE32(OP_DELEGRETURN);
1343 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1347 * END OF "GENERIC" ENCODE ROUTINES.
1351 * Encode an ACCESS request
1353 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1355 struct xdr_stream xdr;
1356 struct compound_hdr hdr = {
1360 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1361 encode_compound_hdr(&xdr, &hdr);
1362 encode_putfh(&xdr, args->fh, &hdr);
1363 encode_access(&xdr, args->access, &hdr);
1364 encode_getfattr(&xdr, args->bitmask, &hdr);
1370 * Encode LOOKUP request
1372 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1374 struct xdr_stream xdr;
1375 struct compound_hdr hdr = {
1379 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1380 encode_compound_hdr(&xdr, &hdr);
1381 encode_putfh(&xdr, args->dir_fh, &hdr);
1382 encode_lookup(&xdr, args->name, &hdr);
1383 encode_getfh(&xdr, &hdr);
1384 encode_getfattr(&xdr, args->bitmask, &hdr);
1390 * Encode LOOKUP_ROOT request
1392 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1394 struct xdr_stream xdr;
1395 struct compound_hdr hdr = {
1399 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1400 encode_compound_hdr(&xdr, &hdr);
1401 encode_putrootfh(&xdr, &hdr);
1402 encode_getfh(&xdr, &hdr);
1403 encode_getfattr(&xdr, args->bitmask, &hdr);
1409 * Encode REMOVE request
1411 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
1413 struct xdr_stream xdr;
1414 struct compound_hdr hdr = {
1418 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1419 encode_compound_hdr(&xdr, &hdr);
1420 encode_putfh(&xdr, args->fh, &hdr);
1421 encode_remove(&xdr, &args->name, &hdr);
1422 encode_getfattr(&xdr, args->bitmask, &hdr);
1428 * Encode RENAME request
1430 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1432 struct xdr_stream xdr;
1433 struct compound_hdr hdr = {
1437 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1438 encode_compound_hdr(&xdr, &hdr);
1439 encode_putfh(&xdr, args->old_dir, &hdr);
1440 encode_savefh(&xdr, &hdr);
1441 encode_putfh(&xdr, args->new_dir, &hdr);
1442 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1443 encode_getfattr(&xdr, args->bitmask, &hdr);
1444 encode_restorefh(&xdr, &hdr);
1445 encode_getfattr(&xdr, args->bitmask, &hdr);
1451 * Encode LINK request
1453 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1455 struct xdr_stream xdr;
1456 struct compound_hdr hdr = {
1460 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1461 encode_compound_hdr(&xdr, &hdr);
1462 encode_putfh(&xdr, args->fh, &hdr);
1463 encode_savefh(&xdr, &hdr);
1464 encode_putfh(&xdr, args->dir_fh, &hdr);
1465 encode_link(&xdr, args->name, &hdr);
1466 encode_getfattr(&xdr, args->bitmask, &hdr);
1467 encode_restorefh(&xdr, &hdr);
1468 encode_getfattr(&xdr, args->bitmask, &hdr);
1474 * Encode CREATE request
1476 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1478 struct xdr_stream xdr;
1479 struct compound_hdr hdr = {
1483 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1484 encode_compound_hdr(&xdr, &hdr);
1485 encode_putfh(&xdr, args->dir_fh, &hdr);
1486 encode_savefh(&xdr, &hdr);
1487 encode_create(&xdr, args, &hdr);
1488 encode_getfh(&xdr, &hdr);
1489 encode_getfattr(&xdr, args->bitmask, &hdr);
1490 encode_restorefh(&xdr, &hdr);
1491 encode_getfattr(&xdr, args->bitmask, &hdr);
1497 * Encode SYMLINK request
1499 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1501 return nfs4_xdr_enc_create(req, p, args);
1505 * Encode GETATTR request
1507 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1509 struct xdr_stream xdr;
1510 struct compound_hdr hdr = {
1514 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1515 encode_compound_hdr(&xdr, &hdr);
1516 encode_putfh(&xdr, args->fh, &hdr);
1517 encode_getfattr(&xdr, args->bitmask, &hdr);
1523 * Encode a CLOSE request
1525 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1527 struct xdr_stream xdr;
1528 struct compound_hdr hdr = {
1532 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1533 encode_compound_hdr(&xdr, &hdr);
1534 encode_putfh(&xdr, args->fh, &hdr);
1535 encode_close(&xdr, args, &hdr);
1536 encode_getfattr(&xdr, args->bitmask, &hdr);
1542 * Encode an OPEN request
1544 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1546 struct xdr_stream xdr;
1547 struct compound_hdr hdr = {
1551 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1552 encode_compound_hdr(&xdr, &hdr);
1553 encode_putfh(&xdr, args->fh, &hdr);
1554 encode_savefh(&xdr, &hdr);
1555 encode_open(&xdr, args, &hdr);
1556 encode_getfh(&xdr, &hdr);
1557 encode_getfattr(&xdr, args->bitmask, &hdr);
1558 encode_restorefh(&xdr, &hdr);
1559 encode_getfattr(&xdr, args->bitmask, &hdr);
1565 * Encode an OPEN_CONFIRM request
1567 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1569 struct xdr_stream xdr;
1570 struct compound_hdr hdr = {
1574 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1575 encode_compound_hdr(&xdr, &hdr);
1576 encode_putfh(&xdr, args->fh, &hdr);
1577 encode_open_confirm(&xdr, args, &hdr);
1583 * Encode an OPEN request with no attributes.
1585 static int nfs4_xdr_enc_open_noattr(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, &hdr);
1594 encode_putfh(&xdr, args->fh, &hdr);
1595 encode_open(&xdr, args, &hdr);
1596 encode_getfattr(&xdr, args->bitmask, &hdr);
1602 * Encode an OPEN_DOWNGRADE request
1604 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1606 struct xdr_stream xdr;
1607 struct compound_hdr hdr = {
1611 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1612 encode_compound_hdr(&xdr, &hdr);
1613 encode_putfh(&xdr, args->fh, &hdr);
1614 encode_open_downgrade(&xdr, args, &hdr);
1615 encode_getfattr(&xdr, args->bitmask, &hdr);
1621 * Encode a LOCK request
1623 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1625 struct xdr_stream xdr;
1626 struct compound_hdr hdr = {
1630 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1631 encode_compound_hdr(&xdr, &hdr);
1632 encode_putfh(&xdr, args->fh, &hdr);
1633 encode_lock(&xdr, args, &hdr);
1639 * Encode a LOCKT request
1641 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1643 struct xdr_stream xdr;
1644 struct compound_hdr hdr = {
1648 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1649 encode_compound_hdr(&xdr, &hdr);
1650 encode_putfh(&xdr, args->fh, &hdr);
1651 encode_lockt(&xdr, args, &hdr);
1657 * Encode a LOCKU request
1659 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1661 struct xdr_stream xdr;
1662 struct compound_hdr hdr = {
1666 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1667 encode_compound_hdr(&xdr, &hdr);
1668 encode_putfh(&xdr, args->fh, &hdr);
1669 encode_locku(&xdr, args, &hdr);
1675 * Encode a READLINK request
1677 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1679 struct xdr_stream xdr;
1680 struct compound_hdr hdr = {
1683 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1684 unsigned int replen;
1686 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1687 encode_compound_hdr(&xdr, &hdr);
1688 encode_putfh(&xdr, args->fh, &hdr);
1689 encode_readlink(&xdr, args, req, &hdr);
1691 /* set up reply kvec
1692 * toplevel_status + taglen + rescount + OP_PUTFH + status
1693 * + OP_READLINK + status + string length = 8
1695 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readlink_sz) << 2;
1696 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1697 args->pgbase, args->pglen);
1703 * Encode a READDIR request
1705 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1707 struct xdr_stream xdr;
1708 struct compound_hdr hdr = {
1711 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1714 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1715 encode_compound_hdr(&xdr, &hdr);
1716 encode_putfh(&xdr, args->fh, &hdr);
1717 encode_readdir(&xdr, args, req, &hdr);
1719 /* set up reply kvec
1720 * toplevel_status + taglen + rescount + OP_PUTFH + status
1721 * + OP_READDIR + status + verifer(2) = 9
1723 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readdir_sz) << 2;
1724 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1725 args->pgbase, args->count);
1726 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1727 __func__, replen, args->pages,
1728 args->pgbase, args->count);
1734 * Encode a READ request
1736 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1738 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1739 struct xdr_stream xdr;
1740 struct compound_hdr hdr = {
1745 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1746 encode_compound_hdr(&xdr, &hdr);
1747 encode_putfh(&xdr, args->fh, &hdr);
1748 encode_read(&xdr, args, &hdr);
1750 /* set up reply kvec
1751 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1752 * + OP_READ + status + eof + datalen = 9
1754 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1755 xdr_inline_pages(&req->rq_rcv_buf, replen,
1756 args->pages, args->pgbase, args->count);
1757 req->rq_rcv_buf.flags |= XDRBUF_READ;
1763 * Encode an SETATTR request
1765 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1767 struct xdr_stream xdr;
1768 struct compound_hdr hdr = {
1772 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1773 encode_compound_hdr(&xdr, &hdr);
1774 encode_putfh(&xdr, args->fh, &hdr);
1775 encode_setattr(&xdr, args, args->server, &hdr);
1776 encode_getfattr(&xdr, args->bitmask, &hdr);
1782 * Encode a GETACL request
1785 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
1786 struct nfs_getaclargs *args)
1788 struct xdr_stream xdr;
1789 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1790 struct compound_hdr hdr = {
1795 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1796 encode_compound_hdr(&xdr, &hdr);
1797 encode_putfh(&xdr, args->fh, &hdr);
1798 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
1800 /* set up reply buffer: */
1801 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1802 xdr_inline_pages(&req->rq_rcv_buf, replen,
1803 args->acl_pages, args->acl_pgbase, args->acl_len);
1809 * Encode a WRITE request
1811 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1813 struct xdr_stream xdr;
1814 struct compound_hdr hdr = {
1818 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1819 encode_compound_hdr(&xdr, &hdr);
1820 encode_putfh(&xdr, args->fh, &hdr);
1821 encode_write(&xdr, args, &hdr);
1822 req->rq_snd_buf.flags |= XDRBUF_WRITE;
1823 encode_getfattr(&xdr, args->bitmask, &hdr);
1831 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1833 struct xdr_stream xdr;
1834 struct compound_hdr hdr = {
1838 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1839 encode_compound_hdr(&xdr, &hdr);
1840 encode_putfh(&xdr, args->fh, &hdr);
1841 encode_commit(&xdr, args, &hdr);
1842 encode_getfattr(&xdr, args->bitmask, &hdr);
1850 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
1852 struct xdr_stream xdr;
1853 struct compound_hdr hdr = {
1857 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1858 encode_compound_hdr(&xdr, &hdr);
1859 encode_putfh(&xdr, args->fh, &hdr);
1860 encode_fsinfo(&xdr, args->bitmask, &hdr);
1866 * a PATHCONF request
1868 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_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, &hdr);
1877 encode_putfh(&xdr, args->fh, &hdr);
1878 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
1887 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
1889 struct xdr_stream xdr;
1890 struct compound_hdr hdr = {
1894 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1895 encode_compound_hdr(&xdr, &hdr);
1896 encode_putfh(&xdr, args->fh, &hdr);
1897 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
1898 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
1904 * GETATTR_BITMAP request
1906 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle)
1908 struct xdr_stream xdr;
1909 struct compound_hdr hdr = {
1913 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1914 encode_compound_hdr(&xdr, &hdr);
1915 encode_putfh(&xdr, fhandle, &hdr);
1916 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1917 FATTR4_WORD0_LINK_SUPPORT|
1918 FATTR4_WORD0_SYMLINK_SUPPORT|
1919 FATTR4_WORD0_ACLSUPPORT, &hdr);
1927 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1929 struct xdr_stream xdr;
1930 struct compound_hdr hdr = {
1934 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1935 encode_compound_hdr(&xdr, &hdr);
1936 encode_renew(&xdr, clp, &hdr);
1942 * a SETCLIENTID request
1944 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
1946 struct xdr_stream xdr;
1947 struct compound_hdr hdr = {
1951 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1952 encode_compound_hdr(&xdr, &hdr);
1953 encode_setclientid(&xdr, sc, &hdr);
1959 * a SETCLIENTID_CONFIRM request
1961 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
1963 struct xdr_stream xdr;
1964 struct compound_hdr hdr = {
1967 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1969 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1970 encode_compound_hdr(&xdr, &hdr);
1971 encode_setclientid_confirm(&xdr, clp, &hdr);
1972 encode_putrootfh(&xdr, &hdr);
1973 encode_fsinfo(&xdr, lease_bitmap, &hdr);
1979 * DELEGRETURN request
1981 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
1983 struct xdr_stream xdr;
1984 struct compound_hdr hdr = {
1988 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1989 encode_compound_hdr(&xdr, &hdr);
1990 encode_putfh(&xdr, args->fhandle, &hdr);
1991 encode_delegreturn(&xdr, args->stateid, &hdr);
1992 encode_getfattr(&xdr, args->bitmask, &hdr);
1998 * Encode FS_LOCATIONS request
2000 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2002 struct xdr_stream xdr;
2003 struct compound_hdr hdr = {
2006 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
2009 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2010 encode_compound_hdr(&xdr, &hdr);
2011 encode_putfh(&xdr, args->dir_fh, &hdr);
2012 encode_lookup(&xdr, args->name, &hdr);
2013 encode_fs_locations(&xdr, args->bitmask, &hdr);
2016 * toplevel_status + OP_PUTFH + status
2017 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2019 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2020 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2027 * START OF "GENERIC" DECODE ROUTINES.
2028 * These may look a little ugly since they are imported from a "generic"
2029 * set of XDR encode/decode routines which are intended to be shared by
2030 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2032 * If the pain of reading these is too great, it should be a straightforward
2033 * task to translate them into Linux-specific versions which are more
2034 * consistent with the style used in NFSv2/v3...
2036 #define READ32(x) (x) = ntohl(*p++)
2037 #define READ64(x) do { \
2038 (x) = (u64)ntohl(*p++) << 32; \
2039 (x) |= ntohl(*p++); \
2041 #define READTIME(x) do { \
2043 (x.tv_sec) = ntohl(*p++); \
2044 (x.tv_nsec) = ntohl(*p++); \
2046 #define COPYMEM(x,nbytes) do { \
2047 memcpy((x), p, nbytes); \
2048 p += XDR_QUADLEN(nbytes); \
2051 #define READ_BUF(nbytes) do { \
2052 p = xdr_inline_decode(xdr, nbytes); \
2053 if (unlikely(!p)) { \
2054 dprintk("nfs: %s: prematurely hit end of receive" \
2055 " buffer\n", __func__); \
2056 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2057 __func__, xdr->p, nbytes, xdr->end); \
2062 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2069 *string = (char *)p;
2073 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2078 READ32(hdr->status);
2079 READ32(hdr->taglen);
2081 READ_BUF(hdr->taglen + 4);
2082 hdr->tag = (char *)p;
2083 p += XDR_QUADLEN(hdr->taglen);
2085 if (unlikely(hdr->nops < 1))
2086 return nfs4_stat_to_errno(hdr->status);
2090 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2098 if (opnum != expected) {
2099 dprintk("nfs: Server returned operation"
2100 " %d but we issued a request for %d\n",
2105 if (nfserr != NFS_OK)
2106 return nfs4_stat_to_errno(nfserr);
2111 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2114 unsigned int strlen;
2118 return decode_opaque_inline(xdr, &strlen, &str);
2121 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2129 bitmap[0] = bitmap[1] = 0;
2130 READ_BUF((bmlen << 2));
2139 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2149 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2151 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2152 decode_attr_bitmap(xdr, bitmask);
2153 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2155 bitmask[0] = bitmask[1] = 0;
2156 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
2160 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2165 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2167 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2170 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2171 dprintk("%s: bad type %d\n", __func__, *type);
2174 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2176 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type].nfs2type);
2180 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2185 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2187 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2190 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2192 dprintk("%s: change attribute=%Lu\n", __func__,
2193 (unsigned long long)*change);
2197 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2202 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2204 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2207 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2209 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
2213 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2218 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2220 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2223 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2225 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
2229 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2234 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2236 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2239 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2241 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
2245 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2251 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2253 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2255 READ64(fsid->major);
2256 READ64(fsid->minor);
2257 bitmap[0] &= ~FATTR4_WORD0_FSID;
2259 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
2260 (unsigned long long)fsid->major,
2261 (unsigned long long)fsid->minor);
2265 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2270 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2272 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2275 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2277 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
2281 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2285 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2286 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2288 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2291 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2293 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
2297 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2302 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2304 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2307 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2309 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2313 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2318 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2320 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2323 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2325 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2329 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2335 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2337 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2340 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2342 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
2346 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2352 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2354 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2357 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2359 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
2363 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2369 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2371 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2374 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2376 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
2380 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2391 path->ncomponents = 0;
2392 while (path->ncomponents < n) {
2393 struct nfs4_string *component = &path->components[path->ncomponents];
2394 status = decode_opaque_inline(xdr, &component->len, &component->data);
2395 if (unlikely(status != 0))
2397 if (path->ncomponents != n)
2399 dprintk("%s", component->data);
2400 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2401 path->ncomponents++;
2403 dprintk("cannot parse %d components in path\n", n);
2411 /* a root pathname is sent as a zero component4 */
2412 path->ncomponents = 1;
2413 path->components[0].len=0;
2414 path->components[0].data=NULL;
2415 dprintk("path /\n");
2418 dprintk(" status %d", status);
2423 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2429 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2432 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2434 dprintk("%s: fsroot ", __func__);
2435 status = decode_pathname(xdr, &res->fs_path);
2436 if (unlikely(status != 0))
2442 res->nlocations = 0;
2443 while (res->nlocations < n) {
2445 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2451 dprintk("%s: servers ", __func__);
2452 while (loc->nservers < m) {
2453 struct nfs4_string *server = &loc->servers[loc->nservers];
2454 status = decode_opaque_inline(xdr, &server->len, &server->data);
2455 if (unlikely(status != 0))
2457 dprintk("%s ", server->data);
2458 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2462 dprintk("%s: using first %u of %u servers "
2463 "returned for location %u\n",
2465 NFS4_FS_LOCATION_MAXSERVERS,
2466 m, res->nlocations);
2467 for (i = loc->nservers; i < m; i++) {
2470 status = decode_opaque_inline(xdr, &len, &data);
2471 if (unlikely(status != 0))
2476 status = decode_pathname(xdr, &loc->rootpath);
2477 if (unlikely(status != 0))
2479 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2483 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
2490 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2496 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2498 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2501 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2503 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
2507 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2513 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2515 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2518 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2520 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
2524 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2530 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2532 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2535 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2537 dprintk("%s: maxname=%u\n", __func__, *maxname);
2541 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2547 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2549 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2553 if (maxread > 0x7FFFFFFF)
2554 maxread = 0x7FFFFFFF;
2555 *res = (uint32_t)maxread;
2556 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2558 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
2562 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2568 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2570 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2574 if (maxwrite > 0x7FFFFFFF)
2575 maxwrite = 0x7FFFFFFF;
2576 *res = (uint32_t)maxwrite;
2577 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2579 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
2583 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2588 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2590 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2594 bitmap[1] &= ~FATTR4_WORD1_MODE;
2596 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
2600 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2605 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2607 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2610 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2612 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
2616 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
2622 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2624 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2628 if (len < XDR_MAX_NETOBJ) {
2629 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2630 dprintk("%s: nfs_map_name_to_uid failed!\n",
2633 dprintk("%s: name too long (%u)!\n",
2635 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2637 dprintk("%s: uid=%d\n", __func__, (int)*uid);
2641 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
2647 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2649 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2653 if (len < XDR_MAX_NETOBJ) {
2654 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2655 dprintk("%s: nfs_map_group_to_gid failed!\n",
2658 dprintk("%s: name too long (%u)!\n",
2660 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2662 dprintk("%s: gid=%d\n", __func__, (int)*gid);
2666 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2668 uint32_t major = 0, minor = 0;
2672 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2674 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2680 tmp = MKDEV(major, minor);
2681 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2683 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2685 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
2689 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2695 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2697 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2700 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2702 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
2706 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2712 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2714 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2717 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2719 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
2723 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2729 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2731 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2734 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2736 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
2740 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2745 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2747 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2750 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2752 dprintk("%s: space used=%Lu\n", __func__,
2753 (unsigned long long)*used);
2757 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2766 time->tv_sec = (time_t)sec;
2767 time->tv_nsec = (long)nsec;
2771 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2777 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2779 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2780 status = decode_attr_time(xdr, time);
2781 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2783 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
2787 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2793 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2795 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2796 status = decode_attr_time(xdr, time);
2797 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2799 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
2803 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2809 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2811 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2812 status = decode_attr_time(xdr, time);
2813 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2815 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
2819 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
2821 unsigned int attrwords = XDR_QUADLEN(attrlen);
2822 unsigned int nwords = xdr->p - savep;
2824 if (unlikely(attrwords != nwords)) {
2825 dprintk("%s: server returned incorrect attribute length: "
2829 (attrwords < nwords) ? '<' : '>',
2836 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2841 READ32(cinfo->atomic);
2842 READ64(cinfo->before);
2843 READ64(cinfo->after);
2847 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2853 status = decode_op_hdr(xdr, OP_ACCESS);
2859 access->supported = supp;
2860 access->access = acc;
2864 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2869 status = decode_op_hdr(xdr, OP_CLOSE);
2871 nfs_increment_open_seqid(status, res->seqid);
2874 READ_BUF(NFS4_STATEID_SIZE);
2875 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
2879 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2884 status = decode_op_hdr(xdr, OP_COMMIT);
2888 COPYMEM(res->verf->verifier, 8);
2892 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2898 status = decode_op_hdr(xdr, OP_CREATE);
2901 if ((status = decode_change_info(xdr, cinfo)))
2905 READ_BUF(bmlen << 2);
2909 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2912 uint32_t attrlen, bitmap[2] = {0};
2915 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2917 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2919 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2921 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2923 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2925 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2927 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2929 status = verify_attr_len(xdr, savep, attrlen);
2931 dprintk("%s: xdr returned %d!\n", __func__, -status);
2935 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2938 uint32_t attrlen, bitmap[2] = {0};
2941 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2943 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2945 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2948 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2950 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2952 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2954 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2956 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2958 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2961 status = verify_attr_len(xdr, savep, attrlen);
2963 dprintk("%s: xdr returned %d!\n", __func__, -status);
2967 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2970 uint32_t attrlen, bitmap[2] = {0};
2973 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2975 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2977 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2980 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2982 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2985 status = verify_attr_len(xdr, savep, attrlen);
2987 dprintk("%s: xdr returned %d!\n", __func__, -status);
2991 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2997 int status, fmode = 0;
3000 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3002 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3005 fattr->bitmap[0] = bitmap[0];
3006 fattr->bitmap[1] = bitmap[1];
3008 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3012 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
3014 fattr->type = nfs_type2fmt[type].nfs2type;
3015 fmode = nfs_type2fmt[type].mode;
3017 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
3019 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
3021 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
3023 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
3025 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3026 struct nfs4_fs_locations,
3029 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
3031 fattr->mode |= fmode;
3032 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
3034 if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0)
3036 if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0)
3038 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
3040 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
3042 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
3044 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
3046 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
3048 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
3050 if (fattr->fileid == 0 && fileid != 0)
3051 fattr->fileid = fileid;
3052 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
3053 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
3055 dprintk("%s: xdr returned %d\n", __func__, -status);
3060 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3063 uint32_t attrlen, bitmap[2];
3066 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3068 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3070 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3073 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3075 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3077 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3079 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3081 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3082 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3084 fsinfo->wtpref = fsinfo->wtmax;
3086 status = verify_attr_len(xdr, savep, attrlen);
3088 dprintk("%s: xdr returned %d!\n", __func__, -status);
3092 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3098 /* Zero handle first to allow comparisons */
3099 memset(fh, 0, sizeof(*fh));
3101 status = decode_op_hdr(xdr, OP_GETFH);
3107 if (len > NFS4_FHSIZE)
3111 COPYMEM(fh->data, len);
3115 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3119 status = decode_op_hdr(xdr, OP_LINK);
3122 return decode_change_info(xdr, cinfo);
3126 * We create the owner, so we know a proper owner.id length is 4.
3128 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3130 uint64_t offset, length, clientid;
3132 uint32_t namelen, type;
3139 fl->fl_start = (loff_t)offset;
3140 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3141 if (length == ~(uint64_t)0)
3142 fl->fl_end = OFFSET_MAX;
3143 fl->fl_type = F_WRLCK;
3145 fl->fl_type = F_RDLCK;
3151 return -NFS4ERR_DENIED;
3154 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3159 status = decode_op_hdr(xdr, OP_LOCK);
3163 READ_BUF(NFS4_STATEID_SIZE);
3164 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3165 } else if (status == -NFS4ERR_DENIED)
3166 status = decode_lock_denied(xdr, NULL);
3167 if (res->open_seqid != NULL)
3168 nfs_increment_open_seqid(status, res->open_seqid);
3169 nfs_increment_lock_seqid(status, res->lock_seqid);
3174 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3177 status = decode_op_hdr(xdr, OP_LOCKT);
3178 if (status == -NFS4ERR_DENIED)
3179 return decode_lock_denied(xdr, res->denied);
3183 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3188 status = decode_op_hdr(xdr, OP_LOCKU);
3190 nfs_increment_lock_seqid(status, res->seqid);
3192 READ_BUF(NFS4_STATEID_SIZE);
3193 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3198 static int decode_lookup(struct xdr_stream *xdr)
3200 return decode_op_hdr(xdr, OP_LOOKUP);
3203 /* This is too sick! */
3204 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3207 uint32_t limit_type, nblocks, blocksize;
3211 switch (limit_type) {
3218 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3223 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3226 uint32_t delegation_type;
3229 READ32(delegation_type);
3230 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3231 res->delegation_type = 0;
3234 READ_BUF(NFS4_STATEID_SIZE+4);
3235 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3236 READ32(res->do_recall);
3238 switch (delegation_type) {
3239 case NFS4_OPEN_DELEGATE_READ:
3240 res->delegation_type = FMODE_READ;
3242 case NFS4_OPEN_DELEGATE_WRITE:
3243 res->delegation_type = FMODE_WRITE|FMODE_READ;
3244 if (decode_space_limit(xdr, &res->maxsize) < 0)
3247 return decode_ace(xdr, NULL, res->server->nfs_client);
3250 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3253 uint32_t savewords, bmlen, i;
3256 status = decode_op_hdr(xdr, OP_OPEN);
3258 nfs_increment_open_seqid(status, res->seqid);
3261 READ_BUF(NFS4_STATEID_SIZE);
3262 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3264 decode_change_info(xdr, &res->cinfo);
3267 READ32(res->rflags);
3272 READ_BUF(bmlen << 2);
3273 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3274 for (i = 0; i < savewords; ++i)
3275 READ32(res->attrset[i]);
3276 for (; i < NFS4_BITMAP_SIZE; i++)
3277 res->attrset[i] = 0;
3279 return decode_delegation(xdr, res);
3281 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
3285 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3290 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3292 nfs_increment_open_seqid(status, res->seqid);
3295 READ_BUF(NFS4_STATEID_SIZE);
3296 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3300 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3305 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3307 nfs_increment_open_seqid(status, res->seqid);
3310 READ_BUF(NFS4_STATEID_SIZE);
3311 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3315 static int decode_putfh(struct xdr_stream *xdr)
3317 return decode_op_hdr(xdr, OP_PUTFH);
3320 static int decode_putrootfh(struct xdr_stream *xdr)
3322 return decode_op_hdr(xdr, OP_PUTROOTFH);
3325 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3327 struct kvec *iov = req->rq_rcv_buf.head;
3329 uint32_t count, eof, recvd, hdrlen;
3332 status = decode_op_hdr(xdr, OP_READ);
3338 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3339 recvd = req->rq_rcv_buf.len - hdrlen;
3340 if (count > recvd) {
3341 dprintk("NFS: server cheating in read reply: "
3342 "count %u > recvd %u\n", count, recvd);
3346 xdr_read_pages(xdr, count);
3352 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3354 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3355 struct page *page = *rcvbuf->pages;
3356 struct kvec *iov = rcvbuf->head;
3358 u32 recvd, pglen = rcvbuf->page_len;
3359 __be32 *end, *entry, *p, *kaddr;
3360 unsigned int nr = 0;
3363 status = decode_op_hdr(xdr, OP_READDIR);
3367 COPYMEM(readdir->verifier.data, 8);
3368 dprintk("%s: verifier = %08x:%08x\n",
3370 ((u32 *)readdir->verifier.data)[0],
3371 ((u32 *)readdir->verifier.data)[1]);
3374 hdrlen = (char *) p - (char *) iov->iov_base;
3375 recvd = rcvbuf->len - hdrlen;
3378 xdr_read_pages(xdr, pglen);
3380 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3381 kaddr = p = kmap_atomic(page, KM_USER0);
3382 end = p + ((pglen + readdir->pgbase) >> 2);
3385 /* Make sure the packet actually has a value_follows and EOF entry */
3386 if ((entry + 1) > end)
3389 for (; *p++; nr++) {
3390 u32 len, attrlen, xlen;
3393 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3394 p += 2; /* cookie */
3395 len = ntohl(*p++); /* filename length */
3396 if (len > NFS4_MAXNAMLEN) {
3397 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3401 xlen = XDR_QUADLEN(len);
3402 if (end - p < xlen + 1)
3404 dprintk("filename = %*s\n", len, (char *)p);
3406 len = ntohl(*p++); /* bitmap length */
3407 if (end - p < len + 1)
3410 attrlen = XDR_QUADLEN(ntohl(*p++));
3411 if (end - p < attrlen + 2)
3413 p += attrlen; /* attributes */
3417 * Apparently some server sends responses that are a valid size, but
3418 * contain no entries, and have value_follows==0 and EOF==0. For
3419 * those, just set the EOF marker.
3421 if (!nr && entry[1] == 0) {
3422 dprintk("NFS: readdir reply truncated!\n");
3426 kunmap_atomic(kaddr, KM_USER0);
3430 * When we get a short packet there are 2 possibilities. We can
3431 * return an error, or fix up the response to look like a valid
3432 * response and return what we have so far. If there are no
3433 * entries and the packet was short, then return -EIO. If there
3434 * are valid entries in the response, return them and pretend that
3435 * the call was successful, but incomplete. The caller can retry the
3436 * readdir starting at the last cookie.
3438 dprintk("%s: short packet at entry %d\n", __func__, nr);
3439 entry[0] = entry[1] = 0;
3443 kunmap_atomic(kaddr, KM_USER0);
3444 return -errno_NFSERR_IO;
3447 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3449 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3450 struct kvec *iov = rcvbuf->head;
3457 status = decode_op_hdr(xdr, OP_READLINK);
3461 /* Convert length of symlink */
3464 if (len >= rcvbuf->page_len || len <= 0) {
3465 dprintk("nfs: server returned giant symlink!\n");
3466 return -ENAMETOOLONG;
3468 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3469 recvd = req->rq_rcv_buf.len - hdrlen;
3471 dprintk("NFS: server cheating in readlink reply: "
3472 "count %u > recvd %u\n", len, recvd);
3475 xdr_read_pages(xdr, len);
3477 * The XDR encode routine has set things up so that
3478 * the link text will be copied directly into the
3479 * buffer. We just have to do overflow-checking,
3480 * and and null-terminate the text (the VFS expects
3481 * null-termination).
3483 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3484 kaddr[len+rcvbuf->page_base] = '\0';
3485 kunmap_atomic(kaddr, KM_USER0);
3489 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3493 status = decode_op_hdr(xdr, OP_REMOVE);
3496 status = decode_change_info(xdr, cinfo);
3501 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3502 struct nfs4_change_info *new_cinfo)
3506 status = decode_op_hdr(xdr, OP_RENAME);
3509 if ((status = decode_change_info(xdr, old_cinfo)))
3511 status = decode_change_info(xdr, new_cinfo);
3516 static int decode_renew(struct xdr_stream *xdr)
3518 return decode_op_hdr(xdr, OP_RENEW);
3522 decode_restorefh(struct xdr_stream *xdr)
3524 return decode_op_hdr(xdr, OP_RESTOREFH);
3527 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3533 struct kvec *iov = req->rq_rcv_buf.head;
3537 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3539 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3541 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3544 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3546 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3550 /* We ignore &savep and don't do consistency checks on
3551 * the attr length. Let userspace figure it out.... */
3552 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3553 recvd = req->rq_rcv_buf.len - hdrlen;
3554 if (attrlen > recvd) {
3555 dprintk("NFS: server cheating in getattr"
3556 " acl reply: attrlen %u > recvd %u\n",
3560 xdr_read_pages(xdr, attrlen);
3563 status = -EOPNOTSUPP;
3570 decode_savefh(struct xdr_stream *xdr)
3572 return decode_op_hdr(xdr, OP_SAVEFH);
3575 static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3581 status = decode_op_hdr(xdr, OP_SETATTR);
3586 READ_BUF(bmlen << 2);
3590 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
3598 if (opnum != OP_SETCLIENTID) {
3599 dprintk("nfs: decode_setclientid: Server returned operation"
3604 if (nfserr == NFS_OK) {
3605 READ_BUF(8 + NFS4_VERIFIER_SIZE);
3606 READ64(clp->cl_clientid);
3607 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
3608 } else if (nfserr == NFSERR_CLID_INUSE) {
3611 /* skip netid string */
3616 /* skip uaddr string */
3620 return -NFSERR_CLID_INUSE;
3622 return nfs4_stat_to_errno(nfserr);
3627 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3629 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3632 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3637 status = decode_op_hdr(xdr, OP_WRITE);
3643 READ32(res->verf->committed);
3644 COPYMEM(res->verf->verifier, 8);
3648 static int decode_delegreturn(struct xdr_stream *xdr)
3650 return decode_op_hdr(xdr, OP_DELEGRETURN);
3654 * END OF "GENERIC" DECODE ROUTINES.
3658 * Decode OPEN_DOWNGRADE response
3660 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3662 struct xdr_stream xdr;
3663 struct compound_hdr hdr;
3666 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3667 status = decode_compound_hdr(&xdr, &hdr);
3670 status = decode_putfh(&xdr);
3673 status = decode_open_downgrade(&xdr, res);
3676 decode_getfattr(&xdr, res->fattr, res->server);
3682 * Decode ACCESS response
3684 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
3686 struct xdr_stream xdr;
3687 struct compound_hdr hdr;
3690 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3691 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3693 status = decode_putfh(&xdr);
3696 status = decode_access(&xdr, res);
3699 decode_getfattr(&xdr, res->fattr, res->server);
3705 * Decode LOOKUP response
3707 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3709 struct xdr_stream xdr;
3710 struct compound_hdr hdr;
3713 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3714 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3716 if ((status = decode_putfh(&xdr)) != 0)
3718 if ((status = decode_lookup(&xdr)) != 0)
3720 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3722 status = decode_getfattr(&xdr, res->fattr, res->server);
3728 * Decode LOOKUP_ROOT response
3730 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
3732 struct xdr_stream xdr;
3733 struct compound_hdr hdr;
3736 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3737 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3739 if ((status = decode_putrootfh(&xdr)) != 0)
3741 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3742 status = decode_getfattr(&xdr, res->fattr, res->server);
3748 * Decode REMOVE response
3750 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
3752 struct xdr_stream xdr;
3753 struct compound_hdr hdr;
3756 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3757 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3759 if ((status = decode_putfh(&xdr)) != 0)
3761 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3763 decode_getfattr(&xdr, &res->dir_attr, res->server);
3769 * Decode RENAME response
3771 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
3773 struct xdr_stream xdr;
3774 struct compound_hdr hdr;
3777 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3778 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3780 if ((status = decode_putfh(&xdr)) != 0)
3782 if ((status = decode_savefh(&xdr)) != 0)
3784 if ((status = decode_putfh(&xdr)) != 0)
3786 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3788 /* Current FH is target directory */
3789 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3791 if ((status = decode_restorefh(&xdr)) != 0)
3793 decode_getfattr(&xdr, res->old_fattr, res->server);
3799 * Decode LINK response
3801 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
3803 struct xdr_stream xdr;
3804 struct compound_hdr hdr;
3807 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3808 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3810 if ((status = decode_putfh(&xdr)) != 0)
3812 if ((status = decode_savefh(&xdr)) != 0)
3814 if ((status = decode_putfh(&xdr)) != 0)
3816 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3819 * Note order: OP_LINK leaves the directory as the current
3822 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3824 if ((status = decode_restorefh(&xdr)) != 0)
3826 decode_getfattr(&xdr, res->fattr, res->server);
3832 * Decode CREATE response
3834 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3836 struct xdr_stream xdr;
3837 struct compound_hdr hdr;
3840 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3841 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3843 if ((status = decode_putfh(&xdr)) != 0)
3845 if ((status = decode_savefh(&xdr)) != 0)
3847 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3849 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3851 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3853 if ((status = decode_restorefh(&xdr)) != 0)
3855 decode_getfattr(&xdr, res->dir_fattr, res->server);
3861 * Decode SYMLINK response
3863 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
3865 return nfs4_xdr_dec_create(rqstp, p, res);
3869 * Decode GETATTR response
3871 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
3873 struct xdr_stream xdr;
3874 struct compound_hdr hdr;
3877 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3878 status = decode_compound_hdr(&xdr, &hdr);
3881 status = decode_putfh(&xdr);
3884 status = decode_getfattr(&xdr, res->fattr, res->server);
3890 * Encode an SETACL request
3893 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
3895 struct xdr_stream xdr;
3896 struct compound_hdr hdr = {
3901 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3902 encode_compound_hdr(&xdr, &hdr);
3903 encode_putfh(&xdr, args->fh, &hdr);
3904 status = encode_setacl(&xdr, args, &hdr);
3910 * Decode SETACL response
3913 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
3915 struct xdr_stream xdr;
3916 struct compound_hdr hdr;
3919 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3920 status = decode_compound_hdr(&xdr, &hdr);
3923 status = decode_putfh(&xdr);
3926 status = decode_setattr(&xdr, res);
3932 * Decode GETACL response
3935 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
3937 struct xdr_stream xdr;
3938 struct compound_hdr hdr;
3941 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3942 status = decode_compound_hdr(&xdr, &hdr);
3945 status = decode_putfh(&xdr);
3948 status = decode_getacl(&xdr, rqstp, acl_len);
3955 * Decode CLOSE response
3957 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
3959 struct xdr_stream xdr;
3960 struct compound_hdr hdr;
3963 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3964 status = decode_compound_hdr(&xdr, &hdr);
3967 status = decode_putfh(&xdr);
3970 status = decode_close(&xdr, res);
3974 * Note: Server may do delete on close for this file
3975 * in which case the getattr call will fail with
3976 * an ESTALE error. Shouldn't be a problem,
3977 * though, since fattr->valid will remain unset.
3979 decode_getfattr(&xdr, res->fattr, res->server);
3985 * Decode OPEN response
3987 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
3989 struct xdr_stream xdr;
3990 struct compound_hdr hdr;
3993 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3994 status = decode_compound_hdr(&xdr, &hdr);
3997 status = decode_putfh(&xdr);
4000 status = decode_savefh(&xdr);
4003 status = decode_open(&xdr, res);
4006 if (decode_getfh(&xdr, &res->fh) != 0)
4008 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4010 if (decode_restorefh(&xdr) != 0)
4012 decode_getfattr(&xdr, res->dir_attr, res->server);
4018 * Decode OPEN_CONFIRM response
4020 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4022 struct xdr_stream xdr;
4023 struct compound_hdr hdr;
4026 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4027 status = decode_compound_hdr(&xdr, &hdr);
4030 status = decode_putfh(&xdr);
4033 status = decode_open_confirm(&xdr, res);
4039 * Decode OPEN response
4041 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4043 struct xdr_stream xdr;
4044 struct compound_hdr hdr;
4047 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4048 status = decode_compound_hdr(&xdr, &hdr);
4051 status = decode_putfh(&xdr);
4054 status = decode_open(&xdr, res);
4057 decode_getfattr(&xdr, res->f_attr, res->server);
4063 * Decode SETATTR response
4065 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4067 struct xdr_stream xdr;
4068 struct compound_hdr hdr;
4071 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4072 status = decode_compound_hdr(&xdr, &hdr);
4075 status = decode_putfh(&xdr);
4078 status = decode_setattr(&xdr, res);
4081 status = decode_getfattr(&xdr, res->fattr, res->server);
4082 if (status == NFS4ERR_DELAY)
4089 * Decode LOCK response
4091 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *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_lock(&xdr, res);
4110 * Decode LOCKT response
4112 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4114 struct xdr_stream xdr;
4115 struct compound_hdr hdr;
4118 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4119 status = decode_compound_hdr(&xdr, &hdr);
4122 status = decode_putfh(&xdr);
4125 status = decode_lockt(&xdr, res);
4131 * Decode LOCKU response
4133 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4135 struct xdr_stream xdr;
4136 struct compound_hdr hdr;
4139 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4140 status = decode_compound_hdr(&xdr, &hdr);
4143 status = decode_putfh(&xdr);
4146 status = decode_locku(&xdr, res);
4152 * Decode READLINK response
4154 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
4156 struct xdr_stream xdr;
4157 struct compound_hdr hdr;
4160 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4161 status = decode_compound_hdr(&xdr, &hdr);
4164 status = decode_putfh(&xdr);
4167 status = decode_readlink(&xdr, rqstp);
4173 * Decode READDIR response
4175 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4177 struct xdr_stream xdr;
4178 struct compound_hdr hdr;
4181 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4182 status = decode_compound_hdr(&xdr, &hdr);
4185 status = decode_putfh(&xdr);
4188 status = decode_readdir(&xdr, rqstp, res);
4194 * Decode Read response
4196 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4198 struct xdr_stream xdr;
4199 struct compound_hdr hdr;
4202 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4203 status = decode_compound_hdr(&xdr, &hdr);
4206 status = decode_putfh(&xdr);
4209 status = decode_read(&xdr, rqstp, res);
4211 status = res->count;
4217 * Decode WRITE response
4219 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4221 struct xdr_stream xdr;
4222 struct compound_hdr hdr;
4225 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4226 status = decode_compound_hdr(&xdr, &hdr);
4229 status = decode_putfh(&xdr);
4232 status = decode_write(&xdr, res);
4235 decode_getfattr(&xdr, res->fattr, res->server);
4237 status = res->count;
4243 * Decode COMMIT response
4245 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4247 struct xdr_stream xdr;
4248 struct compound_hdr hdr;
4251 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4252 status = decode_compound_hdr(&xdr, &hdr);
4255 status = decode_putfh(&xdr);
4258 status = decode_commit(&xdr, res);
4261 decode_getfattr(&xdr, res->fattr, res->server);
4269 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4271 struct xdr_stream xdr;
4272 struct compound_hdr hdr;
4275 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4276 status = decode_compound_hdr(&xdr, &hdr);
4278 status = decode_putfh(&xdr);
4280 status = decode_fsinfo(&xdr, fsinfo);
4287 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
4289 struct xdr_stream xdr;
4290 struct compound_hdr hdr;
4293 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4294 status = decode_compound_hdr(&xdr, &hdr);
4296 status = decode_putfh(&xdr);
4298 status = decode_pathconf(&xdr, pathconf);
4305 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
4307 struct xdr_stream xdr;
4308 struct compound_hdr hdr;
4311 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4312 status = decode_compound_hdr(&xdr, &hdr);
4314 status = decode_putfh(&xdr);
4316 status = decode_statfs(&xdr, fsstat);
4321 * GETATTR_BITMAP request
4323 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
4325 struct xdr_stream xdr;
4326 struct compound_hdr hdr;
4329 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4330 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4332 if ((status = decode_putfh(&xdr)) != 0)
4334 status = decode_server_caps(&xdr, res);
4340 * Decode RENEW response
4342 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
4344 struct xdr_stream xdr;
4345 struct compound_hdr hdr;
4348 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4349 status = decode_compound_hdr(&xdr, &hdr);
4351 status = decode_renew(&xdr);
4356 * a SETCLIENTID request
4358 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4359 struct nfs_client *clp)
4361 struct xdr_stream xdr;
4362 struct compound_hdr hdr;
4365 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4366 status = decode_compound_hdr(&xdr, &hdr);
4368 status = decode_setclientid(&xdr, clp);
4373 * a SETCLIENTID_CONFIRM request
4375 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4377 struct xdr_stream xdr;
4378 struct compound_hdr hdr;
4381 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4382 status = decode_compound_hdr(&xdr, &hdr);
4384 status = decode_setclientid_confirm(&xdr);
4386 status = decode_putrootfh(&xdr);
4388 status = decode_fsinfo(&xdr, fsinfo);
4393 * DELEGRETURN request
4395 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
4397 struct xdr_stream xdr;
4398 struct compound_hdr hdr;
4401 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4402 status = decode_compound_hdr(&xdr, &hdr);
4405 status = decode_putfh(&xdr);
4408 status = decode_delegreturn(&xdr);
4409 decode_getfattr(&xdr, res->fattr, res->server);
4415 * FS_LOCATIONS request
4417 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
4419 struct xdr_stream xdr;
4420 struct compound_hdr hdr;
4423 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4424 status = decode_compound_hdr(&xdr, &hdr);
4427 if ((status = decode_putfh(&xdr)) != 0)
4429 if ((status = decode_lookup(&xdr)) != 0)
4431 xdr_enter_page(&xdr, PAGE_SIZE);
4432 status = decode_getfattr(&xdr, &res->fattr, res->server);
4437 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
4439 uint32_t bitmap[2] = {0};
4444 return ERR_PTR(-EAGAIN);
4446 return ERR_PTR(-EBADCOOKIE);
4449 entry->prev_cookie = entry->cookie;
4450 p = xdr_decode_hyper(p, &entry->cookie);
4451 entry->len = ntohl(*p++);
4452 entry->name = (const char *) p;
4453 p += XDR_QUADLEN(entry->len);
4456 * In case the server doesn't return an inode number,
4457 * we fake one here. (We don't use inode number 0,
4458 * since glibc seems to choke on it...)
4462 len = ntohl(*p++); /* bitmap length */
4464 bitmap[0] = ntohl(*p++);
4466 bitmap[1] = ntohl(*p++);
4470 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4472 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4473 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4474 /* Ignore the return value of rdattr_error for now */
4478 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4479 xdr_decode_hyper(p, &entry->ino);
4480 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4481 xdr_decode_hyper(p, &entry->ino);
4485 entry->eof = !p[0] && p[1];
4490 * We need to translate between nfs status return values and
4491 * the local errno values which may not be the same.
4498 { NFS4ERR_PERM, -EPERM },
4499 { NFS4ERR_NOENT, -ENOENT },
4500 { NFS4ERR_IO, -errno_NFSERR_IO},
4501 { NFS4ERR_NXIO, -ENXIO },
4502 { NFS4ERR_ACCESS, -EACCES },
4503 { NFS4ERR_EXIST, -EEXIST },
4504 { NFS4ERR_XDEV, -EXDEV },
4505 { NFS4ERR_NOTDIR, -ENOTDIR },
4506 { NFS4ERR_ISDIR, -EISDIR },
4507 { NFS4ERR_INVAL, -EINVAL },
4508 { NFS4ERR_FBIG, -EFBIG },
4509 { NFS4ERR_NOSPC, -ENOSPC },
4510 { NFS4ERR_ROFS, -EROFS },
4511 { NFS4ERR_MLINK, -EMLINK },
4512 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
4513 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
4514 { NFS4ERR_DQUOT, -EDQUOT },
4515 { NFS4ERR_STALE, -ESTALE },
4516 { NFS4ERR_BADHANDLE, -EBADHANDLE },
4517 { NFS4ERR_BADOWNER, -EINVAL },
4518 { NFS4ERR_BADNAME, -EINVAL },
4519 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
4520 { NFS4ERR_NOTSUPP, -ENOTSUPP },
4521 { NFS4ERR_TOOSMALL, -ETOOSMALL },
4522 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
4523 { NFS4ERR_BADTYPE, -EBADTYPE },
4524 { NFS4ERR_LOCKED, -EAGAIN },
4525 { NFS4ERR_RESOURCE, -EREMOTEIO },
4526 { NFS4ERR_SYMLINK, -ELOOP },
4527 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
4528 { NFS4ERR_DEADLOCK, -EDEADLK },
4529 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
4530 * to be handled by a
4537 * Convert an NFS error code to a local one.
4538 * This one is used jointly by NFSv2 and NFSv3.
4541 nfs4_stat_to_errno(int stat)
4544 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4545 if (nfs_errtbl[i].stat == stat)
4546 return nfs_errtbl[i].errno;
4548 if (stat <= 10000 || stat > 10100) {
4549 /* The server is looney tunes. */
4550 return -ESERVERFAULT;
4552 /* If we cannot translate the error, the recovery routines should
4554 * Note: remaining NFSv4 error codes have values > 10000, so should
4555 * not conflict with native Linux error codes.
4560 #define PROC(proc, argtype, restype) \
4561 [NFSPROC4_CLNT_##proc] = { \
4562 .p_proc = NFSPROC4_COMPOUND, \
4563 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4564 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
4565 .p_arglen = NFS4_##argtype##_sz, \
4566 .p_replen = NFS4_##restype##_sz, \
4567 .p_statidx = NFSPROC4_CLNT_##proc, \
4571 struct rpc_procinfo nfs4_procedures[] = {
4572 PROC(READ, enc_read, dec_read),
4573 PROC(WRITE, enc_write, dec_write),
4574 PROC(COMMIT, enc_commit, dec_commit),
4575 PROC(OPEN, enc_open, dec_open),
4576 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4577 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4578 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4579 PROC(CLOSE, enc_close, dec_close),
4580 PROC(SETATTR, enc_setattr, dec_setattr),
4581 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4582 PROC(RENEW, enc_renew, dec_renew),
4583 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4584 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4585 PROC(LOCK, enc_lock, dec_lock),
4586 PROC(LOCKT, enc_lockt, dec_lockt),
4587 PROC(LOCKU, enc_locku, dec_locku),
4588 PROC(ACCESS, enc_access, dec_access),
4589 PROC(GETATTR, enc_getattr, dec_getattr),
4590 PROC(LOOKUP, enc_lookup, dec_lookup),
4591 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4592 PROC(REMOVE, enc_remove, dec_remove),
4593 PROC(RENAME, enc_rename, dec_rename),
4594 PROC(LINK, enc_link, dec_link),
4595 PROC(SYMLINK, enc_symlink, dec_symlink),
4596 PROC(CREATE, enc_create, dec_create),
4597 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4598 PROC(STATFS, enc_statfs, dec_statfs),
4599 PROC(READLINK, enc_readlink, dec_readlink),
4600 PROC(READDIR, enc_readdir, dec_readdir),
4601 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4602 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
4603 PROC(GETACL, enc_getacl, dec_getacl),
4604 PROC(SETACL, enc_setacl, dec_setacl),
4605 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
4608 struct rpc_version nfs_version4 = {
4610 .nrprocs = ARRAY_SIZE(nfs4_procedures),
4611 .procs = nfs4_procedures