4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/param.h>
39 #include <linux/time.h>
41 #include <linux/slab.h>
42 #include <linux/utsname.h>
43 #include <linux/errno.h>
44 #include <linux/string.h>
46 #include <linux/pagemap.h>
47 #include <linux/proc_fs.h>
48 #include <linux/kdev_t.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
56 #define NFSDBG_FACILITY NFSDBG_XDR
58 /* Mapping from NFS error code to "errno" error code. */
59 #define errno_NFSERR_IO EIO
61 static int nfs4_stat_to_errno(int);
63 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65 #define NFS4_MAXTAGLEN 20
67 #define NFS4_MAXTAGLEN 0
70 /* lock,open owner id:
71 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
73 #define open_owner_id_maxsz (1 + 4)
74 #define lock_owner_id_maxsz (1 + 4)
75 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
76 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78 #define op_encode_hdr_maxsz (1)
79 #define op_decode_hdr_maxsz (2)
80 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
84 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
86 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
87 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
90 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
92 #define nfs4_fattr_bitmap_maxsz 3
93 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
94 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
96 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98 /* This is based on getfattr, which uses the most attributes: */
99 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
101 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
104 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
110 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
111 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
113 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
114 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116 #define decode_renew_maxsz (op_decode_hdr_maxsz)
117 #define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
125 #define decode_setclientid_maxsz \
126 (op_decode_hdr_maxsz + \
128 1024) /* large value for CLID_INUSE */
129 #define encode_setclientid_confirm_maxsz \
130 (op_encode_hdr_maxsz + \
131 3 + (NFS4_VERIFIER_SIZE >> 2))
132 #define decode_setclientid_confirm_maxsz \
133 (op_decode_hdr_maxsz)
134 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
136 #define encode_share_access_maxsz \
138 #define encode_createmode_maxsz (1 + encode_attrs_maxsz)
139 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141 #define encode_open_maxsz (op_encode_hdr_maxsz + \
142 2 + encode_share_access_maxsz + 2 + \
143 open_owner_id_maxsz + \
144 encode_opentype_maxsz + \
145 encode_claim_null_maxsz)
146 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
147 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
149 #define decode_change_info_maxsz (5)
150 #define decode_open_maxsz (op_decode_hdr_maxsz + \
151 decode_stateid_maxsz + \
152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
155 #define encode_open_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 encode_stateid_maxsz + 1)
158 #define decode_open_confirm_maxsz \
159 (op_decode_hdr_maxsz + \
160 decode_stateid_maxsz)
161 #define encode_open_downgrade_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1 + \
164 encode_share_access_maxsz)
165 #define decode_open_downgrade_maxsz \
166 (op_decode_hdr_maxsz + \
167 decode_stateid_maxsz)
168 #define encode_close_maxsz (op_encode_hdr_maxsz + \
169 1 + encode_stateid_maxsz)
170 #define decode_close_maxsz (op_decode_hdr_maxsz + \
171 decode_stateid_maxsz)
172 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + \
175 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
176 nfs4_fattr_bitmap_maxsz)
177 #define encode_read_maxsz (op_encode_hdr_maxsz + \
178 encode_stateid_maxsz + 3)
179 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
180 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
181 2 + encode_verifier_maxsz + 5)
182 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
183 decode_verifier_maxsz)
184 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
185 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
186 #define encode_write_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 4)
188 #define decode_write_maxsz (op_decode_hdr_maxsz + \
189 2 + decode_verifier_maxsz)
190 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
191 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
192 decode_verifier_maxsz)
193 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
195 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
196 decode_change_info_maxsz)
197 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
199 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
200 decode_change_info_maxsz + \
201 decode_change_info_maxsz)
202 #define encode_link_maxsz (op_encode_hdr_maxsz + \
204 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
205 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
207 1 + encode_stateid_maxsz + 8)
208 #define decode_lock_denied_maxsz \
209 (8 + decode_lockowner_maxsz)
210 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
211 decode_lock_denied_maxsz)
212 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
213 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
215 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
216 encode_stateid_maxsz + \
218 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
219 decode_stateid_maxsz)
220 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
221 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
222 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
223 1 + nfs4_name_maxsz + \
226 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
227 #define encode_create_maxsz (op_encode_hdr_maxsz + \
228 1 + 2 + nfs4_name_maxsz + \
230 #define decode_create_maxsz (op_decode_hdr_maxsz + \
231 decode_change_info_maxsz + \
232 nfs4_fattr_bitmap_maxsz)
233 #define encode_statfs_maxsz (encode_getattr_maxsz)
234 #define decode_statfs_maxsz (decode_getattr_maxsz)
235 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
236 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
237 #define encode_getacl_maxsz (encode_getattr_maxsz)
238 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
239 nfs4_fattr_bitmap_maxsz + 1)
240 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
241 encode_stateid_maxsz + 3)
242 #define decode_setacl_maxsz (decode_setattr_maxsz)
243 #define encode_fs_locations_maxsz \
244 (encode_getattr_maxsz)
245 #define decode_fs_locations_maxsz \
248 #if defined(CONFIG_NFS_V4_1)
249 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
250 encode_verifier_maxsz + \
251 1 /* co_ownerid.len */ + \
252 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
255 0 /* SP4_NONE (for now) */ + \
256 1 /* zero implemetation id array */)
257 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
258 2 /* eir_clientid */ + \
259 1 /* eir_sequenceid */ + \
260 1 /* eir_flags */ + \
262 0 /* SP4_NONE (for now) */ + \
263 2 /* eir_server_owner.so_minor_id */ + \
264 /* eir_server_owner.so_major_id<> */ \
265 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
266 /* eir_server_scope<> */ \
267 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
268 1 /* eir_server_impl_id array length */ + \
269 0 /* ignored eir_server_impl_id contents */)
270 #define encode_sequence_maxsz 0 /* stub */
271 #define decode_sequence_maxsz 0 /* stub */
272 #else /* CONFIG_NFS_V4_1 */
273 #define encode_sequence_maxsz 0
274 #define decode_sequence_maxsz 0
275 #endif /* CONFIG_NFS_V4_1 */
277 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
278 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
279 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
280 encode_sequence_maxsz + \
281 encode_putfh_maxsz + \
283 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
284 decode_sequence_maxsz + \
285 decode_putfh_maxsz + \
287 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
288 encode_sequence_maxsz + \
289 encode_putfh_maxsz + \
290 encode_readlink_maxsz)
291 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
292 decode_sequence_maxsz + \
293 decode_putfh_maxsz + \
294 decode_readlink_maxsz)
295 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
296 encode_sequence_maxsz + \
297 encode_putfh_maxsz + \
298 encode_readdir_maxsz)
299 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
300 decode_sequence_maxsz + \
301 decode_putfh_maxsz + \
302 decode_readdir_maxsz)
303 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
304 encode_sequence_maxsz + \
305 encode_putfh_maxsz + \
306 encode_write_maxsz + \
307 encode_getattr_maxsz)
308 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
309 decode_sequence_maxsz + \
310 decode_putfh_maxsz + \
311 decode_write_maxsz + \
312 decode_getattr_maxsz)
313 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
314 encode_sequence_maxsz + \
315 encode_putfh_maxsz + \
316 encode_commit_maxsz + \
317 encode_getattr_maxsz)
318 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
319 decode_sequence_maxsz + \
320 decode_putfh_maxsz + \
321 decode_commit_maxsz + \
322 decode_getattr_maxsz)
323 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
324 encode_sequence_maxsz + \
325 encode_putfh_maxsz + \
326 encode_savefh_maxsz + \
327 encode_open_maxsz + \
328 encode_getfh_maxsz + \
329 encode_getattr_maxsz + \
330 encode_restorefh_maxsz + \
331 encode_getattr_maxsz)
332 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
333 decode_sequence_maxsz + \
334 decode_putfh_maxsz + \
335 decode_savefh_maxsz + \
336 decode_open_maxsz + \
337 decode_getfh_maxsz + \
338 decode_getattr_maxsz + \
339 decode_restorefh_maxsz + \
340 decode_getattr_maxsz)
341 #define NFS4_enc_open_confirm_sz \
342 (compound_encode_hdr_maxsz + \
343 encode_putfh_maxsz + \
344 encode_open_confirm_maxsz)
345 #define NFS4_dec_open_confirm_sz \
346 (compound_decode_hdr_maxsz + \
347 decode_putfh_maxsz + \
348 decode_open_confirm_maxsz)
349 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
350 encode_sequence_maxsz + \
351 encode_putfh_maxsz + \
352 encode_open_maxsz + \
353 encode_getattr_maxsz)
354 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
355 decode_sequence_maxsz + \
356 decode_putfh_maxsz + \
357 decode_open_maxsz + \
358 decode_getattr_maxsz)
359 #define NFS4_enc_open_downgrade_sz \
360 (compound_encode_hdr_maxsz + \
361 encode_sequence_maxsz + \
362 encode_putfh_maxsz + \
363 encode_open_downgrade_maxsz + \
364 encode_getattr_maxsz)
365 #define NFS4_dec_open_downgrade_sz \
366 (compound_decode_hdr_maxsz + \
367 decode_sequence_maxsz + \
368 decode_putfh_maxsz + \
369 decode_open_downgrade_maxsz + \
370 decode_getattr_maxsz)
371 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
372 encode_sequence_maxsz + \
373 encode_putfh_maxsz + \
374 encode_close_maxsz + \
375 encode_getattr_maxsz)
376 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
377 decode_sequence_maxsz + \
378 decode_putfh_maxsz + \
379 decode_close_maxsz + \
380 decode_getattr_maxsz)
381 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
382 encode_sequence_maxsz + \
383 encode_putfh_maxsz + \
384 encode_setattr_maxsz + \
385 encode_getattr_maxsz)
386 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
387 decode_sequence_maxsz + \
388 decode_putfh_maxsz + \
389 decode_setattr_maxsz + \
390 decode_getattr_maxsz)
391 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
392 encode_sequence_maxsz + \
393 encode_putfh_maxsz + \
395 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
396 decode_sequence_maxsz + \
397 decode_putfh_maxsz + \
399 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
401 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
403 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
404 encode_setclientid_maxsz)
405 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
406 decode_setclientid_maxsz)
407 #define NFS4_enc_setclientid_confirm_sz \
408 (compound_encode_hdr_maxsz + \
409 encode_setclientid_confirm_maxsz + \
410 encode_putrootfh_maxsz + \
412 #define NFS4_dec_setclientid_confirm_sz \
413 (compound_decode_hdr_maxsz + \
414 decode_setclientid_confirm_maxsz + \
415 decode_putrootfh_maxsz + \
417 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
418 encode_sequence_maxsz + \
419 encode_putfh_maxsz + \
421 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
422 decode_sequence_maxsz + \
423 decode_putfh_maxsz + \
425 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
426 encode_sequence_maxsz + \
427 encode_putfh_maxsz + \
429 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
430 decode_sequence_maxsz + \
431 decode_putfh_maxsz + \
433 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
434 encode_sequence_maxsz + \
435 encode_putfh_maxsz + \
437 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
438 decode_sequence_maxsz + \
439 decode_putfh_maxsz + \
441 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
442 encode_sequence_maxsz + \
443 encode_putfh_maxsz + \
444 encode_access_maxsz + \
445 encode_getattr_maxsz)
446 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
447 decode_sequence_maxsz + \
448 decode_putfh_maxsz + \
449 decode_access_maxsz + \
450 decode_getattr_maxsz)
451 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
452 encode_sequence_maxsz + \
453 encode_putfh_maxsz + \
454 encode_getattr_maxsz)
455 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
456 decode_sequence_maxsz + \
457 decode_putfh_maxsz + \
458 decode_getattr_maxsz)
459 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
460 encode_sequence_maxsz + \
461 encode_putfh_maxsz + \
462 encode_lookup_maxsz + \
463 encode_getattr_maxsz + \
465 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
466 decode_sequence_maxsz + \
467 decode_putfh_maxsz + \
468 decode_lookup_maxsz + \
469 decode_getattr_maxsz + \
471 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
472 encode_sequence_maxsz + \
473 encode_putrootfh_maxsz + \
474 encode_getattr_maxsz + \
476 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
477 decode_sequence_maxsz + \
478 decode_putrootfh_maxsz + \
479 decode_getattr_maxsz + \
481 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
482 encode_sequence_maxsz + \
483 encode_putfh_maxsz + \
484 encode_remove_maxsz + \
485 encode_getattr_maxsz)
486 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
487 decode_sequence_maxsz + \
488 decode_putfh_maxsz + \
489 decode_remove_maxsz + \
490 decode_getattr_maxsz)
491 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
492 encode_sequence_maxsz + \
493 encode_putfh_maxsz + \
494 encode_savefh_maxsz + \
495 encode_putfh_maxsz + \
496 encode_rename_maxsz + \
497 encode_getattr_maxsz + \
498 encode_restorefh_maxsz + \
499 encode_getattr_maxsz)
500 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
501 decode_sequence_maxsz + \
502 decode_putfh_maxsz + \
503 decode_savefh_maxsz + \
504 decode_putfh_maxsz + \
505 decode_rename_maxsz + \
506 decode_getattr_maxsz + \
507 decode_restorefh_maxsz + \
508 decode_getattr_maxsz)
509 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
510 encode_sequence_maxsz + \
511 encode_putfh_maxsz + \
512 encode_savefh_maxsz + \
513 encode_putfh_maxsz + \
514 encode_link_maxsz + \
515 decode_getattr_maxsz + \
516 encode_restorefh_maxsz + \
517 decode_getattr_maxsz)
518 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
519 decode_sequence_maxsz + \
520 decode_putfh_maxsz + \
521 decode_savefh_maxsz + \
522 decode_putfh_maxsz + \
523 decode_link_maxsz + \
524 decode_getattr_maxsz + \
525 decode_restorefh_maxsz + \
526 decode_getattr_maxsz)
527 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
528 encode_sequence_maxsz + \
529 encode_putfh_maxsz + \
530 encode_symlink_maxsz + \
531 encode_getattr_maxsz + \
533 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
534 decode_sequence_maxsz + \
535 decode_putfh_maxsz + \
536 decode_symlink_maxsz + \
537 decode_getattr_maxsz + \
539 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
540 encode_sequence_maxsz + \
541 encode_putfh_maxsz + \
542 encode_savefh_maxsz + \
543 encode_create_maxsz + \
544 encode_getfh_maxsz + \
545 encode_getattr_maxsz + \
546 encode_restorefh_maxsz + \
547 encode_getattr_maxsz)
548 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
549 decode_sequence_maxsz + \
550 decode_putfh_maxsz + \
551 decode_savefh_maxsz + \
552 decode_create_maxsz + \
553 decode_getfh_maxsz + \
554 decode_getattr_maxsz + \
555 decode_restorefh_maxsz + \
556 decode_getattr_maxsz)
557 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
558 encode_sequence_maxsz + \
559 encode_putfh_maxsz + \
560 encode_getattr_maxsz)
561 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
562 decode_sequence_maxsz + \
563 decode_putfh_maxsz + \
564 decode_getattr_maxsz)
565 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
566 encode_sequence_maxsz + \
567 encode_putfh_maxsz + \
569 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
570 decode_sequence_maxsz + \
571 decode_putfh_maxsz + \
573 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
574 encode_sequence_maxsz + \
575 encode_putfh_maxsz + \
576 encode_getattr_maxsz)
577 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
578 decode_sequence_maxsz + \
579 decode_putfh_maxsz + \
580 decode_getattr_maxsz)
581 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
582 encode_sequence_maxsz + \
583 encode_putfh_maxsz + \
584 encode_delegreturn_maxsz + \
585 encode_getattr_maxsz)
586 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
587 decode_sequence_maxsz + \
588 decode_delegreturn_maxsz + \
589 decode_getattr_maxsz)
590 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
591 encode_sequence_maxsz + \
592 encode_putfh_maxsz + \
594 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
595 decode_sequence_maxsz + \
596 decode_putfh_maxsz + \
598 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
599 encode_sequence_maxsz + \
600 encode_putfh_maxsz + \
602 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
603 decode_sequence_maxsz + \
604 decode_putfh_maxsz + \
606 #define NFS4_enc_fs_locations_sz \
607 (compound_encode_hdr_maxsz + \
608 encode_sequence_maxsz + \
609 encode_putfh_maxsz + \
610 encode_lookup_maxsz + \
611 encode_fs_locations_maxsz)
612 #define NFS4_dec_fs_locations_sz \
613 (compound_decode_hdr_maxsz + \
614 decode_sequence_maxsz + \
615 decode_putfh_maxsz + \
616 decode_lookup_maxsz + \
617 decode_fs_locations_maxsz)
618 #if defined(CONFIG_NFS_V4_1)
619 #define NFS4_enc_exchange_id_sz \
620 (compound_encode_hdr_maxsz + \
621 encode_exchange_id_maxsz)
622 #define NFS4_dec_exchange_id_sz \
623 (compound_decode_hdr_maxsz + \
624 decode_exchange_id_maxsz)
625 #endif /* CONFIG_NFS_V4_1 */
627 static const umode_t nfs_type2fmt[] = {
634 [NF4SOCK] = S_IFSOCK,
640 struct compound_hdr {
646 uint32_t replen; /* expected reply words */
651 * START OF "GENERIC" ENCODE ROUTINES.
652 * These may look a little ugly since they are imported from a "generic"
653 * set of XDR encode/decode routines which are intended to be shared by
654 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
656 * If the pain of reading these is too great, it should be a straightforward
657 * task to translate them into Linux-specific versions which are more
658 * consistent with the style used in NFSv2/v3...
660 #define WRITE32(n) *p++ = htonl(n)
661 #define WRITE64(n) do { \
662 *p++ = htonl((uint32_t)((n) >> 32)); \
663 *p++ = htonl((uint32_t)(n)); \
665 #define WRITEMEM(ptr,nbytes) do { \
666 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
669 #define RESERVE_SPACE(nbytes) do { \
670 p = xdr_reserve_space(xdr, nbytes); \
674 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
678 p = xdr_reserve_space(xdr, 4 + len);
680 xdr_encode_opaque(p, str, len);
683 static void encode_compound_hdr(struct xdr_stream *xdr,
684 struct rpc_rqst *req,
685 struct compound_hdr *hdr)
688 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
690 /* initialize running count of expected bytes in reply.
691 * NOTE: the replied tag SHOULD be the same is the one sent,
692 * but this is not required as a MUST for the server to do so. */
693 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
695 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
696 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
697 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
698 WRITE32(hdr->taglen);
699 WRITEMEM(hdr->tag, hdr->taglen);
700 WRITE32(hdr->minorversion);
705 static void encode_nops(struct compound_hdr *hdr)
707 *hdr->nops_p = htonl(hdr->nops);
710 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
714 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
716 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
719 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
721 char owner_name[IDMAP_NAMESZ];
722 char owner_group[IDMAP_NAMESZ];
723 int owner_namelen = 0;
724 int owner_grouplen = 0;
732 * We reserve enough space to write the entire attribute buffer at once.
733 * In the worst-case, this would be
734 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
735 * = 36 bytes, plus any contribution from variable-length fields
736 * such as owner/group.
741 if (iap->ia_valid & ATTR_SIZE)
743 if (iap->ia_valid & ATTR_MODE)
745 if (iap->ia_valid & ATTR_UID) {
746 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
747 if (owner_namelen < 0) {
748 dprintk("nfs: couldn't resolve uid %d to string\n",
751 strcpy(owner_name, "nobody");
752 owner_namelen = sizeof("nobody") - 1;
755 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
757 if (iap->ia_valid & ATTR_GID) {
758 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
759 if (owner_grouplen < 0) {
760 dprintk("nfs: couldn't resolve gid %d to string\n",
762 strcpy(owner_group, "nobody");
763 owner_grouplen = sizeof("nobody") - 1;
766 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
768 if (iap->ia_valid & ATTR_ATIME_SET)
770 else if (iap->ia_valid & ATTR_ATIME)
772 if (iap->ia_valid & ATTR_MTIME_SET)
774 else if (iap->ia_valid & ATTR_MTIME)
779 * We write the bitmap length now, but leave the bitmap and the attribute
780 * buffer length to be backfilled at the end of this routine.
786 if (iap->ia_valid & ATTR_SIZE) {
787 bmval0 |= FATTR4_WORD0_SIZE;
788 WRITE64(iap->ia_size);
790 if (iap->ia_valid & ATTR_MODE) {
791 bmval1 |= FATTR4_WORD1_MODE;
792 WRITE32(iap->ia_mode & S_IALLUGO);
794 if (iap->ia_valid & ATTR_UID) {
795 bmval1 |= FATTR4_WORD1_OWNER;
796 WRITE32(owner_namelen);
797 WRITEMEM(owner_name, owner_namelen);
799 if (iap->ia_valid & ATTR_GID) {
800 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
801 WRITE32(owner_grouplen);
802 WRITEMEM(owner_group, owner_grouplen);
804 if (iap->ia_valid & ATTR_ATIME_SET) {
805 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
806 WRITE32(NFS4_SET_TO_CLIENT_TIME);
808 WRITE32(iap->ia_mtime.tv_sec);
809 WRITE32(iap->ia_mtime.tv_nsec);
811 else if (iap->ia_valid & ATTR_ATIME) {
812 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
813 WRITE32(NFS4_SET_TO_SERVER_TIME);
815 if (iap->ia_valid & ATTR_MTIME_SET) {
816 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
817 WRITE32(NFS4_SET_TO_CLIENT_TIME);
819 WRITE32(iap->ia_mtime.tv_sec);
820 WRITE32(iap->ia_mtime.tv_nsec);
822 else if (iap->ia_valid & ATTR_MTIME) {
823 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
824 WRITE32(NFS4_SET_TO_SERVER_TIME);
828 * Now we backfill the bitmap and the attribute buffer length.
830 if (len != ((char *)p - (char *)q) + 4) {
831 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
832 len, ((char *)p - (char *)q) + 4);
835 len = (char *)p - (char *)q - 12;
836 *q++ = htonl(bmval0);
837 *q++ = htonl(bmval1);
843 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
851 hdr->replen += decode_access_maxsz;
854 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
858 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
860 WRITE32(arg->seqid->sequence->counter);
861 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
863 hdr->replen += decode_close_maxsz;
866 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
872 WRITE64(args->offset);
873 WRITE32(args->count);
875 hdr->replen += decode_commit_maxsz;
878 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
884 WRITE32(create->ftype);
886 switch (create->ftype) {
889 WRITE32(create->u.symlink.len);
890 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
893 case NF4BLK: case NF4CHR:
895 WRITE32(create->u.device.specdata1);
896 WRITE32(create->u.device.specdata2);
903 RESERVE_SPACE(4 + create->name->len);
904 WRITE32(create->name->len);
905 WRITEMEM(create->name->name, create->name->len);
907 hdr->replen += decode_create_maxsz;
909 encode_attrs(xdr, create->attrs, create->server);
912 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
921 hdr->replen += decode_getattr_maxsz;
924 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
934 hdr->replen += decode_getattr_maxsz;
937 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
939 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
940 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
943 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
945 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
946 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
949 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
951 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
952 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
955 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
962 hdr->replen += decode_getfh_maxsz;
965 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
969 RESERVE_SPACE(8 + name->len);
972 WRITEMEM(name->name, name->len);
974 hdr->replen += decode_link_maxsz;
977 static inline int nfs4_lock_type(struct file_lock *fl, int block)
979 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
980 return block ? NFS4_READW_LT : NFS4_READ_LT;
981 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
984 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
986 if (fl->fl_end == OFFSET_MAX)
988 return fl->fl_end - fl->fl_start + 1;
992 * opcode,type,reclaim,offset,length,new_lock_owner = 32
993 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
995 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1001 WRITE32(nfs4_lock_type(args->fl, args->block));
1002 WRITE32(args->reclaim);
1003 WRITE64(args->fl->fl_start);
1004 WRITE64(nfs4_lock_length(args->fl));
1005 WRITE32(args->new_lock_owner);
1006 if (args->new_lock_owner){
1007 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
1008 WRITE32(args->open_seqid->sequence->counter);
1009 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
1010 WRITE32(args->lock_seqid->sequence->counter);
1011 WRITE64(args->lock_owner.clientid);
1013 WRITEMEM("lock id:", 8);
1014 WRITE64(args->lock_owner.id);
1017 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
1018 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
1019 WRITE32(args->lock_seqid->sequence->counter);
1022 hdr->replen += decode_lock_maxsz;
1025 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1031 WRITE32(nfs4_lock_type(args->fl, 0));
1032 WRITE64(args->fl->fl_start);
1033 WRITE64(nfs4_lock_length(args->fl));
1034 WRITE64(args->lock_owner.clientid);
1036 WRITEMEM("lock id:", 8);
1037 WRITE64(args->lock_owner.id);
1039 hdr->replen += decode_lockt_maxsz;
1042 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1046 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
1048 WRITE32(nfs4_lock_type(args->fl, 0));
1049 WRITE32(args->seqid->sequence->counter);
1050 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
1051 WRITE64(args->fl->fl_start);
1052 WRITE64(nfs4_lock_length(args->fl));
1054 hdr->replen += decode_locku_maxsz;
1057 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1059 int len = name->len;
1062 RESERVE_SPACE(8 + len);
1065 WRITEMEM(name->name, len);
1067 hdr->replen += decode_lookup_maxsz;
1070 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1075 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1077 WRITE32(NFS4_SHARE_ACCESS_READ);
1080 WRITE32(NFS4_SHARE_ACCESS_WRITE);
1082 case FMODE_READ|FMODE_WRITE:
1083 WRITE32(NFS4_SHARE_ACCESS_BOTH);
1088 WRITE32(0); /* for linux, share_deny = 0 always */
1091 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1095 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1100 WRITE32(arg->seqid->sequence->counter);
1101 encode_share_access(xdr, arg->fmode);
1103 WRITE64(arg->clientid);
1105 WRITEMEM("open id:", 8);
1109 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1114 switch(arg->open_flags & O_EXCL) {
1116 WRITE32(NFS4_CREATE_UNCHECKED);
1117 encode_attrs(xdr, arg->u.attrs, arg->server);
1120 WRITE32(NFS4_CREATE_EXCLUSIVE);
1121 encode_nfs4_verifier(xdr, &arg->u.verifier);
1125 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1130 switch (arg->open_flags & O_CREAT) {
1132 WRITE32(NFS4_OPEN_NOCREATE);
1135 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1136 WRITE32(NFS4_OPEN_CREATE);
1137 encode_createmode(xdr, arg);
1141 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1146 switch (delegation_type) {
1148 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1151 WRITE32(NFS4_OPEN_DELEGATE_READ);
1153 case FMODE_WRITE|FMODE_READ:
1154 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1161 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1166 WRITE32(NFS4_OPEN_CLAIM_NULL);
1167 encode_string(xdr, name->len, name->name);
1170 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1175 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1176 encode_delegation_type(xdr, type);
1179 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1183 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1184 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1185 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1186 encode_string(xdr, name->len, name->name);
1189 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1191 encode_openhdr(xdr, arg);
1192 encode_opentype(xdr, arg);
1193 switch (arg->claim) {
1194 case NFS4_OPEN_CLAIM_NULL:
1195 encode_claim_null(xdr, arg->name);
1197 case NFS4_OPEN_CLAIM_PREVIOUS:
1198 encode_claim_previous(xdr, arg->u.delegation_type);
1200 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1201 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1207 hdr->replen += decode_open_maxsz;
1210 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1214 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1215 WRITE32(OP_OPEN_CONFIRM);
1216 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1217 WRITE32(arg->seqid->sequence->counter);
1219 hdr->replen += decode_open_confirm_maxsz;
1222 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1226 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1227 WRITE32(OP_OPEN_DOWNGRADE);
1228 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1229 WRITE32(arg->seqid->sequence->counter);
1230 encode_share_access(xdr, arg->fmode);
1232 hdr->replen += decode_open_downgrade_maxsz;
1236 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1241 RESERVE_SPACE(8 + len);
1244 WRITEMEM(fh->data, len);
1246 hdr->replen += decode_putfh_maxsz;
1249 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1254 WRITE32(OP_PUTROOTFH);
1256 hdr->replen += decode_putrootfh_maxsz;
1259 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1261 nfs4_stateid stateid;
1264 RESERVE_SPACE(NFS4_STATEID_SIZE);
1265 if (ctx->state != NULL) {
1266 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1267 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1269 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1272 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1279 encode_stateid(xdr, args->context);
1282 WRITE64(args->offset);
1283 WRITE32(args->count);
1285 hdr->replen += decode_read_maxsz;
1288 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1290 uint32_t attrs[2] = {
1291 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1292 FATTR4_WORD1_MOUNTED_ON_FILEID,
1296 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1297 WRITE32(OP_READDIR);
1298 WRITE64(readdir->cookie);
1299 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1300 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1301 WRITE32(readdir->count);
1303 /* Switch to mounted_on_fileid if the server supports it */
1304 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1305 attrs[0] &= ~FATTR4_WORD0_FILEID;
1307 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1308 WRITE32(attrs[0] & readdir->bitmask[0]);
1309 WRITE32(attrs[1] & readdir->bitmask[1]);
1311 hdr->replen += decode_readdir_maxsz;
1312 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1314 (unsigned long long)readdir->cookie,
1315 ((u32 *)readdir->verifier.data)[0],
1316 ((u32 *)readdir->verifier.data)[1],
1317 attrs[0] & readdir->bitmask[0],
1318 attrs[1] & readdir->bitmask[1]);
1321 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1326 WRITE32(OP_READLINK);
1328 hdr->replen += decode_readlink_maxsz;
1331 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1335 RESERVE_SPACE(8 + name->len);
1338 WRITEMEM(name->name, name->len);
1340 hdr->replen += decode_remove_maxsz;
1343 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1347 RESERVE_SPACE(8 + oldname->len);
1349 WRITE32(oldname->len);
1350 WRITEMEM(oldname->name, oldname->len);
1352 RESERVE_SPACE(4 + newname->len);
1353 WRITE32(newname->len);
1354 WRITEMEM(newname->name, newname->len);
1356 hdr->replen += decode_rename_maxsz;
1359 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1365 WRITE64(client_stateid->cl_clientid);
1367 hdr->replen += decode_renew_maxsz;
1371 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1376 WRITE32(OP_RESTOREFH);
1378 hdr->replen += decode_restorefh_maxsz;
1382 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1386 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1387 WRITE32(OP_SETATTR);
1388 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1391 WRITE32(FATTR4_WORD0_ACL);
1392 if (arg->acl_len % 4)
1395 WRITE32(arg->acl_len);
1396 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1398 hdr->replen += decode_setacl_maxsz;
1403 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1410 hdr->replen += decode_savefh_maxsz;
1413 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1417 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1418 WRITE32(OP_SETATTR);
1419 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1421 hdr->replen += decode_setattr_maxsz;
1422 encode_attrs(xdr, arg->iap, server);
1425 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1429 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1430 WRITE32(OP_SETCLIENTID);
1431 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1433 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1435 WRITE32(setclientid->sc_prog);
1436 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1437 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1439 WRITE32(setclientid->sc_cb_ident);
1441 hdr->replen += decode_setclientid_maxsz;
1444 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
1448 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1449 WRITE32(OP_SETCLIENTID_CONFIRM);
1450 WRITE64(client_state->cl_clientid);
1451 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1453 hdr->replen += decode_setclientid_confirm_maxsz;
1456 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1463 encode_stateid(xdr, args->context);
1466 WRITE64(args->offset);
1467 WRITE32(args->stable);
1468 WRITE32(args->count);
1470 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1472 hdr->replen += decode_write_maxsz;
1475 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1479 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1481 WRITE32(OP_DELEGRETURN);
1482 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1484 hdr->replen += decode_delegreturn_maxsz;
1487 #if defined(CONFIG_NFS_V4_1)
1488 /* NFSv4.1 operations */
1489 static void encode_exchange_id(struct xdr_stream *xdr,
1490 struct nfs41_exchange_id_args *args,
1491 struct compound_hdr *hdr)
1495 RESERVE_SPACE(4 + sizeof(args->verifier->data));
1496 WRITE32(OP_EXCHANGE_ID);
1497 WRITEMEM(args->verifier->data, sizeof(args->verifier->data));
1499 encode_string(xdr, args->id_len, args->id);
1502 WRITE32(args->flags);
1503 WRITE32(0); /* zero length state_protect4_a */
1504 WRITE32(0); /* zero length implementation id array */
1506 hdr->replen += decode_exchange_id_maxsz;
1508 #endif /* CONFIG_NFS_V4_1 */
1510 static void encode_sequence(struct xdr_stream *xdr,
1511 const struct nfs4_sequence_args *args,
1512 struct compound_hdr *hdr)
1514 #if defined(CONFIG_NFS_V4_1)
1515 struct nfs4_session *session = args->sa_session;
1522 hdr->replen += decode_sequence_maxsz;
1523 #endif /* CONFIG_NFS_V4_1 */
1527 * END OF "GENERIC" ENCODE ROUTINES.
1530 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1532 #if defined(CONFIG_NFS_V4_1)
1533 if (args->sa_session)
1534 return args->sa_session->clp->cl_minorversion;
1535 #endif /* CONFIG_NFS_V4_1 */
1540 * Encode an ACCESS request
1542 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1544 struct xdr_stream xdr;
1545 struct compound_hdr hdr = {
1546 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1549 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1550 encode_compound_hdr(&xdr, req, &hdr);
1551 encode_sequence(&xdr, &args->seq_args, &hdr);
1552 encode_putfh(&xdr, args->fh, &hdr);
1553 encode_access(&xdr, args->access, &hdr);
1554 encode_getfattr(&xdr, args->bitmask, &hdr);
1560 * Encode LOOKUP request
1562 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1564 struct xdr_stream xdr;
1565 struct compound_hdr hdr = {
1566 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1569 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1570 encode_compound_hdr(&xdr, req, &hdr);
1571 encode_sequence(&xdr, &args->seq_args, &hdr);
1572 encode_putfh(&xdr, args->dir_fh, &hdr);
1573 encode_lookup(&xdr, args->name, &hdr);
1574 encode_getfh(&xdr, &hdr);
1575 encode_getfattr(&xdr, args->bitmask, &hdr);
1581 * Encode LOOKUP_ROOT request
1583 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1585 struct xdr_stream xdr;
1586 struct compound_hdr hdr = {
1587 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1590 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1591 encode_compound_hdr(&xdr, req, &hdr);
1592 encode_sequence(&xdr, &args->seq_args, &hdr);
1593 encode_putrootfh(&xdr, &hdr);
1594 encode_getfh(&xdr, &hdr);
1595 encode_getfattr(&xdr, args->bitmask, &hdr);
1601 * Encode REMOVE request
1603 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
1605 struct xdr_stream xdr;
1606 struct compound_hdr hdr = {
1607 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1610 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1611 encode_compound_hdr(&xdr, req, &hdr);
1612 encode_sequence(&xdr, &args->seq_args, &hdr);
1613 encode_putfh(&xdr, args->fh, &hdr);
1614 encode_remove(&xdr, &args->name, &hdr);
1615 encode_getfattr(&xdr, args->bitmask, &hdr);
1621 * Encode RENAME request
1623 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1625 struct xdr_stream xdr;
1626 struct compound_hdr hdr = {
1627 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1630 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1631 encode_compound_hdr(&xdr, req, &hdr);
1632 encode_sequence(&xdr, &args->seq_args, &hdr);
1633 encode_putfh(&xdr, args->old_dir, &hdr);
1634 encode_savefh(&xdr, &hdr);
1635 encode_putfh(&xdr, args->new_dir, &hdr);
1636 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1637 encode_getfattr(&xdr, args->bitmask, &hdr);
1638 encode_restorefh(&xdr, &hdr);
1639 encode_getfattr(&xdr, args->bitmask, &hdr);
1645 * Encode LINK request
1647 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1649 struct xdr_stream xdr;
1650 struct compound_hdr hdr = {
1651 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1654 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1655 encode_compound_hdr(&xdr, req, &hdr);
1656 encode_sequence(&xdr, &args->seq_args, &hdr);
1657 encode_putfh(&xdr, args->fh, &hdr);
1658 encode_savefh(&xdr, &hdr);
1659 encode_putfh(&xdr, args->dir_fh, &hdr);
1660 encode_link(&xdr, args->name, &hdr);
1661 encode_getfattr(&xdr, args->bitmask, &hdr);
1662 encode_restorefh(&xdr, &hdr);
1663 encode_getfattr(&xdr, args->bitmask, &hdr);
1669 * Encode CREATE request
1671 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1673 struct xdr_stream xdr;
1674 struct compound_hdr hdr = {
1675 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1678 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1679 encode_compound_hdr(&xdr, req, &hdr);
1680 encode_sequence(&xdr, &args->seq_args, &hdr);
1681 encode_putfh(&xdr, args->dir_fh, &hdr);
1682 encode_savefh(&xdr, &hdr);
1683 encode_create(&xdr, args, &hdr);
1684 encode_getfh(&xdr, &hdr);
1685 encode_getfattr(&xdr, args->bitmask, &hdr);
1686 encode_restorefh(&xdr, &hdr);
1687 encode_getfattr(&xdr, args->bitmask, &hdr);
1693 * Encode SYMLINK request
1695 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1697 return nfs4_xdr_enc_create(req, p, args);
1701 * Encode GETATTR request
1703 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1705 struct xdr_stream xdr;
1706 struct compound_hdr hdr = {
1707 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1710 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1711 encode_compound_hdr(&xdr, req, &hdr);
1712 encode_sequence(&xdr, &args->seq_args, &hdr);
1713 encode_putfh(&xdr, args->fh, &hdr);
1714 encode_getfattr(&xdr, args->bitmask, &hdr);
1720 * Encode a CLOSE request
1722 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1724 struct xdr_stream xdr;
1725 struct compound_hdr hdr = {
1726 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1729 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1730 encode_compound_hdr(&xdr, req, &hdr);
1731 encode_sequence(&xdr, &args->seq_args, &hdr);
1732 encode_putfh(&xdr, args->fh, &hdr);
1733 encode_close(&xdr, args, &hdr);
1734 encode_getfattr(&xdr, args->bitmask, &hdr);
1740 * Encode an OPEN request
1742 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1744 struct xdr_stream xdr;
1745 struct compound_hdr hdr = {
1746 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1749 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1750 encode_compound_hdr(&xdr, req, &hdr);
1751 encode_sequence(&xdr, &args->seq_args, &hdr);
1752 encode_putfh(&xdr, args->fh, &hdr);
1753 encode_savefh(&xdr, &hdr);
1754 encode_open(&xdr, args, &hdr);
1755 encode_getfh(&xdr, &hdr);
1756 encode_getfattr(&xdr, args->bitmask, &hdr);
1757 encode_restorefh(&xdr, &hdr);
1758 encode_getfattr(&xdr, args->bitmask, &hdr);
1764 * Encode an OPEN_CONFIRM request
1766 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1768 struct xdr_stream xdr;
1769 struct compound_hdr hdr = {
1773 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1774 encode_compound_hdr(&xdr, req, &hdr);
1775 encode_putfh(&xdr, args->fh, &hdr);
1776 encode_open_confirm(&xdr, args, &hdr);
1782 * Encode an OPEN request with no attributes.
1784 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1786 struct xdr_stream xdr;
1787 struct compound_hdr hdr = {
1788 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1791 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1792 encode_compound_hdr(&xdr, req, &hdr);
1793 encode_sequence(&xdr, &args->seq_args, &hdr);
1794 encode_putfh(&xdr, args->fh, &hdr);
1795 encode_open(&xdr, args, &hdr);
1796 encode_getfattr(&xdr, args->bitmask, &hdr);
1802 * Encode an OPEN_DOWNGRADE request
1804 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1806 struct xdr_stream xdr;
1807 struct compound_hdr hdr = {
1808 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1811 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1812 encode_compound_hdr(&xdr, req, &hdr);
1813 encode_sequence(&xdr, &args->seq_args, &hdr);
1814 encode_putfh(&xdr, args->fh, &hdr);
1815 encode_open_downgrade(&xdr, args, &hdr);
1816 encode_getfattr(&xdr, args->bitmask, &hdr);
1822 * Encode a LOCK request
1824 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1826 struct xdr_stream xdr;
1827 struct compound_hdr hdr = {
1828 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1831 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1832 encode_compound_hdr(&xdr, req, &hdr);
1833 encode_sequence(&xdr, &args->seq_args, &hdr);
1834 encode_putfh(&xdr, args->fh, &hdr);
1835 encode_lock(&xdr, args, &hdr);
1841 * Encode a LOCKT request
1843 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
1845 struct xdr_stream xdr;
1846 struct compound_hdr hdr = {
1847 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1850 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1851 encode_compound_hdr(&xdr, req, &hdr);
1852 encode_sequence(&xdr, &args->seq_args, &hdr);
1853 encode_putfh(&xdr, args->fh, &hdr);
1854 encode_lockt(&xdr, args, &hdr);
1860 * Encode a LOCKU request
1862 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
1864 struct xdr_stream xdr;
1865 struct compound_hdr hdr = {
1866 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1869 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1870 encode_compound_hdr(&xdr, req, &hdr);
1871 encode_sequence(&xdr, &args->seq_args, &hdr);
1872 encode_putfh(&xdr, args->fh, &hdr);
1873 encode_locku(&xdr, args, &hdr);
1879 * Encode a READLINK request
1881 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
1883 struct xdr_stream xdr;
1884 struct compound_hdr hdr = {
1885 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1888 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1889 encode_compound_hdr(&xdr, req, &hdr);
1890 encode_sequence(&xdr, &args->seq_args, &hdr);
1891 encode_putfh(&xdr, args->fh, &hdr);
1892 encode_readlink(&xdr, args, req, &hdr);
1894 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
1895 args->pgbase, args->pglen);
1901 * Encode a READDIR request
1903 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
1905 struct xdr_stream xdr;
1906 struct compound_hdr hdr = {
1907 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1910 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1911 encode_compound_hdr(&xdr, req, &hdr);
1912 encode_sequence(&xdr, &args->seq_args, &hdr);
1913 encode_putfh(&xdr, args->fh, &hdr);
1914 encode_readdir(&xdr, args, req, &hdr);
1916 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
1917 args->pgbase, args->count);
1918 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1919 __func__, hdr.replen << 2, args->pages,
1920 args->pgbase, args->count);
1926 * Encode a READ request
1928 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
1930 struct xdr_stream xdr;
1931 struct compound_hdr hdr = {
1932 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1935 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1936 encode_compound_hdr(&xdr, req, &hdr);
1937 encode_sequence(&xdr, &args->seq_args, &hdr);
1938 encode_putfh(&xdr, args->fh, &hdr);
1939 encode_read(&xdr, args, &hdr);
1941 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
1942 args->pages, args->pgbase, args->count);
1943 req->rq_rcv_buf.flags |= XDRBUF_READ;
1949 * Encode an SETATTR request
1951 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
1953 struct xdr_stream xdr;
1954 struct compound_hdr hdr = {
1955 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1958 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1959 encode_compound_hdr(&xdr, req, &hdr);
1960 encode_sequence(&xdr, &args->seq_args, &hdr);
1961 encode_putfh(&xdr, args->fh, &hdr);
1962 encode_setattr(&xdr, args, args->server, &hdr);
1963 encode_getfattr(&xdr, args->bitmask, &hdr);
1969 * Encode a GETACL request
1972 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
1973 struct nfs_getaclargs *args)
1975 struct xdr_stream xdr;
1976 struct compound_hdr hdr = {
1977 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1981 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1982 encode_compound_hdr(&xdr, req, &hdr);
1983 encode_sequence(&xdr, &args->seq_args, &hdr);
1984 encode_putfh(&xdr, args->fh, &hdr);
1985 replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1;
1986 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
1988 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
1989 args->acl_pages, args->acl_pgbase, args->acl_len);
1995 * Encode a WRITE request
1997 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
1999 struct xdr_stream xdr;
2000 struct compound_hdr hdr = {
2001 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2004 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2005 encode_compound_hdr(&xdr, req, &hdr);
2006 encode_sequence(&xdr, &args->seq_args, &hdr);
2007 encode_putfh(&xdr, args->fh, &hdr);
2008 encode_write(&xdr, args, &hdr);
2009 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2010 encode_getfattr(&xdr, args->bitmask, &hdr);
2018 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
2020 struct xdr_stream xdr;
2021 struct compound_hdr hdr = {
2022 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2025 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2026 encode_compound_hdr(&xdr, req, &hdr);
2027 encode_sequence(&xdr, &args->seq_args, &hdr);
2028 encode_putfh(&xdr, args->fh, &hdr);
2029 encode_commit(&xdr, args, &hdr);
2030 encode_getfattr(&xdr, args->bitmask, &hdr);
2038 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
2040 struct xdr_stream xdr;
2041 struct compound_hdr hdr = {
2042 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2045 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2046 encode_compound_hdr(&xdr, req, &hdr);
2047 encode_sequence(&xdr, &args->seq_args, &hdr);
2048 encode_putfh(&xdr, args->fh, &hdr);
2049 encode_fsinfo(&xdr, args->bitmask, &hdr);
2055 * a PATHCONF request
2057 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
2059 struct xdr_stream xdr;
2060 struct compound_hdr hdr = {
2061 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2064 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2065 encode_compound_hdr(&xdr, req, &hdr);
2066 encode_sequence(&xdr, &args->seq_args, &hdr);
2067 encode_putfh(&xdr, args->fh, &hdr);
2068 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2077 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
2079 struct xdr_stream xdr;
2080 struct compound_hdr hdr = {
2081 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2084 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2085 encode_compound_hdr(&xdr, req, &hdr);
2086 encode_sequence(&xdr, &args->seq_args, &hdr);
2087 encode_putfh(&xdr, args->fh, &hdr);
2088 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2089 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2095 * GETATTR_BITMAP request
2097 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2098 struct nfs4_server_caps_arg *args)
2100 struct xdr_stream xdr;
2101 struct compound_hdr hdr = {
2102 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2105 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2106 encode_compound_hdr(&xdr, req, &hdr);
2107 encode_sequence(&xdr, &args->seq_args, &hdr);
2108 encode_putfh(&xdr, args->fhandle, &hdr);
2109 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2110 FATTR4_WORD0_LINK_SUPPORT|
2111 FATTR4_WORD0_SYMLINK_SUPPORT|
2112 FATTR4_WORD0_ACLSUPPORT, &hdr);
2120 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2122 struct xdr_stream xdr;
2123 struct compound_hdr hdr = {
2127 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2128 encode_compound_hdr(&xdr, req, &hdr);
2129 encode_renew(&xdr, clp, &hdr);
2135 * a SETCLIENTID request
2137 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
2139 struct xdr_stream xdr;
2140 struct compound_hdr hdr = {
2144 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2145 encode_compound_hdr(&xdr, req, &hdr);
2146 encode_setclientid(&xdr, sc, &hdr);
2152 * a SETCLIENTID_CONFIRM request
2154 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2156 struct xdr_stream xdr;
2157 struct compound_hdr hdr = {
2160 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2162 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2163 encode_compound_hdr(&xdr, req, &hdr);
2164 encode_setclientid_confirm(&xdr, clp, &hdr);
2165 encode_putrootfh(&xdr, &hdr);
2166 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2172 * DELEGRETURN request
2174 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
2176 struct xdr_stream xdr;
2177 struct compound_hdr hdr = {
2178 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2181 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2182 encode_compound_hdr(&xdr, req, &hdr);
2183 encode_sequence(&xdr, &args->seq_args, &hdr);
2184 encode_putfh(&xdr, args->fhandle, &hdr);
2185 encode_delegreturn(&xdr, args->stateid, &hdr);
2186 encode_getfattr(&xdr, args->bitmask, &hdr);
2192 * Encode FS_LOCATIONS request
2194 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2196 struct xdr_stream xdr;
2197 struct compound_hdr hdr = {
2198 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2202 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2203 encode_compound_hdr(&xdr, req, &hdr);
2204 encode_sequence(&xdr, &args->seq_args, &hdr);
2205 encode_putfh(&xdr, args->dir_fh, &hdr);
2206 encode_lookup(&xdr, args->name, &hdr);
2207 replen = hdr.replen; /* get the attribute into args->page */
2208 encode_fs_locations(&xdr, args->bitmask, &hdr);
2210 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2216 #if defined(CONFIG_NFS_V4_1)
2218 * EXCHANGE_ID request
2220 static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2221 struct nfs41_exchange_id_args *args)
2223 struct xdr_stream xdr;
2224 struct compound_hdr hdr = {
2225 .minorversion = args->client->cl_minorversion,
2228 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2229 encode_compound_hdr(&xdr, req, &hdr);
2230 encode_exchange_id(&xdr, args, &hdr);
2234 #endif /* CONFIG_NFS_V4_1 */
2237 * START OF "GENERIC" DECODE ROUTINES.
2238 * These may look a little ugly since they are imported from a "generic"
2239 * set of XDR encode/decode routines which are intended to be shared by
2240 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2242 * If the pain of reading these is too great, it should be a straightforward
2243 * task to translate them into Linux-specific versions which are more
2244 * consistent with the style used in NFSv2/v3...
2246 #define READ32(x) (x) = ntohl(*p++)
2247 #define READ64(x) do { \
2248 (x) = (u64)ntohl(*p++) << 32; \
2249 (x) |= ntohl(*p++); \
2251 #define READTIME(x) do { \
2253 (x.tv_sec) = ntohl(*p++); \
2254 (x.tv_nsec) = ntohl(*p++); \
2256 #define COPYMEM(x,nbytes) do { \
2257 memcpy((x), p, nbytes); \
2258 p += XDR_QUADLEN(nbytes); \
2261 #define READ_BUF(nbytes) do { \
2262 p = xdr_inline_decode(xdr, nbytes); \
2263 if (unlikely(!p)) { \
2264 dprintk("nfs: %s: prematurely hit end of receive" \
2265 " buffer\n", __func__); \
2266 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2267 __func__, xdr->p, nbytes, xdr->end); \
2272 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2279 *string = (char *)p;
2283 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2288 READ32(hdr->status);
2289 READ32(hdr->taglen);
2291 READ_BUF(hdr->taglen + 4);
2292 hdr->tag = (char *)p;
2293 p += XDR_QUADLEN(hdr->taglen);
2295 if (unlikely(hdr->nops < 1))
2296 return nfs4_stat_to_errno(hdr->status);
2300 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2308 if (opnum != expected) {
2309 dprintk("nfs: Server returned operation"
2310 " %d but we issued a request for %d\n",
2315 if (nfserr != NFS_OK)
2316 return nfs4_stat_to_errno(nfserr);
2321 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2324 unsigned int strlen;
2328 return decode_opaque_inline(xdr, &strlen, &str);
2331 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2339 bitmap[0] = bitmap[1] = 0;
2340 READ_BUF((bmlen << 2));
2349 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2359 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2361 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2362 decode_attr_bitmap(xdr, bitmask);
2363 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2365 bitmask[0] = bitmask[1] = 0;
2366 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
2370 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2376 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2378 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2381 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2382 dprintk("%s: bad type %d\n", __func__, *type);
2385 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2386 ret = NFS_ATTR_FATTR_TYPE;
2388 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
2392 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2398 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2400 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2403 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2404 ret = NFS_ATTR_FATTR_CHANGE;
2406 dprintk("%s: change attribute=%Lu\n", __func__,
2407 (unsigned long long)*change);
2411 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2417 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2419 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2422 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2423 ret = NFS_ATTR_FATTR_SIZE;
2425 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
2429 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2434 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2436 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2439 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2441 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
2445 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2450 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2452 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2455 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2457 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
2461 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2468 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2470 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2472 READ64(fsid->major);
2473 READ64(fsid->minor);
2474 bitmap[0] &= ~FATTR4_WORD0_FSID;
2475 ret = NFS_ATTR_FATTR_FSID;
2477 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
2478 (unsigned long long)fsid->major,
2479 (unsigned long long)fsid->minor);
2483 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2488 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2490 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2493 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2495 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
2499 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2503 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2504 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2506 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2509 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2511 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
2515 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2521 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2523 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2526 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2527 ret = NFS_ATTR_FATTR_FILEID;
2529 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2533 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2539 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2541 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2544 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2545 ret = NFS_ATTR_FATTR_FILEID;
2547 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2551 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2557 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2559 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2562 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2564 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
2568 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2574 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2576 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2579 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2581 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
2585 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2591 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2593 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2596 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2598 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
2602 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2613 path->ncomponents = 0;
2614 while (path->ncomponents < n) {
2615 struct nfs4_string *component = &path->components[path->ncomponents];
2616 status = decode_opaque_inline(xdr, &component->len, &component->data);
2617 if (unlikely(status != 0))
2619 if (path->ncomponents != n)
2621 dprintk("%s", component->data);
2622 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2623 path->ncomponents++;
2625 dprintk("cannot parse %d components in path\n", n);
2633 /* a root pathname is sent as a zero component4 */
2634 path->ncomponents = 1;
2635 path->components[0].len=0;
2636 path->components[0].data=NULL;
2637 dprintk("path /\n");
2640 dprintk(" status %d", status);
2645 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2651 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2654 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2656 dprintk("%s: fsroot ", __func__);
2657 status = decode_pathname(xdr, &res->fs_path);
2658 if (unlikely(status != 0))
2664 res->nlocations = 0;
2665 while (res->nlocations < n) {
2667 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2673 dprintk("%s: servers ", __func__);
2674 while (loc->nservers < m) {
2675 struct nfs4_string *server = &loc->servers[loc->nservers];
2676 status = decode_opaque_inline(xdr, &server->len, &server->data);
2677 if (unlikely(status != 0))
2679 dprintk("%s ", server->data);
2680 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2684 dprintk("%s: using first %u of %u servers "
2685 "returned for location %u\n",
2687 NFS4_FS_LOCATION_MAXSERVERS,
2688 m, res->nlocations);
2689 for (i = loc->nservers; i < m; i++) {
2692 status = decode_opaque_inline(xdr, &len, &data);
2693 if (unlikely(status != 0))
2698 status = decode_pathname(xdr, &loc->rootpath);
2699 if (unlikely(status != 0))
2701 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2704 if (res->nlocations != 0)
2705 status = NFS_ATTR_FATTR_V4_REFERRAL;
2707 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
2714 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2720 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2722 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2725 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2727 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
2731 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2737 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2739 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2742 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2744 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
2748 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2754 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2756 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2759 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2761 dprintk("%s: maxname=%u\n", __func__, *maxname);
2765 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2771 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2773 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2777 if (maxread > 0x7FFFFFFF)
2778 maxread = 0x7FFFFFFF;
2779 *res = (uint32_t)maxread;
2780 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2782 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
2786 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2792 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2794 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2798 if (maxwrite > 0x7FFFFFFF)
2799 maxwrite = 0x7FFFFFFF;
2800 *res = (uint32_t)maxwrite;
2801 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2803 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
2807 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
2814 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2816 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2819 *mode = tmp & ~S_IFMT;
2820 bitmap[1] &= ~FATTR4_WORD1_MODE;
2821 ret = NFS_ATTR_FATTR_MODE;
2823 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
2827 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2833 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2835 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2838 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2839 ret = NFS_ATTR_FATTR_NLINK;
2841 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
2845 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
2852 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2854 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2858 if (len < XDR_MAX_NETOBJ) {
2859 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
2860 ret = NFS_ATTR_FATTR_OWNER;
2862 dprintk("%s: nfs_map_name_to_uid failed!\n",
2865 dprintk("%s: name too long (%u)!\n",
2867 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2869 dprintk("%s: uid=%d\n", __func__, (int)*uid);
2873 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
2880 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2882 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2886 if (len < XDR_MAX_NETOBJ) {
2887 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
2888 ret = NFS_ATTR_FATTR_GROUP;
2890 dprintk("%s: nfs_map_group_to_gid failed!\n",
2893 dprintk("%s: name too long (%u)!\n",
2895 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2897 dprintk("%s: gid=%d\n", __func__, (int)*gid);
2901 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2903 uint32_t major = 0, minor = 0;
2908 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2910 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2916 tmp = MKDEV(major, minor);
2917 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2919 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2920 ret = NFS_ATTR_FATTR_RDEV;
2922 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
2926 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2932 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2934 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2937 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2939 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
2943 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2949 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2951 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2954 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2956 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
2960 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2966 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2968 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2971 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2973 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
2977 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2983 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2985 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2988 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2989 ret = NFS_ATTR_FATTR_SPACE_USED;
2991 dprintk("%s: space used=%Lu\n", __func__,
2992 (unsigned long long)*used);
2996 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3005 time->tv_sec = (time_t)sec;
3006 time->tv_nsec = (long)nsec;
3010 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3016 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3018 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3019 status = decode_attr_time(xdr, time);
3021 status = NFS_ATTR_FATTR_ATIME;
3022 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3024 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
3028 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3034 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3036 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3037 status = decode_attr_time(xdr, time);
3039 status = NFS_ATTR_FATTR_CTIME;
3040 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3042 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
3046 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3052 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3054 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3055 status = decode_attr_time(xdr, time);
3057 status = NFS_ATTR_FATTR_MTIME;
3058 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3060 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
3064 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
3066 unsigned int attrwords = XDR_QUADLEN(attrlen);
3067 unsigned int nwords = xdr->p - savep;
3069 if (unlikely(attrwords != nwords)) {
3070 dprintk("%s: server returned incorrect attribute length: "
3074 (attrwords < nwords) ? '<' : '>',
3081 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3086 READ32(cinfo->atomic);
3087 READ64(cinfo->before);
3088 READ64(cinfo->after);
3092 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3098 status = decode_op_hdr(xdr, OP_ACCESS);
3104 access->supported = supp;
3105 access->access = acc;
3109 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3114 status = decode_op_hdr(xdr, OP_CLOSE);
3116 nfs_increment_open_seqid(status, res->seqid);
3119 READ_BUF(NFS4_STATEID_SIZE);
3120 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3124 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3129 status = decode_op_hdr(xdr, OP_COMMIT);
3133 COPYMEM(res->verf->verifier, 8);
3137 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3143 status = decode_op_hdr(xdr, OP_CREATE);
3146 if ((status = decode_change_info(xdr, cinfo)))
3150 READ_BUF(bmlen << 2);
3154 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3157 uint32_t attrlen, bitmap[2] = {0};
3160 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3162 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3164 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3166 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3168 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3170 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3172 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3174 status = verify_attr_len(xdr, savep, attrlen);
3176 dprintk("%s: xdr returned %d!\n", __func__, -status);
3180 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3183 uint32_t attrlen, bitmap[2] = {0};
3186 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3188 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3190 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3193 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3195 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3197 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3199 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3201 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3203 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3206 status = verify_attr_len(xdr, savep, attrlen);
3208 dprintk("%s: xdr returned %d!\n", __func__, -status);
3212 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3215 uint32_t attrlen, bitmap[2] = {0};
3218 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3220 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3222 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3225 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3227 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3230 status = verify_attr_len(xdr, savep, attrlen);
3232 dprintk("%s: xdr returned %d!\n", __func__, -status);
3236 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3246 status = decode_op_hdr(xdr, OP_GETATTR);
3250 status = decode_attr_bitmap(xdr, bitmap);
3254 status = decode_attr_length(xdr, &attrlen, &savep);
3259 status = decode_attr_type(xdr, bitmap, &type);
3264 fattr->mode |= nfs_type2fmt[type];
3265 fattr->valid |= status;
3268 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3271 fattr->valid |= status;
3273 status = decode_attr_size(xdr, bitmap, &fattr->size);
3276 fattr->valid |= status;
3278 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3281 fattr->valid |= status;
3283 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3286 fattr->valid |= status;
3288 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3289 struct nfs4_fs_locations,
3293 fattr->valid |= status;
3295 status = decode_attr_mode(xdr, bitmap, &fmode);
3299 fattr->mode |= fmode;
3300 fattr->valid |= status;
3303 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3306 fattr->valid |= status;
3308 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
3311 fattr->valid |= status;
3313 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
3316 fattr->valid |= status;
3318 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3321 fattr->valid |= status;
3323 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3326 fattr->valid |= status;
3328 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3331 fattr->valid |= status;
3333 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3336 fattr->valid |= status;
3338 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3341 fattr->valid |= status;
3343 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3346 if (status != 0 && !(fattr->valid & status)) {
3347 fattr->fileid = fileid;
3348 fattr->valid |= status;
3351 status = verify_attr_len(xdr, savep, attrlen);
3353 dprintk("%s: xdr returned %d\n", __func__, -status);
3358 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3361 uint32_t attrlen, bitmap[2];
3364 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3366 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3368 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3371 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3373 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3375 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3377 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3379 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3380 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3382 fsinfo->wtpref = fsinfo->wtmax;
3384 status = verify_attr_len(xdr, savep, attrlen);
3386 dprintk("%s: xdr returned %d!\n", __func__, -status);
3390 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3396 /* Zero handle first to allow comparisons */
3397 memset(fh, 0, sizeof(*fh));
3399 status = decode_op_hdr(xdr, OP_GETFH);
3405 if (len > NFS4_FHSIZE)
3409 COPYMEM(fh->data, len);
3413 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3417 status = decode_op_hdr(xdr, OP_LINK);
3420 return decode_change_info(xdr, cinfo);
3424 * We create the owner, so we know a proper owner.id length is 4.
3426 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3428 uint64_t offset, length, clientid;
3430 uint32_t namelen, type;
3437 fl->fl_start = (loff_t)offset;
3438 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3439 if (length == ~(uint64_t)0)
3440 fl->fl_end = OFFSET_MAX;
3441 fl->fl_type = F_WRLCK;
3443 fl->fl_type = F_RDLCK;
3449 return -NFS4ERR_DENIED;
3452 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3457 status = decode_op_hdr(xdr, OP_LOCK);
3461 READ_BUF(NFS4_STATEID_SIZE);
3462 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3463 } else if (status == -NFS4ERR_DENIED)
3464 status = decode_lock_denied(xdr, NULL);
3465 if (res->open_seqid != NULL)
3466 nfs_increment_open_seqid(status, res->open_seqid);
3467 nfs_increment_lock_seqid(status, res->lock_seqid);
3472 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3475 status = decode_op_hdr(xdr, OP_LOCKT);
3476 if (status == -NFS4ERR_DENIED)
3477 return decode_lock_denied(xdr, res->denied);
3481 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3486 status = decode_op_hdr(xdr, OP_LOCKU);
3488 nfs_increment_lock_seqid(status, res->seqid);
3490 READ_BUF(NFS4_STATEID_SIZE);
3491 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3496 static int decode_lookup(struct xdr_stream *xdr)
3498 return decode_op_hdr(xdr, OP_LOOKUP);
3501 /* This is too sick! */
3502 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3505 uint32_t limit_type, nblocks, blocksize;
3509 switch (limit_type) {
3516 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3521 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3524 uint32_t delegation_type;
3527 READ32(delegation_type);
3528 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3529 res->delegation_type = 0;
3532 READ_BUF(NFS4_STATEID_SIZE+4);
3533 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3534 READ32(res->do_recall);
3536 switch (delegation_type) {
3537 case NFS4_OPEN_DELEGATE_READ:
3538 res->delegation_type = FMODE_READ;
3540 case NFS4_OPEN_DELEGATE_WRITE:
3541 res->delegation_type = FMODE_WRITE|FMODE_READ;
3542 if (decode_space_limit(xdr, &res->maxsize) < 0)
3545 return decode_ace(xdr, NULL, res->server->nfs_client);
3548 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3551 uint32_t savewords, bmlen, i;
3554 status = decode_op_hdr(xdr, OP_OPEN);
3556 nfs_increment_open_seqid(status, res->seqid);
3559 READ_BUF(NFS4_STATEID_SIZE);
3560 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3562 decode_change_info(xdr, &res->cinfo);
3565 READ32(res->rflags);
3570 READ_BUF(bmlen << 2);
3571 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3572 for (i = 0; i < savewords; ++i)
3573 READ32(res->attrset[i]);
3574 for (; i < NFS4_BITMAP_SIZE; i++)
3575 res->attrset[i] = 0;
3577 return decode_delegation(xdr, res);
3579 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
3583 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3588 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3590 nfs_increment_open_seqid(status, res->seqid);
3593 READ_BUF(NFS4_STATEID_SIZE);
3594 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3598 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3603 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3605 nfs_increment_open_seqid(status, res->seqid);
3608 READ_BUF(NFS4_STATEID_SIZE);
3609 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3613 static int decode_putfh(struct xdr_stream *xdr)
3615 return decode_op_hdr(xdr, OP_PUTFH);
3618 static int decode_putrootfh(struct xdr_stream *xdr)
3620 return decode_op_hdr(xdr, OP_PUTROOTFH);
3623 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3625 struct kvec *iov = req->rq_rcv_buf.head;
3627 uint32_t count, eof, recvd, hdrlen;
3630 status = decode_op_hdr(xdr, OP_READ);
3636 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3637 recvd = req->rq_rcv_buf.len - hdrlen;
3638 if (count > recvd) {
3639 dprintk("NFS: server cheating in read reply: "
3640 "count %u > recvd %u\n", count, recvd);
3644 xdr_read_pages(xdr, count);
3650 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3652 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3653 struct page *page = *rcvbuf->pages;
3654 struct kvec *iov = rcvbuf->head;
3656 u32 recvd, pglen = rcvbuf->page_len;
3657 __be32 *end, *entry, *p, *kaddr;
3658 unsigned int nr = 0;
3661 status = decode_op_hdr(xdr, OP_READDIR);
3665 COPYMEM(readdir->verifier.data, 8);
3666 dprintk("%s: verifier = %08x:%08x\n",
3668 ((u32 *)readdir->verifier.data)[0],
3669 ((u32 *)readdir->verifier.data)[1]);
3672 hdrlen = (char *) p - (char *) iov->iov_base;
3673 recvd = rcvbuf->len - hdrlen;
3676 xdr_read_pages(xdr, pglen);
3678 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3679 kaddr = p = kmap_atomic(page, KM_USER0);
3680 end = p + ((pglen + readdir->pgbase) >> 2);
3683 /* Make sure the packet actually has a value_follows and EOF entry */
3684 if ((entry + 1) > end)
3687 for (; *p++; nr++) {
3688 u32 len, attrlen, xlen;
3691 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3692 p += 2; /* cookie */
3693 len = ntohl(*p++); /* filename length */
3694 if (len > NFS4_MAXNAMLEN) {
3695 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3699 xlen = XDR_QUADLEN(len);
3700 if (end - p < xlen + 1)
3702 dprintk("filename = %*s\n", len, (char *)p);
3704 len = ntohl(*p++); /* bitmap length */
3705 if (end - p < len + 1)
3708 attrlen = XDR_QUADLEN(ntohl(*p++));
3709 if (end - p < attrlen + 2)
3711 p += attrlen; /* attributes */
3715 * Apparently some server sends responses that are a valid size, but
3716 * contain no entries, and have value_follows==0 and EOF==0. For
3717 * those, just set the EOF marker.
3719 if (!nr && entry[1] == 0) {
3720 dprintk("NFS: readdir reply truncated!\n");
3724 kunmap_atomic(kaddr, KM_USER0);
3728 * When we get a short packet there are 2 possibilities. We can
3729 * return an error, or fix up the response to look like a valid
3730 * response and return what we have so far. If there are no
3731 * entries and the packet was short, then return -EIO. If there
3732 * are valid entries in the response, return them and pretend that
3733 * the call was successful, but incomplete. The caller can retry the
3734 * readdir starting at the last cookie.
3736 dprintk("%s: short packet at entry %d\n", __func__, nr);
3737 entry[0] = entry[1] = 0;
3741 kunmap_atomic(kaddr, KM_USER0);
3742 return -errno_NFSERR_IO;
3745 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3747 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3748 struct kvec *iov = rcvbuf->head;
3755 status = decode_op_hdr(xdr, OP_READLINK);
3759 /* Convert length of symlink */
3762 if (len >= rcvbuf->page_len || len <= 0) {
3763 dprintk("nfs: server returned giant symlink!\n");
3764 return -ENAMETOOLONG;
3766 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3767 recvd = req->rq_rcv_buf.len - hdrlen;
3769 dprintk("NFS: server cheating in readlink reply: "
3770 "count %u > recvd %u\n", len, recvd);
3773 xdr_read_pages(xdr, len);
3775 * The XDR encode routine has set things up so that
3776 * the link text will be copied directly into the
3777 * buffer. We just have to do overflow-checking,
3778 * and and null-terminate the text (the VFS expects
3779 * null-termination).
3781 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3782 kaddr[len+rcvbuf->page_base] = '\0';
3783 kunmap_atomic(kaddr, KM_USER0);
3787 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3791 status = decode_op_hdr(xdr, OP_REMOVE);
3794 status = decode_change_info(xdr, cinfo);
3799 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3800 struct nfs4_change_info *new_cinfo)
3804 status = decode_op_hdr(xdr, OP_RENAME);
3807 if ((status = decode_change_info(xdr, old_cinfo)))
3809 status = decode_change_info(xdr, new_cinfo);
3814 static int decode_renew(struct xdr_stream *xdr)
3816 return decode_op_hdr(xdr, OP_RENEW);
3820 decode_restorefh(struct xdr_stream *xdr)
3822 return decode_op_hdr(xdr, OP_RESTOREFH);
3825 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3831 struct kvec *iov = req->rq_rcv_buf.head;
3835 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3837 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3839 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3842 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3844 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3848 /* We ignore &savep and don't do consistency checks on
3849 * the attr length. Let userspace figure it out.... */
3850 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3851 recvd = req->rq_rcv_buf.len - hdrlen;
3852 if (attrlen > recvd) {
3853 dprintk("NFS: server cheating in getattr"
3854 " acl reply: attrlen %u > recvd %u\n",
3858 xdr_read_pages(xdr, attrlen);
3861 status = -EOPNOTSUPP;
3868 decode_savefh(struct xdr_stream *xdr)
3870 return decode_op_hdr(xdr, OP_SAVEFH);
3873 static int decode_setattr(struct xdr_stream *xdr)
3879 status = decode_op_hdr(xdr, OP_SETATTR);
3884 READ_BUF(bmlen << 2);
3888 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
3896 if (opnum != OP_SETCLIENTID) {
3897 dprintk("nfs: decode_setclientid: Server returned operation"
3902 if (nfserr == NFS_OK) {
3903 READ_BUF(8 + NFS4_VERIFIER_SIZE);
3904 READ64(clp->cl_clientid);
3905 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
3906 } else if (nfserr == NFSERR_CLID_INUSE) {
3909 /* skip netid string */
3914 /* skip uaddr string */
3918 return -NFSERR_CLID_INUSE;
3920 return nfs4_stat_to_errno(nfserr);
3925 static int decode_setclientid_confirm(struct xdr_stream *xdr)
3927 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3930 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3935 status = decode_op_hdr(xdr, OP_WRITE);
3941 READ32(res->verf->committed);
3942 COPYMEM(res->verf->verifier, 8);
3946 static int decode_delegreturn(struct xdr_stream *xdr)
3948 return decode_op_hdr(xdr, OP_DELEGRETURN);
3951 #if defined(CONFIG_NFS_V4_1)
3952 static int decode_exchange_id(struct xdr_stream *xdr,
3953 struct nfs41_exchange_id_res *res)
3958 struct nfs_client *clp = res->client;
3960 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
3965 READ64(clp->cl_ex_clid);
3967 READ32(clp->cl_seqid);
3968 READ32(clp->cl_exchange_flags);
3970 /* We ask for SP4_NONE */
3972 if (dummy != SP4_NONE)
3975 /* Throw away minor_id */
3978 /* Throw away Major id */
3983 /* Throw away server_scope */
3988 /* Throw away Implementation id array */
3995 #endif /* CONFIG_NFS_V4_1 */
3997 static int decode_sequence(struct xdr_stream *xdr,
3998 struct nfs4_sequence_res *res,
3999 struct rpc_rqst *rqstp)
4001 #if defined(CONFIG_NFS_V4_1)
4002 if (!res->sr_session)
4006 #endif /* CONFIG_NFS_V4_1 */
4012 * END OF "GENERIC" DECODE ROUTINES.
4016 * Decode OPEN_DOWNGRADE response
4018 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
4020 struct xdr_stream xdr;
4021 struct compound_hdr hdr;
4024 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4025 status = decode_compound_hdr(&xdr, &hdr);
4028 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4031 status = decode_putfh(&xdr);
4034 status = decode_open_downgrade(&xdr, res);
4037 decode_getfattr(&xdr, res->fattr, res->server);
4043 * Decode ACCESS response
4045 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
4047 struct xdr_stream xdr;
4048 struct compound_hdr hdr;
4051 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4052 status = decode_compound_hdr(&xdr, &hdr);
4055 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4058 status = decode_putfh(&xdr);
4061 status = decode_access(&xdr, res);
4064 decode_getfattr(&xdr, res->fattr, res->server);
4070 * Decode LOOKUP response
4072 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
4074 struct xdr_stream xdr;
4075 struct compound_hdr hdr;
4078 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4079 status = decode_compound_hdr(&xdr, &hdr);
4082 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4085 if ((status = decode_putfh(&xdr)) != 0)
4087 if ((status = decode_lookup(&xdr)) != 0)
4089 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4091 status = decode_getfattr(&xdr, res->fattr, res->server);
4097 * Decode LOOKUP_ROOT response
4099 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
4101 struct xdr_stream xdr;
4102 struct compound_hdr hdr;
4105 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4106 status = decode_compound_hdr(&xdr, &hdr);
4109 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4112 if ((status = decode_putrootfh(&xdr)) != 0)
4114 if ((status = decode_getfh(&xdr, res->fh)) == 0)
4115 status = decode_getfattr(&xdr, res->fattr, res->server);
4121 * Decode REMOVE response
4123 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
4125 struct xdr_stream xdr;
4126 struct compound_hdr hdr;
4129 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4130 status = decode_compound_hdr(&xdr, &hdr);
4133 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4136 if ((status = decode_putfh(&xdr)) != 0)
4138 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4140 decode_getfattr(&xdr, &res->dir_attr, res->server);
4146 * Decode RENAME response
4148 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
4150 struct xdr_stream xdr;
4151 struct compound_hdr hdr;
4154 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4155 status = decode_compound_hdr(&xdr, &hdr);
4158 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4161 if ((status = decode_putfh(&xdr)) != 0)
4163 if ((status = decode_savefh(&xdr)) != 0)
4165 if ((status = decode_putfh(&xdr)) != 0)
4167 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4169 /* Current FH is target directory */
4170 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
4172 if ((status = decode_restorefh(&xdr)) != 0)
4174 decode_getfattr(&xdr, res->old_fattr, res->server);
4180 * Decode LINK response
4182 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
4184 struct xdr_stream xdr;
4185 struct compound_hdr hdr;
4188 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4189 status = decode_compound_hdr(&xdr, &hdr);
4192 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4195 if ((status = decode_putfh(&xdr)) != 0)
4197 if ((status = decode_savefh(&xdr)) != 0)
4199 if ((status = decode_putfh(&xdr)) != 0)
4201 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4204 * Note order: OP_LINK leaves the directory as the current
4207 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
4209 if ((status = decode_restorefh(&xdr)) != 0)
4211 decode_getfattr(&xdr, res->fattr, res->server);
4217 * Decode CREATE response
4219 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *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_sequence(&xdr, &res->seq_res, rqstp);
4232 if ((status = decode_putfh(&xdr)) != 0)
4234 if ((status = decode_savefh(&xdr)) != 0)
4236 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4238 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4240 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
4242 if ((status = decode_restorefh(&xdr)) != 0)
4244 decode_getfattr(&xdr, res->dir_fattr, res->server);
4250 * Decode SYMLINK response
4252 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
4254 return nfs4_xdr_dec_create(rqstp, p, res);
4258 * Decode GETATTR response
4260 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
4262 struct xdr_stream xdr;
4263 struct compound_hdr hdr;
4266 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4267 status = decode_compound_hdr(&xdr, &hdr);
4270 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4273 status = decode_putfh(&xdr);
4276 status = decode_getfattr(&xdr, res->fattr, res->server);
4282 * Encode an SETACL request
4285 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
4287 struct xdr_stream xdr;
4288 struct compound_hdr hdr = {
4289 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
4293 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
4294 encode_compound_hdr(&xdr, req, &hdr);
4295 encode_sequence(&xdr, &args->seq_args, &hdr);
4296 encode_putfh(&xdr, args->fh, &hdr);
4297 status = encode_setacl(&xdr, args, &hdr);
4303 * Decode SETACL response
4306 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4307 struct nfs_setaclres *res)
4309 struct xdr_stream xdr;
4310 struct compound_hdr hdr;
4313 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4314 status = decode_compound_hdr(&xdr, &hdr);
4317 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4320 status = decode_putfh(&xdr);
4323 status = decode_setattr(&xdr);
4329 * Decode GETACL response
4332 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4333 struct nfs_getaclres *res)
4335 struct xdr_stream xdr;
4336 struct compound_hdr hdr;
4339 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4340 status = decode_compound_hdr(&xdr, &hdr);
4343 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4346 status = decode_putfh(&xdr);
4349 status = decode_getacl(&xdr, rqstp, &res->acl_len);
4356 * Decode CLOSE response
4358 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
4360 struct xdr_stream xdr;
4361 struct compound_hdr hdr;
4364 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4365 status = decode_compound_hdr(&xdr, &hdr);
4368 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4371 status = decode_putfh(&xdr);
4374 status = decode_close(&xdr, res);
4378 * Note: Server may do delete on close for this file
4379 * in which case the getattr call will fail with
4380 * an ESTALE error. Shouldn't be a problem,
4381 * though, since fattr->valid will remain unset.
4383 decode_getfattr(&xdr, res->fattr, res->server);
4389 * Decode OPEN response
4391 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4393 struct xdr_stream xdr;
4394 struct compound_hdr hdr;
4397 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4398 status = decode_compound_hdr(&xdr, &hdr);
4401 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4404 status = decode_putfh(&xdr);
4407 status = decode_savefh(&xdr);
4410 status = decode_open(&xdr, res);
4413 if (decode_getfh(&xdr, &res->fh) != 0)
4415 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4417 if (decode_restorefh(&xdr) != 0)
4419 decode_getfattr(&xdr, res->dir_attr, res->server);
4425 * Decode OPEN_CONFIRM response
4427 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4429 struct xdr_stream xdr;
4430 struct compound_hdr hdr;
4433 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4434 status = decode_compound_hdr(&xdr, &hdr);
4437 status = decode_putfh(&xdr);
4440 status = decode_open_confirm(&xdr, res);
4446 * Decode OPEN response
4448 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4450 struct xdr_stream xdr;
4451 struct compound_hdr hdr;
4454 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4455 status = decode_compound_hdr(&xdr, &hdr);
4458 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4461 status = decode_putfh(&xdr);
4464 status = decode_open(&xdr, res);
4467 decode_getfattr(&xdr, res->f_attr, res->server);
4473 * Decode SETATTR response
4475 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4477 struct xdr_stream xdr;
4478 struct compound_hdr hdr;
4481 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4482 status = decode_compound_hdr(&xdr, &hdr);
4485 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4488 status = decode_putfh(&xdr);
4491 status = decode_setattr(&xdr);
4494 decode_getfattr(&xdr, res->fattr, res->server);
4500 * Decode LOCK response
4502 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4504 struct xdr_stream xdr;
4505 struct compound_hdr hdr;
4508 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4509 status = decode_compound_hdr(&xdr, &hdr);
4512 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4515 status = decode_putfh(&xdr);
4518 status = decode_lock(&xdr, res);
4524 * Decode LOCKT response
4526 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4528 struct xdr_stream xdr;
4529 struct compound_hdr hdr;
4532 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4533 status = decode_compound_hdr(&xdr, &hdr);
4536 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4539 status = decode_putfh(&xdr);
4542 status = decode_lockt(&xdr, res);
4548 * Decode LOCKU response
4550 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4552 struct xdr_stream xdr;
4553 struct compound_hdr hdr;
4556 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4557 status = decode_compound_hdr(&xdr, &hdr);
4560 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4563 status = decode_putfh(&xdr);
4566 status = decode_locku(&xdr, res);
4572 * Decode READLINK response
4574 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4575 struct nfs4_readlink_res *res)
4577 struct xdr_stream xdr;
4578 struct compound_hdr hdr;
4581 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4582 status = decode_compound_hdr(&xdr, &hdr);
4585 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4588 status = decode_putfh(&xdr);
4591 status = decode_readlink(&xdr, rqstp);
4597 * Decode READDIR response
4599 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4601 struct xdr_stream xdr;
4602 struct compound_hdr hdr;
4605 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4606 status = decode_compound_hdr(&xdr, &hdr);
4609 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4612 status = decode_putfh(&xdr);
4615 status = decode_readdir(&xdr, rqstp, res);
4621 * Decode Read response
4623 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4625 struct xdr_stream xdr;
4626 struct compound_hdr hdr;
4629 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4630 status = decode_compound_hdr(&xdr, &hdr);
4633 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4636 status = decode_putfh(&xdr);
4639 status = decode_read(&xdr, rqstp, res);
4641 status = res->count;
4647 * Decode WRITE response
4649 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4651 struct xdr_stream xdr;
4652 struct compound_hdr hdr;
4655 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4656 status = decode_compound_hdr(&xdr, &hdr);
4659 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4662 status = decode_putfh(&xdr);
4665 status = decode_write(&xdr, res);
4668 decode_getfattr(&xdr, res->fattr, res->server);
4670 status = res->count;
4676 * Decode COMMIT response
4678 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
4680 struct xdr_stream xdr;
4681 struct compound_hdr hdr;
4684 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4685 status = decode_compound_hdr(&xdr, &hdr);
4688 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4691 status = decode_putfh(&xdr);
4694 status = decode_commit(&xdr, res);
4697 decode_getfattr(&xdr, res->fattr, res->server);
4705 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
4706 struct nfs4_fsinfo_res *res)
4708 struct xdr_stream xdr;
4709 struct compound_hdr hdr;
4712 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4713 status = decode_compound_hdr(&xdr, &hdr);
4715 status = decode_sequence(&xdr, &res->seq_res, req);
4717 status = decode_putfh(&xdr);
4719 status = decode_fsinfo(&xdr, res->fsinfo);
4726 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
4727 struct nfs4_pathconf_res *res)
4729 struct xdr_stream xdr;
4730 struct compound_hdr hdr;
4733 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4734 status = decode_compound_hdr(&xdr, &hdr);
4736 status = decode_sequence(&xdr, &res->seq_res, req);
4738 status = decode_putfh(&xdr);
4740 status = decode_pathconf(&xdr, res->pathconf);
4747 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
4748 struct nfs4_statfs_res *res)
4750 struct xdr_stream xdr;
4751 struct compound_hdr hdr;
4754 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4755 status = decode_compound_hdr(&xdr, &hdr);
4757 status = decode_sequence(&xdr, &res->seq_res, req);
4759 status = decode_putfh(&xdr);
4761 status = decode_statfs(&xdr, res->fsstat);
4766 * GETATTR_BITMAP request
4768 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
4770 struct xdr_stream xdr;
4771 struct compound_hdr hdr;
4774 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4775 status = decode_compound_hdr(&xdr, &hdr);
4778 status = decode_sequence(&xdr, &res->seq_res, req);
4781 if ((status = decode_putfh(&xdr)) != 0)
4783 status = decode_server_caps(&xdr, res);
4789 * Decode RENEW response
4791 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
4793 struct xdr_stream xdr;
4794 struct compound_hdr hdr;
4797 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4798 status = decode_compound_hdr(&xdr, &hdr);
4800 status = decode_renew(&xdr);
4805 * a SETCLIENTID request
4807 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4808 struct nfs_client *clp)
4810 struct xdr_stream xdr;
4811 struct compound_hdr hdr;
4814 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4815 status = decode_compound_hdr(&xdr, &hdr);
4817 status = decode_setclientid(&xdr, clp);
4822 * a SETCLIENTID_CONFIRM request
4824 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
4826 struct xdr_stream xdr;
4827 struct compound_hdr hdr;
4830 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4831 status = decode_compound_hdr(&xdr, &hdr);
4833 status = decode_setclientid_confirm(&xdr);
4835 status = decode_putrootfh(&xdr);
4837 status = decode_fsinfo(&xdr, fsinfo);
4842 * DELEGRETURN request
4844 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
4846 struct xdr_stream xdr;
4847 struct compound_hdr hdr;
4850 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4851 status = decode_compound_hdr(&xdr, &hdr);
4854 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4857 status = decode_putfh(&xdr);
4860 status = decode_delegreturn(&xdr);
4861 decode_getfattr(&xdr, res->fattr, res->server);
4867 * FS_LOCATIONS request
4869 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
4870 struct nfs4_fs_locations_res *res)
4872 struct xdr_stream xdr;
4873 struct compound_hdr hdr;
4876 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4877 status = decode_compound_hdr(&xdr, &hdr);
4880 status = decode_sequence(&xdr, &res->seq_res, req);
4883 if ((status = decode_putfh(&xdr)) != 0)
4885 if ((status = decode_lookup(&xdr)) != 0)
4887 xdr_enter_page(&xdr, PAGE_SIZE);
4888 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
4889 res->fs_locations->server);
4894 #if defined(CONFIG_NFS_V4_1)
4896 * EXCHANGE_ID request
4898 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
4901 struct xdr_stream xdr;
4902 struct compound_hdr hdr;
4905 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4906 status = decode_compound_hdr(&xdr, &hdr);
4908 status = decode_exchange_id(&xdr, res);
4911 #endif /* CONFIG_NFS_V4_1 */
4913 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
4915 uint32_t bitmap[2] = {0};
4920 return ERR_PTR(-EAGAIN);
4922 return ERR_PTR(-EBADCOOKIE);
4925 entry->prev_cookie = entry->cookie;
4926 p = xdr_decode_hyper(p, &entry->cookie);
4927 entry->len = ntohl(*p++);
4928 entry->name = (const char *) p;
4929 p += XDR_QUADLEN(entry->len);
4932 * In case the server doesn't return an inode number,
4933 * we fake one here. (We don't use inode number 0,
4934 * since glibc seems to choke on it...)
4938 len = ntohl(*p++); /* bitmap length */
4940 bitmap[0] = ntohl(*p++);
4942 bitmap[1] = ntohl(*p++);
4946 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4948 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4949 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4950 /* Ignore the return value of rdattr_error for now */
4954 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4955 xdr_decode_hyper(p, &entry->ino);
4956 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4957 xdr_decode_hyper(p, &entry->ino);
4961 entry->eof = !p[0] && p[1];
4966 * We need to translate between nfs status return values and
4967 * the local errno values which may not be the same.
4974 { NFS4ERR_PERM, -EPERM },
4975 { NFS4ERR_NOENT, -ENOENT },
4976 { NFS4ERR_IO, -errno_NFSERR_IO},
4977 { NFS4ERR_NXIO, -ENXIO },
4978 { NFS4ERR_ACCESS, -EACCES },
4979 { NFS4ERR_EXIST, -EEXIST },
4980 { NFS4ERR_XDEV, -EXDEV },
4981 { NFS4ERR_NOTDIR, -ENOTDIR },
4982 { NFS4ERR_ISDIR, -EISDIR },
4983 { NFS4ERR_INVAL, -EINVAL },
4984 { NFS4ERR_FBIG, -EFBIG },
4985 { NFS4ERR_NOSPC, -ENOSPC },
4986 { NFS4ERR_ROFS, -EROFS },
4987 { NFS4ERR_MLINK, -EMLINK },
4988 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
4989 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
4990 { NFS4ERR_DQUOT, -EDQUOT },
4991 { NFS4ERR_STALE, -ESTALE },
4992 { NFS4ERR_BADHANDLE, -EBADHANDLE },
4993 { NFS4ERR_BADOWNER, -EINVAL },
4994 { NFS4ERR_BADNAME, -EINVAL },
4995 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
4996 { NFS4ERR_NOTSUPP, -ENOTSUPP },
4997 { NFS4ERR_TOOSMALL, -ETOOSMALL },
4998 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
4999 { NFS4ERR_BADTYPE, -EBADTYPE },
5000 { NFS4ERR_LOCKED, -EAGAIN },
5001 { NFS4ERR_RESOURCE, -EREMOTEIO },
5002 { NFS4ERR_SYMLINK, -ELOOP },
5003 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5004 { NFS4ERR_DEADLOCK, -EDEADLK },
5005 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
5006 * to be handled by a
5013 * Convert an NFS error code to a local one.
5014 * This one is used jointly by NFSv2 and NFSv3.
5017 nfs4_stat_to_errno(int stat)
5020 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5021 if (nfs_errtbl[i].stat == stat)
5022 return nfs_errtbl[i].errno;
5024 if (stat <= 10000 || stat > 10100) {
5025 /* The server is looney tunes. */
5026 return -ESERVERFAULT;
5028 /* If we cannot translate the error, the recovery routines should
5030 * Note: remaining NFSv4 error codes have values > 10000, so should
5031 * not conflict with native Linux error codes.
5036 #define PROC(proc, argtype, restype) \
5037 [NFSPROC4_CLNT_##proc] = { \
5038 .p_proc = NFSPROC4_COMPOUND, \
5039 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5040 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
5041 .p_arglen = NFS4_##argtype##_sz, \
5042 .p_replen = NFS4_##restype##_sz, \
5043 .p_statidx = NFSPROC4_CLNT_##proc, \
5047 struct rpc_procinfo nfs4_procedures[] = {
5048 PROC(READ, enc_read, dec_read),
5049 PROC(WRITE, enc_write, dec_write),
5050 PROC(COMMIT, enc_commit, dec_commit),
5051 PROC(OPEN, enc_open, dec_open),
5052 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5053 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5054 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5055 PROC(CLOSE, enc_close, dec_close),
5056 PROC(SETATTR, enc_setattr, dec_setattr),
5057 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5058 PROC(RENEW, enc_renew, dec_renew),
5059 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5060 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5061 PROC(LOCK, enc_lock, dec_lock),
5062 PROC(LOCKT, enc_lockt, dec_lockt),
5063 PROC(LOCKU, enc_locku, dec_locku),
5064 PROC(ACCESS, enc_access, dec_access),
5065 PROC(GETATTR, enc_getattr, dec_getattr),
5066 PROC(LOOKUP, enc_lookup, dec_lookup),
5067 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5068 PROC(REMOVE, enc_remove, dec_remove),
5069 PROC(RENAME, enc_rename, dec_rename),
5070 PROC(LINK, enc_link, dec_link),
5071 PROC(SYMLINK, enc_symlink, dec_symlink),
5072 PROC(CREATE, enc_create, dec_create),
5073 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5074 PROC(STATFS, enc_statfs, dec_statfs),
5075 PROC(READLINK, enc_readlink, dec_readlink),
5076 PROC(READDIR, enc_readdir, dec_readdir),
5077 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5078 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
5079 PROC(GETACL, enc_getacl, dec_getacl),
5080 PROC(SETACL, enc_setacl, dec_setacl),
5081 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
5082 #if defined(CONFIG_NFS_V4_1)
5083 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
5084 #endif /* CONFIG_NFS_V4_1 */
5087 struct rpc_version nfs_version4 = {
5089 .nrprocs = ARRAY_SIZE(nfs4_procedures),
5090 .procs = nfs4_procedures