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 NFS4_MAX_MACHINE_NAME_LEN (64)
251 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
252 encode_verifier_maxsz + \
253 1 /* co_ownerid.len */ + \
254 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
257 0 /* SP4_NONE (for now) */ + \
258 1 /* zero implemetation id array */)
259 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
260 2 /* eir_clientid */ + \
261 1 /* eir_sequenceid */ + \
262 1 /* eir_flags */ + \
264 0 /* SP4_NONE (for now) */ + \
265 2 /* eir_server_owner.so_minor_id */ + \
266 /* eir_server_owner.so_major_id<> */ \
267 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
268 /* eir_server_scope<> */ \
269 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
270 1 /* eir_server_impl_id array length */ + \
271 0 /* ignored eir_server_impl_id contents */)
272 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
273 #define decode_channel_attrs_maxsz (6 + \
274 1 /* ca_rdma_ird.len */ + \
276 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
277 2 /* csa_clientid */ + \
278 1 /* csa_sequence */ + \
279 1 /* csa_flags */ + \
280 encode_channel_attrs_maxsz + \
281 encode_channel_attrs_maxsz + \
282 1 /* csa_cb_program */ + \
283 1 /* csa_sec_parms.len (1) */ + \
284 1 /* cb_secflavor (AUTH_SYS) */ + \
286 1 /* machinename.len */ + \
287 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
290 1 /* gids.len (0) */)
291 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
292 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
293 1 /* csr_sequence */ + \
294 1 /* csr_flags */ + \
295 decode_channel_attrs_maxsz + \
296 decode_channel_attrs_maxsz)
297 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
298 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
299 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
300 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
301 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
302 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
303 #else /* CONFIG_NFS_V4_1 */
304 #define encode_sequence_maxsz 0
305 #define decode_sequence_maxsz 0
306 #endif /* CONFIG_NFS_V4_1 */
308 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
309 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
310 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
311 encode_sequence_maxsz + \
312 encode_putfh_maxsz + \
314 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
315 decode_sequence_maxsz + \
316 decode_putfh_maxsz + \
318 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
319 encode_sequence_maxsz + \
320 encode_putfh_maxsz + \
321 encode_readlink_maxsz)
322 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
323 decode_sequence_maxsz + \
324 decode_putfh_maxsz + \
325 decode_readlink_maxsz)
326 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
327 encode_sequence_maxsz + \
328 encode_putfh_maxsz + \
329 encode_readdir_maxsz)
330 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
331 decode_sequence_maxsz + \
332 decode_putfh_maxsz + \
333 decode_readdir_maxsz)
334 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
335 encode_sequence_maxsz + \
336 encode_putfh_maxsz + \
337 encode_write_maxsz + \
338 encode_getattr_maxsz)
339 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
340 decode_sequence_maxsz + \
341 decode_putfh_maxsz + \
342 decode_write_maxsz + \
343 decode_getattr_maxsz)
344 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
345 encode_sequence_maxsz + \
346 encode_putfh_maxsz + \
347 encode_commit_maxsz + \
348 encode_getattr_maxsz)
349 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
350 decode_sequence_maxsz + \
351 decode_putfh_maxsz + \
352 decode_commit_maxsz + \
353 decode_getattr_maxsz)
354 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
355 encode_sequence_maxsz + \
356 encode_putfh_maxsz + \
357 encode_savefh_maxsz + \
358 encode_open_maxsz + \
359 encode_getfh_maxsz + \
360 encode_getattr_maxsz + \
361 encode_restorefh_maxsz + \
362 encode_getattr_maxsz)
363 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
364 decode_sequence_maxsz + \
365 decode_putfh_maxsz + \
366 decode_savefh_maxsz + \
367 decode_open_maxsz + \
368 decode_getfh_maxsz + \
369 decode_getattr_maxsz + \
370 decode_restorefh_maxsz + \
371 decode_getattr_maxsz)
372 #define NFS4_enc_open_confirm_sz \
373 (compound_encode_hdr_maxsz + \
374 encode_putfh_maxsz + \
375 encode_open_confirm_maxsz)
376 #define NFS4_dec_open_confirm_sz \
377 (compound_decode_hdr_maxsz + \
378 decode_putfh_maxsz + \
379 decode_open_confirm_maxsz)
380 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
381 encode_sequence_maxsz + \
382 encode_putfh_maxsz + \
383 encode_open_maxsz + \
384 encode_getattr_maxsz)
385 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
386 decode_sequence_maxsz + \
387 decode_putfh_maxsz + \
388 decode_open_maxsz + \
389 decode_getattr_maxsz)
390 #define NFS4_enc_open_downgrade_sz \
391 (compound_encode_hdr_maxsz + \
392 encode_sequence_maxsz + \
393 encode_putfh_maxsz + \
394 encode_open_downgrade_maxsz + \
395 encode_getattr_maxsz)
396 #define NFS4_dec_open_downgrade_sz \
397 (compound_decode_hdr_maxsz + \
398 decode_sequence_maxsz + \
399 decode_putfh_maxsz + \
400 decode_open_downgrade_maxsz + \
401 decode_getattr_maxsz)
402 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
403 encode_sequence_maxsz + \
404 encode_putfh_maxsz + \
405 encode_close_maxsz + \
406 encode_getattr_maxsz)
407 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
408 decode_sequence_maxsz + \
409 decode_putfh_maxsz + \
410 decode_close_maxsz + \
411 decode_getattr_maxsz)
412 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
413 encode_sequence_maxsz + \
414 encode_putfh_maxsz + \
415 encode_setattr_maxsz + \
416 encode_getattr_maxsz)
417 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
418 decode_sequence_maxsz + \
419 decode_putfh_maxsz + \
420 decode_setattr_maxsz + \
421 decode_getattr_maxsz)
422 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
423 encode_sequence_maxsz + \
424 encode_putfh_maxsz + \
426 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
427 decode_sequence_maxsz + \
428 decode_putfh_maxsz + \
430 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
432 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
434 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
435 encode_setclientid_maxsz)
436 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
437 decode_setclientid_maxsz)
438 #define NFS4_enc_setclientid_confirm_sz \
439 (compound_encode_hdr_maxsz + \
440 encode_setclientid_confirm_maxsz + \
441 encode_putrootfh_maxsz + \
443 #define NFS4_dec_setclientid_confirm_sz \
444 (compound_decode_hdr_maxsz + \
445 decode_setclientid_confirm_maxsz + \
446 decode_putrootfh_maxsz + \
448 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
449 encode_sequence_maxsz + \
450 encode_putfh_maxsz + \
452 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
453 decode_sequence_maxsz + \
454 decode_putfh_maxsz + \
456 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
457 encode_sequence_maxsz + \
458 encode_putfh_maxsz + \
460 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
461 decode_sequence_maxsz + \
462 decode_putfh_maxsz + \
464 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
465 encode_sequence_maxsz + \
466 encode_putfh_maxsz + \
468 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
469 decode_sequence_maxsz + \
470 decode_putfh_maxsz + \
472 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
473 encode_sequence_maxsz + \
474 encode_putfh_maxsz + \
475 encode_access_maxsz + \
476 encode_getattr_maxsz)
477 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
478 decode_sequence_maxsz + \
479 decode_putfh_maxsz + \
480 decode_access_maxsz + \
481 decode_getattr_maxsz)
482 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
483 encode_sequence_maxsz + \
484 encode_putfh_maxsz + \
485 encode_getattr_maxsz)
486 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
487 decode_sequence_maxsz + \
488 decode_putfh_maxsz + \
489 decode_getattr_maxsz)
490 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
491 encode_sequence_maxsz + \
492 encode_putfh_maxsz + \
493 encode_lookup_maxsz + \
494 encode_getattr_maxsz + \
496 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
497 decode_sequence_maxsz + \
498 decode_putfh_maxsz + \
499 decode_lookup_maxsz + \
500 decode_getattr_maxsz + \
502 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
503 encode_sequence_maxsz + \
504 encode_putrootfh_maxsz + \
505 encode_getattr_maxsz + \
507 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
508 decode_sequence_maxsz + \
509 decode_putrootfh_maxsz + \
510 decode_getattr_maxsz + \
512 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
513 encode_sequence_maxsz + \
514 encode_putfh_maxsz + \
515 encode_remove_maxsz + \
516 encode_getattr_maxsz)
517 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
518 decode_sequence_maxsz + \
519 decode_putfh_maxsz + \
520 decode_remove_maxsz + \
521 decode_getattr_maxsz)
522 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
523 encode_sequence_maxsz + \
524 encode_putfh_maxsz + \
525 encode_savefh_maxsz + \
526 encode_putfh_maxsz + \
527 encode_rename_maxsz + \
528 encode_getattr_maxsz + \
529 encode_restorefh_maxsz + \
530 encode_getattr_maxsz)
531 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
532 decode_sequence_maxsz + \
533 decode_putfh_maxsz + \
534 decode_savefh_maxsz + \
535 decode_putfh_maxsz + \
536 decode_rename_maxsz + \
537 decode_getattr_maxsz + \
538 decode_restorefh_maxsz + \
539 decode_getattr_maxsz)
540 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
541 encode_sequence_maxsz + \
542 encode_putfh_maxsz + \
543 encode_savefh_maxsz + \
544 encode_putfh_maxsz + \
545 encode_link_maxsz + \
546 decode_getattr_maxsz + \
547 encode_restorefh_maxsz + \
548 decode_getattr_maxsz)
549 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
550 decode_sequence_maxsz + \
551 decode_putfh_maxsz + \
552 decode_savefh_maxsz + \
553 decode_putfh_maxsz + \
554 decode_link_maxsz + \
555 decode_getattr_maxsz + \
556 decode_restorefh_maxsz + \
557 decode_getattr_maxsz)
558 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
559 encode_sequence_maxsz + \
560 encode_putfh_maxsz + \
561 encode_symlink_maxsz + \
562 encode_getattr_maxsz + \
564 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
565 decode_sequence_maxsz + \
566 decode_putfh_maxsz + \
567 decode_symlink_maxsz + \
568 decode_getattr_maxsz + \
570 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
571 encode_sequence_maxsz + \
572 encode_putfh_maxsz + \
573 encode_savefh_maxsz + \
574 encode_create_maxsz + \
575 encode_getfh_maxsz + \
576 encode_getattr_maxsz + \
577 encode_restorefh_maxsz + \
578 encode_getattr_maxsz)
579 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
580 decode_sequence_maxsz + \
581 decode_putfh_maxsz + \
582 decode_savefh_maxsz + \
583 decode_create_maxsz + \
584 decode_getfh_maxsz + \
585 decode_getattr_maxsz + \
586 decode_restorefh_maxsz + \
587 decode_getattr_maxsz)
588 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
589 encode_sequence_maxsz + \
590 encode_putfh_maxsz + \
591 encode_getattr_maxsz)
592 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
593 decode_sequence_maxsz + \
594 decode_putfh_maxsz + \
595 decode_getattr_maxsz)
596 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
597 encode_sequence_maxsz + \
598 encode_putfh_maxsz + \
600 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
601 decode_sequence_maxsz + \
602 decode_putfh_maxsz + \
604 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
605 encode_sequence_maxsz + \
606 encode_putfh_maxsz + \
607 encode_getattr_maxsz)
608 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
609 decode_sequence_maxsz + \
610 decode_putfh_maxsz + \
611 decode_getattr_maxsz)
612 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
613 encode_sequence_maxsz + \
614 encode_putfh_maxsz + \
615 encode_delegreturn_maxsz + \
616 encode_getattr_maxsz)
617 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
618 decode_sequence_maxsz + \
619 decode_delegreturn_maxsz + \
620 decode_getattr_maxsz)
621 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
622 encode_sequence_maxsz + \
623 encode_putfh_maxsz + \
625 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
626 decode_sequence_maxsz + \
627 decode_putfh_maxsz + \
629 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
630 encode_sequence_maxsz + \
631 encode_putfh_maxsz + \
633 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
634 decode_sequence_maxsz + \
635 decode_putfh_maxsz + \
637 #define NFS4_enc_fs_locations_sz \
638 (compound_encode_hdr_maxsz + \
639 encode_sequence_maxsz + \
640 encode_putfh_maxsz + \
641 encode_lookup_maxsz + \
642 encode_fs_locations_maxsz)
643 #define NFS4_dec_fs_locations_sz \
644 (compound_decode_hdr_maxsz + \
645 decode_sequence_maxsz + \
646 decode_putfh_maxsz + \
647 decode_lookup_maxsz + \
648 decode_fs_locations_maxsz)
649 #if defined(CONFIG_NFS_V4_1)
650 #define NFS4_enc_exchange_id_sz \
651 (compound_encode_hdr_maxsz + \
652 encode_exchange_id_maxsz)
653 #define NFS4_dec_exchange_id_sz \
654 (compound_decode_hdr_maxsz + \
655 decode_exchange_id_maxsz)
656 #define NFS4_enc_create_session_sz \
657 (compound_encode_hdr_maxsz + \
658 encode_create_session_maxsz)
659 #define NFS4_dec_create_session_sz \
660 (compound_decode_hdr_maxsz + \
661 decode_create_session_maxsz)
662 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
663 encode_destroy_session_maxsz)
664 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
665 decode_destroy_session_maxsz)
666 #define NFS4_enc_sequence_sz \
667 (compound_decode_hdr_maxsz + \
668 encode_sequence_maxsz)
669 #define NFS4_dec_sequence_sz \
670 (compound_decode_hdr_maxsz + \
671 decode_sequence_maxsz)
672 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
673 encode_sequence_maxsz + \
674 encode_putrootfh_maxsz + \
676 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
677 decode_sequence_maxsz + \
678 decode_putrootfh_maxsz + \
680 #endif /* CONFIG_NFS_V4_1 */
682 static const umode_t nfs_type2fmt[] = {
689 [NF4SOCK] = S_IFSOCK,
695 struct compound_hdr {
701 uint32_t replen; /* expected reply words */
706 * START OF "GENERIC" ENCODE ROUTINES.
707 * These may look a little ugly since they are imported from a "generic"
708 * set of XDR encode/decode routines which are intended to be shared by
709 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
711 * If the pain of reading these is too great, it should be a straightforward
712 * task to translate them into Linux-specific versions which are more
713 * consistent with the style used in NFSv2/v3...
715 #define WRITE32(n) *p++ = htonl(n)
716 #define WRITE64(n) do { \
717 *p++ = htonl((uint32_t)((n) >> 32)); \
718 *p++ = htonl((uint32_t)(n)); \
720 #define WRITEMEM(ptr,nbytes) do { \
721 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
724 #define RESERVE_SPACE(nbytes) do { \
725 p = xdr_reserve_space(xdr, nbytes); \
729 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
733 p = xdr_reserve_space(xdr, 4 + len);
735 xdr_encode_opaque(p, str, len);
738 static void encode_compound_hdr(struct xdr_stream *xdr,
739 struct rpc_rqst *req,
740 struct compound_hdr *hdr)
743 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
745 /* initialize running count of expected bytes in reply.
746 * NOTE: the replied tag SHOULD be the same is the one sent,
747 * but this is not required as a MUST for the server to do so. */
748 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
750 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
751 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
752 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
753 WRITE32(hdr->taglen);
754 WRITEMEM(hdr->tag, hdr->taglen);
755 WRITE32(hdr->minorversion);
760 static void encode_nops(struct compound_hdr *hdr)
762 BUG_ON(hdr->nops > NFS4_MAX_OPS);
763 *hdr->nops_p = htonl(hdr->nops);
766 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
770 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
772 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
775 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
777 char owner_name[IDMAP_NAMESZ];
778 char owner_group[IDMAP_NAMESZ];
779 int owner_namelen = 0;
780 int owner_grouplen = 0;
788 * We reserve enough space to write the entire attribute buffer at once.
789 * In the worst-case, this would be
790 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
791 * = 36 bytes, plus any contribution from variable-length fields
792 * such as owner/group.
797 if (iap->ia_valid & ATTR_SIZE)
799 if (iap->ia_valid & ATTR_MODE)
801 if (iap->ia_valid & ATTR_UID) {
802 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
803 if (owner_namelen < 0) {
804 dprintk("nfs: couldn't resolve uid %d to string\n",
807 strcpy(owner_name, "nobody");
808 owner_namelen = sizeof("nobody") - 1;
811 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
813 if (iap->ia_valid & ATTR_GID) {
814 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
815 if (owner_grouplen < 0) {
816 dprintk("nfs: couldn't resolve gid %d to string\n",
818 strcpy(owner_group, "nobody");
819 owner_grouplen = sizeof("nobody") - 1;
822 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
824 if (iap->ia_valid & ATTR_ATIME_SET)
826 else if (iap->ia_valid & ATTR_ATIME)
828 if (iap->ia_valid & ATTR_MTIME_SET)
830 else if (iap->ia_valid & ATTR_MTIME)
835 * We write the bitmap length now, but leave the bitmap and the attribute
836 * buffer length to be backfilled at the end of this routine.
842 if (iap->ia_valid & ATTR_SIZE) {
843 bmval0 |= FATTR4_WORD0_SIZE;
844 WRITE64(iap->ia_size);
846 if (iap->ia_valid & ATTR_MODE) {
847 bmval1 |= FATTR4_WORD1_MODE;
848 WRITE32(iap->ia_mode & S_IALLUGO);
850 if (iap->ia_valid & ATTR_UID) {
851 bmval1 |= FATTR4_WORD1_OWNER;
852 WRITE32(owner_namelen);
853 WRITEMEM(owner_name, owner_namelen);
855 if (iap->ia_valid & ATTR_GID) {
856 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
857 WRITE32(owner_grouplen);
858 WRITEMEM(owner_group, owner_grouplen);
860 if (iap->ia_valid & ATTR_ATIME_SET) {
861 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
862 WRITE32(NFS4_SET_TO_CLIENT_TIME);
864 WRITE32(iap->ia_mtime.tv_sec);
865 WRITE32(iap->ia_mtime.tv_nsec);
867 else if (iap->ia_valid & ATTR_ATIME) {
868 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
869 WRITE32(NFS4_SET_TO_SERVER_TIME);
871 if (iap->ia_valid & ATTR_MTIME_SET) {
872 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
873 WRITE32(NFS4_SET_TO_CLIENT_TIME);
875 WRITE32(iap->ia_mtime.tv_sec);
876 WRITE32(iap->ia_mtime.tv_nsec);
878 else if (iap->ia_valid & ATTR_MTIME) {
879 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
880 WRITE32(NFS4_SET_TO_SERVER_TIME);
884 * Now we backfill the bitmap and the attribute buffer length.
886 if (len != ((char *)p - (char *)q) + 4) {
887 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
888 len, ((char *)p - (char *)q) + 4);
891 len = (char *)p - (char *)q - 12;
892 *q++ = htonl(bmval0);
893 *q++ = htonl(bmval1);
899 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
907 hdr->replen += decode_access_maxsz;
910 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
914 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
916 WRITE32(arg->seqid->sequence->counter);
917 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
919 hdr->replen += decode_close_maxsz;
922 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
928 WRITE64(args->offset);
929 WRITE32(args->count);
931 hdr->replen += decode_commit_maxsz;
934 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
940 WRITE32(create->ftype);
942 switch (create->ftype) {
945 WRITE32(create->u.symlink.len);
946 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
949 case NF4BLK: case NF4CHR:
951 WRITE32(create->u.device.specdata1);
952 WRITE32(create->u.device.specdata2);
959 RESERVE_SPACE(4 + create->name->len);
960 WRITE32(create->name->len);
961 WRITEMEM(create->name->name, create->name->len);
963 hdr->replen += decode_create_maxsz;
965 encode_attrs(xdr, create->attrs, create->server);
968 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
977 hdr->replen += decode_getattr_maxsz;
980 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
990 hdr->replen += decode_getattr_maxsz;
993 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
995 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
996 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
999 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1001 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1002 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
1005 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1007 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1008 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1011 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1018 hdr->replen += decode_getfh_maxsz;
1021 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1025 RESERVE_SPACE(8 + name->len);
1028 WRITEMEM(name->name, name->len);
1030 hdr->replen += decode_link_maxsz;
1033 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1035 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1036 return block ? NFS4_READW_LT : NFS4_READ_LT;
1037 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1040 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1042 if (fl->fl_end == OFFSET_MAX)
1043 return ~(uint64_t)0;
1044 return fl->fl_end - fl->fl_start + 1;
1048 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1049 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1051 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1057 WRITE32(nfs4_lock_type(args->fl, args->block));
1058 WRITE32(args->reclaim);
1059 WRITE64(args->fl->fl_start);
1060 WRITE64(nfs4_lock_length(args->fl));
1061 WRITE32(args->new_lock_owner);
1062 if (args->new_lock_owner){
1063 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
1064 WRITE32(args->open_seqid->sequence->counter);
1065 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
1066 WRITE32(args->lock_seqid->sequence->counter);
1067 WRITE64(args->lock_owner.clientid);
1069 WRITEMEM("lock id:", 8);
1070 WRITE64(args->lock_owner.id);
1073 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
1074 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
1075 WRITE32(args->lock_seqid->sequence->counter);
1078 hdr->replen += decode_lock_maxsz;
1081 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1087 WRITE32(nfs4_lock_type(args->fl, 0));
1088 WRITE64(args->fl->fl_start);
1089 WRITE64(nfs4_lock_length(args->fl));
1090 WRITE64(args->lock_owner.clientid);
1092 WRITEMEM("lock id:", 8);
1093 WRITE64(args->lock_owner.id);
1095 hdr->replen += decode_lockt_maxsz;
1098 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1102 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
1104 WRITE32(nfs4_lock_type(args->fl, 0));
1105 WRITE32(args->seqid->sequence->counter);
1106 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
1107 WRITE64(args->fl->fl_start);
1108 WRITE64(nfs4_lock_length(args->fl));
1110 hdr->replen += decode_locku_maxsz;
1113 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1115 int len = name->len;
1118 RESERVE_SPACE(8 + len);
1121 WRITEMEM(name->name, len);
1123 hdr->replen += decode_lookup_maxsz;
1126 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1131 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1133 WRITE32(NFS4_SHARE_ACCESS_READ);
1136 WRITE32(NFS4_SHARE_ACCESS_WRITE);
1138 case FMODE_READ|FMODE_WRITE:
1139 WRITE32(NFS4_SHARE_ACCESS_BOTH);
1144 WRITE32(0); /* for linux, share_deny = 0 always */
1147 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1151 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1156 WRITE32(arg->seqid->sequence->counter);
1157 encode_share_access(xdr, arg->fmode);
1159 WRITE64(arg->clientid);
1161 WRITEMEM("open id:", 8);
1165 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1170 switch(arg->open_flags & O_EXCL) {
1172 WRITE32(NFS4_CREATE_UNCHECKED);
1173 encode_attrs(xdr, arg->u.attrs, arg->server);
1176 WRITE32(NFS4_CREATE_EXCLUSIVE);
1177 encode_nfs4_verifier(xdr, &arg->u.verifier);
1181 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1186 switch (arg->open_flags & O_CREAT) {
1188 WRITE32(NFS4_OPEN_NOCREATE);
1191 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1192 WRITE32(NFS4_OPEN_CREATE);
1193 encode_createmode(xdr, arg);
1197 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1202 switch (delegation_type) {
1204 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1207 WRITE32(NFS4_OPEN_DELEGATE_READ);
1209 case FMODE_WRITE|FMODE_READ:
1210 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1217 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1222 WRITE32(NFS4_OPEN_CLAIM_NULL);
1223 encode_string(xdr, name->len, name->name);
1226 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1231 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1232 encode_delegation_type(xdr, type);
1235 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1239 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1240 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1241 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1242 encode_string(xdr, name->len, name->name);
1245 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1247 encode_openhdr(xdr, arg);
1248 encode_opentype(xdr, arg);
1249 switch (arg->claim) {
1250 case NFS4_OPEN_CLAIM_NULL:
1251 encode_claim_null(xdr, arg->name);
1253 case NFS4_OPEN_CLAIM_PREVIOUS:
1254 encode_claim_previous(xdr, arg->u.delegation_type);
1256 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1257 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1263 hdr->replen += decode_open_maxsz;
1266 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1270 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1271 WRITE32(OP_OPEN_CONFIRM);
1272 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1273 WRITE32(arg->seqid->sequence->counter);
1275 hdr->replen += decode_open_confirm_maxsz;
1278 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1282 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
1283 WRITE32(OP_OPEN_DOWNGRADE);
1284 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
1285 WRITE32(arg->seqid->sequence->counter);
1286 encode_share_access(xdr, arg->fmode);
1288 hdr->replen += decode_open_downgrade_maxsz;
1292 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1297 RESERVE_SPACE(8 + len);
1300 WRITEMEM(fh->data, len);
1302 hdr->replen += decode_putfh_maxsz;
1305 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1310 WRITE32(OP_PUTROOTFH);
1312 hdr->replen += decode_putrootfh_maxsz;
1315 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1317 nfs4_stateid stateid;
1320 RESERVE_SPACE(NFS4_STATEID_SIZE);
1321 if (ctx->state != NULL) {
1322 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1323 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
1325 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1328 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1335 encode_stateid(xdr, args->context);
1338 WRITE64(args->offset);
1339 WRITE32(args->count);
1341 hdr->replen += decode_read_maxsz;
1344 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1346 uint32_t attrs[2] = {
1347 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1348 FATTR4_WORD1_MOUNTED_ON_FILEID,
1352 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
1353 WRITE32(OP_READDIR);
1354 WRITE64(readdir->cookie);
1355 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
1356 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1357 WRITE32(readdir->count);
1359 /* Switch to mounted_on_fileid if the server supports it */
1360 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1361 attrs[0] &= ~FATTR4_WORD0_FILEID;
1363 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1364 WRITE32(attrs[0] & readdir->bitmask[0]);
1365 WRITE32(attrs[1] & readdir->bitmask[1]);
1367 hdr->replen += decode_readdir_maxsz;
1368 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1370 (unsigned long long)readdir->cookie,
1371 ((u32 *)readdir->verifier.data)[0],
1372 ((u32 *)readdir->verifier.data)[1],
1373 attrs[0] & readdir->bitmask[0],
1374 attrs[1] & readdir->bitmask[1]);
1377 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1382 WRITE32(OP_READLINK);
1384 hdr->replen += decode_readlink_maxsz;
1387 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1391 RESERVE_SPACE(8 + name->len);
1394 WRITEMEM(name->name, name->len);
1396 hdr->replen += decode_remove_maxsz;
1399 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1403 RESERVE_SPACE(8 + oldname->len);
1405 WRITE32(oldname->len);
1406 WRITEMEM(oldname->name, oldname->len);
1408 RESERVE_SPACE(4 + newname->len);
1409 WRITE32(newname->len);
1410 WRITEMEM(newname->name, newname->len);
1412 hdr->replen += decode_rename_maxsz;
1415 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1421 WRITE64(client_stateid->cl_clientid);
1423 hdr->replen += decode_renew_maxsz;
1427 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1432 WRITE32(OP_RESTOREFH);
1434 hdr->replen += decode_restorefh_maxsz;
1438 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1442 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1443 WRITE32(OP_SETATTR);
1444 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
1447 WRITE32(FATTR4_WORD0_ACL);
1448 if (arg->acl_len % 4)
1451 WRITE32(arg->acl_len);
1452 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1454 hdr->replen += decode_setacl_maxsz;
1459 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1466 hdr->replen += decode_savefh_maxsz;
1469 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1473 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1474 WRITE32(OP_SETATTR);
1475 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
1477 hdr->replen += decode_setattr_maxsz;
1478 encode_attrs(xdr, arg->iap, server);
1481 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1485 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
1486 WRITE32(OP_SETCLIENTID);
1487 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1489 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1491 WRITE32(setclientid->sc_prog);
1492 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1493 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1495 WRITE32(setclientid->sc_cb_ident);
1497 hdr->replen += decode_setclientid_maxsz;
1500 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
1504 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1505 WRITE32(OP_SETCLIENTID_CONFIRM);
1506 WRITE64(client_state->cl_clientid);
1507 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
1509 hdr->replen += decode_setclientid_confirm_maxsz;
1512 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1519 encode_stateid(xdr, args->context);
1522 WRITE64(args->offset);
1523 WRITE32(args->stable);
1524 WRITE32(args->count);
1526 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1528 hdr->replen += decode_write_maxsz;
1531 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1535 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1537 WRITE32(OP_DELEGRETURN);
1538 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
1540 hdr->replen += decode_delegreturn_maxsz;
1543 #if defined(CONFIG_NFS_V4_1)
1544 /* NFSv4.1 operations */
1545 static void encode_exchange_id(struct xdr_stream *xdr,
1546 struct nfs41_exchange_id_args *args,
1547 struct compound_hdr *hdr)
1551 RESERVE_SPACE(4 + sizeof(args->verifier->data));
1552 WRITE32(OP_EXCHANGE_ID);
1553 WRITEMEM(args->verifier->data, sizeof(args->verifier->data));
1555 encode_string(xdr, args->id_len, args->id);
1558 WRITE32(args->flags);
1559 WRITE32(0); /* zero length state_protect4_a */
1560 WRITE32(0); /* zero length implementation id array */
1562 hdr->replen += decode_exchange_id_maxsz;
1565 static void encode_create_session(struct xdr_stream *xdr,
1566 struct nfs41_create_session_args *args,
1567 struct compound_hdr *hdr)
1570 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1572 struct nfs_client *clp = args->client;
1575 WRITE32(OP_CREATE_SESSION);
1578 WRITE64(clp->cl_ex_clid);
1581 WRITE32(clp->cl_seqid); /*Sequence id */
1582 WRITE32(args->flags); /*flags */
1584 RESERVE_SPACE(2*28); /* 2 channel_attrs */
1586 WRITE32(args->fc_attrs.headerpadsz); /* header padding size */
1587 WRITE32(args->fc_attrs.max_rqst_sz); /* max req size */
1588 WRITE32(args->fc_attrs.max_resp_sz); /* max resp size */
1589 WRITE32(args->fc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1590 WRITE32(args->fc_attrs.max_ops); /* max operations */
1591 WRITE32(args->fc_attrs.max_reqs); /* max requests */
1592 WRITE32(0); /* rdmachannel_attrs */
1595 WRITE32(args->fc_attrs.headerpadsz); /* header padding size */
1596 WRITE32(args->bc_attrs.max_rqst_sz); /* max req size */
1597 WRITE32(args->bc_attrs.max_resp_sz); /* max resp size */
1598 WRITE32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1599 WRITE32(args->bc_attrs.max_ops); /* max operations */
1600 WRITE32(args->bc_attrs.max_reqs); /* max requests */
1601 WRITE32(0); /* rdmachannel_attrs */
1604 WRITE32(args->cb_program); /* cb_program */
1606 RESERVE_SPACE(4); /* # of security flavors */
1610 WRITE32(RPC_AUTH_UNIX); /* auth_sys */
1612 /* authsys_parms rfc1831 */
1614 WRITE32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
1615 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1617 RESERVE_SPACE(16 + len);
1619 WRITEMEM(machine_name, len);
1620 WRITE32(0); /* UID */
1621 WRITE32(0); /* GID */
1622 WRITE32(0); /* No more gids */
1624 hdr->replen += decode_create_session_maxsz;
1627 static void encode_destroy_session(struct xdr_stream *xdr,
1628 struct nfs4_session *session,
1629 struct compound_hdr *hdr)
1632 RESERVE_SPACE(4 + NFS4_MAX_SESSIONID_LEN);
1633 WRITE32(OP_DESTROY_SESSION);
1634 WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1636 hdr->replen += decode_destroy_session_maxsz;
1638 #endif /* CONFIG_NFS_V4_1 */
1640 static void encode_sequence(struct xdr_stream *xdr,
1641 const struct nfs4_sequence_args *args,
1642 struct compound_hdr *hdr)
1644 #if defined(CONFIG_NFS_V4_1)
1645 struct nfs4_session *session = args->sa_session;
1646 struct nfs4_slot_table *tp;
1647 struct nfs4_slot *slot;
1653 tp = &session->fc_slot_table;
1655 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1656 slot = tp->slots + args->sa_slotid;
1659 WRITE32(OP_SEQUENCE);
1662 * Sessionid + seqid + slotid + max slotid + cache_this
1664 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1665 "max_slotid=%d cache_this=%d\n",
1667 ((u32 *)session->sess_id.data)[0],
1668 ((u32 *)session->sess_id.data)[1],
1669 ((u32 *)session->sess_id.data)[2],
1670 ((u32 *)session->sess_id.data)[3],
1671 slot->seq_nr, args->sa_slotid,
1672 tp->highest_used_slotid, args->sa_cache_this);
1673 RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 16);
1674 WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1675 WRITE32(slot->seq_nr);
1676 WRITE32(args->sa_slotid);
1677 WRITE32(tp->highest_used_slotid);
1678 WRITE32(args->sa_cache_this);
1680 hdr->replen += decode_sequence_maxsz;
1681 #endif /* CONFIG_NFS_V4_1 */
1685 * END OF "GENERIC" ENCODE ROUTINES.
1688 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1690 #if defined(CONFIG_NFS_V4_1)
1691 if (args->sa_session)
1692 return args->sa_session->clp->cl_minorversion;
1693 #endif /* CONFIG_NFS_V4_1 */
1698 * Encode an ACCESS request
1700 static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
1702 struct xdr_stream xdr;
1703 struct compound_hdr hdr = {
1704 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1707 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1708 encode_compound_hdr(&xdr, req, &hdr);
1709 encode_sequence(&xdr, &args->seq_args, &hdr);
1710 encode_putfh(&xdr, args->fh, &hdr);
1711 encode_access(&xdr, args->access, &hdr);
1712 encode_getfattr(&xdr, args->bitmask, &hdr);
1718 * Encode LOOKUP request
1720 static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
1722 struct xdr_stream xdr;
1723 struct compound_hdr hdr = {
1724 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1727 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1728 encode_compound_hdr(&xdr, req, &hdr);
1729 encode_sequence(&xdr, &args->seq_args, &hdr);
1730 encode_putfh(&xdr, args->dir_fh, &hdr);
1731 encode_lookup(&xdr, args->name, &hdr);
1732 encode_getfh(&xdr, &hdr);
1733 encode_getfattr(&xdr, args->bitmask, &hdr);
1739 * Encode LOOKUP_ROOT request
1741 static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
1743 struct xdr_stream xdr;
1744 struct compound_hdr hdr = {
1745 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1748 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1749 encode_compound_hdr(&xdr, req, &hdr);
1750 encode_sequence(&xdr, &args->seq_args, &hdr);
1751 encode_putrootfh(&xdr, &hdr);
1752 encode_getfh(&xdr, &hdr);
1753 encode_getfattr(&xdr, args->bitmask, &hdr);
1759 * Encode REMOVE request
1761 static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
1763 struct xdr_stream xdr;
1764 struct compound_hdr hdr = {
1765 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1768 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1769 encode_compound_hdr(&xdr, req, &hdr);
1770 encode_sequence(&xdr, &args->seq_args, &hdr);
1771 encode_putfh(&xdr, args->fh, &hdr);
1772 encode_remove(&xdr, &args->name, &hdr);
1773 encode_getfattr(&xdr, args->bitmask, &hdr);
1779 * Encode RENAME request
1781 static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
1783 struct xdr_stream xdr;
1784 struct compound_hdr hdr = {
1785 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1788 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1789 encode_compound_hdr(&xdr, req, &hdr);
1790 encode_sequence(&xdr, &args->seq_args, &hdr);
1791 encode_putfh(&xdr, args->old_dir, &hdr);
1792 encode_savefh(&xdr, &hdr);
1793 encode_putfh(&xdr, args->new_dir, &hdr);
1794 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1795 encode_getfattr(&xdr, args->bitmask, &hdr);
1796 encode_restorefh(&xdr, &hdr);
1797 encode_getfattr(&xdr, args->bitmask, &hdr);
1803 * Encode LINK request
1805 static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
1807 struct xdr_stream xdr;
1808 struct compound_hdr hdr = {
1809 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1812 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1813 encode_compound_hdr(&xdr, req, &hdr);
1814 encode_sequence(&xdr, &args->seq_args, &hdr);
1815 encode_putfh(&xdr, args->fh, &hdr);
1816 encode_savefh(&xdr, &hdr);
1817 encode_putfh(&xdr, args->dir_fh, &hdr);
1818 encode_link(&xdr, args->name, &hdr);
1819 encode_getfattr(&xdr, args->bitmask, &hdr);
1820 encode_restorefh(&xdr, &hdr);
1821 encode_getfattr(&xdr, args->bitmask, &hdr);
1827 * Encode CREATE request
1829 static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1831 struct xdr_stream xdr;
1832 struct compound_hdr hdr = {
1833 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1836 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1837 encode_compound_hdr(&xdr, req, &hdr);
1838 encode_sequence(&xdr, &args->seq_args, &hdr);
1839 encode_putfh(&xdr, args->dir_fh, &hdr);
1840 encode_savefh(&xdr, &hdr);
1841 encode_create(&xdr, args, &hdr);
1842 encode_getfh(&xdr, &hdr);
1843 encode_getfattr(&xdr, args->bitmask, &hdr);
1844 encode_restorefh(&xdr, &hdr);
1845 encode_getfattr(&xdr, args->bitmask, &hdr);
1851 * Encode SYMLINK request
1853 static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
1855 return nfs4_xdr_enc_create(req, p, args);
1859 * Encode GETATTR request
1861 static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
1863 struct xdr_stream xdr;
1864 struct compound_hdr hdr = {
1865 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1868 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1869 encode_compound_hdr(&xdr, req, &hdr);
1870 encode_sequence(&xdr, &args->seq_args, &hdr);
1871 encode_putfh(&xdr, args->fh, &hdr);
1872 encode_getfattr(&xdr, args->bitmask, &hdr);
1878 * Encode a CLOSE request
1880 static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1882 struct xdr_stream xdr;
1883 struct compound_hdr hdr = {
1884 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1887 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1888 encode_compound_hdr(&xdr, req, &hdr);
1889 encode_sequence(&xdr, &args->seq_args, &hdr);
1890 encode_putfh(&xdr, args->fh, &hdr);
1891 encode_close(&xdr, args, &hdr);
1892 encode_getfattr(&xdr, args->bitmask, &hdr);
1898 * Encode an OPEN request
1900 static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1902 struct xdr_stream xdr;
1903 struct compound_hdr hdr = {
1904 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1907 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1908 encode_compound_hdr(&xdr, req, &hdr);
1909 encode_sequence(&xdr, &args->seq_args, &hdr);
1910 encode_putfh(&xdr, args->fh, &hdr);
1911 encode_savefh(&xdr, &hdr);
1912 encode_open(&xdr, args, &hdr);
1913 encode_getfh(&xdr, &hdr);
1914 encode_getfattr(&xdr, args->bitmask, &hdr);
1915 encode_restorefh(&xdr, &hdr);
1916 encode_getfattr(&xdr, args->bitmask, &hdr);
1922 * Encode an OPEN_CONFIRM request
1924 static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
1926 struct xdr_stream xdr;
1927 struct compound_hdr hdr = {
1931 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1932 encode_compound_hdr(&xdr, req, &hdr);
1933 encode_putfh(&xdr, args->fh, &hdr);
1934 encode_open_confirm(&xdr, args, &hdr);
1940 * Encode an OPEN request with no attributes.
1942 static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
1944 struct xdr_stream xdr;
1945 struct compound_hdr hdr = {
1946 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1949 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1950 encode_compound_hdr(&xdr, req, &hdr);
1951 encode_sequence(&xdr, &args->seq_args, &hdr);
1952 encode_putfh(&xdr, args->fh, &hdr);
1953 encode_open(&xdr, args, &hdr);
1954 encode_getfattr(&xdr, args->bitmask, &hdr);
1960 * Encode an OPEN_DOWNGRADE request
1962 static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
1964 struct xdr_stream xdr;
1965 struct compound_hdr hdr = {
1966 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1969 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1970 encode_compound_hdr(&xdr, req, &hdr);
1971 encode_sequence(&xdr, &args->seq_args, &hdr);
1972 encode_putfh(&xdr, args->fh, &hdr);
1973 encode_open_downgrade(&xdr, args, &hdr);
1974 encode_getfattr(&xdr, args->bitmask, &hdr);
1980 * Encode a LOCK request
1982 static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
1984 struct xdr_stream xdr;
1985 struct compound_hdr hdr = {
1986 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1989 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1990 encode_compound_hdr(&xdr, req, &hdr);
1991 encode_sequence(&xdr, &args->seq_args, &hdr);
1992 encode_putfh(&xdr, args->fh, &hdr);
1993 encode_lock(&xdr, args, &hdr);
1999 * Encode a LOCKT request
2001 static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
2003 struct xdr_stream xdr;
2004 struct compound_hdr hdr = {
2005 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2008 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2009 encode_compound_hdr(&xdr, req, &hdr);
2010 encode_sequence(&xdr, &args->seq_args, &hdr);
2011 encode_putfh(&xdr, args->fh, &hdr);
2012 encode_lockt(&xdr, args, &hdr);
2018 * Encode a LOCKU request
2020 static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
2022 struct xdr_stream xdr;
2023 struct compound_hdr hdr = {
2024 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2027 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2028 encode_compound_hdr(&xdr, req, &hdr);
2029 encode_sequence(&xdr, &args->seq_args, &hdr);
2030 encode_putfh(&xdr, args->fh, &hdr);
2031 encode_locku(&xdr, args, &hdr);
2037 * Encode a READLINK request
2039 static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
2041 struct xdr_stream xdr;
2042 struct compound_hdr hdr = {
2043 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2046 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2047 encode_compound_hdr(&xdr, req, &hdr);
2048 encode_sequence(&xdr, &args->seq_args, &hdr);
2049 encode_putfh(&xdr, args->fh, &hdr);
2050 encode_readlink(&xdr, args, req, &hdr);
2052 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2053 args->pgbase, args->pglen);
2059 * Encode a READDIR request
2061 static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
2063 struct xdr_stream xdr;
2064 struct compound_hdr hdr = {
2065 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2068 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2069 encode_compound_hdr(&xdr, req, &hdr);
2070 encode_sequence(&xdr, &args->seq_args, &hdr);
2071 encode_putfh(&xdr, args->fh, &hdr);
2072 encode_readdir(&xdr, args, req, &hdr);
2074 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2075 args->pgbase, args->count);
2076 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2077 __func__, hdr.replen << 2, args->pages,
2078 args->pgbase, args->count);
2084 * Encode a READ request
2086 static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
2088 struct xdr_stream xdr;
2089 struct compound_hdr hdr = {
2090 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2093 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2094 encode_compound_hdr(&xdr, req, &hdr);
2095 encode_sequence(&xdr, &args->seq_args, &hdr);
2096 encode_putfh(&xdr, args->fh, &hdr);
2097 encode_read(&xdr, args, &hdr);
2099 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2100 args->pages, args->pgbase, args->count);
2101 req->rq_rcv_buf.flags |= XDRBUF_READ;
2107 * Encode an SETATTR request
2109 static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
2111 struct xdr_stream xdr;
2112 struct compound_hdr hdr = {
2113 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2116 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2117 encode_compound_hdr(&xdr, req, &hdr);
2118 encode_sequence(&xdr, &args->seq_args, &hdr);
2119 encode_putfh(&xdr, args->fh, &hdr);
2120 encode_setattr(&xdr, args, args->server, &hdr);
2121 encode_getfattr(&xdr, args->bitmask, &hdr);
2127 * Encode a GETACL request
2130 nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
2131 struct nfs_getaclargs *args)
2133 struct xdr_stream xdr;
2134 struct compound_hdr hdr = {
2135 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2139 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2140 encode_compound_hdr(&xdr, req, &hdr);
2141 encode_sequence(&xdr, &args->seq_args, &hdr);
2142 encode_putfh(&xdr, args->fh, &hdr);
2143 replen = hdr.replen + nfs4_fattr_bitmap_maxsz + 1;
2144 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
2146 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2147 args->acl_pages, args->acl_pgbase, args->acl_len);
2153 * Encode a WRITE request
2155 static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
2157 struct xdr_stream xdr;
2158 struct compound_hdr hdr = {
2159 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2162 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2163 encode_compound_hdr(&xdr, req, &hdr);
2164 encode_sequence(&xdr, &args->seq_args, &hdr);
2165 encode_putfh(&xdr, args->fh, &hdr);
2166 encode_write(&xdr, args, &hdr);
2167 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2168 encode_getfattr(&xdr, args->bitmask, &hdr);
2176 static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
2178 struct xdr_stream xdr;
2179 struct compound_hdr hdr = {
2180 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2183 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2184 encode_compound_hdr(&xdr, req, &hdr);
2185 encode_sequence(&xdr, &args->seq_args, &hdr);
2186 encode_putfh(&xdr, args->fh, &hdr);
2187 encode_commit(&xdr, args, &hdr);
2188 encode_getfattr(&xdr, args->bitmask, &hdr);
2196 static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
2198 struct xdr_stream xdr;
2199 struct compound_hdr hdr = {
2200 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2203 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2204 encode_compound_hdr(&xdr, req, &hdr);
2205 encode_sequence(&xdr, &args->seq_args, &hdr);
2206 encode_putfh(&xdr, args->fh, &hdr);
2207 encode_fsinfo(&xdr, args->bitmask, &hdr);
2213 * a PATHCONF request
2215 static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
2217 struct xdr_stream xdr;
2218 struct compound_hdr hdr = {
2219 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2222 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2223 encode_compound_hdr(&xdr, req, &hdr);
2224 encode_sequence(&xdr, &args->seq_args, &hdr);
2225 encode_putfh(&xdr, args->fh, &hdr);
2226 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2235 static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
2237 struct xdr_stream xdr;
2238 struct compound_hdr hdr = {
2239 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2242 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2243 encode_compound_hdr(&xdr, req, &hdr);
2244 encode_sequence(&xdr, &args->seq_args, &hdr);
2245 encode_putfh(&xdr, args->fh, &hdr);
2246 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2247 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2253 * GETATTR_BITMAP request
2255 static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
2256 struct nfs4_server_caps_arg *args)
2258 struct xdr_stream xdr;
2259 struct compound_hdr hdr = {
2260 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2263 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2264 encode_compound_hdr(&xdr, req, &hdr);
2265 encode_sequence(&xdr, &args->seq_args, &hdr);
2266 encode_putfh(&xdr, args->fhandle, &hdr);
2267 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2268 FATTR4_WORD0_LINK_SUPPORT|
2269 FATTR4_WORD0_SYMLINK_SUPPORT|
2270 FATTR4_WORD0_ACLSUPPORT, &hdr);
2278 static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2280 struct xdr_stream xdr;
2281 struct compound_hdr hdr = {
2285 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2286 encode_compound_hdr(&xdr, req, &hdr);
2287 encode_renew(&xdr, clp, &hdr);
2293 * a SETCLIENTID request
2295 static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
2297 struct xdr_stream xdr;
2298 struct compound_hdr hdr = {
2302 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2303 encode_compound_hdr(&xdr, req, &hdr);
2304 encode_setclientid(&xdr, sc, &hdr);
2310 * a SETCLIENTID_CONFIRM request
2312 static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
2314 struct xdr_stream xdr;
2315 struct compound_hdr hdr = {
2318 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2320 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2321 encode_compound_hdr(&xdr, req, &hdr);
2322 encode_setclientid_confirm(&xdr, clp, &hdr);
2323 encode_putrootfh(&xdr, &hdr);
2324 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2330 * DELEGRETURN request
2332 static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
2334 struct xdr_stream xdr;
2335 struct compound_hdr hdr = {
2336 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2339 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2340 encode_compound_hdr(&xdr, req, &hdr);
2341 encode_sequence(&xdr, &args->seq_args, &hdr);
2342 encode_putfh(&xdr, args->fhandle, &hdr);
2343 encode_delegreturn(&xdr, args->stateid, &hdr);
2344 encode_getfattr(&xdr, args->bitmask, &hdr);
2350 * Encode FS_LOCATIONS request
2352 static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
2354 struct xdr_stream xdr;
2355 struct compound_hdr hdr = {
2356 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2360 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2361 encode_compound_hdr(&xdr, req, &hdr);
2362 encode_sequence(&xdr, &args->seq_args, &hdr);
2363 encode_putfh(&xdr, args->dir_fh, &hdr);
2364 encode_lookup(&xdr, args->name, &hdr);
2365 replen = hdr.replen; /* get the attribute into args->page */
2366 encode_fs_locations(&xdr, args->bitmask, &hdr);
2368 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2374 #if defined(CONFIG_NFS_V4_1)
2376 * EXCHANGE_ID request
2378 static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p,
2379 struct nfs41_exchange_id_args *args)
2381 struct xdr_stream xdr;
2382 struct compound_hdr hdr = {
2383 .minorversion = args->client->cl_minorversion,
2386 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2387 encode_compound_hdr(&xdr, req, &hdr);
2388 encode_exchange_id(&xdr, args, &hdr);
2394 * a CREATE_SESSION request
2396 static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p,
2397 struct nfs41_create_session_args *args)
2399 struct xdr_stream xdr;
2400 struct compound_hdr hdr = {
2401 .minorversion = args->client->cl_minorversion,
2404 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2405 encode_compound_hdr(&xdr, req, &hdr);
2406 encode_create_session(&xdr, args, &hdr);
2412 * a DESTROY_SESSION request
2414 static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p,
2415 struct nfs4_session *session)
2417 struct xdr_stream xdr;
2418 struct compound_hdr hdr = {
2419 .minorversion = session->clp->cl_minorversion,
2422 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2423 encode_compound_hdr(&xdr, req, &hdr);
2424 encode_destroy_session(&xdr, session, &hdr);
2430 * a SEQUENCE request
2432 static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p,
2433 struct nfs4_sequence_args *args)
2435 struct xdr_stream xdr;
2436 struct compound_hdr hdr = {
2437 .minorversion = nfs4_xdr_minorversion(args),
2440 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2441 encode_compound_hdr(&xdr, req, &hdr);
2442 encode_sequence(&xdr, args, &hdr);
2448 * a GET_LEASE_TIME request
2450 static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
2451 struct nfs4_get_lease_time_args *args)
2453 struct xdr_stream xdr;
2454 struct compound_hdr hdr = {
2455 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2457 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2459 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2460 encode_compound_hdr(&xdr, req, &hdr);
2461 encode_sequence(&xdr, &args->la_seq_args, &hdr);
2462 encode_putrootfh(&xdr, &hdr);
2463 encode_fsinfo(&xdr, lease_bitmap, &hdr);
2467 #endif /* CONFIG_NFS_V4_1 */
2470 * START OF "GENERIC" DECODE ROUTINES.
2471 * These may look a little ugly since they are imported from a "generic"
2472 * set of XDR encode/decode routines which are intended to be shared by
2473 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2475 * If the pain of reading these is too great, it should be a straightforward
2476 * task to translate them into Linux-specific versions which are more
2477 * consistent with the style used in NFSv2/v3...
2479 #define READ32(x) (x) = ntohl(*p++)
2480 #define READ64(x) do { \
2481 (x) = (u64)ntohl(*p++) << 32; \
2482 (x) |= ntohl(*p++); \
2484 #define READTIME(x) do { \
2486 (x.tv_sec) = ntohl(*p++); \
2487 (x.tv_nsec) = ntohl(*p++); \
2489 #define COPYMEM(x,nbytes) do { \
2490 memcpy((x), p, nbytes); \
2491 p += XDR_QUADLEN(nbytes); \
2494 #define READ_BUF(nbytes) do { \
2495 p = xdr_inline_decode(xdr, nbytes); \
2496 if (unlikely(!p)) { \
2497 dprintk("nfs: %s: prematurely hit end of receive" \
2498 " buffer\n", __func__); \
2499 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
2500 __func__, xdr->p, nbytes, xdr->end); \
2505 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2512 *string = (char *)p;
2516 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2521 READ32(hdr->status);
2522 READ32(hdr->taglen);
2524 READ_BUF(hdr->taglen + 4);
2525 hdr->tag = (char *)p;
2526 p += XDR_QUADLEN(hdr->taglen);
2528 if (unlikely(hdr->nops < 1))
2529 return nfs4_stat_to_errno(hdr->status);
2533 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2541 if (opnum != expected) {
2542 dprintk("nfs: Server returned operation"
2543 " %d but we issued a request for %d\n",
2548 if (nfserr != NFS_OK)
2549 return nfs4_stat_to_errno(nfserr);
2554 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2557 unsigned int strlen;
2561 return decode_opaque_inline(xdr, &strlen, &str);
2564 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2572 bitmap[0] = bitmap[1] = 0;
2573 READ_BUF((bmlen << 2));
2582 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2592 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2594 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2595 decode_attr_bitmap(xdr, bitmask);
2596 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2598 bitmask[0] = bitmask[1] = 0;
2599 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
2603 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2609 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2611 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2614 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2615 dprintk("%s: bad type %d\n", __func__, *type);
2618 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2619 ret = NFS_ATTR_FATTR_TYPE;
2621 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
2625 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2631 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2633 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2636 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2637 ret = NFS_ATTR_FATTR_CHANGE;
2639 dprintk("%s: change attribute=%Lu\n", __func__,
2640 (unsigned long long)*change);
2644 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2650 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2652 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2655 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2656 ret = NFS_ATTR_FATTR_SIZE;
2658 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
2662 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2667 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2669 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2672 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2674 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
2678 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2683 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2685 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2688 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2690 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
2694 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2701 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2703 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2705 READ64(fsid->major);
2706 READ64(fsid->minor);
2707 bitmap[0] &= ~FATTR4_WORD0_FSID;
2708 ret = NFS_ATTR_FATTR_FSID;
2710 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
2711 (unsigned long long)fsid->major,
2712 (unsigned long long)fsid->minor);
2716 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2721 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2723 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2726 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2728 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
2732 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2736 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2737 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2739 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2742 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2744 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
2748 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2754 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2756 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2759 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2760 ret = NFS_ATTR_FATTR_FILEID;
2762 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2766 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2772 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2774 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2777 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2778 ret = NFS_ATTR_FATTR_FILEID;
2780 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
2784 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2790 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2792 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2795 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2797 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
2801 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2807 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2809 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2812 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2814 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
2818 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2824 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2826 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2829 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2831 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
2835 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2846 path->ncomponents = 0;
2847 while (path->ncomponents < n) {
2848 struct nfs4_string *component = &path->components[path->ncomponents];
2849 status = decode_opaque_inline(xdr, &component->len, &component->data);
2850 if (unlikely(status != 0))
2852 if (path->ncomponents != n)
2854 dprintk("%s", component->data);
2855 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2856 path->ncomponents++;
2858 dprintk("cannot parse %d components in path\n", n);
2866 /* a root pathname is sent as a zero component4 */
2867 path->ncomponents = 1;
2868 path->components[0].len=0;
2869 path->components[0].data=NULL;
2870 dprintk("path /\n");
2873 dprintk(" status %d", status);
2878 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
2884 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2887 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2889 dprintk("%s: fsroot ", __func__);
2890 status = decode_pathname(xdr, &res->fs_path);
2891 if (unlikely(status != 0))
2897 res->nlocations = 0;
2898 while (res->nlocations < n) {
2900 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
2906 dprintk("%s: servers ", __func__);
2907 while (loc->nservers < m) {
2908 struct nfs4_string *server = &loc->servers[loc->nservers];
2909 status = decode_opaque_inline(xdr, &server->len, &server->data);
2910 if (unlikely(status != 0))
2912 dprintk("%s ", server->data);
2913 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2917 dprintk("%s: using first %u of %u servers "
2918 "returned for location %u\n",
2920 NFS4_FS_LOCATION_MAXSERVERS,
2921 m, res->nlocations);
2922 for (i = loc->nservers; i < m; i++) {
2925 status = decode_opaque_inline(xdr, &len, &data);
2926 if (unlikely(status != 0))
2931 status = decode_pathname(xdr, &loc->rootpath);
2932 if (unlikely(status != 0))
2934 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
2937 if (res->nlocations != 0)
2938 status = NFS_ATTR_FATTR_V4_REFERRAL;
2940 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
2947 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2953 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2955 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2958 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2960 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
2964 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2970 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2972 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2975 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2977 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
2981 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2987 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2989 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2992 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2994 dprintk("%s: maxname=%u\n", __func__, *maxname);
2998 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3004 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3006 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3010 if (maxread > 0x7FFFFFFF)
3011 maxread = 0x7FFFFFFF;
3012 *res = (uint32_t)maxread;
3013 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3015 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3019 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3025 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3027 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3031 if (maxwrite > 0x7FFFFFFF)
3032 maxwrite = 0x7FFFFFFF;
3033 *res = (uint32_t)maxwrite;
3034 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3036 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3040 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3047 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3049 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3052 *mode = tmp & ~S_IFMT;
3053 bitmap[1] &= ~FATTR4_WORD1_MODE;
3054 ret = NFS_ATTR_FATTR_MODE;
3056 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3060 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3066 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3068 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3071 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3072 ret = NFS_ATTR_FATTR_NLINK;
3074 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3078 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3079 struct nfs_client *clp, uint32_t *uid, int may_sleep)
3086 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3088 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3094 } else if (len < XDR_MAX_NETOBJ) {
3095 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3096 ret = NFS_ATTR_FATTR_OWNER;
3098 dprintk("%s: nfs_map_name_to_uid failed!\n",
3101 dprintk("%s: name too long (%u)!\n",
3103 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3105 dprintk("%s: uid=%d\n", __func__, (int)*uid);
3109 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3110 struct nfs_client *clp, uint32_t *gid, int may_sleep)
3117 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3119 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3125 } else if (len < XDR_MAX_NETOBJ) {
3126 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3127 ret = NFS_ATTR_FATTR_GROUP;
3129 dprintk("%s: nfs_map_group_to_gid failed!\n",
3132 dprintk("%s: name too long (%u)!\n",
3134 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3136 dprintk("%s: gid=%d\n", __func__, (int)*gid);
3140 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3142 uint32_t major = 0, minor = 0;
3147 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3149 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3155 tmp = MKDEV(major, minor);
3156 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3158 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3159 ret = NFS_ATTR_FATTR_RDEV;
3161 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3165 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3171 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3173 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3176 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3178 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3182 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3188 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3190 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3193 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3195 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3199 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3205 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3207 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3210 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3212 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
3216 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3222 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3224 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3227 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
3228 ret = NFS_ATTR_FATTR_SPACE_USED;
3230 dprintk("%s: space used=%Lu\n", __func__,
3231 (unsigned long long)*used);
3235 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3244 time->tv_sec = (time_t)sec;
3245 time->tv_nsec = (long)nsec;
3249 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3255 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3257 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3258 status = decode_attr_time(xdr, time);
3260 status = NFS_ATTR_FATTR_ATIME;
3261 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3263 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
3267 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3273 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3275 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3276 status = decode_attr_time(xdr, time);
3278 status = NFS_ATTR_FATTR_CTIME;
3279 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3281 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
3285 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3291 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3293 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3294 status = decode_attr_time(xdr, time);
3296 status = NFS_ATTR_FATTR_MTIME;
3297 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3299 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
3303 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
3305 unsigned int attrwords = XDR_QUADLEN(attrlen);
3306 unsigned int nwords = xdr->p - savep;
3308 if (unlikely(attrwords != nwords)) {
3309 dprintk("%s: server returned incorrect attribute length: "
3313 (attrwords < nwords) ? '<' : '>',
3320 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3325 READ32(cinfo->atomic);
3326 READ64(cinfo->before);
3327 READ64(cinfo->after);
3331 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3337 status = decode_op_hdr(xdr, OP_ACCESS);
3343 access->supported = supp;
3344 access->access = acc;
3348 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3353 status = decode_op_hdr(xdr, OP_CLOSE);
3355 nfs_increment_open_seqid(status, res->seqid);
3358 READ_BUF(NFS4_STATEID_SIZE);
3359 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3363 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3368 status = decode_op_hdr(xdr, OP_COMMIT);
3372 COPYMEM(res->verf->verifier, 8);
3376 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3382 status = decode_op_hdr(xdr, OP_CREATE);
3385 if ((status = decode_change_info(xdr, cinfo)))
3389 READ_BUF(bmlen << 2);
3393 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3396 uint32_t attrlen, bitmap[2] = {0};
3399 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3401 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3403 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3405 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3407 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3409 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3411 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3413 status = verify_attr_len(xdr, savep, attrlen);
3415 dprintk("%s: xdr returned %d!\n", __func__, -status);
3419 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3422 uint32_t attrlen, bitmap[2] = {0};
3425 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3427 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3429 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3432 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3434 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3436 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3438 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3440 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3442 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3445 status = verify_attr_len(xdr, savep, attrlen);
3447 dprintk("%s: xdr returned %d!\n", __func__, -status);
3451 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3454 uint32_t attrlen, bitmap[2] = {0};
3457 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3459 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3461 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3464 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3466 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3469 status = verify_attr_len(xdr, savep, attrlen);
3471 dprintk("%s: xdr returned %d!\n", __func__, -status);
3475 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3476 const struct nfs_server *server, int may_sleep)
3486 status = decode_op_hdr(xdr, OP_GETATTR);
3490 status = decode_attr_bitmap(xdr, bitmap);
3494 status = decode_attr_length(xdr, &attrlen, &savep);
3499 status = decode_attr_type(xdr, bitmap, &type);
3504 fattr->mode |= nfs_type2fmt[type];
3505 fattr->valid |= status;
3508 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3511 fattr->valid |= status;
3513 status = decode_attr_size(xdr, bitmap, &fattr->size);
3516 fattr->valid |= status;
3518 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3521 fattr->valid |= status;
3523 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3526 fattr->valid |= status;
3528 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
3529 struct nfs4_fs_locations,
3533 fattr->valid |= status;
3535 status = decode_attr_mode(xdr, bitmap, &fmode);
3539 fattr->mode |= fmode;
3540 fattr->valid |= status;
3543 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3546 fattr->valid |= status;
3548 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3549 &fattr->uid, may_sleep);
3552 fattr->valid |= status;
3554 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3555 &fattr->gid, may_sleep);
3558 fattr->valid |= status;
3560 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3563 fattr->valid |= status;
3565 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3568 fattr->valid |= status;
3570 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3573 fattr->valid |= status;
3575 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3578 fattr->valid |= status;
3580 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3583 fattr->valid |= status;
3585 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3588 if (status != 0 && !(fattr->valid & status)) {
3589 fattr->fileid = fileid;
3590 fattr->valid |= status;
3593 status = verify_attr_len(xdr, savep, attrlen);
3595 dprintk("%s: xdr returned %d\n", __func__, -status);
3600 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3603 uint32_t attrlen, bitmap[2];
3606 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3608 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3610 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3613 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3615 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3617 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3619 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3621 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3622 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3624 fsinfo->wtpref = fsinfo->wtmax;
3626 status = verify_attr_len(xdr, savep, attrlen);
3628 dprintk("%s: xdr returned %d!\n", __func__, -status);
3632 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3638 /* Zero handle first to allow comparisons */
3639 memset(fh, 0, sizeof(*fh));
3641 status = decode_op_hdr(xdr, OP_GETFH);
3647 if (len > NFS4_FHSIZE)
3651 COPYMEM(fh->data, len);
3655 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3659 status = decode_op_hdr(xdr, OP_LINK);
3662 return decode_change_info(xdr, cinfo);
3666 * We create the owner, so we know a proper owner.id length is 4.
3668 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
3670 uint64_t offset, length, clientid;
3672 uint32_t namelen, type;
3679 fl->fl_start = (loff_t)offset;
3680 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3681 if (length == ~(uint64_t)0)
3682 fl->fl_end = OFFSET_MAX;
3683 fl->fl_type = F_WRLCK;
3685 fl->fl_type = F_RDLCK;
3691 return -NFS4ERR_DENIED;
3694 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3699 status = decode_op_hdr(xdr, OP_LOCK);
3703 READ_BUF(NFS4_STATEID_SIZE);
3704 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3705 } else if (status == -NFS4ERR_DENIED)
3706 status = decode_lock_denied(xdr, NULL);
3707 if (res->open_seqid != NULL)
3708 nfs_increment_open_seqid(status, res->open_seqid);
3709 nfs_increment_lock_seqid(status, res->lock_seqid);
3714 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
3717 status = decode_op_hdr(xdr, OP_LOCKT);
3718 if (status == -NFS4ERR_DENIED)
3719 return decode_lock_denied(xdr, res->denied);
3723 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3728 status = decode_op_hdr(xdr, OP_LOCKU);
3730 nfs_increment_lock_seqid(status, res->seqid);
3732 READ_BUF(NFS4_STATEID_SIZE);
3733 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3738 static int decode_lookup(struct xdr_stream *xdr)
3740 return decode_op_hdr(xdr, OP_LOOKUP);
3743 /* This is too sick! */
3744 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3747 uint32_t limit_type, nblocks, blocksize;
3751 switch (limit_type) {
3758 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3763 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3766 uint32_t delegation_type;
3769 READ32(delegation_type);
3770 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3771 res->delegation_type = 0;
3774 READ_BUF(NFS4_STATEID_SIZE+4);
3775 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
3776 READ32(res->do_recall);
3778 switch (delegation_type) {
3779 case NFS4_OPEN_DELEGATE_READ:
3780 res->delegation_type = FMODE_READ;
3782 case NFS4_OPEN_DELEGATE_WRITE:
3783 res->delegation_type = FMODE_WRITE|FMODE_READ;
3784 if (decode_space_limit(xdr, &res->maxsize) < 0)
3787 return decode_ace(xdr, NULL, res->server->nfs_client);
3790 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3793 uint32_t savewords, bmlen, i;
3796 status = decode_op_hdr(xdr, OP_OPEN);
3798 nfs_increment_open_seqid(status, res->seqid);
3801 READ_BUF(NFS4_STATEID_SIZE);
3802 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3804 decode_change_info(xdr, &res->cinfo);
3807 READ32(res->rflags);
3812 READ_BUF(bmlen << 2);
3813 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3814 for (i = 0; i < savewords; ++i)
3815 READ32(res->attrset[i]);
3816 for (; i < NFS4_BITMAP_SIZE; i++)
3817 res->attrset[i] = 0;
3819 return decode_delegation(xdr, res);
3821 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
3825 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3830 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3832 nfs_increment_open_seqid(status, res->seqid);
3835 READ_BUF(NFS4_STATEID_SIZE);
3836 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3840 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3845 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3847 nfs_increment_open_seqid(status, res->seqid);
3850 READ_BUF(NFS4_STATEID_SIZE);
3851 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3855 static int decode_putfh(struct xdr_stream *xdr)
3857 return decode_op_hdr(xdr, OP_PUTFH);
3860 static int decode_putrootfh(struct xdr_stream *xdr)
3862 return decode_op_hdr(xdr, OP_PUTROOTFH);
3865 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3867 struct kvec *iov = req->rq_rcv_buf.head;
3869 uint32_t count, eof, recvd, hdrlen;
3872 status = decode_op_hdr(xdr, OP_READ);
3878 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3879 recvd = req->rq_rcv_buf.len - hdrlen;
3880 if (count > recvd) {
3881 dprintk("NFS: server cheating in read reply: "
3882 "count %u > recvd %u\n", count, recvd);
3886 xdr_read_pages(xdr, count);
3892 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3894 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3895 struct page *page = *rcvbuf->pages;
3896 struct kvec *iov = rcvbuf->head;
3898 u32 recvd, pglen = rcvbuf->page_len;
3899 __be32 *end, *entry, *p, *kaddr;
3900 unsigned int nr = 0;
3903 status = decode_op_hdr(xdr, OP_READDIR);
3907 COPYMEM(readdir->verifier.data, 8);
3908 dprintk("%s: verifier = %08x:%08x\n",
3910 ((u32 *)readdir->verifier.data)[0],
3911 ((u32 *)readdir->verifier.data)[1]);
3914 hdrlen = (char *) p - (char *) iov->iov_base;
3915 recvd = rcvbuf->len - hdrlen;
3918 xdr_read_pages(xdr, pglen);
3920 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
3921 kaddr = p = kmap_atomic(page, KM_USER0);
3922 end = p + ((pglen + readdir->pgbase) >> 2);
3925 /* Make sure the packet actually has a value_follows and EOF entry */
3926 if ((entry + 1) > end)
3929 for (; *p++; nr++) {
3930 u32 len, attrlen, xlen;
3933 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
3934 p += 2; /* cookie */
3935 len = ntohl(*p++); /* filename length */
3936 if (len > NFS4_MAXNAMLEN) {
3937 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3941 xlen = XDR_QUADLEN(len);
3942 if (end - p < xlen + 1)
3944 dprintk("filename = %*s\n", len, (char *)p);
3946 len = ntohl(*p++); /* bitmap length */
3947 if (end - p < len + 1)
3950 attrlen = XDR_QUADLEN(ntohl(*p++));
3951 if (end - p < attrlen + 2)
3953 p += attrlen; /* attributes */
3957 * Apparently some server sends responses that are a valid size, but
3958 * contain no entries, and have value_follows==0 and EOF==0. For
3959 * those, just set the EOF marker.
3961 if (!nr && entry[1] == 0) {
3962 dprintk("NFS: readdir reply truncated!\n");
3966 kunmap_atomic(kaddr, KM_USER0);
3970 * When we get a short packet there are 2 possibilities. We can
3971 * return an error, or fix up the response to look like a valid
3972 * response and return what we have so far. If there are no
3973 * entries and the packet was short, then return -EIO. If there
3974 * are valid entries in the response, return them and pretend that
3975 * the call was successful, but incomplete. The caller can retry the
3976 * readdir starting at the last cookie.
3978 dprintk("%s: short packet at entry %d\n", __func__, nr);
3979 entry[0] = entry[1] = 0;
3983 kunmap_atomic(kaddr, KM_USER0);
3984 return -errno_NFSERR_IO;
3987 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3989 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3990 struct kvec *iov = rcvbuf->head;
3997 status = decode_op_hdr(xdr, OP_READLINK);
4001 /* Convert length of symlink */
4004 if (len >= rcvbuf->page_len || len <= 0) {
4005 dprintk("nfs: server returned giant symlink!\n");
4006 return -ENAMETOOLONG;
4008 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4009 recvd = req->rq_rcv_buf.len - hdrlen;
4011 dprintk("NFS: server cheating in readlink reply: "
4012 "count %u > recvd %u\n", len, recvd);
4015 xdr_read_pages(xdr, len);
4017 * The XDR encode routine has set things up so that
4018 * the link text will be copied directly into the
4019 * buffer. We just have to do overflow-checking,
4020 * and and null-terminate the text (the VFS expects
4021 * null-termination).
4023 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
4024 kaddr[len+rcvbuf->page_base] = '\0';
4025 kunmap_atomic(kaddr, KM_USER0);
4029 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4033 status = decode_op_hdr(xdr, OP_REMOVE);
4036 status = decode_change_info(xdr, cinfo);
4041 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4042 struct nfs4_change_info *new_cinfo)
4046 status = decode_op_hdr(xdr, OP_RENAME);
4049 if ((status = decode_change_info(xdr, old_cinfo)))
4051 status = decode_change_info(xdr, new_cinfo);
4056 static int decode_renew(struct xdr_stream *xdr)
4058 return decode_op_hdr(xdr, OP_RENEW);
4062 decode_restorefh(struct xdr_stream *xdr)
4064 return decode_op_hdr(xdr, OP_RESTOREFH);
4067 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4073 struct kvec *iov = req->rq_rcv_buf.head;
4077 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4079 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4081 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4084 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4086 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
4090 /* We ignore &savep and don't do consistency checks on
4091 * the attr length. Let userspace figure it out.... */
4092 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4093 recvd = req->rq_rcv_buf.len - hdrlen;
4094 if (attrlen > recvd) {
4095 dprintk("NFS: server cheating in getattr"
4096 " acl reply: attrlen %u > recvd %u\n",
4100 xdr_read_pages(xdr, attrlen);
4103 status = -EOPNOTSUPP;
4110 decode_savefh(struct xdr_stream *xdr)
4112 return decode_op_hdr(xdr, OP_SAVEFH);
4115 static int decode_setattr(struct xdr_stream *xdr)
4121 status = decode_op_hdr(xdr, OP_SETATTR);
4126 READ_BUF(bmlen << 2);
4130 static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
4138 if (opnum != OP_SETCLIENTID) {
4139 dprintk("nfs: decode_setclientid: Server returned operation"
4144 if (nfserr == NFS_OK) {
4145 READ_BUF(8 + NFS4_VERIFIER_SIZE);
4146 READ64(clp->cl_clientid);
4147 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
4148 } else if (nfserr == NFSERR_CLID_INUSE) {
4151 /* skip netid string */
4156 /* skip uaddr string */
4160 return -NFSERR_CLID_INUSE;
4162 return nfs4_stat_to_errno(nfserr);
4167 static int decode_setclientid_confirm(struct xdr_stream *xdr)
4169 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4172 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4177 status = decode_op_hdr(xdr, OP_WRITE);
4183 READ32(res->verf->committed);
4184 COPYMEM(res->verf->verifier, 8);
4188 static int decode_delegreturn(struct xdr_stream *xdr)
4190 return decode_op_hdr(xdr, OP_DELEGRETURN);
4193 #if defined(CONFIG_NFS_V4_1)
4194 static int decode_exchange_id(struct xdr_stream *xdr,
4195 struct nfs41_exchange_id_res *res)
4200 struct nfs_client *clp = res->client;
4202 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4207 READ64(clp->cl_ex_clid);
4209 READ32(clp->cl_seqid);
4210 READ32(clp->cl_exchange_flags);
4212 /* We ask for SP4_NONE */
4214 if (dummy != SP4_NONE)
4217 /* Throw away minor_id */
4220 /* Throw away Major id */
4225 /* Throw away server_scope */
4230 /* Throw away Implementation id array */
4238 static int decode_chan_attrs(struct xdr_stream *xdr,
4239 struct nfs4_channel_attrs *attrs)
4245 READ32(attrs->headerpadsz);
4246 READ32(attrs->max_rqst_sz);
4247 READ32(attrs->max_resp_sz);
4248 READ32(attrs->max_resp_sz_cached);
4249 READ32(attrs->max_ops);
4250 READ32(attrs->max_reqs);
4252 if (unlikely(nr_attrs > 1)) {
4253 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4254 __func__, nr_attrs);
4258 READ_BUF(4); /* skip rdma_attrs */
4262 static int decode_create_session(struct xdr_stream *xdr,
4263 struct nfs41_create_session_res *res)
4267 struct nfs_client *clp = res->client;
4268 struct nfs4_session *session = clp->cl_session;
4270 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
4276 READ_BUF(NFS4_MAX_SESSIONID_LEN);
4277 COPYMEM(&session->sess_id, NFS4_MAX_SESSIONID_LEN);
4281 READ32(clp->cl_seqid);
4282 READ32(session->flags);
4284 /* Channel attributes */
4285 status = decode_chan_attrs(xdr, &session->fc_attrs);
4287 status = decode_chan_attrs(xdr, &session->bc_attrs);
4291 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4293 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4295 #endif /* CONFIG_NFS_V4_1 */
4297 static int decode_sequence(struct xdr_stream *xdr,
4298 struct nfs4_sequence_res *res,
4299 struct rpc_rqst *rqstp)
4301 #if defined(CONFIG_NFS_V4_1)
4302 struct nfs4_slot *slot;
4303 struct nfs4_sessionid id;
4308 if (!res->sr_session)
4311 status = decode_op_hdr(xdr, OP_SEQUENCE);
4316 * If the server returns different values for sessionID, slotID or
4317 * sequence number, the server is looney tunes.
4319 status = -ESERVERFAULT;
4321 slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid];
4322 READ_BUF(NFS4_MAX_SESSIONID_LEN + 20);
4323 COPYMEM(id.data, NFS4_MAX_SESSIONID_LEN);
4324 if (memcmp(id.data, res->sr_session->sess_id.data,
4325 NFS4_MAX_SESSIONID_LEN)) {
4326 dprintk("%s Invalid session id\n", __func__);
4331 if (dummy != slot->seq_nr) {
4332 dprintk("%s Invalid sequence number\n", __func__);
4337 if (dummy != res->sr_slotid) {
4338 dprintk("%s Invalid slot id\n", __func__);
4341 /* highest slot id - currently not processed */
4343 /* target highest slot id - currently not processed */
4345 /* result flags - currently not processed */
4349 res->sr_status = status;
4351 #else /* CONFIG_NFS_V4_1 */
4353 #endif /* CONFIG_NFS_V4_1 */
4357 * END OF "GENERIC" DECODE ROUTINES.
4361 * Decode OPEN_DOWNGRADE response
4363 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
4365 struct xdr_stream xdr;
4366 struct compound_hdr hdr;
4369 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4370 status = decode_compound_hdr(&xdr, &hdr);
4373 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4376 status = decode_putfh(&xdr);
4379 status = decode_open_downgrade(&xdr, res);
4382 decode_getfattr(&xdr, res->fattr, res->server,
4383 !RPC_IS_ASYNC(rqstp->rq_task));
4389 * Decode ACCESS response
4391 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *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_access(&xdr, res);
4410 decode_getfattr(&xdr, res->fattr, res->server,
4411 !RPC_IS_ASYNC(rqstp->rq_task));
4417 * Decode LOOKUP response
4419 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
4421 struct xdr_stream xdr;
4422 struct compound_hdr hdr;
4425 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4426 status = decode_compound_hdr(&xdr, &hdr);
4429 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4432 if ((status = decode_putfh(&xdr)) != 0)
4434 if ((status = decode_lookup(&xdr)) != 0)
4436 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4438 status = decode_getfattr(&xdr, res->fattr, res->server
4439 ,!RPC_IS_ASYNC(rqstp->rq_task));
4445 * Decode LOOKUP_ROOT response
4447 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
4449 struct xdr_stream xdr;
4450 struct compound_hdr hdr;
4453 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4454 status = decode_compound_hdr(&xdr, &hdr);
4457 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4460 if ((status = decode_putrootfh(&xdr)) != 0)
4462 if ((status = decode_getfh(&xdr, res->fh)) == 0)
4463 status = decode_getfattr(&xdr, res->fattr, res->server,
4464 !RPC_IS_ASYNC(rqstp->rq_task));
4470 * Decode REMOVE response
4472 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
4474 struct xdr_stream xdr;
4475 struct compound_hdr hdr;
4478 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4479 status = decode_compound_hdr(&xdr, &hdr);
4482 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4485 if ((status = decode_putfh(&xdr)) != 0)
4487 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
4489 decode_getfattr(&xdr, &res->dir_attr, res->server,
4490 !RPC_IS_ASYNC(rqstp->rq_task));
4496 * Decode RENAME response
4498 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
4500 struct xdr_stream xdr;
4501 struct compound_hdr hdr;
4504 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4505 status = decode_compound_hdr(&xdr, &hdr);
4508 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4511 if ((status = decode_putfh(&xdr)) != 0)
4513 if ((status = decode_savefh(&xdr)) != 0)
4515 if ((status = decode_putfh(&xdr)) != 0)
4517 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
4519 /* Current FH is target directory */
4520 if (decode_getfattr(&xdr, res->new_fattr, res->server,
4521 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
4523 if ((status = decode_restorefh(&xdr)) != 0)
4525 decode_getfattr(&xdr, res->old_fattr, res->server,
4526 !RPC_IS_ASYNC(rqstp->rq_task));
4532 * Decode LINK response
4534 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
4536 struct xdr_stream xdr;
4537 struct compound_hdr hdr;
4540 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4541 status = decode_compound_hdr(&xdr, &hdr);
4544 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4547 if ((status = decode_putfh(&xdr)) != 0)
4549 if ((status = decode_savefh(&xdr)) != 0)
4551 if ((status = decode_putfh(&xdr)) != 0)
4553 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
4556 * Note order: OP_LINK leaves the directory as the current
4559 if (decode_getfattr(&xdr, res->dir_attr, res->server,
4560 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
4562 if ((status = decode_restorefh(&xdr)) != 0)
4564 decode_getfattr(&xdr, res->fattr, res->server,
4565 !RPC_IS_ASYNC(rqstp->rq_task));
4571 * Decode CREATE response
4573 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
4575 struct xdr_stream xdr;
4576 struct compound_hdr hdr;
4579 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4580 status = decode_compound_hdr(&xdr, &hdr);
4583 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4586 if ((status = decode_putfh(&xdr)) != 0)
4588 if ((status = decode_savefh(&xdr)) != 0)
4590 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
4592 if ((status = decode_getfh(&xdr, res->fh)) != 0)
4594 if (decode_getfattr(&xdr, res->fattr, res->server,
4595 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
4597 if ((status = decode_restorefh(&xdr)) != 0)
4599 decode_getfattr(&xdr, res->dir_fattr, res->server,
4600 !RPC_IS_ASYNC(rqstp->rq_task));
4606 * Decode SYMLINK response
4608 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
4610 return nfs4_xdr_dec_create(rqstp, p, res);
4614 * Decode GETATTR response
4616 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
4618 struct xdr_stream xdr;
4619 struct compound_hdr hdr;
4622 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4623 status = decode_compound_hdr(&xdr, &hdr);
4626 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4629 status = decode_putfh(&xdr);
4632 status = decode_getfattr(&xdr, res->fattr, res->server,
4633 !RPC_IS_ASYNC(rqstp->rq_task));
4639 * Encode an SETACL request
4642 nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
4644 struct xdr_stream xdr;
4645 struct compound_hdr hdr = {
4646 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
4650 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
4651 encode_compound_hdr(&xdr, req, &hdr);
4652 encode_sequence(&xdr, &args->seq_args, &hdr);
4653 encode_putfh(&xdr, args->fh, &hdr);
4654 status = encode_setacl(&xdr, args, &hdr);
4660 * Decode SETACL response
4663 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4664 struct nfs_setaclres *res)
4666 struct xdr_stream xdr;
4667 struct compound_hdr hdr;
4670 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4671 status = decode_compound_hdr(&xdr, &hdr);
4674 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4677 status = decode_putfh(&xdr);
4680 status = decode_setattr(&xdr);
4686 * Decode GETACL response
4689 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4690 struct nfs_getaclres *res)
4692 struct xdr_stream xdr;
4693 struct compound_hdr hdr;
4696 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4697 status = decode_compound_hdr(&xdr, &hdr);
4700 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4703 status = decode_putfh(&xdr);
4706 status = decode_getacl(&xdr, rqstp, &res->acl_len);
4713 * Decode CLOSE response
4715 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
4717 struct xdr_stream xdr;
4718 struct compound_hdr hdr;
4721 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4722 status = decode_compound_hdr(&xdr, &hdr);
4725 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4728 status = decode_putfh(&xdr);
4731 status = decode_close(&xdr, res);
4735 * Note: Server may do delete on close for this file
4736 * in which case the getattr call will fail with
4737 * an ESTALE error. Shouldn't be a problem,
4738 * though, since fattr->valid will remain unset.
4740 decode_getfattr(&xdr, res->fattr, res->server,
4741 !RPC_IS_ASYNC(rqstp->rq_task));
4747 * Decode OPEN response
4749 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4751 struct xdr_stream xdr;
4752 struct compound_hdr hdr;
4755 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4756 status = decode_compound_hdr(&xdr, &hdr);
4759 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4762 status = decode_putfh(&xdr);
4765 status = decode_savefh(&xdr);
4768 status = decode_open(&xdr, res);
4771 if (decode_getfh(&xdr, &res->fh) != 0)
4773 if (decode_getfattr(&xdr, res->f_attr, res->server,
4774 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
4776 if (decode_restorefh(&xdr) != 0)
4778 decode_getfattr(&xdr, res->dir_attr, res->server,
4779 !RPC_IS_ASYNC(rqstp->rq_task));
4785 * Decode OPEN_CONFIRM response
4787 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
4789 struct xdr_stream xdr;
4790 struct compound_hdr hdr;
4793 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4794 status = decode_compound_hdr(&xdr, &hdr);
4797 status = decode_putfh(&xdr);
4800 status = decode_open_confirm(&xdr, res);
4806 * Decode OPEN response
4808 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
4810 struct xdr_stream xdr;
4811 struct compound_hdr hdr;
4814 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4815 status = decode_compound_hdr(&xdr, &hdr);
4818 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4821 status = decode_putfh(&xdr);
4824 status = decode_open(&xdr, res);
4827 decode_getfattr(&xdr, res->f_attr, res->server,
4828 !RPC_IS_ASYNC(rqstp->rq_task));
4834 * Decode SETATTR response
4836 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
4838 struct xdr_stream xdr;
4839 struct compound_hdr hdr;
4842 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4843 status = decode_compound_hdr(&xdr, &hdr);
4846 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4849 status = decode_putfh(&xdr);
4852 status = decode_setattr(&xdr);
4855 decode_getfattr(&xdr, res->fattr, res->server,
4856 !RPC_IS_ASYNC(rqstp->rq_task));
4862 * Decode LOCK response
4864 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
4866 struct xdr_stream xdr;
4867 struct compound_hdr hdr;
4870 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4871 status = decode_compound_hdr(&xdr, &hdr);
4874 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4877 status = decode_putfh(&xdr);
4880 status = decode_lock(&xdr, res);
4886 * Decode LOCKT response
4888 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
4890 struct xdr_stream xdr;
4891 struct compound_hdr hdr;
4894 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4895 status = decode_compound_hdr(&xdr, &hdr);
4898 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4901 status = decode_putfh(&xdr);
4904 status = decode_lockt(&xdr, res);
4910 * Decode LOCKU response
4912 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
4914 struct xdr_stream xdr;
4915 struct compound_hdr hdr;
4918 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4919 status = decode_compound_hdr(&xdr, &hdr);
4922 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4925 status = decode_putfh(&xdr);
4928 status = decode_locku(&xdr, res);
4934 * Decode READLINK response
4936 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4937 struct nfs4_readlink_res *res)
4939 struct xdr_stream xdr;
4940 struct compound_hdr hdr;
4943 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4944 status = decode_compound_hdr(&xdr, &hdr);
4947 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4950 status = decode_putfh(&xdr);
4953 status = decode_readlink(&xdr, rqstp);
4959 * Decode READDIR response
4961 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
4963 struct xdr_stream xdr;
4964 struct compound_hdr hdr;
4967 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4968 status = decode_compound_hdr(&xdr, &hdr);
4971 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4974 status = decode_putfh(&xdr);
4977 status = decode_readdir(&xdr, rqstp, res);
4983 * Decode Read response
4985 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
4987 struct xdr_stream xdr;
4988 struct compound_hdr hdr;
4991 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4992 status = decode_compound_hdr(&xdr, &hdr);
4995 status = decode_sequence(&xdr, &res->seq_res, rqstp);
4998 status = decode_putfh(&xdr);
5001 status = decode_read(&xdr, rqstp, res);
5003 status = res->count;
5009 * Decode WRITE response
5011 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
5013 struct xdr_stream xdr;
5014 struct compound_hdr hdr;
5017 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5018 status = decode_compound_hdr(&xdr, &hdr);
5021 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5024 status = decode_putfh(&xdr);
5027 status = decode_write(&xdr, res);
5030 decode_getfattr(&xdr, res->fattr, res->server,
5031 !RPC_IS_ASYNC(rqstp->rq_task));
5033 status = res->count;
5039 * Decode COMMIT response
5041 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
5043 struct xdr_stream xdr;
5044 struct compound_hdr hdr;
5047 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5048 status = decode_compound_hdr(&xdr, &hdr);
5051 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5054 status = decode_putfh(&xdr);
5057 status = decode_commit(&xdr, res);
5060 decode_getfattr(&xdr, res->fattr, res->server,
5061 !RPC_IS_ASYNC(rqstp->rq_task));
5069 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
5070 struct nfs4_fsinfo_res *res)
5072 struct xdr_stream xdr;
5073 struct compound_hdr hdr;
5076 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5077 status = decode_compound_hdr(&xdr, &hdr);
5079 status = decode_sequence(&xdr, &res->seq_res, req);
5081 status = decode_putfh(&xdr);
5083 status = decode_fsinfo(&xdr, res->fsinfo);
5090 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
5091 struct nfs4_pathconf_res *res)
5093 struct xdr_stream xdr;
5094 struct compound_hdr hdr;
5097 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5098 status = decode_compound_hdr(&xdr, &hdr);
5100 status = decode_sequence(&xdr, &res->seq_res, req);
5102 status = decode_putfh(&xdr);
5104 status = decode_pathconf(&xdr, res->pathconf);
5111 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
5112 struct nfs4_statfs_res *res)
5114 struct xdr_stream xdr;
5115 struct compound_hdr hdr;
5118 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5119 status = decode_compound_hdr(&xdr, &hdr);
5121 status = decode_sequence(&xdr, &res->seq_res, req);
5123 status = decode_putfh(&xdr);
5125 status = decode_statfs(&xdr, res->fsstat);
5130 * GETATTR_BITMAP request
5132 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
5134 struct xdr_stream xdr;
5135 struct compound_hdr hdr;
5138 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5139 status = decode_compound_hdr(&xdr, &hdr);
5142 status = decode_sequence(&xdr, &res->seq_res, req);
5145 if ((status = decode_putfh(&xdr)) != 0)
5147 status = decode_server_caps(&xdr, res);
5153 * Decode RENEW response
5155 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
5157 struct xdr_stream xdr;
5158 struct compound_hdr hdr;
5161 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5162 status = decode_compound_hdr(&xdr, &hdr);
5164 status = decode_renew(&xdr);
5169 * a SETCLIENTID request
5171 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
5172 struct nfs_client *clp)
5174 struct xdr_stream xdr;
5175 struct compound_hdr hdr;
5178 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5179 status = decode_compound_hdr(&xdr, &hdr);
5181 status = decode_setclientid(&xdr, clp);
5186 * a SETCLIENTID_CONFIRM request
5188 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
5190 struct xdr_stream xdr;
5191 struct compound_hdr hdr;
5194 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5195 status = decode_compound_hdr(&xdr, &hdr);
5197 status = decode_setclientid_confirm(&xdr);
5199 status = decode_putrootfh(&xdr);
5201 status = decode_fsinfo(&xdr, fsinfo);
5206 * DELEGRETURN request
5208 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
5210 struct xdr_stream xdr;
5211 struct compound_hdr hdr;
5214 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5215 status = decode_compound_hdr(&xdr, &hdr);
5218 status = decode_sequence(&xdr, &res->seq_res, rqstp);
5221 status = decode_putfh(&xdr);
5224 status = decode_delegreturn(&xdr);
5225 decode_getfattr(&xdr, res->fattr, res->server,
5226 !RPC_IS_ASYNC(rqstp->rq_task));
5232 * FS_LOCATIONS request
5234 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
5235 struct nfs4_fs_locations_res *res)
5237 struct xdr_stream xdr;
5238 struct compound_hdr hdr;
5241 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
5242 status = decode_compound_hdr(&xdr, &hdr);
5245 status = decode_sequence(&xdr, &res->seq_res, req);
5248 if ((status = decode_putfh(&xdr)) != 0)
5250 if ((status = decode_lookup(&xdr)) != 0)
5252 xdr_enter_page(&xdr, PAGE_SIZE);
5253 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
5254 res->fs_locations->server,
5255 !RPC_IS_ASYNC(req->rq_task));
5260 #if defined(CONFIG_NFS_V4_1)
5262 * EXCHANGE_ID request
5264 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
5267 struct xdr_stream xdr;
5268 struct compound_hdr hdr;
5271 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5272 status = decode_compound_hdr(&xdr, &hdr);
5274 status = decode_exchange_id(&xdr, res);
5279 * a CREATE_SESSION request
5281 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
5282 struct nfs41_create_session_res *res)
5284 struct xdr_stream xdr;
5285 struct compound_hdr hdr;
5288 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5289 status = decode_compound_hdr(&xdr, &hdr);
5291 status = decode_create_session(&xdr, res);
5296 * a DESTROY_SESSION request
5298 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
5301 struct xdr_stream xdr;
5302 struct compound_hdr hdr;
5305 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5306 status = decode_compound_hdr(&xdr, &hdr);
5308 status = decode_destroy_session(&xdr, dummy);
5313 * a SEQUENCE request
5315 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p,
5316 struct nfs4_sequence_res *res)
5318 struct xdr_stream xdr;
5319 struct compound_hdr hdr;
5322 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5323 status = decode_compound_hdr(&xdr, &hdr);
5325 status = decode_sequence(&xdr, res, rqstp);
5330 * a GET_LEASE_TIME request
5332 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
5333 struct nfs4_get_lease_time_res *res)
5335 struct xdr_stream xdr;
5336 struct compound_hdr hdr;
5339 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
5340 status = decode_compound_hdr(&xdr, &hdr);
5342 status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
5344 status = decode_putrootfh(&xdr);
5346 status = decode_fsinfo(&xdr, res->lr_fsinfo);
5349 #endif /* CONFIG_NFS_V4_1 */
5351 __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
5353 uint32_t bitmap[2] = {0};
5358 return ERR_PTR(-EAGAIN);
5360 return ERR_PTR(-EBADCOOKIE);
5363 entry->prev_cookie = entry->cookie;
5364 p = xdr_decode_hyper(p, &entry->cookie);
5365 entry->len = ntohl(*p++);
5366 entry->name = (const char *) p;
5367 p += XDR_QUADLEN(entry->len);
5370 * In case the server doesn't return an inode number,
5371 * we fake one here. (We don't use inode number 0,
5372 * since glibc seems to choke on it...)
5376 len = ntohl(*p++); /* bitmap length */
5378 bitmap[0] = ntohl(*p++);
5380 bitmap[1] = ntohl(*p++);
5384 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
5386 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
5387 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
5388 /* Ignore the return value of rdattr_error for now */
5392 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
5393 xdr_decode_hyper(p, &entry->ino);
5394 else if (bitmap[0] == FATTR4_WORD0_FILEID)
5395 xdr_decode_hyper(p, &entry->ino);
5399 entry->eof = !p[0] && p[1];
5404 * We need to translate between nfs status return values and
5405 * the local errno values which may not be the same.
5412 { NFS4ERR_PERM, -EPERM },
5413 { NFS4ERR_NOENT, -ENOENT },
5414 { NFS4ERR_IO, -errno_NFSERR_IO},
5415 { NFS4ERR_NXIO, -ENXIO },
5416 { NFS4ERR_ACCESS, -EACCES },
5417 { NFS4ERR_EXIST, -EEXIST },
5418 { NFS4ERR_XDEV, -EXDEV },
5419 { NFS4ERR_NOTDIR, -ENOTDIR },
5420 { NFS4ERR_ISDIR, -EISDIR },
5421 { NFS4ERR_INVAL, -EINVAL },
5422 { NFS4ERR_FBIG, -EFBIG },
5423 { NFS4ERR_NOSPC, -ENOSPC },
5424 { NFS4ERR_ROFS, -EROFS },
5425 { NFS4ERR_MLINK, -EMLINK },
5426 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
5427 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
5428 { NFS4ERR_DQUOT, -EDQUOT },
5429 { NFS4ERR_STALE, -ESTALE },
5430 { NFS4ERR_BADHANDLE, -EBADHANDLE },
5431 { NFS4ERR_BADOWNER, -EINVAL },
5432 { NFS4ERR_BADNAME, -EINVAL },
5433 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
5434 { NFS4ERR_NOTSUPP, -ENOTSUPP },
5435 { NFS4ERR_TOOSMALL, -ETOOSMALL },
5436 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
5437 { NFS4ERR_BADTYPE, -EBADTYPE },
5438 { NFS4ERR_LOCKED, -EAGAIN },
5439 { NFS4ERR_RESOURCE, -EREMOTEIO },
5440 { NFS4ERR_SYMLINK, -ELOOP },
5441 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
5442 { NFS4ERR_DEADLOCK, -EDEADLK },
5443 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
5444 * to be handled by a
5451 * Convert an NFS error code to a local one.
5452 * This one is used jointly by NFSv2 and NFSv3.
5455 nfs4_stat_to_errno(int stat)
5458 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
5459 if (nfs_errtbl[i].stat == stat)
5460 return nfs_errtbl[i].errno;
5462 if (stat <= 10000 || stat > 10100) {
5463 /* The server is looney tunes. */
5464 return -ESERVERFAULT;
5466 /* If we cannot translate the error, the recovery routines should
5468 * Note: remaining NFSv4 error codes have values > 10000, so should
5469 * not conflict with native Linux error codes.
5474 #define PROC(proc, argtype, restype) \
5475 [NFSPROC4_CLNT_##proc] = { \
5476 .p_proc = NFSPROC4_COMPOUND, \
5477 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
5478 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
5479 .p_arglen = NFS4_##argtype##_sz, \
5480 .p_replen = NFS4_##restype##_sz, \
5481 .p_statidx = NFSPROC4_CLNT_##proc, \
5485 struct rpc_procinfo nfs4_procedures[] = {
5486 PROC(READ, enc_read, dec_read),
5487 PROC(WRITE, enc_write, dec_write),
5488 PROC(COMMIT, enc_commit, dec_commit),
5489 PROC(OPEN, enc_open, dec_open),
5490 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
5491 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
5492 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
5493 PROC(CLOSE, enc_close, dec_close),
5494 PROC(SETATTR, enc_setattr, dec_setattr),
5495 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
5496 PROC(RENEW, enc_renew, dec_renew),
5497 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
5498 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
5499 PROC(LOCK, enc_lock, dec_lock),
5500 PROC(LOCKT, enc_lockt, dec_lockt),
5501 PROC(LOCKU, enc_locku, dec_locku),
5502 PROC(ACCESS, enc_access, dec_access),
5503 PROC(GETATTR, enc_getattr, dec_getattr),
5504 PROC(LOOKUP, enc_lookup, dec_lookup),
5505 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
5506 PROC(REMOVE, enc_remove, dec_remove),
5507 PROC(RENAME, enc_rename, dec_rename),
5508 PROC(LINK, enc_link, dec_link),
5509 PROC(SYMLINK, enc_symlink, dec_symlink),
5510 PROC(CREATE, enc_create, dec_create),
5511 PROC(PATHCONF, enc_pathconf, dec_pathconf),
5512 PROC(STATFS, enc_statfs, dec_statfs),
5513 PROC(READLINK, enc_readlink, dec_readlink),
5514 PROC(READDIR, enc_readdir, dec_readdir),
5515 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
5516 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
5517 PROC(GETACL, enc_getacl, dec_getacl),
5518 PROC(SETACL, enc_setacl, dec_setacl),
5519 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
5520 #if defined(CONFIG_NFS_V4_1)
5521 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
5522 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
5523 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
5524 PROC(SEQUENCE, enc_sequence, dec_sequence),
5525 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
5526 #endif /* CONFIG_NFS_V4_1 */
5529 struct rpc_version nfs_version4 = {
5531 .nrprocs = ARRAY_SIZE(nfs4_procedures),
5532 .procs = nfs4_procedures