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/module.h>
48 #include <linux/utsname.h>
49 #include <linux/sunrpc/clnt.h>
50 #include <linux/sunrpc/msg_prot.h>
51 #include <linux/sunrpc/gss_api.h>
52 #include <linux/nfs.h>
53 #include <linux/nfs4.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/nfs_idmap.h>
62 #define NFSDBG_FACILITY NFSDBG_XDR
64 /* Mapping from NFS error code to "errno" error code. */
65 #define errno_NFSERR_IO EIO
67 static int nfs4_stat_to_errno(int);
69 /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
71 #define NFS4_MAXTAGLEN 20
73 #define NFS4_MAXTAGLEN 0
76 /* lock,open owner id:
77 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
79 #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
80 #define lock_owner_id_maxsz (1 + 1 + 4)
81 #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
82 #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
83 #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84 #define op_encode_hdr_maxsz (1)
85 #define op_decode_hdr_maxsz (2)
86 #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
87 #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88 #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
89 #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
90 #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
92 #define decode_putfh_maxsz (op_decode_hdr_maxsz)
93 #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
94 #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
95 #define encode_getfh_maxsz (op_encode_hdr_maxsz)
96 #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
97 ((3+NFS4_FHSIZE) >> 2))
98 #define nfs4_fattr_bitmap_maxsz 4
99 #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
100 #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
101 #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
102 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
103 #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
104 /* We support only one layout type per file system */
105 #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
106 /* This is based on getfattr, which uses the most attributes: */
107 #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
108 3 + 3 + 3 + nfs4_owner_maxsz + \
109 nfs4_group_maxsz + decode_mdsthreshold_maxsz))
110 #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
111 nfs4_fattr_value_maxsz)
112 #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
113 #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
118 #define encode_savefh_maxsz (op_encode_hdr_maxsz)
119 #define decode_savefh_maxsz (op_decode_hdr_maxsz)
120 #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
121 #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
122 #define encode_fsinfo_maxsz (encode_getattr_maxsz)
123 /* The 5 accounts for the PNFS attributes, and assumes that at most three
124 * layout types will be returned.
126 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
127 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
128 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
129 #define decode_renew_maxsz (op_decode_hdr_maxsz)
130 #define encode_setclientid_maxsz \
131 (op_encode_hdr_maxsz + \
132 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
133 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
135 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
136 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
138 #define decode_setclientid_maxsz \
139 (op_decode_hdr_maxsz + \
141 1024) /* large value for CLID_INUSE */
142 #define encode_setclientid_confirm_maxsz \
143 (op_encode_hdr_maxsz + \
144 3 + (NFS4_VERIFIER_SIZE >> 2))
145 #define decode_setclientid_confirm_maxsz \
146 (op_decode_hdr_maxsz)
147 #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
148 #define decode_lookup_maxsz (op_decode_hdr_maxsz)
149 #define encode_share_access_maxsz \
151 #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
152 #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
153 #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
154 #define encode_open_maxsz (op_encode_hdr_maxsz + \
155 2 + encode_share_access_maxsz + 2 + \
156 open_owner_id_maxsz + \
157 encode_opentype_maxsz + \
158 encode_claim_null_maxsz)
159 #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
160 #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
162 #define decode_change_info_maxsz (5)
163 #define decode_open_maxsz (op_decode_hdr_maxsz + \
164 decode_stateid_maxsz + \
165 decode_change_info_maxsz + 1 + \
166 nfs4_fattr_bitmap_maxsz + \
167 decode_delegation_maxsz)
168 #define encode_open_confirm_maxsz \
169 (op_encode_hdr_maxsz + \
170 encode_stateid_maxsz + 1)
171 #define decode_open_confirm_maxsz \
172 (op_decode_hdr_maxsz + \
173 decode_stateid_maxsz)
174 #define encode_open_downgrade_maxsz \
175 (op_encode_hdr_maxsz + \
176 encode_stateid_maxsz + 1 + \
177 encode_share_access_maxsz)
178 #define decode_open_downgrade_maxsz \
179 (op_decode_hdr_maxsz + \
180 decode_stateid_maxsz)
181 #define encode_close_maxsz (op_encode_hdr_maxsz + \
182 1 + encode_stateid_maxsz)
183 #define decode_close_maxsz (op_decode_hdr_maxsz + \
184 decode_stateid_maxsz)
185 #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + \
188 #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
189 nfs4_fattr_bitmap_maxsz)
190 #define encode_read_maxsz (op_encode_hdr_maxsz + \
191 encode_stateid_maxsz + 3)
192 #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
193 #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
194 2 + encode_verifier_maxsz + 5)
195 #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
196 decode_verifier_maxsz)
197 #define encode_readlink_maxsz (op_encode_hdr_maxsz)
198 #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
199 #define encode_write_maxsz (op_encode_hdr_maxsz + \
200 encode_stateid_maxsz + 4)
201 #define decode_write_maxsz (op_decode_hdr_maxsz + \
202 2 + decode_verifier_maxsz)
203 #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
204 #define decode_commit_maxsz (op_decode_hdr_maxsz + \
205 decode_verifier_maxsz)
206 #define encode_remove_maxsz (op_encode_hdr_maxsz + \
208 #define decode_remove_maxsz (op_decode_hdr_maxsz + \
209 decode_change_info_maxsz)
210 #define encode_rename_maxsz (op_encode_hdr_maxsz + \
212 #define decode_rename_maxsz (op_decode_hdr_maxsz + \
213 decode_change_info_maxsz + \
214 decode_change_info_maxsz)
215 #define encode_link_maxsz (op_encode_hdr_maxsz + \
217 #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
218 #define encode_lockowner_maxsz (7)
219 #define encode_lock_maxsz (op_encode_hdr_maxsz + \
221 1 + encode_stateid_maxsz + 1 + \
222 encode_lockowner_maxsz)
223 #define decode_lock_denied_maxsz \
224 (8 + decode_lockowner_maxsz)
225 #define decode_lock_maxsz (op_decode_hdr_maxsz + \
226 decode_lock_denied_maxsz)
227 #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
228 encode_lockowner_maxsz)
229 #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
230 decode_lock_denied_maxsz)
231 #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
232 encode_stateid_maxsz + \
234 #define decode_locku_maxsz (op_decode_hdr_maxsz + \
235 decode_stateid_maxsz)
236 #define encode_release_lockowner_maxsz \
237 (op_encode_hdr_maxsz + \
238 encode_lockowner_maxsz)
239 #define decode_release_lockowner_maxsz \
240 (op_decode_hdr_maxsz)
241 #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
242 #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
243 #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
244 1 + nfs4_name_maxsz + \
247 #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
248 #define encode_create_maxsz (op_encode_hdr_maxsz + \
249 1 + 2 + nfs4_name_maxsz + \
251 #define decode_create_maxsz (op_decode_hdr_maxsz + \
252 decode_change_info_maxsz + \
253 nfs4_fattr_bitmap_maxsz)
254 #define encode_statfs_maxsz (encode_getattr_maxsz)
255 #define decode_statfs_maxsz (decode_getattr_maxsz)
256 #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
257 #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
258 #define encode_getacl_maxsz (encode_getattr_maxsz)
259 #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
260 nfs4_fattr_bitmap_maxsz + 1)
261 #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
262 encode_stateid_maxsz + 3)
263 #define decode_setacl_maxsz (decode_setattr_maxsz)
264 #define encode_fs_locations_maxsz \
265 (encode_getattr_maxsz)
266 #define decode_fs_locations_maxsz \
268 #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
269 #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
271 #if defined(CONFIG_NFS_V4_1)
272 #define NFS4_MAX_MACHINE_NAME_LEN (64)
274 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
275 encode_verifier_maxsz + \
276 1 /* co_ownerid.len */ + \
277 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
280 0 /* SP4_NONE (for now) */ + \
281 1 /* implementation id array of size 1 */ + \
282 1 /* nii_domain */ + \
283 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
285 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
287 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
288 2 /* eir_clientid */ + \
289 1 /* eir_sequenceid */ + \
290 1 /* eir_flags */ + \
292 0 /* SP4_NONE (for now) */ + \
293 2 /* eir_server_owner.so_minor_id */ + \
294 /* eir_server_owner.so_major_id<> */ \
295 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
296 /* eir_server_scope<> */ \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
298 1 /* eir_server_impl_id array length */ + \
299 1 /* nii_domain */ + \
300 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
302 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
304 #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
305 #define decode_channel_attrs_maxsz (6 + \
306 1 /* ca_rdma_ird.len */ + \
308 #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
309 2 /* csa_clientid */ + \
310 1 /* csa_sequence */ + \
311 1 /* csa_flags */ + \
312 encode_channel_attrs_maxsz + \
313 encode_channel_attrs_maxsz + \
314 1 /* csa_cb_program */ + \
315 1 /* csa_sec_parms.len (1) */ + \
316 1 /* cb_secflavor (AUTH_SYS) */ + \
318 1 /* machinename.len */ + \
319 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
322 1 /* gids.len (0) */)
323 #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
324 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
325 1 /* csr_sequence */ + \
326 1 /* csr_flags */ + \
327 decode_channel_attrs_maxsz + \
328 decode_channel_attrs_maxsz)
329 #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
330 #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
331 #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
332 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
333 #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
334 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
335 #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
336 #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
337 #define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
338 encode_verifier_maxsz)
339 #define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
340 2 /* nfs_cookie4 gdlr_cookie */ + \
341 decode_verifier_maxsz \
342 /* verifier4 gdlr_verifier */ + \
343 1 /* gdlr_deviceid_list count */ + \
344 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
345 NFS4_DEVICEID4_SIZE) \
346 /* gdlr_deviceid_list */ + \
347 1 /* bool gdlr_eof */)
348 #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
349 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
350 #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
351 1 /* layout type */ + \
352 1 /* opaque devaddr4 length */ + \
353 /* devaddr4 payload is read into page */ \
354 1 /* notification bitmap length */ + \
355 1 /* notification bitmap */)
356 #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
357 encode_stateid_maxsz)
358 #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
359 decode_stateid_maxsz + \
360 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
361 #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
365 encode_stateid_maxsz + \
366 1 /* new offset (true) */ + \
367 2 /* last byte written */ + \
368 1 /* nt_timechanged (false) */ + \
369 1 /* layoutupdate4 layout type */ + \
370 1 /* NULL filelayout layoutupdate4 payload */)
371 #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
372 #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
373 encode_stateid_maxsz + \
374 1 /* FIXME: opaque lrf_body always empty at the moment */)
375 #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
376 1 + decode_stateid_maxsz)
377 #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
378 #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
379 #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
380 XDR_QUADLEN(NFS4_STATEID_SIZE))
381 #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
382 #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
383 XDR_QUADLEN(NFS4_STATEID_SIZE))
384 #define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
385 #else /* CONFIG_NFS_V4_1 */
386 #define encode_sequence_maxsz 0
387 #define decode_sequence_maxsz 0
388 #endif /* CONFIG_NFS_V4_1 */
390 #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
391 #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
392 #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
393 encode_sequence_maxsz + \
394 encode_putfh_maxsz + \
396 #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
397 decode_sequence_maxsz + \
398 decode_putfh_maxsz + \
400 #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
401 encode_sequence_maxsz + \
402 encode_putfh_maxsz + \
403 encode_readlink_maxsz)
404 #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
405 decode_sequence_maxsz + \
406 decode_putfh_maxsz + \
407 decode_readlink_maxsz)
408 #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
409 encode_sequence_maxsz + \
410 encode_putfh_maxsz + \
411 encode_readdir_maxsz)
412 #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
413 decode_sequence_maxsz + \
414 decode_putfh_maxsz + \
415 decode_readdir_maxsz)
416 #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
417 encode_sequence_maxsz + \
418 encode_putfh_maxsz + \
419 encode_write_maxsz + \
420 encode_getattr_maxsz)
421 #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
422 decode_sequence_maxsz + \
423 decode_putfh_maxsz + \
424 decode_write_maxsz + \
425 decode_getattr_maxsz)
426 #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
427 encode_sequence_maxsz + \
428 encode_putfh_maxsz + \
430 #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
431 decode_sequence_maxsz + \
432 decode_putfh_maxsz + \
434 #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
435 encode_sequence_maxsz + \
436 encode_putfh_maxsz + \
437 encode_open_maxsz + \
438 encode_getfh_maxsz + \
439 encode_getattr_maxsz)
440 #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
441 decode_sequence_maxsz + \
442 decode_putfh_maxsz + \
443 decode_open_maxsz + \
444 decode_getfh_maxsz + \
445 decode_getattr_maxsz)
446 #define NFS4_enc_open_confirm_sz \
447 (compound_encode_hdr_maxsz + \
448 encode_putfh_maxsz + \
449 encode_open_confirm_maxsz)
450 #define NFS4_dec_open_confirm_sz \
451 (compound_decode_hdr_maxsz + \
452 decode_putfh_maxsz + \
453 decode_open_confirm_maxsz)
454 #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
455 encode_sequence_maxsz + \
456 encode_putfh_maxsz + \
457 encode_open_maxsz + \
458 encode_getattr_maxsz)
459 #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
460 decode_sequence_maxsz + \
461 decode_putfh_maxsz + \
462 decode_open_maxsz + \
463 decode_getattr_maxsz)
464 #define NFS4_enc_open_downgrade_sz \
465 (compound_encode_hdr_maxsz + \
466 encode_sequence_maxsz + \
467 encode_putfh_maxsz + \
468 encode_open_downgrade_maxsz + \
469 encode_getattr_maxsz)
470 #define NFS4_dec_open_downgrade_sz \
471 (compound_decode_hdr_maxsz + \
472 decode_sequence_maxsz + \
473 decode_putfh_maxsz + \
474 decode_open_downgrade_maxsz + \
475 decode_getattr_maxsz)
476 #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
477 encode_sequence_maxsz + \
478 encode_putfh_maxsz + \
479 encode_close_maxsz + \
480 encode_getattr_maxsz)
481 #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
482 decode_sequence_maxsz + \
483 decode_putfh_maxsz + \
484 decode_close_maxsz + \
485 decode_getattr_maxsz)
486 #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
487 encode_sequence_maxsz + \
488 encode_putfh_maxsz + \
489 encode_setattr_maxsz + \
490 encode_getattr_maxsz)
491 #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
492 decode_sequence_maxsz + \
493 decode_putfh_maxsz + \
494 decode_setattr_maxsz + \
495 decode_getattr_maxsz)
496 #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
497 encode_sequence_maxsz + \
498 encode_putfh_maxsz + \
500 #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
501 decode_sequence_maxsz + \
502 decode_putfh_maxsz + \
504 #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
506 #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
508 #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
509 encode_setclientid_maxsz)
510 #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
511 decode_setclientid_maxsz)
512 #define NFS4_enc_setclientid_confirm_sz \
513 (compound_encode_hdr_maxsz + \
514 encode_setclientid_confirm_maxsz + \
515 encode_putrootfh_maxsz + \
517 #define NFS4_dec_setclientid_confirm_sz \
518 (compound_decode_hdr_maxsz + \
519 decode_setclientid_confirm_maxsz + \
520 decode_putrootfh_maxsz + \
522 #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
523 encode_sequence_maxsz + \
524 encode_putfh_maxsz + \
526 #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
527 decode_sequence_maxsz + \
528 decode_putfh_maxsz + \
530 #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
531 encode_sequence_maxsz + \
532 encode_putfh_maxsz + \
534 #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
535 decode_sequence_maxsz + \
536 decode_putfh_maxsz + \
538 #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
539 encode_sequence_maxsz + \
540 encode_putfh_maxsz + \
542 #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
543 decode_sequence_maxsz + \
544 decode_putfh_maxsz + \
546 #define NFS4_enc_release_lockowner_sz \
547 (compound_encode_hdr_maxsz + \
548 encode_lockowner_maxsz)
549 #define NFS4_dec_release_lockowner_sz \
550 (compound_decode_hdr_maxsz + \
551 decode_lockowner_maxsz)
552 #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
553 encode_sequence_maxsz + \
554 encode_putfh_maxsz + \
555 encode_access_maxsz + \
556 encode_getattr_maxsz)
557 #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
558 decode_sequence_maxsz + \
559 decode_putfh_maxsz + \
560 decode_access_maxsz + \
561 decode_getattr_maxsz)
562 #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
563 encode_sequence_maxsz + \
564 encode_putfh_maxsz + \
565 encode_getattr_maxsz)
566 #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
567 decode_sequence_maxsz + \
568 decode_putfh_maxsz + \
569 decode_getattr_maxsz)
570 #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
571 encode_sequence_maxsz + \
572 encode_putfh_maxsz + \
573 encode_lookup_maxsz + \
574 encode_getattr_maxsz + \
576 #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
577 decode_sequence_maxsz + \
578 decode_putfh_maxsz + \
579 decode_lookup_maxsz + \
580 decode_getattr_maxsz + \
582 #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
583 encode_sequence_maxsz + \
584 encode_putrootfh_maxsz + \
585 encode_getattr_maxsz + \
587 #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
588 decode_sequence_maxsz + \
589 decode_putrootfh_maxsz + \
590 decode_getattr_maxsz + \
592 #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
593 encode_sequence_maxsz + \
594 encode_putfh_maxsz + \
596 #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
597 decode_sequence_maxsz + \
598 decode_putfh_maxsz + \
600 #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
601 encode_sequence_maxsz + \
602 encode_putfh_maxsz + \
603 encode_savefh_maxsz + \
604 encode_putfh_maxsz + \
606 #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
607 decode_sequence_maxsz + \
608 decode_putfh_maxsz + \
609 decode_savefh_maxsz + \
610 decode_putfh_maxsz + \
612 #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
613 encode_sequence_maxsz + \
614 encode_putfh_maxsz + \
615 encode_savefh_maxsz + \
616 encode_putfh_maxsz + \
617 encode_link_maxsz + \
618 encode_restorefh_maxsz + \
619 encode_getattr_maxsz)
620 #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
621 decode_sequence_maxsz + \
622 decode_putfh_maxsz + \
623 decode_savefh_maxsz + \
624 decode_putfh_maxsz + \
625 decode_link_maxsz + \
626 decode_restorefh_maxsz + \
627 decode_getattr_maxsz)
628 #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
629 encode_sequence_maxsz + \
630 encode_putfh_maxsz + \
631 encode_symlink_maxsz + \
632 encode_getattr_maxsz + \
634 #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
635 decode_sequence_maxsz + \
636 decode_putfh_maxsz + \
637 decode_symlink_maxsz + \
638 decode_getattr_maxsz + \
640 #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
641 encode_sequence_maxsz + \
642 encode_putfh_maxsz + \
643 encode_create_maxsz + \
644 encode_getfh_maxsz + \
645 encode_getattr_maxsz)
646 #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
647 decode_sequence_maxsz + \
648 decode_putfh_maxsz + \
649 decode_create_maxsz + \
650 decode_getfh_maxsz + \
651 decode_getattr_maxsz)
652 #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
653 encode_sequence_maxsz + \
654 encode_putfh_maxsz + \
655 encode_getattr_maxsz)
656 #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
657 decode_sequence_maxsz + \
658 decode_putfh_maxsz + \
659 decode_getattr_maxsz)
660 #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
661 encode_sequence_maxsz + \
662 encode_putfh_maxsz + \
664 #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
665 decode_sequence_maxsz + \
666 decode_putfh_maxsz + \
668 #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
669 encode_sequence_maxsz + \
670 encode_putfh_maxsz + \
671 encode_getattr_maxsz)
672 #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
673 decode_sequence_maxsz + \
674 decode_putfh_maxsz + \
675 decode_getattr_maxsz)
676 #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
677 encode_sequence_maxsz + \
678 encode_putfh_maxsz + \
679 encode_delegreturn_maxsz + \
680 encode_getattr_maxsz)
681 #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
682 decode_sequence_maxsz + \
683 decode_delegreturn_maxsz + \
684 decode_getattr_maxsz)
685 #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
686 encode_sequence_maxsz + \
687 encode_putfh_maxsz + \
689 #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
690 decode_sequence_maxsz + \
691 decode_putfh_maxsz + \
693 #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
694 encode_sequence_maxsz + \
695 encode_putfh_maxsz + \
697 #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
698 decode_sequence_maxsz + \
699 decode_putfh_maxsz + \
701 #define NFS4_enc_fs_locations_sz \
702 (compound_encode_hdr_maxsz + \
703 encode_sequence_maxsz + \
704 encode_putfh_maxsz + \
705 encode_lookup_maxsz + \
706 encode_fs_locations_maxsz)
707 #define NFS4_dec_fs_locations_sz \
708 (compound_decode_hdr_maxsz + \
709 decode_sequence_maxsz + \
710 decode_putfh_maxsz + \
711 decode_lookup_maxsz + \
712 decode_fs_locations_maxsz)
713 #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
714 encode_sequence_maxsz + \
715 encode_putfh_maxsz + \
716 encode_secinfo_maxsz)
717 #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
718 decode_sequence_maxsz + \
719 decode_putfh_maxsz + \
720 decode_secinfo_maxsz)
721 #if defined(CONFIG_NFS_V4_1)
722 #define NFS4_enc_exchange_id_sz \
723 (compound_encode_hdr_maxsz + \
724 encode_exchange_id_maxsz)
725 #define NFS4_dec_exchange_id_sz \
726 (compound_decode_hdr_maxsz + \
727 decode_exchange_id_maxsz)
728 #define NFS4_enc_create_session_sz \
729 (compound_encode_hdr_maxsz + \
730 encode_create_session_maxsz)
731 #define NFS4_dec_create_session_sz \
732 (compound_decode_hdr_maxsz + \
733 decode_create_session_maxsz)
734 #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
735 encode_destroy_session_maxsz)
736 #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
737 decode_destroy_session_maxsz)
738 #define NFS4_enc_sequence_sz \
739 (compound_decode_hdr_maxsz + \
740 encode_sequence_maxsz)
741 #define NFS4_dec_sequence_sz \
742 (compound_decode_hdr_maxsz + \
743 decode_sequence_maxsz)
744 #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
745 encode_sequence_maxsz + \
746 encode_putrootfh_maxsz + \
748 #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
749 decode_sequence_maxsz + \
750 decode_putrootfh_maxsz + \
752 #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
753 encode_sequence_maxsz + \
754 encode_reclaim_complete_maxsz)
755 #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
756 decode_sequence_maxsz + \
757 decode_reclaim_complete_maxsz)
758 #define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
759 encode_sequence_maxsz + \
760 encode_putfh_maxsz + \
761 encode_getdevicelist_maxsz)
762 #define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
763 decode_sequence_maxsz + \
764 decode_putfh_maxsz + \
765 decode_getdevicelist_maxsz)
766 #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
767 encode_sequence_maxsz +\
768 encode_getdeviceinfo_maxsz)
769 #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
770 decode_sequence_maxsz + \
771 decode_getdeviceinfo_maxsz)
772 #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
773 encode_sequence_maxsz + \
774 encode_putfh_maxsz + \
775 encode_layoutget_maxsz)
776 #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
777 decode_sequence_maxsz + \
778 decode_putfh_maxsz + \
779 decode_layoutget_maxsz)
780 #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
781 encode_sequence_maxsz +\
782 encode_putfh_maxsz + \
783 encode_layoutcommit_maxsz + \
784 encode_getattr_maxsz)
785 #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
786 decode_sequence_maxsz + \
787 decode_putfh_maxsz + \
788 decode_layoutcommit_maxsz + \
789 decode_getattr_maxsz)
790 #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
791 encode_sequence_maxsz + \
792 encode_putfh_maxsz + \
793 encode_layoutreturn_maxsz)
794 #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
795 decode_sequence_maxsz + \
796 decode_putfh_maxsz + \
797 decode_layoutreturn_maxsz)
798 #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
799 encode_sequence_maxsz + \
800 encode_putrootfh_maxsz +\
801 encode_secinfo_no_name_maxsz)
802 #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
803 decode_sequence_maxsz + \
804 decode_putrootfh_maxsz + \
805 decode_secinfo_no_name_maxsz)
806 #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
807 encode_sequence_maxsz + \
808 encode_test_stateid_maxsz)
809 #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
810 decode_sequence_maxsz + \
811 decode_test_stateid_maxsz)
812 #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
813 encode_sequence_maxsz + \
814 encode_free_stateid_maxsz)
815 #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
816 decode_sequence_maxsz + \
817 decode_free_stateid_maxsz)
819 const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
820 compound_encode_hdr_maxsz +
821 encode_sequence_maxsz +
823 encode_getattr_maxsz) *
826 const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
827 compound_decode_hdr_maxsz +
828 decode_sequence_maxsz +
829 decode_putfh_maxsz) *
831 #endif /* CONFIG_NFS_V4_1 */
833 static unsigned short send_implementation_id = 1;
835 module_param(send_implementation_id, ushort, 0644);
836 MODULE_PARM_DESC(send_implementation_id,
837 "Send implementation ID with NFSv4.1 exchange_id");
839 static const umode_t nfs_type2fmt[] = {
846 [NF4SOCK] = S_IFSOCK,
852 struct compound_hdr {
858 uint32_t replen; /* expected reply words */
862 static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
864 __be32 *p = xdr_reserve_space(xdr, nbytes);
869 static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
873 p = xdr_reserve_space(xdr, len);
874 xdr_encode_opaque_fixed(p, buf, len);
877 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
881 p = reserve_space(xdr, 4 + len);
882 xdr_encode_opaque(p, str, len);
885 static void encode_uint32(struct xdr_stream *xdr, u32 n)
889 p = reserve_space(xdr, 4);
893 static void encode_uint64(struct xdr_stream *xdr, u64 n)
897 p = reserve_space(xdr, 8);
898 xdr_encode_hyper(p, n);
901 static void encode_nfs4_seqid(struct xdr_stream *xdr,
902 const struct nfs_seqid *seqid)
904 encode_uint32(xdr, seqid->sequence->counter);
907 static void encode_compound_hdr(struct xdr_stream *xdr,
908 struct rpc_rqst *req,
909 struct compound_hdr *hdr)
912 struct rpc_auth *auth = req->rq_cred->cr_auth;
914 /* initialize running count of expected bytes in reply.
915 * NOTE: the replied tag SHOULD be the same is the one sent,
916 * but this is not required as a MUST for the server to do so. */
917 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
919 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
920 encode_string(xdr, hdr->taglen, hdr->tag);
921 p = reserve_space(xdr, 8);
922 *p++ = cpu_to_be32(hdr->minorversion);
924 *p = cpu_to_be32(hdr->nops);
927 static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
929 struct compound_hdr *hdr)
931 encode_uint32(xdr, op);
933 hdr->replen += replen;
936 static void encode_nops(struct compound_hdr *hdr)
938 BUG_ON(hdr->nops > NFS4_MAX_OPS);
939 *hdr->nops_p = htonl(hdr->nops);
942 static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
944 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
947 static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
949 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
952 static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
954 char owner_name[IDMAP_NAMESZ];
955 char owner_group[IDMAP_NAMESZ];
956 int owner_namelen = 0;
957 int owner_grouplen = 0;
965 * We reserve enough space to write the entire attribute buffer at once.
966 * In the worst-case, this would be
967 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
968 * = 36 bytes, plus any contribution from variable-length fields
969 * such as owner/group.
974 if (iap->ia_valid & ATTR_SIZE)
976 if (iap->ia_valid & ATTR_MODE)
978 if (iap->ia_valid & ATTR_UID) {
979 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
980 if (owner_namelen < 0) {
981 dprintk("nfs: couldn't resolve uid %d to string\n",
984 strcpy(owner_name, "nobody");
985 owner_namelen = sizeof("nobody") - 1;
988 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
990 if (iap->ia_valid & ATTR_GID) {
991 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
992 if (owner_grouplen < 0) {
993 dprintk("nfs: couldn't resolve gid %d to string\n",
995 strcpy(owner_group, "nobody");
996 owner_grouplen = sizeof("nobody") - 1;
999 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1001 if (iap->ia_valid & ATTR_ATIME_SET)
1003 else if (iap->ia_valid & ATTR_ATIME)
1005 if (iap->ia_valid & ATTR_MTIME_SET)
1007 else if (iap->ia_valid & ATTR_MTIME)
1009 p = reserve_space(xdr, len);
1012 * We write the bitmap length now, but leave the bitmap and the attribute
1013 * buffer length to be backfilled at the end of this routine.
1015 *p++ = cpu_to_be32(2);
1019 if (iap->ia_valid & ATTR_SIZE) {
1020 bmval0 |= FATTR4_WORD0_SIZE;
1021 p = xdr_encode_hyper(p, iap->ia_size);
1023 if (iap->ia_valid & ATTR_MODE) {
1024 bmval1 |= FATTR4_WORD1_MODE;
1025 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1027 if (iap->ia_valid & ATTR_UID) {
1028 bmval1 |= FATTR4_WORD1_OWNER;
1029 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1031 if (iap->ia_valid & ATTR_GID) {
1032 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
1033 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1035 if (iap->ia_valid & ATTR_ATIME_SET) {
1036 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1037 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1038 *p++ = cpu_to_be32(0);
1039 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1040 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1042 else if (iap->ia_valid & ATTR_ATIME) {
1043 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
1044 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1046 if (iap->ia_valid & ATTR_MTIME_SET) {
1047 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1048 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1049 *p++ = cpu_to_be32(0);
1050 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1051 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1053 else if (iap->ia_valid & ATTR_MTIME) {
1054 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
1055 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1059 * Now we backfill the bitmap and the attribute buffer length.
1061 if (len != ((char *)p - (char *)q) + 4) {
1062 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
1063 len, ((char *)p - (char *)q) + 4);
1066 len = (char *)p - (char *)q - 12;
1067 *q++ = htonl(bmval0);
1068 *q++ = htonl(bmval1);
1074 static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1076 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1077 encode_uint32(xdr, access);
1080 static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1082 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
1083 encode_nfs4_seqid(xdr, arg->seqid);
1084 encode_nfs4_stateid(xdr, arg->stateid);
1087 static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
1091 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1092 p = reserve_space(xdr, 12);
1093 p = xdr_encode_hyper(p, args->offset);
1094 *p = cpu_to_be32(args->count);
1097 static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1101 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1102 encode_uint32(xdr, create->ftype);
1104 switch (create->ftype) {
1106 p = reserve_space(xdr, 4);
1107 *p = cpu_to_be32(create->u.symlink.len);
1108 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
1111 case NF4BLK: case NF4CHR:
1112 p = reserve_space(xdr, 8);
1113 *p++ = cpu_to_be32(create->u.device.specdata1);
1114 *p = cpu_to_be32(create->u.device.specdata2);
1121 encode_string(xdr, create->name->len, create->name->name);
1122 encode_attrs(xdr, create->attrs, create->server);
1125 static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
1129 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1130 p = reserve_space(xdr, 8);
1131 *p++ = cpu_to_be32(1);
1132 *p = cpu_to_be32(bitmap);
1135 static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1139 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1140 p = reserve_space(xdr, 12);
1141 *p++ = cpu_to_be32(2);
1142 *p++ = cpu_to_be32(bm0);
1143 *p = cpu_to_be32(bm1);
1147 encode_getattr_three(struct xdr_stream *xdr,
1148 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1149 struct compound_hdr *hdr)
1153 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1155 p = reserve_space(xdr, 16);
1156 *p++ = cpu_to_be32(3);
1157 *p++ = cpu_to_be32(bm0);
1158 *p++ = cpu_to_be32(bm1);
1159 *p = cpu_to_be32(bm2);
1161 p = reserve_space(xdr, 12);
1162 *p++ = cpu_to_be32(2);
1163 *p++ = cpu_to_be32(bm0);
1164 *p = cpu_to_be32(bm1);
1166 p = reserve_space(xdr, 8);
1167 *p++ = cpu_to_be32(1);
1168 *p = cpu_to_be32(bm0);
1172 static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1174 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1175 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
1178 static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
1179 struct compound_hdr *hdr)
1181 encode_getattr_three(xdr,
1182 bitmask[0] & nfs4_fattr_bitmap[0],
1183 bitmask[1] & nfs4_fattr_bitmap[1],
1184 bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD,
1188 static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1190 encode_getattr_three(xdr,
1191 bitmask[0] & nfs4_fsinfo_bitmap[0],
1192 bitmask[1] & nfs4_fsinfo_bitmap[1],
1193 bitmask[2] & nfs4_fsinfo_bitmap[2],
1197 static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1199 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1200 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
1203 static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1205 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
1208 static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1210 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
1211 encode_string(xdr, name->len, name->name);
1214 static inline int nfs4_lock_type(struct file_lock *fl, int block)
1216 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1217 return block ? NFS4_READW_LT : NFS4_READ_LT;
1218 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1221 static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1223 if (fl->fl_end == OFFSET_MAX)
1224 return ~(uint64_t)0;
1225 return fl->fl_end - fl->fl_start + 1;
1228 static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1232 p = reserve_space(xdr, 32);
1233 p = xdr_encode_hyper(p, lowner->clientid);
1234 *p++ = cpu_to_be32(20);
1235 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1236 *p++ = cpu_to_be32(lowner->s_dev);
1237 xdr_encode_hyper(p, lowner->id);
1241 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1242 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1244 static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
1248 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1249 p = reserve_space(xdr, 28);
1250 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1251 *p++ = cpu_to_be32(args->reclaim);
1252 p = xdr_encode_hyper(p, args->fl->fl_start);
1253 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1254 *p = cpu_to_be32(args->new_lock_owner);
1255 if (args->new_lock_owner){
1256 encode_nfs4_seqid(xdr, args->open_seqid);
1257 encode_nfs4_stateid(xdr, args->open_stateid);
1258 encode_nfs4_seqid(xdr, args->lock_seqid);
1259 encode_lockowner(xdr, &args->lock_owner);
1262 encode_nfs4_stateid(xdr, args->lock_stateid);
1263 encode_nfs4_seqid(xdr, args->lock_seqid);
1267 static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1271 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1272 p = reserve_space(xdr, 20);
1273 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1274 p = xdr_encode_hyper(p, args->fl->fl_start);
1275 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1276 encode_lockowner(xdr, &args->lock_owner);
1279 static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1283 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1284 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
1285 encode_nfs4_seqid(xdr, args->seqid);
1286 encode_nfs4_stateid(xdr, args->stateid);
1287 p = reserve_space(xdr, 16);
1288 p = xdr_encode_hyper(p, args->fl->fl_start);
1289 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1292 static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1294 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1295 encode_lockowner(xdr, lowner);
1298 static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1300 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
1301 encode_string(xdr, name->len, name->name);
1304 static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
1308 p = reserve_space(xdr, 8);
1309 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
1311 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
1314 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
1316 case FMODE_READ|FMODE_WRITE:
1317 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
1320 *p++ = cpu_to_be32(0);
1322 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
1325 static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1329 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1332 encode_nfs4_seqid(xdr, arg->seqid);
1333 encode_share_access(xdr, arg->fmode);
1334 p = reserve_space(xdr, 36);
1335 p = xdr_encode_hyper(p, arg->clientid);
1336 *p++ = cpu_to_be32(24);
1337 p = xdr_encode_opaque_fixed(p, "open id:", 8);
1338 *p++ = cpu_to_be32(arg->server->s_dev);
1339 *p++ = cpu_to_be32(arg->id.uniquifier);
1340 xdr_encode_hyper(p, arg->id.create_time);
1343 static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1346 struct nfs_client *clp;
1348 p = reserve_space(xdr, 4);
1349 switch(arg->open_flags & O_EXCL) {
1351 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
1352 encode_attrs(xdr, arg->u.attrs, arg->server);
1355 clp = arg->server->nfs_client;
1356 if (clp->cl_mvops->minor_version > 0) {
1357 if (nfs4_has_persistent_session(clp)) {
1358 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1359 encode_attrs(xdr, arg->u.attrs, arg->server);
1363 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1364 encode_nfs4_verifier(xdr, &arg->u.verifier);
1366 encode_attrs(xdr, &dummy, arg->server);
1369 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1370 encode_nfs4_verifier(xdr, &arg->u.verifier);
1375 static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1379 p = reserve_space(xdr, 4);
1380 switch (arg->open_flags & O_CREAT) {
1382 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
1385 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1386 *p = cpu_to_be32(NFS4_OPEN_CREATE);
1387 encode_createmode(xdr, arg);
1391 static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
1395 p = reserve_space(xdr, 4);
1396 switch (delegation_type) {
1398 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
1401 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
1403 case FMODE_WRITE|FMODE_READ:
1404 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
1411 static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1415 p = reserve_space(xdr, 4);
1416 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
1417 encode_string(xdr, name->len, name->name);
1420 static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
1424 p = reserve_space(xdr, 4);
1425 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
1426 encode_delegation_type(xdr, type);
1429 static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1433 p = reserve_space(xdr, 4);
1434 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1435 encode_nfs4_stateid(xdr, stateid);
1436 encode_string(xdr, name->len, name->name);
1439 static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1441 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
1442 encode_openhdr(xdr, arg);
1443 encode_opentype(xdr, arg);
1444 switch (arg->claim) {
1445 case NFS4_OPEN_CLAIM_NULL:
1446 encode_claim_null(xdr, arg->name);
1448 case NFS4_OPEN_CLAIM_PREVIOUS:
1449 encode_claim_previous(xdr, arg->u.delegation_type);
1451 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1452 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1459 static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1461 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1462 encode_nfs4_stateid(xdr, arg->stateid);
1463 encode_nfs4_seqid(xdr, arg->seqid);
1466 static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1468 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1469 encode_nfs4_stateid(xdr, arg->stateid);
1470 encode_nfs4_seqid(xdr, arg->seqid);
1471 encode_share_access(xdr, arg->fmode);
1475 encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1477 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
1478 encode_string(xdr, fh->size, fh->data);
1481 static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1483 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
1486 static void encode_open_stateid(struct xdr_stream *xdr,
1487 const struct nfs_open_context *ctx,
1488 const struct nfs_lock_context *l_ctx,
1492 nfs4_stateid stateid;
1494 if (ctx->state != NULL) {
1495 nfs4_select_rw_stateid(&stateid, ctx->state,
1496 fmode, l_ctx->lockowner, l_ctx->pid);
1499 encode_nfs4_stateid(xdr, &stateid);
1501 encode_nfs4_stateid(xdr, &zero_stateid);
1504 static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1508 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
1509 encode_open_stateid(xdr, args->context, args->lock_context,
1510 FMODE_READ, hdr->minorversion);
1512 p = reserve_space(xdr, 12);
1513 p = xdr_encode_hyper(p, args->offset);
1514 *p = cpu_to_be32(args->count);
1517 static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
1519 uint32_t attrs[2] = {
1520 FATTR4_WORD0_RDATTR_ERROR,
1521 FATTR4_WORD1_MOUNTED_ON_FILEID,
1523 uint32_t dircount = readdir->count >> 1;
1526 if (readdir->plus) {
1527 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1528 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
1529 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1530 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1531 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1532 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1535 /* Use mounted_on_fileid only if the server supports it */
1536 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1537 attrs[0] |= FATTR4_WORD0_FILEID;
1539 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1540 encode_uint64(xdr, readdir->cookie);
1541 encode_nfs4_verifier(xdr, &readdir->verifier);
1542 p = reserve_space(xdr, 20);
1543 *p++ = cpu_to_be32(dircount);
1544 *p++ = cpu_to_be32(readdir->count);
1545 *p++ = cpu_to_be32(2);
1547 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1548 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1549 memcpy(verf, readdir->verifier.data, sizeof(verf));
1550 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1552 (unsigned long long)readdir->cookie,
1554 attrs[0] & readdir->bitmask[0],
1555 attrs[1] & readdir->bitmask[1]);
1558 static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1560 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
1563 static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1565 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
1566 encode_string(xdr, name->len, name->name);
1569 static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1571 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1572 encode_string(xdr, oldname->len, oldname->name);
1573 encode_string(xdr, newname->len, newname->name);
1576 static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1577 struct compound_hdr *hdr)
1579 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1580 encode_uint64(xdr, clid);
1584 encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1586 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
1590 encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
1594 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1595 encode_nfs4_stateid(xdr, &zero_stateid);
1596 p = reserve_space(xdr, 2*4);
1597 *p++ = cpu_to_be32(1);
1598 *p = cpu_to_be32(FATTR4_WORD0_ACL);
1599 BUG_ON(arg->acl_len % 4);
1600 p = reserve_space(xdr, 4);
1601 *p = cpu_to_be32(arg->acl_len);
1602 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1606 encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1608 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
1611 static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1613 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1614 encode_nfs4_stateid(xdr, &arg->stateid);
1615 encode_attrs(xdr, arg->iap, server);
1618 static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
1622 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1623 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
1625 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1626 p = reserve_space(xdr, 4);
1627 *p = cpu_to_be32(setclientid->sc_prog);
1628 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1629 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1630 p = reserve_space(xdr, 4);
1631 *p = cpu_to_be32(setclientid->sc_cb_ident);
1634 static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1636 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1637 decode_setclientid_confirm_maxsz, hdr);
1638 encode_uint64(xdr, arg->clientid);
1639 encode_nfs4_verifier(xdr, &arg->confirm);
1642 static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1646 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
1647 encode_open_stateid(xdr, args->context, args->lock_context,
1648 FMODE_WRITE, hdr->minorversion);
1650 p = reserve_space(xdr, 16);
1651 p = xdr_encode_hyper(p, args->offset);
1652 *p++ = cpu_to_be32(args->stable);
1653 *p = cpu_to_be32(args->count);
1655 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1658 static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1660 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1661 encode_nfs4_stateid(xdr, stateid);
1664 static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1666 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
1667 encode_string(xdr, name->len, name->name);
1670 #if defined(CONFIG_NFS_V4_1)
1671 /* NFSv4.1 operations */
1672 static void encode_exchange_id(struct xdr_stream *xdr,
1673 struct nfs41_exchange_id_args *args,
1674 struct compound_hdr *hdr)
1677 char impl_name[NFS4_OPAQUE_LIMIT];
1680 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1681 encode_nfs4_verifier(xdr, args->verifier);
1683 encode_string(xdr, args->id_len, args->id);
1685 p = reserve_space(xdr, 12);
1686 *p++ = cpu_to_be32(args->flags);
1687 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
1689 if (send_implementation_id &&
1690 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1691 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1692 <= NFS4_OPAQUE_LIMIT + 1)
1693 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1694 utsname()->sysname, utsname()->release,
1695 utsname()->version, utsname()->machine);
1698 *p = cpu_to_be32(1); /* implementation id array length=1 */
1701 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1702 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1703 encode_string(xdr, len, impl_name);
1704 /* just send zeros for nii_date - the date is in nii_name */
1705 p = reserve_space(xdr, 12);
1706 p = xdr_encode_hyper(p, 0);
1707 *p = cpu_to_be32(0);
1709 *p = cpu_to_be32(0); /* implementation id array length=0 */
1712 static void encode_create_session(struct xdr_stream *xdr,
1713 struct nfs41_create_session_args *args,
1714 struct compound_hdr *hdr)
1717 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1719 struct nfs_client *clp = args->client;
1720 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
1721 u32 max_resp_sz_cached;
1724 * Assumes OPEN is the biggest non-idempotent compound.
1725 * 2 is the verifier.
1727 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1728 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
1730 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1733 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1734 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
1735 p = xdr_encode_hyper(p, clp->cl_clientid);
1736 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1737 *p++ = cpu_to_be32(args->flags); /*flags */
1740 *p++ = cpu_to_be32(0); /* header padding size */
1741 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1742 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
1743 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1744 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1745 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1746 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1749 *p++ = cpu_to_be32(0); /* header padding size */
1750 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1751 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1752 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1753 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1754 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1755 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1757 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1758 *p++ = cpu_to_be32(1);
1759 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1761 /* authsys_parms rfc1831 */
1762 *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */
1763 p = xdr_encode_opaque(p, machine_name, len);
1764 *p++ = cpu_to_be32(0); /* UID */
1765 *p++ = cpu_to_be32(0); /* GID */
1766 *p = cpu_to_be32(0); /* No more gids */
1769 static void encode_destroy_session(struct xdr_stream *xdr,
1770 struct nfs4_session *session,
1771 struct compound_hdr *hdr)
1773 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1774 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1777 static void encode_reclaim_complete(struct xdr_stream *xdr,
1778 struct nfs41_reclaim_complete_args *args,
1779 struct compound_hdr *hdr)
1781 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1782 encode_uint32(xdr, args->one_fs);
1784 #endif /* CONFIG_NFS_V4_1 */
1786 static void encode_sequence(struct xdr_stream *xdr,
1787 const struct nfs4_sequence_args *args,
1788 struct compound_hdr *hdr)
1790 #if defined(CONFIG_NFS_V4_1)
1791 struct nfs4_session *session = args->sa_session;
1792 struct nfs4_slot_table *tp;
1793 struct nfs4_slot *slot;
1799 tp = &session->fc_slot_table;
1801 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1802 slot = tp->slots + args->sa_slotid;
1804 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1807 * Sessionid + seqid + slotid + max slotid + cache_this
1809 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1810 "max_slotid=%d cache_this=%d\n",
1812 ((u32 *)session->sess_id.data)[0],
1813 ((u32 *)session->sess_id.data)[1],
1814 ((u32 *)session->sess_id.data)[2],
1815 ((u32 *)session->sess_id.data)[3],
1816 slot->seq_nr, args->sa_slotid,
1817 tp->highest_used_slotid, args->sa_cache_this);
1818 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
1819 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1820 *p++ = cpu_to_be32(slot->seq_nr);
1821 *p++ = cpu_to_be32(args->sa_slotid);
1822 *p++ = cpu_to_be32(tp->highest_used_slotid);
1823 *p = cpu_to_be32(args->sa_cache_this);
1824 #endif /* CONFIG_NFS_V4_1 */
1827 #ifdef CONFIG_NFS_V4_1
1829 encode_getdevicelist(struct xdr_stream *xdr,
1830 const struct nfs4_getdevicelist_args *args,
1831 struct compound_hdr *hdr)
1834 nfs4_verifier dummy = {
1838 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1839 p = reserve_space(xdr, 16);
1840 *p++ = cpu_to_be32(args->layoutclass);
1841 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1842 xdr_encode_hyper(p, 0ULL); /* cookie */
1843 encode_nfs4_verifier(xdr, &dummy);
1847 encode_getdeviceinfo(struct xdr_stream *xdr,
1848 const struct nfs4_getdeviceinfo_args *args,
1849 struct compound_hdr *hdr)
1853 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1854 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
1855 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1856 NFS4_DEVICEID4_SIZE);
1857 *p++ = cpu_to_be32(args->pdev->layout_type);
1858 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1859 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1863 encode_layoutget(struct xdr_stream *xdr,
1864 const struct nfs4_layoutget_args *args,
1865 struct compound_hdr *hdr)
1869 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1870 p = reserve_space(xdr, 36);
1871 *p++ = cpu_to_be32(0); /* Signal layout available */
1872 *p++ = cpu_to_be32(args->type);
1873 *p++ = cpu_to_be32(args->range.iomode);
1874 p = xdr_encode_hyper(p, args->range.offset);
1875 p = xdr_encode_hyper(p, args->range.length);
1876 p = xdr_encode_hyper(p, args->minlength);
1877 encode_nfs4_stateid(xdr, &args->stateid);
1878 encode_uint32(xdr, args->maxcount);
1880 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1884 (unsigned long)args->range.offset,
1885 (unsigned long)args->range.length,
1890 encode_layoutcommit(struct xdr_stream *xdr,
1891 struct inode *inode,
1892 const struct nfs4_layoutcommit_args *args,
1893 struct compound_hdr *hdr)
1897 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1898 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1900 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1901 p = reserve_space(xdr, 20);
1902 /* Only whole file layouts */
1903 p = xdr_encode_hyper(p, 0); /* offset */
1904 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
1905 *p = cpu_to_be32(0); /* reclaim */
1906 encode_nfs4_stateid(xdr, &args->stateid);
1907 p = reserve_space(xdr, 20);
1908 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1909 p = xdr_encode_hyper(p, args->lastbytewritten);
1910 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1911 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1913 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1914 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1915 NFS_I(inode)->layout, xdr, args);
1917 encode_uint32(xdr, 0); /* no layout-type payload */
1923 encode_layoutreturn(struct xdr_stream *xdr,
1924 const struct nfs4_layoutreturn_args *args,
1925 struct compound_hdr *hdr)
1929 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1930 p = reserve_space(xdr, 16);
1931 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1932 *p++ = cpu_to_be32(args->layout_type);
1933 *p++ = cpu_to_be32(IOMODE_ANY);
1934 *p = cpu_to_be32(RETURN_FILE);
1935 p = reserve_space(xdr, 16);
1936 p = xdr_encode_hyper(p, 0);
1937 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1938 spin_lock(&args->inode->i_lock);
1939 encode_nfs4_stateid(xdr, &args->stateid);
1940 spin_unlock(&args->inode->i_lock);
1941 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1942 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1943 NFS_I(args->inode)->layout, xdr, args);
1945 encode_uint32(xdr, 0);
1949 encode_secinfo_no_name(struct xdr_stream *xdr,
1950 const struct nfs41_secinfo_no_name_args *args,
1951 struct compound_hdr *hdr)
1953 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1954 encode_uint32(xdr, args->style);
1958 static void encode_test_stateid(struct xdr_stream *xdr,
1959 struct nfs41_test_stateid_args *args,
1960 struct compound_hdr *hdr)
1962 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
1963 encode_uint32(xdr, 1);
1964 encode_nfs4_stateid(xdr, args->stateid);
1967 static void encode_free_stateid(struct xdr_stream *xdr,
1968 struct nfs41_free_stateid_args *args,
1969 struct compound_hdr *hdr)
1971 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
1972 encode_nfs4_stateid(xdr, args->stateid);
1974 #endif /* CONFIG_NFS_V4_1 */
1977 * END OF "GENERIC" ENCODE ROUTINES.
1980 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1982 #if defined(CONFIG_NFS_V4_1)
1983 if (args->sa_session)
1984 return args->sa_session->clp->cl_mvops->minor_version;
1985 #endif /* CONFIG_NFS_V4_1 */
1990 * Encode an ACCESS request
1992 static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1993 const struct nfs4_accessargs *args)
1995 struct compound_hdr hdr = {
1996 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
1999 encode_compound_hdr(xdr, req, &hdr);
2000 encode_sequence(xdr, &args->seq_args, &hdr);
2001 encode_putfh(xdr, args->fh, &hdr);
2002 encode_access(xdr, args->access, &hdr);
2003 encode_getfattr(xdr, args->bitmask, &hdr);
2008 * Encode LOOKUP request
2010 static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2011 const struct nfs4_lookup_arg *args)
2013 struct compound_hdr hdr = {
2014 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2017 encode_compound_hdr(xdr, req, &hdr);
2018 encode_sequence(xdr, &args->seq_args, &hdr);
2019 encode_putfh(xdr, args->dir_fh, &hdr);
2020 encode_lookup(xdr, args->name, &hdr);
2021 encode_getfh(xdr, &hdr);
2022 encode_getfattr(xdr, args->bitmask, &hdr);
2027 * Encode LOOKUP_ROOT request
2029 static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2030 struct xdr_stream *xdr,
2031 const struct nfs4_lookup_root_arg *args)
2033 struct compound_hdr hdr = {
2034 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2037 encode_compound_hdr(xdr, req, &hdr);
2038 encode_sequence(xdr, &args->seq_args, &hdr);
2039 encode_putrootfh(xdr, &hdr);
2040 encode_getfh(xdr, &hdr);
2041 encode_getfattr(xdr, args->bitmask, &hdr);
2046 * Encode REMOVE request
2048 static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2049 const struct nfs_removeargs *args)
2051 struct compound_hdr hdr = {
2052 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2055 encode_compound_hdr(xdr, req, &hdr);
2056 encode_sequence(xdr, &args->seq_args, &hdr);
2057 encode_putfh(xdr, args->fh, &hdr);
2058 encode_remove(xdr, &args->name, &hdr);
2063 * Encode RENAME request
2065 static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2066 const struct nfs_renameargs *args)
2068 struct compound_hdr hdr = {
2069 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2072 encode_compound_hdr(xdr, req, &hdr);
2073 encode_sequence(xdr, &args->seq_args, &hdr);
2074 encode_putfh(xdr, args->old_dir, &hdr);
2075 encode_savefh(xdr, &hdr);
2076 encode_putfh(xdr, args->new_dir, &hdr);
2077 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2082 * Encode LINK request
2084 static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2085 const struct nfs4_link_arg *args)
2087 struct compound_hdr hdr = {
2088 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2091 encode_compound_hdr(xdr, req, &hdr);
2092 encode_sequence(xdr, &args->seq_args, &hdr);
2093 encode_putfh(xdr, args->fh, &hdr);
2094 encode_savefh(xdr, &hdr);
2095 encode_putfh(xdr, args->dir_fh, &hdr);
2096 encode_link(xdr, args->name, &hdr);
2097 encode_restorefh(xdr, &hdr);
2098 encode_getfattr(xdr, args->bitmask, &hdr);
2103 * Encode CREATE request
2105 static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2106 const struct nfs4_create_arg *args)
2108 struct compound_hdr hdr = {
2109 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2112 encode_compound_hdr(xdr, req, &hdr);
2113 encode_sequence(xdr, &args->seq_args, &hdr);
2114 encode_putfh(xdr, args->dir_fh, &hdr);
2115 encode_create(xdr, args, &hdr);
2116 encode_getfh(xdr, &hdr);
2117 encode_getfattr(xdr, args->bitmask, &hdr);
2122 * Encode SYMLINK request
2124 static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2125 const struct nfs4_create_arg *args)
2127 nfs4_xdr_enc_create(req, xdr, args);
2131 * Encode GETATTR request
2133 static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2134 const struct nfs4_getattr_arg *args)
2136 struct compound_hdr hdr = {
2137 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2140 encode_compound_hdr(xdr, req, &hdr);
2141 encode_sequence(xdr, &args->seq_args, &hdr);
2142 encode_putfh(xdr, args->fh, &hdr);
2143 encode_getfattr(xdr, args->bitmask, &hdr);
2148 * Encode a CLOSE request
2150 static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2151 struct nfs_closeargs *args)
2153 struct compound_hdr hdr = {
2154 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2157 encode_compound_hdr(xdr, req, &hdr);
2158 encode_sequence(xdr, &args->seq_args, &hdr);
2159 encode_putfh(xdr, args->fh, &hdr);
2160 encode_close(xdr, args, &hdr);
2161 encode_getfattr(xdr, args->bitmask, &hdr);
2166 * Encode an OPEN request
2168 static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2169 struct nfs_openargs *args)
2171 struct compound_hdr hdr = {
2172 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2175 encode_compound_hdr(xdr, req, &hdr);
2176 encode_sequence(xdr, &args->seq_args, &hdr);
2177 encode_putfh(xdr, args->fh, &hdr);
2178 encode_open(xdr, args, &hdr);
2179 encode_getfh(xdr, &hdr);
2180 encode_getfattr_open(xdr, args->bitmask, &hdr);
2185 * Encode an OPEN_CONFIRM request
2187 static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2188 struct xdr_stream *xdr,
2189 struct nfs_open_confirmargs *args)
2191 struct compound_hdr hdr = {
2195 encode_compound_hdr(xdr, req, &hdr);
2196 encode_putfh(xdr, args->fh, &hdr);
2197 encode_open_confirm(xdr, args, &hdr);
2202 * Encode an OPEN request with no attributes.
2204 static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2205 struct xdr_stream *xdr,
2206 struct nfs_openargs *args)
2208 struct compound_hdr hdr = {
2209 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2212 encode_compound_hdr(xdr, req, &hdr);
2213 encode_sequence(xdr, &args->seq_args, &hdr);
2214 encode_putfh(xdr, args->fh, &hdr);
2215 encode_open(xdr, args, &hdr);
2216 encode_getfattr(xdr, args->bitmask, &hdr);
2221 * Encode an OPEN_DOWNGRADE request
2223 static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2224 struct xdr_stream *xdr,
2225 struct nfs_closeargs *args)
2227 struct compound_hdr hdr = {
2228 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2231 encode_compound_hdr(xdr, req, &hdr);
2232 encode_sequence(xdr, &args->seq_args, &hdr);
2233 encode_putfh(xdr, args->fh, &hdr);
2234 encode_open_downgrade(xdr, args, &hdr);
2235 encode_getfattr(xdr, args->bitmask, &hdr);
2240 * Encode a LOCK request
2242 static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2243 struct nfs_lock_args *args)
2245 struct compound_hdr hdr = {
2246 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2249 encode_compound_hdr(xdr, req, &hdr);
2250 encode_sequence(xdr, &args->seq_args, &hdr);
2251 encode_putfh(xdr, args->fh, &hdr);
2252 encode_lock(xdr, args, &hdr);
2257 * Encode a LOCKT request
2259 static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2260 struct nfs_lockt_args *args)
2262 struct compound_hdr hdr = {
2263 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2266 encode_compound_hdr(xdr, req, &hdr);
2267 encode_sequence(xdr, &args->seq_args, &hdr);
2268 encode_putfh(xdr, args->fh, &hdr);
2269 encode_lockt(xdr, args, &hdr);
2274 * Encode a LOCKU request
2276 static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2277 struct nfs_locku_args *args)
2279 struct compound_hdr hdr = {
2280 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2283 encode_compound_hdr(xdr, req, &hdr);
2284 encode_sequence(xdr, &args->seq_args, &hdr);
2285 encode_putfh(xdr, args->fh, &hdr);
2286 encode_locku(xdr, args, &hdr);
2290 static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2291 struct xdr_stream *xdr,
2292 struct nfs_release_lockowner_args *args)
2294 struct compound_hdr hdr = {
2298 encode_compound_hdr(xdr, req, &hdr);
2299 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2304 * Encode a READLINK request
2306 static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2307 const struct nfs4_readlink *args)
2309 struct compound_hdr hdr = {
2310 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2313 encode_compound_hdr(xdr, req, &hdr);
2314 encode_sequence(xdr, &args->seq_args, &hdr);
2315 encode_putfh(xdr, args->fh, &hdr);
2316 encode_readlink(xdr, args, req, &hdr);
2318 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2319 args->pgbase, args->pglen);
2324 * Encode a READDIR request
2326 static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2327 const struct nfs4_readdir_arg *args)
2329 struct compound_hdr hdr = {
2330 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2333 encode_compound_hdr(xdr, req, &hdr);
2334 encode_sequence(xdr, &args->seq_args, &hdr);
2335 encode_putfh(xdr, args->fh, &hdr);
2336 encode_readdir(xdr, args, req, &hdr);
2338 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
2339 args->pgbase, args->count);
2340 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
2341 __func__, hdr.replen << 2, args->pages,
2342 args->pgbase, args->count);
2347 * Encode a READ request
2349 static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2350 struct nfs_readargs *args)
2352 struct compound_hdr hdr = {
2353 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2356 encode_compound_hdr(xdr, req, &hdr);
2357 encode_sequence(xdr, &args->seq_args, &hdr);
2358 encode_putfh(xdr, args->fh, &hdr);
2359 encode_read(xdr, args, &hdr);
2361 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2362 args->pages, args->pgbase, args->count);
2363 req->rq_rcv_buf.flags |= XDRBUF_READ;
2368 * Encode an SETATTR request
2370 static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2371 struct nfs_setattrargs *args)
2373 struct compound_hdr hdr = {
2374 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2377 encode_compound_hdr(xdr, req, &hdr);
2378 encode_sequence(xdr, &args->seq_args, &hdr);
2379 encode_putfh(xdr, args->fh, &hdr);
2380 encode_setattr(xdr, args, args->server, &hdr);
2381 encode_getfattr(xdr, args->bitmask, &hdr);
2386 * Encode a GETACL request
2388 static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2389 struct nfs_getaclargs *args)
2391 struct compound_hdr hdr = {
2392 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2396 encode_compound_hdr(xdr, req, &hdr);
2397 encode_sequence(xdr, &args->seq_args, &hdr);
2398 encode_putfh(xdr, args->fh, &hdr);
2399 replen = hdr.replen + op_decode_hdr_maxsz + 1;
2400 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
2402 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2403 args->acl_pages, args->acl_pgbase, args->acl_len);
2409 * Encode a WRITE request
2411 static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2412 struct nfs_writeargs *args)
2414 struct compound_hdr hdr = {
2415 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2418 encode_compound_hdr(xdr, req, &hdr);
2419 encode_sequence(xdr, &args->seq_args, &hdr);
2420 encode_putfh(xdr, args->fh, &hdr);
2421 encode_write(xdr, args, &hdr);
2422 req->rq_snd_buf.flags |= XDRBUF_WRITE;
2424 encode_getfattr(xdr, args->bitmask, &hdr);
2431 static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2432 struct nfs_commitargs *args)
2434 struct compound_hdr hdr = {
2435 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2438 encode_compound_hdr(xdr, req, &hdr);
2439 encode_sequence(xdr, &args->seq_args, &hdr);
2440 encode_putfh(xdr, args->fh, &hdr);
2441 encode_commit(xdr, args, &hdr);
2448 static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2449 struct nfs4_fsinfo_arg *args)
2451 struct compound_hdr hdr = {
2452 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2455 encode_compound_hdr(xdr, req, &hdr);
2456 encode_sequence(xdr, &args->seq_args, &hdr);
2457 encode_putfh(xdr, args->fh, &hdr);
2458 encode_fsinfo(xdr, args->bitmask, &hdr);
2463 * a PATHCONF request
2465 static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2466 const struct nfs4_pathconf_arg *args)
2468 struct compound_hdr hdr = {
2469 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2472 encode_compound_hdr(xdr, req, &hdr);
2473 encode_sequence(xdr, &args->seq_args, &hdr);
2474 encode_putfh(xdr, args->fh, &hdr);
2475 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
2483 static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2484 const struct nfs4_statfs_arg *args)
2486 struct compound_hdr hdr = {
2487 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2490 encode_compound_hdr(xdr, req, &hdr);
2491 encode_sequence(xdr, &args->seq_args, &hdr);
2492 encode_putfh(xdr, args->fh, &hdr);
2493 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
2494 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
2499 * GETATTR_BITMAP request
2501 static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2502 struct xdr_stream *xdr,
2503 struct nfs4_server_caps_arg *args)
2505 struct compound_hdr hdr = {
2506 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2509 encode_compound_hdr(xdr, req, &hdr);
2510 encode_sequence(xdr, &args->seq_args, &hdr);
2511 encode_putfh(xdr, args->fhandle, &hdr);
2512 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2513 FATTR4_WORD0_FH_EXPIRE_TYPE|
2514 FATTR4_WORD0_LINK_SUPPORT|
2515 FATTR4_WORD0_SYMLINK_SUPPORT|
2516 FATTR4_WORD0_ACLSUPPORT, &hdr);
2523 static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2524 struct nfs_client *clp)
2526 struct compound_hdr hdr = {
2530 encode_compound_hdr(xdr, req, &hdr);
2531 encode_renew(xdr, clp->cl_clientid, &hdr);
2536 * a SETCLIENTID request
2538 static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2539 struct xdr_stream *xdr,
2540 struct nfs4_setclientid *sc)
2542 struct compound_hdr hdr = {
2546 encode_compound_hdr(xdr, req, &hdr);
2547 encode_setclientid(xdr, sc, &hdr);
2552 * a SETCLIENTID_CONFIRM request
2554 static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2555 struct xdr_stream *xdr,
2556 struct nfs4_setclientid_res *arg)
2558 struct compound_hdr hdr = {
2561 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2563 encode_compound_hdr(xdr, req, &hdr);
2564 encode_setclientid_confirm(xdr, arg, &hdr);
2565 encode_putrootfh(xdr, &hdr);
2566 encode_fsinfo(xdr, lease_bitmap, &hdr);
2571 * DELEGRETURN request
2573 static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2574 struct xdr_stream *xdr,
2575 const struct nfs4_delegreturnargs *args)
2577 struct compound_hdr hdr = {
2578 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2581 encode_compound_hdr(xdr, req, &hdr);
2582 encode_sequence(xdr, &args->seq_args, &hdr);
2583 encode_putfh(xdr, args->fhandle, &hdr);
2584 encode_getfattr(xdr, args->bitmask, &hdr);
2585 encode_delegreturn(xdr, args->stateid, &hdr);
2590 * Encode FS_LOCATIONS request
2592 static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2593 struct xdr_stream *xdr,
2594 struct nfs4_fs_locations_arg *args)
2596 struct compound_hdr hdr = {
2597 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2601 encode_compound_hdr(xdr, req, &hdr);
2602 encode_sequence(xdr, &args->seq_args, &hdr);
2603 encode_putfh(xdr, args->dir_fh, &hdr);
2604 encode_lookup(xdr, args->name, &hdr);
2605 replen = hdr.replen; /* get the attribute into args->page */
2606 encode_fs_locations(xdr, args->bitmask, &hdr);
2608 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
2614 * Encode SECINFO request
2616 static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2617 struct xdr_stream *xdr,
2618 struct nfs4_secinfo_arg *args)
2620 struct compound_hdr hdr = {
2621 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2624 encode_compound_hdr(xdr, req, &hdr);
2625 encode_sequence(xdr, &args->seq_args, &hdr);
2626 encode_putfh(xdr, args->dir_fh, &hdr);
2627 encode_secinfo(xdr, args->name, &hdr);
2631 #if defined(CONFIG_NFS_V4_1)
2633 * EXCHANGE_ID request
2635 static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2636 struct xdr_stream *xdr,
2637 struct nfs41_exchange_id_args *args)
2639 struct compound_hdr hdr = {
2640 .minorversion = args->client->cl_mvops->minor_version,
2643 encode_compound_hdr(xdr, req, &hdr);
2644 encode_exchange_id(xdr, args, &hdr);
2649 * a CREATE_SESSION request
2651 static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2652 struct xdr_stream *xdr,
2653 struct nfs41_create_session_args *args)
2655 struct compound_hdr hdr = {
2656 .minorversion = args->client->cl_mvops->minor_version,
2659 encode_compound_hdr(xdr, req, &hdr);
2660 encode_create_session(xdr, args, &hdr);
2665 * a DESTROY_SESSION request
2667 static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2668 struct xdr_stream *xdr,
2669 struct nfs4_session *session)
2671 struct compound_hdr hdr = {
2672 .minorversion = session->clp->cl_mvops->minor_version,
2675 encode_compound_hdr(xdr, req, &hdr);
2676 encode_destroy_session(xdr, session, &hdr);
2681 * a SEQUENCE request
2683 static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2684 struct nfs4_sequence_args *args)
2686 struct compound_hdr hdr = {
2687 .minorversion = nfs4_xdr_minorversion(args),
2690 encode_compound_hdr(xdr, req, &hdr);
2691 encode_sequence(xdr, args, &hdr);
2696 * a GET_LEASE_TIME request
2698 static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2699 struct xdr_stream *xdr,
2700 struct nfs4_get_lease_time_args *args)
2702 struct compound_hdr hdr = {
2703 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2705 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
2707 encode_compound_hdr(xdr, req, &hdr);
2708 encode_sequence(xdr, &args->la_seq_args, &hdr);
2709 encode_putrootfh(xdr, &hdr);
2710 encode_fsinfo(xdr, lease_bitmap, &hdr);
2715 * a RECLAIM_COMPLETE request
2717 static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2718 struct xdr_stream *xdr,
2719 struct nfs41_reclaim_complete_args *args)
2721 struct compound_hdr hdr = {
2722 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2725 encode_compound_hdr(xdr, req, &hdr);
2726 encode_sequence(xdr, &args->seq_args, &hdr);
2727 encode_reclaim_complete(xdr, args, &hdr);
2732 * Encode GETDEVICELIST request
2734 static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2735 struct xdr_stream *xdr,
2736 struct nfs4_getdevicelist_args *args)
2738 struct compound_hdr hdr = {
2739 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2742 encode_compound_hdr(xdr, req, &hdr);
2743 encode_sequence(xdr, &args->seq_args, &hdr);
2744 encode_putfh(xdr, args->fh, &hdr);
2745 encode_getdevicelist(xdr, args, &hdr);
2750 * Encode GETDEVICEINFO request
2752 static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2753 struct xdr_stream *xdr,
2754 struct nfs4_getdeviceinfo_args *args)
2756 struct compound_hdr hdr = {
2757 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2760 encode_compound_hdr(xdr, req, &hdr);
2761 encode_sequence(xdr, &args->seq_args, &hdr);
2762 encode_getdeviceinfo(xdr, args, &hdr);
2764 /* set up reply kvec. Subtract notification bitmap max size (2)
2765 * so that notification bitmap is put in xdr_buf tail */
2766 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2767 args->pdev->pages, args->pdev->pgbase,
2774 * Encode LAYOUTGET request
2776 static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2777 struct xdr_stream *xdr,
2778 struct nfs4_layoutget_args *args)
2780 struct compound_hdr hdr = {
2781 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2784 encode_compound_hdr(xdr, req, &hdr);
2785 encode_sequence(xdr, &args->seq_args, &hdr);
2786 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2787 encode_layoutget(xdr, args, &hdr);
2789 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2790 args->layout.pages, 0, args->layout.pglen);
2796 * Encode LAYOUTCOMMIT request
2798 static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2799 struct xdr_stream *xdr,
2800 struct nfs4_layoutcommit_args *args)
2802 struct nfs4_layoutcommit_data *data =
2803 container_of(args, struct nfs4_layoutcommit_data, args);
2804 struct compound_hdr hdr = {
2805 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2808 encode_compound_hdr(xdr, req, &hdr);
2809 encode_sequence(xdr, &args->seq_args, &hdr);
2810 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2811 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
2812 encode_getfattr(xdr, args->bitmask, &hdr);
2817 * Encode LAYOUTRETURN request
2819 static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2820 struct xdr_stream *xdr,
2821 struct nfs4_layoutreturn_args *args)
2823 struct compound_hdr hdr = {
2824 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2827 encode_compound_hdr(xdr, req, &hdr);
2828 encode_sequence(xdr, &args->seq_args, &hdr);
2829 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2830 encode_layoutreturn(xdr, args, &hdr);
2835 * Encode SECINFO_NO_NAME request
2837 static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2838 struct xdr_stream *xdr,
2839 struct nfs41_secinfo_no_name_args *args)
2841 struct compound_hdr hdr = {
2842 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2845 encode_compound_hdr(xdr, req, &hdr);
2846 encode_sequence(xdr, &args->seq_args, &hdr);
2847 encode_putrootfh(xdr, &hdr);
2848 encode_secinfo_no_name(xdr, args, &hdr);
2854 * Encode TEST_STATEID request
2856 static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2857 struct xdr_stream *xdr,
2858 struct nfs41_test_stateid_args *args)
2860 struct compound_hdr hdr = {
2861 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2864 encode_compound_hdr(xdr, req, &hdr);
2865 encode_sequence(xdr, &args->seq_args, &hdr);
2866 encode_test_stateid(xdr, args, &hdr);
2871 * Encode FREE_STATEID request
2873 static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2874 struct xdr_stream *xdr,
2875 struct nfs41_free_stateid_args *args)
2877 struct compound_hdr hdr = {
2878 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2881 encode_compound_hdr(xdr, req, &hdr);
2882 encode_sequence(xdr, &args->seq_args, &hdr);
2883 encode_free_stateid(xdr, args, &hdr);
2886 #endif /* CONFIG_NFS_V4_1 */
2888 static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2890 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2891 "Remaining buffer length is %tu words.\n",
2892 func, xdr->end - xdr->p);
2895 static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
2899 p = xdr_inline_decode(xdr, 4);
2902 *len = be32_to_cpup(p);
2903 p = xdr_inline_decode(xdr, *len);
2906 *string = (char *)p;
2909 print_overflow_msg(__func__, xdr);
2913 static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2917 p = xdr_inline_decode(xdr, 8);
2920 hdr->status = be32_to_cpup(p++);
2921 hdr->taglen = be32_to_cpup(p);
2923 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2926 hdr->tag = (char *)p;
2927 p += XDR_QUADLEN(hdr->taglen);
2928 hdr->nops = be32_to_cpup(p);
2929 if (unlikely(hdr->nops < 1))
2930 return nfs4_stat_to_errno(hdr->status);
2933 print_overflow_msg(__func__, xdr);
2937 static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2943 p = xdr_inline_decode(xdr, 8);
2946 opnum = be32_to_cpup(p++);
2947 if (opnum != expected) {
2948 dprintk("nfs: Server returned operation"
2949 " %d but we issued a request for %d\n",
2953 nfserr = be32_to_cpup(p);
2954 if (nfserr != NFS_OK)
2955 return nfs4_stat_to_errno(nfserr);
2958 print_overflow_msg(__func__, xdr);
2963 static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
2966 unsigned int strlen;
2969 p = xdr_inline_decode(xdr, 12);
2971 return decode_opaque_inline(xdr, &strlen, &str);
2972 print_overflow_msg(__func__, xdr);
2976 static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2981 p = xdr_inline_decode(xdr, 4);
2984 bmlen = be32_to_cpup(p);
2986 bitmap[0] = bitmap[1] = bitmap[2] = 0;
2987 p = xdr_inline_decode(xdr, (bmlen << 2));
2991 bitmap[0] = be32_to_cpup(p++);
2993 bitmap[1] = be32_to_cpup(p++);
2995 bitmap[2] = be32_to_cpup(p);
3000 print_overflow_msg(__func__, xdr);
3004 static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
3008 p = xdr_inline_decode(xdr, 4);
3011 *attrlen = be32_to_cpup(p);
3015 print_overflow_msg(__func__, xdr);
3019 static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3021 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
3023 ret = decode_attr_bitmap(xdr, bitmask);
3024 if (unlikely(ret < 0))
3026 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3028 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3029 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3030 bitmask[0], bitmask[1], bitmask[2]);
3034 static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3040 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3042 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3043 p = xdr_inline_decode(xdr, 4);
3046 *type = be32_to_cpup(p);
3047 if (*type < NF4REG || *type > NF4NAMEDATTR) {
3048 dprintk("%s: bad type %d\n", __func__, *type);
3051 bitmap[0] &= ~FATTR4_WORD0_TYPE;
3052 ret = NFS_ATTR_FATTR_TYPE;
3054 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3057 print_overflow_msg(__func__, xdr);
3061 static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3062 uint32_t *bitmap, uint32_t *type)
3067 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3069 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3070 p = xdr_inline_decode(xdr, 4);
3073 *type = be32_to_cpup(p);
3074 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3076 dprintk("%s: expire type=0x%x\n", __func__, *type);
3079 print_overflow_msg(__func__, xdr);
3083 static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3089 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3091 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3092 p = xdr_inline_decode(xdr, 8);
3095 xdr_decode_hyper(p, change);
3096 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3097 ret = NFS_ATTR_FATTR_CHANGE;
3099 dprintk("%s: change attribute=%Lu\n", __func__,
3100 (unsigned long long)*change);
3103 print_overflow_msg(__func__, xdr);
3107 static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3113 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3115 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3116 p = xdr_inline_decode(xdr, 8);
3119 xdr_decode_hyper(p, size);
3120 bitmap[0] &= ~FATTR4_WORD0_SIZE;
3121 ret = NFS_ATTR_FATTR_SIZE;
3123 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3126 print_overflow_msg(__func__, xdr);
3130 static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3135 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3137 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3138 p = xdr_inline_decode(xdr, 4);
3141 *res = be32_to_cpup(p);
3142 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3144 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
3147 print_overflow_msg(__func__, xdr);
3151 static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3156 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3158 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3159 p = xdr_inline_decode(xdr, 4);
3162 *res = be32_to_cpup(p);
3163 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3165 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
3168 print_overflow_msg(__func__, xdr);
3172 static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
3179 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3181 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3182 p = xdr_inline_decode(xdr, 16);
3185 p = xdr_decode_hyper(p, &fsid->major);
3186 xdr_decode_hyper(p, &fsid->minor);
3187 bitmap[0] &= ~FATTR4_WORD0_FSID;
3188 ret = NFS_ATTR_FATTR_FSID;
3190 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
3191 (unsigned long long)fsid->major,
3192 (unsigned long long)fsid->minor);
3195 print_overflow_msg(__func__, xdr);
3199 static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3204 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3206 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3207 p = xdr_inline_decode(xdr, 4);
3210 *res = be32_to_cpup(p);
3211 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3213 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
3216 print_overflow_msg(__func__, xdr);
3220 static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3224 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3226 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3227 p = xdr_inline_decode(xdr, 4);
3230 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3231 *res = -be32_to_cpup(p);
3235 print_overflow_msg(__func__, xdr);
3239 static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3245 memset(fh, 0, sizeof(*fh));
3247 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3249 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3250 p = xdr_inline_decode(xdr, 4);
3253 len = be32_to_cpup(p);
3254 if (len > NFS4_FHSIZE)
3256 p = xdr_inline_decode(xdr, len);
3260 memcpy(fh->data, p, len);
3263 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3267 print_overflow_msg(__func__, xdr);
3271 static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3275 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3276 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3278 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3279 p = xdr_inline_decode(xdr, 4);
3282 *res = be32_to_cpup(p);
3283 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3285 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
3288 print_overflow_msg(__func__, xdr);
3292 static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3298 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3300 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3301 p = xdr_inline_decode(xdr, 8);
3304 xdr_decode_hyper(p, fileid);
3305 bitmap[0] &= ~FATTR4_WORD0_FILEID;
3306 ret = NFS_ATTR_FATTR_FILEID;
3308 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3311 print_overflow_msg(__func__, xdr);
3315 static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3321 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3323 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3324 p = xdr_inline_decode(xdr, 8);
3327 xdr_decode_hyper(p, fileid);
3328 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
3329 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
3331 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3334 print_overflow_msg(__func__, xdr);
3338 static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3344 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3346 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3347 p = xdr_inline_decode(xdr, 8);
3350 xdr_decode_hyper(p, res);
3351 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3353 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
3356 print_overflow_msg(__func__, xdr);
3360 static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3366 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3368 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3369 p = xdr_inline_decode(xdr, 8);
3372 xdr_decode_hyper(p, res);
3373 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3375 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
3378 print_overflow_msg(__func__, xdr);
3382 static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3388 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3390 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3391 p = xdr_inline_decode(xdr, 8);
3394 xdr_decode_hyper(p, res);
3395 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3397 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
3400 print_overflow_msg(__func__, xdr);
3404 static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3410 p = xdr_inline_decode(xdr, 4);
3413 n = be32_to_cpup(p);
3416 dprintk("pathname4: ");
3417 path->ncomponents = 0;
3418 while (path->ncomponents < n) {
3419 struct nfs4_string *component = &path->components[path->ncomponents];
3420 status = decode_opaque_inline(xdr, &component->len, &component->data);
3421 if (unlikely(status != 0))
3425 (path->ncomponents != n ? "/ " : ""),
3426 component->len, component->data);
3427 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3428 path->ncomponents++;
3430 dprintk("cannot parse %d components in path\n", n);
3437 /* a root pathname is sent as a zero component4 */
3438 path->ncomponents = 1;
3439 path->components[0].len=0;
3440 path->components[0].data=NULL;
3441 dprintk("pathname4: /\n");
3444 dprintk(" status %d", status);
3448 print_overflow_msg(__func__, xdr);
3452 static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3458 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3461 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3464 /* Ignore borken servers that return unrequested attrs */
3465 if (unlikely(res == NULL))
3467 dprintk("%s: fsroot:\n", __func__);
3468 status = decode_pathname(xdr, &res->fs_path);
3469 if (unlikely(status != 0))
3471 p = xdr_inline_decode(xdr, 4);
3474 n = be32_to_cpup(p);
3477 res->nlocations = 0;
3478 while (res->nlocations < n) {
3480 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
3482 p = xdr_inline_decode(xdr, 4);
3485 m = be32_to_cpup(p);
3488 dprintk("%s: servers:\n", __func__);
3489 while (loc->nservers < m) {
3490 struct nfs4_string *server = &loc->servers[loc->nservers];
3491 status = decode_opaque_inline(xdr, &server->len, &server->data);
3492 if (unlikely(status != 0))
3494 dprintk("%s ", server->data);
3495 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3499 dprintk("%s: using first %u of %u servers "
3500 "returned for location %u\n",
3502 NFS4_FS_LOCATION_MAXSERVERS,
3503 m, res->nlocations);
3504 for (i = loc->nservers; i < m; i++) {
3507 status = decode_opaque_inline(xdr, &len, &data);
3508 if (unlikely(status != 0))
3513 status = decode_pathname(xdr, &loc->rootpath);
3514 if (unlikely(status != 0))
3516 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
3519 if (res->nlocations != 0)
3520 status = NFS_ATTR_FATTR_V4_LOCATIONS;
3522 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3525 print_overflow_msg(__func__, xdr);
3531 static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3537 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3539 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3540 p = xdr_inline_decode(xdr, 8);
3543 xdr_decode_hyper(p, res);
3544 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3546 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
3549 print_overflow_msg(__func__, xdr);
3553 static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3559 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3561 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3562 p = xdr_inline_decode(xdr, 4);
3565 *maxlink = be32_to_cpup(p);
3566 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3568 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
3571 print_overflow_msg(__func__, xdr);
3575 static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3581 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3583 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3584 p = xdr_inline_decode(xdr, 4);
3587 *maxname = be32_to_cpup(p);
3588 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3590 dprintk("%s: maxname=%u\n", __func__, *maxname);
3593 print_overflow_msg(__func__, xdr);
3597 static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3603 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3605 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3607 p = xdr_inline_decode(xdr, 8);
3610 xdr_decode_hyper(p, &maxread);
3611 if (maxread > 0x7FFFFFFF)
3612 maxread = 0x7FFFFFFF;
3613 *res = (uint32_t)maxread;
3614 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3616 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
3619 print_overflow_msg(__func__, xdr);
3623 static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3629 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3631 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3633 p = xdr_inline_decode(xdr, 8);
3636 xdr_decode_hyper(p, &maxwrite);
3637 if (maxwrite > 0x7FFFFFFF)
3638 maxwrite = 0x7FFFFFFF;
3639 *res = (uint32_t)maxwrite;
3640 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3642 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
3645 print_overflow_msg(__func__, xdr);
3649 static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
3656 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3658 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3659 p = xdr_inline_decode(xdr, 4);
3662 tmp = be32_to_cpup(p);
3663 *mode = tmp & ~S_IFMT;
3664 bitmap[1] &= ~FATTR4_WORD1_MODE;
3665 ret = NFS_ATTR_FATTR_MODE;
3667 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3670 print_overflow_msg(__func__, xdr);
3674 static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3680 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3682 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3683 p = xdr_inline_decode(xdr, 4);
3686 *nlink = be32_to_cpup(p);
3687 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3688 ret = NFS_ATTR_FATTR_NLINK;
3690 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3693 print_overflow_msg(__func__, xdr);
3697 static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3698 const struct nfs_server *server, uint32_t *uid,
3699 struct nfs4_string *owner_name)
3706 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3708 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
3709 p = xdr_inline_decode(xdr, 4);
3712 len = be32_to_cpup(p);
3713 p = xdr_inline_decode(xdr, len);
3716 if (owner_name != NULL) {
3717 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3718 if (owner_name->data != NULL) {
3719 owner_name->len = len;
3720 ret = NFS_ATTR_FATTR_OWNER_NAME;
3722 } else if (len < XDR_MAX_NETOBJ) {
3723 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
3724 ret = NFS_ATTR_FATTR_OWNER;
3726 dprintk("%s: nfs_map_name_to_uid failed!\n",
3729 dprintk("%s: name too long (%u)!\n",
3731 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3733 dprintk("%s: uid=%d\n", __func__, (int)*uid);
3736 print_overflow_msg(__func__, xdr);
3740 static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3741 const struct nfs_server *server, uint32_t *gid,
3742 struct nfs4_string *group_name)
3749 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3751 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
3752 p = xdr_inline_decode(xdr, 4);
3755 len = be32_to_cpup(p);
3756 p = xdr_inline_decode(xdr, len);
3759 if (group_name != NULL) {
3760 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3761 if (group_name->data != NULL) {
3762 group_name->len = len;
3763 ret = NFS_ATTR_FATTR_GROUP_NAME;
3765 } else if (len < XDR_MAX_NETOBJ) {
3766 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
3767 ret = NFS_ATTR_FATTR_GROUP;
3769 dprintk("%s: nfs_map_group_to_gid failed!\n",
3772 dprintk("%s: name too long (%u)!\n",
3774 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3776 dprintk("%s: gid=%d\n", __func__, (int)*gid);
3779 print_overflow_msg(__func__, xdr);
3783 static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3785 uint32_t major = 0, minor = 0;
3790 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3792 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3795 p = xdr_inline_decode(xdr, 8);
3798 major = be32_to_cpup(p++);
3799 minor = be32_to_cpup(p);
3800 tmp = MKDEV(major, minor);
3801 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3803 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
3804 ret = NFS_ATTR_FATTR_RDEV;
3806 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
3809 print_overflow_msg(__func__, xdr);
3813 static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3819 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3821 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
3822 p = xdr_inline_decode(xdr, 8);
3825 xdr_decode_hyper(p, res);
3826 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3828 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
3831 print_overflow_msg(__func__, xdr);
3835 static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3841 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3843 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
3844 p = xdr_inline_decode(xdr, 8);
3847 xdr_decode_hyper(p, res);
3848 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3850 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
3853 print_overflow_msg(__func__, xdr);
3857 static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3863 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3865 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
3866 p = xdr_inline_decode(xdr, 8);
3869 xdr_decode_hyper(p, res);
3870 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3872 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
3875 print_overflow_msg(__func__, xdr);
3879 static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3885 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3887 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
3888 p = xdr_inline_decode(xdr, 8);
3891 xdr_decode_hyper(p, used);
3892 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
3893 ret = NFS_ATTR_FATTR_SPACE_USED;
3895 dprintk("%s: space used=%Lu\n", __func__,
3896 (unsigned long long)*used);
3899 print_overflow_msg(__func__, xdr);
3903 static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3909 p = xdr_inline_decode(xdr, 12);
3912 p = xdr_decode_hyper(p, &sec);
3913 nsec = be32_to_cpup(p);
3914 time->tv_sec = (time_t)sec;
3915 time->tv_nsec = (long)nsec;
3918 print_overflow_msg(__func__, xdr);
3922 static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3928 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3930 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3931 status = decode_attr_time(xdr, time);
3933 status = NFS_ATTR_FATTR_ATIME;
3934 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3936 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
3940 static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3946 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3948 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3949 status = decode_attr_time(xdr, time);
3951 status = NFS_ATTR_FATTR_CTIME;
3952 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3954 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
3958 static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3959 struct timespec *time)
3965 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3967 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3968 status = decode_attr_time(xdr, time);
3969 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3971 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3972 (long)time->tv_nsec);
3976 static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3982 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3984 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3985 status = decode_attr_time(xdr, time);
3987 status = NFS_ATTR_FATTR_MTIME;
3988 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3990 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
3994 static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
3996 unsigned int attrwords = XDR_QUADLEN(attrlen);
3997 unsigned int nwords = xdr->p - savep;
3999 if (unlikely(attrwords != nwords)) {
4000 dprintk("%s: server returned incorrect attribute length: "
4004 (attrwords < nwords) ? '<' : '>',
4011 static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4015 p = xdr_inline_decode(xdr, 20);
4018 cinfo->atomic = be32_to_cpup(p++);
4019 p = xdr_decode_hyper(p, &cinfo->before);
4020 xdr_decode_hyper(p, &cinfo->after);
4023 print_overflow_msg(__func__, xdr);
4027 static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4033 status = decode_op_hdr(xdr, OP_ACCESS);
4036 p = xdr_inline_decode(xdr, 8);
4039 supp = be32_to_cpup(p++);
4040 acc = be32_to_cpup(p);
4041 access->supported = supp;
4042 access->access = acc;
4045 print_overflow_msg(__func__, xdr);
4049 static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4053 p = xdr_inline_decode(xdr, len);
4055 memcpy(buf, p, len);
4058 print_overflow_msg(__func__, xdr);
4062 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4064 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
4067 static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4071 status = decode_op_hdr(xdr, OP_CLOSE);
4073 nfs_increment_open_seqid(status, res->seqid);
4075 status = decode_stateid(xdr, &res->stateid);
4079 static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4081 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
4084 static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
4088 status = decode_op_hdr(xdr, OP_COMMIT);
4090 status = decode_verifier(xdr, res->verf->verifier);
4094 static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4100 status = decode_op_hdr(xdr, OP_CREATE);
4103 if ((status = decode_change_info(xdr, cinfo)))
4105 p = xdr_inline_decode(xdr, 4);
4108 bmlen = be32_to_cpup(p);
4109 p = xdr_inline_decode(xdr, bmlen << 2);
4113 print_overflow_msg(__func__, xdr);
4117 static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4120 uint32_t attrlen, bitmap[3] = {0};
4123 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4125 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4127 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4129 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4131 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4132 &res->fh_expire_type)) != 0)
4134 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4136 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4138 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4140 status = verify_attr_len(xdr, savep, attrlen);
4142 dprintk("%s: xdr returned %d!\n", __func__, -status);
4146 static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4149 uint32_t attrlen, bitmap[3] = {0};
4152 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4154 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4156 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4159 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4161 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4163 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4165 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4167 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4169 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4172 status = verify_attr_len(xdr, savep, attrlen);
4174 dprintk("%s: xdr returned %d!\n", __func__, -status);
4178 static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4181 uint32_t attrlen, bitmap[3] = {0};
4184 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4186 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4188 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4191 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4193 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4196 status = verify_attr_len(xdr, savep, attrlen);
4198 dprintk("%s: xdr returned %d!\n", __func__, -status);
4202 static int decode_threshold_hint(struct xdr_stream *xdr,
4210 if (likely(bitmap[0] & hint_bit)) {
4211 p = xdr_inline_decode(xdr, 8);
4214 xdr_decode_hyper(p, res);
4218 print_overflow_msg(__func__, xdr);
4222 static int decode_first_threshold_item4(struct xdr_stream *xdr,
4223 struct nfs4_threshold *res)
4226 uint32_t bitmap[3] = {0,}, attrlen;
4230 p = xdr_inline_decode(xdr, 4);
4232 print_overflow_msg(__func__, xdr);
4235 res->l_type = be32_to_cpup(p);
4237 /* thi_hintset bitmap */
4238 status = decode_attr_bitmap(xdr, bitmap);
4242 /* thi_hintlist length */
4243 status = decode_attr_length(xdr, &attrlen, &savep);
4247 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4250 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4253 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4257 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4262 status = verify_attr_len(xdr, savep, attrlen);
4263 res->bm = bitmap[0];
4265 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4266 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4269 dprintk("%s ret=%d!\n", __func__, status);
4274 * Thresholds on pNFS direct I/O vrs MDS I/O
4276 static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4278 struct nfs4_threshold *res)
4284 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4286 if (likely(bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD)) {
4287 p = xdr_inline_decode(xdr, 4);
4290 num = be32_to_cpup(p);
4294 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4295 "drivers per filesystem not supported\n",
4298 status = decode_first_threshold_item4(xdr, res);
4302 print_overflow_msg(__func__, xdr);
4306 static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4307 struct nfs_fattr *fattr, struct nfs_fh *fh,
4308 struct nfs4_fs_locations *fs_loc,
4309 const struct nfs_server *server)
4316 status = decode_attr_type(xdr, bitmap, &type);
4321 fattr->mode |= nfs_type2fmt[type];
4322 fattr->valid |= status;
4325 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4328 fattr->valid |= status;
4330 status = decode_attr_size(xdr, bitmap, &fattr->size);
4333 fattr->valid |= status;
4335 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4338 fattr->valid |= status;
4341 status = decode_attr_error(xdr, bitmap, &err);
4345 status = decode_attr_filehandle(xdr, bitmap, fh);
4349 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4352 fattr->valid |= status;
4354 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4357 fattr->valid |= status;
4359 status = decode_attr_mode(xdr, bitmap, &fmode);
4363 fattr->mode |= fmode;
4364 fattr->valid |= status;
4367 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4370 fattr->valid |= status;
4372 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4375 fattr->valid |= status;
4377 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4380 fattr->valid |= status;
4382 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4385 fattr->valid |= status;
4387 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4390 fattr->valid |= status;
4392 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4395 fattr->valid |= status;
4397 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4400 fattr->valid |= status;
4402 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4405 fattr->valid |= status;
4407 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4410 fattr->valid |= status;
4412 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4417 dprintk("%s: xdr returned %d\n", __func__, -status);
4421 static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4422 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4423 const struct nfs_server *server)
4430 status = decode_op_hdr(xdr, OP_GETATTR);
4434 status = decode_attr_bitmap(xdr, bitmap);
4438 status = decode_attr_length(xdr, &attrlen, &savep);
4442 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
4446 status = verify_attr_len(xdr, savep, attrlen);
4448 dprintk("%s: xdr returned %d\n", __func__, -status);
4452 static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4453 const struct nfs_server *server)
4455 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
4459 * Decode potentially multiple layout types. Currently we only support
4460 * one layout driver per file system.
4462 static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4463 uint32_t *layouttype)
4468 p = xdr_inline_decode(xdr, 4);
4471 num = be32_to_cpup(p);
4473 /* pNFS is not supported by the underlying file system */
4479 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4480 "drivers per filesystem not supported\n", __func__);
4482 /* Decode and set first layout type, move xdr->p past unused types */
4483 p = xdr_inline_decode(xdr, num * 4);
4486 *layouttype = be32_to_cpup(p);
4489 print_overflow_msg(__func__, xdr);
4494 * The type of file system exported.
4495 * Note we must ensure that layouttype is set in any non-error case.
4497 static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4498 uint32_t *layouttype)
4502 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4503 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4505 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4506 status = decode_first_pnfs_layout_type(xdr, layouttype);
4507 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4514 * The prefered block size for layout directed io
4516 static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4521 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4523 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4524 p = xdr_inline_decode(xdr, 4);
4526 print_overflow_msg(__func__, xdr);
4529 *res = be32_to_cpup(p);
4530 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4535 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4538 uint32_t attrlen, bitmap[3];
4541 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4543 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4545 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4548 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4550 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4552 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4554 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4556 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4557 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4559 fsinfo->wtpref = fsinfo->wtmax;
4560 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4563 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4566 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4570 status = verify_attr_len(xdr, savep, attrlen);
4572 dprintk("%s: xdr returned %d!\n", __func__, -status);
4576 static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4582 /* Zero handle first to allow comparisons */
4583 memset(fh, 0, sizeof(*fh));
4585 status = decode_op_hdr(xdr, OP_GETFH);
4589 p = xdr_inline_decode(xdr, 4);
4592 len = be32_to_cpup(p);
4593 if (len > NFS4_FHSIZE)
4596 p = xdr_inline_decode(xdr, len);
4599 memcpy(fh->data, p, len);
4602 print_overflow_msg(__func__, xdr);
4606 static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4610 status = decode_op_hdr(xdr, OP_LINK);
4613 return decode_change_info(xdr, cinfo);
4617 * We create the owner, so we know a proper owner.id length is 4.
4619 static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
4621 uint64_t offset, length, clientid;
4623 uint32_t namelen, type;
4625 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
4628 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
4629 p = xdr_decode_hyper(p, &length);
4630 type = be32_to_cpup(p++); /* 4 byte read */
4631 if (fl != NULL) { /* manipulate file lock */
4632 fl->fl_start = (loff_t)offset;
4633 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4634 if (length == ~(uint64_t)0)
4635 fl->fl_end = OFFSET_MAX;
4636 fl->fl_type = F_WRLCK;
4638 fl->fl_type = F_RDLCK;
4641 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4642 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4643 p = xdr_inline_decode(xdr, namelen); /* variable size field */
4645 return -NFS4ERR_DENIED;
4647 print_overflow_msg(__func__, xdr);
4651 static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
4655 status = decode_op_hdr(xdr, OP_LOCK);
4659 status = decode_stateid(xdr, &res->stateid);
4660 if (unlikely(status))
4662 } else if (status == -NFS4ERR_DENIED)
4663 status = decode_lock_denied(xdr, NULL);
4664 if (res->open_seqid != NULL)
4665 nfs_increment_open_seqid(status, res->open_seqid);
4666 nfs_increment_lock_seqid(status, res->lock_seqid);
4671 static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
4674 status = decode_op_hdr(xdr, OP_LOCKT);
4675 if (status == -NFS4ERR_DENIED)
4676 return decode_lock_denied(xdr, res->denied);
4680 static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
4684 status = decode_op_hdr(xdr, OP_LOCKU);
4686 nfs_increment_lock_seqid(status, res->seqid);
4688 status = decode_stateid(xdr, &res->stateid);
4692 static int decode_release_lockowner(struct xdr_stream *xdr)
4694 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4697 static int decode_lookup(struct xdr_stream *xdr)
4699 return decode_op_hdr(xdr, OP_LOOKUP);
4702 /* This is too sick! */
4703 static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4706 uint32_t limit_type, nblocks, blocksize;
4708 p = xdr_inline_decode(xdr, 12);
4711 limit_type = be32_to_cpup(p++);
4712 switch (limit_type) {
4714 xdr_decode_hyper(p, maxsize);
4717 nblocks = be32_to_cpup(p++);
4718 blocksize = be32_to_cpup(p);
4719 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
4723 print_overflow_msg(__func__, xdr);
4727 static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4730 uint32_t delegation_type;
4733 p = xdr_inline_decode(xdr, 4);
4736 delegation_type = be32_to_cpup(p);
4737 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4738 res->delegation_type = 0;
4741 status = decode_stateid(xdr, &res->delegation);
4742 if (unlikely(status))
4744 p = xdr_inline_decode(xdr, 4);
4747 res->do_recall = be32_to_cpup(p);
4749 switch (delegation_type) {
4750 case NFS4_OPEN_DELEGATE_READ:
4751 res->delegation_type = FMODE_READ;
4753 case NFS4_OPEN_DELEGATE_WRITE:
4754 res->delegation_type = FMODE_WRITE|FMODE_READ;
4755 if (decode_space_limit(xdr, &res->maxsize) < 0)
4758 return decode_ace(xdr, NULL, res->server->nfs_client);
4760 print_overflow_msg(__func__, xdr);
4764 static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4767 uint32_t savewords, bmlen, i;
4770 status = decode_op_hdr(xdr, OP_OPEN);
4772 nfs_increment_open_seqid(status, res->seqid);
4774 status = decode_stateid(xdr, &res->stateid);
4775 if (unlikely(status))
4778 decode_change_info(xdr, &res->cinfo);
4780 p = xdr_inline_decode(xdr, 8);
4783 res->rflags = be32_to_cpup(p++);
4784 bmlen = be32_to_cpup(p);
4788 p = xdr_inline_decode(xdr, bmlen << 2);
4791 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4792 for (i = 0; i < savewords; ++i)
4793 res->attrset[i] = be32_to_cpup(p++);
4794 for (; i < NFS4_BITMAP_SIZE; i++)
4795 res->attrset[i] = 0;
4797 return decode_delegation(xdr, res);
4799 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
4802 print_overflow_msg(__func__, xdr);
4806 static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4810 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
4812 nfs_increment_open_seqid(status, res->seqid);
4814 status = decode_stateid(xdr, &res->stateid);
4818 static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4822 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
4824 nfs_increment_open_seqid(status, res->seqid);
4826 status = decode_stateid(xdr, &res->stateid);
4830 static int decode_putfh(struct xdr_stream *xdr)
4832 return decode_op_hdr(xdr, OP_PUTFH);
4835 static int decode_putrootfh(struct xdr_stream *xdr)
4837 return decode_op_hdr(xdr, OP_PUTROOTFH);
4840 static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4842 struct kvec *iov = req->rq_rcv_buf.head;
4844 uint32_t count, eof, recvd, hdrlen;
4847 status = decode_op_hdr(xdr, OP_READ);
4850 p = xdr_inline_decode(xdr, 8);
4853 eof = be32_to_cpup(p++);
4854 count = be32_to_cpup(p);
4855 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
4856 recvd = req->rq_rcv_buf.len - hdrlen;
4857 if (count > recvd) {
4858 dprintk("NFS: server cheating in read reply: "
4859 "count %u > recvd %u\n", count, recvd);
4863 xdr_read_pages(xdr, count);
4868 print_overflow_msg(__func__, xdr);
4872 static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4874 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4875 struct kvec *iov = rcvbuf->head;
4877 u32 recvd, pglen = rcvbuf->page_len;
4881 status = decode_op_hdr(xdr, OP_READDIR);
4883 status = decode_verifier(xdr, readdir->verifier.data);
4884 if (unlikely(status))
4886 memcpy(verf, readdir->verifier.data, sizeof(verf));
4887 dprintk("%s: verifier = %08x:%08x\n",
4888 __func__, verf[0], verf[1]);
4890 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4891 recvd = rcvbuf->len - hdrlen;
4894 xdr_read_pages(xdr, pglen);
4900 static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4902 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4903 struct kvec *iov = rcvbuf->head;
4909 status = decode_op_hdr(xdr, OP_READLINK);
4913 /* Convert length of symlink */
4914 p = xdr_inline_decode(xdr, 4);
4917 len = be32_to_cpup(p);
4918 if (len >= rcvbuf->page_len || len <= 0) {
4919 dprintk("nfs: server returned giant symlink!\n");
4920 return -ENAMETOOLONG;
4922 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4923 recvd = req->rq_rcv_buf.len - hdrlen;
4925 dprintk("NFS: server cheating in readlink reply: "
4926 "count %u > recvd %u\n", len, recvd);
4929 xdr_read_pages(xdr, len);
4931 * The XDR encode routine has set things up so that
4932 * the link text will be copied directly into the
4933 * buffer. We just have to do overflow-checking,
4934 * and and null-terminate the text (the VFS expects
4935 * null-termination).
4937 xdr_terminate_string(rcvbuf, len);
4940 print_overflow_msg(__func__, xdr);
4944 static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4948 status = decode_op_hdr(xdr, OP_REMOVE);
4951 status = decode_change_info(xdr, cinfo);
4956 static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4957 struct nfs4_change_info *new_cinfo)
4961 status = decode_op_hdr(xdr, OP_RENAME);
4964 if ((status = decode_change_info(xdr, old_cinfo)))
4966 status = decode_change_info(xdr, new_cinfo);
4971 static int decode_renew(struct xdr_stream *xdr)
4973 return decode_op_hdr(xdr, OP_RENEW);
4977 decode_restorefh(struct xdr_stream *xdr)
4979 return decode_op_hdr(xdr, OP_RESTOREFH);
4982 static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4983 struct nfs_getaclres *res)
4985 __be32 *savep, *bm_p;
4988 struct kvec *iov = req->rq_rcv_buf.head;
4990 size_t page_len = xdr->buf->page_len;
4993 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4997 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4998 res->acl_data_offset <<= 2;
4999 /* Check if the acl data starts beyond the allocated buffer */
5000 if (res->acl_data_offset > page_len)
5003 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5005 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5008 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5010 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
5013 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5014 * are stored with the acl data to handle the problem of
5015 * variable length bitmaps.*/
5018 /* We ignore &savep and don't do consistency checks on
5019 * the attr length. Let userspace figure it out.... */
5020 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
5021 attrlen += res->acl_data_offset;
5022 if (attrlen > page_len) {
5023 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
5024 /* getxattr interface called with a NULL buf */
5025 res->acl_len = attrlen;
5028 dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
5032 xdr_read_pages(xdr, attrlen);
5033 res->acl_len = attrlen;
5035 status = -EOPNOTSUPP;
5042 decode_savefh(struct xdr_stream *xdr)
5044 return decode_op_hdr(xdr, OP_SAVEFH);
5047 static int decode_setattr(struct xdr_stream *xdr)
5053 status = decode_op_hdr(xdr, OP_SETATTR);
5056 p = xdr_inline_decode(xdr, 4);
5059 bmlen = be32_to_cpup(p);
5060 p = xdr_inline_decode(xdr, bmlen << 2);
5064 print_overflow_msg(__func__, xdr);
5068 static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
5074 p = xdr_inline_decode(xdr, 8);
5077 opnum = be32_to_cpup(p++);
5078 if (opnum != OP_SETCLIENTID) {
5079 dprintk("nfs: decode_setclientid: Server returned operation"
5083 nfserr = be32_to_cpup(p);
5084 if (nfserr == NFS_OK) {
5085 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5088 p = xdr_decode_hyper(p, &res->clientid);
5089 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
5090 } else if (nfserr == NFSERR_CLID_INUSE) {
5093 /* skip netid string */
5094 p = xdr_inline_decode(xdr, 4);
5097 len = be32_to_cpup(p);
5098 p = xdr_inline_decode(xdr, len);
5102 /* skip uaddr string */
5103 p = xdr_inline_decode(xdr, 4);
5106 len = be32_to_cpup(p);
5107 p = xdr_inline_decode(xdr, len);
5110 return -NFSERR_CLID_INUSE;
5112 return nfs4_stat_to_errno(nfserr);
5116 print_overflow_msg(__func__, xdr);
5120 static int decode_setclientid_confirm(struct xdr_stream *xdr)
5122 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5125 static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5130 status = decode_op_hdr(xdr, OP_WRITE);
5134 p = xdr_inline_decode(xdr, 16);
5137 res->count = be32_to_cpup(p++);
5138 res->verf->committed = be32_to_cpup(p++);
5139 memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE);
5142 print_overflow_msg(__func__, xdr);
5146 static int decode_delegreturn(struct xdr_stream *xdr)
5148 return decode_op_hdr(xdr, OP_DELEGRETURN);
5151 static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5155 p = xdr_inline_decode(xdr, 4);
5158 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5159 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5162 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5165 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5167 p = xdr_inline_decode(xdr, 8);
5170 flavor->gss.qop4 = be32_to_cpup(p++);
5171 flavor->gss.service = be32_to_cpup(p);
5176 print_overflow_msg(__func__, xdr);
5182 static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5184 struct nfs4_secinfo_flavor *sec_flavor;
5189 p = xdr_inline_decode(xdr, 4);
5193 res->flavors->num_flavors = 0;
5194 num_flavors = be32_to_cpup(p);
5196 for (i = 0; i < num_flavors; i++) {
5197 sec_flavor = &res->flavors->flavors[i];
5198 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
5201 p = xdr_inline_decode(xdr, 4);
5204 sec_flavor->flavor = be32_to_cpup(p);
5206 if (sec_flavor->flavor == RPC_AUTH_GSS) {
5207 status = decode_secinfo_gss(xdr, sec_flavor);
5211 res->flavors->num_flavors++;
5218 print_overflow_msg(__func__, xdr);
5222 static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5224 int status = decode_op_hdr(xdr, OP_SECINFO);
5227 return decode_secinfo_common(xdr, res);
5230 #if defined(CONFIG_NFS_V4_1)
5231 static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5233 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5236 return decode_secinfo_common(xdr, res);
5239 static int decode_exchange_id(struct xdr_stream *xdr,
5240 struct nfs41_exchange_id_res *res)
5246 struct nfs_client *clp = res->client;
5247 uint32_t impl_id_count;
5249 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5253 p = xdr_inline_decode(xdr, 8);
5256 xdr_decode_hyper(p, &clp->cl_clientid);
5257 p = xdr_inline_decode(xdr, 12);
5260 clp->cl_seqid = be32_to_cpup(p++);
5261 clp->cl_exchange_flags = be32_to_cpup(p++);
5263 /* We ask for SP4_NONE */
5264 dummy = be32_to_cpup(p);
5265 if (dummy != SP4_NONE)
5268 /* server_owner4.so_minor_id */
5269 p = xdr_inline_decode(xdr, 8);
5272 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
5274 /* server_owner4.so_major_id */
5275 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5276 if (unlikely(status))
5278 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5280 memcpy(res->server_owner->major_id, dummy_str, dummy);
5281 res->server_owner->major_id_sz = dummy;
5284 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5285 if (unlikely(status))
5287 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5289 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5290 res->server_scope->server_scope_sz = dummy;
5292 /* Implementation Id */
5293 p = xdr_inline_decode(xdr, 4);
5296 impl_id_count = be32_to_cpup(p++);
5298 if (impl_id_count) {
5300 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5301 if (unlikely(status))
5303 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5305 memcpy(res->impl_id->domain, dummy_str, dummy);
5308 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5309 if (unlikely(status))
5311 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5313 memcpy(res->impl_id->name, dummy_str, dummy);
5316 p = xdr_inline_decode(xdr, 12);
5319 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5320 res->impl_id->date.nseconds = be32_to_cpup(p);
5322 /* if there's more than one entry, ignore the rest */
5326 print_overflow_msg(__func__, xdr);
5330 static int decode_chan_attrs(struct xdr_stream *xdr,
5331 struct nfs4_channel_attrs *attrs)
5336 p = xdr_inline_decode(xdr, 28);
5339 val = be32_to_cpup(p++); /* headerpadsz */
5341 return -EINVAL; /* no support for header padding yet */
5342 attrs->max_rqst_sz = be32_to_cpup(p++);
5343 attrs->max_resp_sz = be32_to_cpup(p++);
5344 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5345 attrs->max_ops = be32_to_cpup(p++);
5346 attrs->max_reqs = be32_to_cpup(p++);
5347 nr_attrs = be32_to_cpup(p);
5348 if (unlikely(nr_attrs > 1)) {
5349 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5350 "count %u\n", __func__, nr_attrs);
5353 if (nr_attrs == 1) {
5354 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5360 print_overflow_msg(__func__, xdr);
5364 static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5366 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5369 static int decode_create_session(struct xdr_stream *xdr,
5370 struct nfs41_create_session_res *res)
5374 struct nfs_client *clp = res->client;
5375 struct nfs4_session *session = clp->cl_session;
5377 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5379 status = decode_sessionid(xdr, &session->sess_id);
5380 if (unlikely(status))
5384 p = xdr_inline_decode(xdr, 8);
5387 clp->cl_seqid = be32_to_cpup(p++);
5388 session->flags = be32_to_cpup(p);
5390 /* Channel attributes */
5391 status = decode_chan_attrs(xdr, &session->fc_attrs);
5393 status = decode_chan_attrs(xdr, &session->bc_attrs);
5396 print_overflow_msg(__func__, xdr);
5400 static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5402 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5405 static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5407 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5409 #endif /* CONFIG_NFS_V4_1 */
5411 static int decode_sequence(struct xdr_stream *xdr,
5412 struct nfs4_sequence_res *res,
5413 struct rpc_rqst *rqstp)
5415 #if defined(CONFIG_NFS_V4_1)
5416 struct nfs4_sessionid id;
5421 if (!res->sr_session)
5424 status = decode_op_hdr(xdr, OP_SEQUENCE);
5426 status = decode_sessionid(xdr, &id);
5427 if (unlikely(status))
5431 * If the server returns different values for sessionID, slotID or
5432 * sequence number, the server is looney tunes.
5434 status = -EREMOTEIO;
5436 if (memcmp(id.data, res->sr_session->sess_id.data,
5437 NFS4_MAX_SESSIONID_LEN)) {
5438 dprintk("%s Invalid session id\n", __func__);
5442 p = xdr_inline_decode(xdr, 20);
5447 dummy = be32_to_cpup(p++);
5448 if (dummy != res->sr_slot->seq_nr) {
5449 dprintk("%s Invalid sequence number\n", __func__);
5453 dummy = be32_to_cpup(p++);
5454 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
5455 dprintk("%s Invalid slot id\n", __func__);
5458 /* highest slot id - currently not processed */
5459 dummy = be32_to_cpup(p++);
5460 /* target highest slot id - currently not processed */
5461 dummy = be32_to_cpup(p++);
5463 res->sr_status_flags = be32_to_cpup(p);
5466 res->sr_status = status;
5469 print_overflow_msg(__func__, xdr);
5472 #else /* CONFIG_NFS_V4_1 */
5474 #endif /* CONFIG_NFS_V4_1 */
5477 #if defined(CONFIG_NFS_V4_1)
5479 * TODO: Need to handle case when EOF != true;
5481 static int decode_getdevicelist(struct xdr_stream *xdr,
5482 struct pnfs_devicelist *res)
5486 struct nfs_writeverf verftemp;
5488 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5492 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5496 /* TODO: Skip cookie for now */
5500 p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE);
5502 res->num_devs = be32_to_cpup(p);
5504 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5506 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
5507 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
5508 __func__, res->num_devs);
5512 p = xdr_inline_decode(xdr,
5513 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5516 for (i = 0; i < res->num_devs; i++)
5517 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5518 NFS4_DEVICEID4_SIZE);
5519 res->eof = be32_to_cpup(p);
5522 print_overflow_msg(__func__, xdr);
5526 static int decode_getdeviceinfo(struct xdr_stream *xdr,
5527 struct pnfs_device *pdev)
5533 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5535 if (status == -ETOOSMALL) {
5536 p = xdr_inline_decode(xdr, 4);
5539 pdev->mincount = be32_to_cpup(p);
5540 dprintk("%s: Min count too small. mincnt = %u\n",
5541 __func__, pdev->mincount);
5546 p = xdr_inline_decode(xdr, 8);
5549 type = be32_to_cpup(p++);
5550 if (type != pdev->layout_type) {
5551 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5552 __func__, pdev->layout_type, type);
5556 * Get the length of the opaque device_addr4. xdr_read_pages places
5557 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5558 * and places the remaining xdr data in xdr_buf->tail
5560 pdev->mincount = be32_to_cpup(p);
5561 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5563 /* Parse notification bitmap, verifying that it is zero. */
5564 p = xdr_inline_decode(xdr, 4);
5567 len = be32_to_cpup(p);
5571 p = xdr_inline_decode(xdr, 4 * len);
5574 for (i = 0; i < len; i++, p++) {
5575 if (be32_to_cpup(p)) {
5576 dprintk("%s: notifications not supported\n",
5584 print_overflow_msg(__func__, xdr);
5588 static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5589 struct nfs4_layoutget_res *res)
5594 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5595 struct kvec *iov = rcvbuf->head;
5598 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5601 p = xdr_inline_decode(xdr, 4);
5604 res->return_on_close = be32_to_cpup(p);
5605 decode_stateid(xdr, &res->stateid);
5606 p = xdr_inline_decode(xdr, 4);
5609 layout_count = be32_to_cpup(p);
5610 if (!layout_count) {
5611 dprintk("%s: server responded with empty layout array\n",
5616 p = xdr_inline_decode(xdr, 28);
5619 p = xdr_decode_hyper(p, &res->range.offset);
5620 p = xdr_decode_hyper(p, &res->range.length);
5621 res->range.iomode = be32_to_cpup(p++);
5622 res->type = be32_to_cpup(p++);
5623 res->layoutp->len = be32_to_cpup(p);
5625 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5627 (unsigned long)res->range.offset,
5628 (unsigned long)res->range.length,
5633 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5634 recvd = req->rq_rcv_buf.len - hdrlen;
5635 if (res->layoutp->len > recvd) {
5636 dprintk("NFS: server cheating in layoutget reply: "
5637 "layout len %u > recvd %u\n",
5638 res->layoutp->len, recvd);
5642 xdr_read_pages(xdr, res->layoutp->len);
5644 if (layout_count > 1) {
5645 /* We only handle a length one array at the moment. Any
5646 * further entries are just ignored. Note that this means
5647 * the client may see a response that is less than the
5648 * minimum it requested.
5650 dprintk("%s: server responded with %d layouts, dropping tail\n",
5651 __func__, layout_count);
5656 print_overflow_msg(__func__, xdr);
5660 static int decode_layoutreturn(struct xdr_stream *xdr,
5661 struct nfs4_layoutreturn_res *res)
5666 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5669 p = xdr_inline_decode(xdr, 4);
5672 res->lrs_present = be32_to_cpup(p);
5673 if (res->lrs_present)
5674 status = decode_stateid(xdr, &res->stateid);
5677 print_overflow_msg(__func__, xdr);
5681 static int decode_layoutcommit(struct xdr_stream *xdr,
5682 struct rpc_rqst *req,
5683 struct nfs4_layoutcommit_res *res)
5689 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5690 res->status = status;
5694 p = xdr_inline_decode(xdr, 4);
5697 sizechanged = be32_to_cpup(p);
5700 /* throw away new size */
5701 p = xdr_inline_decode(xdr, 8);
5707 print_overflow_msg(__func__, xdr);
5711 static int decode_test_stateid(struct xdr_stream *xdr,
5712 struct nfs41_test_stateid_res *res)
5718 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5722 p = xdr_inline_decode(xdr, 4);
5725 num_res = be32_to_cpup(p++);
5729 p = xdr_inline_decode(xdr, 4);
5732 res->status = be32_to_cpup(p++);
5736 print_overflow_msg(__func__, xdr);
5741 static int decode_free_stateid(struct xdr_stream *xdr,
5742 struct nfs41_free_stateid_res *res)
5747 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5751 p = xdr_inline_decode(xdr, 4);
5754 res->status = be32_to_cpup(p++);
5757 print_overflow_msg(__func__, xdr);
5760 #endif /* CONFIG_NFS_V4_1 */
5763 * END OF "GENERIC" DECODE ROUTINES.
5767 * Decode OPEN_DOWNGRADE response
5769 static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5770 struct xdr_stream *xdr,
5771 struct nfs_closeres *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_open_downgrade(xdr, res);
5788 decode_getfattr(xdr, res->fattr, res->server);
5794 * Decode ACCESS response
5796 static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5797 struct nfs4_accessres *res)
5799 struct compound_hdr hdr;
5802 status = decode_compound_hdr(xdr, &hdr);
5805 status = decode_sequence(xdr, &res->seq_res, rqstp);
5808 status = decode_putfh(xdr);
5811 status = decode_access(xdr, res);
5814 decode_getfattr(xdr, res->fattr, res->server);
5820 * Decode LOOKUP response
5822 static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5823 struct nfs4_lookup_res *res)
5825 struct compound_hdr hdr;
5828 status = decode_compound_hdr(xdr, &hdr);
5831 status = decode_sequence(xdr, &res->seq_res, rqstp);
5834 status = decode_putfh(xdr);
5837 status = decode_lookup(xdr);
5840 status = decode_getfh(xdr, res->fh);
5843 status = decode_getfattr(xdr, res->fattr, res->server);
5849 * Decode LOOKUP_ROOT response
5851 static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5852 struct xdr_stream *xdr,
5853 struct nfs4_lookup_res *res)
5855 struct compound_hdr hdr;
5858 status = decode_compound_hdr(xdr, &hdr);
5861 status = decode_sequence(xdr, &res->seq_res, rqstp);
5864 status = decode_putrootfh(xdr);
5867 status = decode_getfh(xdr, res->fh);
5869 status = decode_getfattr(xdr, res->fattr, res->server);
5875 * Decode REMOVE response
5877 static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5878 struct nfs_removeres *res)
5880 struct compound_hdr hdr;
5883 status = decode_compound_hdr(xdr, &hdr);
5886 status = decode_sequence(xdr, &res->seq_res, rqstp);
5889 status = decode_putfh(xdr);
5892 status = decode_remove(xdr, &res->cinfo);
5898 * Decode RENAME response
5900 static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5901 struct nfs_renameres *res)
5903 struct compound_hdr hdr;
5906 status = decode_compound_hdr(xdr, &hdr);
5909 status = decode_sequence(xdr, &res->seq_res, rqstp);
5912 status = decode_putfh(xdr);
5915 status = decode_savefh(xdr);
5918 status = decode_putfh(xdr);
5921 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5927 * Decode LINK response
5929 static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5930 struct nfs4_link_res *res)
5932 struct compound_hdr hdr;
5935 status = decode_compound_hdr(xdr, &hdr);
5938 status = decode_sequence(xdr, &res->seq_res, rqstp);
5941 status = decode_putfh(xdr);
5944 status = decode_savefh(xdr);
5947 status = decode_putfh(xdr);
5950 status = decode_link(xdr, &res->cinfo);
5954 * Note order: OP_LINK leaves the directory as the current
5957 status = decode_restorefh(xdr);
5960 decode_getfattr(xdr, res->fattr, res->server);
5966 * Decode CREATE response
5968 static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5969 struct nfs4_create_res *res)
5971 struct compound_hdr hdr;
5974 status = decode_compound_hdr(xdr, &hdr);
5977 status = decode_sequence(xdr, &res->seq_res, rqstp);
5980 status = decode_putfh(xdr);
5983 status = decode_create(xdr, &res->dir_cinfo);
5986 status = decode_getfh(xdr, res->fh);
5989 decode_getfattr(xdr, res->fattr, res->server);
5995 * Decode SYMLINK response
5997 static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5998 struct nfs4_create_res *res)
6000 return nfs4_xdr_dec_create(rqstp, xdr, res);
6004 * Decode GETATTR response
6006 static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6007 struct nfs4_getattr_res *res)
6009 struct compound_hdr hdr;
6012 status = decode_compound_hdr(xdr, &hdr);
6015 status = decode_sequence(xdr, &res->seq_res, rqstp);
6018 status = decode_putfh(xdr);
6021 status = decode_getfattr(xdr, res->fattr, res->server);
6027 * Encode an SETACL request
6029 static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6030 struct nfs_setaclargs *args)
6032 struct compound_hdr hdr = {
6033 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
6036 encode_compound_hdr(xdr, req, &hdr);
6037 encode_sequence(xdr, &args->seq_args, &hdr);
6038 encode_putfh(xdr, args->fh, &hdr);
6039 encode_setacl(xdr, args, &hdr);
6044 * Decode SETACL response
6047 nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6048 struct nfs_setaclres *res)
6050 struct compound_hdr hdr;
6053 status = decode_compound_hdr(xdr, &hdr);
6056 status = decode_sequence(xdr, &res->seq_res, rqstp);
6059 status = decode_putfh(xdr);
6062 status = decode_setattr(xdr);
6068 * Decode GETACL response
6071 nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6072 struct nfs_getaclres *res)
6074 struct compound_hdr hdr;
6077 if (res->acl_scratch != NULL) {
6078 void *p = page_address(res->acl_scratch);
6079 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6081 status = decode_compound_hdr(xdr, &hdr);
6084 status = decode_sequence(xdr, &res->seq_res, rqstp);
6087 status = decode_putfh(xdr);
6090 status = decode_getacl(xdr, rqstp, res);
6097 * Decode CLOSE response
6099 static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6100 struct nfs_closeres *res)
6102 struct compound_hdr hdr;
6105 status = decode_compound_hdr(xdr, &hdr);
6108 status = decode_sequence(xdr, &res->seq_res, rqstp);
6111 status = decode_putfh(xdr);
6114 status = decode_close(xdr, res);
6118 * Note: Server may do delete on close for this file
6119 * in which case the getattr call will fail with
6120 * an ESTALE error. Shouldn't be a problem,
6121 * though, since fattr->valid will remain unset.
6123 decode_getfattr(xdr, res->fattr, res->server);
6129 * Decode OPEN response
6131 static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6132 struct nfs_openres *res)
6134 struct compound_hdr hdr;
6137 status = decode_compound_hdr(xdr, &hdr);
6140 status = decode_sequence(xdr, &res->seq_res, rqstp);
6143 status = decode_putfh(xdr);
6146 status = decode_open(xdr, res);
6149 if (decode_getfh(xdr, &res->fh) != 0)
6151 decode_getfattr(xdr, res->f_attr, res->server);
6157 * Decode OPEN_CONFIRM response
6159 static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6160 struct xdr_stream *xdr,
6161 struct nfs_open_confirmres *res)
6163 struct compound_hdr hdr;
6166 status = decode_compound_hdr(xdr, &hdr);
6169 status = decode_putfh(xdr);
6172 status = decode_open_confirm(xdr, res);
6178 * Decode OPEN response
6180 static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6181 struct xdr_stream *xdr,
6182 struct nfs_openres *res)
6184 struct compound_hdr hdr;
6187 status = decode_compound_hdr(xdr, &hdr);
6190 status = decode_sequence(xdr, &res->seq_res, rqstp);
6193 status = decode_putfh(xdr);
6196 status = decode_open(xdr, res);
6199 decode_getfattr(xdr, res->f_attr, res->server);
6205 * Decode SETATTR response
6207 static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6208 struct xdr_stream *xdr,
6209 struct nfs_setattrres *res)
6211 struct compound_hdr hdr;
6214 status = decode_compound_hdr(xdr, &hdr);
6217 status = decode_sequence(xdr, &res->seq_res, rqstp);
6220 status = decode_putfh(xdr);
6223 status = decode_setattr(xdr);
6226 decode_getfattr(xdr, res->fattr, res->server);
6232 * Decode LOCK response
6234 static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6235 struct nfs_lock_res *res)
6237 struct compound_hdr hdr;
6240 status = decode_compound_hdr(xdr, &hdr);
6243 status = decode_sequence(xdr, &res->seq_res, rqstp);
6246 status = decode_putfh(xdr);
6249 status = decode_lock(xdr, res);
6255 * Decode LOCKT response
6257 static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6258 struct nfs_lockt_res *res)
6260 struct compound_hdr hdr;
6263 status = decode_compound_hdr(xdr, &hdr);
6266 status = decode_sequence(xdr, &res->seq_res, rqstp);
6269 status = decode_putfh(xdr);
6272 status = decode_lockt(xdr, res);
6278 * Decode LOCKU response
6280 static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6281 struct nfs_locku_res *res)
6283 struct compound_hdr hdr;
6286 status = decode_compound_hdr(xdr, &hdr);
6289 status = decode_sequence(xdr, &res->seq_res, rqstp);
6292 status = decode_putfh(xdr);
6295 status = decode_locku(xdr, res);
6300 static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6301 struct xdr_stream *xdr, void *dummy)
6303 struct compound_hdr hdr;
6306 status = decode_compound_hdr(xdr, &hdr);
6308 status = decode_release_lockowner(xdr);
6313 * Decode READLINK response
6315 static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6316 struct xdr_stream *xdr,
6317 struct nfs4_readlink_res *res)
6319 struct compound_hdr hdr;
6322 status = decode_compound_hdr(xdr, &hdr);
6325 status = decode_sequence(xdr, &res->seq_res, rqstp);
6328 status = decode_putfh(xdr);
6331 status = decode_readlink(xdr, rqstp);
6337 * Decode READDIR response
6339 static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6340 struct nfs4_readdir_res *res)
6342 struct compound_hdr hdr;
6345 status = decode_compound_hdr(xdr, &hdr);
6348 status = decode_sequence(xdr, &res->seq_res, rqstp);
6351 status = decode_putfh(xdr);
6354 status = decode_readdir(xdr, rqstp, res);
6360 * Decode Read response
6362 static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6363 struct nfs_readres *res)
6365 struct compound_hdr hdr;
6368 status = decode_compound_hdr(xdr, &hdr);
6371 status = decode_sequence(xdr, &res->seq_res, rqstp);
6374 status = decode_putfh(xdr);
6377 status = decode_read(xdr, rqstp, res);
6379 status = res->count;
6385 * Decode WRITE response
6387 static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6388 struct nfs_writeres *res)
6390 struct compound_hdr hdr;
6393 status = decode_compound_hdr(xdr, &hdr);
6396 status = decode_sequence(xdr, &res->seq_res, rqstp);
6399 status = decode_putfh(xdr);
6402 status = decode_write(xdr, res);
6406 decode_getfattr(xdr, res->fattr, res->server);
6408 status = res->count;
6414 * Decode COMMIT response
6416 static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6417 struct nfs_commitres *res)
6419 struct compound_hdr hdr;
6422 status = decode_compound_hdr(xdr, &hdr);
6425 status = decode_sequence(xdr, &res->seq_res, rqstp);
6428 status = decode_putfh(xdr);
6431 status = decode_commit(xdr, res);
6437 * Decode FSINFO response
6439 static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6440 struct nfs4_fsinfo_res *res)
6442 struct compound_hdr hdr;
6445 status = decode_compound_hdr(xdr, &hdr);
6447 status = decode_sequence(xdr, &res->seq_res, req);
6449 status = decode_putfh(xdr);
6451 status = decode_fsinfo(xdr, res->fsinfo);
6456 * Decode PATHCONF response
6458 static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6459 struct nfs4_pathconf_res *res)
6461 struct compound_hdr hdr;
6464 status = decode_compound_hdr(xdr, &hdr);
6466 status = decode_sequence(xdr, &res->seq_res, req);
6468 status = decode_putfh(xdr);
6470 status = decode_pathconf(xdr, res->pathconf);
6475 * Decode STATFS response
6477 static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6478 struct nfs4_statfs_res *res)
6480 struct compound_hdr hdr;
6483 status = decode_compound_hdr(xdr, &hdr);
6485 status = decode_sequence(xdr, &res->seq_res, req);
6487 status = decode_putfh(xdr);
6489 status = decode_statfs(xdr, res->fsstat);
6494 * Decode GETATTR_BITMAP response
6496 static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6497 struct xdr_stream *xdr,
6498 struct nfs4_server_caps_res *res)
6500 struct compound_hdr hdr;
6503 status = decode_compound_hdr(xdr, &hdr);
6506 status = decode_sequence(xdr, &res->seq_res, req);
6509 status = decode_putfh(xdr);
6512 status = decode_server_caps(xdr, res);
6518 * Decode RENEW response
6520 static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6523 struct compound_hdr hdr;
6526 status = decode_compound_hdr(xdr, &hdr);
6528 status = decode_renew(xdr);
6533 * Decode SETCLIENTID response
6535 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6536 struct xdr_stream *xdr,
6537 struct nfs4_setclientid_res *res)
6539 struct compound_hdr hdr;
6542 status = decode_compound_hdr(xdr, &hdr);
6544 status = decode_setclientid(xdr, res);
6549 * Decode SETCLIENTID_CONFIRM response
6551 static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6552 struct xdr_stream *xdr,
6553 struct nfs_fsinfo *fsinfo)
6555 struct compound_hdr hdr;
6558 status = decode_compound_hdr(xdr, &hdr);
6560 status = decode_setclientid_confirm(xdr);
6562 status = decode_putrootfh(xdr);
6564 status = decode_fsinfo(xdr, fsinfo);
6569 * Decode DELEGRETURN response
6571 static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6572 struct xdr_stream *xdr,
6573 struct nfs4_delegreturnres *res)
6575 struct compound_hdr hdr;
6578 status = decode_compound_hdr(xdr, &hdr);
6581 status = decode_sequence(xdr, &res->seq_res, rqstp);
6584 status = decode_putfh(xdr);
6587 status = decode_getfattr(xdr, res->fattr, res->server);
6590 status = decode_delegreturn(xdr);
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_generic(xdr, &res->fs_locations->fattr,
6619 NULL, res->fs_locations,
6620 res->fs_locations->server);
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);
6875 * Decode SECINFO_NO_NAME response
6877 static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6878 struct xdr_stream *xdr,
6879 struct nfs4_secinfo_res *res)
6881 struct compound_hdr hdr;
6884 status = decode_compound_hdr(xdr, &hdr);
6887 status = decode_sequence(xdr, &res->seq_res, rqstp);
6890 status = decode_putrootfh(xdr);
6893 status = decode_secinfo_no_name(xdr, res);
6899 * Decode TEST_STATEID response
6901 static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6902 struct xdr_stream *xdr,
6903 struct nfs41_test_stateid_res *res)
6905 struct compound_hdr hdr;
6908 status = decode_compound_hdr(xdr, &hdr);
6911 status = decode_sequence(xdr, &res->seq_res, rqstp);
6914 status = decode_test_stateid(xdr, res);
6920 * Decode FREE_STATEID response
6922 static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6923 struct xdr_stream *xdr,
6924 struct nfs41_free_stateid_res *res)
6926 struct compound_hdr hdr;
6929 status = decode_compound_hdr(xdr, &hdr);
6932 status = decode_sequence(xdr, &res->seq_res, rqstp);
6935 status = decode_free_stateid(xdr, res);
6939 #endif /* CONFIG_NFS_V4_1 */
6942 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6943 * the local page cache.
6944 * @xdr: XDR stream where entry resides
6945 * @entry: buffer to fill in with entry data
6946 * @plus: boolean indicating whether this should be a readdirplus entry
6948 * Returns zero if successful, otherwise a negative errno value is
6951 * This function is not invoked during READDIR reply decoding, but
6952 * rather whenever an application invokes the getdents(2) system call
6953 * on a directory already in our cache.
6955 int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6958 uint32_t bitmap[3] = {0};
6960 __be32 *p = xdr_inline_decode(xdr, 4);
6963 if (*p == xdr_zero) {
6964 p = xdr_inline_decode(xdr, 4);
6973 p = xdr_inline_decode(xdr, 12);
6976 entry->prev_cookie = entry->cookie;
6977 p = xdr_decode_hyper(p, &entry->cookie);
6978 entry->len = be32_to_cpup(p);
6980 p = xdr_inline_decode(xdr, entry->len);
6983 entry->name = (const char *) p;
6986 * In case the server doesn't return an inode number,
6987 * we fake one here. (We don't use inode number 0,
6988 * since glibc seems to choke on it...)
6991 entry->fattr->valid = 0;
6993 if (decode_attr_bitmap(xdr, bitmap) < 0)
6996 if (decode_attr_length(xdr, &len, &p) < 0)
6999 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
7000 NULL, entry->server) < 0)
7002 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7003 entry->ino = entry->fattr->mounted_on_fileid;
7004 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
7005 entry->ino = entry->fattr->fileid;
7007 entry->d_type = DT_UNKNOWN;
7008 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7009 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7014 print_overflow_msg(__func__, xdr);
7019 * We need to translate between nfs status return values and
7020 * the local errno values which may not be the same.
7027 { NFS4ERR_PERM, -EPERM },
7028 { NFS4ERR_NOENT, -ENOENT },
7029 { NFS4ERR_IO, -errno_NFSERR_IO},
7030 { NFS4ERR_NXIO, -ENXIO },
7031 { NFS4ERR_ACCESS, -EACCES },
7032 { NFS4ERR_EXIST, -EEXIST },
7033 { NFS4ERR_XDEV, -EXDEV },
7034 { NFS4ERR_NOTDIR, -ENOTDIR },
7035 { NFS4ERR_ISDIR, -EISDIR },
7036 { NFS4ERR_INVAL, -EINVAL },
7037 { NFS4ERR_FBIG, -EFBIG },
7038 { NFS4ERR_NOSPC, -ENOSPC },
7039 { NFS4ERR_ROFS, -EROFS },
7040 { NFS4ERR_MLINK, -EMLINK },
7041 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7042 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7043 { NFS4ERR_DQUOT, -EDQUOT },
7044 { NFS4ERR_STALE, -ESTALE },
7045 { NFS4ERR_BADHANDLE, -EBADHANDLE },
7046 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7047 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7048 { NFS4ERR_TOOSMALL, -ETOOSMALL },
7049 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
7050 { NFS4ERR_BADTYPE, -EBADTYPE },
7051 { NFS4ERR_LOCKED, -EAGAIN },
7052 { NFS4ERR_SYMLINK, -ELOOP },
7053 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7054 { NFS4ERR_DEADLOCK, -EDEADLK },
7059 * Convert an NFS error code to a local one.
7060 * This one is used jointly by NFSv2 and NFSv3.
7063 nfs4_stat_to_errno(int stat)
7066 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7067 if (nfs_errtbl[i].stat == stat)
7068 return nfs_errtbl[i].errno;
7070 if (stat <= 10000 || stat > 10100) {
7071 /* The server is looney tunes. */
7074 /* If we cannot translate the error, the recovery routines should
7076 * Note: remaining NFSv4 error codes have values > 10000, so should
7077 * not conflict with native Linux error codes.
7082 #define PROC(proc, argtype, restype) \
7083 [NFSPROC4_CLNT_##proc] = { \
7084 .p_proc = NFSPROC4_COMPOUND, \
7085 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
7086 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
7087 .p_arglen = NFS4_##argtype##_sz, \
7088 .p_replen = NFS4_##restype##_sz, \
7089 .p_statidx = NFSPROC4_CLNT_##proc, \
7093 struct rpc_procinfo nfs4_procedures[] = {
7094 PROC(READ, enc_read, dec_read),
7095 PROC(WRITE, enc_write, dec_write),
7096 PROC(COMMIT, enc_commit, dec_commit),
7097 PROC(OPEN, enc_open, dec_open),
7098 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7099 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7100 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7101 PROC(CLOSE, enc_close, dec_close),
7102 PROC(SETATTR, enc_setattr, dec_setattr),
7103 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7104 PROC(RENEW, enc_renew, dec_renew),
7105 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7106 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7107 PROC(LOCK, enc_lock, dec_lock),
7108 PROC(LOCKT, enc_lockt, dec_lockt),
7109 PROC(LOCKU, enc_locku, dec_locku),
7110 PROC(ACCESS, enc_access, dec_access),
7111 PROC(GETATTR, enc_getattr, dec_getattr),
7112 PROC(LOOKUP, enc_lookup, dec_lookup),
7113 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7114 PROC(REMOVE, enc_remove, dec_remove),
7115 PROC(RENAME, enc_rename, dec_rename),
7116 PROC(LINK, enc_link, dec_link),
7117 PROC(SYMLINK, enc_symlink, dec_symlink),
7118 PROC(CREATE, enc_create, dec_create),
7119 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7120 PROC(STATFS, enc_statfs, dec_statfs),
7121 PROC(READLINK, enc_readlink, dec_readlink),
7122 PROC(READDIR, enc_readdir, dec_readdir),
7123 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7124 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7125 PROC(GETACL, enc_getacl, dec_getacl),
7126 PROC(SETACL, enc_setacl, dec_setacl),
7127 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7128 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
7129 PROC(SECINFO, enc_secinfo, dec_secinfo),
7130 #if defined(CONFIG_NFS_V4_1)
7131 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7132 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7133 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7134 PROC(SEQUENCE, enc_sequence, dec_sequence),
7135 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7136 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7137 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7138 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
7139 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7140 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7141 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7142 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7143 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
7144 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
7145 #endif /* CONFIG_NFS_V4_1 */
7148 const struct rpc_version nfs_version4 = {
7150 .nrprocs = ARRAY_SIZE(nfs4_procedures),
7151 .procs = nfs4_procedures