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/sunrpc/gss_api.h>
50 #include <linux/nfs.h>
51 #include <linux/nfs4.h>
52 #include <linux/nfs_fs.h>
53 #include <linux/nfs_idmap.h>
58 #define NFSDBG_FACILITY NFSDBG_XDR
60 /* Mapping from NFS error code to "errno" error code. */
61 #define errno_NFSERR_IO EIO
63 static int nfs4_stat_to_errno(int);
65 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
67 #define NFS4_MAXTAGLEN 20
69 #define NFS4_MAXTAGLEN 0
72 /* lock,open owner id:
73 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
75 #define open_owner_id_maxsz (1 + 1 + 4)
76 #define lock_owner_id_maxsz (1 + 1 + 4)
77 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
78 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
80 #define op_encode_hdr_maxsz (1)
81 #define op_decode_hdr_maxsz (2)
82 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
84 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
85 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
86 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
88 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
89 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
90 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
91 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
92 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
93 ((3+NFS4_FHSIZE) >> 2))
94 #define nfs4_fattr_bitmap_maxsz 4
95 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
96 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
97 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
98 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
99 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
100 /* This is based on getfattr, which uses the most attributes: */
101 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
102 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
103 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
104 nfs4_fattr_value_maxsz)
105 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
106 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
111 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
112 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
113 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
114 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
115 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
116 /* The 5 accounts for the PNFS attributes, and assumes that at most three
117 * layout types will be returned.
119 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
120 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
121 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
122 #define decode_renew_maxsz (op_decode_hdr_maxsz)
123 #define encode_setclientid_maxsz \
124 (op_encode_hdr_maxsz + \
125 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
126 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
128 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
129 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
131 #define decode_setclientid_maxsz \
132 (op_decode_hdr_maxsz + \
134 1024) /* large value for CLID_INUSE */
135 #define encode_setclientid_confirm_maxsz \
136 (op_encode_hdr_maxsz + \
137 3 + (NFS4_VERIFIER_SIZE >> 2))
138 #define decode_setclientid_confirm_maxsz \
139 (op_decode_hdr_maxsz)
140 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
141 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
142 #define encode_share_access_maxsz \
144 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
145 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
146 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
147 #define encode_open_maxsz (op_encode_hdr_maxsz + \
148 2 + encode_share_access_maxsz + 2 + \
149 open_owner_id_maxsz + \
150 encode_opentype_maxsz + \
151 encode_claim_null_maxsz)
152 #define decode_space_limit_maxsz (3)
153 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
154 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
155 decode_space_limit_maxsz + \
157 #define decode_change_info_maxsz (5)
158 #define decode_open_maxsz (op_decode_hdr_maxsz + \
159 decode_stateid_maxsz + \
160 decode_change_info_maxsz + 1 + \
161 nfs4_fattr_bitmap_maxsz + \
162 decode_delegation_maxsz)
163 #define encode_open_confirm_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1)
166 #define decode_open_confirm_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169 #define encode_open_downgrade_maxsz \
170 (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + 1 + \
172 encode_share_access_maxsz)
173 #define decode_open_downgrade_maxsz \
174 (op_decode_hdr_maxsz + \
175 decode_stateid_maxsz)
176 #define encode_close_maxsz (op_encode_hdr_maxsz + \
177 1 + encode_stateid_maxsz)
178 #define decode_close_maxsz (op_decode_hdr_maxsz + \
179 decode_stateid_maxsz)
180 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
181 encode_stateid_maxsz + \
183 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
184 nfs4_fattr_bitmap_maxsz)
185 #define encode_read_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + 3)
187 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
188 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
189 2 + encode_verifier_maxsz + 5)
190 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
191 decode_verifier_maxsz)
192 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
193 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
194 #define encode_write_maxsz (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + 4)
196 #define decode_write_maxsz (op_decode_hdr_maxsz + \
197 2 + decode_verifier_maxsz)
198 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
199 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
200 decode_verifier_maxsz)
201 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
203 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
204 decode_change_info_maxsz)
205 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
207 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
208 decode_change_info_maxsz + \
209 decode_change_info_maxsz)
210 #define encode_link_maxsz (op_encode_hdr_maxsz + \
212 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
213 #define encode_lockowner_maxsz (7)
214 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
216 1 + encode_stateid_maxsz + 1 + \
217 encode_lockowner_maxsz)
218 #define decode_lock_denied_maxsz \
219 (8 + decode_lockowner_maxsz)
220 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
221 decode_lock_denied_maxsz)
222 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
223 encode_lockowner_maxsz)
224 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
225 decode_lock_denied_maxsz)
226 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
227 encode_stateid_maxsz + \
229 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
230 decode_stateid_maxsz)
231 #define encode_release_lockowner_maxsz \
232 (op_encode_hdr_maxsz + \
233 encode_lockowner_maxsz)
234 #define decode_release_lockowner_maxsz \
235 (op_decode_hdr_maxsz)
236 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
237 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
238 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
239 1 + nfs4_name_maxsz + \
242 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
243 #define encode_create_maxsz (op_encode_hdr_maxsz + \
244 1 + 2 + nfs4_name_maxsz + \
246 #define decode_create_maxsz (op_decode_hdr_maxsz + \
247 decode_change_info_maxsz + \
248 nfs4_fattr_bitmap_maxsz)
249 #define encode_statfs_maxsz (encode_getattr_maxsz)
250 #define decode_statfs_maxsz (decode_getattr_maxsz)
251 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
252 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
253 #define encode_getacl_maxsz (encode_getattr_maxsz)
254 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
255 nfs4_fattr_bitmap_maxsz + 1)
256 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
257 encode_stateid_maxsz + 3)
258 #define decode_setacl_maxsz (decode_setattr_maxsz)
259 #define encode_fs_locations_maxsz \
260 (encode_getattr_maxsz)
261 #define decode_fs_locations_maxsz \
263 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
264 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
266 #if defined(CONFIG_NFS_V4_1)
267 #define NFS4_MAX_MACHINE_NAME_LEN (64)
269 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
270 encode_verifier_maxsz + \
271 1 /* co_ownerid.len */ + \
272 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
275 0 /* SP4_NONE (for now) */ + \
276 1 /* zero implemetation id array */)
277 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
278 2 /* eir_clientid */ + \
279 1 /* eir_sequenceid */ + \
280 1 /* eir_flags */ + \
282 0 /* SP4_NONE (for now) */ + \
283 2 /* eir_server_owner.so_minor_id */ + \
284 /* eir_server_owner.so_major_id<> */ \
285 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
286 /* eir_server_scope<> */ \
287 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
288 1 /* eir_server_impl_id array length */ + \
289 0 /* ignored eir_server_impl_id contents */)
290 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
291 #define decode_channel_attrs_maxsz (6 + \
292 1 /* ca_rdma_ird.len */ + \
294 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
295 2 /* csa_clientid */ + \
296 1 /* csa_sequence */ + \
297 1 /* csa_flags */ + \
298 encode_channel_attrs_maxsz + \
299 encode_channel_attrs_maxsz + \
300 1 /* csa_cb_program */ + \
301 1 /* csa_sec_parms.len (1) */ + \
302 1 /* cb_secflavor (AUTH_SYS) */ + \
304 1 /* machinename.len */ + \
305 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
308 1 /* gids.len (0) */)
309 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
310 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
311 1 /* csr_sequence */ + \
312 1 /* csr_flags */ + \
313 decode_channel_attrs_maxsz + \
314 decode_channel_attrs_maxsz)
315 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
316 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
317 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
318 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
319 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
320 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
321 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
322 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
323 #define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
324 encode_verifier_maxsz)
325 #define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
326 2 /* nfs_cookie4 gdlr_cookie */ + \
327 decode_verifier_maxsz \
328 /* verifier4 gdlr_verifier */ + \
329 1 /* gdlr_deviceid_list count */ + \
330 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
331 NFS4_DEVICEID4_SIZE) \
332 /* gdlr_deviceid_list */ + \
333 1 /* bool gdlr_eof */)
334 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
335 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
336 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
337 1 /* layout type */ + \
338 1 /* opaque devaddr4 length */ + \
339 /* devaddr4 payload is read into page */ \
340 1 /* notification bitmap length */ + \
341 1 /* notification bitmap */)
342 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
343 encode_stateid_maxsz)
344 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
345 decode_stateid_maxsz + \
346 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
347 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
351 encode_stateid_maxsz + \
352 1 /* new offset (true) */ + \
353 2 /* last byte written */ + \
354 1 /* nt_timechanged (false) */ + \
355 1 /* layoutupdate4 layout type */ + \
356 1 /* NULL filelayout layoutupdate4 payload */)
357 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
358 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
359 encode_stateid_maxsz + \
360 1 /* FIXME: opaque lrf_body always empty at the moment */)
361 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
362 1 + decode_stateid_maxsz)
363 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
364 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
365 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
366 XDR_QUADLEN(NFS4_STATEID_SIZE))
367 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
368 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
369 XDR_QUADLEN(NFS4_STATEID_SIZE))
370 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
371 #else /* CONFIG_NFS_V4_1 */
372 #define encode_sequence_maxsz 0
373 #define decode_sequence_maxsz 0
374 #endif /* CONFIG_NFS_V4_1 */
376 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
377 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
378 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
379 encode_sequence_maxsz + \
380 encode_putfh_maxsz + \
382 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
383 decode_sequence_maxsz + \
384 decode_putfh_maxsz + \
386 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
387 encode_sequence_maxsz + \
388 encode_putfh_maxsz + \
389 encode_readlink_maxsz)
390 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
391 decode_sequence_maxsz + \
392 decode_putfh_maxsz + \
393 decode_readlink_maxsz)
394 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
395 encode_sequence_maxsz + \
396 encode_putfh_maxsz + \
397 encode_readdir_maxsz)
398 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
399 decode_sequence_maxsz + \
400 decode_putfh_maxsz + \
401 decode_readdir_maxsz)
402 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
403 encode_sequence_maxsz + \
404 encode_putfh_maxsz + \
405 encode_write_maxsz + \
406 encode_getattr_maxsz)
407 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
408 decode_sequence_maxsz + \
409 decode_putfh_maxsz + \
410 decode_write_maxsz + \
411 decode_getattr_maxsz)
412 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
413 encode_sequence_maxsz + \
414 encode_putfh_maxsz + \
415 encode_commit_maxsz + \
416 encode_getattr_maxsz)
417 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
418 decode_sequence_maxsz + \
419 decode_putfh_maxsz + \
420 decode_commit_maxsz + \
421 decode_getattr_maxsz)
422 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
423 encode_sequence_maxsz + \
424 encode_putfh_maxsz + \
425 encode_savefh_maxsz + \
426 encode_open_maxsz + \
427 encode_getfh_maxsz + \
428 encode_getattr_maxsz + \
429 encode_restorefh_maxsz + \
430 encode_getattr_maxsz)
431 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
432 decode_sequence_maxsz + \
433 decode_putfh_maxsz + \
434 decode_savefh_maxsz + \
435 decode_open_maxsz + \
436 decode_getfh_maxsz + \
437 decode_getattr_maxsz + \
438 decode_restorefh_maxsz + \
439 decode_getattr_maxsz)
440 #define NFS4_enc_open_confirm_sz \
441 (compound_encode_hdr_maxsz + \
442 encode_putfh_maxsz + \
443 encode_open_confirm_maxsz)
444 #define NFS4_dec_open_confirm_sz \
445 (compound_decode_hdr_maxsz + \
446 decode_putfh_maxsz + \
447 decode_open_confirm_maxsz)
448 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
449 encode_sequence_maxsz + \
450 encode_putfh_maxsz + \
451 encode_open_maxsz + \
452 encode_getattr_maxsz)
453 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
454 decode_sequence_maxsz + \
455 decode_putfh_maxsz + \
456 decode_open_maxsz + \
457 decode_getattr_maxsz)
458 #define NFS4_enc_open_downgrade_sz \
459 (compound_encode_hdr_maxsz + \
460 encode_sequence_maxsz + \
461 encode_putfh_maxsz + \
462 encode_open_downgrade_maxsz + \
463 encode_getattr_maxsz)
464 #define NFS4_dec_open_downgrade_sz \
465 (compound_decode_hdr_maxsz + \
466 decode_sequence_maxsz + \
467 decode_putfh_maxsz + \
468 decode_open_downgrade_maxsz + \
469 decode_getattr_maxsz)
470 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
471 encode_sequence_maxsz + \
472 encode_putfh_maxsz + \
473 encode_close_maxsz + \
474 encode_getattr_maxsz)
475 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
476 decode_sequence_maxsz + \
477 decode_putfh_maxsz + \
478 decode_close_maxsz + \
479 decode_getattr_maxsz)
480 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
481 encode_sequence_maxsz + \
482 encode_putfh_maxsz + \
483 encode_setattr_maxsz + \
484 encode_getattr_maxsz)
485 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
486 decode_sequence_maxsz + \
487 decode_putfh_maxsz + \
488 decode_setattr_maxsz + \
489 decode_getattr_maxsz)
490 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
491 encode_sequence_maxsz + \
492 encode_putfh_maxsz + \
494 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
495 decode_sequence_maxsz + \
496 decode_putfh_maxsz + \
498 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
500 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
502 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
503 encode_setclientid_maxsz)
504 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
505 decode_setclientid_maxsz)
506 #define NFS4_enc_setclientid_confirm_sz \
507 (compound_encode_hdr_maxsz + \
508 encode_setclientid_confirm_maxsz + \
509 encode_putrootfh_maxsz + \
511 #define NFS4_dec_setclientid_confirm_sz \
512 (compound_decode_hdr_maxsz + \
513 decode_setclientid_confirm_maxsz + \
514 decode_putrootfh_maxsz + \
516 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
517 encode_sequence_maxsz + \
518 encode_putfh_maxsz + \
520 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
521 decode_sequence_maxsz + \
522 decode_putfh_maxsz + \
524 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
525 encode_sequence_maxsz + \
526 encode_putfh_maxsz + \
528 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
529 decode_sequence_maxsz + \
530 decode_putfh_maxsz + \
532 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
533 encode_sequence_maxsz + \
534 encode_putfh_maxsz + \
536 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
537 decode_sequence_maxsz + \
538 decode_putfh_maxsz + \
540 #define NFS4_enc_release_lockowner_sz \
541 (compound_encode_hdr_maxsz + \
542 encode_lockowner_maxsz)
543 #define NFS4_dec_release_lockowner_sz \
544 (compound_decode_hdr_maxsz + \
545 decode_lockowner_maxsz)
546 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
547 encode_sequence_maxsz + \
548 encode_putfh_maxsz + \
549 encode_access_maxsz + \
550 encode_getattr_maxsz)
551 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
552 decode_sequence_maxsz + \
553 decode_putfh_maxsz + \
554 decode_access_maxsz + \
555 decode_getattr_maxsz)
556 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
557 encode_sequence_maxsz + \
558 encode_putfh_maxsz + \
559 encode_getattr_maxsz)
560 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
561 decode_sequence_maxsz + \
562 decode_putfh_maxsz + \
563 decode_getattr_maxsz)
564 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
565 encode_sequence_maxsz + \
566 encode_putfh_maxsz + \
567 encode_lookup_maxsz + \
568 encode_getattr_maxsz + \
570 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
571 decode_sequence_maxsz + \
572 decode_putfh_maxsz + \
573 decode_lookup_maxsz + \
574 decode_getattr_maxsz + \
576 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
577 encode_sequence_maxsz + \
578 encode_putrootfh_maxsz + \
579 encode_getattr_maxsz + \
581 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
582 decode_sequence_maxsz + \
583 decode_putrootfh_maxsz + \
584 decode_getattr_maxsz + \
586 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
587 encode_sequence_maxsz + \
588 encode_putfh_maxsz + \
589 encode_remove_maxsz + \
590 encode_getattr_maxsz)
591 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
592 decode_sequence_maxsz + \
593 decode_putfh_maxsz + \
594 decode_remove_maxsz + \
595 decode_getattr_maxsz)
596 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
597 encode_sequence_maxsz + \
598 encode_putfh_maxsz + \
599 encode_savefh_maxsz + \
600 encode_putfh_maxsz + \
601 encode_rename_maxsz + \
602 encode_getattr_maxsz + \
603 encode_restorefh_maxsz + \
604 encode_getattr_maxsz)
605 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
606 decode_sequence_maxsz + \
607 decode_putfh_maxsz + \
608 decode_savefh_maxsz + \
609 decode_putfh_maxsz + \
610 decode_rename_maxsz + \
611 decode_getattr_maxsz + \
612 decode_restorefh_maxsz + \
613 decode_getattr_maxsz)
614 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
615 encode_sequence_maxsz + \
616 encode_putfh_maxsz + \
617 encode_savefh_maxsz + \
618 encode_putfh_maxsz + \
619 encode_link_maxsz + \
620 decode_getattr_maxsz + \
621 encode_restorefh_maxsz + \
622 decode_getattr_maxsz)
623 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
624 decode_sequence_maxsz + \
625 decode_putfh_maxsz + \
626 decode_savefh_maxsz + \
627 decode_putfh_maxsz + \
628 decode_link_maxsz + \
629 decode_getattr_maxsz + \
630 decode_restorefh_maxsz + \
631 decode_getattr_maxsz)
632 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
633 encode_sequence_maxsz + \
634 encode_putfh_maxsz + \
635 encode_symlink_maxsz + \
636 encode_getattr_maxsz + \
638 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
639 decode_sequence_maxsz + \
640 decode_putfh_maxsz + \
641 decode_symlink_maxsz + \
642 decode_getattr_maxsz + \
644 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
645 encode_sequence_maxsz + \
646 encode_putfh_maxsz + \
647 encode_savefh_maxsz + \
648 encode_create_maxsz + \
649 encode_getfh_maxsz + \
650 encode_getattr_maxsz + \
651 encode_restorefh_maxsz + \
652 encode_getattr_maxsz)
653 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
654 decode_sequence_maxsz + \
655 decode_putfh_maxsz + \
656 decode_savefh_maxsz + \
657 decode_create_maxsz + \
658 decode_getfh_maxsz + \
659 decode_getattr_maxsz + \
660 decode_restorefh_maxsz + \
661 decode_getattr_maxsz)
662 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
663 encode_sequence_maxsz + \
664 encode_putfh_maxsz + \
665 encode_getattr_maxsz)
666 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
667 decode_sequence_maxsz + \
668 decode_putfh_maxsz + \
669 decode_getattr_maxsz)
670 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
671 encode_sequence_maxsz + \
672 encode_putfh_maxsz + \
674 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
675 decode_sequence_maxsz + \
676 decode_putfh_maxsz + \
678 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
679 encode_sequence_maxsz + \
680 encode_putfh_maxsz + \
681 encode_getattr_maxsz)
682 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
683 decode_sequence_maxsz + \
684 decode_putfh_maxsz + \
685 decode_getattr_maxsz)
686 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
687 encode_sequence_maxsz + \
688 encode_putfh_maxsz + \
689 encode_delegreturn_maxsz + \
690 encode_getattr_maxsz)
691 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
692 decode_sequence_maxsz + \
693 decode_delegreturn_maxsz + \
694 decode_getattr_maxsz)
695 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
696 encode_sequence_maxsz + \
697 encode_putfh_maxsz + \
699 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
700 decode_sequence_maxsz + \
701 decode_putfh_maxsz + \
703 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
704 encode_sequence_maxsz + \
705 encode_putfh_maxsz + \
707 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
708 decode_sequence_maxsz + \
709 decode_putfh_maxsz + \
711 #define NFS4_enc_fs_locations_sz \
712 (compound_encode_hdr_maxsz + \
713 encode_sequence_maxsz + \
714 encode_putfh_maxsz + \
715 encode_lookup_maxsz + \
716 encode_fs_locations_maxsz)
717 #define NFS4_dec_fs_locations_sz \
718 (compound_decode_hdr_maxsz + \
719 decode_sequence_maxsz + \
720 decode_putfh_maxsz + \
721 decode_lookup_maxsz + \
722 decode_fs_locations_maxsz)
723 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
724 encode_sequence_maxsz + \
725 encode_putfh_maxsz + \
726 encode_secinfo_maxsz)
727 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
728 decode_sequence_maxsz + \
729 decode_putfh_maxsz + \
730 decode_secinfo_maxsz)
731 #if defined(CONFIG_NFS_V4_1)
732 #define NFS4_enc_exchange_id_sz \
733 (compound_encode_hdr_maxsz + \
734 encode_exchange_id_maxsz)
735 #define NFS4_dec_exchange_id_sz \
736 (compound_decode_hdr_maxsz + \
737 decode_exchange_id_maxsz)
738 #define NFS4_enc_create_session_sz \
739 (compound_encode_hdr_maxsz + \
740 encode_create_session_maxsz)
741 #define NFS4_dec_create_session_sz \
742 (compound_decode_hdr_maxsz + \
743 decode_create_session_maxsz)
744 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
745 encode_destroy_session_maxsz)
746 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
747 decode_destroy_session_maxsz)
748 #define NFS4_enc_sequence_sz \
749 (compound_decode_hdr_maxsz + \
750 encode_sequence_maxsz)
751 #define NFS4_dec_sequence_sz \
752 (compound_decode_hdr_maxsz + \
753 decode_sequence_maxsz)
754 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
755 encode_sequence_maxsz + \
756 encode_putrootfh_maxsz + \
758 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
759 decode_sequence_maxsz + \
760 decode_putrootfh_maxsz + \
762 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
763 encode_sequence_maxsz + \
764 encode_reclaim_complete_maxsz)
765 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
766 decode_sequence_maxsz + \
767 decode_reclaim_complete_maxsz)
768 #define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
769 encode_sequence_maxsz + \
770 encode_putfh_maxsz + \
771 encode_getdevicelist_maxsz)
772 #define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
773 decode_sequence_maxsz + \
774 decode_putfh_maxsz + \
775 decode_getdevicelist_maxsz)
776 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
777 encode_sequence_maxsz +\
778 encode_getdeviceinfo_maxsz)
779 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
780 decode_sequence_maxsz + \
781 decode_getdeviceinfo_maxsz)
782 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
783 encode_sequence_maxsz + \
784 encode_putfh_maxsz + \
785 encode_layoutget_maxsz)
786 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
787 decode_sequence_maxsz + \
788 decode_putfh_maxsz + \
789 decode_layoutget_maxsz)
790 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
791 encode_sequence_maxsz +\
792 encode_putfh_maxsz + \
793 encode_layoutcommit_maxsz + \
794 encode_getattr_maxsz)
795 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
796 decode_sequence_maxsz + \
797 decode_putfh_maxsz + \
798 decode_layoutcommit_maxsz + \
799 decode_getattr_maxsz)
800 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
801 encode_sequence_maxsz + \
802 encode_putfh_maxsz + \
803 encode_layoutreturn_maxsz)
804 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
805 decode_sequence_maxsz + \
806 decode_putfh_maxsz + \
807 decode_layoutreturn_maxsz)
808 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
809 encode_sequence_maxsz + \
810 encode_putrootfh_maxsz +\
811 encode_secinfo_no_name_maxsz)
812 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
813 decode_sequence_maxsz + \
814 decode_putrootfh_maxsz + \
815 decode_secinfo_no_name_maxsz)
816 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
817 encode_sequence_maxsz + \
818 encode_test_stateid_maxsz)
819 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
820 decode_sequence_maxsz + \
821 decode_test_stateid_maxsz)
822 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
823 encode_sequence_maxsz + \
824 encode_free_stateid_maxsz)
825 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
826 decode_sequence_maxsz + \
827 decode_free_stateid_maxsz)
829 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
830 compound_encode_hdr_maxsz +
831 encode_sequence_maxsz +
833 encode_getattr_maxsz) *
836 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
837 compound_decode_hdr_maxsz +
838 decode_sequence_maxsz +
839 decode_putfh_maxsz) *
841 #endif /* CONFIG_NFS_V4_1 */
843 static const umode_t nfs_type2fmt[] = {
850 [NF4SOCK] = S_IFSOCK,
856 struct compound_hdr {
862 uint32_t replen; /* expected reply words */
866 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
868 __be32 *p = xdr_reserve_space(xdr, nbytes);
873 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
877 p = xdr_reserve_space(xdr, 4 + len);
879 xdr_encode_opaque(p, str, len);
882 static void encode_compound_hdr(struct xdr_stream *xdr,
883 struct rpc_rqst *req,
884 struct compound_hdr *hdr)
887 struct rpc_auth *auth = req->rq_cred->cr_auth;
889 /* initialize running count of expected bytes in reply.
890 * NOTE: the replied tag SHOULD be the same is the one sent,
891 * but this is not required as a MUST for the server to do so. */
892 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
894 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
895 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
896 p = reserve_space(xdr, 4 + hdr->taglen + 8);
897 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
898 *p++ = cpu_to_be32(hdr->minorversion);
900 *p = cpu_to_be32(hdr->nops);
903 static void encode_nops(struct compound_hdr *hdr)
905 BUG_ON(hdr->nops > NFS4_MAX_OPS);
906 *hdr->nops_p = htonl(hdr->nops);
909 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
913 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
915 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
918 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
920 char owner_name[IDMAP_NAMESZ];
921 char owner_group[IDMAP_NAMESZ];
922 int owner_namelen = 0;
923 int owner_grouplen = 0;
931 * We reserve enough space to write the entire attribute buffer at once.
932 * In the worst-case, this would be
933 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
934 * = 36 bytes, plus any contribution from variable-length fields
935 * such as owner/group.
940 if (iap->ia_valid & ATTR_SIZE)
942 if (iap->ia_valid & ATTR_MODE)
944 if (iap->ia_valid & ATTR_UID) {
945 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
946 if (owner_namelen < 0) {
947 dprintk("nfs: couldn't resolve uid %d to string\n",
950 strcpy(owner_name, "nobody");
951 owner_namelen = sizeof("nobody") - 1;
954 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
956 if (iap->ia_valid & ATTR_GID) {
957 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
958 if (owner_grouplen < 0) {
959 dprintk("nfs: couldn't resolve gid %d to string\n",
961 strcpy(owner_group, "nobody");
962 owner_grouplen = sizeof("nobody") - 1;
965 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
967 if (iap->ia_valid & ATTR_ATIME_SET)
969 else if (iap->ia_valid & ATTR_ATIME)
971 if (iap->ia_valid & ATTR_MTIME_SET)
973 else if (iap->ia_valid & ATTR_MTIME)
975 p = reserve_space(xdr, len);
978 * We write the bitmap length now, but leave the bitmap and the attribute
979 * buffer length to be backfilled at the end of this routine.
981 *p++ = cpu_to_be32(2);
985 if (iap->ia_valid & ATTR_SIZE) {
986 bmval0 |= FATTR4_WORD0_SIZE;
987 p = xdr_encode_hyper(p, iap->ia_size);
989 if (iap->ia_valid & ATTR_MODE) {
990 bmval1 |= FATTR4_WORD1_MODE;
991 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
993 if (iap->ia_valid & ATTR_UID) {
994 bmval1 |= FATTR4_WORD1_OWNER;
995 p = xdr_encode_opaque(p, owner_name, owner_namelen);
997 if (iap->ia_valid & ATTR_GID) {
998 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
999 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1001 if (iap->ia_valid & ATTR_ATIME_SET) {
1002 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1003 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1004 *p++ = cpu_to_be32(0);
1005 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1006 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1008 else if (iap->ia_valid & ATTR_ATIME) {
1009 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1010 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1012 if (iap->ia_valid & ATTR_MTIME_SET) {
1013 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1014 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1015 *p++ = cpu_to_be32(0);
1016 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1017 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1019 else if (iap->ia_valid & ATTR_MTIME) {
1020 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1021 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1025 * Now we backfill the bitmap and the attribute buffer length.
1027 if (len != ((char *)p - (char *)q) + 4) {
1028 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
1029 len, ((char *)p - (char *)q) + 4);
1032 len = (char *)p - (char *)q - 12;
1033 *q++ = htonl(bmval0);
1034 *q++ = htonl(bmval1);
1040 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1044 p = reserve_space(xdr, 8);
1045 *p++ = cpu_to_be32(OP_ACCESS);
1046 *p = cpu_to_be32(access);
1048 hdr->replen += decode_access_maxsz;
1051 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1055 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
1056 *p++ = cpu_to_be32(OP_CLOSE);
1057 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
1058 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1060 hdr->replen += decode_close_maxsz;
1063 static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1067 p = reserve_space(xdr, 16);
1068 *p++ = cpu_to_be32(OP_COMMIT);
1069 p = xdr_encode_hyper(p, args->offset);
1070 *p = cpu_to_be32(args->count);
1072 hdr->replen += decode_commit_maxsz;
1075 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1079 p = reserve_space(xdr, 8);
1080 *p++ = cpu_to_be32(OP_CREATE);
1081 *p = cpu_to_be32(create->ftype);
1083 switch (create->ftype) {
1085 p = reserve_space(xdr, 4);
1086 *p = cpu_to_be32(create->u.symlink.len);
1087 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1090 case NF4BLK: case NF4CHR:
1091 p = reserve_space(xdr, 8);
1092 *p++ = cpu_to_be32(create->u.device.specdata1);
1093 *p = cpu_to_be32(create->u.device.specdata2);
1100 encode_string(xdr, create->name->len, create->name->name);
1102 hdr->replen += decode_create_maxsz;
1104 encode_attrs(xdr, create->attrs, create->server);
1107 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1111 p = reserve_space(xdr, 12);
1112 *p++ = cpu_to_be32(OP_GETATTR);
1113 *p++ = cpu_to_be32(1);
1114 *p = cpu_to_be32(bitmap);
1116 hdr->replen += decode_getattr_maxsz;
1119 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1123 p = reserve_space(xdr, 16);
1124 *p++ = cpu_to_be32(OP_GETATTR);
1125 *p++ = cpu_to_be32(2);
1126 *p++ = cpu_to_be32(bm0);
1127 *p = cpu_to_be32(bm1);
1129 hdr->replen += decode_getattr_maxsz;
1133 encode_getattr_three(struct xdr_stream *xdr,
1134 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1135 struct compound_hdr *hdr)
1139 p = reserve_space(xdr, 4);
1140 *p = cpu_to_be32(OP_GETATTR);
1142 p = reserve_space(xdr, 16);
1143 *p++ = cpu_to_be32(3);
1144 *p++ = cpu_to_be32(bm0);
1145 *p++ = cpu_to_be32(bm1);
1146 *p = cpu_to_be32(bm2);
1148 p = reserve_space(xdr, 12);
1149 *p++ = cpu_to_be32(2);
1150 *p++ = cpu_to_be32(bm0);
1151 *p = cpu_to_be32(bm1);
1153 p = reserve_space(xdr, 8);
1154 *p++ = cpu_to_be32(1);
1155 *p = cpu_to_be32(bm0);
1158 hdr->replen += decode_getattr_maxsz;
1161 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1163 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1164 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
1167 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1169 encode_getattr_three(xdr,
1170 bitmask[0] & nfs4_fsinfo_bitmap[0],
1171 bitmask[1] & nfs4_fsinfo_bitmap[1],
1172 bitmask[2] & nfs4_fsinfo_bitmap[2],
1176 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1178 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1179 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1182 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1186 p = reserve_space(xdr, 4);
1187 *p = cpu_to_be32(OP_GETFH);
1189 hdr->replen += decode_getfh_maxsz;
1192 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1196 p = reserve_space(xdr, 8 + name->len);
1197 *p++ = cpu_to_be32(OP_LINK);
1198 xdr_encode_opaque(p, name->name, name->len);
1200 hdr->replen += decode_link_maxsz;
1203 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1205 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1206 return block ? NFS4_READW_LT : NFS4_READ_LT;
1207 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1210 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1212 if (fl->fl_end == OFFSET_MAX)
1213 return ~(uint64_t)0;
1214 return fl->fl_end - fl->fl_start + 1;
1217 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1221 p = reserve_space(xdr, 32);
1222 p = xdr_encode_hyper(p, lowner->clientid);
1223 *p++ = cpu_to_be32(20);
1224 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1225 *p++ = cpu_to_be32(lowner->s_dev);
1226 xdr_encode_hyper(p, lowner->id);
1230 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1231 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1233 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1237 p = reserve_space(xdr, 32);
1238 *p++ = cpu_to_be32(OP_LOCK);
1239 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1240 *p++ = cpu_to_be32(args->reclaim);
1241 p = xdr_encode_hyper(p, args->fl->fl_start);
1242 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1243 *p = cpu_to_be32(args->new_lock_owner);
1244 if (args->new_lock_owner){
1245 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1246 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
1247 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
1248 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
1249 encode_lockowner(xdr, &args->lock_owner);
1252 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
1253 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
1254 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
1257 hdr->replen += decode_lock_maxsz;
1260 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1264 p = reserve_space(xdr, 24);
1265 *p++ = cpu_to_be32(OP_LOCKT);
1266 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1267 p = xdr_encode_hyper(p, args->fl->fl_start);
1268 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1269 encode_lockowner(xdr, &args->lock_owner);
1271 hdr->replen += decode_lockt_maxsz;
1274 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1278 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
1279 *p++ = cpu_to_be32(OP_LOCKU);
1280 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1281 *p++ = cpu_to_be32(args->seqid->sequence->counter);
1282 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
1283 p = xdr_encode_hyper(p, args->fl->fl_start);
1284 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1286 hdr->replen += decode_locku_maxsz;
1289 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1293 p = reserve_space(xdr, 4);
1294 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1295 encode_lockowner(xdr, lowner);
1297 hdr->replen += decode_release_lockowner_maxsz;
1300 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1302 int len = name->len;
1305 p = reserve_space(xdr, 8 + len);
1306 *p++ = cpu_to_be32(OP_LOOKUP);
1307 xdr_encode_opaque(p, name->name, len);
1309 hdr->replen += decode_lookup_maxsz;
1312 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1316 p = reserve_space(xdr, 8);
1317 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1319 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1322 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1324 case FMODE_READ|FMODE_WRITE:
1325 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1328 *p++ = cpu_to_be32(0);
1330 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1333 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1337 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1340 p = reserve_space(xdr, 8);
1341 *p++ = cpu_to_be32(OP_OPEN);
1342 *p = cpu_to_be32(arg->seqid->sequence->counter);
1343 encode_share_access(xdr, arg->fmode);
1344 p = reserve_space(xdr, 32);
1345 p = xdr_encode_hyper(p, arg->clientid);
1346 *p++ = cpu_to_be32(20);
1347 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1348 *p++ = cpu_to_be32(arg->server->s_dev);
1349 xdr_encode_hyper(p, arg->id);
1352 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1355 struct nfs_client *clp;
1357 p = reserve_space(xdr, 4);
1358 switch(arg->open_flags & O_EXCL) {
1360 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1361 encode_attrs(xdr, arg->u.attrs, arg->server);
1364 clp = arg->server->nfs_client;
1365 if (clp->cl_mvops->minor_version > 0) {
1366 if (nfs4_has_persistent_session(clp)) {
1367 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1368 encode_attrs(xdr, arg->u.attrs, arg->server);
1372 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1373 encode_nfs4_verifier(xdr, &arg->u.verifier);
1375 encode_attrs(xdr, &dummy, arg->server);
1378 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1379 encode_nfs4_verifier(xdr, &arg->u.verifier);
1384 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1388 p = reserve_space(xdr, 4);
1389 switch (arg->open_flags & O_CREAT) {
1391 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1394 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1395 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1396 encode_createmode(xdr, arg);
1400 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1404 p = reserve_space(xdr, 4);
1405 switch (delegation_type) {
1407 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1410 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1412 case FMODE_WRITE|FMODE_READ:
1413 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1420 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1424 p = reserve_space(xdr, 4);
1425 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1426 encode_string(xdr, name->len, name->name);
1429 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1433 p = reserve_space(xdr, 4);
1434 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1435 encode_delegation_type(xdr, type);
1438 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1442 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1443 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1444 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1445 encode_string(xdr, name->len, name->name);
1448 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1450 encode_openhdr(xdr, arg);
1451 encode_opentype(xdr, arg);
1452 switch (arg->claim) {
1453 case NFS4_OPEN_CLAIM_NULL:
1454 encode_claim_null(xdr, arg->name);
1456 case NFS4_OPEN_CLAIM_PREVIOUS:
1457 encode_claim_previous(xdr, arg->u.delegation_type);
1459 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1460 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1466 hdr->replen += decode_open_maxsz;
1469 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1473 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1474 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
1475 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1476 *p = cpu_to_be32(arg->seqid->sequence->counter);
1478 hdr->replen += decode_open_confirm_maxsz;
1481 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1485 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
1486 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
1487 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1488 *p = cpu_to_be32(arg->seqid->sequence->counter);
1489 encode_share_access(xdr, arg->fmode);
1491 hdr->replen += decode_open_downgrade_maxsz;
1495 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1500 p = reserve_space(xdr, 8 + len);
1501 *p++ = cpu_to_be32(OP_PUTFH);
1502 xdr_encode_opaque(p, fh->data, len);
1504 hdr->replen += decode_putfh_maxsz;
1507 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1511 p = reserve_space(xdr, 4);
1512 *p = cpu_to_be32(OP_PUTROOTFH);
1514 hdr->replen += decode_putrootfh_maxsz;
1517 static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
1519 nfs4_stateid stateid;
1522 p = reserve_space(xdr, NFS4_STATEID_SIZE);
1523 if (ctx->state != NULL) {
1524 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
1526 stateid.stateid.seqid = 0;
1527 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
1529 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1532 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1536 p = reserve_space(xdr, 4);
1537 *p = cpu_to_be32(OP_READ);
1539 encode_stateid(xdr, args->context, args->lock_context,
1542 p = reserve_space(xdr, 12);
1543 p = xdr_encode_hyper(p, args->offset);
1544 *p = cpu_to_be32(args->count);
1546 hdr->replen += decode_read_maxsz;
1549 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1551 uint32_t attrs[2] = {
1552 FATTR4_WORD0_RDATTR_ERROR,
1553 FATTR4_WORD1_MOUNTED_ON_FILEID,
1555 uint32_t dircount = readdir->count >> 1;
1558 if (readdir->plus) {
1559 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1560 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1561 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1562 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1563 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1564 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1567 /* Use mounted_on_fileid only if the server supports it */
1568 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1569 attrs[0] |= FATTR4_WORD0_FILEID;
1571 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
1572 *p++ = cpu_to_be32(OP_READDIR);
1573 p = xdr_encode_hyper(p, readdir->cookie);
1574 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
1575 *p++ = cpu_to_be32(dircount);
1576 *p++ = cpu_to_be32(readdir->count);
1577 *p++ = cpu_to_be32(2);
1579 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1580 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1582 hdr->replen += decode_readdir_maxsz;
1583 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1585 (unsigned long long)readdir->cookie,
1586 ((u32 *)readdir->verifier.data)[0],
1587 ((u32 *)readdir->verifier.data)[1],
1588 attrs[0] & readdir->bitmask[0],
1589 attrs[1] & readdir->bitmask[1]);
1592 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1596 p = reserve_space(xdr, 4);
1597 *p = cpu_to_be32(OP_READLINK);
1599 hdr->replen += decode_readlink_maxsz;
1602 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1606 p = reserve_space(xdr, 8 + name->len);
1607 *p++ = cpu_to_be32(OP_REMOVE);
1608 xdr_encode_opaque(p, name->name, name->len);
1610 hdr->replen += decode_remove_maxsz;
1613 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1617 p = reserve_space(xdr, 4);
1618 *p = cpu_to_be32(OP_RENAME);
1619 encode_string(xdr, oldname->len, oldname->name);
1620 encode_string(xdr, newname->len, newname->name);
1622 hdr->replen += decode_rename_maxsz;
1625 static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
1629 p = reserve_space(xdr, 12);
1630 *p++ = cpu_to_be32(OP_RENEW);
1631 xdr_encode_hyper(p, client_stateid->cl_clientid);
1633 hdr->replen += decode_renew_maxsz;
1637 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1641 p = reserve_space(xdr, 4);
1642 *p = cpu_to_be32(OP_RESTOREFH);
1644 hdr->replen += decode_restorefh_maxsz;
1648 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1652 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1653 *p++ = cpu_to_be32(OP_SETATTR);
1654 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1655 p = reserve_space(xdr, 2*4);
1656 *p++ = cpu_to_be32(1);
1657 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1658 BUG_ON(arg->acl_len % 4);
1659 p = reserve_space(xdr, 4);
1660 *p = cpu_to_be32(arg->acl_len);
1661 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1663 hdr->replen += decode_setacl_maxsz;
1667 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1671 p = reserve_space(xdr, 4);
1672 *p = cpu_to_be32(OP_SAVEFH);
1674 hdr->replen += decode_savefh_maxsz;
1677 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1681 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1682 *p++ = cpu_to_be32(OP_SETATTR);
1683 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
1685 hdr->replen += decode_setattr_maxsz;
1686 encode_attrs(xdr, arg->iap, server);
1689 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1693 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
1694 *p++ = cpu_to_be32(OP_SETCLIENTID);
1695 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1697 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1698 p = reserve_space(xdr, 4);
1699 *p = cpu_to_be32(setclientid->sc_prog);
1700 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1701 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1702 p = reserve_space(xdr, 4);
1703 *p = cpu_to_be32(setclientid->sc_cb_ident);
1705 hdr->replen += decode_setclientid_maxsz;
1708 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1712 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
1713 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
1714 p = xdr_encode_hyper(p, arg->clientid);
1715 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
1717 hdr->replen += decode_setclientid_confirm_maxsz;
1720 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1724 p = reserve_space(xdr, 4);
1725 *p = cpu_to_be32(OP_WRITE);
1727 encode_stateid(xdr, args->context, args->lock_context,
1730 p = reserve_space(xdr, 16);
1731 p = xdr_encode_hyper(p, args->offset);
1732 *p++ = cpu_to_be32(args->stable);
1733 *p = cpu_to_be32(args->count);
1735 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1737 hdr->replen += decode_write_maxsz;
1740 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1744 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1746 *p++ = cpu_to_be32(OP_DELEGRETURN);
1747 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1749 hdr->replen += decode_delegreturn_maxsz;
1752 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1754 int len = name->len;
1757 p = reserve_space(xdr, 8 + len);
1758 *p++ = cpu_to_be32(OP_SECINFO);
1759 xdr_encode_opaque(p, name->name, len);
1761 hdr->replen += decode_secinfo_maxsz;
1764 #if defined(CONFIG_NFS_V4_1)
1765 /* NFSv4.1 operations */
1766 static void encode_exchange_id(struct xdr_stream *xdr,
1767 struct nfs41_exchange_id_args *args,
1768 struct compound_hdr *hdr)
1772 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
1773 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
1774 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
1776 encode_string(xdr, args->id_len, args->id);
1778 p = reserve_space(xdr, 12);
1779 *p++ = cpu_to_be32(args->flags);
1780 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
1781 *p = cpu_to_be32(0); /* zero length implementation id array */
1783 hdr->replen += decode_exchange_id_maxsz;
1786 static void encode_create_session(struct xdr_stream *xdr,
1787 struct nfs41_create_session_args *args,
1788 struct compound_hdr *hdr)
1791 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1793 struct nfs_client *clp = args->client;
1794 u32 max_resp_sz_cached;
1797 * Assumes OPEN is the biggest non-idempotent compound.
1798 * 2 is the verifier.
1800 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1801 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1803 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1806 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
1807 *p++ = cpu_to_be32(OP_CREATE_SESSION);
1808 p = xdr_encode_hyper(p, clp->cl_clientid);
1809 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1810 *p++ = cpu_to_be32(args->flags); /*flags */
1813 *p++ = cpu_to_be32(0); /* header padding size */
1814 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1815 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1816 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1817 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1818 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1819 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1822 *p++ = cpu_to_be32(0); /* header padding size */
1823 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1824 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1825 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1826 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1827 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1828 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1830 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1831 *p++ = cpu_to_be32(1);
1832 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1834 /* authsys_parms rfc1831 */
1835 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
1836 p = xdr_encode_opaque(p, machine_name, len);
1837 *p++ = cpu_to_be32(0); /* UID */
1838 *p++ = cpu_to_be32(0); /* GID */
1839 *p = cpu_to_be32(0); /* No more gids */
1841 hdr->replen += decode_create_session_maxsz;
1844 static void encode_destroy_session(struct xdr_stream *xdr,
1845 struct nfs4_session *session,
1846 struct compound_hdr *hdr)
1849 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
1850 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
1851 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1853 hdr->replen += decode_destroy_session_maxsz;
1856 static void encode_reclaim_complete(struct xdr_stream *xdr,
1857 struct nfs41_reclaim_complete_args *args,
1858 struct compound_hdr *hdr)
1862 p = reserve_space(xdr, 8);
1863 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1864 *p++ = cpu_to_be32(args->one_fs);
1866 hdr->replen += decode_reclaim_complete_maxsz;
1868 #endif /* CONFIG_NFS_V4_1 */
1870 static void encode_sequence(struct xdr_stream *xdr,
1871 const struct nfs4_sequence_args *args,
1872 struct compound_hdr *hdr)
1874 #if defined(CONFIG_NFS_V4_1)
1875 struct nfs4_session *session = args->sa_session;
1876 struct nfs4_slot_table *tp;
1877 struct nfs4_slot *slot;
1883 tp = &session->fc_slot_table;
1885 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1886 slot = tp->slots + args->sa_slotid;
1888 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
1889 *p++ = cpu_to_be32(OP_SEQUENCE);
1892 * Sessionid + seqid + slotid + max slotid + cache_this
1894 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1895 "max_slotid=%d cache_this=%d\n",
1897 ((u32 *)session->sess_id.data)[0],
1898 ((u32 *)session->sess_id.data)[1],
1899 ((u32 *)session->sess_id.data)[2],
1900 ((u32 *)session->sess_id.data)[3],
1901 slot->seq_nr, args->sa_slotid,
1902 tp->highest_used_slotid, args->sa_cache_this);
1903 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1904 *p++ = cpu_to_be32(slot->seq_nr);
1905 *p++ = cpu_to_be32(args->sa_slotid);
1906 *p++ = cpu_to_be32(tp->highest_used_slotid);
1907 *p = cpu_to_be32(args->sa_cache_this);
1909 hdr->replen += decode_sequence_maxsz;
1910 #endif /* CONFIG_NFS_V4_1 */
1913 #ifdef CONFIG_NFS_V4_1
1915 encode_getdevicelist(struct xdr_stream *xdr,
1916 const struct nfs4_getdevicelist_args *args,
1917 struct compound_hdr *hdr)
1920 nfs4_verifier dummy = {
1924 p = reserve_space(xdr, 20);
1925 *p++ = cpu_to_be32(OP_GETDEVICELIST);
1926 *p++ = cpu_to_be32(args->layoutclass);
1927 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1928 xdr_encode_hyper(p, 0ULL); /* cookie */
1929 encode_nfs4_verifier(xdr, &dummy);
1931 hdr->replen += decode_getdevicelist_maxsz;
1935 encode_getdeviceinfo(struct xdr_stream *xdr,
1936 const struct nfs4_getdeviceinfo_args *args,
1937 struct compound_hdr *hdr)
1941 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1942 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1943 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1944 NFS4_DEVICEID4_SIZE);
1945 *p++ = cpu_to_be32(args->pdev->layout_type);
1946 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1947 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1949 hdr->replen += decode_getdeviceinfo_maxsz;
1953 encode_layoutget(struct xdr_stream *xdr,
1954 const struct nfs4_layoutget_args *args,
1955 struct compound_hdr *hdr)
1959 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1960 *p++ = cpu_to_be32(OP_LAYOUTGET);
1961 *p++ = cpu_to_be32(0); /* Signal layout available */
1962 *p++ = cpu_to_be32(args->type);
1963 *p++ = cpu_to_be32(args->range.iomode);
1964 p = xdr_encode_hyper(p, args->range.offset);
1965 p = xdr_encode_hyper(p, args->range.length);
1966 p = xdr_encode_hyper(p, args->minlength);
1967 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1968 *p = cpu_to_be32(args->maxcount);
1970 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1974 (unsigned long)args->range.offset,
1975 (unsigned long)args->range.length,
1978 hdr->replen += decode_layoutget_maxsz;
1982 encode_layoutcommit(struct xdr_stream *xdr,
1983 struct inode *inode,
1984 const struct nfs4_layoutcommit_args *args,
1985 struct compound_hdr *hdr)
1989 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1990 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1992 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1993 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1994 /* Only whole file layouts */
1995 p = xdr_encode_hyper(p, 0); /* offset */
1996 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
1997 *p++ = cpu_to_be32(0); /* reclaim */
1998 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1999 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2000 p = xdr_encode_hyper(p, args->lastbytewritten);
2001 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2002 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2004 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2005 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2006 NFS_I(inode)->layout, xdr, args);
2008 p = reserve_space(xdr, 4);
2009 *p = cpu_to_be32(0); /* no layout-type payload */
2013 hdr->replen += decode_layoutcommit_maxsz;
2018 encode_layoutreturn(struct xdr_stream *xdr,
2019 const struct nfs4_layoutreturn_args *args,
2020 struct compound_hdr *hdr)
2024 p = reserve_space(xdr, 20);
2025 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
2026 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2027 *p++ = cpu_to_be32(args->layout_type);
2028 *p++ = cpu_to_be32(IOMODE_ANY);
2029 *p = cpu_to_be32(RETURN_FILE);
2030 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
2031 p = xdr_encode_hyper(p, 0);
2032 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2033 spin_lock(&args->inode->i_lock);
2034 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
2035 spin_unlock(&args->inode->i_lock);
2036 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2037 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2038 NFS_I(args->inode)->layout, xdr, args);
2040 p = reserve_space(xdr, 4);
2041 *p = cpu_to_be32(0);
2044 hdr->replen += decode_layoutreturn_maxsz;
2048 encode_secinfo_no_name(struct xdr_stream *xdr,
2049 const struct nfs41_secinfo_no_name_args *args,
2050 struct compound_hdr *hdr)
2053 p = reserve_space(xdr, 8);
2054 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2055 *p++ = cpu_to_be32(args->style);
2057 hdr->replen += decode_secinfo_no_name_maxsz;
2061 static void encode_test_stateid(struct xdr_stream *xdr,
2062 struct nfs41_test_stateid_args *args,
2063 struct compound_hdr *hdr)
2067 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
2068 *p++ = cpu_to_be32(OP_TEST_STATEID);
2069 *p++ = cpu_to_be32(1);
2070 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2072 hdr->replen += decode_test_stateid_maxsz;
2075 static void encode_free_stateid(struct xdr_stream *xdr,
2076 struct nfs41_free_stateid_args *args,
2077 struct compound_hdr *hdr)
2080 p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
2081 *p++ = cpu_to_be32(OP_FREE_STATEID);
2082 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2084 hdr->replen += decode_free_stateid_maxsz;
2086 #endif /* CONFIG_NFS_V4_1 */
2089 * END OF "GENERIC" ENCODE ROUTINES.
2092 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2094 #if defined(CONFIG_NFS_V4_1)
2095 if (args->sa_session)
2096 return args->sa_session->clp->cl_mvops->minor_version;
2097 #endif /* CONFIG_NFS_V4_1 */
2102 * Encode an ACCESS request
2104 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2105 const struct nfs4_accessargs *args)
2107 struct compound_hdr hdr = {
2108 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2111 encode_compound_hdr(xdr, req, &hdr);
2112 encode_sequence(xdr, &args->seq_args, &hdr);
2113 encode_putfh(xdr, args->fh, &hdr);
2114 encode_access(xdr, args->access, &hdr);
2115 encode_getfattr(xdr, args->bitmask, &hdr);
2120 * Encode LOOKUP request
2122 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2123 const struct nfs4_lookup_arg *args)
2125 struct compound_hdr hdr = {
2126 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2129 encode_compound_hdr(xdr, req, &hdr);
2130 encode_sequence(xdr, &args->seq_args, &hdr);
2131 encode_putfh(xdr, args->dir_fh, &hdr);
2132 encode_lookup(xdr, args->name, &hdr);
2133 encode_getfh(xdr, &hdr);
2134 encode_getfattr(xdr, args->bitmask, &hdr);
2139 * Encode LOOKUP_ROOT request
2141 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2142 struct xdr_stream *xdr,
2143 const struct nfs4_lookup_root_arg *args)
2145 struct compound_hdr hdr = {
2146 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2149 encode_compound_hdr(xdr, req, &hdr);
2150 encode_sequence(xdr, &args->seq_args, &hdr);
2151 encode_putrootfh(xdr, &hdr);
2152 encode_getfh(xdr, &hdr);
2153 encode_getfattr(xdr, args->bitmask, &hdr);
2158 * Encode REMOVE request
2160 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2161 const struct nfs_removeargs *args)
2163 struct compound_hdr hdr = {
2164 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2167 encode_compound_hdr(xdr, req, &hdr);
2168 encode_sequence(xdr, &args->seq_args, &hdr);
2169 encode_putfh(xdr, args->fh, &hdr);
2170 encode_remove(xdr, &args->name, &hdr);
2171 encode_getfattr(xdr, args->bitmask, &hdr);
2176 * Encode RENAME request
2178 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2179 const struct nfs_renameargs *args)
2181 struct compound_hdr hdr = {
2182 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2185 encode_compound_hdr(xdr, req, &hdr);
2186 encode_sequence(xdr, &args->seq_args, &hdr);
2187 encode_putfh(xdr, args->old_dir, &hdr);
2188 encode_savefh(xdr, &hdr);
2189 encode_putfh(xdr, args->new_dir, &hdr);
2190 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2191 encode_getfattr(xdr, args->bitmask, &hdr);
2192 encode_restorefh(xdr, &hdr);
2193 encode_getfattr(xdr, args->bitmask, &hdr);
2198 * Encode LINK request
2200 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2201 const struct nfs4_link_arg *args)
2203 struct compound_hdr hdr = {
2204 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2207 encode_compound_hdr(xdr, req, &hdr);
2208 encode_sequence(xdr, &args->seq_args, &hdr);
2209 encode_putfh(xdr, args->fh, &hdr);
2210 encode_savefh(xdr, &hdr);
2211 encode_putfh(xdr, args->dir_fh, &hdr);
2212 encode_link(xdr, args->name, &hdr);
2213 encode_getfattr(xdr, args->bitmask, &hdr);
2214 encode_restorefh(xdr, &hdr);
2215 encode_getfattr(xdr, args->bitmask, &hdr);
2220 * Encode CREATE request
2222 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2223 const struct nfs4_create_arg *args)
2225 struct compound_hdr hdr = {
2226 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2229 encode_compound_hdr(xdr, req, &hdr);
2230 encode_sequence(xdr, &args->seq_args, &hdr);
2231 encode_putfh(xdr, args->dir_fh, &hdr);
2232 encode_savefh(xdr, &hdr);
2233 encode_create(xdr, args, &hdr);
2234 encode_getfh(xdr, &hdr);
2235 encode_getfattr(xdr, args->bitmask, &hdr);
2236 encode_restorefh(xdr, &hdr);
2237 encode_getfattr(xdr, args->bitmask, &hdr);
2242 * Encode SYMLINK request
2244 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2245 const struct nfs4_create_arg *args)
2247 nfs4_xdr_enc_create(req, xdr, args);
2251 * Encode GETATTR request
2253 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2254 const struct nfs4_getattr_arg *args)
2256 struct compound_hdr hdr = {
2257 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2260 encode_compound_hdr(xdr, req, &hdr);
2261 encode_sequence(xdr, &args->seq_args, &hdr);
2262 encode_putfh(xdr, args->fh, &hdr);
2263 encode_getfattr(xdr, args->bitmask, &hdr);
2268 * Encode a CLOSE request
2270 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2271 struct nfs_closeargs *args)
2273 struct compound_hdr hdr = {
2274 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2277 encode_compound_hdr(xdr, req, &hdr);
2278 encode_sequence(xdr, &args->seq_args, &hdr);
2279 encode_putfh(xdr, args->fh, &hdr);
2280 encode_close(xdr, args, &hdr);
2281 encode_getfattr(xdr, args->bitmask, &hdr);
2286 * Encode an OPEN request
2288 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2289 struct nfs_openargs *args)
2291 struct compound_hdr hdr = {
2292 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2295 encode_compound_hdr(xdr, req, &hdr);
2296 encode_sequence(xdr, &args->seq_args, &hdr);
2297 encode_putfh(xdr, args->fh, &hdr);
2298 encode_savefh(xdr, &hdr);
2299 encode_open(xdr, args, &hdr);
2300 encode_getfh(xdr, &hdr);
2301 encode_getfattr(xdr, args->bitmask, &hdr);
2302 encode_restorefh(xdr, &hdr);
2303 encode_getfattr(xdr, args->bitmask, &hdr);
2308 * Encode an OPEN_CONFIRM request
2310 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2311 struct xdr_stream *xdr,
2312 struct nfs_open_confirmargs *args)
2314 struct compound_hdr hdr = {
2318 encode_compound_hdr(xdr, req, &hdr);
2319 encode_putfh(xdr, args->fh, &hdr);
2320 encode_open_confirm(xdr, args, &hdr);
2325 * Encode an OPEN request with no attributes.
2327 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2328 struct xdr_stream *xdr,
2329 struct nfs_openargs *args)
2331 struct compound_hdr hdr = {
2332 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2335 encode_compound_hdr(xdr, req, &hdr);
2336 encode_sequence(xdr, &args->seq_args, &hdr);
2337 encode_putfh(xdr, args->fh, &hdr);
2338 encode_open(xdr, args, &hdr);
2339 encode_getfattr(xdr, args->bitmask, &hdr);
2344 * Encode an OPEN_DOWNGRADE request
2346 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2347 struct xdr_stream *xdr,
2348 struct nfs_closeargs *args)
2350 struct compound_hdr hdr = {
2351 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2354 encode_compound_hdr(xdr, req, &hdr);
2355 encode_sequence(xdr, &args->seq_args, &hdr);
2356 encode_putfh(xdr, args->fh, &hdr);
2357 encode_open_downgrade(xdr, args, &hdr);
2358 encode_getfattr(xdr, args->bitmask, &hdr);
2363 * Encode a LOCK request
2365 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2366 struct nfs_lock_args *args)
2368 struct compound_hdr hdr = {
2369 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2372 encode_compound_hdr(xdr, req, &hdr);
2373 encode_sequence(xdr, &args->seq_args, &hdr);
2374 encode_putfh(xdr, args->fh, &hdr);
2375 encode_lock(xdr, args, &hdr);
2380 * Encode a LOCKT request
2382 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2383 struct nfs_lockt_args *args)
2385 struct compound_hdr hdr = {
2386 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2389 encode_compound_hdr(xdr, req, &hdr);
2390 encode_sequence(xdr, &args->seq_args, &hdr);
2391 encode_putfh(xdr, args->fh, &hdr);
2392 encode_lockt(xdr, args, &hdr);
2397 * Encode a LOCKU request
2399 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2400 struct nfs_locku_args *args)
2402 struct compound_hdr hdr = {
2403 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2406 encode_compound_hdr(xdr, req, &hdr);
2407 encode_sequence(xdr, &args->seq_args, &hdr);
2408 encode_putfh(xdr, args->fh, &hdr);
2409 encode_locku(xdr, args, &hdr);
2413 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2414 struct xdr_stream *xdr,
2415 struct nfs_release_lockowner_args *args)
2417 struct compound_hdr hdr = {
2421 encode_compound_hdr(xdr, req, &hdr);
2422 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2427 * Encode a READLINK request
2429 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2430 const struct nfs4_readlink *args)
2432 struct compound_hdr hdr = {
2433 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2436 encode_compound_hdr(xdr, req, &hdr);
2437 encode_sequence(xdr, &args->seq_args, &hdr);
2438 encode_putfh(xdr, args->fh, &hdr);
2439 encode_readlink(xdr, args, req, &hdr);
2441 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2442 args->pgbase, args->pglen);
2447 * Encode a READDIR request
2449 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2450 const struct nfs4_readdir_arg *args)
2452 struct compound_hdr hdr = {
2453 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2456 encode_compound_hdr(xdr, req, &hdr);
2457 encode_sequence(xdr, &args->seq_args, &hdr);
2458 encode_putfh(xdr, args->fh, &hdr);
2459 encode_readdir(xdr, args, req, &hdr);
2461 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2462 args->pgbase, args->count);
2463 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2464 __func__, hdr.replen << 2, args->pages,
2465 args->pgbase, args->count);
2470 * Encode a READ request
2472 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2473 struct nfs_readargs *args)
2475 struct compound_hdr hdr = {
2476 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2479 encode_compound_hdr(xdr, req, &hdr);
2480 encode_sequence(xdr, &args->seq_args, &hdr);
2481 encode_putfh(xdr, args->fh, &hdr);
2482 encode_read(xdr, args, &hdr);
2484 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2485 args->pages, args->pgbase, args->count);
2486 req->rq_rcv_buf.flags |= XDRBUF_READ;
2491 * Encode an SETATTR request
2493 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2494 struct nfs_setattrargs *args)
2496 struct compound_hdr hdr = {
2497 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2500 encode_compound_hdr(xdr, req, &hdr);
2501 encode_sequence(xdr, &args->seq_args, &hdr);
2502 encode_putfh(xdr, args->fh, &hdr);
2503 encode_setattr(xdr, args, args->server, &hdr);
2504 encode_getfattr(xdr, args->bitmask, &hdr);
2509 * Encode a GETACL request
2511 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2512 struct nfs_getaclargs *args)
2514 struct compound_hdr hdr = {
2515 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2519 encode_compound_hdr(xdr, req, &hdr);
2520 encode_sequence(xdr, &args->seq_args, &hdr);
2521 encode_putfh(xdr, args->fh, &hdr);
2522 replen = hdr.replen + op_decode_hdr_maxsz + 1;
2523 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2525 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2526 args->acl_pages, args->acl_pgbase, args->acl_len);
2532 * Encode a WRITE request
2534 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2535 struct nfs_writeargs *args)
2537 struct compound_hdr hdr = {
2538 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2541 encode_compound_hdr(xdr, req, &hdr);
2542 encode_sequence(xdr, &args->seq_args, &hdr);
2543 encode_putfh(xdr, args->fh, &hdr);
2544 encode_write(xdr, args, &hdr);
2545 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2547 encode_getfattr(xdr, args->bitmask, &hdr);
2554 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2555 struct nfs_writeargs *args)
2557 struct compound_hdr hdr = {
2558 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2561 encode_compound_hdr(xdr, req, &hdr);
2562 encode_sequence(xdr, &args->seq_args, &hdr);
2563 encode_putfh(xdr, args->fh, &hdr);
2564 encode_commit(xdr, args, &hdr);
2566 encode_getfattr(xdr, args->bitmask, &hdr);
2573 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2574 struct nfs4_fsinfo_arg *args)
2576 struct compound_hdr hdr = {
2577 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2580 encode_compound_hdr(xdr, req, &hdr);
2581 encode_sequence(xdr, &args->seq_args, &hdr);
2582 encode_putfh(xdr, args->fh, &hdr);
2583 encode_fsinfo(xdr, args->bitmask, &hdr);
2588 * a PATHCONF request
2590 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2591 const struct nfs4_pathconf_arg *args)
2593 struct compound_hdr hdr = {
2594 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2597 encode_compound_hdr(xdr, req, &hdr);
2598 encode_sequence(xdr, &args->seq_args, &hdr);
2599 encode_putfh(xdr, args->fh, &hdr);
2600 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2608 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2609 const struct nfs4_statfs_arg *args)
2611 struct compound_hdr hdr = {
2612 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2615 encode_compound_hdr(xdr, req, &hdr);
2616 encode_sequence(xdr, &args->seq_args, &hdr);
2617 encode_putfh(xdr, args->fh, &hdr);
2618 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2619 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2624 * GETATTR_BITMAP request
2626 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2627 struct xdr_stream *xdr,
2628 struct nfs4_server_caps_arg *args)
2630 struct compound_hdr hdr = {
2631 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2634 encode_compound_hdr(xdr, req, &hdr);
2635 encode_sequence(xdr, &args->seq_args, &hdr);
2636 encode_putfh(xdr, args->fhandle, &hdr);
2637 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2638 FATTR4_WORD0_LINK_SUPPORT|
2639 FATTR4_WORD0_SYMLINK_SUPPORT|
2640 FATTR4_WORD0_ACLSUPPORT, &hdr);
2647 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2648 struct nfs_client *clp)
2650 struct compound_hdr hdr = {
2654 encode_compound_hdr(xdr, req, &hdr);
2655 encode_renew(xdr, clp, &hdr);
2660 * a SETCLIENTID request
2662 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2663 struct xdr_stream *xdr,
2664 struct nfs4_setclientid *sc)
2666 struct compound_hdr hdr = {
2670 encode_compound_hdr(xdr, req, &hdr);
2671 encode_setclientid(xdr, sc, &hdr);
2676 * a SETCLIENTID_CONFIRM request
2678 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2679 struct xdr_stream *xdr,
2680 struct nfs4_setclientid_res *arg)
2682 struct compound_hdr hdr = {
2685 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2687 encode_compound_hdr(xdr, req, &hdr);
2688 encode_setclientid_confirm(xdr, arg, &hdr);
2689 encode_putrootfh(xdr, &hdr);
2690 encode_fsinfo(xdr, lease_bitmap, &hdr);
2695 * DELEGRETURN request
2697 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2698 struct xdr_stream *xdr,
2699 const struct nfs4_delegreturnargs *args)
2701 struct compound_hdr hdr = {
2702 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2705 encode_compound_hdr(xdr, req, &hdr);
2706 encode_sequence(xdr, &args->seq_args, &hdr);
2707 encode_putfh(xdr, args->fhandle, &hdr);
2708 encode_delegreturn(xdr, args->stateid, &hdr);
2709 encode_getfattr(xdr, args->bitmask, &hdr);
2714 * Encode FS_LOCATIONS request
2716 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2717 struct xdr_stream *xdr,
2718 struct nfs4_fs_locations_arg *args)
2720 struct compound_hdr hdr = {
2721 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2725 encode_compound_hdr(xdr, req, &hdr);
2726 encode_sequence(xdr, &args->seq_args, &hdr);
2727 encode_putfh(xdr, args->dir_fh, &hdr);
2728 encode_lookup(xdr, args->name, &hdr);
2729 replen = hdr.replen; /* get the attribute into args->page */
2730 encode_fs_locations(xdr, args->bitmask, &hdr);
2732 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2738 * Encode SECINFO request
2740 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2741 struct xdr_stream *xdr,
2742 struct nfs4_secinfo_arg *args)
2744 struct compound_hdr hdr = {
2745 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2748 encode_compound_hdr(xdr, req, &hdr);
2749 encode_sequence(xdr, &args->seq_args, &hdr);
2750 encode_putfh(xdr, args->dir_fh, &hdr);
2751 encode_secinfo(xdr, args->name, &hdr);
2755 #if defined(CONFIG_NFS_V4_1)
2757 * EXCHANGE_ID request
2759 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2760 struct xdr_stream *xdr,
2761 struct nfs41_exchange_id_args *args)
2763 struct compound_hdr hdr = {
2764 .minorversion = args->client->cl_mvops->minor_version,
2767 encode_compound_hdr(xdr, req, &hdr);
2768 encode_exchange_id(xdr, args, &hdr);
2773 * a CREATE_SESSION request
2775 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2776 struct xdr_stream *xdr,
2777 struct nfs41_create_session_args *args)
2779 struct compound_hdr hdr = {
2780 .minorversion = args->client->cl_mvops->minor_version,
2783 encode_compound_hdr(xdr, req, &hdr);
2784 encode_create_session(xdr, args, &hdr);
2789 * a DESTROY_SESSION request
2791 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2792 struct xdr_stream *xdr,
2793 struct nfs4_session *session)
2795 struct compound_hdr hdr = {
2796 .minorversion = session->clp->cl_mvops->minor_version,
2799 encode_compound_hdr(xdr, req, &hdr);
2800 encode_destroy_session(xdr, session, &hdr);
2805 * a SEQUENCE request
2807 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2808 struct nfs4_sequence_args *args)
2810 struct compound_hdr hdr = {
2811 .minorversion = nfs4_xdr_minorversion(args),
2814 encode_compound_hdr(xdr, req, &hdr);
2815 encode_sequence(xdr, args, &hdr);
2820 * a GET_LEASE_TIME request
2822 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2823 struct xdr_stream *xdr,
2824 struct nfs4_get_lease_time_args *args)
2826 struct compound_hdr hdr = {
2827 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2829 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2831 encode_compound_hdr(xdr, req, &hdr);
2832 encode_sequence(xdr, &args->la_seq_args, &hdr);
2833 encode_putrootfh(xdr, &hdr);
2834 encode_fsinfo(xdr, lease_bitmap, &hdr);
2839 * a RECLAIM_COMPLETE request
2841 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2842 struct xdr_stream *xdr,
2843 struct nfs41_reclaim_complete_args *args)
2845 struct compound_hdr hdr = {
2846 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2849 encode_compound_hdr(xdr, req, &hdr);
2850 encode_sequence(xdr, &args->seq_args, &hdr);
2851 encode_reclaim_complete(xdr, args, &hdr);
2856 * Encode GETDEVICELIST request
2858 static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2859 struct xdr_stream *xdr,
2860 struct nfs4_getdevicelist_args *args)
2862 struct compound_hdr hdr = {
2863 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2866 encode_compound_hdr(xdr, req, &hdr);
2867 encode_sequence(xdr, &args->seq_args, &hdr);
2868 encode_putfh(xdr, args->fh, &hdr);
2869 encode_getdevicelist(xdr, args, &hdr);
2874 * Encode GETDEVICEINFO request
2876 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2877 struct xdr_stream *xdr,
2878 struct nfs4_getdeviceinfo_args *args)
2880 struct compound_hdr hdr = {
2881 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2884 encode_compound_hdr(xdr, req, &hdr);
2885 encode_sequence(xdr, &args->seq_args, &hdr);
2886 encode_getdeviceinfo(xdr, args, &hdr);
2888 /* set up reply kvec. Subtract notification bitmap max size (2)
2889 * so that notification bitmap is put in xdr_buf tail */
2890 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2891 args->pdev->pages, args->pdev->pgbase,
2898 * Encode LAYOUTGET request
2900 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2901 struct xdr_stream *xdr,
2902 struct nfs4_layoutget_args *args)
2904 struct compound_hdr hdr = {
2905 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2908 encode_compound_hdr(xdr, req, &hdr);
2909 encode_sequence(xdr, &args->seq_args, &hdr);
2910 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2911 encode_layoutget(xdr, args, &hdr);
2913 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2914 args->layout.pages, 0, args->layout.pglen);
2920 * Encode LAYOUTCOMMIT request
2922 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2923 struct xdr_stream *xdr,
2924 struct nfs4_layoutcommit_args *args)
2926 struct nfs4_layoutcommit_data *data =
2927 container_of(args, struct nfs4_layoutcommit_data, args);
2928 struct compound_hdr hdr = {
2929 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2932 encode_compound_hdr(xdr, req, &hdr);
2933 encode_sequence(xdr, &args->seq_args, &hdr);
2934 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2935 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2936 encode_getfattr(xdr, args->bitmask, &hdr);
2941 * Encode LAYOUTRETURN request
2943 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2944 struct xdr_stream *xdr,
2945 struct nfs4_layoutreturn_args *args)
2947 struct compound_hdr hdr = {
2948 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2951 encode_compound_hdr(xdr, req, &hdr);
2952 encode_sequence(xdr, &args->seq_args, &hdr);
2953 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2954 encode_layoutreturn(xdr, args, &hdr);
2959 * Encode SECINFO_NO_NAME request
2961 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2962 struct xdr_stream *xdr,
2963 struct nfs41_secinfo_no_name_args *args)
2965 struct compound_hdr hdr = {
2966 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2969 encode_compound_hdr(xdr, req, &hdr);
2970 encode_sequence(xdr, &args->seq_args, &hdr);
2971 encode_putrootfh(xdr, &hdr);
2972 encode_secinfo_no_name(xdr, args, &hdr);
2978 * Encode TEST_STATEID request
2980 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2981 struct xdr_stream *xdr,
2982 struct nfs41_test_stateid_args *args)
2984 struct compound_hdr hdr = {
2985 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2988 encode_compound_hdr(xdr, req, &hdr);
2989 encode_sequence(xdr, &args->seq_args, &hdr);
2990 encode_test_stateid(xdr, args, &hdr);
2995 * Encode FREE_STATEID request
2997 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2998 struct xdr_stream *xdr,
2999 struct nfs41_free_stateid_args *args)
3001 struct compound_hdr hdr = {
3002 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3005 encode_compound_hdr(xdr, req, &hdr);
3006 encode_sequence(xdr, &args->seq_args, &hdr);
3007 encode_free_stateid(xdr, args, &hdr);
3010 #endif /* CONFIG_NFS_V4_1 */
3012 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3014 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3015 "Remaining buffer length is %tu words.\n",
3016 func, xdr->end - xdr->p);
3019 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
3023 p = xdr_inline_decode(xdr, 4);
3026 *len = be32_to_cpup(p);
3027 p = xdr_inline_decode(xdr, *len);
3030 *string = (char *)p;
3033 print_overflow_msg(__func__, xdr);
3037 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3041 p = xdr_inline_decode(xdr, 8);
3044 hdr->status = be32_to_cpup(p++);
3045 hdr->taglen = be32_to_cpup(p);
3047 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3050 hdr->tag = (char *)p;
3051 p += XDR_QUADLEN(hdr->taglen);
3052 hdr->nops = be32_to_cpup(p);
3053 if (unlikely(hdr->nops < 1))
3054 return nfs4_stat_to_errno(hdr->status);
3057 print_overflow_msg(__func__, xdr);
3061 static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3068 p = xdr_inline_decode(xdr, 8);
3071 opnum = be32_to_cpup(p++);
3072 if (unlikely(opnum != expected))
3073 goto out_bad_operation;
3074 nfserr = be32_to_cpup(p);
3075 if (nfserr == NFS_OK)
3078 *nfs_retval = nfs4_stat_to_errno(nfserr);
3081 dprintk("nfs: Server returned operation"
3082 " %d but we issued a request for %d\n",
3084 *nfs_retval = -EREMOTEIO;
3087 print_overflow_msg(__func__, xdr);
3092 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3096 __decode_op_hdr(xdr, expected, &retval);
3101 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
3104 unsigned int strlen;
3107 p = xdr_inline_decode(xdr, 12);
3109 return decode_opaque_inline(xdr, &strlen, &str);
3110 print_overflow_msg(__func__, xdr);
3114 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3119 p = xdr_inline_decode(xdr, 4);
3122 bmlen = be32_to_cpup(p);
3124 bitmap[0] = bitmap[1] = bitmap[2] = 0;
3125 p = xdr_inline_decode(xdr, (bmlen << 2));
3129 bitmap[0] = be32_to_cpup(p++);
3131 bitmap[1] = be32_to_cpup(p++);
3133 bitmap[2] = be32_to_cpup(p);
3138 print_overflow_msg(__func__, xdr);
3142 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
3146 p = xdr_inline_decode(xdr, 4);
3149 *attrlen = be32_to_cpup(p);
3153 print_overflow_msg(__func__, xdr);
3157 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3159 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3161 ret = decode_attr_bitmap(xdr, bitmask);
3162 if (unlikely(ret < 0))
3164 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3166 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3167 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3168 bitmask[0], bitmask[1], bitmask[2]);
3172 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3178 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3180 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3181 p = xdr_inline_decode(xdr, 4);
3184 *type = be32_to_cpup(p);
3185 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3186 dprintk("%s: bad type %d\n", __func__, *type);
3189 bitmap[0] &= ~FATTR4_WORD0_TYPE;
3190 ret = NFS_ATTR_FATTR_TYPE;
3192 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3195 print_overflow_msg(__func__, xdr);
3199 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3205 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3207 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3208 p = xdr_inline_decode(xdr, 8);
3211 xdr_decode_hyper(p, change);
3212 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3213 ret = NFS_ATTR_FATTR_CHANGE;
3215 dprintk("%s: change attribute=%Lu\n", __func__,
3216 (unsigned long long)*change);
3219 print_overflow_msg(__func__, xdr);
3223 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3229 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3231 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3232 p = xdr_inline_decode(xdr, 8);
3235 xdr_decode_hyper(p, size);
3236 bitmap[0] &= ~FATTR4_WORD0_SIZE;
3237 ret = NFS_ATTR_FATTR_SIZE;
3239 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3242 print_overflow_msg(__func__, xdr);
3246 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3251 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3253 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3254 p = xdr_inline_decode(xdr, 4);
3257 *res = be32_to_cpup(p);
3258 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3260 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3263 print_overflow_msg(__func__, xdr);
3267 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3272 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3274 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3275 p = xdr_inline_decode(xdr, 4);
3278 *res = be32_to_cpup(p);
3279 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3281 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3284 print_overflow_msg(__func__, xdr);
3288 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3295 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3297 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3298 p = xdr_inline_decode(xdr, 16);
3301 p = xdr_decode_hyper(p, &fsid->major);
3302 xdr_decode_hyper(p, &fsid->minor);
3303 bitmap[0] &= ~FATTR4_WORD0_FSID;
3304 ret = NFS_ATTR_FATTR_FSID;
3306 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3307 (unsigned long long)fsid->major,
3308 (unsigned long long)fsid->minor);
3311 print_overflow_msg(__func__, xdr);
3315 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3320 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3322 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3323 p = xdr_inline_decode(xdr, 4);
3326 *res = be32_to_cpup(p);
3327 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3329 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
3332 print_overflow_msg(__func__, xdr);
3336 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3340 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3342 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3343 p = xdr_inline_decode(xdr, 4);
3346 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3347 *res = -be32_to_cpup(p);
3351 print_overflow_msg(__func__, xdr);
3355 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3361 memset(fh, 0, sizeof(*fh));
3363 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3365 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3366 p = xdr_inline_decode(xdr, 4);
3369 len = be32_to_cpup(p);
3370 if (len > NFS4_FHSIZE)
3372 p = xdr_inline_decode(xdr, len);
3376 memcpy(fh->data, p, len);
3379 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3383 print_overflow_msg(__func__, xdr);
3387 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3391 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3392 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3394 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3395 p = xdr_inline_decode(xdr, 4);
3398 *res = be32_to_cpup(p);
3399 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3401 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3404 print_overflow_msg(__func__, xdr);
3408 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3414 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3416 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3417 p = xdr_inline_decode(xdr, 8);
3420 xdr_decode_hyper(p, fileid);
3421 bitmap[0] &= ~FATTR4_WORD0_FILEID;
3422 ret = NFS_ATTR_FATTR_FILEID;
3424 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3427 print_overflow_msg(__func__, xdr);
3431 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3437 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3439 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3440 p = xdr_inline_decode(xdr, 8);
3443 xdr_decode_hyper(p, fileid);
3444 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3445 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3447 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3450 print_overflow_msg(__func__, xdr);
3454 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3460 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3462 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3463 p = xdr_inline_decode(xdr, 8);
3466 xdr_decode_hyper(p, res);
3467 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3469 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3472 print_overflow_msg(__func__, xdr);
3476 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3482 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3484 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3485 p = xdr_inline_decode(xdr, 8);
3488 xdr_decode_hyper(p, res);
3489 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3491 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3494 print_overflow_msg(__func__, xdr);
3498 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3504 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3506 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3507 p = xdr_inline_decode(xdr, 8);
3510 xdr_decode_hyper(p, res);
3511 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3513 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3516 print_overflow_msg(__func__, xdr);
3520 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3526 p = xdr_inline_decode(xdr, 4);
3529 n = be32_to_cpup(p);
3533 path->ncomponents = 0;
3534 while (path->ncomponents < n) {
3535 struct nfs4_string *component = &path->components[path->ncomponents];
3536 status = decode_opaque_inline(xdr, &component->len, &component->data);
3537 if (unlikely(status != 0))
3539 if (path->ncomponents != n)
3541 dprintk("%s", component->data);
3542 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3543 path->ncomponents++;
3545 dprintk("cannot parse %d components in path\n", n);
3553 /* a root pathname is sent as a zero component4 */
3554 path->ncomponents = 1;
3555 path->components[0].len=0;
3556 path->components[0].data=NULL;
3557 dprintk("path /\n");
3560 dprintk(" status %d", status);
3564 print_overflow_msg(__func__, xdr);
3568 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3574 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3577 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3579 dprintk("%s: fsroot ", __func__);
3580 status = decode_pathname(xdr, &res->fs_path);
3581 if (unlikely(status != 0))
3583 p = xdr_inline_decode(xdr, 4);
3586 n = be32_to_cpup(p);
3589 res->nlocations = 0;
3590 while (res->nlocations < n) {
3592 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
3594 p = xdr_inline_decode(xdr, 4);
3597 m = be32_to_cpup(p);
3600 dprintk("%s: servers ", __func__);
3601 while (loc->nservers < m) {
3602 struct nfs4_string *server = &loc->servers[loc->nservers];
3603 status = decode_opaque_inline(xdr, &server->len, &server->data);
3604 if (unlikely(status != 0))
3606 dprintk("%s ", server->data);
3607 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3611 dprintk("%s: using first %u of %u servers "
3612 "returned for location %u\n",
3614 NFS4_FS_LOCATION_MAXSERVERS,
3615 m, res->nlocations);
3616 for (i = loc->nservers; i < m; i++) {
3619 status = decode_opaque_inline(xdr, &len, &data);
3620 if (unlikely(status != 0))
3625 status = decode_pathname(xdr, &loc->rootpath);
3626 if (unlikely(status != 0))
3628 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
3631 if (res->nlocations != 0)
3632 status = NFS_ATTR_FATTR_V4_REFERRAL;
3634 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3637 print_overflow_msg(__func__, xdr);
3643 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3649 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3651 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3652 p = xdr_inline_decode(xdr, 8);
3655 xdr_decode_hyper(p, res);
3656 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3658 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3661 print_overflow_msg(__func__, xdr);
3665 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3671 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3673 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3674 p = xdr_inline_decode(xdr, 4);
3677 *maxlink = be32_to_cpup(p);
3678 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3680 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3683 print_overflow_msg(__func__, xdr);
3687 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3693 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3695 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3696 p = xdr_inline_decode(xdr, 4);
3699 *maxname = be32_to_cpup(p);
3700 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3702 dprintk("%s: maxname=%u\n", __func__, *maxname);
3705 print_overflow_msg(__func__, xdr);
3709 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3715 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3717 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3719 p = xdr_inline_decode(xdr, 8);
3722 xdr_decode_hyper(p, &maxread);
3723 if (maxread > 0x7FFFFFFF)
3724 maxread = 0x7FFFFFFF;
3725 *res = (uint32_t)maxread;
3726 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3728 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3731 print_overflow_msg(__func__, xdr);
3735 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3741 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3743 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3745 p = xdr_inline_decode(xdr, 8);
3748 xdr_decode_hyper(p, &maxwrite);
3749 if (maxwrite > 0x7FFFFFFF)
3750 maxwrite = 0x7FFFFFFF;
3751 *res = (uint32_t)maxwrite;
3752 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3754 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3757 print_overflow_msg(__func__, xdr);
3761 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3768 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3770 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3771 p = xdr_inline_decode(xdr, 4);
3774 tmp = be32_to_cpup(p);
3775 *mode = tmp & ~S_IFMT;
3776 bitmap[1] &= ~FATTR4_WORD1_MODE;
3777 ret = NFS_ATTR_FATTR_MODE;
3779 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3782 print_overflow_msg(__func__, xdr);
3786 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3792 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3794 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3795 p = xdr_inline_decode(xdr, 4);
3798 *nlink = be32_to_cpup(p);
3799 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3800 ret = NFS_ATTR_FATTR_NLINK;
3802 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3805 print_overflow_msg(__func__, xdr);
3809 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3810 const struct nfs_server *server, uint32_t *uid, int may_sleep)
3817 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3819 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3820 p = xdr_inline_decode(xdr, 4);
3823 len = be32_to_cpup(p);
3824 p = xdr_inline_decode(xdr, len);
3829 } else if (len < XDR_MAX_NETOBJ) {
3830 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3831 ret = NFS_ATTR_FATTR_OWNER;
3833 dprintk("%s: nfs_map_name_to_uid failed!\n",
3836 dprintk("%s: name too long (%u)!\n",
3838 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3840 dprintk("%s: uid=%d\n", __func__, (int)*uid);
3843 print_overflow_msg(__func__, xdr);
3847 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3848 const struct nfs_server *server, uint32_t *gid, int may_sleep)
3855 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3857 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3858 p = xdr_inline_decode(xdr, 4);
3861 len = be32_to_cpup(p);
3862 p = xdr_inline_decode(xdr, len);
3867 } else if (len < XDR_MAX_NETOBJ) {
3868 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3869 ret = NFS_ATTR_FATTR_GROUP;
3871 dprintk("%s: nfs_map_group_to_gid failed!\n",
3874 dprintk("%s: name too long (%u)!\n",
3876 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3878 dprintk("%s: gid=%d\n", __func__, (int)*gid);
3881 print_overflow_msg(__func__, xdr);
3885 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3887 uint32_t major = 0, minor = 0;
3892 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3894 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3897 p = xdr_inline_decode(xdr, 8);
3900 major = be32_to_cpup(p++);
3901 minor = be32_to_cpup(p);
3902 tmp = MKDEV(major, minor);
3903 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3905 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3906 ret = NFS_ATTR_FATTR_RDEV;
3908 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3911 print_overflow_msg(__func__, xdr);
3915 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3921 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3923 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3924 p = xdr_inline_decode(xdr, 8);
3927 xdr_decode_hyper(p, res);
3928 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3930 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3933 print_overflow_msg(__func__, xdr);
3937 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3943 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3945 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3946 p = xdr_inline_decode(xdr, 8);
3949 xdr_decode_hyper(p, res);
3950 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3952 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3955 print_overflow_msg(__func__, xdr);
3959 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3965 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3967 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3968 p = xdr_inline_decode(xdr, 8);
3971 xdr_decode_hyper(p, res);
3972 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3974 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
3977 print_overflow_msg(__func__, xdr);
3981 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3987 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3989 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3990 p = xdr_inline_decode(xdr, 8);
3993 xdr_decode_hyper(p, used);
3994 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
3995 ret = NFS_ATTR_FATTR_SPACE_USED;
3997 dprintk("%s: space used=%Lu\n", __func__,
3998 (unsigned long long)*used);
4001 print_overflow_msg(__func__, xdr);
4005 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4011 p = xdr_inline_decode(xdr, 12);
4014 p = xdr_decode_hyper(p, &sec);
4015 nsec = be32_to_cpup(p);
4016 time->tv_sec = (time_t)sec;
4017 time->tv_nsec = (long)nsec;
4020 print_overflow_msg(__func__, xdr);
4024 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4030 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4032 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4033 status = decode_attr_time(xdr, time);
4035 status = NFS_ATTR_FATTR_ATIME;
4036 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4038 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
4042 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4048 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4050 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4051 status = decode_attr_time(xdr, time);
4053 status = NFS_ATTR_FATTR_CTIME;
4054 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4056 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
4060 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4061 struct timespec *time)
4067 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4069 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4070 status = decode_attr_time(xdr, time);
4071 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4073 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4074 (long)time->tv_nsec);
4078 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4084 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4086 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4087 status = decode_attr_time(xdr, time);
4089 status = NFS_ATTR_FATTR_MTIME;
4090 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4092 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
4096 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
4098 unsigned int attrwords = XDR_QUADLEN(attrlen);
4099 unsigned int nwords = xdr->p - savep;
4101 if (unlikely(attrwords != nwords)) {
4102 dprintk("%s: server returned incorrect attribute length: "
4106 (attrwords < nwords) ? '<' : '>',
4113 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4117 p = xdr_inline_decode(xdr, 20);
4120 cinfo->atomic = be32_to_cpup(p++);
4121 p = xdr_decode_hyper(p, &cinfo->before);
4122 xdr_decode_hyper(p, &cinfo->after);
4125 print_overflow_msg(__func__, xdr);
4129 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4135 status = decode_op_hdr(xdr, OP_ACCESS);
4138 p = xdr_inline_decode(xdr, 8);
4141 supp = be32_to_cpup(p++);
4142 acc = be32_to_cpup(p);
4143 access->supported = supp;
4144 access->access = acc;
4147 print_overflow_msg(__func__, xdr);
4151 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4155 p = xdr_inline_decode(xdr, len);
4157 memcpy(buf, p, len);
4160 print_overflow_msg(__func__, xdr);
4164 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4166 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
4169 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4173 status = decode_op_hdr(xdr, OP_CLOSE);
4175 nfs_increment_open_seqid(status, res->seqid);
4177 status = decode_stateid(xdr, &res->stateid);
4181 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4183 return decode_opaque_fixed(xdr, verifier, 8);
4186 static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4190 status = decode_op_hdr(xdr, OP_COMMIT);
4192 status = decode_verifier(xdr, res->verf->verifier);
4196 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4202 status = decode_op_hdr(xdr, OP_CREATE);
4205 if ((status = decode_change_info(xdr, cinfo)))
4207 p = xdr_inline_decode(xdr, 4);
4210 bmlen = be32_to_cpup(p);
4211 p = xdr_inline_decode(xdr, bmlen << 2);
4215 print_overflow_msg(__func__, xdr);
4219 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4222 uint32_t attrlen, bitmap[3] = {0};
4225 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4227 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4229 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4231 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4233 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4235 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4237 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4239 status = verify_attr_len(xdr, savep, attrlen);
4241 dprintk("%s: xdr returned %d!\n", __func__, -status);
4245 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4248 uint32_t attrlen, bitmap[3] = {0};
4251 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4253 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4255 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4258 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4260 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4262 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4264 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4266 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4268 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4271 status = verify_attr_len(xdr, savep, attrlen);
4273 dprintk("%s: xdr returned %d!\n", __func__, -status);
4277 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4280 uint32_t attrlen, bitmap[3] = {0};
4283 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4285 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4287 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4290 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4292 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4295 status = verify_attr_len(xdr, savep, attrlen);
4297 dprintk("%s: xdr returned %d!\n", __func__, -status);
4301 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4302 struct nfs_fattr *fattr, struct nfs_fh *fh,
4303 const struct nfs_server *server, int may_sleep)
4310 status = decode_attr_type(xdr, bitmap, &type);
4315 fattr->mode |= nfs_type2fmt[type];
4316 fattr->valid |= status;
4319 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4322 fattr->valid |= status;
4324 status = decode_attr_size(xdr, bitmap, &fattr->size);
4327 fattr->valid |= status;
4329 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4332 fattr->valid |= status;
4335 status = decode_attr_error(xdr, bitmap, &err);
4338 if (err == -NFS4ERR_WRONGSEC)
4339 nfs_fixup_secinfo_attributes(fattr, fh);
4341 status = decode_attr_filehandle(xdr, bitmap, fh);
4345 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4348 fattr->valid |= status;
4350 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
4351 struct nfs4_fs_locations,
4355 fattr->valid |= status;
4357 status = decode_attr_mode(xdr, bitmap, &fmode);
4361 fattr->mode |= fmode;
4362 fattr->valid |= status;
4365 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4368 fattr->valid |= status;
4370 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
4373 fattr->valid |= status;
4375 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
4378 fattr->valid |= status;
4380 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4383 fattr->valid |= status;
4385 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4388 fattr->valid |= status;
4390 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4393 fattr->valid |= status;
4395 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4398 fattr->valid |= status;
4400 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4403 fattr->valid |= status;
4405 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4408 fattr->valid |= status;
4411 dprintk("%s: xdr returned %d\n", __func__, -status);
4415 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4416 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4423 status = decode_op_hdr(xdr, OP_GETATTR);
4427 status = decode_attr_bitmap(xdr, bitmap);
4431 status = decode_attr_length(xdr, &attrlen, &savep);
4435 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4439 status = verify_attr_len(xdr, savep, attrlen);
4441 dprintk("%s: xdr returned %d\n", __func__, -status);
4445 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4446 const struct nfs_server *server, int may_sleep)
4448 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4452 * Decode potentially multiple layout types. Currently we only support
4453 * one layout driver per file system.
4455 static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4456 uint32_t *layouttype)
4461 p = xdr_inline_decode(xdr, 4);
4464 num = be32_to_cpup(p);
4466 /* pNFS is not supported by the underlying file system */
4472 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4473 "per filesystem not supported\n", __func__);
4475 /* Decode and set first layout type, move xdr->p past unused types */
4476 p = xdr_inline_decode(xdr, num * 4);
4479 *layouttype = be32_to_cpup(p);
4482 print_overflow_msg(__func__, xdr);
4487 * The type of file system exported.
4488 * Note we must ensure that layouttype is set in any non-error case.
4490 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4491 uint32_t *layouttype)
4495 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4496 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4498 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4499 status = decode_first_pnfs_layout_type(xdr, layouttype);
4500 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4507 * The prefered block size for layout directed io
4509 static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4514 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4516 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4517 p = xdr_inline_decode(xdr, 4);
4519 print_overflow_msg(__func__, xdr);
4522 *res = be32_to_cpup(p);
4523 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4528 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4531 uint32_t attrlen, bitmap[3];
4534 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4536 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4538 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4541 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4543 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4545 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4547 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4549 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4550 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4552 fsinfo->wtpref = fsinfo->wtmax;
4553 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4556 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4559 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4563 status = verify_attr_len(xdr, savep, attrlen);
4565 dprintk("%s: xdr returned %d!\n", __func__, -status);
4569 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4575 /* Zero handle first to allow comparisons */
4576 memset(fh, 0, sizeof(*fh));
4578 status = decode_op_hdr(xdr, OP_GETFH);
4582 p = xdr_inline_decode(xdr, 4);
4585 len = be32_to_cpup(p);
4586 if (len > NFS4_FHSIZE)
4589 p = xdr_inline_decode(xdr, len);
4592 memcpy(fh->data, p, len);
4595 print_overflow_msg(__func__, xdr);
4599 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4603 status = decode_op_hdr(xdr, OP_LINK);
4606 return decode_change_info(xdr, cinfo);
4610 * We create the owner, so we know a proper owner.id length is 4.
4612 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4614 uint64_t offset, length, clientid;
4616 uint32_t namelen, type;
4618 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4621 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4622 p = xdr_decode_hyper(p, &length);
4623 type = be32_to_cpup(p++); /* 4 byte read */
4624 if (fl != NULL) { /* manipulate file lock */
4625 fl->fl_start = (loff_t)offset;
4626 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4627 if (length == ~(uint64_t)0)
4628 fl->fl_end = OFFSET_MAX;
4629 fl->fl_type = F_WRLCK;
4631 fl->fl_type = F_RDLCK;
4634 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4635 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4636 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4638 return -NFS4ERR_DENIED;
4640 print_overflow_msg(__func__, xdr);
4644 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4648 status = decode_op_hdr(xdr, OP_LOCK);
4652 status = decode_stateid(xdr, &res->stateid);
4653 if (unlikely(status))
4655 } else if (status == -NFS4ERR_DENIED)
4656 status = decode_lock_denied(xdr, NULL);
4657 if (res->open_seqid != NULL)
4658 nfs_increment_open_seqid(status, res->open_seqid);
4659 nfs_increment_lock_seqid(status, res->lock_seqid);
4664 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4667 status = decode_op_hdr(xdr, OP_LOCKT);
4668 if (status == -NFS4ERR_DENIED)
4669 return decode_lock_denied(xdr, res->denied);
4673 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
4677 status = decode_op_hdr(xdr, OP_LOCKU);
4679 nfs_increment_lock_seqid(status, res->seqid);
4681 status = decode_stateid(xdr, &res->stateid);
4685 static int decode_release_lockowner(struct xdr_stream *xdr)
4687 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4690 static int decode_lookup(struct xdr_stream *xdr)
4692 return decode_op_hdr(xdr, OP_LOOKUP);
4695 /* This is too sick! */
4696 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4699 uint32_t limit_type, nblocks, blocksize;
4701 p = xdr_inline_decode(xdr, 12);
4704 limit_type = be32_to_cpup(p++);
4705 switch (limit_type) {
4707 xdr_decode_hyper(p, maxsize);
4710 nblocks = be32_to_cpup(p++);
4711 blocksize = be32_to_cpup(p);
4712 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
4716 print_overflow_msg(__func__, xdr);
4720 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4723 uint32_t delegation_type;
4726 p = xdr_inline_decode(xdr, 4);
4729 delegation_type = be32_to_cpup(p);
4730 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4731 res->delegation_type = 0;
4734 status = decode_stateid(xdr, &res->delegation);
4735 if (unlikely(status))
4737 p = xdr_inline_decode(xdr, 4);
4740 res->do_recall = be32_to_cpup(p);
4742 switch (delegation_type) {
4743 case NFS4_OPEN_DELEGATE_READ:
4744 res->delegation_type = FMODE_READ;
4746 case NFS4_OPEN_DELEGATE_WRITE:
4747 res->delegation_type = FMODE_WRITE|FMODE_READ;
4748 if (decode_space_limit(xdr, &res->maxsize) < 0)
4751 return decode_ace(xdr, NULL, res->server->nfs_client);
4753 print_overflow_msg(__func__, xdr);
4757 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4760 uint32_t savewords, bmlen, i;
4763 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
4765 nfs_increment_open_seqid(status, res->seqid);
4768 status = decode_stateid(xdr, &res->stateid);
4769 if (unlikely(status))
4772 decode_change_info(xdr, &res->cinfo);
4774 p = xdr_inline_decode(xdr, 8);
4777 res->rflags = be32_to_cpup(p++);
4778 bmlen = be32_to_cpup(p);
4782 p = xdr_inline_decode(xdr, bmlen << 2);
4785 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4786 for (i = 0; i < savewords; ++i)
4787 res->attrset[i] = be32_to_cpup(p++);
4788 for (; i < NFS4_BITMAP_SIZE; i++)
4789 res->attrset[i] = 0;
4791 return decode_delegation(xdr, res);
4793 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
4796 print_overflow_msg(__func__, xdr);
4800 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4804 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
4806 nfs_increment_open_seqid(status, res->seqid);
4808 status = decode_stateid(xdr, &res->stateid);
4812 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4816 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
4818 nfs_increment_open_seqid(status, res->seqid);
4820 status = decode_stateid(xdr, &res->stateid);
4824 static int decode_putfh(struct xdr_stream *xdr)
4826 return decode_op_hdr(xdr, OP_PUTFH);
4829 static int decode_putrootfh(struct xdr_stream *xdr)
4831 return decode_op_hdr(xdr, OP_PUTROOTFH);
4834 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4836 struct kvec *iov = req->rq_rcv_buf.head;
4838 uint32_t count, eof, recvd, hdrlen;
4841 status = decode_op_hdr(xdr, OP_READ);
4844 p = xdr_inline_decode(xdr, 8);
4847 eof = be32_to_cpup(p++);
4848 count = be32_to_cpup(p);
4849 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
4850 recvd = req->rq_rcv_buf.len - hdrlen;
4851 if (count > recvd) {
4852 dprintk("NFS: server cheating in read reply: "
4853 "count %u > recvd %u\n", count, recvd);
4857 xdr_read_pages(xdr, count);
4862 print_overflow_msg(__func__, xdr);
4866 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4868 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4869 struct kvec *iov = rcvbuf->head;
4871 u32 recvd, pglen = rcvbuf->page_len;
4874 status = decode_op_hdr(xdr, OP_READDIR);
4876 status = decode_verifier(xdr, readdir->verifier.data);
4877 if (unlikely(status))
4879 dprintk("%s: verifier = %08x:%08x\n",
4881 ((u32 *)readdir->verifier.data)[0],
4882 ((u32 *)readdir->verifier.data)[1]);
4885 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4886 recvd = rcvbuf->len - hdrlen;
4889 xdr_read_pages(xdr, pglen);
4895 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4897 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4898 struct kvec *iov = rcvbuf->head;
4904 status = decode_op_hdr(xdr, OP_READLINK);
4908 /* Convert length of symlink */
4909 p = xdr_inline_decode(xdr, 4);
4912 len = be32_to_cpup(p);
4913 if (len >= rcvbuf->page_len || len <= 0) {
4914 dprintk("nfs: server returned giant symlink!\n");
4915 return -ENAMETOOLONG;
4917 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4918 recvd = req->rq_rcv_buf.len - hdrlen;
4920 dprintk("NFS: server cheating in readlink reply: "
4921 "count %u > recvd %u\n", len, recvd);
4924 xdr_read_pages(xdr, len);
4926 * The XDR encode routine has set things up so that
4927 * the link text will be copied directly into the
4928 * buffer. We just have to do overflow-checking,
4929 * and and null-terminate the text (the VFS expects
4930 * null-termination).
4932 xdr_terminate_string(rcvbuf, len);
4935 print_overflow_msg(__func__, xdr);
4939 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4943 status = decode_op_hdr(xdr, OP_REMOVE);
4946 status = decode_change_info(xdr, cinfo);
4951 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4952 struct nfs4_change_info *new_cinfo)
4956 status = decode_op_hdr(xdr, OP_RENAME);
4959 if ((status = decode_change_info(xdr, old_cinfo)))
4961 status = decode_change_info(xdr, new_cinfo);
4966 static int decode_renew(struct xdr_stream *xdr)
4968 return decode_op_hdr(xdr, OP_RENEW);
4972 decode_restorefh(struct xdr_stream *xdr)
4974 return decode_op_hdr(xdr, OP_RESTOREFH);
4977 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4978 struct nfs_getaclres *res)
4980 __be32 *savep, *bm_p;
4983 struct kvec *iov = req->rq_rcv_buf.head;
4985 size_t page_len = xdr->buf->page_len;
4988 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4992 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4993 res->acl_data_offset <<= 2;
4994 /* Check if the acl data starts beyond the allocated buffer */
4995 if (res->acl_data_offset > page_len)
4998 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5000 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5003 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5005 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5008 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5009 * are stored with the acl data to handle the problem of
5010 * variable length bitmaps.*/
5013 /* We ignore &savep and don't do consistency checks on
5014 * the attr length. Let userspace figure it out.... */
5015 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
5016 attrlen += res->acl_data_offset;
5017 if (attrlen > page_len) {
5018 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
5019 /* getxattr interface called with a NULL buf */
5020 res->acl_len = attrlen;
5023 dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
5027 xdr_read_pages(xdr, attrlen);
5028 res->acl_len = attrlen;
5030 status = -EOPNOTSUPP;
5037 decode_savefh(struct xdr_stream *xdr)
5039 return decode_op_hdr(xdr, OP_SAVEFH);
5042 static int decode_setattr(struct xdr_stream *xdr)
5048 status = decode_op_hdr(xdr, OP_SETATTR);
5051 p = xdr_inline_decode(xdr, 4);
5054 bmlen = be32_to_cpup(p);
5055 p = xdr_inline_decode(xdr, bmlen << 2);
5059 print_overflow_msg(__func__, xdr);
5063 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
5069 p = xdr_inline_decode(xdr, 8);
5072 opnum = be32_to_cpup(p++);
5073 if (opnum != OP_SETCLIENTID) {
5074 dprintk("nfs: decode_setclientid: Server returned operation"
5078 nfserr = be32_to_cpup(p);
5079 if (nfserr == NFS_OK) {
5080 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5083 p = xdr_decode_hyper(p, &res->clientid);
5084 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
5085 } else if (nfserr == NFSERR_CLID_INUSE) {
5088 /* skip netid string */
5089 p = xdr_inline_decode(xdr, 4);
5092 len = be32_to_cpup(p);
5093 p = xdr_inline_decode(xdr, len);
5097 /* skip uaddr string */
5098 p = xdr_inline_decode(xdr, 4);
5101 len = be32_to_cpup(p);
5102 p = xdr_inline_decode(xdr, len);
5105 return -NFSERR_CLID_INUSE;
5107 return nfs4_stat_to_errno(nfserr);
5111 print_overflow_msg(__func__, xdr);
5115 static int decode_setclientid_confirm(struct xdr_stream *xdr)
5117 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5120 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5125 status = decode_op_hdr(xdr, OP_WRITE);
5129 p = xdr_inline_decode(xdr, 16);
5132 res->count = be32_to_cpup(p++);
5133 res->verf->committed = be32_to_cpup(p++);
5134 memcpy(res->verf->verifier, p, 8);
5137 print_overflow_msg(__func__, xdr);
5141 static int decode_delegreturn(struct xdr_stream *xdr)
5143 return decode_op_hdr(xdr, OP_DELEGRETURN);
5146 static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5150 p = xdr_inline_decode(xdr, 4);
5153 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5154 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5157 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5160 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5162 p = xdr_inline_decode(xdr, 8);
5165 flavor->gss.qop4 = be32_to_cpup(p++);
5166 flavor->gss.service = be32_to_cpup(p);
5171 print_overflow_msg(__func__, xdr);
5177 static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5179 struct nfs4_secinfo_flavor *sec_flavor;
5184 status = decode_op_hdr(xdr, OP_SECINFO);
5187 p = xdr_inline_decode(xdr, 4);
5191 res->flavors->num_flavors = 0;
5192 num_flavors = be32_to_cpup(p);
5194 for (i = 0; i < num_flavors; i++) {
5195 sec_flavor = &res->flavors->flavors[i];
5196 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5199 p = xdr_inline_decode(xdr, 4);
5202 sec_flavor->flavor = be32_to_cpup(p);
5204 if (sec_flavor->flavor == RPC_AUTH_GSS) {
5205 status = decode_secinfo_gss(xdr, sec_flavor);
5209 res->flavors->num_flavors++;
5215 print_overflow_msg(__func__, xdr);
5219 #if defined(CONFIG_NFS_V4_1)
5220 static int decode_exchange_id(struct xdr_stream *xdr,
5221 struct nfs41_exchange_id_res *res)
5227 struct nfs_client *clp = res->client;
5229 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5233 p = xdr_inline_decode(xdr, 8);
5236 xdr_decode_hyper(p, &clp->cl_clientid);
5237 p = xdr_inline_decode(xdr, 12);
5240 clp->cl_seqid = be32_to_cpup(p++);
5241 clp->cl_exchange_flags = be32_to_cpup(p++);
5243 /* We ask for SP4_NONE */
5244 dummy = be32_to_cpup(p);
5245 if (dummy != SP4_NONE)
5248 /* Throw away minor_id */
5249 p = xdr_inline_decode(xdr, 8);
5253 /* Throw away Major id */
5254 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5255 if (unlikely(status))
5258 /* Save server_scope */
5259 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5260 if (unlikely(status))
5263 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5266 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5267 res->server_scope->server_scope_sz = dummy;
5269 /* Throw away Implementation id array */
5270 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5271 if (unlikely(status))
5276 print_overflow_msg(__func__, xdr);
5280 static int decode_chan_attrs(struct xdr_stream *xdr,
5281 struct nfs4_channel_attrs *attrs)
5286 p = xdr_inline_decode(xdr, 28);
5289 val = be32_to_cpup(p++); /* headerpadsz */
5291 return -EINVAL; /* no support for header padding yet */
5292 attrs->max_rqst_sz = be32_to_cpup(p++);
5293 attrs->max_resp_sz = be32_to_cpup(p++);
5294 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5295 attrs->max_ops = be32_to_cpup(p++);
5296 attrs->max_reqs = be32_to_cpup(p++);
5297 nr_attrs = be32_to_cpup(p);
5298 if (unlikely(nr_attrs > 1)) {
5299 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
5300 __func__, nr_attrs);
5303 if (nr_attrs == 1) {
5304 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5310 print_overflow_msg(__func__, xdr);
5314 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5316 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5319 static int decode_create_session(struct xdr_stream *xdr,
5320 struct nfs41_create_session_res *res)
5324 struct nfs_client *clp = res->client;
5325 struct nfs4_session *session = clp->cl_session;
5327 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5329 status = decode_sessionid(xdr, &session->sess_id);
5330 if (unlikely(status))
5334 p = xdr_inline_decode(xdr, 8);
5337 clp->cl_seqid = be32_to_cpup(p++);
5338 session->flags = be32_to_cpup(p);
5340 /* Channel attributes */
5341 status = decode_chan_attrs(xdr, &session->fc_attrs);
5343 status = decode_chan_attrs(xdr, &session->bc_attrs);
5346 print_overflow_msg(__func__, xdr);
5350 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5352 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5355 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5357 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5359 #endif /* CONFIG_NFS_V4_1 */
5361 static int decode_sequence(struct xdr_stream *xdr,
5362 struct nfs4_sequence_res *res,
5363 struct rpc_rqst *rqstp)
5365 #if defined(CONFIG_NFS_V4_1)
5366 struct nfs4_sessionid id;
5371 if (!res->sr_session)
5374 status = decode_op_hdr(xdr, OP_SEQUENCE);
5376 status = decode_sessionid(xdr, &id);
5377 if (unlikely(status))
5381 * If the server returns different values for sessionID, slotID or
5382 * sequence number, the server is looney tunes.
5384 status = -EREMOTEIO;
5386 if (memcmp(id.data, res->sr_session->sess_id.data,
5387 NFS4_MAX_SESSIONID_LEN)) {
5388 dprintk("%s Invalid session id\n", __func__);
5392 p = xdr_inline_decode(xdr, 20);
5397 dummy = be32_to_cpup(p++);
5398 if (dummy != res->sr_slot->seq_nr) {
5399 dprintk("%s Invalid sequence number\n", __func__);
5403 dummy = be32_to_cpup(p++);
5404 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
5405 dprintk("%s Invalid slot id\n", __func__);
5408 /* highest slot id - currently not processed */
5409 dummy = be32_to_cpup(p++);
5410 /* target highest slot id - currently not processed */
5411 dummy = be32_to_cpup(p++);
5413 res->sr_status_flags = be32_to_cpup(p);
5416 res->sr_status = status;
5419 print_overflow_msg(__func__, xdr);
5422 #else /* CONFIG_NFS_V4_1 */
5424 #endif /* CONFIG_NFS_V4_1 */
5427 #if defined(CONFIG_NFS_V4_1)
5429 * TODO: Need to handle case when EOF != true;
5431 static int decode_getdevicelist(struct xdr_stream *xdr,
5432 struct pnfs_devicelist *res)
5436 struct nfs_writeverf verftemp;
5438 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5442 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5446 /* TODO: Skip cookie for now */
5450 p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8);
5452 res->num_devs = be32_to_cpup(p);
5454 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5456 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
5457 printk(KERN_ERR "%s too many result dev_num %u\n",
5458 __func__, res->num_devs);
5462 p = xdr_inline_decode(xdr,
5463 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5466 for (i = 0; i < res->num_devs; i++)
5467 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5468 NFS4_DEVICEID4_SIZE);
5469 res->eof = be32_to_cpup(p);
5472 print_overflow_msg(__func__, xdr);
5476 static int decode_getdeviceinfo(struct xdr_stream *xdr,
5477 struct pnfs_device *pdev)
5483 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5485 if (status == -ETOOSMALL) {
5486 p = xdr_inline_decode(xdr, 4);
5489 pdev->mincount = be32_to_cpup(p);
5490 dprintk("%s: Min count too small. mincnt = %u\n",
5491 __func__, pdev->mincount);
5496 p = xdr_inline_decode(xdr, 8);
5499 type = be32_to_cpup(p++);
5500 if (type != pdev->layout_type) {
5501 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5502 __func__, pdev->layout_type, type);
5506 * Get the length of the opaque device_addr4. xdr_read_pages places
5507 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5508 * and places the remaining xdr data in xdr_buf->tail
5510 pdev->mincount = be32_to_cpup(p);
5511 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5513 /* Parse notification bitmap, verifying that it is zero. */
5514 p = xdr_inline_decode(xdr, 4);
5517 len = be32_to_cpup(p);
5521 p = xdr_inline_decode(xdr, 4 * len);
5524 for (i = 0; i < len; i++, p++) {
5525 if (be32_to_cpup(p)) {
5526 dprintk("%s: notifications not supported\n",
5534 print_overflow_msg(__func__, xdr);
5538 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5539 struct nfs4_layoutget_res *res)
5544 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5545 struct kvec *iov = rcvbuf->head;
5548 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5551 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5554 res->return_on_close = be32_to_cpup(p++);
5555 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5556 layout_count = be32_to_cpup(p);
5557 if (!layout_count) {
5558 dprintk("%s: server responded with empty layout array\n",
5563 p = xdr_inline_decode(xdr, 28);
5566 p = xdr_decode_hyper(p, &res->range.offset);
5567 p = xdr_decode_hyper(p, &res->range.length);
5568 res->range.iomode = be32_to_cpup(p++);
5569 res->type = be32_to_cpup(p++);
5570 res->layoutp->len = be32_to_cpup(p);
5572 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5574 (unsigned long)res->range.offset,
5575 (unsigned long)res->range.length,
5580 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5581 recvd = req->rq_rcv_buf.len - hdrlen;
5582 if (res->layoutp->len > recvd) {
5583 dprintk("NFS: server cheating in layoutget reply: "
5584 "layout len %u > recvd %u\n",
5585 res->layoutp->len, recvd);
5589 xdr_read_pages(xdr, res->layoutp->len);
5591 if (layout_count > 1) {
5592 /* We only handle a length one array at the moment. Any
5593 * further entries are just ignored. Note that this means
5594 * the client may see a response that is less than the
5595 * minimum it requested.
5597 dprintk("%s: server responded with %d layouts, dropping tail\n",
5598 __func__, layout_count);
5603 print_overflow_msg(__func__, xdr);
5607 static int decode_layoutreturn(struct xdr_stream *xdr,
5608 struct nfs4_layoutreturn_res *res)
5613 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5616 p = xdr_inline_decode(xdr, 4);
5619 res->lrs_present = be32_to_cpup(p);
5620 if (res->lrs_present)
5621 status = decode_stateid(xdr, &res->stateid);
5624 print_overflow_msg(__func__, xdr);
5628 static int decode_layoutcommit(struct xdr_stream *xdr,
5629 struct rpc_rqst *req,
5630 struct nfs4_layoutcommit_res *res)
5636 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5637 res->status = status;
5641 p = xdr_inline_decode(xdr, 4);
5644 sizechanged = be32_to_cpup(p);
5647 /* throw away new size */
5648 p = xdr_inline_decode(xdr, 8);
5654 print_overflow_msg(__func__, xdr);
5658 static int decode_test_stateid(struct xdr_stream *xdr,
5659 struct nfs41_test_stateid_res *res)
5665 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5669 p = xdr_inline_decode(xdr, 4);
5672 num_res = be32_to_cpup(p++);
5676 p = xdr_inline_decode(xdr, 4);
5679 res->status = be32_to_cpup(p++);
5682 print_overflow_msg(__func__, xdr);
5687 static int decode_free_stateid(struct xdr_stream *xdr,
5688 struct nfs41_free_stateid_res *res)
5693 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5697 p = xdr_inline_decode(xdr, 4);
5700 res->status = be32_to_cpup(p++);
5703 print_overflow_msg(__func__, xdr);
5706 #endif /* CONFIG_NFS_V4_1 */
5709 * END OF "GENERIC" DECODE ROUTINES.
5713 * Decode OPEN_DOWNGRADE response
5715 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5716 struct xdr_stream *xdr,
5717 struct nfs_closeres *res)
5719 struct compound_hdr hdr;
5722 status = decode_compound_hdr(xdr, &hdr);
5725 status = decode_sequence(xdr, &res->seq_res, rqstp);
5728 status = decode_putfh(xdr);
5731 status = decode_open_downgrade(xdr, res);
5734 decode_getfattr(xdr, res->fattr, res->server,
5735 !RPC_IS_ASYNC(rqstp->rq_task));
5741 * Decode ACCESS response
5743 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5744 struct nfs4_accessres *res)
5746 struct compound_hdr hdr;
5749 status = decode_compound_hdr(xdr, &hdr);
5752 status = decode_sequence(xdr, &res->seq_res, rqstp);
5755 status = decode_putfh(xdr);
5758 status = decode_access(xdr, res);
5761 decode_getfattr(xdr, res->fattr, res->server,
5762 !RPC_IS_ASYNC(rqstp->rq_task));
5768 * Decode LOOKUP response
5770 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5771 struct nfs4_lookup_res *res)
5773 struct compound_hdr hdr;
5776 status = decode_compound_hdr(xdr, &hdr);
5779 status = decode_sequence(xdr, &res->seq_res, rqstp);
5782 status = decode_putfh(xdr);
5785 status = decode_lookup(xdr);
5788 status = decode_getfh(xdr, res->fh);
5791 status = decode_getfattr(xdr, res->fattr, res->server
5792 ,!RPC_IS_ASYNC(rqstp->rq_task));
5798 * Decode LOOKUP_ROOT response
5800 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5801 struct xdr_stream *xdr,
5802 struct nfs4_lookup_res *res)
5804 struct compound_hdr hdr;
5807 status = decode_compound_hdr(xdr, &hdr);
5810 status = decode_sequence(xdr, &res->seq_res, rqstp);
5813 status = decode_putrootfh(xdr);
5816 status = decode_getfh(xdr, res->fh);
5818 status = decode_getfattr(xdr, res->fattr, res->server,
5819 !RPC_IS_ASYNC(rqstp->rq_task));
5825 * Decode REMOVE response
5827 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5828 struct nfs_removeres *res)
5830 struct compound_hdr hdr;
5833 status = decode_compound_hdr(xdr, &hdr);
5836 status = decode_sequence(xdr, &res->seq_res, rqstp);
5839 status = decode_putfh(xdr);
5842 status = decode_remove(xdr, &res->cinfo);
5845 decode_getfattr(xdr, res->dir_attr, res->server,
5846 !RPC_IS_ASYNC(rqstp->rq_task));
5852 * Decode RENAME response
5854 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5855 struct nfs_renameres *res)
5857 struct compound_hdr hdr;
5860 status = decode_compound_hdr(xdr, &hdr);
5863 status = decode_sequence(xdr, &res->seq_res, rqstp);
5866 status = decode_putfh(xdr);
5869 status = decode_savefh(xdr);
5872 status = decode_putfh(xdr);
5875 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5878 /* Current FH is target directory */
5879 if (decode_getfattr(xdr, res->new_fattr, res->server,
5880 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5882 status = decode_restorefh(xdr);
5885 decode_getfattr(xdr, res->old_fattr, res->server,
5886 !RPC_IS_ASYNC(rqstp->rq_task));
5892 * Decode LINK response
5894 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5895 struct nfs4_link_res *res)
5897 struct compound_hdr hdr;
5900 status = decode_compound_hdr(xdr, &hdr);
5903 status = decode_sequence(xdr, &res->seq_res, rqstp);
5906 status = decode_putfh(xdr);
5909 status = decode_savefh(xdr);
5912 status = decode_putfh(xdr);
5915 status = decode_link(xdr, &res->cinfo);
5919 * Note order: OP_LINK leaves the directory as the current
5922 if (decode_getfattr(xdr, res->dir_attr, res->server,
5923 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5925 status = decode_restorefh(xdr);
5928 decode_getfattr(xdr, res->fattr, res->server,
5929 !RPC_IS_ASYNC(rqstp->rq_task));
5935 * Decode CREATE response
5937 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5938 struct nfs4_create_res *res)
5940 struct compound_hdr hdr;
5943 status = decode_compound_hdr(xdr, &hdr);
5946 status = decode_sequence(xdr, &res->seq_res, rqstp);
5949 status = decode_putfh(xdr);
5952 status = decode_savefh(xdr);
5955 status = decode_create(xdr, &res->dir_cinfo);
5958 status = decode_getfh(xdr, res->fh);
5961 if (decode_getfattr(xdr, res->fattr, res->server,
5962 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
5964 status = decode_restorefh(xdr);
5967 decode_getfattr(xdr, res->dir_fattr, res->server,
5968 !RPC_IS_ASYNC(rqstp->rq_task));
5974 * Decode SYMLINK response
5976 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5977 struct nfs4_create_res *res)
5979 return nfs4_xdr_dec_create(rqstp, xdr, res);
5983 * Decode GETATTR response
5985 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5986 struct nfs4_getattr_res *res)
5988 struct compound_hdr hdr;
5991 status = decode_compound_hdr(xdr, &hdr);
5994 status = decode_sequence(xdr, &res->seq_res, rqstp);
5997 status = decode_putfh(xdr);
6000 status = decode_getfattr(xdr, res->fattr, res->server,
6001 !RPC_IS_ASYNC(rqstp->rq_task));
6007 * Encode an SETACL request
6009 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6010 struct nfs_setaclargs *args)
6012 struct compound_hdr hdr = {
6013 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
6016 encode_compound_hdr(xdr, req, &hdr);
6017 encode_sequence(xdr, &args->seq_args, &hdr);
6018 encode_putfh(xdr, args->fh, &hdr);
6019 encode_setacl(xdr, args, &hdr);
6024 * Decode SETACL response
6027 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6028 struct nfs_setaclres *res)
6030 struct compound_hdr hdr;
6033 status = decode_compound_hdr(xdr, &hdr);
6036 status = decode_sequence(xdr, &res->seq_res, rqstp);
6039 status = decode_putfh(xdr);
6042 status = decode_setattr(xdr);
6048 * Decode GETACL response
6051 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6052 struct nfs_getaclres *res)
6054 struct compound_hdr hdr;
6057 if (res->acl_scratch != NULL) {
6058 void *p = page_address(res->acl_scratch);
6059 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6061 status = decode_compound_hdr(xdr, &hdr);
6064 status = decode_sequence(xdr, &res->seq_res, rqstp);
6067 status = decode_putfh(xdr);
6070 status = decode_getacl(xdr, rqstp, res);
6077 * Decode CLOSE response
6079 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6080 struct nfs_closeres *res)
6082 struct compound_hdr hdr;
6085 status = decode_compound_hdr(xdr, &hdr);
6088 status = decode_sequence(xdr, &res->seq_res, rqstp);
6091 status = decode_putfh(xdr);
6094 status = decode_close(xdr, res);
6098 * Note: Server may do delete on close for this file
6099 * in which case the getattr call will fail with
6100 * an ESTALE error. Shouldn't be a problem,
6101 * though, since fattr->valid will remain unset.
6103 decode_getfattr(xdr, res->fattr, res->server,
6104 !RPC_IS_ASYNC(rqstp->rq_task));
6110 * Decode OPEN response
6112 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6113 struct nfs_openres *res)
6115 struct compound_hdr hdr;
6118 status = decode_compound_hdr(xdr, &hdr);
6121 status = decode_sequence(xdr, &res->seq_res, rqstp);
6124 status = decode_putfh(xdr);
6127 status = decode_savefh(xdr);
6130 status = decode_open(xdr, res);
6133 status = decode_getfh(xdr, &res->fh);
6136 if (decode_getfattr(xdr, res->f_attr, res->server,
6137 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
6139 if (decode_restorefh(xdr) != 0)
6141 decode_getfattr(xdr, res->dir_attr, res->server,
6142 !RPC_IS_ASYNC(rqstp->rq_task));
6148 * Decode OPEN_CONFIRM response
6150 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6151 struct xdr_stream *xdr,
6152 struct nfs_open_confirmres *res)
6154 struct compound_hdr hdr;
6157 status = decode_compound_hdr(xdr, &hdr);
6160 status = decode_putfh(xdr);
6163 status = decode_open_confirm(xdr, res);
6169 * Decode OPEN response
6171 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6172 struct xdr_stream *xdr,
6173 struct nfs_openres *res)
6175 struct compound_hdr hdr;
6178 status = decode_compound_hdr(xdr, &hdr);
6181 status = decode_sequence(xdr, &res->seq_res, rqstp);
6184 status = decode_putfh(xdr);
6187 status = decode_open(xdr, res);
6190 decode_getfattr(xdr, res->f_attr, res->server,
6191 !RPC_IS_ASYNC(rqstp->rq_task));
6197 * Decode SETATTR response
6199 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6200 struct xdr_stream *xdr,
6201 struct nfs_setattrres *res)
6203 struct compound_hdr hdr;
6206 status = decode_compound_hdr(xdr, &hdr);
6209 status = decode_sequence(xdr, &res->seq_res, rqstp);
6212 status = decode_putfh(xdr);
6215 status = decode_setattr(xdr);
6218 decode_getfattr(xdr, res->fattr, res->server,
6219 !RPC_IS_ASYNC(rqstp->rq_task));
6225 * Decode LOCK response
6227 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6228 struct nfs_lock_res *res)
6230 struct compound_hdr hdr;
6233 status = decode_compound_hdr(xdr, &hdr);
6236 status = decode_sequence(xdr, &res->seq_res, rqstp);
6239 status = decode_putfh(xdr);
6242 status = decode_lock(xdr, res);
6248 * Decode LOCKT response
6250 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6251 struct nfs_lockt_res *res)
6253 struct compound_hdr hdr;
6256 status = decode_compound_hdr(xdr, &hdr);
6259 status = decode_sequence(xdr, &res->seq_res, rqstp);
6262 status = decode_putfh(xdr);
6265 status = decode_lockt(xdr, res);
6271 * Decode LOCKU response
6273 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6274 struct nfs_locku_res *res)
6276 struct compound_hdr hdr;
6279 status = decode_compound_hdr(xdr, &hdr);
6282 status = decode_sequence(xdr, &res->seq_res, rqstp);
6285 status = decode_putfh(xdr);
6288 status = decode_locku(xdr, res);
6293 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6294 struct xdr_stream *xdr, void *dummy)
6296 struct compound_hdr hdr;
6299 status = decode_compound_hdr(xdr, &hdr);
6301 status = decode_release_lockowner(xdr);
6306 * Decode READLINK response
6308 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6309 struct xdr_stream *xdr,
6310 struct nfs4_readlink_res *res)
6312 struct compound_hdr hdr;
6315 status = decode_compound_hdr(xdr, &hdr);
6318 status = decode_sequence(xdr, &res->seq_res, rqstp);
6321 status = decode_putfh(xdr);
6324 status = decode_readlink(xdr, rqstp);
6330 * Decode READDIR response
6332 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6333 struct nfs4_readdir_res *res)
6335 struct compound_hdr hdr;
6338 status = decode_compound_hdr(xdr, &hdr);
6341 status = decode_sequence(xdr, &res->seq_res, rqstp);
6344 status = decode_putfh(xdr);
6347 status = decode_readdir(xdr, rqstp, res);
6353 * Decode Read response
6355 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6356 struct nfs_readres *res)
6358 struct compound_hdr hdr;
6361 status = decode_compound_hdr(xdr, &hdr);
6364 status = decode_sequence(xdr, &res->seq_res, rqstp);
6367 status = decode_putfh(xdr);
6370 status = decode_read(xdr, rqstp, res);
6372 status = res->count;
6378 * Decode WRITE response
6380 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6381 struct nfs_writeres *res)
6383 struct compound_hdr hdr;
6386 status = decode_compound_hdr(xdr, &hdr);
6389 status = decode_sequence(xdr, &res->seq_res, rqstp);
6392 status = decode_putfh(xdr);
6395 status = decode_write(xdr, res);
6399 decode_getfattr(xdr, res->fattr, res->server,
6400 !RPC_IS_ASYNC(rqstp->rq_task));
6402 status = res->count;
6408 * Decode COMMIT response
6410 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6411 struct nfs_writeres *res)
6413 struct compound_hdr hdr;
6416 status = decode_compound_hdr(xdr, &hdr);
6419 status = decode_sequence(xdr, &res->seq_res, rqstp);
6422 status = decode_putfh(xdr);
6425 status = decode_commit(xdr, res);
6429 decode_getfattr(xdr, res->fattr, res->server,
6430 !RPC_IS_ASYNC(rqstp->rq_task));
6436 * Decode FSINFO response
6438 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6439 struct nfs4_fsinfo_res *res)
6441 struct compound_hdr hdr;
6444 status = decode_compound_hdr(xdr, &hdr);
6446 status = decode_sequence(xdr, &res->seq_res, req);
6448 status = decode_putfh(xdr);
6450 status = decode_fsinfo(xdr, res->fsinfo);
6455 * Decode PATHCONF response
6457 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6458 struct nfs4_pathconf_res *res)
6460 struct compound_hdr hdr;
6463 status = decode_compound_hdr(xdr, &hdr);
6465 status = decode_sequence(xdr, &res->seq_res, req);
6467 status = decode_putfh(xdr);
6469 status = decode_pathconf(xdr, res->pathconf);
6474 * Decode STATFS response
6476 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6477 struct nfs4_statfs_res *res)
6479 struct compound_hdr hdr;
6482 status = decode_compound_hdr(xdr, &hdr);
6484 status = decode_sequence(xdr, &res->seq_res, req);
6486 status = decode_putfh(xdr);
6488 status = decode_statfs(xdr, res->fsstat);
6493 * Decode GETATTR_BITMAP response
6495 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6496 struct xdr_stream *xdr,
6497 struct nfs4_server_caps_res *res)
6499 struct compound_hdr hdr;
6502 status = decode_compound_hdr(xdr, &hdr);
6505 status = decode_sequence(xdr, &res->seq_res, req);
6508 status = decode_putfh(xdr);
6511 status = decode_server_caps(xdr, res);
6517 * Decode RENEW response
6519 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6522 struct compound_hdr hdr;
6525 status = decode_compound_hdr(xdr, &hdr);
6527 status = decode_renew(xdr);
6532 * Decode SETCLIENTID response
6534 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6535 struct xdr_stream *xdr,
6536 struct nfs4_setclientid_res *res)
6538 struct compound_hdr hdr;
6541 status = decode_compound_hdr(xdr, &hdr);
6543 status = decode_setclientid(xdr, res);
6548 * Decode SETCLIENTID_CONFIRM response
6550 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6551 struct xdr_stream *xdr,
6552 struct nfs_fsinfo *fsinfo)
6554 struct compound_hdr hdr;
6557 status = decode_compound_hdr(xdr, &hdr);
6559 status = decode_setclientid_confirm(xdr);
6561 status = decode_putrootfh(xdr);
6563 status = decode_fsinfo(xdr, fsinfo);
6568 * Decode DELEGRETURN response
6570 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6571 struct xdr_stream *xdr,
6572 struct nfs4_delegreturnres *res)
6574 struct compound_hdr hdr;
6577 status = decode_compound_hdr(xdr, &hdr);
6580 status = decode_sequence(xdr, &res->seq_res, rqstp);
6583 status = decode_putfh(xdr);
6586 status = decode_delegreturn(xdr);
6589 decode_getfattr(xdr, res->fattr, res->server,
6590 !RPC_IS_ASYNC(rqstp->rq_task));
6596 * Decode FS_LOCATIONS response
6598 static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6599 struct xdr_stream *xdr,
6600 struct nfs4_fs_locations_res *res)
6602 struct compound_hdr hdr;
6605 status = decode_compound_hdr(xdr, &hdr);
6608 status = decode_sequence(xdr, &res->seq_res, req);
6611 status = decode_putfh(xdr);
6614 status = decode_lookup(xdr);
6617 xdr_enter_page(xdr, PAGE_SIZE);
6618 status = decode_getfattr(xdr, &res->fs_locations->fattr,
6619 res->fs_locations->server,
6620 !RPC_IS_ASYNC(req->rq_task));
6626 * Decode SECINFO response
6628 static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6629 struct xdr_stream *xdr,
6630 struct nfs4_secinfo_res *res)
6632 struct compound_hdr hdr;
6635 status = decode_compound_hdr(xdr, &hdr);
6638 status = decode_sequence(xdr, &res->seq_res, rqstp);
6641 status = decode_putfh(xdr);
6644 status = decode_secinfo(xdr, res);
6649 #if defined(CONFIG_NFS_V4_1)
6651 * Decode EXCHANGE_ID response
6653 static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6654 struct xdr_stream *xdr,
6657 struct compound_hdr hdr;
6660 status = decode_compound_hdr(xdr, &hdr);
6662 status = decode_exchange_id(xdr, res);
6667 * Decode CREATE_SESSION response
6669 static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6670 struct xdr_stream *xdr,
6671 struct nfs41_create_session_res *res)
6673 struct compound_hdr hdr;
6676 status = decode_compound_hdr(xdr, &hdr);
6678 status = decode_create_session(xdr, res);
6683 * Decode DESTROY_SESSION response
6685 static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6686 struct xdr_stream *xdr,
6689 struct compound_hdr hdr;
6692 status = decode_compound_hdr(xdr, &hdr);
6694 status = decode_destroy_session(xdr, res);
6699 * Decode SEQUENCE response
6701 static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6702 struct xdr_stream *xdr,
6703 struct nfs4_sequence_res *res)
6705 struct compound_hdr hdr;
6708 status = decode_compound_hdr(xdr, &hdr);
6710 status = decode_sequence(xdr, res, rqstp);
6715 * Decode GET_LEASE_TIME response
6717 static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6718 struct xdr_stream *xdr,
6719 struct nfs4_get_lease_time_res *res)
6721 struct compound_hdr hdr;
6724 status = decode_compound_hdr(xdr, &hdr);
6726 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
6728 status = decode_putrootfh(xdr);
6730 status = decode_fsinfo(xdr, res->lr_fsinfo);
6735 * Decode RECLAIM_COMPLETE response
6737 static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6738 struct xdr_stream *xdr,
6739 struct nfs41_reclaim_complete_res *res)
6741 struct compound_hdr hdr;
6744 status = decode_compound_hdr(xdr, &hdr);
6746 status = decode_sequence(xdr, &res->seq_res, rqstp);
6748 status = decode_reclaim_complete(xdr, (void *)NULL);
6753 * Decode GETDEVICELIST response
6755 static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6756 struct xdr_stream *xdr,
6757 struct nfs4_getdevicelist_res *res)
6759 struct compound_hdr hdr;
6762 dprintk("encoding getdevicelist!\n");
6764 status = decode_compound_hdr(xdr, &hdr);
6767 status = decode_sequence(xdr, &res->seq_res, rqstp);
6770 status = decode_putfh(xdr);
6773 status = decode_getdevicelist(xdr, res->devlist);
6779 * Decode GETDEVINFO response
6781 static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6782 struct xdr_stream *xdr,
6783 struct nfs4_getdeviceinfo_res *res)
6785 struct compound_hdr hdr;
6788 status = decode_compound_hdr(xdr, &hdr);
6791 status = decode_sequence(xdr, &res->seq_res, rqstp);
6794 status = decode_getdeviceinfo(xdr, res->pdev);
6800 * Decode LAYOUTGET response
6802 static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6803 struct xdr_stream *xdr,
6804 struct nfs4_layoutget_res *res)
6806 struct compound_hdr hdr;
6809 status = decode_compound_hdr(xdr, &hdr);
6812 status = decode_sequence(xdr, &res->seq_res, rqstp);
6815 status = decode_putfh(xdr);
6818 status = decode_layoutget(xdr, rqstp, res);
6824 * Decode LAYOUTRETURN response
6826 static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6827 struct xdr_stream *xdr,
6828 struct nfs4_layoutreturn_res *res)
6830 struct compound_hdr hdr;
6833 status = decode_compound_hdr(xdr, &hdr);
6836 status = decode_sequence(xdr, &res->seq_res, rqstp);
6839 status = decode_putfh(xdr);
6842 status = decode_layoutreturn(xdr, res);
6848 * Decode LAYOUTCOMMIT response
6850 static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6851 struct xdr_stream *xdr,
6852 struct nfs4_layoutcommit_res *res)
6854 struct compound_hdr hdr;
6857 status = decode_compound_hdr(xdr, &hdr);
6860 status = decode_sequence(xdr, &res->seq_res, rqstp);
6863 status = decode_putfh(xdr);
6866 status = decode_layoutcommit(xdr, rqstp, res);
6869 decode_getfattr(xdr, res->fattr, res->server,
6870 !RPC_IS_ASYNC(rqstp->rq_task));
6876 * Decode SECINFO_NO_NAME response
6878 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6879 struct xdr_stream *xdr,
6880 struct nfs4_secinfo_res *res)
6882 struct compound_hdr hdr;
6885 status = decode_compound_hdr(xdr, &hdr);
6888 status = decode_sequence(xdr, &res->seq_res, rqstp);
6891 status = decode_putrootfh(xdr);
6894 status = decode_secinfo(xdr, res);
6900 * Decode TEST_STATEID response
6902 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6903 struct xdr_stream *xdr,
6904 struct nfs41_test_stateid_res *res)
6906 struct compound_hdr hdr;
6909 status = decode_compound_hdr(xdr, &hdr);
6912 status = decode_sequence(xdr, &res->seq_res, rqstp);
6915 status = decode_test_stateid(xdr, res);
6921 * Decode FREE_STATEID response
6923 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6924 struct xdr_stream *xdr,
6925 struct nfs41_free_stateid_res *res)
6927 struct compound_hdr hdr;
6930 status = decode_compound_hdr(xdr, &hdr);
6933 status = decode_sequence(xdr, &res->seq_res, rqstp);
6936 status = decode_free_stateid(xdr, res);
6940 #endif /* CONFIG_NFS_V4_1 */
6943 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6944 * the local page cache.
6945 * @xdr: XDR stream where entry resides
6946 * @entry: buffer to fill in with entry data
6947 * @plus: boolean indicating whether this should be a readdirplus entry
6949 * Returns zero if successful, otherwise a negative errno value is
6952 * This function is not invoked during READDIR reply decoding, but
6953 * rather whenever an application invokes the getdents(2) system call
6954 * on a directory already in our cache.
6956 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6959 uint32_t bitmap[3] = {0};
6961 __be32 *p = xdr_inline_decode(xdr, 4);
6964 if (*p == xdr_zero) {
6965 p = xdr_inline_decode(xdr, 4);
6974 p = xdr_inline_decode(xdr, 12);
6977 entry->prev_cookie = entry->cookie;
6978 p = xdr_decode_hyper(p, &entry->cookie);
6979 entry->len = be32_to_cpup(p);
6981 p = xdr_inline_decode(xdr, entry->len);
6984 entry->name = (const char *) p;
6987 * In case the server doesn't return an inode number,
6988 * we fake one here. (We don't use inode number 0,
6989 * since glibc seems to choke on it...)
6992 entry->fattr->valid = 0;
6994 if (decode_attr_bitmap(xdr, bitmap) < 0)
6997 if (decode_attr_length(xdr, &len, &p) < 0)
7000 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7001 entry->server, 1) < 0)
7003 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7004 entry->ino = entry->fattr->mounted_on_fileid;
7005 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
7006 entry->ino = entry->fattr->fileid;
7008 entry->d_type = DT_UNKNOWN;
7009 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7010 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7015 print_overflow_msg(__func__, xdr);
7020 * We need to translate between nfs status return values and
7021 * the local errno values which may not be the same.
7028 { NFS4ERR_PERM, -EPERM },
7029 { NFS4ERR_NOENT, -ENOENT },
7030 { NFS4ERR_IO, -errno_NFSERR_IO},
7031 { NFS4ERR_NXIO, -ENXIO },
7032 { NFS4ERR_ACCESS, -EACCES },
7033 { NFS4ERR_EXIST, -EEXIST },
7034 { NFS4ERR_XDEV, -EXDEV },
7035 { NFS4ERR_NOTDIR, -ENOTDIR },
7036 { NFS4ERR_ISDIR, -EISDIR },
7037 { NFS4ERR_INVAL, -EINVAL },
7038 { NFS4ERR_FBIG, -EFBIG },
7039 { NFS4ERR_NOSPC, -ENOSPC },
7040 { NFS4ERR_ROFS, -EROFS },
7041 { NFS4ERR_MLINK, -EMLINK },
7042 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7043 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7044 { NFS4ERR_DQUOT, -EDQUOT },
7045 { NFS4ERR_STALE, -ESTALE },
7046 { NFS4ERR_BADHANDLE, -EBADHANDLE },
7047 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7048 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7049 { NFS4ERR_TOOSMALL, -ETOOSMALL },
7050 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
7051 { NFS4ERR_BADTYPE, -EBADTYPE },
7052 { NFS4ERR_LOCKED, -EAGAIN },
7053 { NFS4ERR_SYMLINK, -ELOOP },
7054 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7055 { NFS4ERR_DEADLOCK, -EDEADLK },
7060 * Convert an NFS error code to a local one.
7061 * This one is used jointly by NFSv2 and NFSv3.
7064 nfs4_stat_to_errno(int stat)
7067 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7068 if (nfs_errtbl[i].stat == stat)
7069 return nfs_errtbl[i].errno;
7071 if (stat <= 10000 || stat > 10100) {
7072 /* The server is looney tunes. */
7075 /* If we cannot translate the error, the recovery routines should
7077 * Note: remaining NFSv4 error codes have values > 10000, so should
7078 * not conflict with native Linux error codes.
7083 #define PROC(proc, argtype, restype) \
7084 [NFSPROC4_CLNT_##proc] = { \
7085 .p_proc = NFSPROC4_COMPOUND, \
7086 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
7087 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
7088 .p_arglen = NFS4_##argtype##_sz, \
7089 .p_replen = NFS4_##restype##_sz, \
7090 .p_statidx = NFSPROC4_CLNT_##proc, \
7094 struct rpc_procinfo nfs4_procedures[] = {
7095 PROC(READ, enc_read, dec_read),
7096 PROC(WRITE, enc_write, dec_write),
7097 PROC(COMMIT, enc_commit, dec_commit),
7098 PROC(OPEN, enc_open, dec_open),
7099 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7100 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7101 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7102 PROC(CLOSE, enc_close, dec_close),
7103 PROC(SETATTR, enc_setattr, dec_setattr),
7104 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7105 PROC(RENEW, enc_renew, dec_renew),
7106 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7107 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7108 PROC(LOCK, enc_lock, dec_lock),
7109 PROC(LOCKT, enc_lockt, dec_lockt),
7110 PROC(LOCKU, enc_locku, dec_locku),
7111 PROC(ACCESS, enc_access, dec_access),
7112 PROC(GETATTR, enc_getattr, dec_getattr),
7113 PROC(LOOKUP, enc_lookup, dec_lookup),
7114 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7115 PROC(REMOVE, enc_remove, dec_remove),
7116 PROC(RENAME, enc_rename, dec_rename),
7117 PROC(LINK, enc_link, dec_link),
7118 PROC(SYMLINK, enc_symlink, dec_symlink),
7119 PROC(CREATE, enc_create, dec_create),
7120 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7121 PROC(STATFS, enc_statfs, dec_statfs),
7122 PROC(READLINK, enc_readlink, dec_readlink),
7123 PROC(READDIR, enc_readdir, dec_readdir),
7124 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7125 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7126 PROC(GETACL, enc_getacl, dec_getacl),
7127 PROC(SETACL, enc_setacl, dec_setacl),
7128 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7129 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
7130 PROC(SECINFO, enc_secinfo, dec_secinfo),
7131 #if defined(CONFIG_NFS_V4_1)
7132 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7133 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7134 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7135 PROC(SEQUENCE, enc_sequence, dec_sequence),
7136 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7137 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7138 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7139 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
7140 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7141 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7142 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7143 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7144 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
7145 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
7146 #endif /* CONFIG_NFS_V4_1 */
7149 struct rpc_version nfs_version4 = {
7151 .nrprocs = ARRAY_SIZE(nfs4_procedures),
7152 .procs = nfs4_procedures