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/errno.h>
42 #include <linux/string.h>
44 #include <linux/pagemap.h>
45 #include <linux/proc_fs.h>
46 #include <linux/kdev_t.h>
47 #include <linux/sunrpc/clnt.h>
48 #include <linux/sunrpc/msg_prot.h>
49 #include <linux/nfs.h>
50 #include <linux/nfs4.h>
51 #include <linux/nfs_fs.h>
52 #include <linux/nfs_idmap.h>
57 #define NFSDBG_FACILITY NFSDBG_XDR
59 /* Mapping from NFS error code to "errno" error code. */
60 #define errno_NFSERR_IO EIO
62 static int nfs4_stat_to_errno(int);
64 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
66 #define NFS4_MAXTAGLEN 20
68 #define NFS4_MAXTAGLEN 0
71 /* lock,open owner id:
72 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
74 #define open_owner_id_maxsz (1 + 1 + 4)
75 #define lock_owner_id_maxsz (1 + 1 + 4)
76 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
77 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79 #define op_encode_hdr_maxsz (1)
80 #define op_decode_hdr_maxsz (2)
81 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
84 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
85 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
87 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
88 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
89 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
90 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
91 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
92 ((3+NFS4_FHSIZE) >> 2))
93 #define nfs4_fattr_bitmap_maxsz 3
94 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
95 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
96 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
97 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
99 /* This is based on getfattr, which uses the most attributes: */
100 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
101 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
102 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
103 nfs4_fattr_value_maxsz)
104 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
105 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
110 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
111 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
112 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
113 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
114 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
115 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
116 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
117 #define decode_renew_maxsz (op_decode_hdr_maxsz)
118 #define encode_setclientid_maxsz \
119 (op_encode_hdr_maxsz + \
120 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
121 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
123 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
124 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
126 #define decode_setclientid_maxsz \
127 (op_decode_hdr_maxsz + \
129 1024) /* large value for CLID_INUSE */
130 #define encode_setclientid_confirm_maxsz \
131 (op_encode_hdr_maxsz + \
132 3 + (NFS4_VERIFIER_SIZE >> 2))
133 #define decode_setclientid_confirm_maxsz \
134 (op_decode_hdr_maxsz)
135 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
136 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
137 #define encode_share_access_maxsz \
139 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
140 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
141 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
142 #define encode_open_maxsz (op_encode_hdr_maxsz + \
143 2 + encode_share_access_maxsz + 2 + \
144 open_owner_id_maxsz + \
145 encode_opentype_maxsz + \
146 encode_claim_null_maxsz)
147 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
148 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
150 #define decode_change_info_maxsz (5)
151 #define decode_open_maxsz (op_decode_hdr_maxsz + \
152 decode_stateid_maxsz + \
153 decode_change_info_maxsz + 1 + \
154 nfs4_fattr_bitmap_maxsz + \
155 decode_delegation_maxsz)
156 #define encode_open_confirm_maxsz \
157 (op_encode_hdr_maxsz + \
158 encode_stateid_maxsz + 1)
159 #define decode_open_confirm_maxsz \
160 (op_decode_hdr_maxsz + \
161 decode_stateid_maxsz)
162 #define encode_open_downgrade_maxsz \
163 (op_encode_hdr_maxsz + \
164 encode_stateid_maxsz + 1 + \
165 encode_share_access_maxsz)
166 #define decode_open_downgrade_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169 #define encode_close_maxsz (op_encode_hdr_maxsz + \
170 1 + encode_stateid_maxsz)
171 #define decode_close_maxsz (op_decode_hdr_maxsz + \
172 decode_stateid_maxsz)
173 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
174 encode_stateid_maxsz + \
176 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
177 nfs4_fattr_bitmap_maxsz)
178 #define encode_read_maxsz (op_encode_hdr_maxsz + \
179 encode_stateid_maxsz + 3)
180 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
181 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
182 2 + encode_verifier_maxsz + 5)
183 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
184 decode_verifier_maxsz)
185 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
186 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
187 #define encode_write_maxsz (op_encode_hdr_maxsz + \
188 encode_stateid_maxsz + 4)
189 #define decode_write_maxsz (op_decode_hdr_maxsz + \
190 2 + decode_verifier_maxsz)
191 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
192 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
193 decode_verifier_maxsz)
194 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
196 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
197 decode_change_info_maxsz)
198 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
200 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
201 decode_change_info_maxsz + \
202 decode_change_info_maxsz)
203 #define encode_link_maxsz (op_encode_hdr_maxsz + \
205 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
206 #define encode_lockowner_maxsz (7)
207 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
209 1 + encode_stateid_maxsz + 1 + \
210 encode_lockowner_maxsz)
211 #define decode_lock_denied_maxsz \
212 (8 + decode_lockowner_maxsz)
213 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
215 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
216 encode_lockowner_maxsz)
217 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
218 decode_lock_denied_maxsz)
219 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
220 encode_stateid_maxsz + \
222 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
223 decode_stateid_maxsz)
224 #define encode_release_lockowner_maxsz \
225 (op_encode_hdr_maxsz + \
226 encode_lockowner_maxsz)
227 #define decode_release_lockowner_maxsz \
228 (op_decode_hdr_maxsz)
229 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
230 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
231 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
232 1 + nfs4_name_maxsz + \
235 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
236 #define encode_create_maxsz (op_encode_hdr_maxsz + \
237 1 + 2 + nfs4_name_maxsz + \
239 #define decode_create_maxsz (op_decode_hdr_maxsz + \
240 decode_change_info_maxsz + \
241 nfs4_fattr_bitmap_maxsz)
242 #define encode_statfs_maxsz (encode_getattr_maxsz)
243 #define decode_statfs_maxsz (decode_getattr_maxsz)
244 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
245 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
246 #define encode_getacl_maxsz (encode_getattr_maxsz)
247 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
248 nfs4_fattr_bitmap_maxsz + 1)
249 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
250 encode_stateid_maxsz + 3)
251 #define decode_setacl_maxsz (decode_setattr_maxsz)
252 #define encode_fs_locations_maxsz \
253 (encode_getattr_maxsz)
254 #define decode_fs_locations_maxsz \
257 #if defined(CONFIG_NFS_V4_1)
258 #define NFS4_MAX_MACHINE_NAME_LEN (64)
260 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
261 encode_verifier_maxsz + \
262 1 /* co_ownerid.len */ + \
263 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
266 0 /* SP4_NONE (for now) */ + \
267 1 /* zero implemetation id array */)
268 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
269 2 /* eir_clientid */ + \
270 1 /* eir_sequenceid */ + \
271 1 /* eir_flags */ + \
273 0 /* SP4_NONE (for now) */ + \
274 2 /* eir_server_owner.so_minor_id */ + \
275 /* eir_server_owner.so_major_id<> */ \
276 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
277 /* eir_server_scope<> */ \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
279 1 /* eir_server_impl_id array length */ + \
280 0 /* ignored eir_server_impl_id contents */)
281 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
282 #define decode_channel_attrs_maxsz (6 + \
283 1 /* ca_rdma_ird.len */ + \
285 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
286 2 /* csa_clientid */ + \
287 1 /* csa_sequence */ + \
288 1 /* csa_flags */ + \
289 encode_channel_attrs_maxsz + \
290 encode_channel_attrs_maxsz + \
291 1 /* csa_cb_program */ + \
292 1 /* csa_sec_parms.len (1) */ + \
293 1 /* cb_secflavor (AUTH_SYS) */ + \
295 1 /* machinename.len */ + \
296 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
299 1 /* gids.len (0) */)
300 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
301 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
302 1 /* csr_sequence */ + \
303 1 /* csr_flags */ + \
304 decode_channel_attrs_maxsz + \
305 decode_channel_attrs_maxsz)
306 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
307 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
308 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
309 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
310 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
311 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
312 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
313 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
314 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
315 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
316 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
317 1 /* layout type */ + \
318 1 /* opaque devaddr4 length */ + \
319 /* devaddr4 payload is read into page */ \
320 1 /* notification bitmap length */ + \
321 1 /* notification bitmap */)
322 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
323 encode_stateid_maxsz)
324 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
325 decode_stateid_maxsz + \
326 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
327 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
331 encode_stateid_maxsz + \
332 1 /* new offset (true) */ + \
333 2 /* last byte written */ + \
334 1 /* nt_timechanged (false) */ + \
335 1 /* layoutupdate4 layout type */ + \
336 1 /* NULL filelayout layoutupdate4 payload */)
337 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
339 #else /* CONFIG_NFS_V4_1 */
340 #define encode_sequence_maxsz 0
341 #define decode_sequence_maxsz 0
342 #endif /* CONFIG_NFS_V4_1 */
344 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
345 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
346 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
347 encode_sequence_maxsz + \
348 encode_putfh_maxsz + \
350 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
351 decode_sequence_maxsz + \
352 decode_putfh_maxsz + \
354 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
355 encode_sequence_maxsz + \
356 encode_putfh_maxsz + \
357 encode_readlink_maxsz)
358 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
359 decode_sequence_maxsz + \
360 decode_putfh_maxsz + \
361 decode_readlink_maxsz)
362 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
363 encode_sequence_maxsz + \
364 encode_putfh_maxsz + \
365 encode_readdir_maxsz)
366 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
367 decode_sequence_maxsz + \
368 decode_putfh_maxsz + \
369 decode_readdir_maxsz)
370 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
371 encode_sequence_maxsz + \
372 encode_putfh_maxsz + \
373 encode_write_maxsz + \
374 encode_getattr_maxsz)
375 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
376 decode_sequence_maxsz + \
377 decode_putfh_maxsz + \
378 decode_write_maxsz + \
379 decode_getattr_maxsz)
380 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
381 encode_sequence_maxsz + \
382 encode_putfh_maxsz + \
383 encode_commit_maxsz + \
384 encode_getattr_maxsz)
385 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
386 decode_sequence_maxsz + \
387 decode_putfh_maxsz + \
388 decode_commit_maxsz + \
389 decode_getattr_maxsz)
390 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
391 encode_sequence_maxsz + \
392 encode_putfh_maxsz + \
393 encode_savefh_maxsz + \
394 encode_open_maxsz + \
395 encode_getfh_maxsz + \
396 encode_getattr_maxsz + \
397 encode_restorefh_maxsz + \
398 encode_getattr_maxsz)
399 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
400 decode_sequence_maxsz + \
401 decode_putfh_maxsz + \
402 decode_savefh_maxsz + \
403 decode_open_maxsz + \
404 decode_getfh_maxsz + \
405 decode_getattr_maxsz + \
406 decode_restorefh_maxsz + \
407 decode_getattr_maxsz)
408 #define NFS4_enc_open_confirm_sz \
409 (compound_encode_hdr_maxsz + \
410 encode_putfh_maxsz + \
411 encode_open_confirm_maxsz)
412 #define NFS4_dec_open_confirm_sz \
413 (compound_decode_hdr_maxsz + \
414 decode_putfh_maxsz + \
415 decode_open_confirm_maxsz)
416 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
417 encode_sequence_maxsz + \
418 encode_putfh_maxsz + \
419 encode_open_maxsz + \
420 encode_getattr_maxsz)
421 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
422 decode_sequence_maxsz + \
423 decode_putfh_maxsz + \
424 decode_open_maxsz + \
425 decode_getattr_maxsz)
426 #define NFS4_enc_open_downgrade_sz \
427 (compound_encode_hdr_maxsz + \
428 encode_sequence_maxsz + \
429 encode_putfh_maxsz + \
430 encode_open_downgrade_maxsz + \
431 encode_getattr_maxsz)
432 #define NFS4_dec_open_downgrade_sz \
433 (compound_decode_hdr_maxsz + \
434 decode_sequence_maxsz + \
435 decode_putfh_maxsz + \
436 decode_open_downgrade_maxsz + \
437 decode_getattr_maxsz)
438 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
439 encode_sequence_maxsz + \
440 encode_putfh_maxsz + \
441 encode_close_maxsz + \
442 encode_getattr_maxsz)
443 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
444 decode_sequence_maxsz + \
445 decode_putfh_maxsz + \
446 decode_close_maxsz + \
447 decode_getattr_maxsz)
448 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
449 encode_sequence_maxsz + \
450 encode_putfh_maxsz + \
451 encode_setattr_maxsz + \
452 encode_getattr_maxsz)
453 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
454 decode_sequence_maxsz + \
455 decode_putfh_maxsz + \
456 decode_setattr_maxsz + \
457 decode_getattr_maxsz)
458 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
459 encode_sequence_maxsz + \
460 encode_putfh_maxsz + \
462 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
463 decode_sequence_maxsz + \
464 decode_putfh_maxsz + \
466 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
468 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
470 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
471 encode_setclientid_maxsz)
472 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
473 decode_setclientid_maxsz)
474 #define NFS4_enc_setclientid_confirm_sz \
475 (compound_encode_hdr_maxsz + \
476 encode_setclientid_confirm_maxsz + \
477 encode_putrootfh_maxsz + \
479 #define NFS4_dec_setclientid_confirm_sz \
480 (compound_decode_hdr_maxsz + \
481 decode_setclientid_confirm_maxsz + \
482 decode_putrootfh_maxsz + \
484 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
485 encode_sequence_maxsz + \
486 encode_putfh_maxsz + \
488 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
489 decode_sequence_maxsz + \
490 decode_putfh_maxsz + \
492 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
493 encode_sequence_maxsz + \
494 encode_putfh_maxsz + \
496 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
497 decode_sequence_maxsz + \
498 decode_putfh_maxsz + \
500 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
501 encode_sequence_maxsz + \
502 encode_putfh_maxsz + \
504 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
505 decode_sequence_maxsz + \
506 decode_putfh_maxsz + \
508 #define NFS4_enc_release_lockowner_sz \
509 (compound_encode_hdr_maxsz + \
510 encode_lockowner_maxsz)
511 #define NFS4_dec_release_lockowner_sz \
512 (compound_decode_hdr_maxsz + \
513 decode_lockowner_maxsz)
514 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
515 encode_sequence_maxsz + \
516 encode_putfh_maxsz + \
517 encode_access_maxsz + \
518 encode_getattr_maxsz)
519 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
520 decode_sequence_maxsz + \
521 decode_putfh_maxsz + \
522 decode_access_maxsz + \
523 decode_getattr_maxsz)
524 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
525 encode_sequence_maxsz + \
526 encode_putfh_maxsz + \
527 encode_getattr_maxsz)
528 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
529 decode_sequence_maxsz + \
530 decode_putfh_maxsz + \
531 decode_getattr_maxsz)
532 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
533 encode_sequence_maxsz + \
534 encode_putfh_maxsz + \
535 encode_lookup_maxsz + \
536 encode_getattr_maxsz + \
538 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
539 decode_sequence_maxsz + \
540 decode_putfh_maxsz + \
541 decode_lookup_maxsz + \
542 decode_getattr_maxsz + \
544 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
545 encode_sequence_maxsz + \
546 encode_putrootfh_maxsz + \
547 encode_getattr_maxsz + \
549 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
550 decode_sequence_maxsz + \
551 decode_putrootfh_maxsz + \
552 decode_getattr_maxsz + \
554 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
555 encode_sequence_maxsz + \
556 encode_putfh_maxsz + \
557 encode_remove_maxsz + \
558 encode_getattr_maxsz)
559 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
560 decode_sequence_maxsz + \
561 decode_putfh_maxsz + \
562 decode_remove_maxsz + \
563 decode_getattr_maxsz)
564 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
565 encode_sequence_maxsz + \
566 encode_putfh_maxsz + \
567 encode_savefh_maxsz + \
568 encode_putfh_maxsz + \
569 encode_rename_maxsz + \
570 encode_getattr_maxsz + \
571 encode_restorefh_maxsz + \
572 encode_getattr_maxsz)
573 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
574 decode_sequence_maxsz + \
575 decode_putfh_maxsz + \
576 decode_savefh_maxsz + \
577 decode_putfh_maxsz + \
578 decode_rename_maxsz + \
579 decode_getattr_maxsz + \
580 decode_restorefh_maxsz + \
581 decode_getattr_maxsz)
582 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
583 encode_sequence_maxsz + \
584 encode_putfh_maxsz + \
585 encode_savefh_maxsz + \
586 encode_putfh_maxsz + \
587 encode_link_maxsz + \
588 decode_getattr_maxsz + \
589 encode_restorefh_maxsz + \
590 decode_getattr_maxsz)
591 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
592 decode_sequence_maxsz + \
593 decode_putfh_maxsz + \
594 decode_savefh_maxsz + \
595 decode_putfh_maxsz + \
596 decode_link_maxsz + \
597 decode_getattr_maxsz + \
598 decode_restorefh_maxsz + \
599 decode_getattr_maxsz)
600 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
601 encode_sequence_maxsz + \
602 encode_putfh_maxsz + \
603 encode_symlink_maxsz + \
604 encode_getattr_maxsz + \
606 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
607 decode_sequence_maxsz + \
608 decode_putfh_maxsz + \
609 decode_symlink_maxsz + \
610 decode_getattr_maxsz + \
612 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
613 encode_sequence_maxsz + \
614 encode_putfh_maxsz + \
615 encode_savefh_maxsz + \
616 encode_create_maxsz + \
617 encode_getfh_maxsz + \
618 encode_getattr_maxsz + \
619 encode_restorefh_maxsz + \
620 encode_getattr_maxsz)
621 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
622 decode_sequence_maxsz + \
623 decode_putfh_maxsz + \
624 decode_savefh_maxsz + \
625 decode_create_maxsz + \
626 decode_getfh_maxsz + \
627 decode_getattr_maxsz + \
628 decode_restorefh_maxsz + \
629 decode_getattr_maxsz)
630 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
631 encode_sequence_maxsz + \
632 encode_putfh_maxsz + \
633 encode_getattr_maxsz)
634 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
635 decode_sequence_maxsz + \
636 decode_putfh_maxsz + \
637 decode_getattr_maxsz)
638 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
639 encode_sequence_maxsz + \
640 encode_putfh_maxsz + \
642 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
643 decode_sequence_maxsz + \
644 decode_putfh_maxsz + \
646 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
647 encode_sequence_maxsz + \
648 encode_putfh_maxsz + \
649 encode_getattr_maxsz)
650 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
651 decode_sequence_maxsz + \
652 decode_putfh_maxsz + \
653 decode_getattr_maxsz)
654 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
655 encode_sequence_maxsz + \
656 encode_putfh_maxsz + \
657 encode_delegreturn_maxsz + \
658 encode_getattr_maxsz)
659 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
660 decode_sequence_maxsz + \
661 decode_delegreturn_maxsz + \
662 decode_getattr_maxsz)
663 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
664 encode_sequence_maxsz + \
665 encode_putfh_maxsz + \
667 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
668 decode_sequence_maxsz + \
669 decode_putfh_maxsz + \
671 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
672 encode_sequence_maxsz + \
673 encode_putfh_maxsz + \
675 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
676 decode_sequence_maxsz + \
677 decode_putfh_maxsz + \
679 #define NFS4_enc_fs_locations_sz \
680 (compound_encode_hdr_maxsz + \
681 encode_sequence_maxsz + \
682 encode_putfh_maxsz + \
683 encode_lookup_maxsz + \
684 encode_fs_locations_maxsz)
685 #define NFS4_dec_fs_locations_sz \
686 (compound_decode_hdr_maxsz + \
687 decode_sequence_maxsz + \
688 decode_putfh_maxsz + \
689 decode_lookup_maxsz + \
690 decode_fs_locations_maxsz)
691 #if defined(CONFIG_NFS_V4_1)
692 #define NFS4_enc_exchange_id_sz \
693 (compound_encode_hdr_maxsz + \
694 encode_exchange_id_maxsz)
695 #define NFS4_dec_exchange_id_sz \
696 (compound_decode_hdr_maxsz + \
697 decode_exchange_id_maxsz)
698 #define NFS4_enc_create_session_sz \
699 (compound_encode_hdr_maxsz + \
700 encode_create_session_maxsz)
701 #define NFS4_dec_create_session_sz \
702 (compound_decode_hdr_maxsz + \
703 decode_create_session_maxsz)
704 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
705 encode_destroy_session_maxsz)
706 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
707 decode_destroy_session_maxsz)
708 #define NFS4_enc_sequence_sz \
709 (compound_decode_hdr_maxsz + \
710 encode_sequence_maxsz)
711 #define NFS4_dec_sequence_sz \
712 (compound_decode_hdr_maxsz + \
713 decode_sequence_maxsz)
714 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
715 encode_sequence_maxsz + \
716 encode_putrootfh_maxsz + \
718 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
719 decode_sequence_maxsz + \
720 decode_putrootfh_maxsz + \
722 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
723 encode_sequence_maxsz + \
724 encode_reclaim_complete_maxsz)
725 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
726 decode_sequence_maxsz + \
727 decode_reclaim_complete_maxsz)
728 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
729 encode_sequence_maxsz +\
730 encode_getdeviceinfo_maxsz)
731 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
732 decode_sequence_maxsz + \
733 decode_getdeviceinfo_maxsz)
734 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
735 encode_sequence_maxsz + \
736 encode_putfh_maxsz + \
737 encode_layoutget_maxsz)
738 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
739 decode_sequence_maxsz + \
740 decode_putfh_maxsz + \
741 decode_layoutget_maxsz)
742 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
743 encode_sequence_maxsz +\
744 encode_putfh_maxsz + \
745 encode_layoutcommit_maxsz + \
746 encode_getattr_maxsz)
747 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
748 decode_sequence_maxsz + \
749 decode_putfh_maxsz + \
750 decode_layoutcommit_maxsz + \
751 decode_getattr_maxsz)
754 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
755 compound_encode_hdr_maxsz +
756 encode_sequence_maxsz +
758 encode_getattr_maxsz) *
761 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
762 compound_decode_hdr_maxsz +
763 decode_sequence_maxsz +
764 decode_putfh_maxsz) *
766 #endif /* CONFIG_NFS_V4_1 */
768 static const umode_t nfs_type2fmt[] = {
775 [NF4SOCK] = S_IFSOCK,
781 struct compound_hdr {
787 uint32_t replen; /* expected reply words */
791 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
793 __be32 *p = xdr_reserve_space(xdr, nbytes);
798 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
802 p = xdr_reserve_space(xdr, 4 + len);
804 xdr_encode_opaque(p, str, len);
807 static void encode_compound_hdr(struct xdr_stream *xdr,
808 struct rpc_rqst *req,
809 struct compound_hdr *hdr)
812 struct rpc_auth *auth = req->rq_cred->cr_auth;
814 /* initialize running count of expected bytes in reply.
815 * NOTE: the replied tag SHOULD be the same is the one sent,
816 * but this is not required as a MUST for the server to do so. */
817 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
819 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
820 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
821 p = reserve_space(xdr, 4 + hdr->taglen + 8);
822 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
823 *p++ = cpu_to_be32(hdr->minorversion);
825 *p = cpu_to_be32(hdr->nops);
828 static void encode_nops(struct compound_hdr *hdr)
830 BUG_ON(hdr->nops > NFS4_MAX_OPS);
831 *hdr->nops_p = htonl(hdr->nops);
834 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
838 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
840 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
843 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
845 char owner_name[IDMAP_NAMESZ];
846 char owner_group[IDMAP_NAMESZ];
847 int owner_namelen = 0;
848 int owner_grouplen = 0;
856 * We reserve enough space to write the entire attribute buffer at once.
857 * In the worst-case, this would be
858 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
859 * = 36 bytes, plus any contribution from variable-length fields
860 * such as owner/group.
865 if (iap->ia_valid & ATTR_SIZE)
867 if (iap->ia_valid & ATTR_MODE)
869 if (iap->ia_valid & ATTR_UID) {
870 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
871 if (owner_namelen < 0) {
872 dprintk("nfs: couldn't resolve uid %d to string\n",
875 strcpy(owner_name, "nobody");
876 owner_namelen = sizeof("nobody") - 1;
879 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
881 if (iap->ia_valid & ATTR_GID) {
882 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
883 if (owner_grouplen < 0) {
884 dprintk("nfs: couldn't resolve gid %d to string\n",
886 strcpy(owner_group, "nobody");
887 owner_grouplen = sizeof("nobody") - 1;
890 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
892 if (iap->ia_valid & ATTR_ATIME_SET)
894 else if (iap->ia_valid & ATTR_ATIME)
896 if (iap->ia_valid & ATTR_MTIME_SET)
898 else if (iap->ia_valid & ATTR_MTIME)
900 p = reserve_space(xdr, len);
903 * We write the bitmap length now, but leave the bitmap and the attribute
904 * buffer length to be backfilled at the end of this routine.
906 *p++ = cpu_to_be32(2);
910 if (iap->ia_valid & ATTR_SIZE) {
911 bmval0 |= FATTR4_WORD0_SIZE;
912 p = xdr_encode_hyper(p, iap->ia_size);
914 if (iap->ia_valid & ATTR_MODE) {
915 bmval1 |= FATTR4_WORD1_MODE;
916 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
918 if (iap->ia_valid & ATTR_UID) {
919 bmval1 |= FATTR4_WORD1_OWNER;
920 p = xdr_encode_opaque(p, owner_name, owner_namelen);
922 if (iap->ia_valid & ATTR_GID) {
923 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
924 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
926 if (iap->ia_valid & ATTR_ATIME_SET) {
927 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
928 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
929 *p++ = cpu_to_be32(0);
930 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
931 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
933 else if (iap->ia_valid & ATTR_ATIME) {
934 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
935 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
937 if (iap->ia_valid & ATTR_MTIME_SET) {
938 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
939 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
940 *p++ = cpu_to_be32(0);
941 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
942 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
944 else if (iap->ia_valid & ATTR_MTIME) {
945 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
946 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
950 * Now we backfill the bitmap and the attribute buffer length.
952 if (len != ((char *)p - (char *)q) + 4) {
953 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
954 len, ((char *)p - (char *)q) + 4);
957 len = (char *)p - (char *)q - 12;
958 *q++ = htonl(bmval0);
959 *q++ = htonl(bmval1);
965 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
969 p = reserve_space(xdr, 8);
970 *p++ = cpu_to_be32(OP_ACCESS);
971 *p = cpu_to_be32(access);
973 hdr->replen += decode_access_maxsz;
976 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
980 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
981 *p++ = cpu_to_be32(OP_CLOSE);
982 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
983 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
985 hdr->replen += decode_close_maxsz;
988 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
992 p = reserve_space(xdr, 16);
993 *p++ = cpu_to_be32(OP_COMMIT);
994 p = xdr_encode_hyper(p, args->offset);
995 *p = cpu_to_be32(args->count);
997 hdr->replen += decode_commit_maxsz;
1000 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1004 p = reserve_space(xdr, 8);
1005 *p++ = cpu_to_be32(OP_CREATE);
1006 *p = cpu_to_be32(create->ftype);
1008 switch (create->ftype) {
1010 p = reserve_space(xdr, 4);
1011 *p = cpu_to_be32(create->u.symlink.len);
1012 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1015 case NF4BLK: case NF4CHR:
1016 p = reserve_space(xdr, 8);
1017 *p++ = cpu_to_be32(create->u.device.specdata1);
1018 *p = cpu_to_be32(create->u.device.specdata2);
1025 encode_string(xdr, create->name->len, create->name->name);
1027 hdr->replen += decode_create_maxsz;
1029 encode_attrs(xdr, create->attrs, create->server);
1032 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1036 p = reserve_space(xdr, 12);
1037 *p++ = cpu_to_be32(OP_GETATTR);
1038 *p++ = cpu_to_be32(1);
1039 *p = cpu_to_be32(bitmap);
1041 hdr->replen += decode_getattr_maxsz;
1044 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1048 p = reserve_space(xdr, 16);
1049 *p++ = cpu_to_be32(OP_GETATTR);
1050 *p++ = cpu_to_be32(2);
1051 *p++ = cpu_to_be32(bm0);
1052 *p = cpu_to_be32(bm1);
1054 hdr->replen += decode_getattr_maxsz;
1057 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1059 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1060 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
1063 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1065 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1066 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
1069 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1071 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1072 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1075 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1079 p = reserve_space(xdr, 4);
1080 *p = cpu_to_be32(OP_GETFH);
1082 hdr->replen += decode_getfh_maxsz;
1085 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1089 p = reserve_space(xdr, 8 + name->len);
1090 *p++ = cpu_to_be32(OP_LINK);
1091 xdr_encode_opaque(p, name->name, name->len);
1093 hdr->replen += decode_link_maxsz;
1096 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1098 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1099 return block ? NFS4_READW_LT : NFS4_READ_LT;
1100 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1103 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1105 if (fl->fl_end == OFFSET_MAX)
1106 return ~(uint64_t)0;
1107 return fl->fl_end - fl->fl_start + 1;
1110 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1114 p = reserve_space(xdr, 32);
1115 p = xdr_encode_hyper(p, lowner->clientid);
1116 *p++ = cpu_to_be32(20);
1117 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1118 *p++ = cpu_to_be32(lowner->s_dev);
1119 xdr_encode_hyper(p, lowner->id);
1123 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1124 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1126 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1130 p = reserve_space(xdr, 32);
1131 *p++ = cpu_to_be32(OP_LOCK);
1132 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1133 *p++ = cpu_to_be32(args->reclaim);
1134 p = xdr_encode_hyper(p, args->fl->fl_start);
1135 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1136 *p = cpu_to_be32(args->new_lock_owner);
1137 if (args->new_lock_owner){
1138 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1139 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
1140 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
1141 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
1142 encode_lockowner(xdr, &args->lock_owner);
1145 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
1146 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
1147 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
1150 hdr->replen += decode_lock_maxsz;
1153 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1157 p = reserve_space(xdr, 24);
1158 *p++ = cpu_to_be32(OP_LOCKT);
1159 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1160 p = xdr_encode_hyper(p, args->fl->fl_start);
1161 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1162 encode_lockowner(xdr, &args->lock_owner);
1164 hdr->replen += decode_lockt_maxsz;
1167 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1171 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
1172 *p++ = cpu_to_be32(OP_LOCKU);
1173 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1174 *p++ = cpu_to_be32(args->seqid->sequence->counter);
1175 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
1176 p = xdr_encode_hyper(p, args->fl->fl_start);
1177 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1179 hdr->replen += decode_locku_maxsz;
1182 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1186 p = reserve_space(xdr, 4);
1187 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1188 encode_lockowner(xdr, lowner);
1190 hdr->replen += decode_release_lockowner_maxsz;
1193 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1195 int len = name->len;
1198 p = reserve_space(xdr, 8 + len);
1199 *p++ = cpu_to_be32(OP_LOOKUP);
1200 xdr_encode_opaque(p, name->name, len);
1202 hdr->replen += decode_lookup_maxsz;
1205 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1209 p = reserve_space(xdr, 8);
1210 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1212 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1215 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1217 case FMODE_READ|FMODE_WRITE:
1218 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1221 *p++ = cpu_to_be32(0);
1223 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1226 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1230 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1233 p = reserve_space(xdr, 8);
1234 *p++ = cpu_to_be32(OP_OPEN);
1235 *p = cpu_to_be32(arg->seqid->sequence->counter);
1236 encode_share_access(xdr, arg->fmode);
1237 p = reserve_space(xdr, 32);
1238 p = xdr_encode_hyper(p, arg->clientid);
1239 *p++ = cpu_to_be32(20);
1240 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1241 *p++ = cpu_to_be32(arg->server->s_dev);
1242 xdr_encode_hyper(p, arg->id);
1245 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1248 struct nfs_client *clp;
1250 p = reserve_space(xdr, 4);
1251 switch(arg->open_flags & O_EXCL) {
1253 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1254 encode_attrs(xdr, arg->u.attrs, arg->server);
1257 clp = arg->server->nfs_client;
1258 if (clp->cl_mvops->minor_version > 0) {
1259 if (nfs4_has_persistent_session(clp)) {
1260 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1261 encode_attrs(xdr, arg->u.attrs, arg->server);
1265 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1266 encode_nfs4_verifier(xdr, &arg->u.verifier);
1268 encode_attrs(xdr, &dummy, arg->server);
1271 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1272 encode_nfs4_verifier(xdr, &arg->u.verifier);
1277 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1281 p = reserve_space(xdr, 4);
1282 switch (arg->open_flags & O_CREAT) {
1284 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1287 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1288 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1289 encode_createmode(xdr, arg);
1293 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1297 p = reserve_space(xdr, 4);
1298 switch (delegation_type) {
1300 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1303 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1305 case FMODE_WRITE|FMODE_READ:
1306 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1313 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1317 p = reserve_space(xdr, 4);
1318 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1319 encode_string(xdr, name->len, name->name);
1322 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1326 p = reserve_space(xdr, 4);
1327 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1328 encode_delegation_type(xdr, type);
1331 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1335 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1336 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1337 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1338 encode_string(xdr, name->len, name->name);
1341 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1343 encode_openhdr(xdr, arg);
1344 encode_opentype(xdr, arg);
1345 switch (arg->claim) {
1346 case NFS4_OPEN_CLAIM_NULL:
1347 encode_claim_null(xdr, arg->name);
1349 case NFS4_OPEN_CLAIM_PREVIOUS:
1350 encode_claim_previous(xdr, arg->u.delegation_type);
1352 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1353 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1359 hdr->replen += decode_open_maxsz;
1362 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1366 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1367 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
1368 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1369 *p = cpu_to_be32(arg->seqid->sequence->counter);
1371 hdr->replen += decode_open_confirm_maxsz;
1374 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1378 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1379 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
1380 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1381 *p = cpu_to_be32(arg->seqid->sequence->counter);
1382 encode_share_access(xdr, arg->fmode);
1384 hdr->replen += decode_open_downgrade_maxsz;
1388 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1393 p = reserve_space(xdr, 8 + len);
1394 *p++ = cpu_to_be32(OP_PUTFH);
1395 xdr_encode_opaque(p, fh->data, len);
1397 hdr->replen += decode_putfh_maxsz;
1400 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1404 p = reserve_space(xdr, 4);
1405 *p = cpu_to_be32(OP_PUTROOTFH);
1407 hdr->replen += decode_putrootfh_maxsz;
1410 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
1412 nfs4_stateid stateid;
1415 p = reserve_space(xdr, NFS4_STATEID_SIZE);
1416 if (ctx->state != NULL) {
1417 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
1419 stateid.stateid.seqid = 0;
1420 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
1422 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1425 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1429 p = reserve_space(xdr, 4);
1430 *p = cpu_to_be32(OP_READ);
1432 encode_stateid(xdr, args->context, args->lock_context,
1435 p = reserve_space(xdr, 12);
1436 p = xdr_encode_hyper(p, args->offset);
1437 *p = cpu_to_be32(args->count);
1439 hdr->replen += decode_read_maxsz;
1442 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1444 uint32_t attrs[2] = {0, 0};
1445 uint32_t dircount = readdir->count >> 1;
1448 if (readdir->plus) {
1449 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1450 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE;
1451 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1452 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1453 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1454 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1457 attrs[0] |= FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID;
1458 attrs[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
1459 /* Switch to mounted_on_fileid if the server supports it */
1460 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1461 attrs[0] &= ~FATTR4_WORD0_FILEID;
1463 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1465 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
1466 *p++ = cpu_to_be32(OP_READDIR);
1467 p = xdr_encode_hyper(p, readdir->cookie);
1468 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
1469 *p++ = cpu_to_be32(dircount);
1470 *p++ = cpu_to_be32(readdir->count);
1471 *p++ = cpu_to_be32(2);
1473 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1474 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1476 hdr->replen += decode_readdir_maxsz;
1477 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1479 (unsigned long long)readdir->cookie,
1480 ((u32 *)readdir->verifier.data)[0],
1481 ((u32 *)readdir->verifier.data)[1],
1482 attrs[0] & readdir->bitmask[0],
1483 attrs[1] & readdir->bitmask[1]);
1486 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1490 p = reserve_space(xdr, 4);
1491 *p = cpu_to_be32(OP_READLINK);
1493 hdr->replen += decode_readlink_maxsz;
1496 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1500 p = reserve_space(xdr, 8 + name->len);
1501 *p++ = cpu_to_be32(OP_REMOVE);
1502 xdr_encode_opaque(p, name->name, name->len);
1504 hdr->replen += decode_remove_maxsz;
1507 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1511 p = reserve_space(xdr, 4);
1512 *p = cpu_to_be32(OP_RENAME);
1513 encode_string(xdr, oldname->len, oldname->name);
1514 encode_string(xdr, newname->len, newname->name);
1516 hdr->replen += decode_rename_maxsz;
1519 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1523 p = reserve_space(xdr, 12);
1524 *p++ = cpu_to_be32(OP_RENEW);
1525 xdr_encode_hyper(p, client_stateid->cl_clientid);
1527 hdr->replen += decode_renew_maxsz;
1531 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1535 p = reserve_space(xdr, 4);
1536 *p = cpu_to_be32(OP_RESTOREFH);
1538 hdr->replen += decode_restorefh_maxsz;
1542 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1546 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1547 *p++ = cpu_to_be32(OP_SETATTR);
1548 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1549 p = reserve_space(xdr, 2*4);
1550 *p++ = cpu_to_be32(1);
1551 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1552 BUG_ON(arg->acl_len % 4);
1553 p = reserve_space(xdr, 4);
1554 *p = cpu_to_be32(arg->acl_len);
1555 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1557 hdr->replen += decode_setacl_maxsz;
1561 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1565 p = reserve_space(xdr, 4);
1566 *p = cpu_to_be32(OP_SAVEFH);
1568 hdr->replen += decode_savefh_maxsz;
1571 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1575 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1576 *p++ = cpu_to_be32(OP_SETATTR);
1577 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
1579 hdr->replen += decode_setattr_maxsz;
1580 encode_attrs(xdr, arg->iap, server);
1583 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1587 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
1588 *p++ = cpu_to_be32(OP_SETCLIENTID);
1589 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1591 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1592 p = reserve_space(xdr, 4);
1593 *p = cpu_to_be32(setclientid->sc_prog);
1594 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1595 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1596 p = reserve_space(xdr, 4);
1597 *p = cpu_to_be32(setclientid->sc_cb_ident);
1599 hdr->replen += decode_setclientid_maxsz;
1602 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1606 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
1607 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
1608 p = xdr_encode_hyper(p, arg->clientid);
1609 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
1611 hdr->replen += decode_setclientid_confirm_maxsz;
1614 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1618 p = reserve_space(xdr, 4);
1619 *p = cpu_to_be32(OP_WRITE);
1621 encode_stateid(xdr, args->context, args->lock_context,
1624 p = reserve_space(xdr, 16);
1625 p = xdr_encode_hyper(p, args->offset);
1626 *p++ = cpu_to_be32(args->stable);
1627 *p = cpu_to_be32(args->count);
1629 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1631 hdr->replen += decode_write_maxsz;
1634 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1638 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1640 *p++ = cpu_to_be32(OP_DELEGRETURN);
1641 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1643 hdr->replen += decode_delegreturn_maxsz;
1646 #if defined(CONFIG_NFS_V4_1)
1647 /* NFSv4.1 operations */
1648 static void encode_exchange_id(struct xdr_stream *xdr,
1649 struct nfs41_exchange_id_args *args,
1650 struct compound_hdr *hdr)
1654 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
1655 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
1656 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
1658 encode_string(xdr, args->id_len, args->id);
1660 p = reserve_space(xdr, 12);
1661 *p++ = cpu_to_be32(args->flags);
1662 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
1663 *p = cpu_to_be32(0); /* zero length implementation id array */
1665 hdr->replen += decode_exchange_id_maxsz;
1668 static void encode_create_session(struct xdr_stream *xdr,
1669 struct nfs41_create_session_args *args,
1670 struct compound_hdr *hdr)
1673 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1675 struct nfs_client *clp = args->client;
1676 u32 max_resp_sz_cached;
1679 * Assumes OPEN is the biggest non-idempotent compound.
1680 * 2 is the verifier.
1682 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1683 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1685 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1688 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
1689 *p++ = cpu_to_be32(OP_CREATE_SESSION);
1690 p = xdr_encode_hyper(p, clp->cl_clientid);
1691 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1692 *p++ = cpu_to_be32(args->flags); /*flags */
1695 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1696 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1697 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1698 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1699 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1700 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1701 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1704 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1705 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1706 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1707 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1708 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1709 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1710 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1712 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1713 *p++ = cpu_to_be32(1);
1714 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1716 /* authsys_parms rfc1831 */
1717 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
1718 p = xdr_encode_opaque(p, machine_name, len);
1719 *p++ = cpu_to_be32(0); /* UID */
1720 *p++ = cpu_to_be32(0); /* GID */
1721 *p = cpu_to_be32(0); /* No more gids */
1723 hdr->replen += decode_create_session_maxsz;
1726 static void encode_destroy_session(struct xdr_stream *xdr,
1727 struct nfs4_session *session,
1728 struct compound_hdr *hdr)
1731 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
1732 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
1733 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1735 hdr->replen += decode_destroy_session_maxsz;
1738 static void encode_reclaim_complete(struct xdr_stream *xdr,
1739 struct nfs41_reclaim_complete_args *args,
1740 struct compound_hdr *hdr)
1744 p = reserve_space(xdr, 8);
1745 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1746 *p++ = cpu_to_be32(args->one_fs);
1748 hdr->replen += decode_reclaim_complete_maxsz;
1750 #endif /* CONFIG_NFS_V4_1 */
1752 static void encode_sequence(struct xdr_stream *xdr,
1753 const struct nfs4_sequence_args *args,
1754 struct compound_hdr *hdr)
1756 #if defined(CONFIG_NFS_V4_1)
1757 struct nfs4_session *session = args->sa_session;
1758 struct nfs4_slot_table *tp;
1759 struct nfs4_slot *slot;
1765 tp = &session->fc_slot_table;
1767 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1768 slot = tp->slots + args->sa_slotid;
1770 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
1771 *p++ = cpu_to_be32(OP_SEQUENCE);
1774 * Sessionid + seqid + slotid + max slotid + cache_this
1776 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1777 "max_slotid=%d cache_this=%d\n",
1779 ((u32 *)session->sess_id.data)[0],
1780 ((u32 *)session->sess_id.data)[1],
1781 ((u32 *)session->sess_id.data)[2],
1782 ((u32 *)session->sess_id.data)[3],
1783 slot->seq_nr, args->sa_slotid,
1784 tp->highest_used_slotid, args->sa_cache_this);
1785 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1786 *p++ = cpu_to_be32(slot->seq_nr);
1787 *p++ = cpu_to_be32(args->sa_slotid);
1788 *p++ = cpu_to_be32(tp->highest_used_slotid);
1789 *p = cpu_to_be32(args->sa_cache_this);
1791 hdr->replen += decode_sequence_maxsz;
1792 #endif /* CONFIG_NFS_V4_1 */
1795 #ifdef CONFIG_NFS_V4_1
1797 encode_getdeviceinfo(struct xdr_stream *xdr,
1798 const struct nfs4_getdeviceinfo_args *args,
1799 struct compound_hdr *hdr)
1803 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1804 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1805 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1806 NFS4_DEVICEID4_SIZE);
1807 *p++ = cpu_to_be32(args->pdev->layout_type);
1808 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1809 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1811 hdr->replen += decode_getdeviceinfo_maxsz;
1815 encode_layoutget(struct xdr_stream *xdr,
1816 const struct nfs4_layoutget_args *args,
1817 struct compound_hdr *hdr)
1821 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1822 *p++ = cpu_to_be32(OP_LAYOUTGET);
1823 *p++ = cpu_to_be32(0); /* Signal layout available */
1824 *p++ = cpu_to_be32(args->type);
1825 *p++ = cpu_to_be32(args->range.iomode);
1826 p = xdr_encode_hyper(p, args->range.offset);
1827 p = xdr_encode_hyper(p, args->range.length);
1828 p = xdr_encode_hyper(p, args->minlength);
1829 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1830 *p = cpu_to_be32(args->maxcount);
1832 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1836 (unsigned long)args->range.offset,
1837 (unsigned long)args->range.length,
1840 hdr->replen += decode_layoutget_maxsz;
1844 encode_layoutcommit(struct xdr_stream *xdr,
1845 const struct nfs4_layoutcommit_args *args,
1846 struct compound_hdr *hdr)
1850 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1851 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1853 p = reserve_space(xdr, 48 + NFS4_STATEID_SIZE);
1854 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1855 /* Only whole file layouts */
1856 p = xdr_encode_hyper(p, 0); /* offset */
1857 p = xdr_encode_hyper(p, NFS4_MAX_UINT64); /* length */
1858 *p++ = cpu_to_be32(0); /* reclaim */
1859 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1860 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1861 p = xdr_encode_hyper(p, args->lastbytewritten);
1862 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1863 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1864 *p++ = cpu_to_be32(0); /* no file layout payload */
1867 hdr->replen += decode_layoutcommit_maxsz;
1870 #endif /* CONFIG_NFS_V4_1 */
1873 * END OF "GENERIC" ENCODE ROUTINES.
1876 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1878 #if defined(CONFIG_NFS_V4_1)
1879 if (args->sa_session)
1880 return args->sa_session->clp->cl_mvops->minor_version;
1881 #endif /* CONFIG_NFS_V4_1 */
1886 * Encode an ACCESS request
1888 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1889 const struct nfs4_accessargs *args)
1891 struct compound_hdr hdr = {
1892 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1895 encode_compound_hdr(xdr, req, &hdr);
1896 encode_sequence(xdr, &args->seq_args, &hdr);
1897 encode_putfh(xdr, args->fh, &hdr);
1898 encode_access(xdr, args->access, &hdr);
1899 encode_getfattr(xdr, args->bitmask, &hdr);
1904 * Encode LOOKUP request
1906 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1907 const struct nfs4_lookup_arg *args)
1909 struct compound_hdr hdr = {
1910 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1913 encode_compound_hdr(xdr, req, &hdr);
1914 encode_sequence(xdr, &args->seq_args, &hdr);
1915 encode_putfh(xdr, args->dir_fh, &hdr);
1916 encode_lookup(xdr, args->name, &hdr);
1917 encode_getfh(xdr, &hdr);
1918 encode_getfattr(xdr, args->bitmask, &hdr);
1923 * Encode LOOKUP_ROOT request
1925 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
1926 struct xdr_stream *xdr,
1927 const struct nfs4_lookup_root_arg *args)
1929 struct compound_hdr hdr = {
1930 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1933 encode_compound_hdr(xdr, req, &hdr);
1934 encode_sequence(xdr, &args->seq_args, &hdr);
1935 encode_putrootfh(xdr, &hdr);
1936 encode_getfh(xdr, &hdr);
1937 encode_getfattr(xdr, args->bitmask, &hdr);
1942 * Encode REMOVE request
1944 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
1945 const struct nfs_removeargs *args)
1947 struct compound_hdr hdr = {
1948 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1951 encode_compound_hdr(xdr, req, &hdr);
1952 encode_sequence(xdr, &args->seq_args, &hdr);
1953 encode_putfh(xdr, args->fh, &hdr);
1954 encode_remove(xdr, &args->name, &hdr);
1955 encode_getfattr(xdr, args->bitmask, &hdr);
1960 * Encode RENAME request
1962 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
1963 const struct nfs_renameargs *args)
1965 struct compound_hdr hdr = {
1966 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1969 encode_compound_hdr(xdr, req, &hdr);
1970 encode_sequence(xdr, &args->seq_args, &hdr);
1971 encode_putfh(xdr, args->old_dir, &hdr);
1972 encode_savefh(xdr, &hdr);
1973 encode_putfh(xdr, args->new_dir, &hdr);
1974 encode_rename(xdr, args->old_name, args->new_name, &hdr);
1975 encode_getfattr(xdr, args->bitmask, &hdr);
1976 encode_restorefh(xdr, &hdr);
1977 encode_getfattr(xdr, args->bitmask, &hdr);
1982 * Encode LINK request
1984 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
1985 const struct nfs4_link_arg *args)
1987 struct compound_hdr hdr = {
1988 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1991 encode_compound_hdr(xdr, req, &hdr);
1992 encode_sequence(xdr, &args->seq_args, &hdr);
1993 encode_putfh(xdr, args->fh, &hdr);
1994 encode_savefh(xdr, &hdr);
1995 encode_putfh(xdr, args->dir_fh, &hdr);
1996 encode_link(xdr, args->name, &hdr);
1997 encode_getfattr(xdr, args->bitmask, &hdr);
1998 encode_restorefh(xdr, &hdr);
1999 encode_getfattr(xdr, args->bitmask, &hdr);
2004 * Encode CREATE request
2006 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2007 const struct nfs4_create_arg *args)
2009 struct compound_hdr hdr = {
2010 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2013 encode_compound_hdr(xdr, req, &hdr);
2014 encode_sequence(xdr, &args->seq_args, &hdr);
2015 encode_putfh(xdr, args->dir_fh, &hdr);
2016 encode_savefh(xdr, &hdr);
2017 encode_create(xdr, args, &hdr);
2018 encode_getfh(xdr, &hdr);
2019 encode_getfattr(xdr, args->bitmask, &hdr);
2020 encode_restorefh(xdr, &hdr);
2021 encode_getfattr(xdr, args->bitmask, &hdr);
2026 * Encode SYMLINK request
2028 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2029 const struct nfs4_create_arg *args)
2031 nfs4_xdr_enc_create(req, xdr, args);
2035 * Encode GETATTR request
2037 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2038 const struct nfs4_getattr_arg *args)
2040 struct compound_hdr hdr = {
2041 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2044 encode_compound_hdr(xdr, req, &hdr);
2045 encode_sequence(xdr, &args->seq_args, &hdr);
2046 encode_putfh(xdr, args->fh, &hdr);
2047 encode_getfattr(xdr, args->bitmask, &hdr);
2052 * Encode a CLOSE request
2054 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2055 struct nfs_closeargs *args)
2057 struct compound_hdr hdr = {
2058 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2061 encode_compound_hdr(xdr, req, &hdr);
2062 encode_sequence(xdr, &args->seq_args, &hdr);
2063 encode_putfh(xdr, args->fh, &hdr);
2064 encode_close(xdr, args, &hdr);
2065 encode_getfattr(xdr, args->bitmask, &hdr);
2070 * Encode an OPEN request
2072 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2073 struct nfs_openargs *args)
2075 struct compound_hdr hdr = {
2076 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2079 encode_compound_hdr(xdr, req, &hdr);
2080 encode_sequence(xdr, &args->seq_args, &hdr);
2081 encode_putfh(xdr, args->fh, &hdr);
2082 encode_savefh(xdr, &hdr);
2083 encode_open(xdr, args, &hdr);
2084 encode_getfh(xdr, &hdr);
2085 encode_getfattr(xdr, args->bitmask, &hdr);
2086 encode_restorefh(xdr, &hdr);
2087 encode_getfattr(xdr, args->bitmask, &hdr);
2092 * Encode an OPEN_CONFIRM request
2094 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2095 struct xdr_stream *xdr,
2096 struct nfs_open_confirmargs *args)
2098 struct compound_hdr hdr = {
2102 encode_compound_hdr(xdr, req, &hdr);
2103 encode_putfh(xdr, args->fh, &hdr);
2104 encode_open_confirm(xdr, args, &hdr);
2109 * Encode an OPEN request with no attributes.
2111 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2112 struct xdr_stream *xdr,
2113 struct nfs_openargs *args)
2115 struct compound_hdr hdr = {
2116 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2119 encode_compound_hdr(xdr, req, &hdr);
2120 encode_sequence(xdr, &args->seq_args, &hdr);
2121 encode_putfh(xdr, args->fh, &hdr);
2122 encode_open(xdr, args, &hdr);
2123 encode_getfattr(xdr, args->bitmask, &hdr);
2128 * Encode an OPEN_DOWNGRADE request
2130 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2131 struct xdr_stream *xdr,
2132 struct nfs_closeargs *args)
2134 struct compound_hdr hdr = {
2135 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2138 encode_compound_hdr(xdr, req, &hdr);
2139 encode_sequence(xdr, &args->seq_args, &hdr);
2140 encode_putfh(xdr, args->fh, &hdr);
2141 encode_open_downgrade(xdr, args, &hdr);
2142 encode_getfattr(xdr, args->bitmask, &hdr);
2147 * Encode a LOCK request
2149 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2150 struct nfs_lock_args *args)
2152 struct compound_hdr hdr = {
2153 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2156 encode_compound_hdr(xdr, req, &hdr);
2157 encode_sequence(xdr, &args->seq_args, &hdr);
2158 encode_putfh(xdr, args->fh, &hdr);
2159 encode_lock(xdr, args, &hdr);
2164 * Encode a LOCKT request
2166 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2167 struct nfs_lockt_args *args)
2169 struct compound_hdr hdr = {
2170 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2173 encode_compound_hdr(xdr, req, &hdr);
2174 encode_sequence(xdr, &args->seq_args, &hdr);
2175 encode_putfh(xdr, args->fh, &hdr);
2176 encode_lockt(xdr, args, &hdr);
2181 * Encode a LOCKU request
2183 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2184 struct nfs_locku_args *args)
2186 struct compound_hdr hdr = {
2187 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2190 encode_compound_hdr(xdr, req, &hdr);
2191 encode_sequence(xdr, &args->seq_args, &hdr);
2192 encode_putfh(xdr, args->fh, &hdr);
2193 encode_locku(xdr, args, &hdr);
2197 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2198 struct xdr_stream *xdr,
2199 struct nfs_release_lockowner_args *args)
2201 struct compound_hdr hdr = {
2205 encode_compound_hdr(xdr, req, &hdr);
2206 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2211 * Encode a READLINK request
2213 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2214 const struct nfs4_readlink *args)
2216 struct compound_hdr hdr = {
2217 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2220 encode_compound_hdr(xdr, req, &hdr);
2221 encode_sequence(xdr, &args->seq_args, &hdr);
2222 encode_putfh(xdr, args->fh, &hdr);
2223 encode_readlink(xdr, args, req, &hdr);
2225 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2226 args->pgbase, args->pglen);
2231 * Encode a READDIR request
2233 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2234 const struct nfs4_readdir_arg *args)
2236 struct compound_hdr hdr = {
2237 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2240 encode_compound_hdr(xdr, req, &hdr);
2241 encode_sequence(xdr, &args->seq_args, &hdr);
2242 encode_putfh(xdr, args->fh, &hdr);
2243 encode_readdir(xdr, args, req, &hdr);
2245 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2246 args->pgbase, args->count);
2247 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2248 __func__, hdr.replen << 2, args->pages,
2249 args->pgbase, args->count);
2254 * Encode a READ request
2256 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2257 struct nfs_readargs *args)
2259 struct compound_hdr hdr = {
2260 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2263 encode_compound_hdr(xdr, req, &hdr);
2264 encode_sequence(xdr, &args->seq_args, &hdr);
2265 encode_putfh(xdr, args->fh, &hdr);
2266 encode_read(xdr, args, &hdr);
2268 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2269 args->pages, args->pgbase, args->count);
2270 req->rq_rcv_buf.flags |= XDRBUF_READ;
2275 * Encode an SETATTR request
2277 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2278 struct nfs_setattrargs *args)
2280 struct compound_hdr hdr = {
2281 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2284 encode_compound_hdr(xdr, req, &hdr);
2285 encode_sequence(xdr, &args->seq_args, &hdr);
2286 encode_putfh(xdr, args->fh, &hdr);
2287 encode_setattr(xdr, args, args->server, &hdr);
2288 encode_getfattr(xdr, args->bitmask, &hdr);
2293 * Encode a GETACL request
2295 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2296 struct nfs_getaclargs *args)
2298 struct compound_hdr hdr = {
2299 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2303 encode_compound_hdr(xdr, req, &hdr);
2304 encode_sequence(xdr, &args->seq_args, &hdr);
2305 encode_putfh(xdr, args->fh, &hdr);
2306 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
2307 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2309 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2310 args->acl_pages, args->acl_pgbase, args->acl_len);
2315 * Encode a WRITE request
2317 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2318 struct nfs_writeargs *args)
2320 struct compound_hdr hdr = {
2321 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2324 encode_compound_hdr(xdr, req, &hdr);
2325 encode_sequence(xdr, &args->seq_args, &hdr);
2326 encode_putfh(xdr, args->fh, &hdr);
2327 encode_write(xdr, args, &hdr);
2328 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2330 encode_getfattr(xdr, args->bitmask, &hdr);
2337 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2338 struct nfs_writeargs *args)
2340 struct compound_hdr hdr = {
2341 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2344 encode_compound_hdr(xdr, req, &hdr);
2345 encode_sequence(xdr, &args->seq_args, &hdr);
2346 encode_putfh(xdr, args->fh, &hdr);
2347 encode_commit(xdr, args, &hdr);
2349 encode_getfattr(xdr, args->bitmask, &hdr);
2356 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2357 struct nfs4_fsinfo_arg *args)
2359 struct compound_hdr hdr = {
2360 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2363 encode_compound_hdr(xdr, req, &hdr);
2364 encode_sequence(xdr, &args->seq_args, &hdr);
2365 encode_putfh(xdr, args->fh, &hdr);
2366 encode_fsinfo(xdr, args->bitmask, &hdr);
2371 * a PATHCONF request
2373 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2374 const struct nfs4_pathconf_arg *args)
2376 struct compound_hdr hdr = {
2377 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2380 encode_compound_hdr(xdr, req, &hdr);
2381 encode_sequence(xdr, &args->seq_args, &hdr);
2382 encode_putfh(xdr, args->fh, &hdr);
2383 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2391 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2392 const struct nfs4_statfs_arg *args)
2394 struct compound_hdr hdr = {
2395 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2398 encode_compound_hdr(xdr, req, &hdr);
2399 encode_sequence(xdr, &args->seq_args, &hdr);
2400 encode_putfh(xdr, args->fh, &hdr);
2401 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2402 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2407 * GETATTR_BITMAP request
2409 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2410 struct xdr_stream *xdr,
2411 struct nfs4_server_caps_arg *args)
2413 struct compound_hdr hdr = {
2414 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2417 encode_compound_hdr(xdr, req, &hdr);
2418 encode_sequence(xdr, &args->seq_args, &hdr);
2419 encode_putfh(xdr, args->fhandle, &hdr);
2420 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2421 FATTR4_WORD0_LINK_SUPPORT|
2422 FATTR4_WORD0_SYMLINK_SUPPORT|
2423 FATTR4_WORD0_ACLSUPPORT, &hdr);
2430 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2431 struct nfs_client *clp)
2433 struct compound_hdr hdr = {
2437 encode_compound_hdr(xdr, req, &hdr);
2438 encode_renew(xdr, clp, &hdr);
2443 * a SETCLIENTID request
2445 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2446 struct xdr_stream *xdr,
2447 struct nfs4_setclientid *sc)
2449 struct compound_hdr hdr = {
2453 encode_compound_hdr(xdr, req, &hdr);
2454 encode_setclientid(xdr, sc, &hdr);
2459 * a SETCLIENTID_CONFIRM request
2461 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2462 struct xdr_stream *xdr,
2463 struct nfs4_setclientid_res *arg)
2465 struct compound_hdr hdr = {
2468 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2470 encode_compound_hdr(xdr, req, &hdr);
2471 encode_setclientid_confirm(xdr, arg, &hdr);
2472 encode_putrootfh(xdr, &hdr);
2473 encode_fsinfo(xdr, lease_bitmap, &hdr);
2478 * DELEGRETURN request
2480 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2481 struct xdr_stream *xdr,
2482 const struct nfs4_delegreturnargs *args)
2484 struct compound_hdr hdr = {
2485 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2488 encode_compound_hdr(xdr, req, &hdr);
2489 encode_sequence(xdr, &args->seq_args, &hdr);
2490 encode_putfh(xdr, args->fhandle, &hdr);
2491 encode_delegreturn(xdr, args->stateid, &hdr);
2492 encode_getfattr(xdr, args->bitmask, &hdr);
2497 * Encode FS_LOCATIONS request
2499 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2500 struct xdr_stream *xdr,
2501 struct nfs4_fs_locations_arg *args)
2503 struct compound_hdr hdr = {
2504 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2508 encode_compound_hdr(xdr, req, &hdr);
2509 encode_sequence(xdr, &args->seq_args, &hdr);
2510 encode_putfh(xdr, args->dir_fh, &hdr);
2511 encode_lookup(xdr, args->name, &hdr);
2512 replen = hdr.replen; /* get the attribute into args->page */
2513 encode_fs_locations(xdr, args->bitmask, &hdr);
2515 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2520 #if defined(CONFIG_NFS_V4_1)
2522 * EXCHANGE_ID request
2524 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2525 struct xdr_stream *xdr,
2526 struct nfs41_exchange_id_args *args)
2528 struct compound_hdr hdr = {
2529 .minorversion = args->client->cl_mvops->minor_version,
2532 encode_compound_hdr(xdr, req, &hdr);
2533 encode_exchange_id(xdr, args, &hdr);
2538 * a CREATE_SESSION request
2540 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2541 struct xdr_stream *xdr,
2542 struct nfs41_create_session_args *args)
2544 struct compound_hdr hdr = {
2545 .minorversion = args->client->cl_mvops->minor_version,
2548 encode_compound_hdr(xdr, req, &hdr);
2549 encode_create_session(xdr, args, &hdr);
2554 * a DESTROY_SESSION request
2556 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2557 struct xdr_stream *xdr,
2558 struct nfs4_session *session)
2560 struct compound_hdr hdr = {
2561 .minorversion = session->clp->cl_mvops->minor_version,
2564 encode_compound_hdr(xdr, req, &hdr);
2565 encode_destroy_session(xdr, session, &hdr);
2570 * a SEQUENCE request
2572 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2573 struct nfs4_sequence_args *args)
2575 struct compound_hdr hdr = {
2576 .minorversion = nfs4_xdr_minorversion(args),
2579 encode_compound_hdr(xdr, req, &hdr);
2580 encode_sequence(xdr, args, &hdr);
2585 * a GET_LEASE_TIME request
2587 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2588 struct xdr_stream *xdr,
2589 struct nfs4_get_lease_time_args *args)
2591 struct compound_hdr hdr = {
2592 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2594 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2596 encode_compound_hdr(xdr, req, &hdr);
2597 encode_sequence(xdr, &args->la_seq_args, &hdr);
2598 encode_putrootfh(xdr, &hdr);
2599 encode_fsinfo(xdr, lease_bitmap, &hdr);
2604 * a RECLAIM_COMPLETE request
2606 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2607 struct xdr_stream *xdr,
2608 struct nfs41_reclaim_complete_args *args)
2610 struct compound_hdr hdr = {
2611 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2614 encode_compound_hdr(xdr, req, &hdr);
2615 encode_sequence(xdr, &args->seq_args, &hdr);
2616 encode_reclaim_complete(xdr, args, &hdr);
2621 * Encode GETDEVICEINFO request
2623 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2624 struct xdr_stream *xdr,
2625 struct nfs4_getdeviceinfo_args *args)
2627 struct compound_hdr hdr = {
2628 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2631 encode_compound_hdr(xdr, req, &hdr);
2632 encode_sequence(xdr, &args->seq_args, &hdr);
2633 encode_getdeviceinfo(xdr, args, &hdr);
2635 /* set up reply kvec. Subtract notification bitmap max size (2)
2636 * so that notification bitmap is put in xdr_buf tail */
2637 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2638 args->pdev->pages, args->pdev->pgbase,
2645 * Encode LAYOUTGET request
2647 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2648 struct xdr_stream *xdr,
2649 struct nfs4_layoutget_args *args)
2651 struct compound_hdr hdr = {
2652 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2655 encode_compound_hdr(xdr, req, &hdr);
2656 encode_sequence(xdr, &args->seq_args, &hdr);
2657 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2658 encode_layoutget(xdr, args, &hdr);
2660 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2661 args->layout.pages, 0, args->layout.pglen);
2667 * Encode LAYOUTCOMMIT request
2669 static int nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2670 struct xdr_stream *xdr,
2671 struct nfs4_layoutcommit_args *args)
2673 struct compound_hdr hdr = {
2674 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2677 encode_compound_hdr(xdr, req, &hdr);
2678 encode_sequence(xdr, &args->seq_args, &hdr);
2679 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2680 encode_layoutcommit(xdr, args, &hdr);
2681 encode_getfattr(xdr, args->bitmask, &hdr);
2685 #endif /* CONFIG_NFS_V4_1 */
2687 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2689 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2690 "Remaining buffer length is %tu words.\n",
2691 func, xdr->end - xdr->p);
2694 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2698 p = xdr_inline_decode(xdr, 4);
2701 *len = be32_to_cpup(p);
2702 p = xdr_inline_decode(xdr, *len);
2705 *string = (char *)p;
2708 print_overflow_msg(__func__, xdr);
2712 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2716 p = xdr_inline_decode(xdr, 8);
2719 hdr->status = be32_to_cpup(p++);
2720 hdr->taglen = be32_to_cpup(p);
2722 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2725 hdr->tag = (char *)p;
2726 p += XDR_QUADLEN(hdr->taglen);
2727 hdr->nops = be32_to_cpup(p);
2728 if (unlikely(hdr->nops < 1))
2729 return nfs4_stat_to_errno(hdr->status);
2732 print_overflow_msg(__func__, xdr);
2736 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2742 p = xdr_inline_decode(xdr, 8);
2745 opnum = be32_to_cpup(p++);
2746 if (opnum != expected) {
2747 dprintk("nfs: Server returned operation"
2748 " %d but we issued a request for %d\n",
2752 nfserr = be32_to_cpup(p);
2753 if (nfserr != NFS_OK)
2754 return nfs4_stat_to_errno(nfserr);
2757 print_overflow_msg(__func__, xdr);
2762 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2765 unsigned int strlen;
2768 p = xdr_inline_decode(xdr, 12);
2770 return decode_opaque_inline(xdr, &strlen, &str);
2771 print_overflow_msg(__func__, xdr);
2775 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2780 p = xdr_inline_decode(xdr, 4);
2783 bmlen = be32_to_cpup(p);
2785 bitmap[0] = bitmap[1] = 0;
2786 p = xdr_inline_decode(xdr, (bmlen << 2));
2790 bitmap[0] = be32_to_cpup(p++);
2792 bitmap[1] = be32_to_cpup(p);
2796 print_overflow_msg(__func__, xdr);
2800 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
2804 p = xdr_inline_decode(xdr, 4);
2807 *attrlen = be32_to_cpup(p);
2811 print_overflow_msg(__func__, xdr);
2815 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2817 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2819 ret = decode_attr_bitmap(xdr, bitmask);
2820 if (unlikely(ret < 0))
2822 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2824 bitmask[0] = bitmask[1] = 0;
2825 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
2829 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2835 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2837 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2838 p = xdr_inline_decode(xdr, 4);
2841 *type = be32_to_cpup(p);
2842 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2843 dprintk("%s: bad type %d\n", __func__, *type);
2846 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2847 ret = NFS_ATTR_FATTR_TYPE;
2849 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
2852 print_overflow_msg(__func__, xdr);
2856 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2862 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2864 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2865 p = xdr_inline_decode(xdr, 8);
2868 xdr_decode_hyper(p, change);
2869 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2870 ret = NFS_ATTR_FATTR_CHANGE;
2872 dprintk("%s: change attribute=%Lu\n", __func__,
2873 (unsigned long long)*change);
2876 print_overflow_msg(__func__, xdr);
2880 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2886 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2888 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2889 p = xdr_inline_decode(xdr, 8);
2892 xdr_decode_hyper(p, size);
2893 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2894 ret = NFS_ATTR_FATTR_SIZE;
2896 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
2899 print_overflow_msg(__func__, xdr);
2903 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2908 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2910 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2911 p = xdr_inline_decode(xdr, 4);
2914 *res = be32_to_cpup(p);
2915 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2917 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
2920 print_overflow_msg(__func__, xdr);
2924 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2929 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2931 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2932 p = xdr_inline_decode(xdr, 4);
2935 *res = be32_to_cpup(p);
2936 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2938 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
2941 print_overflow_msg(__func__, xdr);
2945 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
2952 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2954 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2955 p = xdr_inline_decode(xdr, 16);
2958 p = xdr_decode_hyper(p, &fsid->major);
2959 xdr_decode_hyper(p, &fsid->minor);
2960 bitmap[0] &= ~FATTR4_WORD0_FSID;
2961 ret = NFS_ATTR_FATTR_FSID;
2963 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
2964 (unsigned long long)fsid->major,
2965 (unsigned long long)fsid->minor);
2968 print_overflow_msg(__func__, xdr);
2972 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2977 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2979 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2980 p = xdr_inline_decode(xdr, 4);
2983 *res = be32_to_cpup(p);
2984 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2986 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
2989 print_overflow_msg(__func__, xdr);
2993 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
2997 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
2999 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3000 p = xdr_inline_decode(xdr, 4);
3003 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3007 print_overflow_msg(__func__, xdr);
3011 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3017 memset(fh, 0, sizeof(*fh));
3019 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3021 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3022 p = xdr_inline_decode(xdr, 4);
3025 len = be32_to_cpup(p);
3026 if (len > NFS4_FHSIZE)
3028 p = xdr_inline_decode(xdr, len);
3032 memcpy(fh->data, p, len);
3035 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3039 print_overflow_msg(__func__, xdr);
3043 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3047 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3048 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3050 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3051 p = xdr_inline_decode(xdr, 4);
3054 *res = be32_to_cpup(p);
3055 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3057 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3060 print_overflow_msg(__func__, xdr);
3064 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3070 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3072 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3073 p = xdr_inline_decode(xdr, 8);
3076 xdr_decode_hyper(p, fileid);
3077 bitmap[0] &= ~FATTR4_WORD0_FILEID;
3078 ret = NFS_ATTR_FATTR_FILEID;
3080 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3083 print_overflow_msg(__func__, xdr);
3087 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3093 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3095 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3096 p = xdr_inline_decode(xdr, 8);
3099 xdr_decode_hyper(p, fileid);
3100 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3101 ret = NFS_ATTR_FATTR_FILEID;
3103 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3106 print_overflow_msg(__func__, xdr);
3110 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3116 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3118 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3119 p = xdr_inline_decode(xdr, 8);
3122 xdr_decode_hyper(p, res);
3123 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3125 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3128 print_overflow_msg(__func__, xdr);
3132 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3138 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3140 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3141 p = xdr_inline_decode(xdr, 8);
3144 xdr_decode_hyper(p, res);
3145 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3147 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3150 print_overflow_msg(__func__, xdr);
3154 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3160 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3162 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3163 p = xdr_inline_decode(xdr, 8);
3166 xdr_decode_hyper(p, res);
3167 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3169 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3172 print_overflow_msg(__func__, xdr);
3176 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3182 p = xdr_inline_decode(xdr, 4);
3185 n = be32_to_cpup(p);
3189 path->ncomponents = 0;
3190 while (path->ncomponents < n) {
3191 struct nfs4_string *component = &path->components[path->ncomponents];
3192 status = decode_opaque_inline(xdr, &component->len, &component->data);
3193 if (unlikely(status != 0))
3195 if (path->ncomponents != n)
3197 dprintk("%s", component->data);
3198 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3199 path->ncomponents++;
3201 dprintk("cannot parse %d components in path\n", n);
3209 /* a root pathname is sent as a zero component4 */
3210 path->ncomponents = 1;
3211 path->components[0].len=0;
3212 path->components[0].data=NULL;
3213 dprintk("path /\n");
3216 dprintk(" status %d", status);
3220 print_overflow_msg(__func__, xdr);
3224 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3230 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3233 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3235 dprintk("%s: fsroot ", __func__);
3236 status = decode_pathname(xdr, &res->fs_path);
3237 if (unlikely(status != 0))
3239 p = xdr_inline_decode(xdr, 4);
3242 n = be32_to_cpup(p);
3245 res->nlocations = 0;
3246 while (res->nlocations < n) {
3248 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
3250 p = xdr_inline_decode(xdr, 4);
3253 m = be32_to_cpup(p);
3256 dprintk("%s: servers ", __func__);
3257 while (loc->nservers < m) {
3258 struct nfs4_string *server = &loc->servers[loc->nservers];
3259 status = decode_opaque_inline(xdr, &server->len, &server->data);
3260 if (unlikely(status != 0))
3262 dprintk("%s ", server->data);
3263 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3267 dprintk("%s: using first %u of %u servers "
3268 "returned for location %u\n",
3270 NFS4_FS_LOCATION_MAXSERVERS,
3271 m, res->nlocations);
3272 for (i = loc->nservers; i < m; i++) {
3275 status = decode_opaque_inline(xdr, &len, &data);
3276 if (unlikely(status != 0))
3281 status = decode_pathname(xdr, &loc->rootpath);
3282 if (unlikely(status != 0))
3284 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
3287 if (res->nlocations != 0)
3288 status = NFS_ATTR_FATTR_V4_REFERRAL;
3290 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3293 print_overflow_msg(__func__, xdr);
3299 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3305 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3307 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3308 p = xdr_inline_decode(xdr, 8);
3311 xdr_decode_hyper(p, res);
3312 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3314 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3317 print_overflow_msg(__func__, xdr);
3321 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3327 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3329 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3330 p = xdr_inline_decode(xdr, 4);
3333 *maxlink = be32_to_cpup(p);
3334 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3336 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3339 print_overflow_msg(__func__, xdr);
3343 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3349 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3351 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3352 p = xdr_inline_decode(xdr, 4);
3355 *maxname = be32_to_cpup(p);
3356 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3358 dprintk("%s: maxname=%u\n", __func__, *maxname);
3361 print_overflow_msg(__func__, xdr);
3365 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3371 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3373 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3375 p = xdr_inline_decode(xdr, 8);
3378 xdr_decode_hyper(p, &maxread);
3379 if (maxread > 0x7FFFFFFF)
3380 maxread = 0x7FFFFFFF;
3381 *res = (uint32_t)maxread;
3382 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3384 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3387 print_overflow_msg(__func__, xdr);
3391 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3397 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3399 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3401 p = xdr_inline_decode(xdr, 8);
3404 xdr_decode_hyper(p, &maxwrite);
3405 if (maxwrite > 0x7FFFFFFF)
3406 maxwrite = 0x7FFFFFFF;
3407 *res = (uint32_t)maxwrite;
3408 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3410 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3413 print_overflow_msg(__func__, xdr);
3417 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3424 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3426 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3427 p = xdr_inline_decode(xdr, 4);
3430 tmp = be32_to_cpup(p);
3431 *mode = tmp & ~S_IFMT;
3432 bitmap[1] &= ~FATTR4_WORD1_MODE;
3433 ret = NFS_ATTR_FATTR_MODE;
3435 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3438 print_overflow_msg(__func__, xdr);
3442 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3448 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3450 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3451 p = xdr_inline_decode(xdr, 4);
3454 *nlink = be32_to_cpup(p);
3455 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3456 ret = NFS_ATTR_FATTR_NLINK;
3458 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3461 print_overflow_msg(__func__, xdr);
3465 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3466 const struct nfs_server *server, uint32_t *uid, int may_sleep)
3473 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3475 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3476 p = xdr_inline_decode(xdr, 4);
3479 len = be32_to_cpup(p);
3480 p = xdr_inline_decode(xdr, len);
3485 } else if (len < XDR_MAX_NETOBJ) {
3486 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3487 ret = NFS_ATTR_FATTR_OWNER;
3489 dprintk("%s: nfs_map_name_to_uid failed!\n",
3492 dprintk("%s: name too long (%u)!\n",
3494 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3496 dprintk("%s: uid=%d\n", __func__, (int)*uid);
3499 print_overflow_msg(__func__, xdr);
3503 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3504 const struct nfs_server *server, uint32_t *gid, int may_sleep)
3511 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3513 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3514 p = xdr_inline_decode(xdr, 4);
3517 len = be32_to_cpup(p);
3518 p = xdr_inline_decode(xdr, len);
3523 } else if (len < XDR_MAX_NETOBJ) {
3524 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3525 ret = NFS_ATTR_FATTR_GROUP;
3527 dprintk("%s: nfs_map_group_to_gid failed!\n",
3530 dprintk("%s: name too long (%u)!\n",
3532 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3534 dprintk("%s: gid=%d\n", __func__, (int)*gid);
3537 print_overflow_msg(__func__, xdr);
3541 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3543 uint32_t major = 0, minor = 0;
3548 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3550 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3553 p = xdr_inline_decode(xdr, 8);
3556 major = be32_to_cpup(p++);
3557 minor = be32_to_cpup(p);
3558 tmp = MKDEV(major, minor);
3559 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3561 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3562 ret = NFS_ATTR_FATTR_RDEV;
3564 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3567 print_overflow_msg(__func__, xdr);
3571 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3577 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3579 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3580 p = xdr_inline_decode(xdr, 8);
3583 xdr_decode_hyper(p, res);
3584 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3586 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3589 print_overflow_msg(__func__, xdr);
3593 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3599 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3601 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3602 p = xdr_inline_decode(xdr, 8);
3605 xdr_decode_hyper(p, res);
3606 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3608 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3611 print_overflow_msg(__func__, xdr);
3615 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3621 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3623 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3624 p = xdr_inline_decode(xdr, 8);
3627 xdr_decode_hyper(p, res);
3628 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3630 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
3633 print_overflow_msg(__func__, xdr);
3637 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3643 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3645 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3646 p = xdr_inline_decode(xdr, 8);
3649 xdr_decode_hyper(p, used);
3650 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
3651 ret = NFS_ATTR_FATTR_SPACE_USED;
3653 dprintk("%s: space used=%Lu\n", __func__,
3654 (unsigned long long)*used);
3657 print_overflow_msg(__func__, xdr);
3661 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3667 p = xdr_inline_decode(xdr, 12);
3670 p = xdr_decode_hyper(p, &sec);
3671 nsec = be32_to_cpup(p);
3672 time->tv_sec = (time_t)sec;
3673 time->tv_nsec = (long)nsec;
3676 print_overflow_msg(__func__, xdr);
3680 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3686 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3688 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3689 status = decode_attr_time(xdr, time);
3691 status = NFS_ATTR_FATTR_ATIME;
3692 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3694 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
3698 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3704 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3706 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3707 status = decode_attr_time(xdr, time);
3709 status = NFS_ATTR_FATTR_CTIME;
3710 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3712 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
3716 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3717 struct timespec *time)
3723 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3725 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3726 status = decode_attr_time(xdr, time);
3727 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3729 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3730 (long)time->tv_nsec);
3734 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3740 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3742 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3743 status = decode_attr_time(xdr, time);
3745 status = NFS_ATTR_FATTR_MTIME;
3746 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3748 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
3752 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
3754 unsigned int attrwords = XDR_QUADLEN(attrlen);
3755 unsigned int nwords = xdr->p - savep;
3757 if (unlikely(attrwords != nwords)) {
3758 dprintk("%s: server returned incorrect attribute length: "
3762 (attrwords < nwords) ? '<' : '>',
3769 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3773 p = xdr_inline_decode(xdr, 20);
3776 cinfo->atomic = be32_to_cpup(p++);
3777 p = xdr_decode_hyper(p, &cinfo->before);
3778 xdr_decode_hyper(p, &cinfo->after);
3781 print_overflow_msg(__func__, xdr);
3785 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3791 status = decode_op_hdr(xdr, OP_ACCESS);
3794 p = xdr_inline_decode(xdr, 8);
3797 supp = be32_to_cpup(p++);
3798 acc = be32_to_cpup(p);
3799 access->supported = supp;
3800 access->access = acc;
3803 print_overflow_msg(__func__, xdr);
3807 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
3811 p = xdr_inline_decode(xdr, len);
3813 memcpy(buf, p, len);
3816 print_overflow_msg(__func__, xdr);
3820 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3822 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
3825 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3829 status = decode_op_hdr(xdr, OP_CLOSE);
3831 nfs_increment_open_seqid(status, res->seqid);
3833 status = decode_stateid(xdr, &res->stateid);
3837 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3839 return decode_opaque_fixed(xdr, verifier, 8);
3842 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3846 status = decode_op_hdr(xdr, OP_COMMIT);
3848 status = decode_verifier(xdr, res->verf->verifier);
3852 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3858 status = decode_op_hdr(xdr, OP_CREATE);
3861 if ((status = decode_change_info(xdr, cinfo)))
3863 p = xdr_inline_decode(xdr, 4);
3866 bmlen = be32_to_cpup(p);
3867 p = xdr_inline_decode(xdr, bmlen << 2);
3871 print_overflow_msg(__func__, xdr);
3875 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3878 uint32_t attrlen, bitmap[2] = {0};
3881 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3883 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3885 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3887 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3889 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3891 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3893 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3895 status = verify_attr_len(xdr, savep, attrlen);
3897 dprintk("%s: xdr returned %d!\n", __func__, -status);
3901 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3904 uint32_t attrlen, bitmap[2] = {0};
3907 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3909 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3911 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3914 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3916 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3918 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3920 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3922 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3924 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3927 status = verify_attr_len(xdr, savep, attrlen);
3929 dprintk("%s: xdr returned %d!\n", __func__, -status);
3933 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3936 uint32_t attrlen, bitmap[2] = {0};
3939 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3941 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3943 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3946 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3948 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3951 status = verify_attr_len(xdr, savep, attrlen);
3953 dprintk("%s: xdr returned %d!\n", __func__, -status);
3957 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
3958 struct nfs_fattr *fattr, struct nfs_fh *fh,
3959 const struct nfs_server *server, int may_sleep)
3966 status = decode_attr_type(xdr, bitmap, &type);
3971 fattr->mode |= nfs_type2fmt[type];
3972 fattr->valid |= status;
3975 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3978 fattr->valid |= status;
3980 status = decode_attr_size(xdr, bitmap, &fattr->size);
3983 fattr->valid |= status;
3985 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3988 fattr->valid |= status;
3990 status = decode_attr_error(xdr, bitmap);
3994 status = decode_attr_filehandle(xdr, bitmap, fh);
3998 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4001 fattr->valid |= status;
4003 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
4004 struct nfs4_fs_locations,
4008 fattr->valid |= status;
4010 status = decode_attr_mode(xdr, bitmap, &fmode);
4014 fattr->mode |= fmode;
4015 fattr->valid |= status;
4018 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4021 fattr->valid |= status;
4023 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
4026 fattr->valid |= status;
4028 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
4031 fattr->valid |= status;
4033 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4036 fattr->valid |= status;
4038 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4041 fattr->valid |= status;
4043 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4046 fattr->valid |= status;
4048 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4051 fattr->valid |= status;
4053 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4056 fattr->valid |= status;
4058 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
4061 if (status != 0 && !(fattr->valid & status)) {
4062 fattr->fileid = fileid;
4063 fattr->valid |= status;
4067 dprintk("%s: xdr returned %d\n", __func__, -status);
4071 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4072 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4079 status = decode_op_hdr(xdr, OP_GETATTR);
4083 status = decode_attr_bitmap(xdr, bitmap);
4087 status = decode_attr_length(xdr, &attrlen, &savep);
4091 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4095 status = verify_attr_len(xdr, savep, attrlen);
4097 dprintk("%s: xdr returned %d\n", __func__, -status);
4101 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4102 const struct nfs_server *server, int may_sleep)
4104 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4108 * Decode potentially multiple layout types. Currently we only support
4109 * one layout driver per file system.
4111 static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4112 uint32_t *layouttype)
4117 p = xdr_inline_decode(xdr, 4);
4120 num = be32_to_cpup(p);
4122 /* pNFS is not supported by the underlying file system */
4128 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4129 "per filesystem not supported\n", __func__);
4131 /* Decode and set first layout type, move xdr->p past unused types */
4132 p = xdr_inline_decode(xdr, num * 4);
4135 *layouttype = be32_to_cpup(p);
4138 print_overflow_msg(__func__, xdr);
4143 * The type of file system exported.
4144 * Note we must ensure that layouttype is set in any non-error case.
4146 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4147 uint32_t *layouttype)
4151 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4152 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4154 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4155 status = decode_first_pnfs_layout_type(xdr, layouttype);
4156 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4162 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4165 uint32_t attrlen, bitmap[2];
4168 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4170 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4172 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4175 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4177 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4179 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4181 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4183 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4184 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4186 fsinfo->wtpref = fsinfo->wtmax;
4187 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4190 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4194 status = verify_attr_len(xdr, savep, attrlen);
4196 dprintk("%s: xdr returned %d!\n", __func__, -status);
4200 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4206 /* Zero handle first to allow comparisons */
4207 memset(fh, 0, sizeof(*fh));
4209 status = decode_op_hdr(xdr, OP_GETFH);
4213 p = xdr_inline_decode(xdr, 4);
4216 len = be32_to_cpup(p);
4217 if (len > NFS4_FHSIZE)
4220 p = xdr_inline_decode(xdr, len);
4223 memcpy(fh->data, p, len);
4226 print_overflow_msg(__func__, xdr);
4230 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4234 status = decode_op_hdr(xdr, OP_LINK);
4237 return decode_change_info(xdr, cinfo);
4241 * We create the owner, so we know a proper owner.id length is 4.
4243 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4245 uint64_t offset, length, clientid;
4247 uint32_t namelen, type;
4249 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4252 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4253 p = xdr_decode_hyper(p, &length);
4254 type = be32_to_cpup(p++); /* 4 byte read */
4255 if (fl != NULL) { /* manipulate file lock */
4256 fl->fl_start = (loff_t)offset;
4257 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4258 if (length == ~(uint64_t)0)
4259 fl->fl_end = OFFSET_MAX;
4260 fl->fl_type = F_WRLCK;
4262 fl->fl_type = F_RDLCK;
4265 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4266 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4267 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4269 return -NFS4ERR_DENIED;
4271 print_overflow_msg(__func__, xdr);
4275 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4279 status = decode_op_hdr(xdr, OP_LOCK);
4283 status = decode_stateid(xdr, &res->stateid);
4284 if (unlikely(status))
4286 } else if (status == -NFS4ERR_DENIED)
4287 status = decode_lock_denied(xdr, NULL);
4288 if (res->open_seqid != NULL)
4289 nfs_increment_open_seqid(status, res->open_seqid);
4290 nfs_increment_lock_seqid(status, res->lock_seqid);
4295 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4298 status = decode_op_hdr(xdr, OP_LOCKT);
4299 if (status == -NFS4ERR_DENIED)
4300 return decode_lock_denied(xdr, res->denied);
4304 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
4308 status = decode_op_hdr(xdr, OP_LOCKU);
4310 nfs_increment_lock_seqid(status, res->seqid);
4312 status = decode_stateid(xdr, &res->stateid);
4316 static int decode_release_lockowner(struct xdr_stream *xdr)
4318 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4321 static int decode_lookup(struct xdr_stream *xdr)
4323 return decode_op_hdr(xdr, OP_LOOKUP);
4326 /* This is too sick! */
4327 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4330 uint32_t limit_type, nblocks, blocksize;
4332 p = xdr_inline_decode(xdr, 12);
4335 limit_type = be32_to_cpup(p++);
4336 switch (limit_type) {
4338 xdr_decode_hyper(p, maxsize);
4341 nblocks = be32_to_cpup(p++);
4342 blocksize = be32_to_cpup(p);
4343 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
4347 print_overflow_msg(__func__, xdr);
4351 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4354 uint32_t delegation_type;
4357 p = xdr_inline_decode(xdr, 4);
4360 delegation_type = be32_to_cpup(p);
4361 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4362 res->delegation_type = 0;
4365 status = decode_stateid(xdr, &res->delegation);
4366 if (unlikely(status))
4368 p = xdr_inline_decode(xdr, 4);
4371 res->do_recall = be32_to_cpup(p);
4373 switch (delegation_type) {
4374 case NFS4_OPEN_DELEGATE_READ:
4375 res->delegation_type = FMODE_READ;
4377 case NFS4_OPEN_DELEGATE_WRITE:
4378 res->delegation_type = FMODE_WRITE|FMODE_READ;
4379 if (decode_space_limit(xdr, &res->maxsize) < 0)
4382 return decode_ace(xdr, NULL, res->server->nfs_client);
4384 print_overflow_msg(__func__, xdr);
4388 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4391 uint32_t savewords, bmlen, i;
4394 status = decode_op_hdr(xdr, OP_OPEN);
4396 nfs_increment_open_seqid(status, res->seqid);
4398 status = decode_stateid(xdr, &res->stateid);
4399 if (unlikely(status))
4402 decode_change_info(xdr, &res->cinfo);
4404 p = xdr_inline_decode(xdr, 8);
4407 res->rflags = be32_to_cpup(p++);
4408 bmlen = be32_to_cpup(p);
4412 p = xdr_inline_decode(xdr, bmlen << 2);
4415 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4416 for (i = 0; i < savewords; ++i)
4417 res->attrset[i] = be32_to_cpup(p++);
4418 for (; i < NFS4_BITMAP_SIZE; i++)
4419 res->attrset[i] = 0;
4421 return decode_delegation(xdr, res);
4423 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
4426 print_overflow_msg(__func__, xdr);
4430 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4434 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
4436 nfs_increment_open_seqid(status, res->seqid);
4438 status = decode_stateid(xdr, &res->stateid);
4442 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4446 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
4448 nfs_increment_open_seqid(status, res->seqid);
4450 status = decode_stateid(xdr, &res->stateid);
4454 static int decode_putfh(struct xdr_stream *xdr)
4456 return decode_op_hdr(xdr, OP_PUTFH);
4459 static int decode_putrootfh(struct xdr_stream *xdr)
4461 return decode_op_hdr(xdr, OP_PUTROOTFH);
4464 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4466 struct kvec *iov = req->rq_rcv_buf.head;
4468 uint32_t count, eof, recvd, hdrlen;
4471 status = decode_op_hdr(xdr, OP_READ);
4474 p = xdr_inline_decode(xdr, 8);
4477 eof = be32_to_cpup(p++);
4478 count = be32_to_cpup(p);
4479 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
4480 recvd = req->rq_rcv_buf.len - hdrlen;
4481 if (count > recvd) {
4482 dprintk("NFS: server cheating in read reply: "
4483 "count %u > recvd %u\n", count, recvd);
4487 xdr_read_pages(xdr, count);
4492 print_overflow_msg(__func__, xdr);
4496 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4498 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4499 struct kvec *iov = rcvbuf->head;
4501 u32 recvd, pglen = rcvbuf->page_len;
4504 status = decode_op_hdr(xdr, OP_READDIR);
4506 status = decode_verifier(xdr, readdir->verifier.data);
4507 if (unlikely(status))
4509 dprintk("%s: verifier = %08x:%08x\n",
4511 ((u32 *)readdir->verifier.data)[0],
4512 ((u32 *)readdir->verifier.data)[1]);
4515 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4516 recvd = rcvbuf->len - hdrlen;
4519 xdr_read_pages(xdr, pglen);
4525 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4527 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4528 struct kvec *iov = rcvbuf->head;
4534 status = decode_op_hdr(xdr, OP_READLINK);
4538 /* Convert length of symlink */
4539 p = xdr_inline_decode(xdr, 4);
4542 len = be32_to_cpup(p);
4543 if (len >= rcvbuf->page_len || len <= 0) {
4544 dprintk("nfs: server returned giant symlink!\n");
4545 return -ENAMETOOLONG;
4547 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4548 recvd = req->rq_rcv_buf.len - hdrlen;
4550 dprintk("NFS: server cheating in readlink reply: "
4551 "count %u > recvd %u\n", len, recvd);
4554 xdr_read_pages(xdr, len);
4556 * The XDR encode routine has set things up so that
4557 * the link text will be copied directly into the
4558 * buffer. We just have to do overflow-checking,
4559 * and and null-terminate the text (the VFS expects
4560 * null-termination).
4562 xdr_terminate_string(rcvbuf, len);
4565 print_overflow_msg(__func__, xdr);
4569 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4573 status = decode_op_hdr(xdr, OP_REMOVE);
4576 status = decode_change_info(xdr, cinfo);
4581 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4582 struct nfs4_change_info *new_cinfo)
4586 status = decode_op_hdr(xdr, OP_RENAME);
4589 if ((status = decode_change_info(xdr, old_cinfo)))
4591 status = decode_change_info(xdr, new_cinfo);
4596 static int decode_renew(struct xdr_stream *xdr)
4598 return decode_op_hdr(xdr, OP_RENEW);
4602 decode_restorefh(struct xdr_stream *xdr)
4604 return decode_op_hdr(xdr, OP_RESTOREFH);
4607 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4613 struct kvec *iov = req->rq_rcv_buf.head;
4617 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4619 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4621 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4624 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4626 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
4630 /* We ignore &savep and don't do consistency checks on
4631 * the attr length. Let userspace figure it out.... */
4632 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4633 recvd = req->rq_rcv_buf.len - hdrlen;
4634 if (attrlen > recvd) {
4635 dprintk("NFS: server cheating in getattr"
4636 " acl reply: attrlen %u > recvd %u\n",
4640 xdr_read_pages(xdr, attrlen);
4643 status = -EOPNOTSUPP;
4650 decode_savefh(struct xdr_stream *xdr)
4652 return decode_op_hdr(xdr, OP_SAVEFH);
4655 static int decode_setattr(struct xdr_stream *xdr)
4661 status = decode_op_hdr(xdr, OP_SETATTR);
4664 p = xdr_inline_decode(xdr, 4);
4667 bmlen = be32_to_cpup(p);
4668 p = xdr_inline_decode(xdr, bmlen << 2);
4672 print_overflow_msg(__func__, xdr);
4676 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
4682 p = xdr_inline_decode(xdr, 8);
4685 opnum = be32_to_cpup(p++);
4686 if (opnum != OP_SETCLIENTID) {
4687 dprintk("nfs: decode_setclientid: Server returned operation"
4691 nfserr = be32_to_cpup(p);
4692 if (nfserr == NFS_OK) {
4693 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4696 p = xdr_decode_hyper(p, &res->clientid);
4697 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
4698 } else if (nfserr == NFSERR_CLID_INUSE) {
4701 /* skip netid string */
4702 p = xdr_inline_decode(xdr, 4);
4705 len = be32_to_cpup(p);
4706 p = xdr_inline_decode(xdr, len);
4710 /* skip uaddr string */
4711 p = xdr_inline_decode(xdr, 4);
4714 len = be32_to_cpup(p);
4715 p = xdr_inline_decode(xdr, len);
4718 return -NFSERR_CLID_INUSE;
4720 return nfs4_stat_to_errno(nfserr);
4724 print_overflow_msg(__func__, xdr);
4728 static int decode_setclientid_confirm(struct xdr_stream *xdr)
4730 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4733 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4738 status = decode_op_hdr(xdr, OP_WRITE);
4742 p = xdr_inline_decode(xdr, 16);
4745 res->count = be32_to_cpup(p++);
4746 res->verf->committed = be32_to_cpup(p++);
4747 memcpy(res->verf->verifier, p, 8);
4750 print_overflow_msg(__func__, xdr);
4754 static int decode_delegreturn(struct xdr_stream *xdr)
4756 return decode_op_hdr(xdr, OP_DELEGRETURN);
4759 #if defined(CONFIG_NFS_V4_1)
4760 static int decode_exchange_id(struct xdr_stream *xdr,
4761 struct nfs41_exchange_id_res *res)
4767 struct nfs_client *clp = res->client;
4769 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4773 p = xdr_inline_decode(xdr, 8);
4776 xdr_decode_hyper(p, &clp->cl_clientid);
4777 p = xdr_inline_decode(xdr, 12);
4780 clp->cl_seqid = be32_to_cpup(p++);
4781 clp->cl_exchange_flags = be32_to_cpup(p++);
4783 /* We ask for SP4_NONE */
4784 dummy = be32_to_cpup(p);
4785 if (dummy != SP4_NONE)
4788 /* Throw away minor_id */
4789 p = xdr_inline_decode(xdr, 8);
4793 /* Throw away Major id */
4794 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4795 if (unlikely(status))
4798 /* Throw away server_scope */
4799 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4800 if (unlikely(status))
4803 /* Throw away Implementation id array */
4804 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4805 if (unlikely(status))
4810 print_overflow_msg(__func__, xdr);
4814 static int decode_chan_attrs(struct xdr_stream *xdr,
4815 struct nfs4_channel_attrs *attrs)
4820 p = xdr_inline_decode(xdr, 28);
4823 attrs->headerpadsz = be32_to_cpup(p++);
4824 attrs->max_rqst_sz = be32_to_cpup(p++);
4825 attrs->max_resp_sz = be32_to_cpup(p++);
4826 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4827 attrs->max_ops = be32_to_cpup(p++);
4828 attrs->max_reqs = be32_to_cpup(p++);
4829 nr_attrs = be32_to_cpup(p);
4830 if (unlikely(nr_attrs > 1)) {
4831 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4832 __func__, nr_attrs);
4835 if (nr_attrs == 1) {
4836 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4842 print_overflow_msg(__func__, xdr);
4846 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4848 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
4851 static int decode_create_session(struct xdr_stream *xdr,
4852 struct nfs41_create_session_res *res)
4856 struct nfs_client *clp = res->client;
4857 struct nfs4_session *session = clp->cl_session;
4859 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
4861 status = decode_sessionid(xdr, &session->sess_id);
4862 if (unlikely(status))
4866 p = xdr_inline_decode(xdr, 8);
4869 clp->cl_seqid = be32_to_cpup(p++);
4870 session->flags = be32_to_cpup(p);
4872 /* Channel attributes */
4873 status = decode_chan_attrs(xdr, &session->fc_attrs);
4875 status = decode_chan_attrs(xdr, &session->bc_attrs);
4878 print_overflow_msg(__func__, xdr);
4882 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4884 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4887 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
4889 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
4891 #endif /* CONFIG_NFS_V4_1 */
4893 static int decode_sequence(struct xdr_stream *xdr,
4894 struct nfs4_sequence_res *res,
4895 struct rpc_rqst *rqstp)
4897 #if defined(CONFIG_NFS_V4_1)
4898 struct nfs4_sessionid id;
4903 if (!res->sr_session)
4906 status = decode_op_hdr(xdr, OP_SEQUENCE);
4908 status = decode_sessionid(xdr, &id);
4909 if (unlikely(status))
4913 * If the server returns different values for sessionID, slotID or
4914 * sequence number, the server is looney tunes.
4916 status = -EREMOTEIO;
4918 if (memcmp(id.data, res->sr_session->sess_id.data,
4919 NFS4_MAX_SESSIONID_LEN)) {
4920 dprintk("%s Invalid session id\n", __func__);
4924 p = xdr_inline_decode(xdr, 20);
4929 dummy = be32_to_cpup(p++);
4930 if (dummy != res->sr_slot->seq_nr) {
4931 dprintk("%s Invalid sequence number\n", __func__);
4935 dummy = be32_to_cpup(p++);
4936 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
4937 dprintk("%s Invalid slot id\n", __func__);
4940 /* highest slot id - currently not processed */
4941 dummy = be32_to_cpup(p++);
4942 /* target highest slot id - currently not processed */
4943 dummy = be32_to_cpup(p++);
4945 res->sr_status_flags = be32_to_cpup(p);
4948 res->sr_status = status;
4951 print_overflow_msg(__func__, xdr);
4954 #else /* CONFIG_NFS_V4_1 */
4956 #endif /* CONFIG_NFS_V4_1 */
4959 #if defined(CONFIG_NFS_V4_1)
4961 static int decode_getdeviceinfo(struct xdr_stream *xdr,
4962 struct pnfs_device *pdev)
4968 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
4970 if (status == -ETOOSMALL) {
4971 p = xdr_inline_decode(xdr, 4);
4974 pdev->mincount = be32_to_cpup(p);
4975 dprintk("%s: Min count too small. mincnt = %u\n",
4976 __func__, pdev->mincount);
4981 p = xdr_inline_decode(xdr, 8);
4984 type = be32_to_cpup(p++);
4985 if (type != pdev->layout_type) {
4986 dprintk("%s: layout mismatch req: %u pdev: %u\n",
4987 __func__, pdev->layout_type, type);
4991 * Get the length of the opaque device_addr4. xdr_read_pages places
4992 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
4993 * and places the remaining xdr data in xdr_buf->tail
4995 pdev->mincount = be32_to_cpup(p);
4996 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
4998 /* Parse notification bitmap, verifying that it is zero. */
4999 p = xdr_inline_decode(xdr, 4);
5002 len = be32_to_cpup(p);
5006 p = xdr_inline_decode(xdr, 4 * len);
5009 for (i = 0; i < len; i++, p++) {
5010 if (be32_to_cpup(p)) {
5011 dprintk("%s: notifications not supported\n",
5019 print_overflow_msg(__func__, xdr);
5023 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5024 struct nfs4_layoutget_res *res)
5029 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5030 struct kvec *iov = rcvbuf->head;
5033 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5036 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5039 res->return_on_close = be32_to_cpup(p++);
5040 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5041 layout_count = be32_to_cpup(p);
5042 if (!layout_count) {
5043 dprintk("%s: server responded with empty layout array\n",
5048 p = xdr_inline_decode(xdr, 28);
5051 p = xdr_decode_hyper(p, &res->range.offset);
5052 p = xdr_decode_hyper(p, &res->range.length);
5053 res->range.iomode = be32_to_cpup(p++);
5054 res->type = be32_to_cpup(p++);
5055 res->layoutp->len = be32_to_cpup(p);
5057 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5059 (unsigned long)res->range.offset,
5060 (unsigned long)res->range.length,
5065 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5066 recvd = req->rq_rcv_buf.len - hdrlen;
5067 if (res->layoutp->len > recvd) {
5068 dprintk("NFS: server cheating in layoutget reply: "
5069 "layout len %u > recvd %u\n",
5070 res->layoutp->len, recvd);
5074 xdr_read_pages(xdr, res->layoutp->len);
5076 if (layout_count > 1) {
5077 /* We only handle a length one array at the moment. Any
5078 * further entries are just ignored. Note that this means
5079 * the client may see a response that is less than the
5080 * minimum it requested.
5082 dprintk("%s: server responded with %d layouts, dropping tail\n",
5083 __func__, layout_count);
5088 print_overflow_msg(__func__, xdr);
5092 static int decode_layoutcommit(struct xdr_stream *xdr,
5093 struct rpc_rqst *req,
5094 struct nfs4_layoutcommit_res *res)
5100 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5104 p = xdr_inline_decode(xdr, 4);
5107 sizechanged = be32_to_cpup(p);
5110 /* throw away new size */
5111 p = xdr_inline_decode(xdr, 8);
5117 print_overflow_msg(__func__, xdr);
5120 #endif /* CONFIG_NFS_V4_1 */
5123 * END OF "GENERIC" DECODE ROUTINES.
5127 * Decode OPEN_DOWNGRADE response
5129 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5130 struct xdr_stream *xdr,
5131 struct nfs_closeres *res)
5133 struct compound_hdr hdr;
5136 status = decode_compound_hdr(xdr, &hdr);
5139 status = decode_sequence(xdr, &res->seq_res, rqstp);
5142 status = decode_putfh(xdr);
5145 status = decode_open_downgrade(xdr, res);
5148 decode_getfattr(xdr, res->fattr, res->server,
5149 !RPC_IS_ASYNC(rqstp->rq_task));
5155 * Decode ACCESS response
5157 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5158 struct nfs4_accessres *res)
5160 struct compound_hdr hdr;
5163 status = decode_compound_hdr(xdr, &hdr);
5166 status = decode_sequence(xdr, &res->seq_res, rqstp);
5169 status = decode_putfh(xdr);
5172 status = decode_access(xdr, res);
5175 decode_getfattr(xdr, res->fattr, res->server,
5176 !RPC_IS_ASYNC(rqstp->rq_task));
5182 * Decode LOOKUP response
5184 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5185 struct nfs4_lookup_res *res)
5187 struct compound_hdr hdr;
5190 status = decode_compound_hdr(xdr, &hdr);
5193 status = decode_sequence(xdr, &res->seq_res, rqstp);
5196 status = decode_putfh(xdr);
5199 status = decode_lookup(xdr);
5202 status = decode_getfh(xdr, res->fh);
5205 status = decode_getfattr(xdr, res->fattr, res->server
5206 ,!RPC_IS_ASYNC(rqstp->rq_task));
5212 * Decode LOOKUP_ROOT response
5214 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5215 struct xdr_stream *xdr,
5216 struct nfs4_lookup_res *res)
5218 struct compound_hdr hdr;
5221 status = decode_compound_hdr(xdr, &hdr);
5224 status = decode_sequence(xdr, &res->seq_res, rqstp);
5227 status = decode_putrootfh(xdr);
5230 status = decode_getfh(xdr, res->fh);
5232 status = decode_getfattr(xdr, res->fattr, res->server,
5233 !RPC_IS_ASYNC(rqstp->rq_task));
5239 * Decode REMOVE response
5241 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5242 struct nfs_removeres *res)
5244 struct compound_hdr hdr;
5247 status = decode_compound_hdr(xdr, &hdr);
5250 status = decode_sequence(xdr, &res->seq_res, rqstp);
5253 status = decode_putfh(xdr);
5256 status = decode_remove(xdr, &res->cinfo);
5259 decode_getfattr(xdr, res->dir_attr, res->server,
5260 !RPC_IS_ASYNC(rqstp->rq_task));
5266 * Decode RENAME response
5268 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5269 struct nfs_renameres *res)
5271 struct compound_hdr hdr;
5274 status = decode_compound_hdr(xdr, &hdr);
5277 status = decode_sequence(xdr, &res->seq_res, rqstp);
5280 status = decode_putfh(xdr);
5283 status = decode_savefh(xdr);
5286 status = decode_putfh(xdr);
5289 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5292 /* Current FH is target directory */
5293 if (decode_getfattr(xdr, res->new_fattr, res->server,
5294 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5296 status = decode_restorefh(xdr);
5299 decode_getfattr(xdr, res->old_fattr, res->server,
5300 !RPC_IS_ASYNC(rqstp->rq_task));
5306 * Decode LINK response
5308 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5309 struct nfs4_link_res *res)
5311 struct compound_hdr hdr;
5314 status = decode_compound_hdr(xdr, &hdr);
5317 status = decode_sequence(xdr, &res->seq_res, rqstp);
5320 status = decode_putfh(xdr);
5323 status = decode_savefh(xdr);
5326 status = decode_putfh(xdr);
5329 status = decode_link(xdr, &res->cinfo);
5333 * Note order: OP_LINK leaves the directory as the current
5336 if (decode_getfattr(xdr, res->dir_attr, res->server,
5337 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5339 status = decode_restorefh(xdr);
5342 decode_getfattr(xdr, res->fattr, res->server,
5343 !RPC_IS_ASYNC(rqstp->rq_task));
5349 * Decode CREATE response
5351 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5352 struct nfs4_create_res *res)
5354 struct compound_hdr hdr;
5357 status = decode_compound_hdr(xdr, &hdr);
5360 status = decode_sequence(xdr, &res->seq_res, rqstp);
5363 status = decode_putfh(xdr);
5366 status = decode_savefh(xdr);
5369 status = decode_create(xdr, &res->dir_cinfo);
5372 status = decode_getfh(xdr, res->fh);
5375 if (decode_getfattr(xdr, res->fattr, res->server,
5376 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5378 status = decode_restorefh(xdr);
5381 decode_getfattr(xdr, res->dir_fattr, res->server,
5382 !RPC_IS_ASYNC(rqstp->rq_task));
5388 * Decode SYMLINK response
5390 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5391 struct nfs4_create_res *res)
5393 return nfs4_xdr_dec_create(rqstp, xdr, res);
5397 * Decode GETATTR response
5399 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5400 struct nfs4_getattr_res *res)
5402 struct compound_hdr hdr;
5405 status = decode_compound_hdr(xdr, &hdr);
5408 status = decode_sequence(xdr, &res->seq_res, rqstp);
5411 status = decode_putfh(xdr);
5414 status = decode_getfattr(xdr, res->fattr, res->server,
5415 !RPC_IS_ASYNC(rqstp->rq_task));
5421 * Encode an SETACL request
5423 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5424 struct nfs_setaclargs *args)
5426 struct compound_hdr hdr = {
5427 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
5430 encode_compound_hdr(xdr, req, &hdr);
5431 encode_sequence(xdr, &args->seq_args, &hdr);
5432 encode_putfh(xdr, args->fh, &hdr);
5433 encode_setacl(xdr, args, &hdr);
5438 * Decode SETACL response
5441 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5442 struct nfs_setaclres *res)
5444 struct compound_hdr hdr;
5447 status = decode_compound_hdr(xdr, &hdr);
5450 status = decode_sequence(xdr, &res->seq_res, rqstp);
5453 status = decode_putfh(xdr);
5456 status = decode_setattr(xdr);
5462 * Decode GETACL response
5465 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5466 struct nfs_getaclres *res)
5468 struct compound_hdr hdr;
5471 status = decode_compound_hdr(xdr, &hdr);
5474 status = decode_sequence(xdr, &res->seq_res, rqstp);
5477 status = decode_putfh(xdr);
5480 status = decode_getacl(xdr, rqstp, &res->acl_len);
5487 * Decode CLOSE response
5489 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5490 struct nfs_closeres *res)
5492 struct compound_hdr hdr;
5495 status = decode_compound_hdr(xdr, &hdr);
5498 status = decode_sequence(xdr, &res->seq_res, rqstp);
5501 status = decode_putfh(xdr);
5504 status = decode_close(xdr, res);
5508 * Note: Server may do delete on close for this file
5509 * in which case the getattr call will fail with
5510 * an ESTALE error. Shouldn't be a problem,
5511 * though, since fattr->valid will remain unset.
5513 decode_getfattr(xdr, res->fattr, res->server,
5514 !RPC_IS_ASYNC(rqstp->rq_task));
5520 * Decode OPEN response
5522 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5523 struct nfs_openres *res)
5525 struct compound_hdr hdr;
5528 status = decode_compound_hdr(xdr, &hdr);
5531 status = decode_sequence(xdr, &res->seq_res, rqstp);
5534 status = decode_putfh(xdr);
5537 status = decode_savefh(xdr);
5540 status = decode_open(xdr, res);
5543 if (decode_getfh(xdr, &res->fh) != 0)
5545 if (decode_getfattr(xdr, res->f_attr, res->server,
5546 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5548 if (decode_restorefh(xdr) != 0)
5550 decode_getfattr(xdr, res->dir_attr, res->server,
5551 !RPC_IS_ASYNC(rqstp->rq_task));
5557 * Decode OPEN_CONFIRM response
5559 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5560 struct xdr_stream *xdr,
5561 struct nfs_open_confirmres *res)
5563 struct compound_hdr hdr;
5566 status = decode_compound_hdr(xdr, &hdr);
5569 status = decode_putfh(xdr);
5572 status = decode_open_confirm(xdr, res);
5578 * Decode OPEN response
5580 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5581 struct xdr_stream *xdr,
5582 struct nfs_openres *res)
5584 struct compound_hdr hdr;
5587 status = decode_compound_hdr(xdr, &hdr);
5590 status = decode_sequence(xdr, &res->seq_res, rqstp);
5593 status = decode_putfh(xdr);
5596 status = decode_open(xdr, res);
5599 decode_getfattr(xdr, res->f_attr, res->server,
5600 !RPC_IS_ASYNC(rqstp->rq_task));
5606 * Decode SETATTR response
5608 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5609 struct xdr_stream *xdr,
5610 struct nfs_setattrres *res)
5612 struct compound_hdr hdr;
5615 status = decode_compound_hdr(xdr, &hdr);
5618 status = decode_sequence(xdr, &res->seq_res, rqstp);
5621 status = decode_putfh(xdr);
5624 status = decode_setattr(xdr);
5627 decode_getfattr(xdr, res->fattr, res->server,
5628 !RPC_IS_ASYNC(rqstp->rq_task));
5634 * Decode LOCK response
5636 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5637 struct nfs_lock_res *res)
5639 struct compound_hdr hdr;
5642 status = decode_compound_hdr(xdr, &hdr);
5645 status = decode_sequence(xdr, &res->seq_res, rqstp);
5648 status = decode_putfh(xdr);
5651 status = decode_lock(xdr, res);
5657 * Decode LOCKT response
5659 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5660 struct nfs_lockt_res *res)
5662 struct compound_hdr hdr;
5665 status = decode_compound_hdr(xdr, &hdr);
5668 status = decode_sequence(xdr, &res->seq_res, rqstp);
5671 status = decode_putfh(xdr);
5674 status = decode_lockt(xdr, res);
5680 * Decode LOCKU response
5682 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5683 struct nfs_locku_res *res)
5685 struct compound_hdr hdr;
5688 status = decode_compound_hdr(xdr, &hdr);
5691 status = decode_sequence(xdr, &res->seq_res, rqstp);
5694 status = decode_putfh(xdr);
5697 status = decode_locku(xdr, res);
5702 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5703 struct xdr_stream *xdr, void *dummy)
5705 struct compound_hdr hdr;
5708 status = decode_compound_hdr(xdr, &hdr);
5710 status = decode_release_lockowner(xdr);
5715 * Decode READLINK response
5717 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5718 struct xdr_stream *xdr,
5719 struct nfs4_readlink_res *res)
5721 struct compound_hdr hdr;
5724 status = decode_compound_hdr(xdr, &hdr);
5727 status = decode_sequence(xdr, &res->seq_res, rqstp);
5730 status = decode_putfh(xdr);
5733 status = decode_readlink(xdr, rqstp);
5739 * Decode READDIR response
5741 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5742 struct nfs4_readdir_res *res)
5744 struct compound_hdr hdr;
5747 status = decode_compound_hdr(xdr, &hdr);
5750 status = decode_sequence(xdr, &res->seq_res, rqstp);
5753 status = decode_putfh(xdr);
5756 status = decode_readdir(xdr, rqstp, res);
5762 * Decode Read response
5764 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5765 struct nfs_readres *res)
5767 struct compound_hdr hdr;
5770 status = decode_compound_hdr(xdr, &hdr);
5773 status = decode_sequence(xdr, &res->seq_res, rqstp);
5776 status = decode_putfh(xdr);
5779 status = decode_read(xdr, rqstp, res);
5781 status = res->count;
5787 * Decode WRITE response
5789 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5790 struct nfs_writeres *res)
5792 struct compound_hdr hdr;
5795 status = decode_compound_hdr(xdr, &hdr);
5798 status = decode_sequence(xdr, &res->seq_res, rqstp);
5801 status = decode_putfh(xdr);
5804 status = decode_write(xdr, res);
5808 decode_getfattr(xdr, res->fattr, res->server,
5809 !RPC_IS_ASYNC(rqstp->rq_task));
5811 status = res->count;
5817 * Decode COMMIT response
5819 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5820 struct nfs_writeres *res)
5822 struct compound_hdr hdr;
5825 status = decode_compound_hdr(xdr, &hdr);
5828 status = decode_sequence(xdr, &res->seq_res, rqstp);
5831 status = decode_putfh(xdr);
5834 status = decode_commit(xdr, res);
5838 decode_getfattr(xdr, res->fattr, res->server,
5839 !RPC_IS_ASYNC(rqstp->rq_task));
5845 * Decode FSINFO response
5847 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
5848 struct nfs4_fsinfo_res *res)
5850 struct compound_hdr hdr;
5853 status = decode_compound_hdr(xdr, &hdr);
5855 status = decode_sequence(xdr, &res->seq_res, req);
5857 status = decode_putfh(xdr);
5859 status = decode_fsinfo(xdr, res->fsinfo);
5864 * Decode PATHCONF response
5866 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
5867 struct nfs4_pathconf_res *res)
5869 struct compound_hdr hdr;
5872 status = decode_compound_hdr(xdr, &hdr);
5874 status = decode_sequence(xdr, &res->seq_res, req);
5876 status = decode_putfh(xdr);
5878 status = decode_pathconf(xdr, res->pathconf);
5883 * Decode STATFS response
5885 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
5886 struct nfs4_statfs_res *res)
5888 struct compound_hdr hdr;
5891 status = decode_compound_hdr(xdr, &hdr);
5893 status = decode_sequence(xdr, &res->seq_res, req);
5895 status = decode_putfh(xdr);
5897 status = decode_statfs(xdr, res->fsstat);
5902 * Decode GETATTR_BITMAP response
5904 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
5905 struct xdr_stream *xdr,
5906 struct nfs4_server_caps_res *res)
5908 struct compound_hdr hdr;
5911 status = decode_compound_hdr(xdr, &hdr);
5914 status = decode_sequence(xdr, &res->seq_res, req);
5917 status = decode_putfh(xdr);
5920 status = decode_server_caps(xdr, res);
5926 * Decode RENEW response
5928 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5931 struct compound_hdr hdr;
5934 status = decode_compound_hdr(xdr, &hdr);
5936 status = decode_renew(xdr);
5941 * Decode SETCLIENTID response
5943 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
5944 struct xdr_stream *xdr,
5945 struct nfs4_setclientid_res *res)
5947 struct compound_hdr hdr;
5950 status = decode_compound_hdr(xdr, &hdr);
5952 status = decode_setclientid(xdr, res);
5957 * Decode SETCLIENTID_CONFIRM response
5959 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
5960 struct xdr_stream *xdr,
5961 struct nfs_fsinfo *fsinfo)
5963 struct compound_hdr hdr;
5966 status = decode_compound_hdr(xdr, &hdr);
5968 status = decode_setclientid_confirm(xdr);
5970 status = decode_putrootfh(xdr);
5972 status = decode_fsinfo(xdr, fsinfo);
5977 * Decode DELEGRETURN response
5979 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
5980 struct xdr_stream *xdr,
5981 struct nfs4_delegreturnres *res)
5983 struct compound_hdr hdr;
5986 status = decode_compound_hdr(xdr, &hdr);
5989 status = decode_sequence(xdr, &res->seq_res, rqstp);
5992 status = decode_putfh(xdr);
5995 status = decode_delegreturn(xdr);
5998 decode_getfattr(xdr, res->fattr, res->server,
5999 !RPC_IS_ASYNC(rqstp->rq_task));
6005 * Decode FS_LOCATIONS response
6007 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6008 struct xdr_stream *xdr,
6009 struct nfs4_fs_locations_res *res)
6011 struct compound_hdr hdr;
6014 status = decode_compound_hdr(xdr, &hdr);
6017 status = decode_sequence(xdr, &res->seq_res, req);
6020 status = decode_putfh(xdr);
6023 status = decode_lookup(xdr);
6026 xdr_enter_page(xdr, PAGE_SIZE);
6027 status = decode_getfattr(xdr, &res->fs_locations->fattr,
6028 res->fs_locations->server,
6029 !RPC_IS_ASYNC(req->rq_task));
6034 #if defined(CONFIG_NFS_V4_1)
6036 * Decode EXCHANGE_ID response
6038 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6039 struct xdr_stream *xdr,
6042 struct compound_hdr hdr;
6045 status = decode_compound_hdr(xdr, &hdr);
6047 status = decode_exchange_id(xdr, res);
6052 * Decode CREATE_SESSION response
6054 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6055 struct xdr_stream *xdr,
6056 struct nfs41_create_session_res *res)
6058 struct compound_hdr hdr;
6061 status = decode_compound_hdr(xdr, &hdr);
6063 status = decode_create_session(xdr, res);
6068 * Decode DESTROY_SESSION response
6070 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6071 struct xdr_stream *xdr,
6074 struct compound_hdr hdr;
6077 status = decode_compound_hdr(xdr, &hdr);
6079 status = decode_destroy_session(xdr, res);
6084 * Decode SEQUENCE response
6086 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6087 struct xdr_stream *xdr,
6088 struct nfs4_sequence_res *res)
6090 struct compound_hdr hdr;
6093 status = decode_compound_hdr(xdr, &hdr);
6095 status = decode_sequence(xdr, res, rqstp);
6100 * Decode GET_LEASE_TIME response
6102 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6103 struct xdr_stream *xdr,
6104 struct nfs4_get_lease_time_res *res)
6106 struct compound_hdr hdr;
6109 status = decode_compound_hdr(xdr, &hdr);
6111 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
6113 status = decode_putrootfh(xdr);
6115 status = decode_fsinfo(xdr, res->lr_fsinfo);
6120 * Decode RECLAIM_COMPLETE response
6122 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6123 struct xdr_stream *xdr,
6124 struct nfs41_reclaim_complete_res *res)
6126 struct compound_hdr hdr;
6129 status = decode_compound_hdr(xdr, &hdr);
6131 status = decode_sequence(xdr, &res->seq_res, rqstp);
6133 status = decode_reclaim_complete(xdr, (void *)NULL);
6138 * Decode GETDEVINFO response
6140 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6141 struct xdr_stream *xdr,
6142 struct nfs4_getdeviceinfo_res *res)
6144 struct compound_hdr hdr;
6147 status = decode_compound_hdr(xdr, &hdr);
6150 status = decode_sequence(xdr, &res->seq_res, rqstp);
6153 status = decode_getdeviceinfo(xdr, res->pdev);
6159 * Decode LAYOUTGET response
6161 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6162 struct xdr_stream *xdr,
6163 struct nfs4_layoutget_res *res)
6165 struct compound_hdr hdr;
6168 status = decode_compound_hdr(xdr, &hdr);
6171 status = decode_sequence(xdr, &res->seq_res, rqstp);
6174 status = decode_putfh(xdr);
6177 status = decode_layoutget(xdr, rqstp, res);
6183 * Decode LAYOUTCOMMIT response
6185 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6186 struct xdr_stream *xdr,
6187 struct nfs4_layoutcommit_res *res)
6189 struct compound_hdr hdr;
6192 status = decode_compound_hdr(xdr, &hdr);
6195 status = decode_sequence(xdr, &res->seq_res, rqstp);
6198 status = decode_putfh(xdr);
6201 status = decode_layoutcommit(xdr, rqstp, res);
6204 decode_getfattr(xdr, res->fattr, res->server,
6205 !RPC_IS_ASYNC(rqstp->rq_task));
6209 #endif /* CONFIG_NFS_V4_1 */
6212 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6213 * the local page cache.
6214 * @xdr: XDR stream where entry resides
6215 * @entry: buffer to fill in with entry data
6216 * @plus: boolean indicating whether this should be a readdirplus entry
6218 * Returns zero if successful, otherwise a negative errno value is
6221 * This function is not invoked during READDIR reply decoding, but
6222 * rather whenever an application invokes the getdents(2) system call
6223 * on a directory already in our cache.
6225 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6228 uint32_t bitmap[2] = {0};
6230 __be32 *p = xdr_inline_decode(xdr, 4);
6233 if (*p == xdr_zero) {
6234 p = xdr_inline_decode(xdr, 4);
6243 p = xdr_inline_decode(xdr, 12);
6246 entry->prev_cookie = entry->cookie;
6247 p = xdr_decode_hyper(p, &entry->cookie);
6248 entry->len = be32_to_cpup(p);
6250 p = xdr_inline_decode(xdr, entry->len);
6253 entry->name = (const char *) p;
6256 * In case the server doesn't return an inode number,
6257 * we fake one here. (We don't use inode number 0,
6258 * since glibc seems to choke on it...)
6261 entry->fattr->valid = 0;
6263 if (decode_attr_bitmap(xdr, bitmap) < 0)
6266 if (decode_attr_length(xdr, &len, &p) < 0)
6269 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6270 entry->server, 1) < 0)
6272 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6273 entry->ino = entry->fattr->fileid;
6275 entry->d_type = DT_UNKNOWN;
6276 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6277 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6282 print_overflow_msg(__func__, xdr);
6287 * We need to translate between nfs status return values and
6288 * the local errno values which may not be the same.
6295 { NFS4ERR_PERM, -EPERM },
6296 { NFS4ERR_NOENT, -ENOENT },
6297 { NFS4ERR_IO, -errno_NFSERR_IO},
6298 { NFS4ERR_NXIO, -ENXIO },
6299 { NFS4ERR_ACCESS, -EACCES },
6300 { NFS4ERR_EXIST, -EEXIST },
6301 { NFS4ERR_XDEV, -EXDEV },
6302 { NFS4ERR_NOTDIR, -ENOTDIR },
6303 { NFS4ERR_ISDIR, -EISDIR },
6304 { NFS4ERR_INVAL, -EINVAL },
6305 { NFS4ERR_FBIG, -EFBIG },
6306 { NFS4ERR_NOSPC, -ENOSPC },
6307 { NFS4ERR_ROFS, -EROFS },
6308 { NFS4ERR_MLINK, -EMLINK },
6309 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6310 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6311 { NFS4ERR_DQUOT, -EDQUOT },
6312 { NFS4ERR_STALE, -ESTALE },
6313 { NFS4ERR_BADHANDLE, -EBADHANDLE },
6314 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6315 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6316 { NFS4ERR_TOOSMALL, -ETOOSMALL },
6317 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
6318 { NFS4ERR_BADTYPE, -EBADTYPE },
6319 { NFS4ERR_LOCKED, -EAGAIN },
6320 { NFS4ERR_SYMLINK, -ELOOP },
6321 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6322 { NFS4ERR_DEADLOCK, -EDEADLK },
6323 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
6324 * to be handled by a
6331 * Convert an NFS error code to a local one.
6332 * This one is used jointly by NFSv2 and NFSv3.
6335 nfs4_stat_to_errno(int stat)
6338 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6339 if (nfs_errtbl[i].stat == stat)
6340 return nfs_errtbl[i].errno;
6342 if (stat <= 10000 || stat > 10100) {
6343 /* The server is looney tunes. */
6346 /* If we cannot translate the error, the recovery routines should
6348 * Note: remaining NFSv4 error codes have values > 10000, so should
6349 * not conflict with native Linux error codes.
6354 #define PROC(proc, argtype, restype) \
6355 [NFSPROC4_CLNT_##proc] = { \
6356 .p_proc = NFSPROC4_COMPOUND, \
6357 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
6358 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
6359 .p_arglen = NFS4_##argtype##_sz, \
6360 .p_replen = NFS4_##restype##_sz, \
6361 .p_statidx = NFSPROC4_CLNT_##proc, \
6365 struct rpc_procinfo nfs4_procedures[] = {
6366 PROC(READ, enc_read, dec_read),
6367 PROC(WRITE, enc_write, dec_write),
6368 PROC(COMMIT, enc_commit, dec_commit),
6369 PROC(OPEN, enc_open, dec_open),
6370 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6371 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6372 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6373 PROC(CLOSE, enc_close, dec_close),
6374 PROC(SETATTR, enc_setattr, dec_setattr),
6375 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6376 PROC(RENEW, enc_renew, dec_renew),
6377 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6378 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6379 PROC(LOCK, enc_lock, dec_lock),
6380 PROC(LOCKT, enc_lockt, dec_lockt),
6381 PROC(LOCKU, enc_locku, dec_locku),
6382 PROC(ACCESS, enc_access, dec_access),
6383 PROC(GETATTR, enc_getattr, dec_getattr),
6384 PROC(LOOKUP, enc_lookup, dec_lookup),
6385 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6386 PROC(REMOVE, enc_remove, dec_remove),
6387 PROC(RENAME, enc_rename, dec_rename),
6388 PROC(LINK, enc_link, dec_link),
6389 PROC(SYMLINK, enc_symlink, dec_symlink),
6390 PROC(CREATE, enc_create, dec_create),
6391 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6392 PROC(STATFS, enc_statfs, dec_statfs),
6393 PROC(READLINK, enc_readlink, dec_readlink),
6394 PROC(READDIR, enc_readdir, dec_readdir),
6395 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6396 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6397 PROC(GETACL, enc_getacl, dec_getacl),
6398 PROC(SETACL, enc_setacl, dec_setacl),
6399 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6400 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
6401 #if defined(CONFIG_NFS_V4_1)
6402 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6403 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6404 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6405 PROC(SEQUENCE, enc_sequence, dec_sequence),
6406 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6407 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6408 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6409 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
6410 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
6411 #endif /* CONFIG_NFS_V4_1 */
6414 struct rpc_version nfs_version4 = {
6416 .nrprocs = ARRAY_SIZE(nfs4_procedures),
6417 .procs = nfs4_procedures